using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Text; using DSWeb.DataAccess; using System.Data.SqlClient; using DSWeb.Models; using DSWeb.EntityDA; using System.Web.Script.Serialization; namespace DSWeb.Shipping { public partial class ExchangesUnitContact : System.Web.UI.Page { public string strHandleType = String.Empty; public string sSQL = String.Empty; public string gvid = String.Empty; T_ALL_DA T_ALL_DA = new T_ALL_DA(); MoneyConvert MoneyConvert = new MoneyConvert(); TopSeaeEntity TopSeaeEntity = new TopSeaeEntity(); SeaExportInfoDA SeaExportInfoDA = new SeaExportInfoDA(); RangeDA RangeDA = new RangeDA(); public string strUserID;//用户GID protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString().Trim(); hdUserID.Value = strUserID.Trim(); } else { Server.Transfer("~/Error/FriendError.aspx"); return; //strUserID = ""; //hdUserID.Value = strUserID.Trim(); } // if (!IsPostBack) { if (Request.QueryString["handle"] != null) //if (Request.QueryString["handle"] != null) { ViewState["strHandleType"] = Request.QueryString["handle"].ToString();//"edit"; strHandleType = ViewState["strHandleType"].ToString().Trim(); if (Request.QueryString["id"] != null)//if (Request.QueryString["id"] != null) { ViewState["GID"] = Request.QueryString["id"].ToString();//"topseaeusername129481962859531250"; this.hdGid.Value = ViewState["GID"].ToString().Trim(); } if (Request.QueryString["LINKID"] != null)//if (Request.QueryString["id"] != null) { ViewState["LINKID"] = Request.QueryString["LINKID"].ToString(); } // switch (strHandleType) { case "add"://新增 ViewState["GID"] = getBSNO(); this.hdGid.Value = ViewState["GID"].ToString().Trim(); // cbISSTOP.Checked = false; cbISFINANCIALSTAFF.Checked = false; cbISOPERATOR.Checked = false; cbISSALEMAN.Checked = false; cbISOTHER.Checked = false; //tbCODENAME.Text = ""; tbSHOWNAME.Text = ""; tbADDR.Text = ""; tbEMAIL.Text = ""; tbTEL1.Text = "86"; tbTEL2.Text = ""; tbTEL.Text = ""; tbFAX1.Text = "86"; tbFAX2.Text = ""; tbFAX.Text = ""; tbMOBILE1.Text = "86"; tbMOBILE.Text = ""; tbREMARK.Text = ""; break; case "edit"://录入 DataSet ds = T_ALL_DA.GetAllSQL(" select * from info_client_contact where ISDELETED=0 and GID='" + ViewState["GID"].ToString().Trim() + "'"); // if (ds == null) { return; } if (ds.Tables[0].Rows[0]["ISSTOP"].ToString().Trim() == "True") { cbISSTOP.Checked = true; } else { cbISSTOP.Checked = false; } if (ds.Tables[0].Rows[0]["ISFINANCIALSTAFF"].ToString().Trim() == "True") { cbISFINANCIALSTAFF.Checked = true; } else { cbISFINANCIALSTAFF.Checked = false; } if (ds.Tables[0].Rows[0]["ISOPERATOR"].ToString().Trim() == "True") { cbISOPERATOR.Checked = true; } else { cbISOPERATOR.Checked = false; } if (ds.Tables[0].Rows[0]["ISSALEMAN"].ToString().Trim() == "True") { cbISSALEMAN.Checked = true; } else { cbISSALEMAN.Checked = false; } if (ds.Tables[0].Rows[0]["ISOTHER"].ToString().Trim() == "True") { cbISOTHER.Checked = true; } else { cbISOTHER.Checked = false; } // //tbCODENAME.Text = ds.Tables[0].Rows[0]["CODENAME"].ToString().Trim(); tbSHOWNAME.Text = ds.Tables[0].Rows[0]["SHOWNAME"].ToString().Trim(); tbADDR.Text = ds.Tables[0].Rows[0]["ADDR"].ToString().Trim(); tbEMAIL.Text = ds.Tables[0].Rows[0]["EMAIL"].ToString().Trim(); // int itel = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().IndexOf("-"); if (itel != 0) { string[] strTELs = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < strTELs.Length; i++) { if (strTELs[i].Trim() == "" && i == 0) { tbTEL1.Text = "86"; } else { tbTEL1.Text = strTELs[0].Trim(); } if (strTELs[i].Trim() == "" && i == 1) { tbTEL2.Text = ""; } else { tbTEL2.Text = strTELs[1].Trim(); } if (strTELs[i].Trim() == "" && i == 2) { tbTEL.Text = ""; } else { tbTEL.Text = strTELs[2].Trim(); } } } else { tbTEL1.Text = "86"; tbTEL2.Text = ""; tbTEL.Text = ""; } // int iFAX = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().IndexOf("-"); if (iFAX != 0) { string[] strFAXs = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < strFAXs.Length; i++) { if (strFAXs[i].Trim() == "" && i == 0) { tbFAX1.Text = "86"; } else { tbFAX1.Text = strFAXs[0].Trim(); } if (strFAXs[i].Trim() == "" && i == 1) { tbFAX2.Text = ""; } else { tbFAX2.Text = strFAXs[1].Trim(); } if (strFAXs[i].Trim() == "" && i == 2) { tbFAX.Text = ""; } else { tbFAX.Text = strFAXs[2].Trim(); } } } else { tbFAX1.Text = "86"; tbFAX2.Text = ""; tbFAX.Text = ""; } // int iMOBILE = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().IndexOf("-"); if (iMOBILE != 0) { string[] strMOBILEs = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < strMOBILEs.Length; i++) { if (strMOBILEs[i].Trim() == "" && i == 0) { tbMOBILE1.Text = "86"; } else { tbMOBILE1.Text = strMOBILEs[0].Trim(); } if (strMOBILEs[i].Trim() == "" && i == 1) { tbMOBILE.Text = ""; } else { tbMOBILE.Text = strMOBILEs[1].Trim(); } } } else { tbMOBILE1.Text = "86"; tbMOBILE.Text = ""; } // tbREMARK.Text = ds.Tables[0].Rows[0]["REMARK"].ToString().Trim(); //权限可视范围 string strV = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modExchangesUnit"); string strO = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modExchangesUnit"); string alt = ""; if (strV.Trim().Equals("4"))//全部 { ibAdd.Enabled = true; } else if (strV.Trim().Equals("1"))//分公司 { if (strO.Trim().Equals("1"))//公司 { alt = RangeDA.GetUnitCompany(strUserID.Trim(), ViewState["LINKID"].ToString().Trim()); if (alt == "") { getEnabled(); } } else if (strO.Trim().Equals("3"))//个人 { alt = RangeDA.GetUnitPerson(strUserID.Trim(), ViewState["LINKID"].ToString().Trim()); if (alt == "") { getEnabled(); } } } else if (strV.Trim().Equals("3")) { if (strO.Trim().Equals("3"))//个人 { alt = RangeDA.GetUnitPerson(strUserID.Trim(), ViewState["LINKID"].ToString().Trim()); if (alt == "") { getEnabled(); } } else if (strO.Trim().Equals("4"))//无 { getEnabled(); } } // break; } } else { } } } protected void getEnabled() { ibAdd.Enabled = false; ibEnter.Enabled = false; ibDel.Enabled = false; // cbISSTOP.Enabled = false; cbISFINANCIALSTAFF.Enabled = false; cbISOPERATOR.Enabled = false; cbISSALEMAN.Enabled = false; cbISOTHER.Enabled = false; //tbCODENAME.Enabled = false; tbSHOWNAME.Enabled = false; tbADDR.Enabled = false; tbEMAIL.Enabled = false; tbTEL1.Enabled = false; tbTEL2.Enabled = false; tbTEL.Enabled = false; tbFAX1.Enabled = false; tbFAX2.Enabled = false; tbFAX.Enabled = false; tbMOBILE1.Enabled = false; tbMOBILE.Enabled = false; tbREMARK.Enabled = false; } protected String getBSNO() { string strBSNO = Guid.NewGuid().ToString(); strBSNO = strBSNO.Replace("-", ""); strBSNO = "Clie" + strBSNO; return strBSNO; } protected bool getAdd() { string alt = ""; alt = T_ALL_DA.GetInfoClientInsertContact(ViewState["GID"].ToString().Trim(), ViewState["LINKID"].ToString().Trim(), cbISSTOP.Checked, cbISFINANCIALSTAFF.Checked, cbISOPERATOR.Checked, cbISSALEMAN.Checked, cbISOTHER.Checked, tbCODENAME.Text, tbSHOWNAME.Text, tbTEL1.Text + "-" + tbTEL2.Text + "-" + tbTEL.Text, tbFAX1.Text + "-" + tbFAX2.Text + "-" + tbFAX.Text,tbMOBILE1.Text.Trim()+"-"+tbMOBILE.Text.Trim(), tbADDR.Text, tbEMAIL.Text, tbREMARK.Text, strUserID.Trim(),"","","","","",false,false,false,0,0,0,"","","","","",""); if (alt == "") { ViewState["strHandleType"] = "edit"; return true; } else { return false; } } protected bool getEdit() { string alt = ""; alt = T_ALL_DA.GetInfoClientUpdateContact(ViewState["LINKID"].ToString().Trim(), ViewState["GID"].ToString().Trim(), cbISSTOP.Checked, cbISFINANCIALSTAFF.Checked, cbISOPERATOR.Checked, cbISSALEMAN.Checked, cbISOTHER.Checked, tbCODENAME.Text, tbSHOWNAME.Text, tbTEL1.Text + "-" + tbTEL2.Text + "-" + tbTEL.Text, tbFAX1.Text + "-" + tbFAX2.Text + "-" + tbFAX.Text, tbMOBILE1.Text.Trim() + "-" + tbMOBILE.Text.Trim(), tbADDR.Text, tbEMAIL.Text, tbREMARK.Text, strUserID.Trim(), "", "", "", "", "", false, false, false, 0,0, 0, "", "", "", "", "", ""); if (alt == "") { return true; } else { return false; } } protected void btnEnter_Click(object sender, EventArgs e) { if (cbISFINANCIALSTAFF.Checked != true && cbISOPERATOR.Checked != true && cbISSALEMAN.Checked != true && cbISOTHER.Checked != true) { System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport30", "alert('联系人类型为必选项,也可多选!');", true); return; } // //if (tbTEL1.Text.Trim().Equals("") || tbTEL2.Text.Trim().Equals("") || tbTEL.Text.Trim().Equals("") || tbFAX1.Text.Trim().Equals("") || tbFAX2.Text.Trim().Equals("") || tbFAX.Text.Trim().Equals("") || tbMOBILE1.Text.Trim().Equals("") || tbMOBILE.Text.Trim().Equals("")) //{ // System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport30", "alert('联系人的电话、传真、手机都不允许为空!');", true); // return; //} // bool bl = false; strHandleType = ViewState["strHandleType"].ToString(); if (strHandleType.Equals("add"))//新增 { /* //DataSet ds = T_ALL_DA.GetAllSQL(" select * from info_client_contact where ISDELETED=0 and CODENAME='" + tbCODENAME.Text.Trim() + "'"); DataSet ds = T_ALL_DA.GetAllSQL(" select * from info_client_contact where ISDELETED=0 and SHOWNAME='" + tbSHOWNAME.Text.Trim() + "'"); if (ds != null) { if (ds.Tables[0].Rows[0]["CODENAME"].ToString().Trim() != "") { System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport30", "alert('联系人代码重复,请重新填写!');", true); return; } } */ // bl = getAdd(); } else if (strHandleType.Equals("edit"))//录入 { /* //DataSet ds = T_ALL_DA.GetAllSQL(" select * from info_client_contact where ISDELETED=0 and CODENAME='" + tbCODENAME.Text.Trim() + "' and Gid<>'" + ViewState["GID"].ToString().Trim() + "'"); DataSet ds = T_ALL_DA.GetAllSQL(" select * from info_client_contact where ISDELETED=0 and SHOWNAME='" + tbSHOWNAME.Text.Trim() + "' and Gid<>'" + ViewState["GID"].ToString().Trim() + "'"); if (ds != null) { if (ds.Tables[0].Rows[0]["CODENAME"].ToString().Trim() != "") { System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport30", "alert('联系人代码重复,请重新填写!');", true); return; } } // ds = T_ALL_DA.GetAllSQL(" select * from info_client_contact where ISDELETED=0 and SHOWNAME='" + tbSHOWNAME.Text.Trim() + "' and Gid<>'" + ViewState["GID"].ToString().Trim() + "'"); if (ds != null) { if (ds.Tables[0].Rows[0]["SHOWNAME"].ToString().Trim() != "") { System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport30", "alert('联系人简称重复,请重新填写!');", true); return; } } */ // bl = getEdit(); } ibDel.Enabled = true; ibAdd.Enabled = true; if (bl) { //System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport30", "reloadParent('" + ViewState["GID"].ToString().Trim() + "');", true); System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport30", "alert('成功提交!');window.opener.location.reload();history.back();", true); //Response.Write(""); return; } else { System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport31", "alert('出错,请重新填写!');", true); //Response.Write(""); return; } } protected void btnAdd_Click(object sender, EventArgs e) { //Session["USERID"] = "04eaeac5-f271-45d1-b17b-ad4ccbab63d0"; ViewState["strHandleType"] = "add"; ViewState["GID"] = getBSNO(); this.hdGid.Value = ViewState["GID"].ToString().Trim(); // cbISSTOP.Checked = false; cbISFINANCIALSTAFF.Checked = false; cbISOPERATOR.Checked = false; cbISSALEMAN.Checked = false; cbISOTHER.Checked = false; //tbCODENAME.Text = ""; tbSHOWNAME.Text = ""; tbADDR.Text = ""; tbEMAIL.Text = ""; tbTEL1.Text = "86"; tbTEL2.Text = ""; tbTEL.Text = ""; tbFAX1.Text = "86"; tbFAX2.Text = ""; tbFAX.Text = ""; tbREMARK.Text = ""; // ibDel.Enabled = false; ibAdd.Enabled = true; ibEnter.Enabled = true; } protected void btnDel_Click(object sender, EventArgs e) { string alt = T_ALL_DA.GetInfoClientContactDel(ViewState["GID"].ToString().Trim(), strUserID.Trim()); if (alt != "") { System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport50", "alert('" + alt + "');", true); return; } else { //window.opener.location.reload(); System.Web.UI.ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "unReport50", "alert('删除成功!');window.opener.location.reload();history.back();", true); } // ViewState["strHandleType"] = "edit"; DataSet ds = T_ALL_DA.GetAllSQL("select top 1 * from info_client order by CODENAME"); // if (ds == null) { return; } // if (ds.Tables[0].Rows[0]["ISSTOP"].ToString().Trim() == "True") { cbISSTOP.Checked = true; } else { cbISSTOP.Checked = false; } if (ds.Tables[0].Rows[0]["ISFINANCIALSTAFF"].ToString().Trim() == "True") { cbISFINANCIALSTAFF.Checked = true; } else { cbISFINANCIALSTAFF.Checked = false; } if (ds.Tables[0].Rows[0]["ISOPERATOR"].ToString().Trim() == "True") { cbISOPERATOR.Checked = true; } else { cbISOPERATOR.Checked = false; } if (ds.Tables[0].Rows[0]["ISSALEMAN"].ToString().Trim() == "True") { cbISSALEMAN.Checked = true; } else { cbISSALEMAN.Checked = false; } if (ds.Tables[0].Rows[0]["ISOTHER"].ToString().Trim() == "True") { cbISOTHER.Checked = true; } else { cbISOTHER.Checked = false; } // //tbCODENAME.Text = ds.Tables[0].Rows[0]["CODENAME"].ToString().Trim(); tbSHOWNAME.Text = ds.Tables[0].Rows[0]["SHOWNAME"].ToString().Trim(); tbADDR.Text = ds.Tables[0].Rows[0]["ADDR"].ToString().Trim(); tbEMAIL.Text = ds.Tables[0].Rows[0]["EMAIL"].ToString().Trim(); // int itel = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().IndexOf("-"); if (itel != 0) { string[] strTELs = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < strTELs.Length; i++) { if (strTELs[i].Trim() == "" && i == 0) { tbTEL1.Text = "86"; } else { tbTEL1.Text = strTELs[0].Trim(); } if (strTELs[i].Trim() == "" && i == 1) { tbTEL2.Text = ""; } else { tbTEL2.Text = strTELs[1].Trim(); } if (strTELs[i].Trim() == "" && i == 2) { tbTEL.Text = ""; } else { tbTEL.Text = strTELs[2].Trim(); } } } else { tbTEL1.Text = "86"; tbTEL2.Text = ""; tbTEL.Text = ""; } // int iFAX = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().IndexOf("-"); if (iFAX != 0) { string[] strFAXs = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < strFAXs.Length; i++) { if (strFAXs[i].Trim() == "" && i == 0) { tbFAX1.Text = "86"; } else { tbFAX1.Text = strFAXs[0].Trim(); } if (strFAXs[i].Trim() == "" && i == 1) { tbFAX2.Text = ""; } else { tbFAX2.Text = strFAXs[1].Trim(); } if (strFAXs[i].Trim() == "" && i == 2) { tbFAX.Text = ""; } else { tbFAX.Text = strFAXs[2].Trim(); } } } else { tbFAX1.Text = "86"; tbFAX2.Text = ""; tbFAX.Text = ""; } // int iMOBILE = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().IndexOf("-"); if (iMOBILE != 0) { string[] strMOBILEs = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < strMOBILEs.Length; i++) { if (strMOBILEs[i].Trim() == "" && i == 0) { tbMOBILE1.Text = "86"; } else { tbMOBILE1.Text = strMOBILEs[0].Trim(); } if (strMOBILEs[i].Trim() == "" && i == 1) { tbMOBILE.Text = ""; } else { tbMOBILE.Text = strMOBILEs[1].Trim(); } } } else { tbMOBILE1.Text = "86"; tbMOBILE.Text = ""; } // tbREMARK.Text = ds.Tables[0].Rows[0]["REMARK"].ToString().Trim(); // ibDel.Enabled = false; ibAdd.Enabled = false; } public bool IsNumeric(string s) { bool bReturn = true; try { int inum = int.Parse(s); } catch { //int inum = 0; bReturn = false; } return bReturn; } } }