diff --git a/DNSD_DB/Mapper/StudentMap.cs b/DNSD_DB/Mapper/StudentMap.cs index a94136c..96c30ab 100644 --- a/DNSD_DB/Mapper/StudentMap.cs +++ b/DNSD_DB/Mapper/StudentMap.cs @@ -10,4 +10,15 @@ namespace DNSD_DB.Mapper this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey(); } } + + + public class RfidSettingMap : EntityTypeBuilder + { + public RfidSettingMap() + { + + this.MapTo("RfidSetting"); + this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey(); + } + } } \ No newline at end of file diff --git a/DNSD_DB/SqlLiteTool.cs b/DNSD_DB/SqlLiteTool.cs index 93e2385..596305a 100644 --- a/DNSD_DB/SqlLiteTool.cs +++ b/DNSD_DB/SqlLiteTool.cs @@ -14,8 +14,17 @@ namespace DNSD_DB public static void CreateTable(string db) { DbConfiguration.UseTypeBuilders(typeof(StudentMap)); + DbConfiguration.UseTypeBuilders(typeof(RfidSettingMap)); + IDbContext dbContext = new SQLiteContext(new SQLiteConnectionFactory(db)); new SQLiteTableGenerator(dbContext).CreateTables(TableCreateMode.CreateIfNotExists); } + + + public static IDbContext GetDb(string db) + { + IDbContext dbContext = new SQLiteContext(new SQLiteConnectionFactory(db)); + return dbContext; + } } } \ No newline at end of file diff --git a/DNSD_DB/Student.cs b/DNSD_DB/Student.cs index ed04b87..c76e440 100644 --- a/DNSD_DB/Student.cs +++ b/DNSD_DB/Student.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Chloe.Annotations; namespace DNSD_DB @@ -37,4 +38,29 @@ namespace DNSD_DB public string Gender { get; set; } } + + + + public class RfidSetting + { + [Column(IsPrimaryKey = true)] + [AutoIncrement] + [DisplayName("自增主见")] + public int ID { get; set; } + + + public string RfidNo { get; set; } + + + public string Green { get; set; } + + public string Yellow { get; set; } + + public string Red { get; set; } + + public bool IsEnable { get; set; } + + public DateTime CreateDateTime { get; set; } + + } } \ No newline at end of file diff --git a/NDSD-Screwdriver/FrmSetting.Designer.cs b/NDSD-Screwdriver/FrmSetting.Designer.cs new file mode 100644 index 0000000..2e8773b --- /dev/null +++ b/NDSD-Screwdriver/FrmSetting.Designer.cs @@ -0,0 +1,143 @@ +namespace NDSD_Screwdriver +{ + partial class FrmSetting + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.btnSave = new System.Windows.Forms.Button(); + this.RfidNo = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Green = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Yellow = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Red = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.RfidNo, + this.Green, + this.Yellow, + this.Red}); + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(3, 24); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 62; + this.dataGridView1.RowTemplate.Height = 30; + this.dataGridView1.Size = new System.Drawing.Size(693, 788); + this.dataGridView1.TabIndex = 0; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.dataGridView1); + this.groupBox1.Location = new System.Drawing.Point(27, 32); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(699, 815); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "报警灯设置"; + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(30, 904); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(183, 90); + this.btnSave.TabIndex = 2; + this.btnSave.Text = "保存报警灯"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // RfidNo + // + this.RfidNo.DataPropertyName = "RfidNo"; + this.RfidNo.HeaderText = "Rfid"; + this.RfidNo.MaxInputLength = 10; + this.RfidNo.MinimumWidth = 8; + this.RfidNo.Name = "RfidNo"; + this.RfidNo.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.RfidNo.Width = 150; + // + // Green + // + this.Green.DataPropertyName = "Green"; + this.Green.HeaderText = "绿灯"; + this.Green.MaxInputLength = 2; + this.Green.MinimumWidth = 8; + this.Green.Name = "Green"; + this.Green.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.Green.Width = 80; + // + // Yellow + // + this.Yellow.DataPropertyName = "Yellow"; + this.Yellow.HeaderText = "黄灯"; + this.Yellow.MaxInputLength = 2; + this.Yellow.MinimumWidth = 8; + this.Yellow.Name = "Yellow"; + this.Yellow.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.Yellow.Width = 80; + // + // Red + // + this.Red.DataPropertyName = "Red"; + this.Red.HeaderText = "红灯"; + this.Red.MaxInputLength = 5; + this.Red.MinimumWidth = 8; + this.Red.Name = "Red"; + this.Red.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.Red.Width = 80; + // + // FrmSetting + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(2021, 1124); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.groupBox1); + this.Name = "FrmSetting"; + this.Text = "参数设置"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.DataGridViewTextBoxColumn RfidNo; + private System.Windows.Forms.DataGridViewTextBoxColumn Green; + private System.Windows.Forms.DataGridViewTextBoxColumn Yellow; + private System.Windows.Forms.DataGridViewTextBoxColumn Red; + } +} \ No newline at end of file diff --git a/NDSD-Screwdriver/FrmSetting.cs b/NDSD-Screwdriver/FrmSetting.cs new file mode 100644 index 0000000..acf3781 --- /dev/null +++ b/NDSD-Screwdriver/FrmSetting.cs @@ -0,0 +1,189 @@ +using Chloe; + +using DNSD_DB; + +using NewLife.Data; +using NewLife.Reflection; + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace NDSD_Screwdriver +{ + public partial class FrmSetting : Form + { + public FrmSetting() + { + InitializeComponent(); + SqlLiteTool.CreateTable(AppTool.GetDb()); + Init(); + } + + + + + public void Init() + { + dataGridView1.AutoGenerateColumns = false; + var ctx = SqlLiteTool.GetDb(AppTool.GetDb()); + var list= ctx.Query().Where(x => x.IsEnable == true).ToList(); + + // dataGridView1.DataSource = list;//DataGridView的行可以添加删除(只有允许添加行、删除行) + dataGridView1.DataSource = new BindingList(list);//DataGridView的行可以添加删除(只有允许添加行、删除行) + dataGridView1.AllowUserToAddRows = true; + + dataGridView1.AllowUserToDeleteRows = true; + } + + + private DataTable GetTable() { + + DataTable table = new DataTable(); + table.Columns.Add("DisplayMember",typeof(string)); + table.Columns.Add("ValueMember", typeof(string)); + + var dr=table.NewRow(); + dr[0] = "绿色"; + dr[1] = "1"; + + table.Rows.Add(dr); + dr = table.NewRow(); + dr[0] = "黄色"; + dr[1] = "2"; + table.Rows.Add(dr); + + dr = table.NewRow(); + dr[0] = "红色"; + dr[1] = "3"; + table.Rows.Add(dr); + + return table; + + } + + private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e) + { + e.Row.Cells[0].Value = "0"; + e.Row.Cells["D1"].Value = "0"; + e.Row.Cells["D2"].Value = "0"; + e.Row.Cells["D3"].Value = "0"; + } + + private void btnSave_Click(object sender, EventArgs e) + { + + List list = new List(); + foreach (DataGridViewRow row in dataGridView1.Rows) + { + // 检查行的类型,确保不是新行或者标题行 + if (!row.IsNewRow && row.Cells[0].Value != null) + { + RfidSetting rfidSetting = new RfidSetting(); + + // 获取当前行的值,并添加到列表中 + string rfid = row.Cells[0].Value.ToString(); + string green = row.Cells[1].Value.ToString(); + string yellow = row.Cells[2].Value.ToString(); + string red = row.Cells[3].Value.ToString(); + + if (string.IsNullOrEmpty(rfid)) + { + MessageBox.Show("请输入rfid标签"); + return; + } + + rfidSetting.IsEnable = true; + rfidSetting.CreateDateTime = DateTime.Now; + rfidSetting.RfidNo = rfid; + + if (string.IsNullOrEmpty(green)) + { + MessageBox.Show("请输入绿灯"); + + return; + } + else + { + if (!IsInRange(green.ToInt())) + { + MessageBox.Show("绿灯不在有效的范围"); + + return; + } + } + + rfidSetting.Green = green; + + + + if (string.IsNullOrEmpty(yellow)) + { + MessageBox.Show("请输入黄灯"); + + return; + } + else + { + if (!IsInRange(yellow.ToInt())) + { + MessageBox.Show("绿灯不在有效的范围"); + + return; + } + } + + rfidSetting.Yellow = yellow; + + if (string.IsNullOrEmpty(red)) + { + MessageBox.Show("请输入红灯"); + + return; + } + else + { + if (!IsInRange(red.ToInt())) + { + MessageBox.Show("绿灯不在有效的范围"); + + return; + } + } + + rfidSetting.Red = red; + list.Add(rfidSetting); + } + } + + + if (list.Count > 0) + { + var ctx = SqlLiteTool.GetDb(AppTool.GetDb()); + ctx.Update(a => a.IsEnable == true, a => new RfidSetting() + { + IsEnable = false + }); + + ctx.InsertRange(list); + } + + MessageBox.Show("保存成功"); + + } + + + bool IsInRange(int x) + { + int a = 1; + int b = 16; + return x >= a && x <= b; + } + } +} diff --git a/NDSD-Screwdriver/FrmSetting.resx b/NDSD-Screwdriver/FrmSetting.resx new file mode 100644 index 0000000..8cf7a32 --- /dev/null +++ b/NDSD-Screwdriver/FrmSetting.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj index d8b0225..07a3f84 100644 --- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj +++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj @@ -69,6 +69,12 @@ + + Form + + + FrmSetting.cs + Form @@ -85,6 +91,9 @@ ScrewdriverTest.cs + + FrmSetting.cs + MainForm.cs diff --git a/NDSD-Screwdriver/Program.cs b/NDSD-Screwdriver/Program.cs index 6c0c939..4fba7fc 100644 --- a/NDSD-Screwdriver/Program.cs +++ b/NDSD-Screwdriver/Program.cs @@ -22,7 +22,7 @@ namespace NDSD_Screwdriver XTrace.UseConsole(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); + Application.Run(new FrmSetting()); } } }