frmMultipleFileImport.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using WFtpClient;
  11. namespace LYFZ.Software.MainBusiness.MultipleFileImport
  12. {
  13. public partial class frmMultipleFileImport : LYFZ.ComponentLibrary.BaseContentsFormMain
  14. {
  15. string selectType = "";
  16. delegate void FormShowMessage(enumImportMultipFieForm StatusCode, object objectData);
  17. FormShowMessage delegateMessage;
  18. public frmMultipleFileImport()
  19. {
  20. InitializeComponent();
  21. this.Shown += frmMultipleFileImport_Shown;
  22. this.FormClosing += FrmMultipleFileImport_FormClosing;
  23. btn_Faild.Click += btn_Click;
  24. btn_Detail.Click += btn_Click;
  25. btn_Start.Click += btn_Click;
  26. btn_Stop.Click += btn_Click;
  27. btn_AllStart.Click += btn_Click;
  28. btn_AllStop.Click += btn_Click;
  29. btn_Delete.Click += btn_Click;
  30. /*(btn_All.Click += btn_Click;
  31. btn_Success.Click += btn_Click;
  32. btn_upLoad.Click += btn_Click;*/
  33. //frmMultipFileImportThread.GetSingleton().SingletonThreadImportFileFormEvent += frmMultipleFileImport_SingletonThreadImportFileFormEvent;
  34. delegateMessage = new FormShowMessage(FormShowMessageHandler);
  35. cb_AutoCheck.Click += cb_AutoCheck_Click;
  36. cb_AutoCheck.Checked = Properties.Settings.Default.bImportAutoUp;
  37. cb_AutoShutDown.Click += Cb_AutoShutDown_Click;
  38. }
  39. private void FrmMultipleFileImport_FormClosing(object sender, FormClosingEventArgs e)
  40. {
  41. NewMultipFileImport.NewMultipFileImport.RemoveAction("DetailInfo");
  42. }
  43. private void Cb_AutoShutDown_Click(object sender, EventArgs e)
  44. {
  45. Model.Model_Config.bAutoShutDown = cb_AutoShutDown.Checked;
  46. }
  47. void cb_AutoCheck_Click(object sender, EventArgs e)
  48. {
  49. Properties.Settings.Default.bImportAutoUp = cb_AutoCheck.Checked;
  50. Properties.Settings.Default.Save();
  51. }
  52. void FormShowMessageHandler(enumImportMultipFieForm StatusCode, object objectData)
  53. {
  54. switch (StatusCode)
  55. {
  56. case enumImportMultipFieForm.AddList:
  57. ReLoadData(selectType);
  58. break;
  59. case enumImportMultipFieForm.BackNext:
  60. BindDataInfo(objectData);
  61. break;
  62. }
  63. BindDeleteButtonShowOrHide();
  64. }
  65. void MultipFileDataHandler(NewMultipFileImport.MultipFileReport report)
  66. {
  67. switch (report.importMultipType)
  68. {
  69. case NewMultipFileImport.EnumImportMultipType.AddList:
  70. ReLoadData(selectType);
  71. break;
  72. case NewMultipFileImport.EnumImportMultipType.BackNext:
  73. BindDataInfo(report.currentGroupMod);
  74. break;
  75. }
  76. BindDeleteButtonShowOrHide();
  77. }
  78. //void frmMultipleFileImport_SingletonThreadImportFileFormEvent(enumImportMultipFieForm StatusCode, object objectData)
  79. //{
  80. // try
  81. // {
  82. // this.Invoke(delegateMessage, StatusCode, objectData);
  83. // }
  84. // catch
  85. // {
  86. // }
  87. //}
  88. void frmMultipleFileImport_Shown(object sender, EventArgs e)
  89. {
  90. ReLoadData("ALL");
  91. NewMultipFileImport.NewMultipFileImport.AddAction("DetailInfo", MultipFileDataHandler);
  92. }
  93. private void frmMultipleFileImport_Load(object sender, EventArgs e)
  94. {
  95. }
  96. void BindDeleteButtonShowOrHide()
  97. {
  98. if (LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.multipFileReport.bStartThread)
  99. {
  100. btn_Delete.Enabled = false;
  101. }
  102. else
  103. {
  104. btn_Delete.Enabled = true;
  105. }
  106. }
  107. void btn_Click(object sender, EventArgs e)
  108. {
  109. //ReLoadData(((LYFZ.ComponentLibrary.ButtonEx)sender).Tag.ToString());
  110. List<frmFileImportModel> temp_Pools;
  111. switch(((LYFZ.ComponentLibrary.ButtonEx)sender).Tag.ToString())
  112. {
  113. case "Error":
  114. LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.multipFileReport.SetClearErrorData();
  115. ReLoadData("ALL");
  116. break;
  117. case "Delete":
  118. if (listViewEx1.SelectedItems.Count > 0)
  119. {
  120. if (MessageBoxCustom.Show("是否确定删除当前导片队列?", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  121. {
  122. LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.multipFileReport.DeleteModel((frmFileImportModel)listViewEx1.SelectedItems[0].Tag);
  123. ReLoadData("ALL");
  124. }
  125. }
  126. break;
  127. case "Detail":
  128. if(listViewEx1.SelectedItems.Count>0)
  129. {
  130. frmMultipleFileImportDetail detail = new frmMultipleFileImportDetail();
  131. detail.BindImportModel((frmFileImportModel)listViewEx1.SelectedItems[0].Tag);
  132. detail.StartPosition = FormStartPosition.CenterScreen;
  133. detail.Show();
  134. }
  135. else
  136. {
  137. MessageBoxCustom.Show("请选择相应的栏目查看详情");
  138. }
  139. break;
  140. case "Stop":
  141. if (listViewEx1.SelectedItems.Count > 0)
  142. {
  143. btn_Delete.Enabled = true;
  144. ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).errorMsg = "暂停上传";
  145. foreach (var path in ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).local_Path)
  146. {
  147. if (path.upload_Msg == "正在上传" || path.code == 1)
  148. {
  149. continue;
  150. }
  151. else if (path.code == 0)
  152. {
  153. path.code = -1;
  154. path.upload_Msg = "暂停上传";
  155. }
  156. }
  157. LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.RestartThread(((frmFileImportModel)listViewEx1.SelectedItems[0].Tag));
  158. }
  159. else
  160. {
  161. MessageBoxCustom.Show("请选择进行中的队列进行暂停导片!");
  162. }
  163. //frmMultipFileImportThread.GetSingleton().
  164. break;
  165. case "Start":
  166. if (listViewEx1.SelectedItems.Count > 0)
  167. {
  168. ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).Success=false;
  169. ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).errorMsg = "";
  170. foreach (var path in ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).local_Path)
  171. {
  172. if ((path.upload_Msg == "暂停上传" && path.code == -1))
  173. {
  174. path.code = 0;
  175. path.upload_Msg = "等待上传";
  176. }
  177. else
  178. {
  179. }
  180. }
  181. NewMultipFileImport.NewMultipFileImport.StartThread();
  182. //frmMultipFileImportThread.GetSingleton().RestartThread((frmFileImportModel)listViewEx1.SelectedItems[0].Tag);
  183. }
  184. else
  185. {
  186. MessageBoxCustom.Show("请选择指定队列进行导片!");
  187. }
  188. break;
  189. case "AllStart":
  190. temp_Pools = NewMultipFileImport.NewMultipFileImport.GetFileImportList();
  191. foreach (frmFileImportModel mod in temp_Pools)
  192. {
  193. mod.Success = false;
  194. mod.errorMsg = "";
  195. foreach (var path in mod.local_Path)
  196. {
  197. if (path.upload_Msg == "暂停上传" && path.code == -1)
  198. {
  199. path.code = 0;
  200. path.upload_Msg = "";
  201. }
  202. else
  203. {
  204. }
  205. }
  206. }
  207. btn_Delete.Enabled = false;
  208. //frmMultipFileImportThread.GetSingleton().RestartThread(null);
  209. NewMultipFileImport.NewMultipFileImport.StartThread();
  210. break;
  211. case "AllStop":
  212. btn_Delete.Enabled = true;
  213. temp_Pools = NewMultipFileImport.NewMultipFileImport.GetFileImportList();
  214. foreach (frmFileImportModel mod in temp_Pools)
  215. {
  216. mod.errorMsg = "暂停上传";
  217. foreach (var path in mod.local_Path)
  218. {
  219. if (path.upload_Msg == "正在上传" || path.code == 1)
  220. {
  221. continue;
  222. }
  223. else if (path.code == 0)
  224. {
  225. path.code = -1;
  226. path.upload_Msg = "暂停上传";
  227. }
  228. }
  229. }
  230. //frmMultipFileImportThread.GetSingleton().threadStart = false;
  231. //frmMultipFileImportThread.GetSingleton().RestartThread(null);
  232. NewMultipFileImport.NewMultipFileImport.multipFileReport.bStartThread = false;
  233. break;
  234. }
  235. }
  236. /// <summary>
  237. /// 重新绑定数据
  238. /// </summary>
  239. /// <param name="typeName"></param>
  240. public void ReLoadData(string typeName)
  241. {
  242. selectType = typeName;
  243. List<frmFileImportModel> mianList = new List<frmFileImportModel>();
  244. List<frmFileImportModel> tempList = null;
  245. switch(typeName)
  246. {
  247. case "ALL":
  248. mianList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
  249. break;
  250. case "Complete":
  251. tempList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
  252. for (int i = 0; i < tempList.Count;i++ )
  253. {
  254. frmFileImportModel inListModel = GetModel(tempList[i],1);
  255. if(inListModel!=null)
  256. {
  257. mianList.Add(inListModel);
  258. }
  259. }
  260. break;
  261. case "Error":
  262. tempList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
  263. for (int i = 0; i < tempList.Count; i++)
  264. {
  265. frmFileImportModel inListModel = GetModel(tempList[i], -1);
  266. if(inListModel!=null)
  267. {
  268. mianList.Add(inListModel);
  269. }
  270. }
  271. break;
  272. case "upLoad":
  273. tempList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
  274. for (int i = 0; i < tempList.Count; i++)
  275. {
  276. frmFileImportModel inListModel = GetModel(tempList[i], 0);
  277. if(inListModel!=null)
  278. {
  279. mianList.Add(inListModel);
  280. }
  281. }
  282. break;
  283. }
  284. LoadDataInfo(mianList);
  285. }
  286. /// <summary>
  287. /// 通过编码获取实体
  288. /// </summary>
  289. /// <param name="tempModel"></param>
  290. /// <param name="code"></param>
  291. /// <returns></returns>
  292. public frmFileImportModel GetModel(frmFileImportModel tempModel ,int code)
  293. {
  294. frmFileImportModel inListModel = null;
  295. for (int q = 0; q < tempModel.local_Path.Count; q++)
  296. {
  297. if (tempModel.local_Path[q].code == code)
  298. {
  299. if (inListModel == null)
  300. {
  301. inListModel = new frmFileImportModel()
  302. {
  303. service_Path = tempModel.service_Path,
  304. sPh = tempModel.sPh,
  305. local_Path = new List<frmFileImportItemModel>(),
  306. directoryType = tempModel.directoryType,
  307. erpDigOrder = tempModel.erpDigOrder,
  308. erpOrder = tempModel.erpOrder,
  309. takenName = tempModel.takenName
  310. };
  311. }
  312. inListModel.local_Path.Add(tempModel.local_Path[q]);
  313. }
  314. }
  315. return inListModel;
  316. }
  317. /// <summary>
  318. /// 绑定更新进度条
  319. /// </summary>
  320. /// <param name="model"></param>
  321. public void BindDataInfo(object model)
  322. {
  323. List<frmFileImportModel> mianList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileActionImportList();
  324. if (mianList.Count != this.listViewEx1.Items.Count)
  325. {
  326. ReLoadData("ALL");
  327. }
  328. foreach (var mod in this.listViewEx1.Items)
  329. {
  330. bool bStartBind = false;
  331. int processBar = 0;
  332. int errorNumber = 0;
  333. int stopNumber = 0;
  334. int totalCount = 0;
  335. int upCount = 0;
  336. stopNumber = ((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.FindAll(p => p.code == -1 && p.upload_Msg == "暂停上传").Count;
  337. if (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count > 0)
  338. {
  339. upCount = (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count);
  340. totalCount = ((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count;
  341. processBar = (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count * 100 / ((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count);
  342. }
  343. if(((ListViewItem)mod).Tag == model)
  344. {
  345. frmFileImportModel tempModel = (frmFileImportModel)model;
  346. bStartBind = tempModel.local_Path.FindAll(p => p.code == 0).Count > 0;
  347. errorNumber = tempModel.local_Path.FindAll(p => p.code == -1 && p.upload_Msg != "暂停上传").Count;
  348. ((ListViewItem)mod).SubItems[1].Text = processBar + "%";
  349. ((ListViewItem)mod).SubItems[2].Text = (errorNumber > 0 ? "报错数:" + errorNumber : stopNumber > 0 ? "暂停上传" : processBar < 100 ? "传输" : "完成")+"("+ (upCount + "/" + totalCount) + ")";
  350. }
  351. if (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count == 0)
  352. {
  353. ((ListViewItem)mod).SubItems[1].Text = "没有找到本地文件,传输失败";
  354. }
  355. else if (processBar < 100)
  356. {
  357. if (model != null)
  358. {
  359. ((ListViewItem)mod).SubItems[2].Text = (stopNumber > 0 ? "暂停上传" : ((frmFileImportModel)model).errorMsg != "正在上传" ? "传输" : ((frmFileImportModel)model).errorMsg) + "(" + (upCount + "/" + totalCount) + ")";
  360. }
  361. }
  362. else if (processBar >= 100)
  363. {
  364. //((ListViewItem)mod).SubItems[2].Text = "完成";
  365. }
  366. }
  367. BindDeleteButtonShowOrHide();
  368. }
  369. /// <summary>
  370. /// 数据重新绑定
  371. /// </summary>
  372. /// <param name="groupList"></param>
  373. public void LoadDataInfo(List<frmFileImportModel> groupList)
  374. {
  375. this.listViewEx1.Items.Clear();
  376. this.listViewEx1.Groups.Clear();
  377. bool bStartBind = false;
  378. int processBar=0;
  379. int errorNumber=0;
  380. int upCount = 0;
  381. int totalCount = 0;
  382. for (int i = 0; i < groupList.Count; i++)
  383. {
  384. bStartBind = groupList[i].local_Path.FindAll(p => p.code <= 0).Count > 0;
  385. if (groupList[i].local_Path.Count > 0)
  386. {
  387. upCount = groupList[i].local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count;
  388. totalCount = groupList[i].local_Path.Count;
  389. processBar = (groupList[i].local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count * 100 / groupList[i].local_Path.Count);
  390. }
  391. else
  392. {
  393. processBar=-1;
  394. }
  395. errorNumber = groupList[i].local_Path.FindAll(p => p.code == -1 && p.upload_Msg != "暂停上传").Count;
  396. if (bStartBind)
  397. {
  398. ListViewItem group = new ListViewItem(new string[]{
  399. "订单号:" + groupList[i].erpOrder.Ord_SinceOrderNumber + " ["+groupList[i].cusName + "] " + groupList[i].takenName + "[" + groupList[i]. directoryTypeDis() + "]" + "组上传",
  400. processBar==-1?"没有找到本地文件,传输失败":processBar+"%",
  401. (errorNumber > 0 ? "报错数:" + errorNumber : groupList[i].errorMsg)
  402. +"("+ (upCount+"/"+totalCount)+")"
  403. });
  404. group.Tag = groupList[i];
  405. this.listViewEx1.Items.Add(group);
  406. }
  407. }
  408. BindDeleteButtonShowOrHide();
  409. /*pan_UpfileData.Controls.Clear();
  410. for(int i=0;i<groupList.Count;i++)
  411. {
  412. UCGroupItems group = new UCGroupItems();
  413. pan_UpfileData.Controls.Add(group);
  414. group.GroupNameText = groupList[i].takenName;
  415. for (int q = 0; q < groupList[i].local_Path.Count; q++)
  416. {
  417. UCItems item = new UCItems(groupList[i].local_Path[q].local_Path, 0);
  418. group.Add(item);
  419. }
  420. }*/
  421. }
  422. private void tb_LogInfo_Click(object sender, EventArgs e)
  423. {
  424. string[] files = Directory.GetFiles(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "/Logs/ImportThread/");
  425. frmMultipleFileLogs frmLog = new frmMultipleFileLogs();
  426. frmLog.LoadFileList(files);
  427. frmLog.Show();
  428. }
  429. }
  430. }