DZKJ_AddCustomer.aspx.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using LYFZ.WeixinServers.WeiXinAPP;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. namespace LYFZ.WeixinServers.DZKJ
  9. {
  10. public partial class DZKJ_AddCustomer : System.Web.UI.Page
  11. {
  12. public long eid = -1;
  13. public LYFZ.WeixinServiceDate.Model.Model_DZKJ_CustomerAccount dzkjModel = new WeixinServiceDate.Model.Model_DZKJ_CustomerAccount();
  14. LYFZ.WeixinServiceDate.DAL.DAL_DZKJ_CustomerAccount DZKJ_Dal = new WeixinServiceDate.DAL.DAL_DZKJ_CustomerAccount();
  15. public string TxtReadonly = "";
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. CommonHandler.CheckLoginJump(this);
  19. if (!IsPostBack)
  20. {
  21. if (Request.QueryString["eid"] != null && Request.QueryString["eid"].ToString().Trim().Length > 0)
  22. {
  23. try
  24. {
  25. if (CommonHandler.CheckAdmin(this))
  26. {
  27. eid = Convert.ToInt64(Request.QueryString["eid"].ToString().Trim());
  28. dzkjModel = DZKJ_Dal.GetModel(eid);
  29. TxtReadonly = "readonly=\"readonly\"";
  30. }
  31. }
  32. catch { }
  33. }
  34. else if (Request.QueryString["s"] != null && Request.QueryString["s"].ToString().Trim() == "edit")
  35. {
  36. if (CommonHandler.CheckAdmin(this))
  37. {
  38. getEditID();
  39. AddOrEditCustomerAccount();
  40. }
  41. }
  42. else
  43. {
  44. dzkjModel.PeriodOfValidity = DateTime.Now.AddYears(1);
  45. }
  46. }
  47. }
  48. void getEditID()
  49. {
  50. try
  51. {
  52. eid = Convert.ToInt64(Request.QueryString["id"].ToString().Trim());
  53. }
  54. catch { }
  55. }
  56. /*[ID]
  57. ,[Account]
  58. ,[Password]
  59. ,[Contacts]
  60. ,[Telephone]
  61. ,[Sex]
  62. ,[CompanyName]
  63. ,[CompanyAddress]
  64. ,[PeriodOfValidity]
  65. ,[StartSimulatorCount]
  66. ,[HardwareCode]
  67. ,[IP]
  68. ,[RegistrationTime]
  69. ,[LatestLoginTime]
  70. ,[IsEnabled]
  71. * <label>*企业名称</label>
  72. <input name="CompanyName" id="CompanyName" type="text" value="" class="input-xlarge">
  73. <label>企业地址</label>
  74. <input name="CompanyAddress" id="CompanyAddress" type="text" value="" class="input-xlarge">
  75. <label>*硬件码</label>
  76. <input name="HardwareCode" id="HardwareCode" type="text" value="" class="input-xlarge">
  77. <label>*帐号</label>
  78. <input name="Account" id="Account" type="text" value="" class="input-xlarge">
  79. <label>*密码</label>
  80. <input name="Password" id="Password" type="text" value="" class="input-xlarge">
  81. <label>*联系人</label>
  82. <input name="Contacts" id="Contacts" type="text" value="" class="input-xlarge">
  83. <label>性别</label>
  84. <select name="sex" id="sex" class="input-xlarge">
  85. <option value="1">男</option>
  86. <option value="0">女</option>
  87. </select>
  88. <label>*联系电话</label>
  89. <input name="Telephone" id="Telephone" type="text" value="" class="input-xlarge">
  90. <label>*有效期</label>
  91. <input name="PeriodOfValidity" id="PeriodOfValidity" type="text" value="" class="input-xlarge">
  92. <label>*模拟器个数</label>
  93. <input name="StartSimulatorCount" id="StartSimulatorCount" type="text" value="" class="input-xlarge">
  94. <label>*状态</label>
  95. <input name="IsEnabled" id="IsEnabled" type="text" value="" class="input-xlarge">
  96. */
  97. void AddOrEditCustomerAccount()
  98. {
  99. if (!CommonHandler.isAdmin(this,false)) {
  100. LYFZ.WeixinServiceDate.DAL.DAL_DZKJ_DistributorAccount DDistAccount = new WeixinServiceDate.DAL.DAL_DZKJ_DistributorAccount();
  101. LYFZ.WeixinServiceDate.Model.Model_DZKJ_DistributorAccount MDistAccount = DDistAccount.GetModel("AccountID="+CommonHandler.GetAdminUser(this).ID);
  102. LYFZ.WeixinServiceDate.DAL.DAL_DZKJ_CustomerAccount DCustomerAccount = new LYFZ.WeixinServiceDate.DAL.DAL_DZKJ_CustomerAccount();
  103. if (MDistAccount.StartSimulatorCount <= DCustomerAccount.GetUsed(CommonHandler.GetAdminUser(this).ID))
  104. {
  105. MsegesBox("余额不足");
  106. return;
  107. }
  108. }
  109. LYFZ.WeixinServiceDate.Model.Model_DZKJ_CustomerAccount DZKJModel = new WeixinServiceDate.Model.Model_DZKJ_CustomerAccount();
  110. if (eid > 0)
  111. {
  112. DZKJModel = DZKJ_Dal.GetModel(eid);
  113. }
  114. DZKJModel.CompanyName = Request.Form["CompanyName"].ToString();
  115. DZKJModel.CompanyAddress = Request.Form["CompanyAddress"].ToString();
  116. DZKJModel.HardwareCode = Request.Form["HardwareCode"].ToString();
  117. DZKJModel.Account = Request.Form["Account"].ToString();
  118. DZKJModel.Password = Request.Form["Password"].ToString();
  119. DZKJModel.Contacts = Request.Form["Contacts"].ToString();
  120. DZKJModel.Sex = Convert.ToInt32(Request.Form["sex"].ToString());
  121. DZKJModel.Telephone = Request.Form["Telephone"].ToString();
  122. DZKJModel.DistributorID = CommonHandler.GetAdminUser(this).ID;
  123. try
  124. {
  125. DZKJModel.PeriodOfValidity = Convert.ToDateTime(Request.Form["PeriodOfValidity"].ToString());
  126. }
  127. catch
  128. {
  129. MsegesBox("操作失败,有效期格式不正确");
  130. return;
  131. }
  132. try
  133. {
  134. DZKJModel.StartSimulatorCount = Convert.ToInt32(Request.Form["StartSimulatorCount"].ToString());
  135. }
  136. catch
  137. {
  138. MsegesBox("操作失败,模拟器可启动个数格式不正确");
  139. return;
  140. }
  141. DZKJModel.IsEnabled = Convert.ToInt32(Request.Form["IsEnabled"].ToString());
  142. bool ret = false;
  143. try
  144. {
  145. if (eid > 0)
  146. {
  147. ret = DZKJ_Dal.Update(DZKJModel);
  148. }
  149. else
  150. {
  151. DZKJModel.IP = "";
  152. DZKJModel.RegistrationTime = DateTime.Now;
  153. ret = DZKJ_Dal.Add(DZKJModel);
  154. }
  155. }
  156. catch (Exception ex){
  157. if (ex.Message.ToLower().Contains("PK_tb_DZKJ_CustomerAccount".ToLower()))
  158. {
  159. MsegesBox("帐号“" + DZKJModel.Account + "”已经存在,不能重复。" + ex.Message);
  160. }
  161. else {
  162. MsegesBox("操作失败:" + ex.Message);
  163. }
  164. return;
  165. }
  166. if (ret)
  167. {
  168. Global.RefreshDZKJ_CustomerAccountDataTable();
  169. MsegesBox("操作成功");
  170. }
  171. else
  172. {
  173. MsegesBox("操作失败,请重试");
  174. }
  175. }
  176. void MsegesBox(string msg)
  177. {
  178. Response.Write("<script>alert(\"" + msg.Replace("\r\n", "").Replace("\r", "").Replace("\n", "") + "\");document.location='DZKJ_CustomerAccount.aspx';</script>"); return;
  179. }
  180. }
  181. }