Client.aspx.cs
上传用户:jdb8708888
上传日期:2013-05-29
资源大小:19971k
文件大小:28k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

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.IO;
  11. using System.Web.UI.WebControls;
  12. using System.Web.UI.HtmlControls;
  13. using UDS.Components;
  14. namespace UDS.SubModule.CM
  15. {
  16. /// <summary>
  17. /// Clinet 的摘要说明。
  18. /// </summary>
  19. public class Client : System.Web.UI.Page
  20. {
  21. #region 声明
  22. protected System.Web.UI.WebControls.LinkButton LinkButton1;
  23. protected System.Web.UI.WebControls.TextBox tbx_introduce;
  24. protected System.Web.UI.WebControls.Panel pnl_Client;
  25. protected System.Web.UI.HtmlControls.HtmlInputFile File1;
  26. protected System.Web.UI.WebControls.Repeater rpt_Attachment;
  27. protected System.Web.UI.WebControls.Literal ltl_ID;
  28. protected System.Web.UI.WebControls.TextBox tbx_Birthday;
  29. protected System.Web.UI.WebControls.TextBox tbx_ShortName;
  30. protected System.Web.UI.WebControls.TextBox tbx_Name;
  31. protected System.Web.UI.WebControls.CheckBox cbx_zhongduan;
  32. protected System.Web.UI.WebControls.CheckBox cbx_qudao;
  33. protected System.Web.UI.WebControls.CheckBox cbx_shehui;
  34. protected System.Web.UI.WebControls.CheckBox cbx_meiti;
  35. protected System.Web.UI.WebControls.Label lbl_position;
  36. protected System.Web.UI.WebControls.Label lbl_chieftel;
  37. protected System.Web.UI.WebControls.TextBox tbx_UpdateTime;
  38. protected System.Web.UI.WebControls.Literal ltl_AddManName;
  39. protected System.Web.UI.WebControls.Literal ltl_addmantel;
  40. protected System.Web.UI.WebControls.TextBox tbx_affiliatedarea;
  41. protected System.Web.UI.WebControls.TextBox tbx_URL;
  42. protected System.Web.UI.WebControls.TextBox tbx_zip;
  43. protected System.Web.UI.WebControls.TextBox tbx_address;
  44. protected System.Web.UI.WebControls.CheckBox cbx_realestate;
  45. protected System.Web.UI.WebControls.CheckBox cbx_IT;
  46. protected System.Web.UI.WebControls.CheckBox cbx_business;
  47. protected System.Web.UI.WebControls.CheckBox cbx_telecom;
  48. protected System.Web.UI.WebControls.CheckBox cbx_post;
  49. protected System.Web.UI.WebControls.CheckBox cbx_consultation;
  50. protected System.Web.UI.WebControls.CheckBox cbx_travel;
  51. protected System.Web.UI.WebControls.CheckBox cbx_bus;
  52. protected System.Web.UI.WebControls.CheckBox cbx_stock;
  53. protected System.Web.UI.WebControls.CheckBox cbx_insurance;
  54. protected System.Web.UI.WebControls.CheckBox cbx_tax;
  55. protected System.Web.UI.WebControls.CheckBox cbx_make;
  56. protected System.Web.UI.WebControls.CheckBox cbx_electric;
  57. protected System.Web.UI.WebControls.CheckBox cbx_clothe;
  58. protected System.Web.UI.WebControls.CheckBox cbx_food;
  59. protected System.Web.UI.WebControls.CheckBox cbx_medicine;
  60. protected System.Web.UI.WebControls.CheckBox cbx_mechanism;
  61. protected System.Web.UI.WebControls.CheckBox cbx_auto;
  62. protected System.Web.UI.WebControls.TextBox tbx_staffnumber;
  63. protected System.Web.UI.WebControls.TextBox tbx_money;
  64. protected System.Web.UI.WebControls.TextBox tbx_operation;
  65. protected System.Web.UI.WebControls.TextBox tbx_IT;
  66. protected System.Web.UI.WebControls.TextBox tbx_pcnumber;
  67. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
  68. protected System.Web.UI.WebControls.CheckBox cbx_LAN;
  69. protected System.Web.UI.WebControls.CheckBox cbx_WAN;
  70. protected System.Web.UI.WebControls.CheckBox cbx_internet;
  71. protected System.Web.UI.WebControls.TextBox tbx_ITStaffs;
  72. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
  73. protected System.Web.UI.WebControls.TextBox tbx_ITdepartment;
  74. protected System.Web.UI.WebControls.TextBox tbx_principal;
  75. protected System.Web.UI.WebControls.TextBox tbx_system;
  76. protected System.Web.UI.WebControls.CheckBox cbx_sellman;
  77. protected System.Web.UI.WebControls.CheckBox cbx_just;
  78. protected System.Web.UI.WebControls.CheckBox cbx_introduce;
  79. protected System.Web.UI.WebControls.CheckBox cbx_customer;
  80. protected System.Web.UI.WebControls.CheckBox cbx_Email;
  81. protected System.Web.UI.WebControls.CheckBox cbx_media;
  82. protected System.Web.UI.WebControls.CheckBox cbx_Web;
  83. protected System.Web.UI.WebControls.CheckBox cbx_proseminar;
  84. protected System.Web.UI.WebControls.CheckBox cbx_exhibition;
  85. protected System.Web.UI.WebControls.CheckBox cbx_EMS;
  86. protected System.Web.UI.WebControls.Panel penal;
  87. protected System.Web.UI.WebControls.Button btn_OK;
  88. protected System.Web.UI.WebControls.CustomValidator CustomValidator1;
  89. protected System.Web.UI.WebControls.CheckBox cbx_market;
  90. protected System.Web.UI.WebControls.CheckBox cbx_foreign;
  91. protected System.Web.UI.WebControls.CheckBox cbx_private;
  92. protected System.Web.UI.WebControls.CheckBox cbx_stateowned;
  93. protected System.Web.UI.WebControls.CheckBox cbx_government;
  94. protected System.Web.UI.WebControls.Button btn_AddContact;
  95. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
  96. protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
  97. protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
  98. protected System.Web.UI.WebControls.DropDownList ddl_AddMan;
  99. protected System.Web.UI.WebControls.Panel pnl_Leader;
  100. protected System.Web.UI.WebControls.Button btn_LookTel;
  101. protected System.Web.UI.WebControls.Button btn_ChangeAddMan;
  102. protected System.Web.UI.WebControls.Panel pnl_MyCustom;
  103. protected System.Web.UI.WebControls.Panel pnl_Leader1;
  104. protected System.Web.UI.WebControls.Button btn_LookContact;
  105. protected System.Web.UI.WebControls.Label lbl_Message;
  106. #endregion
  107. protected System.Web.UI.WebControls.HyperLink hlk_Chiefman;
  108. protected int clientid;
  109. private void Page_Load(object sender, System.EventArgs e)
  110. {
  111. UDS.Components.CM cm = new UDS.Components.CM();
  112. if(!Page.IsPostBack)
  113. {
  114. tbx_UpdateTime.Text = DateTime.Now.ToShortDateString();
  115. //得到添加人的信息
  116.                 UDS.Components.Staff staff = new UDS.Components.Staff();
  117. #region 显示客户原有信息
  118. UDS.Components.ClientInfo client = cm.GetClientAllInfo((Request.QueryString["ClientID"]==null)?0:Int32.Parse(Request.QueryString["ClientID"].ToString()));
  119. ViewState["ClientID"] = client.ID;
  120. clientid = client.ID;
  121. /* 权限判断
  122.  * 如果是上级则出现下拉菜单,并可重新指定客户经理
  123.  * 其它则无下拉菜单
  124.  */
  125. if(Session["cm_permission"].ToString()=="leader")
  126. {
  127. //绑定下拉列表
  128. pnl_Leader.Visible = true;
  129. ltl_AddManName.Visible = ltl_addmantel.Visible = false;
  130. //不出现修改按钮
  131. pnl_MyCustom.Visible = false;
  132. pnl_Leader1.Visible = true;
  133. BindAddManList();
  134. //添加人默认选中
  135. ddl_AddMan.Items.FindByValue(client.AddManID.ToString()).Selected = true;
  136. }
  137. else
  138. {
  139. pnl_Leader.Visible = false;
  140. ltl_AddManName.Visible = ltl_addmantel.Visible = true;
  141. SqlDataReader dr_staff = null;
  142. if(client.ID!=0)
  143. {
  144. dr_staff = staff.GetStaffInfo(client.AddManID);
  145. while(dr_staff.Read())
  146. {
  147. ltl_AddManName.Text = dr_staff["realname"].ToString();
  148. ltl_addmantel.Text = dr_staff["Mobile"].ToString();
  149. }
  150. }
  151. else
  152. {
  153. dr_staff = staff.GetStaffInfo(Int32.Parse(Request.Cookies["UserID"].Value));
  154. while(dr_staff.Read())
  155. {
  156. ltl_AddManName.Text = dr_staff["realname"].ToString();
  157. ltl_addmantel.Text = dr_staff["Mobile"].ToString();
  158. }
  159. }
  160. dr_staff.Close();
  161. }
  162. ltl_ID.Text = (client.ID.ToString()=="0")?"":client.ID.ToString();
  163. tbx_ShortName.Text = client.ClientShortName;
  164. tbx_Name.Text = client.ClientName;
  165. if(clientid!=0)
  166. tbx_Birthday.Text = client.Birthday.ToShortDateString();
  167. else
  168. tbx_Birthday.Text = DateTime.Now.ToShortDateString();
  169. if(client.ClientType.IndexOf(ClientType.terminal.ToString())>=0) cbx_zhongduan.Checked = true;
  170. if(client.ClientType.IndexOf(ClientType.channal.ToString())>=0) cbx_qudao.Checked = true;
  171. if(client.ClientType.IndexOf(ClientType.social.ToString())>=0) cbx_shehui.Checked = true;
  172. if(client.ClientType.IndexOf(ClientType.media.ToString())>=0) cbx_meiti.Checked = true;
  173. //得到主要联系人的信息
  174. SqlDataReader dr_chief = cm.GetLinkmanByID(client.ChiefLinkmanID.ToString());
  175. while(dr_chief.Read())
  176. {
  177. if(Session["cm_permission"].ToString()=="administrator")
  178. {
  179. hlk_Chiefman.Text = dr_chief["name"].ToString();
  180. hlk_Chiefman.NavigateUrl = "Linkman.aspx?LinkmanID=" + dr_chief["id"].ToString();
  181. hlk_Chiefman.Target = "_blank";
  182. }
  183. else
  184. {
  185. hlk_Chiefman.Text = dr_chief["name"].ToString();
  186. }
  187. lbl_position.Text = dr_chief["position"].ToString();
  188. lbl_chieftel.Text = dr_chief["telephone"].ToString();
  189. }
  190. dr_chief.Close();
  191. tbx_affiliatedarea.Text = client.Affiliatedarea;
  192. tbx_URL.Text = client.URL;
  193. tbx_zip.Text = client.ZIP;
  194. tbx_address.Text = client.Address;
  195. if(client.CompanyProperty.IndexOf(EnterpriseType.government.ToString())>=0) cbx_government.Checked = true;
  196. if(client.CompanyProperty.IndexOf(EnterpriseType.contry.ToString())>=0) cbx_stateowned.Checked = true;
  197. if(client.CompanyProperty.IndexOf(EnterpriseType.privateowned.ToString())>=0) cbx_private.Checked = true;
  198. if(client.CompanyProperty.IndexOf(EnterpriseType.oversea.ToString())>=0) cbx_foreign.Checked = true;
  199. if(client.CompanyProperty.IndexOf(EnterpriseType.stock.ToString())>=0) cbx_market.Checked = true;
  200. if(client.ClientTrade.IndexOf(ClientTrade.realty.ToString())>=0) cbx_realestate.Checked = true;
  201. if(client.ClientTrade.IndexOf(ClientTrade.IT.ToString())>=0) cbx_IT.Checked = true;
  202. if(client.ClientTrade.IndexOf(ClientTrade.business.ToString())>=0) cbx_business.Checked = true;
  203. if(client.ClientTrade.IndexOf(ClientTrade.telecom.ToString())>=0) cbx_telecom.Checked = true;
  204. if(client.ClientTrade.IndexOf(ClientTrade.post.ToString())>=0) cbx_post.Checked = true;
  205. if(client.ClientTrade.IndexOf(ClientTrade.refer.ToString())>=0) cbx_consultation.Checked = true;
  206. if(client.ClientTrade.IndexOf(ClientTrade.travel.ToString())>=0) cbx_travel.Checked = true;
  207. if(client.ClientTrade.IndexOf(ClientTrade.bus.ToString())>=0) cbx_bus.Checked = true;
  208. if(client.ClientTrade.IndexOf(ClientTrade.stock.ToString())>=0) cbx_stock.Checked = true;
  209. if(client.ClientTrade.IndexOf(ClientTrade.insurance.ToString())>=0) cbx_insurance.Checked = true;
  210. if(client.ClientTrade.IndexOf(ClientTrade.tax.ToString())>=0) cbx_tax.Checked = true;
  211. if(client.ClientTrade.IndexOf(ClientTrade.make.ToString())>=0) cbx_make.Checked = true;
  212. if(client.ClientTrade.IndexOf(ClientTrade.he.ToString())>=0) cbx_electric.Checked = true;
  213. if(client.ClientTrade.IndexOf(ClientTrade.clothe.ToString())>=0) cbx_clothe.Checked = true;
  214. if(client.ClientTrade.IndexOf(ClientTrade.food.ToString())>=0) cbx_food.Checked = true;
  215. if(client.ClientTrade.IndexOf(ClientTrade.medicine.ToString())>=0) cbx_medicine.Checked = true;
  216. if(client.ClientTrade.IndexOf(ClientTrade.mechanism.ToString())>=0) cbx_mechanism.Checked = true;
  217. if(client.ClientTrade.IndexOf(ClientTrade.auto.ToString())>=0) cbx_auto.Checked = true;
  218. tbx_staffnumber.Text = client.CompanySize;
  219. tbx_money.Text = client.Money;
  220. tbx_operation.Text = client.Operation;
  221. tbx_introduce.Text = client.Introduce;
  222. tbx_IT.Text = client.ITGrade;
  223. tbx_pcnumber.Text = client.PCNumber.ToString();
  224. if(client.Net.IndexOf(ClientNet.LAN.ToString())>=0) cbx_LAN.Checked = true;
  225. if(client.Net.IndexOf(ClientNet.WAN.ToString())>=0) cbx_WAN.Checked = true;
  226. if(client.Net.IndexOf(ClientNet.INTERNET.ToString())>=0) cbx_internet.Checked = true;
  227. tbx_ITStaffs.Text = client.ITStaffs.ToString();
  228. tbx_ITdepartment.Text = client.ITDepartment;
  229. tbx_principal.Text = client.Principal;
  230. tbx_system.Text = client.System;
  231. if(client.ClientSource.IndexOf(ClientSource.sellman.ToString())>=0) cbx_sellman.Checked = true;
  232. if(client.ClientSource.IndexOf(ClientSource.familiar.ToString())>=0) cbx_just.Checked = true;
  233. if(client.ClientSource.IndexOf(ClientSource.introduce.ToString())>=0) cbx_introduce.Checked = true;
  234. if(client.ClientSource.IndexOf(ClientSource.client.ToString())>=0) cbx_customer.Checked = true;
  235. if(client.ClientInitiative.IndexOf(ClientInitiative.media.ToString())>=0) cbx_media.Checked = true;
  236. if(client.ClientInitiative.IndexOf(ClientInitiative.searchweb.ToString())>=0) cbx_Web.Checked = true;
  237. if(client.ClientInitiative.IndexOf(ClientInitiative.proseminar.ToString())>=0) cbx_proseminar.Checked = true;
  238. if(client.ClientInitiative.IndexOf(ClientInitiative.exhibition.ToString())>=0) cbx_exhibition.Checked = true;
  239. if(client.ClientInitiative.IndexOf(ClientInitiative.post.ToString())>=0) cbx_EMS.Checked = true;
  240. if(client.ClientInitiative.IndexOf(ClientInitiative.email.ToString())>=0) cbx_Email.Checked = true;
  241. #endregion
  242. if(clientid==0)
  243. {
  244. btn_OK.Text = "添加";
  245. CustomValidator1.Enabled = true;
  246. }
  247. else
  248. {
  249. btn_OK.Text = "修改";
  250. CustomValidator1.Enabled = false;
  251. }
  252. penal.Visible = cbx_customer.Checked;
  253. }
  254. else
  255. {
  256. clientid = Int32.Parse(ViewState["ClientID"].ToString());
  257. //显示联系人
  258. string tmplinkmanid1 = (Session["tmplinkmanid"]==null)?"":Session["tmplinkmanid"].ToString();
  259. foreach(string linkmanid in tmplinkmanid1.Split(','))
  260. {
  261. if(linkmanid.Trim()!="")
  262. {
  263. UDS.Components.Linkman linkman = new UDS.Components.Linkman();
  264. UDS.Components.CM cm1 = new UDS.Components.CM();
  265. linkman = cm1.GetLinkmanStructByID(linkmanid);
  266. if(Session["cm_permission"].ToString()=="administrator")
  267. {
  268. hlk_Chiefman.Text = linkman.Name;
  269. hlk_Chiefman.NavigateUrl = "Linkman.aspx?LinkmanID=" + linkman.ID;
  270. hlk_Chiefman.Target = "_blank";
  271. }
  272. else
  273. {
  274. hlk_Chiefman.Text = linkman.Name;;
  275. }
  276. lbl_position.Text = linkman.Position;
  277. lbl_chieftel.Text = linkman.Telephone;
  278. }
  279. }
  280. }
  281. if(clientid!=0)
  282. {
  283. rpt_Attachment.DataSource = cm.GetAttachmentByClientID(clientid);
  284. rpt_Attachment.DataBind();
  285. }
  286. if(clientid==0) 
  287. btn_AddContact.Visible = false;
  288. else
  289. btn_AddContact.Visible = true;
  290. }
  291. #region Web Form Designer generated code
  292. override protected void OnInit(EventArgs e)
  293. {
  294. //
  295. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  296. //
  297. InitializeComponent();
  298. base.OnInit(e);
  299. }
  300. /// <summary>
  301. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  302. /// 此方法的内容。
  303. /// </summary>
  304. private void InitializeComponent()
  305. {    
  306. this.CustomValidator1.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.CustomValidator1_ServerValidate);
  307. this.tbx_ShortName.TextChanged += new System.EventHandler(this.tbx_ShortName_TextChanged);
  308. this.btn_LookTel.Click += new System.EventHandler(this.btn_LookTel_Click);
  309. this.btn_ChangeAddMan.Click += new System.EventHandler(this.btn_ChangeAddMan_Click);
  310. this.cbx_customer.CheckedChanged += new System.EventHandler(this.cbx_customer_CheckedChanged);
  311. this.cbx_customer.PreRender += new System.EventHandler(this.cbx_customer_PreRender);
  312. this.btn_OK.Click += new System.EventHandler(this.btn_OK_Click);
  313. this.btn_AddContact.Click += new System.EventHandler(this.btn_AddContact_Click);
  314. this.btn_LookContact.Click += new System.EventHandler(this.btn_LookContact_Click);
  315. this.Load += new System.EventHandler(this.Page_Load);
  316. }
  317. #endregion
  318. //绑定添加人下拉菜单
  319. private void BindAddManList()
  320. {
  321. UDS.Components.Staff staff = new UDS.Components.Staff();
  322. ddl_AddMan.DataSource = staff.GetStaffFromPosition(Request.Cookies["Username"].Value,2,3);
  323. ddl_AddMan.DataTextField = "realname";
  324. ddl_AddMan.DataValueField = "staff_id";
  325. ddl_AddMan.DataBind();
  326. SqlDataReader dr_staff = staff.GetStaffInfo(long.Parse(Request.Cookies["UserID"].Value));
  327. string myrealname = "";
  328. while(dr_staff.Read())
  329. {
  330. myrealname = dr_staff["realname"].ToString();
  331. }
  332. dr_staff.Close();
  333. ddl_AddMan.Items.Add(new ListItem(myrealname,Request.Cookies["UserID"].Value));
  334. }
  335. private void btn_OK_Click(object sender, System.EventArgs e)
  336. {
  337. UDS.Components.CM cm = new UDS.Components.CM();
  338. UDS.Components.ClientInfo client = cm.GetClientAllInfo(clientid);
  339. if(Page.IsValid)
  340. {
  341. #region 填充client结构
  342. client.ClientShortName = tbx_ShortName.Text;
  343. client.ClientName = tbx_Name.Text;
  344. client.AddManID = Int32.Parse(Request.Cookies["UserID"].Value);
  345. client.UpdateTime = DateTime.Parse(tbx_UpdateTime.Text);
  346. client.Affiliatedarea = tbx_affiliatedarea.Text;
  347. client.URL = tbx_URL.Text;
  348. client.ZIP = tbx_zip.Text;
  349. client.Address = tbx_address.Text;
  350. client.Type = "";
  351. if(cbx_zhongduan.Checked)
  352. {
  353. client.Type += ClientType.terminal.ToString() + ",";
  354. }
  355. if(cbx_qudao.Checked)
  356. {
  357. client.Type += ClientType.channal.ToString() + ",";
  358. }
  359. if(cbx_shehui.Checked)
  360. {
  361. client.Type += ClientType.social.ToString() + ",";
  362. }
  363. if(cbx_meiti.Checked)
  364. {
  365. client.Type += ClientType.media.ToString() + ",";
  366. }
  367. client.EnterpriseType = "";
  368. if(cbx_government.Checked)
  369. {
  370. client.EnterpriseType += EnterpriseType.government.ToString() + ",";
  371. }
  372. if(cbx_stateowned.Checked)
  373. {
  374. client.EnterpriseType += EnterpriseType.contry.ToString() + ",";
  375. }
  376. if(cbx_private.Checked)
  377. {
  378. client.EnterpriseType += EnterpriseType.privateowned.ToString() + ",";
  379. }
  380. if(cbx_foreign.Checked)
  381. {
  382. client.EnterpriseType += EnterpriseType.oversea.ToString() + ",";
  383. }
  384. if(cbx_market.Checked) client.EnterpriseType += EnterpriseType.stock.ToString() + ",";
  385. client.Calling = "";
  386. if(cbx_realestate.Checked) client.Calling += ClientTrade.realty.ToString() + ",";
  387. if(cbx_IT.Checked) client.Calling += ClientTrade.IT.ToString() + ",";
  388. if(cbx_business.Checked) client.Calling += ClientTrade.business.ToString() + ",";
  389. if(cbx_telecom.Checked) client.Calling += ClientTrade.telecom.ToString() + ",";
  390. if(cbx_post.Checked) client.Calling += ClientTrade.post.ToString() + ",";
  391. if(cbx_consultation.Checked) client.Calling += ClientTrade.refer.ToString() + ",";
  392. if(cbx_travel.Checked) client.Calling += ClientTrade.travel.ToString() + ",";
  393. if(cbx_bus.Checked) client.Calling += ClientTrade.bus.ToString() + ",";
  394. if(cbx_stock.Checked) client.Calling += ClientTrade.stock.ToString() + ",";
  395. if(cbx_insurance.Checked) client.Calling += ClientTrade.insurance.ToString() + ",";
  396. if(cbx_tax.Checked) client.Calling += ClientTrade.tax.ToString() + ",";
  397. if(cbx_make.Checked) client.Calling += ClientTrade.make.ToString() + ",";
  398. if(cbx_electric.Checked) client.Calling += ClientTrade.he.ToString() + ",";
  399. if(cbx_clothe.Checked) client.Calling += ClientTrade.clothe.ToString() + ",";
  400. if(cbx_food.Checked) client.Calling += ClientTrade.food.ToString() + ",";
  401. if(cbx_medicine.Checked) client.Calling += ClientTrade.medicine.ToString() + ",";
  402. if(cbx_mechanism.Checked) client.Calling += ClientTrade.mechanism.ToString() + ",";
  403. if(cbx_auto.Checked) client.Calling += ClientTrade.auto.ToString() + ",";
  404. client.CompanySize = tbx_staffnumber.Text;
  405. client.Money = tbx_money.Text;
  406. client.Operation = tbx_operation.Text;
  407. client.Introduce = tbx_introduce.Text;
  408. client.ITGrade = tbx_IT.Text;
  409. client.PCNumber = Int32.Parse(tbx_pcnumber.Text);
  410. client.Net = "";
  411. if(cbx_LAN.Checked) client.Net += ClientNet.LAN.ToString() + ",";
  412. if(cbx_WAN.Checked)  client.Net += ClientNet.WAN.ToString() + ",";
  413. if(cbx_internet.Checked) client.Net += ClientNet.INTERNET.ToString() + ",";
  414. client.ITStaffs = Int32.Parse(tbx_ITStaffs.Text);
  415. client.ITDepartment = tbx_ITdepartment.Text;
  416. client.Principal = tbx_principal.Text;
  417. client.System = tbx_system.Text;
  418. client.ClientSource = "";
  419. if(cbx_sellman.Checked) client.ClientSource += ClientSource.sellman + ",";
  420. if(cbx_just.Checked)  client.ClientSource += ClientSource.familiar + ",";
  421. if(cbx_introduce.Checked)  client.ClientSource += ClientSource.introduce + ",";
  422. if(cbx_customer.Checked)  client.ClientSource += ClientSource.client + ",";
  423. client.ClientInitiative = "";
  424. if(cbx_media.Checked) client.ClientInitiative += ClientInitiative.media + ",";
  425. if(cbx_Web.Checked) client.ClientInitiative += ClientInitiative.searchweb + ",";
  426. if(cbx_proseminar.Checked) client.ClientInitiative += ClientInitiative.proseminar + ",";
  427. if(cbx_exhibition.Checked) client.ClientInitiative += ClientInitiative.exhibition + ",";
  428. if(cbx_EMS.Checked) client.ClientInitiative += ClientInitiative.post + ",";
  429. if(cbx_Email.Checked) client.ClientInitiative += ClientInitiative.email + ",";
  430. #endregion
  431. client.ChiefLinkmanID = (Session["tmpchief"]==null)?0:Int32.Parse(Session["tmpchief"].ToString());
  432. //根据clientid==0判断是update还是add
  433. try
  434. {
  435. if(clientid!=0) //修改
  436. {
  437. SqlDataReader dr_chief = cm.GetLinkmanByID(client.ChiefLinkmanID.ToString());
  438. while(dr_chief.Read())
  439. {
  440. if(Session["cm_permission"].ToString()=="administrator")
  441. {
  442. hlk_Chiefman.Text = dr_chief["name"].ToString();
  443. hlk_Chiefman.NavigateUrl = "Linkman.aspx?LinkmanID=" + dr_chief["id"].ToString();
  444. hlk_Chiefman.Target = "_blank";
  445. }
  446. else
  447. {
  448. hlk_Chiefman.Text = dr_chief["name"].ToString();
  449. }
  450. }
  451. dr_chief.Close();
  452. cm.UpdateClient(client);
  453. Response.Write("<script>alert('修改成功!');opener.location.href=opener.location.href;close();</script>");
  454. }
  455. else //新增
  456. {
  457. CustomValidator1.Enabled = true;
  458. CustomValidator1.Validate();
  459. string tmplinkmanid = (Session["tmplinkmanid"]==null)?"":Session["tmplinkmanid"].ToString();
  460. client.Birthday = DateTime.Now;
  461. client.ID = cm.AddClinet(client);
  462. ViewState["ClientID"] = client.ID.ToString();
  463. ltl_ID.Text = client.ID.ToString();
  464. clientid = client.ID;
  465. SqlDataReader dr_chief = cm.GetLinkmanByID(client.ChiefLinkmanID.ToString());
  466. while(dr_chief.Read())
  467. {
  468. if(Session["cm_permission"].ToString()=="administrator")
  469. {
  470. hlk_Chiefman.Text = dr_chief["name"].ToString();
  471. hlk_Chiefman.NavigateUrl = "Linkman.aspx?LinkmanID=" + dr_chief["id"].ToString();
  472. hlk_Chiefman.Target = "_blank";
  473. }
  474. else
  475. {
  476. hlk_Chiefman.Text = dr_chief["name"].ToString();
  477. }
  478. lbl_position.Text = dr_chief["Position"].ToString();
  479. lbl_chieftel.Text = dr_chief["Telephone"].ToString();
  480. }
  481. dr_chief.Close();
  482. //分析session中的tmplinkmanid使他们得到clientid
  483. foreach(string linkmanid in tmplinkmanid.Split(','))
  484. {
  485. if(linkmanid.Trim()!="")
  486. {
  487. UDS.Components.Linkman linkman = new UDS.Components.Linkman();
  488. UDS.Components.CM cm1 = new UDS.Components.CM();
  489. linkman = cm1.GetLinkmanStructByID(linkmanid);
  490. linkman.ClientID = client.ID;
  491. linkman.ID = Int32.Parse(linkmanid);
  492. cm.UpdateLinkman(linkman);
  493. }
  494. }
  495. //清空Session
  496. Session.Remove("tmpchief");
  497. Session.Remove("tmplinkmanid");
  498. Response.Write("<script>alert('添加成功!');opener.location.href=opener.location.href;close();</script>");
  499. }
  500. }
  501. catch(Exception ex)
  502. {
  503. UDS.Components.Error.Log(ex.Message);
  504. Server.Transfer("../Error.aspx");
  505. }
  506. //Response.Write("<script>if(opener!=null) opener.location.reload();</script>");
  507. //刷新页面显示
  508. if(clientid==0) 
  509. btn_AddContact.Visible = false;
  510. else
  511. btn_AddContact.Visible = true;
  512. penal.Visible = cbx_customer.Checked;
  513. //上传附件
  514. UploadAtt();
  515. //显示附件
  516. if(clientid!=0)
  517. {
  518. rpt_Attachment.DataSource = cm.GetAttachmentByClientID(clientid);
  519. rpt_Attachment.DataBind();
  520. }
  521. }
  522. }
  523. /// <summary>
  524. /// 判断是否有同名客户
  525. /// </summary>
  526. /// <param name="newclientname"></param>
  527. /// <returns></returns>
  528. private bool SameNameClient(string newclientname)
  529. {
  530. UDS.Components.CM cm = new UDS.Components.CM();
  531. SqlDataReader dr = cm.GetClientInfoByName(newclientname);
  532. DataTable dt = UDS.Components.Tools.ConvertDataReaderToDataTable(dr);
  533. if(dt.Rows.Count==0)
  534. return(false);
  535. else
  536. return(true);
  537. }
  538. /// <summary>
  539. /// 上载文件
  540. /// </summary>
  541. private void UploadAtt()
  542. {
  543. HtmlForm FrmCompose   = (HtmlForm)this.Page.FindControl("Client");
  544. UDS.Components.CM cm = new UDS.Components.CM();
  545. string FileName = "";
  546. string Extension = "";
  547. string SavedName = "";
  548. try
  549. {
  550. if(Directory.Exists(Server.MapPath(".")+"\Attachment"))
  551. {
  552. for (int i=0;i<FrmCompose.Controls.Count;i++)
  553. {
  554. if(FrmCompose.Controls [i].GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputFile")
  555. {
  556. HtmlInputFile hif = ((HtmlInputFile)(FrmCompose.Controls[i]));
  557. if(hif.PostedFile.FileName.Trim()!="")
  558. {
  559. FileName = System.IO .Path.GetFileName(hif.PostedFile.FileName);
  560. Extension = System.IO.Path.GetExtension(hif.PostedFile.FileName);
  561. SavedName = cm.InsertFile(FileName,"client",clientid,Extension).ToString();
  562. hif.PostedFile.SaveAs(Server.MapPath(".")+"\Attachment\"+SavedName+Extension );
  563. }
  564. hif=null;
  565. }
  566. }
  567. }
  568. else
  569. {   
  570. Directory.CreateDirectory(Server.MapPath(".")+"\Attachment");
  571. UploadAtt();
  572. }
  573. }
  574. catch(Exception ioex)
  575. {
  576. UDS.Components.Error.Log(ioex.ToString());
  577. Server.Transfer("../Error.aspx");
  578. }
  579. }
  580. private void cbx_customer_PreRender(object sender, System.EventArgs e)
  581. {
  582. //Response.Write("<script>if(document.Client.cbx_customer.checked) document.Client.penal.style.display='';else document.Client.penal.style.display='none';</script>");
  583. }
  584. private void cbx_customer_CheckedChanged(object sender, System.EventArgs e)
  585. {
  586. penal.Visible = ((CheckBox)sender).Checked;
  587. }
  588. private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
  589. {
  590. args.IsValid = !SameNameClient(args.Value);
  591. }
  592. private void tbx_ShortName_TextChanged(object sender, System.EventArgs e)
  593. {
  594. }
  595. private void btn_AddContact_Click(object sender, System.EventArgs e)
  596. {
  597. Response.Write("<script>window.open('ClientContact_thisWeek.aspx?ClientID=" + clientid+"','_blank','');</script>");
  598. }
  599. private void btn_LookTel_Click(object sender, System.EventArgs e)
  600. {
  601. ltl_addmantel.Visible = true;
  602. UDS.Components.Staff staff = new UDS.Components.Staff();
  603. SqlDataReader dr_staff = staff.GetStaffInfo(Int32.Parse(ddl_AddMan.SelectedItem.Value));
  604. while(dr_staff.Read())
  605. {
  606. ltl_addmantel.Text = dr_staff["Mobile"].ToString();
  607. }
  608. dr_staff.Close();
  609. }
  610. private void btn_ChangeAddMan_Click(object sender, System.EventArgs e)
  611. {
  612. UDS.Components.CM cm = new UDS.Components.CM();
  613. UDS.Components.ClientInfo client = cm.GetClientAllInfo(clientid);
  614. if(Page.IsValid)
  615. {
  616. client.AddManID = Int32.Parse(ddl_AddMan.SelectedItem.Value);
  617. cm.UpdateClient(client);
  618. //判断权限
  619. if(ddl_AddMan.SelectedItem.Value==Request.Cookies["UserID"].Value)
  620. {
  621. Session["cm_permission"] = "administrator";
  622. }
  623. else
  624. Session["cm_permission"] = "leader";
  625. Response.Write("<script>alert('修改成功!');opener.location.href='ClientListView.aspx';close();</script>");
  626. }
  627. }
  628. private void btn_LookContact_Click(object sender, System.EventArgs e)
  629. {
  630. Response.Write("<script>window.open('ClientHistoryContact.aspx?ClientID=" + clientid+"','_blank','');</script>");
  631. }
  632. }
  633. }