Form1.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 UAS_DXFORM
  10. {
  11. public partial class Form1 : Form
  12. {
  13. DataHelper dh;
  14. DataTable dtoracle;
  15. DataTable drsqlserver;
  16. DBHandler sql;
  17. LogStringBuilder sqlmessage = new LogStringBuilder();
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22. private void Form1_Load(object sender, EventArgs e)
  23. {
  24. dh = new DataHelper();
  25. sql = new DBHandler("messvr", "vManage", "sa", "Sadxmfg@888");
  26. 提示.ShowBalloonTip(30, "提示", "程序启动", ToolTipIcon.Info);
  27. dtoracle = new DataTable();
  28. drsqlserver = new DataTable();
  29. Timer.Enabled = true;
  30. Timer.Interval = 60000;
  31. Timer.Start();
  32. }
  33. private void Timer_Tick(object sender, EventArgs e)
  34. {
  35. try
  36. {
  37. sqlmessage.Clear();
  38. string sqlinfo = "";
  39. List<string> str = new List<string>();
  40. dtoracle = (DataTable)dh.ExecuteSql("select ban_barcode,ban_prodcode,ve_name,substr(pr_spec,0,64) pr_spec,nvl(substr(pr_orispeccode,0,64),substr(pr_custprodcode,0,64)) pr_orispeccode,ban_qty,ban_remark,ban_inman,pr_brand,lotcode from BarAcceptNotify left join vendor on ban_vendcode=ve_code left join product on ban_prodcode=pr_code where nvl(ban_canup,'N') = 'Y' and nvl(ban_ifup,'N') = 'N'", "select");
  41. if (dtoracle.Rows.Count > 0)
  42. {
  43. for (int i = 0; i < dtoracle.Rows.Count; i++)
  44. {
  45. string ban_barcode = dtoracle.Rows[i]["ban_barcode"].ToString();
  46. string ban_prodcode = dtoracle.Rows[i]["ban_prodcode"].ToString();
  47. string ve_name = dtoracle.Rows[i]["ve_name"].ToString();
  48. string pr_spec = dtoracle.Rows[i]["pr_spec"].ToString();
  49. string pr_orispeccode = dtoracle.Rows[i]["pr_orispeccode"].ToString();
  50. string ban_qty = dtoracle.Rows[i]["ban_qty"].ToString();
  51. string ban_remark = dtoracle.Rows[i]["ban_remark"].ToString();
  52. string ban_inman = dtoracle.Rows[i]["ban_inman"].ToString();
  53. string pr_brand = dtoracle.Rows[i]["pr_brand"].ToString();
  54. string lotcode = dtoracle.Rows[i]["lotcode"].ToString();
  55. str.Add(ban_barcode);
  56. sqlmessage.Append(" MERGE INTO Complist A using (SELECT '" + ban_barcode + "' CompID,'" + ban_prodcode + "' CompName,'" + ban_qty + "' Amount ) AS B on ");
  57. sqlmessage.Append(" (A.CompID = B.CompID) WHEN MATCHED THEN UPDATE SET A.CompName = B.CompName,A.Amount = B.Amount WHEN NOT MATCHED THEN INSERT (CompID,CompName,Amount)VALUES(B.CompID,B.CompName,B.Amount);");
  58. sql.doUpdate(sqlmessage.GetString(), ref sqlinfo);
  59. sqlmessage.Clear();
  60. sqlmessage.Append("MERGE INTO ComponentTrace A using (SELECT '" + ban_barcode + "' CompID,'" + ban_prodcode + "' CompName,'" + ban_qty + "' Amount,'"+ ban_inman + "' OperatorID,'" + pr_orispeccode + "' MnfPartNo");
  61. sqlmessage.Append(",'" + ban_remark + "' MnfDate,'" + pr_brand + "' Manufacturer,'" + ve_name + "' Supplier,'" + lotcode + "' LotNo,'" + pr_spec + "' Remark ) AS B on");
  62. sqlmessage.Append(" (A.CompID = B.CompID) WHEN MATCHED THEN UPDATE SET A.CompName = B.CompName,A.Amount = B.Amount,A.OperatorID = B.OperatorID ,A.MnfPartNo = B.MnfPartNo ,A.MnfDate = B.MnfDate ,A.Manufacturer = B.Manufacturer ,A.Supplier = B.Supplier ,A.LotNo = B.LotNo ,A.Remark = B.Remark ");
  63. sqlmessage.Append("WHEN NOT MATCHED THEN INSERT (CompID,CompName,Amount,OperatorID,MnfPartNo,MnfDate,Manufacturer,Supplier,LotNo,Remark,ReceiveDate)VALUES(B.CompID,B.CompName,B.Amount,B.OperatorID,B.MnfPartNo,B.MnfDate,B.Manufacturer,B.Supplier,B.LotNo,B.Remark,getdate());");
  64. sql.doUpdate(sqlmessage.GetString(), ref sqlinfo);
  65. dh.UpdateByCondition("BarAcceptNotify", "ban_ifup = 'Y'", "ban_barcode = '" + ban_barcode + "'");
  66. }
  67. }
  68. if (str.Count > 0)
  69. {
  70. LogManager.DoLog(str, "下列条码已同步");
  71. Console.WriteLine("下列条码已同步");
  72. }
  73. dh.Dispose();
  74. if (sql.localConnection != null)
  75. {
  76. sql.localConnection.Close();
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. Console.WriteLine(ex.Message);
  82. LogManager.DoLog(ex.Message);
  83. if (dh != null)
  84. {
  85. dh.Dispose();
  86. }
  87. if (sql.localConnection != null)
  88. {
  89. sql.localConnection.Close();
  90. }
  91. }
  92. }
  93. private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
  94. {
  95. Timer.Stop();
  96. if (dh != null)
  97. {
  98. dh.Dispose();
  99. }
  100. if (sql != null)
  101. {
  102. sql.localConnection.Close();
  103. }
  104. 提示.ShowBalloonTip(30, "提示", "程序关闭", ToolTipIcon.Info);
  105. Close();
  106. }
  107. }
  108. }