123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace UAS_DXFORM
- {
- public partial class Form1 : Form
- {
- DataHelper dh;
- DataTable dtoracle;
- DataTable drsqlserver;
- DBHandler sql;
- LogStringBuilder sqlmessage = new LogStringBuilder();
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- dh = new DataHelper();
- sql = new DBHandler("messvr", "vManage", "sa", "Sadxmfg@888");
- 提示.ShowBalloonTip(30, "提示", "程序启动", ToolTipIcon.Info);
- dtoracle = new DataTable();
- drsqlserver = new DataTable();
- Timer.Enabled = true;
- Timer.Interval = 60000;
- Timer.Start();
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- try
- {
- sqlmessage.Clear();
- string sqlinfo = "";
- List<string> str = new List<string>();
- 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");
- if (dtoracle.Rows.Count > 0)
- {
- for (int i = 0; i < dtoracle.Rows.Count; i++)
- {
- string ban_barcode = dtoracle.Rows[i]["ban_barcode"].ToString();
- string ban_prodcode = dtoracle.Rows[i]["ban_prodcode"].ToString();
- string ve_name = dtoracle.Rows[i]["ve_name"].ToString();
- string pr_spec = dtoracle.Rows[i]["pr_spec"].ToString();
- string pr_orispeccode = dtoracle.Rows[i]["pr_orispeccode"].ToString();
- string ban_qty = dtoracle.Rows[i]["ban_qty"].ToString();
- string ban_remark = dtoracle.Rows[i]["ban_remark"].ToString();
- string ban_inman = dtoracle.Rows[i]["ban_inman"].ToString();
- string pr_brand = dtoracle.Rows[i]["pr_brand"].ToString();
- string lotcode = dtoracle.Rows[i]["lotcode"].ToString();
- str.Add(ban_barcode);
- sqlmessage.Append(" MERGE INTO Complist A using (SELECT '" + ban_barcode + "' CompID,'" + ban_prodcode + "' CompName,'" + ban_qty + "' Amount ) AS B on ");
- 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);");
- sql.doUpdate(sqlmessage.GetString(), ref sqlinfo);
- sqlmessage.Clear();
- sqlmessage.Append("MERGE INTO ComponentTrace A using (SELECT '" + ban_barcode + "' CompID,'" + ban_prodcode + "' CompName,'" + ban_qty + "' Amount,'"+ ban_inman + "' OperatorID,'" + pr_orispeccode + "' MnfPartNo");
- sqlmessage.Append(",'" + ban_remark + "' MnfDate,'" + pr_brand + "' Manufacturer,'" + ve_name + "' Supplier,'" + lotcode + "' LotNo,'" + pr_spec + "' Remark ) AS B on");
- 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 ");
- 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());");
- sql.doUpdate(sqlmessage.GetString(), ref sqlinfo);
- dh.UpdateByCondition("BarAcceptNotify", "ban_ifup = 'Y'", "ban_barcode = '" + ban_barcode + "'");
- }
- }
- if (str.Count > 0)
- {
- LogManager.DoLog(str, "下列条码已同步");
- Console.WriteLine("下列条码已同步");
- }
- dh.Dispose();
- if (sql.localConnection != null)
- {
- sql.localConnection.Close();
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- LogManager.DoLog(ex.Message);
- if (dh != null)
- {
- dh.Dispose();
- }
- if (sql.localConnection != null)
- {
- sql.localConnection.Close();
- }
- }
- }
- private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Timer.Stop();
- if (dh != null)
- {
- dh.Dispose();
- }
- if (sql != null)
- {
- sql.localConnection.Close();
- }
- 提示.ShowBalloonTip(30, "提示", "程序关闭", ToolTipIcon.Info);
- Close();
- }
- }
- }
|