frmContractManagement.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.Software.MainBusiness.CameraControlBook
  10. {
  11. public partial class frmContractManagement : LYFZ.Software.UI.CameraControlBook.frmContractManagement
  12. {
  13. LYFZ.BLL.BLL_ErpOrder orderBll = new BLL.BLL_ErpOrder();
  14. public frmContractManagement()
  15. {
  16. this.likbtnUpload.Click += LikbtnUpload_Click;
  17. this.likbtnDelete.Click += LikbtnDelete_Click;
  18. this.Shown += FrmContractManagement_Shown;
  19. this.listBoxEx1.DoubleClick += ListBoxEx1_DoubleClick;
  20. }
  21. private void ListBoxEx1_DoubleClick(object sender, EventArgs e)
  22. {
  23. if (this.listBoxEx1.SelectedItem != null)
  24. {
  25. string Ord_UploadPath = this.listBoxEx1.SelectedItem.ToString();
  26. if (!string.IsNullOrEmpty(Ord_UploadPath))
  27. {
  28. string resData = "";
  29. string downFilePath = Application.StartupPath + "\\Temp\\UploadFile\\" + System.IO.Path.GetFileName(Ord_UploadPath);
  30. LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  31. {
  32. LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer();
  33. resData = tcpFile.DownloadFile(downFilePath, Ord_UploadPath, backgroundWorker);
  34. });
  35. System.Diagnostics.Process.Start(downFilePath);
  36. }
  37. else
  38. {
  39. MessageBoxCustom.Show("未上传预约单!");
  40. }
  41. }
  42. }
  43. private void FrmContractManagement_Shown(object sender, EventArgs e)
  44. {
  45. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  46. {
  47. backgroundWorker.ReportProgress(0, "正在加载数据...");
  48. if (!String.IsNullOrEmpty(this._OrdNumber))
  49. {
  50. string[] tempPaths = this.orderBll.GetContractList(this._OrdNumber);
  51. if (tempPaths != null)
  52. {
  53. this.ContractList.AddRange(tempPaths);
  54. }
  55. }
  56. });
  57. BindContractList();
  58. }
  59. private void LikbtnDelete_Click(object sender, EventArgs e)
  60. {
  61. string retmsg = "";
  62. if (this.listBoxEx1.SelectedItem != null)
  63. {
  64. string Ord_UploadPath = this.listBoxEx1.SelectedItem.ToString();
  65. if (!String.IsNullOrEmpty(Ord_UploadPath))
  66. {
  67. LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  68. {
  69. try
  70. {
  71. this.ContractList.Remove(Ord_UploadPath);
  72. if (this.orderBll.SaveContractList(this._OrdNumber, ContractList.ToArray()))
  73. {
  74. LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer();
  75. retmsg = tcpFile.DeleteFile(Ord_UploadPath, backgroundWorker);
  76. }
  77. else
  78. {
  79. retmsg = "更新合约数据时失败";
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. retmsg = ex.Message;
  85. }
  86. });
  87. }
  88. else {
  89. retmsg = "选择的合约不正确";
  90. }
  91. }
  92. else {
  93. retmsg = "请选择你要删除的合约文件";
  94. }
  95. if (retmsg.Contains("成功"))
  96. {
  97. BindContractList();
  98. }
  99. if(String.IsNullOrEmpty(retmsg))
  100. MessageBoxCustom.Show(retmsg);
  101. }
  102. string _OrdNumber = "";
  103. /// <summary>
  104. /// 订单号
  105. /// </summary>
  106. public string OrdNumber {
  107. get { return _OrdNumber; }
  108. set { _OrdNumber = value; }
  109. }
  110. /// <summary>
  111. /// 当前合约集合
  112. /// </summary>
  113. List<string> ContractList = new List<string>();
  114. private void LikbtnUpload_Click(object sender, EventArgs e)
  115. {
  116. OpenFileDialog openDlg = new OpenFileDialog();
  117. openDlg.Multiselect = false;
  118. if (openDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  119. {
  120. DateTime startime = DateTime.Now;
  121. string filePath = openDlg.FileName.Trim();
  122. if (filePath.Length > 0)
  123. {
  124. bool b = false;
  125. string retmsg = "";
  126. string servicePath =String.Format("UploadFiles\\ReservationForm\\{0}\\{1}", this._OrdNumber, System.IO.Path.GetFileName(filePath));
  127. LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  128. {
  129. try
  130. {
  131. LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer();
  132. retmsg = tcpFile.UploadFileToServer(filePath, servicePath, backgroundWorker);
  133. if (!ContractList.Any(p => p.ToLower() == servicePath.ToLower()))
  134. {
  135. ContractList.Add(servicePath);
  136. b = this.orderBll.SaveContractList(this._OrdNumber, ContractList.ToArray());
  137. if (!b)
  138. {
  139. retmsg = "保存合约数据时失败";
  140. }
  141. }
  142. else
  143. {
  144. b = true;
  145. }
  146. }
  147. catch (Exception ex)
  148. {
  149. retmsg = ex.Message;
  150. b = false;
  151. }
  152. });
  153. if (b)
  154. {
  155. BindContractList();
  156. MessageBoxCustom.Show(
  157. retmsg + "\r\n" +
  158. "上传完成"
  159. );
  160. }
  161. else
  162. {
  163. MessageBoxCustom.Show(
  164. "上传失败\r\n" + retmsg
  165. );
  166. }
  167. }
  168. }
  169. }
  170. void BindContractList()
  171. {
  172. this.listBoxEx1.Items.Clear();
  173. foreach (string filePath in ContractList)
  174. {
  175. this.listBoxEx1.Items.Add(filePath);
  176. }
  177. }
  178. }
  179. }