Form2.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using cuidian.Sql;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using TempDbToUfida;
  12. using TempDbToUfida.OpenApi;
  13. using WangToTempDb;
  14. using YiLvRunFrom.BLL;
  15. using YiLvRunFrom.Dal;
  16. namespace YiLvRunFrom
  17. {
  18. public delegate List<Model.WdtLogs> OneDel(string one);
  19. public delegate bool BoolDel();
  20. public partial class Form2 : Form
  21. {
  22. public Form2()
  23. {
  24. InitializeComponent();
  25. _init();
  26. }
  27. private void _init()
  28. {
  29. //comboBox1.Items.Add("供应商");
  30. //comboBox1.Items.Add("仓库");
  31. comboBox1.Items.Add("存货");
  32. comboBox1.Items.Add("其他入库");
  33. comboBox1.Items.Add("其他出库");
  34. comboBox1.Items.Add("采购订单");
  35. comboBox1.Items.Add("采购入库");
  36. comboBox1.Items.Add("采购退货");
  37. comboBox1.Items.Add("销售订单");
  38. comboBox1.Items.Add("销售出库");
  39. comboBox1.Items.Add("库存");
  40. }
  41. private void LoadList()
  42. {
  43. dgvList.AutoGenerateColumns = false;
  44. dgvList.DataSource = new WdtLosBll().GetList();
  45. }
  46. private List<Model.WdtLogs> LoadList(string typeStr)
  47. {
  48. dgvList.AutoGenerateColumns = false;
  49. List<Model.WdtLogs> wdtList = new WdtLosBll().GetList(typeStr);
  50. dgvList.DataSource = wdtList;
  51. return wdtList;
  52. }
  53. //key:start_time value:2019-08-27 00:00:01 key:end_time value:2019 - 08 - 27 22: 29:41 key:page_no value:0 key:page_size value:100 、
  54. //string[] arrs = str.Split(new string[] { "key:", "value:" }, StringSplitOptions.RemoveEmptyEntries);
  55. private void button1_Click(object sender, EventArgs e)
  56. {
  57. IUpLoad upload = null;
  58. IDownLoad download = null;
  59. Dictionary<string, string> args = new Dictionary<string, string>();
  60. if (comboBox1.SelectedItem == null)
  61. {
  62. MessageBox.Show("请选择数据类型");//OneDel oneDel =LoadList;
  63. }
  64. else if (comboBox1.SelectedItem.ToString() == "存货")
  65. {
  66. upload = new InventoryUpLoad();
  67. download = new DownLoadInventory();
  68. OneDel oneDel = LoadList;
  69. DisposeLogs(oneDel, "存货", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalDays > 30));
  70. }
  71. else if (comboBox1.SelectedItem.ToString() == "其他入库")
  72. {
  73. upload = new StockinUpLoad();
  74. download = new DownLoadOtherin();
  75. OneDel oneDel = LoadList;
  76. DisposeLogs(oneDel, "其他入库", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalDays > 30));
  77. }
  78. else if (comboBox1.SelectedItem.ToString() == "其他出库")
  79. {
  80. upload = new StockoutUpLoad();
  81. download = new DownLoadOtherout();
  82. OneDel oneDel = LoadList;
  83. DisposeLogs(oneDel, "其他出库", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalDays > 30));
  84. }
  85. else if (comboBox1.SelectedItem.ToString() == "采购订单")
  86. {
  87. upload = new PO_PomainUpLoad();
  88. download = new DownLoadPurchaseorder();
  89. OneDel oneDel = LoadList;
  90. DisposeLogs(oneDel, "采购订单", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalDays > 30));
  91. }
  92. else if (comboBox1.SelectedItem.ToString() == "采购入库")
  93. {
  94. upload = new InvoiceItemaUpLoad();
  95. download = new DownLoadPurchasein();
  96. OneDel oneDel = LoadList;
  97. args["status"] = "60";
  98. DisposeLogs(oneDel, "采购入库", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalDays > 30));
  99. }
  100. else if (comboBox1.SelectedItem.ToString() == "采购退货")
  101. {
  102. upload = new PurchaseUpLoad();
  103. download = new DownLoadPurchasereturn();
  104. OneDel oneDel = LoadList;
  105. DisposeLogs(oneDel, "采购退货", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalDays > 30));
  106. }
  107. else if (comboBox1.SelectedItem.ToString() == "销售出库")
  108. {
  109. upload = new DispatchListUpLoad();
  110. download = new DownLoadReturnorder();
  111. OneDel oneDel = LoadList;
  112. DisposeLogs(oneDel, "销售出库", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalDays > 30));
  113. }
  114. //else if (comboBox1.SelectedItem.ToString() == "销售订单")
  115. //{
  116. // upload = new TradeUpLoad();
  117. // download = new DownLoadSaleorder();
  118. // OneDel oneDel = LoadList;
  119. // DisposeLogs(oneDel, "销售订单", upload, download, args, () => (Convert.ToDateTime(args["start_time"]) > Convert.ToDateTime(args["end_time"])) || (Convert.ToDateTime(args["end_time"]) > DateTime.Now) || (Convert.ToDateTime(args["end_time"]).Subtract(Convert.ToDateTime(args["start_time"])).TotalHours > 1));
  120. //}
  121. else if(comboBox1.SelectedItem.ToString() == "库存")
  122. {
  123. MessageBox.Show("库存无需处理");
  124. }
  125. }
  126. /// <summary>
  127. /// 委托处理错误日志类
  128. /// </summary>
  129. /// <param name="one"></param>
  130. /// <param name="oneStr"></param>
  131. /// <param name="upload"></param>
  132. /// <param name="download"></param>
  133. private void DisposeLogs(OneDel one, string oneStr, IUpLoad upload, IDownLoad download, Dictionary<string, string> args, BoolDel getFlag)
  134. {
  135. button1.Text = "正在处理" + oneStr;
  136. List<Model.WdtLogs> inventoryList = one(oneStr);
  137. if (inventoryList.Count == 0)
  138. {
  139. MessageBox.Show("该数据类型没有遗漏及错误");
  140. }
  141. else
  142. {
  143. //upload = new InventoryUpLoad();
  144. //download = new DownLoadInventory();
  145. List<int> sysids = new List<int>();
  146. foreach (Model.WdtLogs item in inventoryList)
  147. {
  148. sysids.Add(item.SysId);
  149. string[] arrs = item.Args.Split(new string[] { "key:", "value:" }, StringSplitOptions.RemoveEmptyEntries);
  150. //时间中不能含有空格,convert用于去除空格,不可删2019-09-01 00:00:00
  151. try
  152. {
  153. args["start_time"] = Convert.ToDateTime(arrs[5]).ToString(); //arrs[1];
  154. args["end_time"] = Convert.ToDateTime(arrs[7]).ToString(); //arrs[3];
  155. }
  156. catch
  157. {
  158. args["start_time"] = Convert.ToDateTime(arrs[1]).ToString(); //arrs[1];
  159. args["end_time"] = Convert.ToDateTime(arrs[3]).ToString(); //arrs[3];
  160. }
  161. if (getFlag())
  162. {
  163. continue;
  164. }
  165. upload.UpLoad(args);
  166. if (oneStr == "销售出库")
  167. {
  168. IUpLoad uploadTwo = new DispatchListSendUpLoad();
  169. uploadTwo.UpLoad(args);
  170. }
  171. }
  172. download.DownLoad();
  173. string deleteStr = string.Join(",", sysids);
  174. TimeDal.deleteErr(deleteStr);
  175. //LoadList("存货");
  176. one(oneStr);
  177. MessageBox.Show(oneStr + "处理成功");
  178. button1.Text = "处理错误";
  179. }
  180. }
  181. private void Form2_Load(object sender, EventArgs e)
  182. {
  183. LoadList();
  184. }
  185. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  186. {
  187. if (comboBox1.SelectedItem.ToString() == "存货")
  188. {
  189. LoadList("存货");
  190. }
  191. else if (comboBox1.SelectedItem.ToString() == "其他入库")
  192. {
  193. LoadList("其他入库");
  194. }
  195. else if (comboBox1.SelectedItem.ToString() == "其他出库")
  196. {
  197. LoadList("其他出库");
  198. }
  199. else if (comboBox1.SelectedItem.ToString() == "采购入库")
  200. {
  201. LoadList("采购入库");
  202. }
  203. else if (comboBox1.SelectedItem.ToString() == "采购订单")
  204. {
  205. LoadList("采购订单");
  206. }
  207. else if (comboBox1.SelectedItem.ToString() == "采购退货")
  208. {
  209. LoadList("采购退货");
  210. }
  211. //else if (comboBox1.SelectedItem.ToString() == "销售订单")
  212. //{
  213. // LoadList("销售订单");
  214. //}
  215. else if (comboBox1.SelectedItem.ToString() == "销售出库")
  216. {
  217. LoadList("销售出库");
  218. }
  219. else if (comboBox1.SelectedItem.ToString() == "库存")
  220. {
  221. LoadList("库存");
  222. }
  223. }
  224. private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
  225. {
  226. foreach (DataGridViewRow dgvRow in dgvList.SelectedRows)
  227. {
  228. DbUtils.ExecuteNonQuery(string.Format("delete from wdtlogs where sysid='{0}'", dgvRow.Cells[0].Value), ConnectionUtils.Instance.GetConnection("TempDB"));
  229. //dgvList.Rows.Remove(dgvRow);
  230. }
  231. if (comboBox1.SelectedItem.ToString() != null)
  232. {
  233. LoadList(comboBox1.SelectedItem.ToString());
  234. }
  235. else
  236. {
  237. MessageBox.Show("未选择数据类型");
  238. }
  239. }
  240. private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
  241. {
  242. }
  243. }
  244. }