frmAdd_OR_Edit_Enterprise.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. using LYFZ.WinAPI;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Dynamic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. namespace LYFZ.ERPCloudClient
  12. {
  13. public partial class frmAdd_OR_Edit_Enterprise : LYFZ.ComponentLibrary.BaseContentsFormMain
  14. {
  15. public frmAdd_OR_Edit_Enterprise()
  16. {
  17. InitializeComponent();
  18. this.Shown += frmAdd_OR_Edit_Enterprise_Shown;
  19. this.btnDetermine.Click += btnDetermine_Click;
  20. this.btnExit.Click += btnExit_Click;
  21. this.cbxServerList.SelectedValueChanged += cbxServerList_SelectedValueChanged;
  22. this.gbtnCopyEid.Click += gbtnCopyEid_Click;
  23. this.gbtnCopyCode.Click += gbtnCopyCode_Click;
  24. this.gbtnCopyAppZhuche.Click += gbtnCopyAppZhuche_Click;
  25. this.gbtnCopyAll.Click += gbtnCopyAll_Click;
  26. if (frmMain.LoginUser.QuanXianPeiZhi == "2")
  27. {
  28. this.btnDetermine.Enabled = false;
  29. }
  30. }
  31. void gbtnCopyAll_Click(object sender, EventArgs e)
  32. {
  33. Clipboard.SetDataObject("客户(企业)名称:"+this.txtEnterpriseName.Text.Trim()+"\r\n"
  34. +"企业ID:" + this.txtEnterpriseID.Text+"\r\n"
  35. + "安装验证码:" + this.txtInstallationCode.Text+"\r\n"
  36. + "APP注册码:" + this.txtWebAppLicense.Text);
  37. }
  38. /// <summary>
  39. /// 复制APP注册码
  40. /// </summary>
  41. /// <param name="sender"></param>
  42. /// <param name="e"></param>
  43. void gbtnCopyAppZhuche_Click(object sender, EventArgs e)
  44. {
  45. Clipboard.SetDataObject("客户(企业)名称:" + this.txtEnterpriseName.Text.Trim() + "\r\n"
  46. + "APP注册码:" + this.txtWebAppLicense.Text);
  47. }
  48. /// <summary>
  49. /// 复制安装验证码
  50. /// </summary>
  51. /// <param name="sender"></param>
  52. /// <param name="e"></param>
  53. void gbtnCopyCode_Click(object sender, EventArgs e)
  54. {
  55. Clipboard.SetDataObject("客户(企业)名称:" + this.txtEnterpriseName.Text.Trim() + "\r\n"
  56. + "安装验证码:" + this.txtInstallationCode.Text);
  57. }
  58. /// <summary>
  59. /// 复制企业ID
  60. /// </summary>
  61. /// <param name="sender"></param>
  62. /// <param name="e"></param>
  63. void gbtnCopyEid_Click(object sender, EventArgs e)
  64. {
  65. Clipboard.SetDataObject("客户(企业)名称:" + this.txtEnterpriseName.Text.Trim() + "\r\n"
  66. + "企业ID:" + this.txtEnterpriseID.Text);
  67. }
  68. void cbxServerList_SelectedValueChanged(object sender, EventArgs e)
  69. {
  70. if (this.cbxServerList.SelectedItem != null)
  71. {
  72. LYFZ.CloudServerData.Model.CloudServerCollection serverModel = (LYFZ.CloudServerData.Model.CloudServerCollection)this.cbxServerList.SelectedItem;
  73. this.txtDomainName.Text = serverModel.DomainName;
  74. this.txtWebAppLicense.Text = GetWebAppLicense(serverModel, this.txtEnterpriseID.Text,this.txtInstallationCode.Text.Trim());
  75. if (String.IsNullOrEmpty(serverModel.FrpConfig))
  76. {
  77. MessageBoxCustom.Show("您选择的服务器配不正确,请重新配置服务器后重试");
  78. }
  79. }
  80. }
  81. /// <summary>
  82. /// 获取WebApp注册码
  83. /// </summary>
  84. /// <param name="server"></param>
  85. /// <returns></returns>
  86. string GetWebAppLicense(LYFZ.CloudServerData.Model.CloudServerCollection server, string _EnterpriseID, string _InstallationCode)
  87. {
  88. string retLicense = "";
  89. if (!String.IsNullOrEmpty(server.FrpConfig))
  90. {
  91. LYFZ.CloudServerData.Model.FRPConfig frpModel = LYFZ.CloudServerData.Model.FRPConfig.JsonDeserializeObject(server.FrpConfig);
  92. dynamic licenseData = new
  93. {
  94. Server_addr = frpModel.Server_addr,
  95. Server_port = frpModel.Server_port,
  96. Privilege_token = frpModel.Privilege_token,
  97. Vhost_http_port = frpModel.Vhost_http_port,
  98. IISWebPort = frpModel.IISWebPort,
  99. EnterpriseID = _EnterpriseID,
  100. ErpServerPort = server.SeverPort,
  101. ErpServerIP=server.DataBaseServerIP,
  102. InstallationCode=_InstallationCode,
  103. ApplyDateTime=DateTime.Now.ToYYYY_MM_dd_HH_mm_ss()
  104. };
  105. retLicense = Newtonsoft.Json.JsonConvert.SerializeObject(licenseData);
  106. }
  107. return LYFZ.WinAPI.SDKSecurity.EncryptDES(retLicense,"lyfz@liu");
  108. }
  109. void btnExit_Click(object sender, EventArgs e)
  110. {
  111. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  112. }
  113. void btnDetermine_Click(object sender, EventArgs e)
  114. {
  115. this.EnterpriseModel.EnterpriseID=this.txtEnterpriseID.Text.Trim();
  116. this.EnterpriseModel.EnterpriseName = this.txtEnterpriseName.Text.Trim();
  117. this.EnterpriseModel.ContactPerson = this.txtContactPerson.Text.Trim();
  118. this.EnterpriseModel.Phone = this.txtPhone.Text.Trim();
  119. this.EnterpriseModel.InstallationCode = this.txtInstallationCode.Text.Trim();
  120. this.EnterpriseModel.EffectiveTime = this.dateTimeEffectiveTime.Value.ToJavaScriptTimeStamp();
  121. this.EnterpriseModel.WebInterfaceAddress = this.txtWebUrl.Text.Trim();
  122. this.EnterpriseModel.Address = this.txtAdderss.Text.Trim();
  123. this.EnterpriseModel.Remarks = this.txtRemarks.Text.Trim();
  124. this.EnterpriseModel.AnnualFee = this.nuMoney.Value;
  125. this.EnterpriseModel.OssCloudDisk=Convert.ToInt32(this.nuOssCloudDisk.Value);
  126. this.EnterpriseModel.ClientAnnualFee = this.nudClientValidity.Value;
  127. if (this.cbxServerList.SelectedItem != null)
  128. {
  129. this.EnterpriseModel.CloudServerID = ((LYFZ.CloudServerData.Model.CloudServerCollection)this.cbxServerList.SelectedItem).ID;
  130. }
  131. else {
  132. MessageBoxCustom.Show("请选择服务器");
  133. return;
  134. }
  135. if (String.IsNullOrEmpty(this.EnterpriseModel.EnterpriseID.Trim()))
  136. {
  137. MessageBoxCustom.Show("企业ID不能为空");
  138. return;
  139. }
  140. if (String.IsNullOrEmpty(this.EnterpriseModel.EnterpriseName.Trim()))
  141. {
  142. MessageBoxCustom.Show("企业名称不能为空");
  143. return;
  144. }
  145. if (String.IsNullOrEmpty(this.EnterpriseModel.ContactPerson.Trim()))
  146. {
  147. MessageBoxCustom.Show("联系人不能为空");
  148. return;
  149. }
  150. if (String.IsNullOrEmpty(this.EnterpriseModel.Phone.Trim()))
  151. {
  152. MessageBoxCustom.Show("联系电话不能为空");
  153. return;
  154. }
  155. if (this.EnterpriseModel.Phone.Trim().Length<7)
  156. {
  157. MessageBoxCustom.Show("联系电话不能小于7位");
  158. return;
  159. }
  160. var featuresData = new
  161. {
  162. MoveAPP = new
  163. {
  164. name = "手机APP",
  165. value = this.chkMoveAPP.Checked ? 1 : 0
  166. },
  167. CloudDatabase = new
  168. {
  169. name = "托管数据库",
  170. value = this.chkCloudDatabase.Checked ? 1 : 0
  171. },
  172. OssCloudDisk = new
  173. {
  174. name = "OSS云盘",
  175. value = this.chkOssCloudDisk.Checked ? 1 : 0
  176. },
  177. ClientDisk = new
  178. {
  179. name = "客片下载",
  180. value = this.chkClientDisk.Checked ? 1 : 0
  181. }
  182. };
  183. this.EnterpriseModel.Features = Newtonsoft.Json.JsonConvert.SerializeObject(featuresData);
  184. bool isSuccess = false;
  185. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  186. {
  187. backgroundWorker.ReportProgress(0, "正在提交客户资料...");
  188. try
  189. {
  190. HPSocketCS.Extended.ReturnData returnData = LYFZ.CloudServerData.ClientDataRequestProcess.RequestQueryAddOrEditEnterprise(frmMain.TcpClient.Client, this.EnterpriseModel);
  191. if (returnData.ReturnStatus)
  192. {
  193. isSuccess = returnData.DataByteToModelObject<bool>();
  194. if (!isSuccess)
  195. {
  196. MessageBoxCustom.Show("提交客户资料失败,请与管理员联系", backgroundWorker: backgroundWorker);
  197. }
  198. else
  199. {
  200. dynamic jsonData = new ExpandoObject();
  201. jsonData.entId= this.EnterpriseModel.EnterpriseID.Trim();
  202. jsonData.status = this.chkClientDisk.Checked ? 1 : 0;
  203. jsonData.entName=this.EnterpriseModel.EnterpriseName.Trim();
  204. jsonData.linker= this.EnterpriseModel.ContactPerson;
  205. jsonData.linkTele = this.EnterpriseModel.Phone;
  206. jsonData.validityTime = this.dateTimeEffectiveTime.Value;
  207. jsonData.serviceCharge = this.nudClientValidity.Value;
  208. string txt = HttpClientHelper.PostResponse("http://p.lyfz.net/api/Systems.ashx/CusRegisterByApp", Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
  209. dynamic dyObjJson = Newtonsoft.Json.JsonConvert.DeserializeObject(txt);
  210. if(dyObjJson.code!=200)
  211. {
  212. MessageBoxCustom.Show("客片管理操作失败:" + dyObjJson.data, backgroundWorker: backgroundWorker);
  213. }
  214. }
  215. }
  216. else
  217. {
  218. MessageBoxCustom.Show("提交客户资料:" + returnData.ReturnMessage, backgroundWorker: backgroundWorker);
  219. }
  220. }
  221. catch (Exception ex)
  222. {
  223. MessageBoxCustom.Show("提交客户资料出错:" + ex.Message, backgroundWorker: backgroundWorker);
  224. }
  225. });
  226. if (isSuccess)
  227. {
  228. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  229. }
  230. }
  231. void BindServerList()
  232. {
  233. if (frmCloudServerCollection.CloudServerCollectionList.Count <= 0)
  234. {
  235. frmCloudServerCollection.LoadCloudServerCollection();
  236. }
  237. this.cbxServerList.Items.Clear();
  238. // this.cbxServerList.Items.Add(new LYFZ.CloudServerData.Model.CloudServerCollection("店内服务器"));
  239. foreach (LYFZ.CloudServerData.Model.CloudServerCollection serverCollectionModel in frmCloudServerCollection.CloudServerCollectionList)
  240. {
  241. this.cbxServerList.Items.Add(serverCollectionModel);
  242. }
  243. // this.cbxServerList.SelectedIndex = 0;
  244. }
  245. void frmAdd_OR_Edit_Enterprise_Shown(object sender, EventArgs e)
  246. {
  247. BindServerList();
  248. if (EnterpriseModel.ID > 0)
  249. {
  250. this.txtEnterpriseID.ReadOnly = true;
  251. this.txtEnterpriseID.Text = this.EnterpriseModel.EnterpriseID.Trim();
  252. this.txtEnterpriseName.Text = this.EnterpriseModel.EnterpriseName.Trim();
  253. this.txtContactPerson.Text = this.EnterpriseModel.ContactPerson;
  254. this.txtPhone.Text = this.EnterpriseModel.Phone;
  255. this.txtInstallationCode.Text = this.EnterpriseModel.InstallationCode.Trim();
  256. this.txtWebUrl.Text = this.EnterpriseModel.WebInterfaceAddress.Trim();
  257. this.dateTimeEffectiveTime.Value = this.EnterpriseModel.EffectiveTime.JavaScriptTimeStampToDateTime();
  258. this.txtAdderss.Text = this.EnterpriseModel.Address;
  259. this.txtRemarks.Text = this.EnterpriseModel.Remarks;
  260. this.nuMoney.Value = this.EnterpriseModel.AnnualFee;
  261. this.nudClientValidity.Value = this.EnterpriseModel.ClientAnnualFee;
  262. if (!String.IsNullOrEmpty(this.EnterpriseModel.Features.Trim()))
  263. {
  264. dynamic featuresData = Newtonsoft.Json.JsonConvert.DeserializeObject(this.EnterpriseModel.Features);
  265. this.chkMoveAPP.Checked = featuresData.MoveAPP.value == 1 ? true : false;
  266. this.chkCloudDatabase.Checked = featuresData.CloudDatabase.value == 1 ? true : false;
  267. if (featuresData.OssCloudDisk == null)
  268. {
  269. this.chkOssCloudDisk.Checked = true;
  270. }
  271. else {
  272. this.chkOssCloudDisk.Checked = featuresData.OssCloudDisk.value == 1 ? true : false;
  273. }
  274. if (featuresData.ClientDisk == null)
  275. {
  276. this.chkClientDisk.Checked = false;
  277. }
  278. else
  279. {
  280. this.chkClientDisk.Checked = featuresData.ClientDisk.value == 1 ? true : false;
  281. }
  282. }
  283. else
  284. {
  285. this.chkMoveAPP.Checked = false;
  286. this.chkCloudDatabase.Checked = false;
  287. this.chkOssCloudDisk.Checked = true;
  288. this.chkClientDisk.Checked = false;
  289. }
  290. this.nuOssCloudDisk.Value = this.EnterpriseModel.OssCloudDisk;
  291. foreach (LYFZ.CloudServerData.Model.CloudServerCollection serverCollectionModel in this.cbxServerList.Items)
  292. {
  293. if (serverCollectionModel.ID == EnterpriseModel.CloudServerID)
  294. {
  295. this.cbxServerList.SelectedItem = serverCollectionModel;
  296. }
  297. }
  298. }
  299. else
  300. {
  301. this.txtEnterpriseID.Text = LYFZ.CloudServerData.DAL.Enterprise.GetNewEnterpriseID();
  302. this.txtInstallationCode.Text = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(this.txtEnterpriseID.Text.Trim() + SDateTime.Now.ToJavaScriptTimeStamp().ToString());
  303. this.dateTimeEffectiveTime.Value = SDateTime.Now.AddYears(1);
  304. }
  305. }
  306. LYFZ.CloudServerData.Model.Enterprise _EnterpriseModel = new CloudServerData.Model.Enterprise();
  307. /// <summary>
  308. /// 客户实体
  309. /// </summary>
  310. public LYFZ.CloudServerData.Model.Enterprise EnterpriseModel
  311. {
  312. get { return _EnterpriseModel; }
  313. set { _EnterpriseModel = value; }
  314. }
  315. }
  316. }