DZKJ_AddDistributor.aspx.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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_AddDistributor : System.Web.UI.Page
  11. {
  12. public long eid = -1;
  13. public LYFZ.WeixinServiceDate.Model.Model_DZKJ_DistributorAccount dzkjModel = new WeixinServiceDate.Model.Model_DZKJ_DistributorAccount();
  14. LYFZ.WeixinServiceDate.DAL.DAL_DZKJ_DistributorAccount DDzkjDistAccount = new WeixinServiceDate.DAL.DAL_DZKJ_DistributorAccount();
  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 = DDzkjDistAccount.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. }
  43. }
  44. void getEditID()
  45. {
  46. try
  47. {
  48. eid = Convert.ToInt64(Request.QueryString["id"].ToString().Trim());
  49. }
  50. catch { }
  51. }
  52. /*[ID]
  53. ,[Account]
  54. ,[Password]
  55. ,[Contacts]
  56. ,[Telephone]
  57. ,[Sex]
  58. ,[CompanyName]
  59. ,[CompanyAddress]
  60. ,[PeriodOfValidity]
  61. ,[StartSimulatorCount]
  62. ,[HardwareCode]
  63. ,[IP]
  64. ,[RegistrationTime]
  65. ,[LatestLoginTime]
  66. ,[IsEnabled]
  67. * <label>*企业名称</label>
  68. <input name="CompanyName" id="CompanyName" type="text" value="" class="input-xlarge">
  69. <label>企业地址</label>
  70. <input name="CompanyAddress" id="CompanyAddress" type="text" value="" class="input-xlarge">
  71. <label>*硬件码</label>
  72. <input name="HardwareCode" id="HardwareCode" type="text" value="" class="input-xlarge">
  73. <label>*帐号</label>
  74. <input name="Account" id="Account" type="text" value="" class="input-xlarge">
  75. <label>*密码</label>
  76. <input name="Password" id="Password" type="text" value="" class="input-xlarge">
  77. <label>*联系人</label>
  78. <input name="Contacts" id="Contacts" type="text" value="" class="input-xlarge">
  79. <label>性别</label>
  80. <select name="sex" id="sex" class="input-xlarge">
  81. <option value="1">男</option>
  82. <option value="0">女</option>
  83. </select>
  84. <label>*联系电话</label>
  85. <input name="Telephone" id="Telephone" type="text" value="" class="input-xlarge">
  86. <label>*有效期</label>
  87. <input name="PeriodOfValidity" id="PeriodOfValidity" type="text" value="" class="input-xlarge">
  88. <label>*模拟器个数</label>
  89. <input name="StartSimulatorCount" id="StartSimulatorCount" type="text" value="" class="input-xlarge">
  90. <label>*状态</label>
  91. <input name="IsEnabled" id="IsEnabled" type="text" value="" class="input-xlarge">
  92. */
  93. LYFZ.WeixinServiceDate.DAL.DAL_DZKJ_DistributorRechargeRecords DZKJRec_Dal = new WeixinServiceDate.DAL.DAL_DZKJ_DistributorRechargeRecords();
  94. void AddOrEditCustomerAccount()
  95. {
  96. LYFZ.WeixinServiceDate.Model.Model_DZKJ_DistributorAccount DZKJModel = new WeixinServiceDate.Model.Model_DZKJ_DistributorAccount();
  97. LYFZ.WeixinServiceDate.Model.Model_AdminUser userModel = new WeixinServiceDate.Model.Model_AdminUser();
  98. LYFZ.WeixinServiceDate.DAL.DAL_AdminUser userDal = new WeixinServiceDate.DAL.DAL_AdminUser();
  99. if (eid > 0)
  100. {
  101. DZKJModel = DDzkjDistAccount.GetModel(eid);
  102. }
  103. DZKJModel.CompanyName = Request.Form["CompanyName"].ToString();
  104. DZKJModel.CompanyAddress = Request.Form["CompanyAddress"].ToString();
  105. DZKJModel.Contacts = Request.Form["Contacts"].ToString();
  106. DZKJModel.Sex = Convert.ToInt32(Request.Form["sex"].ToString());
  107. DZKJModel.Telephone = Request.Form["Telephone"].ToString();
  108. DZKJModel.StartSimulatorCount = 0;
  109. int StartSimulatorCount = 0;
  110. try
  111. {
  112. StartSimulatorCount = Convert.ToInt32(Request.Form["StartSimulatorCount"].ToString());
  113. }
  114. catch
  115. {
  116. MsegesBox("操作失败,购买软件套数格式不正确");
  117. return;
  118. }
  119. DZKJModel.IsEnabled = Convert.ToInt32(Request.Form["IsEnabled"].ToString());
  120. bool ret = false;
  121. try
  122. {
  123. if (eid > 0)
  124. {
  125. ret = DDzkjDistAccount.Update(DZKJModel);
  126. }
  127. else
  128. {
  129. /* 帐号初次建立,生成对应的系统登录帐号 */
  130. userModel.UserName = Request.Form["CompanyName"].ToString();
  131. userModel.Account = Request.Form["Account"].ToString();
  132. userModel.Phone = Request.Form["Telephone"].ToString();
  133. userModel.Password = Request.Form["Password"].ToString();
  134. userModel.Competence = 2;
  135. ret = false;
  136. int Id = userDal.Add(userModel);
  137. DZKJModel.AccountID = Id;
  138. DZKJModel.IP = "";
  139. DZKJModel.RegistrationTime = DateTime.Now;
  140. DZKJModel.ID= LYFZ.WinAPI.CustomPublicMethod.GenerateId();
  141. ret = DDzkjDistAccount.Add(DZKJModel);
  142. if (ret)
  143. {
  144. DDzkjDistAccount.Recharge(DZKJModel.ID, CommonHandler.GetAdminUser(this).Account, 0, StartSimulatorCount, "直接购买时的软件套数");
  145. }
  146. }
  147. }
  148. catch (Exception ex){
  149. if (ex.Message.ToLower().Contains("PK_tb_DZKJ_DistributorAccount".ToLower()))
  150. {
  151. MsegesBox("帐号“" + DZKJModel.AccountID + "”已经存在,不能重复。" + ex.Message);
  152. }
  153. else {
  154. MsegesBox("操作失败:" + ex.Message);
  155. }
  156. return;
  157. }
  158. if (ret)
  159. {
  160. Global.RefreshDZKJ_CustomerAccountDataTable();
  161. MsegesBox("操作成功");
  162. }
  163. else
  164. {
  165. MsegesBox("操作失败,请重试");
  166. }
  167. }
  168. void MsegesBox(string msg)
  169. {
  170. Response.Write("<script>alert(\"" + msg.Replace("\r\n", "").Replace("\r", "").Replace("\n", "") + "\");document.location='DZKJ_DistributorAccount.aspx';</script>"); return;
  171. }
  172. }
  173. }