frmFTPFileImprot.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using LYFZ.ComponentLibrary;
  2. using LYFZ.Network.FTPOperation;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. namespace LYFZ.Software.MainBusiness.MultipleFileImport
  12. {
  13. public partial class frmFTPFileImprot : LYFZ.ComponentLibrary.BaseContentsFormMain
  14. {
  15. Timer timer;
  16. public frmFTPFileImprot()
  17. {
  18. InitializeComponent();
  19. this.Shown += frmFTPFileImprot_Shown;
  20. this.btn_Refresh.Click += btn_Refresh_Click;
  21. radio_None.Click += radio_Click;
  22. radio_fiveRef.Click += radio_Click;
  23. radio_thirdRef.Click += radio_Click;
  24. btn_Start.Click += btn_StartOrStop_Click;
  25. btn_Stop.Click += btn_StartOrStop_Click;
  26. timer = new Timer();
  27. timer.Tick += timer_Tick;
  28. }
  29. void btn_StartOrStop_Click(object sender, EventArgs e)
  30. {
  31. if(this.lv_StatusList.SelectedItems.Count>0)
  32. {
  33. ListViewItem lvi = this.lv_StatusList.SelectedItems[0];
  34. UpFTPServiceFileGroup group = lvi.Tag as UpFTPServiceFileGroup;
  35. CommandData command = new CommandData();
  36. command.CommandType = "S";
  37. command.bUpfileCode = Convert.ToInt32(((ButtonEx)sender).Tag);
  38. command.dirTypeData = group.GuidKey;
  39. HPSocketCS.Extended.RequestData requestData = new HPSocketCS.Extended.RequestData((int)LYFZ.Network.TCPNetworkServer.SerializerRequestCommand.FTPCommand);
  40. requestData.AttachedMessage = Json.JsonTool.ObjectToJson(command);
  41. HPSocketCS.Extended.ReturnData returnData = HPSocketCS.Extended.SerializerDataProcessed.HP_SendSerializerCommandToServer(requestData);
  42. if (returnData.ReturnStatus)
  43. {
  44. }
  45. }
  46. }
  47. void BindCompleteData()
  48. {
  49. try
  50. {
  51. CommandData command = new CommandData();
  52. command.CommandType = "O";
  53. HPSocketCS.Extended.RequestData requestData = new HPSocketCS.Extended.RequestData((int)LYFZ.Network.TCPNetworkServer.SerializerRequestCommand.FTPCommand);
  54. requestData.AttachedMessage = Json.JsonTool.ObjectToJson(command);
  55. HPSocketCS.Extended.ReturnData returnData = HPSocketCS.Extended.SerializerDataProcessed.HP_SendSerializerCommandToServer(requestData);
  56. if (returnData.ReturnStatus)
  57. {
  58. List<dynamic> shopList = new List<dynamic>();
  59. shopList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<dynamic>>(returnData.AttachedMessage);
  60. this.lvComplete.Items.Clear();
  61. shopList = shopList.FindAll(p => Convert.ToString(p.localShopInfo) == CommonLogical.SuccessfulLogin.CompanyName);
  62. foreach (dynamic dyObj in shopList)
  63. {
  64. ListViewGroup group = new ListViewGroup(Convert.ToString(dyObj.localShopInfo));
  65. this.lvComplete.Groups.Add(group);
  66. foreach (var mod in dyObj.Item)
  67. {
  68. ListViewItem item = new ListViewItem(new string[] { mod.Text + "", mod.StartTime + "", mod.EndTime + "" });
  69. item.Group = group;
  70. this.lvComplete.Items.Add(item);
  71. }
  72. }
  73. }
  74. }
  75. catch { }
  76. }
  77. void timer_Tick(object sender, EventArgs e)
  78. {
  79. bool b = this.Visible;
  80. if (b)
  81. {
  82. btn_Refresh_Click(null, null);
  83. }
  84. else
  85. {
  86. timer.Stop();
  87. }
  88. }
  89. /// <summary>
  90. ///
  91. /// </summary>
  92. /// <param name="sender"></param>
  93. /// <param name="e"></param>
  94. void radio_Click(object sender, EventArgs e)
  95. {
  96. RadioButtonEx radio = (RadioButtonEx)sender;
  97. if (radio.Name == "radio_None")
  98. {
  99. timer.Stop();
  100. }
  101. else if (radio.Name == "radio_fiveRef")
  102. {
  103. timer.Interval = 5000;
  104. timer.Start();
  105. }
  106. else if (radio.Name == "radio_thirdRef")
  107. {
  108. timer.Interval = 3000;
  109. timer.Start();
  110. }
  111. }
  112. int nullDataTick = 0;
  113. void btn_Refresh_Click(object sender, EventArgs e)
  114. {
  115. CommandData command = new CommandData();
  116. command.CommandType = "P";
  117. HPSocketCS.Extended.RequestData requestData = new HPSocketCS.Extended.RequestData((int)LYFZ.Network.TCPNetworkServer.SerializerRequestCommand.FTPCommand);
  118. requestData.AttachedMessage = Json.JsonTool.ObjectToJson(command);
  119. HPSocketCS.Extended.ReturnData returnData = HPSocketCS.Extended.SerializerDataProcessed.HP_SendSerializerCommandToServer(requestData);
  120. if (returnData.ReturnStatus)
  121. {
  122. List<UpFTPServiceFileShop> shopList = new List<UpFTPServiceFileShop>();
  123. shopList = (List<UpFTPServiceFileShop>)Json.JsonTool.JsonToObject(returnData.AttachedMessage, shopList);
  124. if(shopList.Count>0)
  125. {
  126. lv_StatusList.Items.Clear();
  127. lv_StatusList.Groups.Clear();
  128. nullDataTick = 0;
  129. }
  130. else
  131. {
  132. nullDataTick++;
  133. if(nullDataTick>3)
  134. {
  135. lv_StatusList.Items.Clear();
  136. lv_StatusList.Groups.Clear();
  137. }
  138. }
  139. bool bFirstStartUp = false;
  140. foreach (var shop in shopList)
  141. {
  142. ListViewGroup group = new ListViewGroup(shop.localShopInfo);
  143. lv_StatusList.Groups.Add(group);
  144. foreach (var mod in shop.items)
  145. {
  146. string statusText = "";
  147. List<UpFTPServiceFileItem> items = mod.items.FindAll(p => p.statusCode == 0 || p.statusCode == -1);
  148. if (mod.bOpenStatus == 1&&items.Count > 0)
  149. {
  150. statusText = "待上传";
  151. if (!bFirstStartUp)
  152. {
  153. statusText = "正在上传";
  154. bFirstStartUp = true;
  155. }
  156. UpFTPServiceFileItem upItem = (mod.items.Find(p => p.statusCode == 99));
  157. if (upItem != null)
  158. {
  159. statusText = "正在上传";
  160. }
  161. }
  162. else if (mod.bOpenStatus == 1 &&
  163. items.Count == 0)
  164. {
  165. statusText = "完成";
  166. }
  167. else if (mod.bOpenStatus == 0)
  168. {
  169. statusText = "暂停";
  170. }
  171. ListViewItem item = new ListViewItem(new string[] {"" + mod.OrderNumber + "(" + mod.DirFileType + "上传到——" +
  172. shop.upShopText + "(" + shop.hostPath + ":" + shop.ftpName + ")" + ")",Convert.ToSingle(mod.processValue*100/mod.totalSize).ToString("0.00")+"%",
  173. statusText});
  174. item.Group = group;
  175. item.Tag = mod;
  176. this.lv_StatusList.Items.Add(item);
  177. }
  178. }
  179. if(shopList.Count>0)
  180. {
  181. radio_Click(new RadioButtonEx() {
  182. Name = "radio_thirdRef"
  183. }, null);
  184. }
  185. else
  186. {
  187. radio_Click(new RadioButtonEx()
  188. {
  189. Name = "radio_None"
  190. }, null);
  191. }
  192. }
  193. }
  194. void frmFTPFileImprot_Shown(object sender, EventArgs e)
  195. {
  196. btn_Refresh_Click(null, null);
  197. }
  198. private void tabControlEx1_SelectedIndexChanged(object sender, EventArgs e)
  199. {
  200. if ((tabControlEx1.TabPages[tabControlEx1.SelectedIndex]).Tag==null&&(tabControlEx1.TabPages[tabControlEx1.SelectedIndex]).Text=="已完成")
  201. {
  202. (tabControlEx1.TabPages[tabControlEx1.SelectedIndex]).Tag = true;
  203. BindCompleteData();
  204. }
  205. }
  206. }
  207. }