ParamSetting.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 UAS_LabelMachine.PublicMethod;
  8. using System.Windows.Forms;
  9. using UAS_LabelMachine.CustomControl;
  10. using UAS_LabelMachine.Entity;
  11. namespace UAS_LabelMachine
  12. {
  13. public partial class ParamSetting : Form
  14. {
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. SqliteDBHelper dbhelper;
  17. DataTable COMINFO;
  18. DataTable plcinstruct;
  19. DataTable DataExtra;
  20. public ParamSetting()
  21. {
  22. InitializeComponent();
  23. }
  24. private void ParamSetting_SizeChanged(object sender, EventArgs e)
  25. {
  26. asc.controlAutoSize(this);
  27. }
  28. private void ParamSetting_Load(object sender, EventArgs e)
  29. {
  30. dbhelper = SystemInf.adh;
  31. loaddata();
  32. }
  33. private void loaddata()
  34. {
  35. COMINFO = (DataTable)dbhelper.ExecuteSql("select * from COMINFO order by ID asc", "select");
  36. if (COMINFO.Rows.Count == 0)
  37. {
  38. for (int i = 1; i < 6; i++)
  39. {
  40. dbhelper.ExecuteSql("insert into COMINFO(ID)values(" + i + ")", "insert");
  41. }
  42. COMINFO = (DataTable)dbhelper.ExecuteSql("select * from COMINFO order by ID asc", "select");
  43. }
  44. for (int i = 1; i < 6; i++)
  45. {
  46. Controls["GP"].Controls["GP"+i].Controls["COM" + i].Text = COMINFO.Rows[i - 1]["COM"].ToString();
  47. Controls["GP"].Controls["GP" + i].Controls["BaudRate" + i].Text = COMINFO.Rows[i - 1]["BaudRate"].ToString();
  48. Controls["GP"].Controls["GP" + i].Controls["Datawait" + i].Text = COMINFO.Rows[i - 1]["Datawait"].ToString();
  49. if (Controls["GP"].Controls["GP" + i].Controls["OutTime" + i] != null)
  50. {
  51. Controls["GP"].Controls["GP" + i].Controls["OutTime" + i].Text = COMINFO.Rows[i - 1]["OutTime"].ToString();
  52. }
  53. }
  54. plcinstruct = (DataTable)dbhelper.ExecuteSql("select * from plcinstruct order by ID asc", "select");
  55. if (plcinstruct.Rows.Count == 0)
  56. {
  57. dbhelper.ExecuteSql("insert into plcinstruct(ID)values(1)", "insert");
  58. plcinstruct = (DataTable)dbhelper.ExecuteSql("select * from plcinstruct order by ID asc", "select");
  59. }
  60. BaseUtil.SetFormValue(this.Controls, plcinstruct);
  61. DataExtra = (DataTable)dbhelper.ExecuteSql("select * from DataExtra order by ID asc", "select");
  62. if (DataExtra.Rows.Count == 0)
  63. {
  64. dbhelper.ExecuteSql("insert into DataExtra(ID)values(1)", "insert");
  65. DataExtra = (DataTable)dbhelper.ExecuteSql("select * from DataExtra order by ID asc", "select");
  66. }
  67. BaseUtil.SetFormValue(this.Controls, DataExtra);
  68. }
  69. private void Save_Click(object sender, EventArgs e)
  70. {
  71. dbhelper.ExecuteSql("delete from COMINFO", "delete");
  72. dbhelper.ExecuteSql("delete from plcinstruct", "delete");
  73. dbhelper.ExecuteSql("delete from DataExtra", "delete");
  74. for (int i = 1; i < 6; i++)
  75. {
  76. COMINFO.Rows[i - 1]["COM"] = Controls["GP"].Controls["GP" + i].Controls["COM" + i].Text;
  77. COMINFO.Rows[i - 1]["COMTYPE"] = Controls["GP"].Controls["GP" + i].Controls["COM" + i].Tag.ToString();
  78. COMINFO.Rows[i - 1]["BaudRate"]= Controls["GP"].Controls["GP" + i].Controls["BaudRate" + i].Text ;
  79. COMINFO.Rows[i - 1]["Datawait"]=Controls["GP"].Controls["GP" + i].Controls["Datawait" + i].Text ;
  80. if (Controls["GP"].Controls["GP" + i].Controls["OutTime" + i] != null)
  81. {
  82. COMINFO.Rows[i - 1]["OutTime"]= Controls["GP"].Controls["GP" + i].Controls["OutTime" + i].Text;
  83. }
  84. }
  85. dbhelper.SaveDataTable( COMINFO, "COMINFO");
  86. for (int i = 0; i < Controls["GPD1"].Controls.Count; i++)
  87. {
  88. if (Controls["GPD1"].Controls[i] is EnterTextBox)
  89. {
  90. plcinstruct.Rows[0][Controls["GPD1"].Controls[i].Name] = Controls["GPD1"].Controls[i].Text;
  91. }
  92. }
  93. dbhelper.SaveDataTable(plcinstruct,"plcinstruct");
  94. for (int i = 0; i < Controls["GPD2"].Controls.Count; i++)
  95. {
  96. if (Controls["GPD2"].Controls[i] is EnterTextBox)
  97. {
  98. DataExtra.Rows[0][Controls["GPD2"].Controls[i].Name] = Controls["GPD2"].Controls[i].Text;
  99. }
  100. }
  101. dbhelper.SaveDataTable(DataExtra,"DataExtra");
  102. MessageBox.Show("保存成功");
  103. }
  104. }
  105. }