Linkman.aspx.cs
上传用户:cha0314
上传日期:2014-03-02
资源大小:12522k
文件大小:8k
源码类别:

C#编程

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12. namespace UDS.SubModule.CM
  13. {
  14. /// <summary>
  15. /// Linkman 的摘要说明。
  16. /// </summary>
  17. public class Linkman : System.Web.UI.Page
  18. {
  19. protected System.Web.UI.WebControls.CheckBox cb_chief;
  20. protected System.Web.UI.WebControls.TextBox tb_Telephone;
  21. protected System.Web.UI.WebControls.TextBox tb_Mobile;
  22. protected System.Web.UI.WebControls.TextBox tb_Name;
  23. protected System.Web.UI.WebControls.TextBox tb_Position;
  24. protected System.Web.UI.WebControls.TextBox tb_Email;
  25. protected System.Web.UI.WebControls.TextBox tb_Description;
  26. protected System.Web.UI.WebControls.TextBox tb_Address;
  27. protected System.Web.UI.WebControls.TextBox tb_Family;
  28. protected System.Web.UI.WebControls.DropDownList ddl_Gender;
  29. protected System.Web.UI.WebControls.DropDownList ddl_ClientName;
  30. protected System.Web.UI.WebControls.Button btn_OK;
  31. protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
  32. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
  33. protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
  34. protected System.Web.UI.WebControls.Button btn_Del;
  35. private string from = "";
  36. private int clientid = 0;
  37. private int linkmanid = 0;
  38. private void Page_Load(object sender, System.EventArgs e)
  39. {
  40. if(!Page.IsPostBack)
  41. {
  42. clientid = ((Request.QueryString["ClientID"]==null)||(Request.QueryString["ClientID"].Trim()==""))?0:Int32.Parse(Request.QueryString["ClientID"].ToString());
  43. linkmanid = ((Request.QueryString["LinkmanID"]==null)||(Request.QueryString["LinkmanID"].Trim()==""))?0:Int32.Parse(Request.QueryString["LinkmanID"].ToString());
  44. from = (Request.QueryString["From"]==null)?"":Request.QueryString["From"];
  45. ViewState["LinkmanID"] = linkmanid.ToString();
  46. BindData();
  47. if(Session["cm_permission"].ToString() == "leader")
  48. btn_OK.Visible = false;
  49. }
  50. else
  51. {
  52. linkmanid = Int32.Parse(ViewState["LinkmanID"].ToString());
  53. clientid = Int32.Parse(ddl_ClientName.SelectedItem.Value);
  54. }
  55. if(linkmanid==0)
  56. {
  57. btn_OK.Text = "添加";
  58. btn_Del.Visible = false;
  59. }
  60. else
  61. {
  62. btn_OK.Text = "修改";
  63. btn_Del.Visible = true;
  64. }
  65. btn_Del.Attributes["onclick"] = "return confirm('确定要删除吗?')";
  66. }
  67. private void BindData()
  68. {
  69. UDS.Components.CM cm = new UDS.Components.CM();
  70. UDS.Components.ClientInfo client = new UDS.Components.ClientInfo();
  71. UDS.Components.Linkman linkman = new UDS.Components.Linkman();
  72. if(linkmanid!=0)
  73. {
  74. linkman = cm.GetLinkmanStructByID(linkmanid.ToString());
  75. clientid = linkman.ClientID;
  76. }
  77. else
  78. {
  79. }
  80. SqlDataReader dr = null;
  81. //dr = cm.GetClientInfo(clientid);
  82. dr = cm.GetMyClients(Int32.Parse(Request.Cookies["UserID"].Value));
  83. client = cm.GetClientAllInfo(clientid);
  84. //绑定客户下拉列表
  85. ddl_ClientName.DataSource = dr;
  86. ddl_ClientName.DataTextField = "Name";
  87. ddl_ClientName.DataValueField = "id";
  88. ddl_ClientName.DataBind();
  89. dr.Close();
  90. if((clientid==0)&&(from)!="ClientList")
  91. ddl_ClientName.Items.Insert(0,new ListItem("当前客户","0"));
  92. else
  93. {
  94. //使传入的clientid处于选中状态
  95. foreach(ListItem lt in ddl_ClientName.Items)
  96. {
  97. if(lt.Value==clientid.ToString())
  98. {
  99. lt.Selected = true;
  100. }
  101. }
  102. }
  103. dr.Close();
  104. if(linkmanid==client.ChiefLinkmanID) cb_chief.Checked = true;
  105. //填充联系人信息
  106. dr = cm.GetLinkmanByID(linkmanid.ToString());
  107. while(dr.Read())
  108. {
  109. tb_Name.Text = dr["Name"].ToString();
  110. tb_Mobile.Text = dr["Mobile"].ToString();
  111. tb_Telephone.Text = dr["Telephone"].ToString();
  112. tb_Position.Text = dr["Position"].ToString();
  113. tb_Email.Text = dr["Email"].ToString();
  114. //填充性别
  115. if(Convert.ToBoolean(dr["gender"])==true) 
  116. {
  117. ddl_Gender.Items[0].Selected = true;
  118. ddl_Gender.Items[1].Selected = false;
  119. }
  120. else
  121. {
  122. ddl_Gender.Items[0].Selected = false;
  123. ddl_Gender.Items[1].Selected = true;
  124. }
  125. tb_Description.Text = dr["description"].ToString();
  126. tb_Address.Text = dr["address"].ToString();
  127. tb_Family.Text = dr["family"].ToString();
  128. }
  129. }
  130. #region Web Form Designer generated code
  131. override protected void OnInit(EventArgs e)
  132. {
  133. //
  134. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  135. //
  136. InitializeComponent();
  137. base.OnInit(e);
  138. }
  139. /// <summary>
  140. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  141. /// 此方法的内容。
  142. /// </summary>
  143. private void InitializeComponent()
  144. {    
  145. this.btn_OK.Click += new System.EventHandler(this.btn_OK_Click);
  146. this.btn_Del.Click += new System.EventHandler(this.btn_Del_Click);
  147. this.Load += new System.EventHandler(this.Page_Load);
  148. }
  149. #endregion
  150. private void btn_OK_Click(object sender, System.EventArgs e)
  151. {
  152. UDS.Components.CM cm = new UDS.Components.CM();
  153. UDS.Components.Linkman linkman = new UDS.Components.Linkman();
  154. linkman.ClientID = clientid;
  155. linkman.Address = tb_Address.Text;
  156. linkman.Description = tb_Description.Text;
  157. linkman.Email = tb_Email.Text;
  158. linkman.Family = tb_Family.Text;
  159. linkman.Gender = (ddl_Gender.SelectedItem.Value=="1")?true:false;
  160. linkman.Mobile = tb_Mobile.Text;
  161. linkman.Name = tb_Name.Text;
  162. linkman.Position = tb_Position.Text;
  163. linkman.Telephone = tb_Telephone.Text;
  164. linkman.ID = linkmanid;
  165. try
  166. {
  167. if(linkmanid!=0) //修改信息
  168. {
  169. if(cb_chief.Checked)
  170. {
  171. UDS.Components.ClientInfo clientinfo = cm.GetClientAllInfo(clientid);
  172. clientinfo.ChiefLinkmanID = linkman.ID;
  173. cm.UpdateClient(clientinfo);
  174. }
  175. else
  176. {
  177. UDS.Components.ClientInfo clientinfo = cm.GetClientAllInfo(clientid);
  178. clientinfo.ChiefLinkmanID = 0;
  179. cm.UpdateClient(clientinfo);
  180. }
  181. cm.UpdateLinkman(linkman);
  182. }
  183. else //添加联系人
  184. {
  185. //如果选择了客户则添加联系人并且修改该客户的主要联系人
  186. if(clientid!=0)
  187. {
  188. linkman.ID = cm.AddLinkman(linkman);
  189. if(cb_chief.Checked)
  190. {
  191. UDS.Components.ClientInfo clientinfo = cm.GetClientAllInfo(clientid);
  192. clientinfo.ChiefLinkmanID = linkman.ID;
  193. cm.UpdateClient(clientinfo);
  194. }
  195. Response.Write("<script>if(opener!=null) opener.location.href=opener.location.href;</script>");
  196. }
  197. else//如果没有选择客户则联系人保存为临时状态即id=0
  198. {
  199. string strlinkmanid = cm.AddLinkman(linkman).ToString();
  200. Session["tmplinkmanid"] += strlinkmanid + ",";
  201. if(cb_chief.Checked) Session["tmpchief"] = strlinkmanid;
  202. Response.Write("<script>if(opener!=null) opener.location.href=opener.location.href;</script>");
  203. }
  204. Response.Write("<script>window.close();</script>");
  205. }
  206. }
  207. catch(Exception ex)
  208. {
  209. UDS.Components.Error.Log(ex.Message);
  210. Server.Transfer("../Error.aspx");
  211. }
  212. }
  213. private void btn_Del_Click(object sender, System.EventArgs e)
  214. {
  215. UDS.Components.CM cm = new UDS.Components.CM();
  216. UDS.Components.Linkman linkman = new UDS.Components.Linkman();
  217. linkman.ID = linkmanid;
  218. if(cm.DelLinkman(linkman))
  219. {
  220. Response.Write("<script>if(opener!=null) opener.location.href=opener.location.href;alert('删除成功!');window.close();</script>");
  221. }
  222. }
  223. }
  224. }