数据库文件

master
杨威 3 months ago
parent 04c3263270
commit 8d4f6ca91f

@ -10,4 +10,15 @@ namespace DNSD_DB.Mapper
this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey();
}
}
public class RfidSettingMap : EntityTypeBuilder<RfidSetting>
{
public RfidSettingMap()
{
this.MapTo("RfidSetting");
this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey();
}
}
}

@ -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;
}
}
}

@ -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; }
}
}

@ -0,0 +1,143 @@
namespace NDSD_Screwdriver
{
partial class FrmSetting
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

@ -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<RfidSetting>().Where(x => x.IsEnable == true).ToList();
// dataGridView1.DataSource = list;//DataGridView的行可以添加删除只有允许添加行、删除行
dataGridView1.DataSource = new BindingList<RfidSetting>(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<RfidSetting> list = new List<RfidSetting>();
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<RfidSetting>(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;
}
}
}

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="RfidNo.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Green.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Yellow.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Red.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

@ -69,6 +69,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AppTool.cs" />
<Compile Include="FrmSetting.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmSetting.Designer.cs">
<DependentUpon>FrmSetting.cs</DependentUpon>
</Compile>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
@ -83,6 +89,9 @@
<Compile Include="ScrewdriverTest.Designer.cs">
<DependentUpon>ScrewdriverTest.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="FrmSetting.resx">
<DependentUpon>FrmSetting.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>

@ -22,7 +22,7 @@ namespace NDSD_Screwdriver
XTrace.UseConsole();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
Application.Run(new FrmSetting());
}
}
}

Loading…
Cancel
Save