PowerSetting.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_LabelMachine.Entity;
  7. namespace UAS_LabelMachine
  8. {
  9. public partial class PowerSetting : Form
  10. {
  11. public PowerSetting()
  12. {
  13. InitializeComponent();
  14. }
  15. DataHelper dh;
  16. DataTable dt;
  17. string condition = "";
  18. private void PowerSetting_Load(object sender, EventArgs e)
  19. {
  20. dh = SystemInf.dh;
  21. LoadData();
  22. }
  23. private void SaveGrid_Click(object sender, EventArgs e)
  24. {
  25. dt = ((DataTable)PowerSetDGV.DataSource).GetChanges();
  26. StringBuilder sql = new StringBuilder();
  27. List<string> SQLS = new List<string>();
  28. for (int i = 0; i < dt.Rows.Count; i++)
  29. {
  30. sql.Clear();
  31. sql.Append("MERGE INTO labelprintpower alias1 USING (select '" + dt.Rows[i]["em_code"].ToString() + "' em_code from dual) alias2 ");
  32. sql.Append("ON (alias1.lpp_emcode=alias2.em_code) WHEN MATCHED THEN UPDATE SET lpp_manual = '" + dt.Rows[i]["lpp_manual"].ToString() + "', ");
  33. sql.Append("lpp_cleandetail = '" + dt.Rows[i]["lpp_cleandetail"].ToString() + "' WHEN NOT MATCHED THEN INSERT (lpp_id,lpp_emcode,lpp_manual) VALUES (labelprintpower_seq.nextval,");
  34. sql.Append(" '" + dt.Rows[i]["em_code"].ToString() + "', '" + dt.Rows[i]["lpp_manual"].ToString() + "')");
  35. SQLS.Add(sql.ToString());
  36. }
  37. dh.ExecuteSQLTran(SQLS.ToArray());
  38. LoadData();
  39. }
  40. private void LoadData()
  41. {
  42. string sql = "select em_code,em_name,lpp_id,lpp_emcode,lpp_manual,lpp_cleandetail from employee left join labelprintpower on em_code = lpp_emcode " + condition;
  43. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  44. BaseUtil.FillDgvWithDataTable(PowerSetDGV, dt);
  45. }
  46. private void Screen_Click(object sender, EventArgs e)
  47. {
  48. condition = BaseUtil.GetScreenSqlCondition(em_code, em_name);
  49. LoadData();
  50. }
  51. }
  52. }