UU跑腿标准版

customermodify.aspx.cs 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Text;
  8. using System.Data;
  9. namespace HySoft.BaseCallCenter.Web.customermanage
  10. {
  11. public partial class customermodify : System.Web.UI.Page
  12. {
  13. private int count = 2;
  14. private string eid = "0";
  15. private string fid = "2";
  16. private string table = "";
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. Response.Expires = -1;
  20. try
  21. {
  22. Model.T_Form_FormInfo model = new BLL.T_Form_FormInfo().GetModel(2);
  23. if (model != null)
  24. {
  25. count = Convert.ToInt32(model.F_ColumnCount.ToString());
  26. eid = model.F_EntityId.ToString();
  27. table = model.F_DBTableName.Trim();
  28. }
  29. }
  30. catch
  31. { }
  32. if (!IsPostBack)
  33. {
  34. if (!string.IsNullOrEmpty(Request.QueryString["customerId"]))
  35. {
  36. hiddCustomerId.Value = Request.QueryString["customerId"];
  37. Initialize(Request.QueryString["customerId"]);
  38. }
  39. InitHtml();
  40. }
  41. }
  42. private void InitHtml()
  43. {
  44. StringBuilder res = new StringBuilder();
  45. res.Append("<table class=\"form_table\" style=\"width:100%;\">");
  46. DataTable dt = new DataTable();
  47. DataTable dtdic = new DataTable();
  48. DataTable dtInfo = new DataTable();
  49. try
  50. {
  51. string customerid = "0";
  52. string value = "";
  53. if (!string.IsNullOrEmpty(Request.QueryString["customerId"]))
  54. {
  55. customerid = Request.QueryString["customerId"];
  56. //获取
  57. dt = new BLL.T_Form_EntityAttribute().GetList("F_EntityId=" + eid + " and F_IsCustomField=1 ").Tables[0];
  58. if (dt.Rows.Count > 0)
  59. {
  60. dtInfo = DBUtility.DbHelperSQL.Query("select * from " + table + " where " + dt.Rows[0]["F_DBFieldlName"].ToString().Trim() + "=" + customerid).Tables[0];
  61. }
  62. dt.Clear();
  63. }
  64. dt = new BLL.T_Form_EntityAttribute().GetList("F_EntityId=" + eid + " and F_VisibleToPlatform=1 ").Tables[0];
  65. for (int i = 0; i < dt.Rows.Count; i++)
  66. {
  67. if (i == 0)
  68. {
  69. res.Append("<tr>");
  70. }
  71. else
  72. {
  73. if (i % count == 0)
  74. {
  75. res.Append("</tr><tr>");
  76. }
  77. }
  78. res.Append("<th style='width:95px;'><span id='span_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' name='span_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "'>" + dt.Rows[i]["F_Name"].ToString().Trim() + ":</span></th>");
  79. if (dt.Rows[i]["F_IsLookup"].ToString().Trim().ToLower() == "true")
  80. {
  81. dtdic = new BLL.T_Sys_DictionaryValue().GetList("F_DictionaryFlag='" + dt.Rows[i]["F_LookupKey"].ToString().Trim() + "'").Tables[0];
  82. string listhtml = "<option value=\"\">请选择" + dt.Rows[i]["F_Name"].ToString().Trim() + "</option>";
  83. foreach (DataRow drdic in dtdic.Rows)
  84. {
  85. string check = "";
  86. if (dtInfo.Rows.Count > 0)
  87. {
  88. //dtInfo.Rows[0][dt.Rows[i]["F_DBFieldlName"].ToString().Trim()].ToString();
  89. if (dtInfo.Select(" " + dt.Rows[i]["F_DBFieldlName"].ToString().Trim() + "=" + drdic["F_DictionaryValueId"].ToString().Trim() + " ").Length > 0)
  90. {
  91. check = "selected";
  92. }
  93. }
  94. listhtml += "<option value=\"" + drdic["F_DictionaryValueId"].ToString().Trim() + "\" " + check + " >" + drdic["F_Name"].ToString().Trim() + "</option>";
  95. }
  96. res.Append("<td><select id='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' name='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' value='" + dt.Rows[i]["F_DBFieldlName"].ToString().Trim() + "' class='selectBox'>" + listhtml + "</select></td>");
  97. }
  98. else
  99. {
  100. switch (dt.Rows[i]["F_DBTypeName"].ToString().Trim().ToLower())
  101. {
  102. case "int":
  103. res.Append("<td><input type='text' id='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' name='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' value='' class='txtInput' onKeyUp=\"this.value=this.value.replace(/[^\\d]/g,'');\" /></td>");
  104. break;
  105. case "decimal":
  106. res.Append("<td><input type='text' id='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' name='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' value='' class='txtInput' onKeyUp=\"this.value=this.value.replace(/[^\\.\\d]/g,'');if(this.value.split('.').length>2){this.value=this.value.split('.')[0]+'.'+this.value.split('.')[1]}\" /></td>");
  107. break;
  108. case "datetime":
  109. res.Append("<td><input type='text' id='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' name='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' value='' onfocus=\"WdatePicker({skin:'whyGreen'})\" class='txtInput' /></td>");
  110. break;
  111. default:
  112. res.Append("<td><input type='text' id='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' name='txt_arr_" + dt.Rows[i]["F_AttributeId"].ToString().Trim() + "' value='' class='txtInput' /></td>");
  113. break;
  114. }
  115. }
  116. if (i == (dt.Rows.Count - 1))
  117. {
  118. int tdcount = 0;
  119. if ((dt.Rows.Count % count) != 0)
  120. {
  121. tdcount = count - (dt.Rows.Count % count);
  122. }
  123. for (int m = 0; m < tdcount; m++)
  124. {
  125. res.Append("<th>&nbsp;</th><td>&nbsp;</td>");
  126. }
  127. res.Append("</tr>");
  128. }
  129. }
  130. }
  131. catch
  132. { }
  133. finally
  134. {
  135. dt.Dispose();
  136. dt.Clear();
  137. }
  138. res.Append("</table>");
  139. divForm.InnerHtml = res.ToString();
  140. }
  141. private string GetFieldValue(DataRow dr,int customerid)
  142. {
  143. string value = "";
  144. try
  145. {
  146. if (dr["F_IsCustomField"].ToString().Trim().ToLower() == "true")
  147. {
  148. value = customerid.ToString();
  149. }
  150. else
  151. {
  152. if (dr["F_IsLookup"].ToString().Trim().ToLower() == "true")
  153. {
  154. if (Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()] != null)
  155. {
  156. value = Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()].ToString();
  157. }
  158. else
  159. {
  160. value = "0";
  161. }
  162. }
  163. else
  164. {
  165. switch (dr["F_DBTypeName"].ToString().Trim().ToLower())
  166. {
  167. case "int":
  168. if (Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()] != null)
  169. {
  170. value = Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()].ToString();
  171. }
  172. else
  173. {
  174. value = "0";
  175. }
  176. break;
  177. case "decimal":
  178. if (Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()] != null)
  179. {
  180. value = Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()].ToString();
  181. }
  182. else
  183. {
  184. value = "0";
  185. }
  186. break;
  187. case "datetime":
  188. if (Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()] != null)
  189. {
  190. value = "'" + Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()].ToString() + "'";
  191. }
  192. else
  193. {
  194. value = "null";
  195. }
  196. break;
  197. default:
  198. if (Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()] != null)
  199. {
  200. value = "'" + Request.Form["txt_arr_" + dr["F_AttributeId"].ToString().Trim()].ToString() + "'";
  201. }
  202. else
  203. {
  204. value = "''";
  205. }
  206. break;
  207. }
  208. }
  209. }
  210. }
  211. catch (Exception ex)
  212. {
  213. }
  214. return value;
  215. }
  216. private bool InsertForm(int customerid)
  217. {
  218. DataTable dt = new DataTable();
  219. try
  220. {
  221. StringBuilder fieldsql = new StringBuilder();
  222. StringBuilder valuesql = new StringBuilder();
  223. dt = new BLL.T_Form_EntityAttribute().GetList("F_EntityId=" + eid + " and (F_VisibleToPlatform=1 or F_IsCustomField=1) ").Tables[0];
  224. for (int i = 0; i < dt.Rows.Count; i++)
  225. {
  226. if (i == 0)
  227. {
  228. fieldsql.Append(" insert into " + dt.Rows[i]["F_DBTableName"].ToString().Trim() + " ([" + dt.Rows[i]["F_DBFieldlName"].ToString().Trim() + "]");
  229. valuesql.Append(" values ( " + GetFieldValue(dt.Rows[i], customerid));
  230. }
  231. else
  232. {
  233. fieldsql.Append(",[" + dt.Rows[i]["F_DBFieldlName"].ToString().Trim() + "]");
  234. valuesql.Append("," + GetFieldValue(dt.Rows[i], customerid));
  235. if (i == (dt.Rows.Count - 1))
  236. {
  237. fieldsql.Append(") ");
  238. valuesql.Append(") ");
  239. }
  240. }
  241. }
  242. string sql = fieldsql.ToString() + valuesql.ToString();
  243. DBUtility.DbHelperSQL.ExecuteSql(sql);
  244. }
  245. catch
  246. { }
  247. finally
  248. {
  249. dt.Dispose();
  250. dt.Clear();
  251. }
  252. return false;
  253. }
  254. protected void btnSubmit_Click(object sender, EventArgs e)
  255. {
  256. SaveInfo();
  257. }
  258. private void SaveInfo()
  259. {
  260. try
  261. {
  262. if (!string.IsNullOrWhiteSpace(Request.QueryString["actionFlag"].Trim()))
  263. {
  264. string actionFlag = Request.QueryString["actionFlag"].Trim();
  265. if (actionFlag == "add")
  266. {
  267. int b1 = new BLL.T_Cus_CustomerBase().Add(T_Cus_CustomerBase);
  268. hiddCustomerId.Value = b1.ToString();
  269. List<Model.T_Cus_ContactPerson> tcclist = new BLL.T_Cus_ContactPerson().GetModelList("F_CustomerId IS NULL or F_CustomerId<=0");
  270. foreach (Model.T_Cus_ContactPerson tcc in tcclist)
  271. {
  272. tcc.F_CustomerId = Convert.ToInt32(hiddCustomerId.Value);
  273. new BLL.T_Cus_ContactPerson().Update(tcc);
  274. }
  275. if (b1 > 0)
  276. {
  277. #region 保存扩展信息
  278. InsertForm(b1);
  279. #endregion
  280. ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('success')</script>");
  281. }
  282. else
  283. {
  284. ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('warn')</script>");
  285. }
  286. }
  287. if (actionFlag == "edit")
  288. {
  289. bool b2 = new BLL.T_Cus_CustomerBase().Update(T_Cus_CustomerBase);
  290. List<Model.T_Cus_ContactPerson> tcclist = new BLL.T_Cus_ContactPerson().GetModelList("F_CustomerId IS NULL or F_CustomerId<=0");
  291. foreach (Model.T_Cus_ContactPerson tcc in tcclist)
  292. {
  293. tcc.F_CustomerId = T_Cus_CustomerBase.F_CustomerId;
  294. new BLL.T_Cus_ContactPerson().Update(tcc);
  295. }
  296. if (b2)
  297. {
  298. ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('success')</script>");
  299. }
  300. else
  301. {
  302. ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('warn')</script>");
  303. }
  304. }
  305. }
  306. }
  307. catch
  308. {
  309. ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('error')</script>");
  310. }
  311. }
  312. #region 信息初始化
  313. private void Initialize(string id)
  314. {
  315. T_Cus_CustomerBase = new BLL.T_Cus_CustomerBase().GetModel(Convert.ToInt32(id));
  316. }
  317. #endregion
  318. #region 公共属性
  319. private Model.T_Cus_CustomerBase T_Cus_CustomerBase
  320. {
  321. get
  322. {
  323. Model.T_Cus_CustomerBase _model = new Model.T_Cus_CustomerBase();
  324. if (hiddCustomerId.Value != "" || hiddCustomerId.Value == "0")
  325. _model.F_CustomerId = Convert.ToInt32(hiddCustomerId.Value);
  326. _model.F_CustomerName = txtCustomerName.Text.Trim();
  327. _model.F_CustomerCode = txtCustomerCode.Text.Trim();
  328. if (hiddSeriveDeptId.Value != "")
  329. _model.F_ServiceDeptID = Convert.ToInt32(hiddSeriveDeptId.Value);
  330. _model.F_ServiceDept = drpServiceDept.Text;
  331. if (hiddProvinceId.Value != "")
  332. _model.F_RegionId = Convert.ToInt32(hiddProvinceId.Value);
  333. _model.F_Province = drpProvince.Text;
  334. if (hiddCityId.Value != "")
  335. _model.F_CityID = Convert.ToInt32(hiddCityId.Value);
  336. _model.F_City = drpCity.Text;
  337. if (hiddProductLineId.Value != "")
  338. _model.F_ProductLineID = Convert.ToInt32(hiddProductLineId.Value);
  339. _model.F_ProductLine = drpProductLine.Text;
  340. if (hiddCustomerNatureId.Value != "")
  341. _model.F_CustomerNatureID = Convert.ToInt32(hiddCustomerNatureId.Value);
  342. _model.F_CustomerNature = drpCustomerNature.Text;
  343. if (hiddCustomerClassId.Value != "")
  344. _model.F_CustomerClassID = Convert.ToInt32(hiddCustomerClassId.Value);
  345. _model.F_CustomerClass = drpCustomerClass.Text;
  346. if (hiddCustomerIndustryId.Value != "")
  347. _model.F_IndustryId = Convert.ToInt32(hiddCustomerIndustryId.Value);
  348. _model.F_CustomerIndustry = drpCustomerIndustry.Text;
  349. if (hiddRelationShipClassId.Value != "")
  350. _model.F_RelationShipClassID = Convert.ToInt32(hiddRelationShipClassId.Value);
  351. _model.F_RelationShipClass = drpRelationShipClass.Text;
  352. if (hiddAfterSaleNameID.Value != "")
  353. _model.F_AfterSaleNameID = Convert.ToInt32(hiddAfterSaleNameID.Value);
  354. _model.F_AfterSaleName = drpAfterSaleName.Text;
  355. //基本信息部分
  356. _model.F_Fax = txtFax.Text.Trim();
  357. _model.F_Email = txtEmail.Text.Trim();
  358. _model.F_Telephone = txtTelephone.Text.Trim();
  359. _model.F_Address = txtAddress.Text.Trim();
  360. _model.F_PostCode = txtPostCode.Text.Trim();
  361. _model.F_CurrentVersion = txtCurrentVersion.Text.Trim();
  362. if (txtSystemStartTime.Text.Trim() != "")
  363. {
  364. DateTime dt = new DateTime();
  365. if (DateTime.TryParse(txtSystemStartTime.Text.Trim(), out dt))
  366. _model.F_SystemStartTime = Convert.ToDateTime(txtSystemStartTime.Text.Trim());
  367. }
  368. if (txtQualityGuaranteeEndTime.Text.Trim() != "")
  369. {
  370. DateTime dt = new DateTime();
  371. if (DateTime.TryParse(txtSystemStartTime.Text.Trim(), out dt))
  372. _model.F_QualityGuaranteeEndTime = Convert.ToDateTime(txtQualityGuaranteeEndTime.Text.Trim());
  373. }
  374. _model.F_SystemType = txtSystemType.Text.Trim();
  375. _model.F_CustomerStatus = txtCustomerStatus.Text.Trim();
  376. if (txtDeviceCount.Text.Trim() != "")
  377. {
  378. int count = 0;
  379. if (int.TryParse(txtDeviceCount.Text.Trim(), out count))
  380. _model.F_DeviceCount = Convert.ToInt32(txtDeviceCount.Text.Trim());
  381. }
  382. //备注信息部分
  383. _model.F_TrackInfo = txtTrackInfo.Value;
  384. _model.F_Notes = txtNotes.Value;
  385. //扩展信息部分
  386. //todo...
  387. return _model;
  388. }
  389. set
  390. {
  391. if (value != null)
  392. {
  393. hiddCustomerId.Value = value.F_CustomerId.ToString();
  394. txtCustomerName.Text = value.F_CustomerName;
  395. txtCustomerCode.Text = value.F_CustomerCode;
  396. hiddSeriveDeptId.Value = value.F_ServiceDeptID.ToString();
  397. hiddProvinceId.Value = value.F_RegionId.ToString();
  398. hiddCityId.Value = value.F_CityID.ToString();
  399. hiddProductLineId.Value = value.F_ProductLineID.ToString();
  400. hiddCustomerNatureId.Value = value.F_CustomerNatureID.ToString();
  401. hiddCustomerClassId.Value = value.F_CustomerClassID.ToString();
  402. hiddCustomerIndustryId.Value = value.F_IndustryId.ToString();
  403. hiddRelationShipClassId.Value = value.F_RelationShipClassID.ToString();
  404. hiddAfterSaleNameID.Value = value.F_AfterSaleNameID.ToString();
  405. drpServiceDept.Text = value.F_ServiceDept;
  406. drpProvince.Text = value.F_Province;
  407. drpCity.Text = value.F_City;
  408. drpProductLine.Text = value.F_ProductLine;
  409. drpCustomerNature.Text = value.F_CustomerNature;
  410. drpCustomerClass.Text = value.F_CustomerClass;
  411. drpCustomerIndustry.Text = value.F_CustomerIndustry;
  412. drpRelationShipClass.Text = value.F_RelationShipClass;
  413. drpAfterSaleName.Text = value.F_AfterSaleName;
  414. //基本信息部分
  415. txtFax.Text = value.F_Fax;
  416. txtEmail.Text = value.F_Email;
  417. txtTelephone.Text = value.F_Telephone;
  418. txtAddress.Text = value.F_Address;
  419. txtPostCode.Text = value.F_PostCode;
  420. txtCurrentVersion.Text = value.F_CurrentVersion;
  421. txtSystemStartTime.Text = value.F_SystemStartTime.ToString();
  422. txtQualityGuaranteeEndTime.Text = value.F_QualityGuaranteeEndTime.ToString();
  423. txtSystemType.Text = value.F_SystemType;
  424. txtCustomerStatus.Text = value.F_CustomerStatus;
  425. txtDeviceCount.Text = value.F_DeviceCount.ToString();
  426. //备注信息部分
  427. txtTrackInfo.Value = value.F_TrackInfo;
  428. txtNotes.Value = value.F_Notes;
  429. //扩展信息部分
  430. //todo...
  431. }
  432. }
  433. }
  434. #endregion
  435. }
  436. }