Special_SmtLocation.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.Threading;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicForm;
  13. using UAS_MES_NEW.PublicMethod;
  14. namespace UAS_MES_NEW.Special
  15. {
  16. public partial class Special_SmtLocation : Form
  17. {
  18. DataHelper dh;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. DataTable dt = new DataTable();
  21. DataTable dbfind;
  22. ExcelHandler eh;
  23. DataTable dbbom;
  24. Thread thread;
  25. public Special_SmtLocation()
  26. {
  27. InitializeComponent();
  28. }
  29. private void Special_BoxSplit_Load(object sender, EventArgs e)
  30. {
  31. eh = new ExcelHandler();
  32. dh = SystemInf.dh;
  33. }
  34. private void Pr_code_DbChange(object sender, EventArgs e)
  35. {
  36. BaseUtil.SetFormValue(this.Controls, dbfind);
  37. }
  38. private void normalButton2_Click(object sender, EventArgs e)
  39. {
  40. DialogResult result = openFileDialog1.ShowDialog();
  41. if (result == DialogResult.OK)
  42. {
  43. textBox1.Text = openFileDialog1.FileName;
  44. }
  45. }
  46. //创建打印进程
  47. private void NewPrint()
  48. {
  49. try
  50. {
  51. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  52. int number = 0;
  53. List<string> snlist = new List<string>();
  54. List<string> imei1list = new List<string>();
  55. List<string> imei2list = new List<string>();
  56. List<string> btlist = new List<string>();
  57. List<string> wifilist = new List<string>();
  58. for (int i = 0; i < dt.Rows.Count; i++)
  59. {
  60. if ( dt.Rows[i]["SN"].ToString().Trim().Length > 2 && dt.Rows[i]["IMEI1"].ToString().Trim().Length > 2 )
  61. {
  62. snlist.Add(dt.Rows[i]["SN"].ToString().Trim());
  63. imei1list.Add(dt.Rows[i]["IMEI1"].ToString().Trim());
  64. imei2list.Add(dt.Rows[i]["IMEI2"].ToString().Trim());
  65. btlist.Add(dt.Rows[i]["BT"].ToString().Trim());
  66. wifilist.Add(dt.Rows[i]["WIFI"].ToString().Trim());
  67. number++;
  68. }
  69. // dh.ExecuteSql("MERGE INTO SNIMEI a USING ( SELECT '" + dt.Rows[i]["SN"].ToString() + "' as SN FROM dual ) b ON (a.SN = b.SN) WHEN MATCHED THEN UPDATE SET a.IMEI1 = '" + dt.Rows[i]["IMEI1"].ToString() + "', a.IMEI2 = '" + dt.Rows[i]["IMEI2"].ToString() + "',a.BT = '" + dt.Rows[i]["BT"].ToString() + "', a.WIFI = '" + dt.Rows[i]["WIFI"].ToString() + "' WHEN NOT MATCHED THEN INSERT (a.SN, a.IMEI1, a.IMEI2,a.BT, a.WIFI) VALUES ('" + dt.Rows[i]["SN"].ToString() + "', '" + dt.Rows[i]["IMEI1"].ToString() + "', '" + dt.Rows[i]["IMEI2"].ToString() + "','" + dt.Rows[i]["BT"].ToString() + "','" + dt.Rows[i]["WIFI"].ToString() + "')", "insert");
  70. }
  71. sql.Clear();
  72. sql.Append("insert into SNIMEI_TEMP(ST_SN,ST_IMEI1,ST_IMEI2,ST_BT,ST_WIFI)");
  73. sql.Append("values(:sn,:imei1,:imei2,:bt,:wifi)");
  74. dh.BatchInsert(sql.GetString(), new string[] { "sn", "imei1", "imei2", "bt", "wifi" }, snlist.ToArray(), imei1list.ToArray(), imei2list.ToArray(), btlist.ToArray(), wifilist.ToArray());
  75. sql.Clear();
  76. sql.Append("merge into SNIMEI using SNIMEI_TEMP on (ST_SN = SN) when MATCHED then UPDATE set IMEI1 = ST_IMEI1,IMEI2=ST_IMEI2,BT=ST_BT,WIFI=ST_WIFI,SDATE = SYSDATE when not MATCHED then insert (SN, IMEI1, IMEI2,BT, WIFI,SDATE)");
  77. sql.Append(" values (ST_SN,ST_IMEI1,ST_IMEI2,ST_BT,ST_WIFI,SYSDATE)");
  78. dh.ExecuteSql(sql.GetString(), "insert");
  79. dh.ExecuteSql("delete SNIMEI_TEMP", "delete");
  80. MessageBox.Show("导入成功!记录:" + dt.Rows.Count + "行");
  81. }
  82. catch (Exception ex)
  83. {
  84. MessageBox.Show(ex.Message);
  85. }
  86. }
  87. private void normalButton3_Click(object sender, EventArgs e)
  88. {
  89. if (textBox1.Text == "")
  90. {
  91. MessageBox.Show("文件地址不可为空");
  92. return;
  93. }
  94. dt = eh.ImportExcel(textBox1.Text, "IMEI");
  95. thread = new Thread(NewPrint);
  96. SetLoadingWindow stw = new SetLoadingWindow(thread, "请稍候...");
  97. BaseUtil.SetFormCenter(stw);
  98. stw.ShowDialog();
  99. //for (int i = 0; i < dt.Rows.Count; i++)
  100. //{
  101. // MessageBox.Show(dt.Rows[i]["RefDes"].ToString()+":"+ dt.Rows[i]["Layer"].ToString());
  102. //}
  103. }
  104. }
  105. }