123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using UAS_LabelMachine.PublicMethod;
- using System.Windows.Forms;
- using UAS_LabelMachine.CustomControl;
- using UAS_LabelMachine.Entity;
- namespace UAS_LabelMachine
- {
- public partial class ParamSetting : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- SqliteDBHelper dbhelper;
- DataTable COMINFO;
- DataTable plcinstruct;
- DataTable DataExtra;
- public ParamSetting()
- {
- InitializeComponent();
- }
- private void ParamSetting_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void ParamSetting_Load(object sender, EventArgs e)
- {
- dbhelper = SystemInf.adh;
- loaddata();
- }
- private void loaddata()
- {
- COMINFO = (DataTable)dbhelper.ExecuteSql("select * from COMINFO order by ID asc", "select");
- if (COMINFO.Rows.Count == 0)
- {
- for (int i = 1; i < 6; i++)
- {
- dbhelper.ExecuteSql("insert into COMINFO(ID)values(" + i + ")", "insert");
- }
- COMINFO = (DataTable)dbhelper.ExecuteSql("select * from COMINFO order by ID asc", "select");
- }
- for (int i = 1; i < 6; i++)
- {
- Controls["GP"].Controls["GP"+i].Controls["COM" + i].Text = COMINFO.Rows[i - 1]["COM"].ToString();
- Controls["GP"].Controls["GP" + i].Controls["BaudRate" + i].Text = COMINFO.Rows[i - 1]["BaudRate"].ToString();
- Controls["GP"].Controls["GP" + i].Controls["Datawait" + i].Text = COMINFO.Rows[i - 1]["Datawait"].ToString();
- if (Controls["GP"].Controls["GP" + i].Controls["OutTime" + i] != null)
- {
- Controls["GP"].Controls["GP" + i].Controls["OutTime" + i].Text = COMINFO.Rows[i - 1]["OutTime"].ToString();
- }
- }
- plcinstruct = (DataTable)dbhelper.ExecuteSql("select * from plcinstruct order by ID asc", "select");
- if (plcinstruct.Rows.Count == 0)
- {
- dbhelper.ExecuteSql("insert into plcinstruct(ID)values(1)", "insert");
- plcinstruct = (DataTable)dbhelper.ExecuteSql("select * from plcinstruct order by ID asc", "select");
- }
- BaseUtil.SetFormValue(this.Controls, plcinstruct);
- DataExtra = (DataTable)dbhelper.ExecuteSql("select * from DataExtra order by ID asc", "select");
- if (DataExtra.Rows.Count == 0)
- {
- dbhelper.ExecuteSql("insert into DataExtra(ID)values(1)", "insert");
- DataExtra = (DataTable)dbhelper.ExecuteSql("select * from DataExtra order by ID asc", "select");
- }
- BaseUtil.SetFormValue(this.Controls, DataExtra);
- }
- private void Save_Click(object sender, EventArgs e)
- {
- dbhelper.ExecuteSql("delete from COMINFO", "delete");
- dbhelper.ExecuteSql("delete from plcinstruct", "delete");
- dbhelper.ExecuteSql("delete from DataExtra", "delete");
- for (int i = 1; i < 6; i++)
- {
- COMINFO.Rows[i - 1]["COM"] = Controls["GP"].Controls["GP" + i].Controls["COM" + i].Text;
- COMINFO.Rows[i - 1]["COMTYPE"] = Controls["GP"].Controls["GP" + i].Controls["COM" + i].Tag.ToString();
- COMINFO.Rows[i - 1]["BaudRate"]= Controls["GP"].Controls["GP" + i].Controls["BaudRate" + i].Text ;
- COMINFO.Rows[i - 1]["Datawait"]=Controls["GP"].Controls["GP" + i].Controls["Datawait" + i].Text ;
- if (Controls["GP"].Controls["GP" + i].Controls["OutTime" + i] != null)
- {
- COMINFO.Rows[i - 1]["OutTime"]= Controls["GP"].Controls["GP" + i].Controls["OutTime" + i].Text;
- }
- }
- dbhelper.SaveDataTable( COMINFO, "COMINFO");
- for (int i = 0; i < Controls["GPD1"].Controls.Count; i++)
- {
- if (Controls["GPD1"].Controls[i] is EnterTextBox)
- {
- plcinstruct.Rows[0][Controls["GPD1"].Controls[i].Name] = Controls["GPD1"].Controls[i].Text;
- }
- }
- dbhelper.SaveDataTable(plcinstruct,"plcinstruct");
- for (int i = 0; i < Controls["GPD2"].Controls.Count; i++)
- {
- if (Controls["GPD2"].Controls[i] is EnterTextBox)
- {
- DataExtra.Rows[0][Controls["GPD2"].Controls[i].Name] = Controls["GPD2"].Controls[i].Text;
- }
- }
- dbhelper.SaveDataTable(DataExtra,"DataExtra");
- MessageBox.Show("保存成功");
- }
- }
- }
|