From 95d9dc3c611d07c6264041592a6c4d6b47194eef Mon Sep 17 00:00:00 2001 From: SoulStar Date: Thu, 15 Aug 2024 17:36:43 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E6=9B=B4=E6=94=B9=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E7=BB=93=E6=9E=84=20=E5=87=86=E5=A4=87?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DNSD_DB/DNSD_DB.csproj | 7 +- .../Entity/LightsEntity.cs | 2 +- .../Entity/MonitorEntity.cs | 2 +- .../RFIDConfigEntity.cs} | 29 ++--- DNSD_DB/Entity/RFIDLogsEntity.cs | 22 ++++ DNSD_DB/Entity/RFIDStatesEntity.cs | 21 ++++ DNSD_DB/Mapper/Maps.cs | 13 +- DNSD_DB/SqlLiteTool.cs | 4 +- NDSD-Screwdriver/FormUtils.cs | 40 ++++++- NDSD-Screwdriver/FrmSetting.Designer.cs | 52 ++++++++ NDSD-Screwdriver/FrmSetting.cs | 37 +++--- NDSD-Screwdriver/MainForm.Designer.cs | 49 +++++--- NDSD-Screwdriver/MainForm.cs | 112 +++++++++++++----- NDSD-Screwdriver/MainForm.resx | 12 ++ NDSD-Screwdriver/MemorySetting.cs | 11 ++ NDSD-Screwdriver/NDSD_Screwdriver.csproj | 2 - 16 files changed, 323 insertions(+), 92 deletions(-) rename {NDSD-Screwdriver => DNSD_DB}/Entity/LightsEntity.cs (89%) rename {NDSD-Screwdriver => DNSD_DB}/Entity/MonitorEntity.cs (96%) rename DNSD_DB/{Entitys.cs => Entity/RFIDConfigEntity.cs} (55%) create mode 100644 DNSD_DB/Entity/RFIDLogsEntity.cs create mode 100644 DNSD_DB/Entity/RFIDStatesEntity.cs diff --git a/DNSD_DB/DNSD_DB.csproj b/DNSD_DB/DNSD_DB.csproj index 0ca0a39..0b7cee9 100644 --- a/DNSD_DB/DNSD_DB.csproj +++ b/DNSD_DB/DNSD_DB.csproj @@ -50,6 +50,7 @@ ..\Dll\System.Data.SQLite.dll + @@ -58,11 +59,15 @@ + + + + + - diff --git a/NDSD-Screwdriver/Entity/LightsEntity.cs b/DNSD_DB/Entity/LightsEntity.cs similarity index 89% rename from NDSD-Screwdriver/Entity/LightsEntity.cs rename to DNSD_DB/Entity/LightsEntity.cs index 0c967ba..593c5bc 100644 --- a/NDSD-Screwdriver/Entity/LightsEntity.cs +++ b/DNSD_DB/Entity/LightsEntity.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace NDSD_Screwdriver.Entity +namespace DNSD_DB.Entity { public class LightsEntity { diff --git a/NDSD-Screwdriver/Entity/MonitorEntity.cs b/DNSD_DB/Entity/MonitorEntity.cs similarity index 96% rename from NDSD-Screwdriver/Entity/MonitorEntity.cs rename to DNSD_DB/Entity/MonitorEntity.cs index 39d2a6d..d1e6f45 100644 --- a/NDSD-Screwdriver/Entity/MonitorEntity.cs +++ b/DNSD_DB/Entity/MonitorEntity.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace NDSD_Screwdriver.Entity +namespace DNSD_DB.Entity { public class MonitorEntity { diff --git a/DNSD_DB/Entitys.cs b/DNSD_DB/Entity/RFIDConfigEntity.cs similarity index 55% rename from DNSD_DB/Entitys.cs rename to DNSD_DB/Entity/RFIDConfigEntity.cs index 85e9b79..ed6c9c8 100644 --- a/DNSD_DB/Entitys.cs +++ b/DNSD_DB/Entity/RFIDConfigEntity.cs @@ -1,11 +1,14 @@ -using System; +using Chloe.Annotations; +using System; +using System.Collections.Generic; using System.ComponentModel; -using Chloe.Annotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace DNSD_DB +namespace DNSD_DB.Entity { - - public class RfidSetting + public class RFIDConfigEntity { [Column(IsPrimaryKey = true)] [AutoIncrement] @@ -14,7 +17,6 @@ namespace DNSD_DB public string RfidNo { get; set; } - public string Green { get; set; } public string Yellow { get; set; } @@ -26,17 +28,4 @@ namespace DNSD_DB public DateTime CreateDateTime { get; set; } } - - public class RFIDLog - { - [Column(IsPrimaryKey = true)] - [AutoIncrement] - public int ID { get; set; } - - public DateTime CreateTime { get; set; } - - public string LogText { get; set; } - - public string RFIDId { get; set; } - } -} \ No newline at end of file +} diff --git a/DNSD_DB/Entity/RFIDLogsEntity.cs b/DNSD_DB/Entity/RFIDLogsEntity.cs new file mode 100644 index 0000000..0d5daf5 --- /dev/null +++ b/DNSD_DB/Entity/RFIDLogsEntity.cs @@ -0,0 +1,22 @@ +using Chloe.Annotations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DNSD_DB.Entity +{ + public class RFIDLogsEntity + { + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int ID { get; set; } + + public DateTime CreateTime { get; set; } + + public string LogText { get; set; } + + public string RFIDId { get; set; } = string.Empty; + } +} diff --git a/DNSD_DB/Entity/RFIDStatesEntity.cs b/DNSD_DB/Entity/RFIDStatesEntity.cs new file mode 100644 index 0000000..89b8836 --- /dev/null +++ b/DNSD_DB/Entity/RFIDStatesEntity.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DNSD_DB.Entity +{ + public class RFIDStatesEntity + { + /// + /// RFID值 + /// + public string RFIDValue { get; set; } + + /// + /// 状态指示 0未操作 1正在操作 2准备操作 3已完成 4超时报警 + /// + public int RFIDState { get; set; } = 0; + } +} diff --git a/DNSD_DB/Mapper/Maps.cs b/DNSD_DB/Mapper/Maps.cs index 6ce9b73..a586f81 100644 --- a/DNSD_DB/Mapper/Maps.cs +++ b/DNSD_DB/Mapper/Maps.cs @@ -1,24 +1,25 @@ using Chloe.Entity; +using DNSD_DB.Entity; namespace DNSD_DB.Mapper { - public class RfidSettingMap : EntityTypeBuilder + public class RFIDConfigEntityMap : EntityTypeBuilder { - public RfidSettingMap() + public RFIDConfigEntityMap() { - this.MapTo("RfidSetting"); + this.MapTo("RFIDConfigEntity"); this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey(); } } - public class RFIDLogMap : EntityTypeBuilder + public class RFIDLogsEntityMap : EntityTypeBuilder { - public RFIDLogMap() + public RFIDLogsEntityMap() { - this.MapTo("RFIDLog"); + this.MapTo("RFIDLogsEntity"); this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey(); } } diff --git a/DNSD_DB/SqlLiteTool.cs b/DNSD_DB/SqlLiteTool.cs index feac795..f728520 100644 --- a/DNSD_DB/SqlLiteTool.cs +++ b/DNSD_DB/SqlLiteTool.cs @@ -13,8 +13,8 @@ namespace DNSD_DB public static void CreateTable(string db) { - DbConfiguration.UseTypeBuilders(typeof(RfidSettingMap)); - DbConfiguration.UseTypeBuilders(typeof(RFIDLogMap)); + DbConfiguration.UseTypeBuilders(typeof(RFIDConfigEntityMap)); + DbConfiguration.UseTypeBuilders(typeof(RFIDLogsEntityMap)); diff --git a/NDSD-Screwdriver/FormUtils.cs b/NDSD-Screwdriver/FormUtils.cs index 3da38db..da81c6b 100644 --- a/NDSD-Screwdriver/FormUtils.cs +++ b/NDSD-Screwdriver/FormUtils.cs @@ -1,4 +1,7 @@ -using System; +using Chloe; +using DNSD_DB; +using DNSD_DB.Entity; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -51,6 +54,41 @@ namespace NDSD_Screwdriver default: return Brushes.Transparent; } } + + /// + /// 插入无RFID编号日志 + /// + /// + /// + public static void LogInsert(IDbContext dbContext, string text) + { + dbContext.Insert(new RFIDLogsEntity() + { + CreateTime = DateTime.Now, + LogText = text, + }); + } + + /// + /// 插入有RFID编号日志 + /// + /// + /// + public static void LogInsert(IDbContext dbContext, string text, string rfid) + { + dbContext.Insert(new RFIDLogsEntity() + { + CreateTime = DateTime.Now, + LogText = text, + RFIDId = rfid + }); + } + + public static void SignAnalysis(IDbContext dbContext) + { + + } + } public enum LightState diff --git a/NDSD-Screwdriver/FrmSetting.Designer.cs b/NDSD-Screwdriver/FrmSetting.Designer.cs index af3d2b4..b7d6ad7 100644 --- a/NDSD-Screwdriver/FrmSetting.Designer.cs +++ b/NDSD-Screwdriver/FrmSetting.Designer.cs @@ -42,9 +42,14 @@ this.Yellow = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Red = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.label3 = new System.Windows.Forms.Label(); + this.Groupbox3 = new System.Windows.Forms.GroupBox(); + this.AlarmTimeValueTextBox = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.SetAlarmTimeValueButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); + this.Groupbox3.SuspendLayout(); this.SuspendLayout(); // // dataGridView1 @@ -63,6 +68,7 @@ this.dataGridView1.RowTemplate.Height = 30; this.dataGridView1.Size = new System.Drawing.Size(615, 657); this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); // // groupBox1 // @@ -194,11 +200,51 @@ this.label3.TabIndex = 4; this.label3.Text = "配置报警灯时,请按照:绿->黄->红 的顺序从大到小填写DO口"; // + // Groupbox3 + // + this.Groupbox3.Controls.Add(this.SetAlarmTimeValueButton); + this.Groupbox3.Controls.Add(this.label4); + this.Groupbox3.Controls.Add(this.AlarmTimeValueTextBox); + this.Groupbox3.Location = new System.Drawing.Point(651, 98); + this.Groupbox3.Name = "Groupbox3"; + this.Groupbox3.Size = new System.Drawing.Size(351, 96); + this.Groupbox3.TabIndex = 5; + this.Groupbox3.TabStop = false; + this.Groupbox3.Text = "超时报警时间设置"; + // + // AlarmTimeValueTextBox + // + this.AlarmTimeValueTextBox.Location = new System.Drawing.Point(120, 37); + this.AlarmTimeValueTextBox.Name = "AlarmTimeValueTextBox"; + this.AlarmTimeValueTextBox.Size = new System.Drawing.Size(100, 25); + this.AlarmTimeValueTextBox.TabIndex = 0; + this.AlarmTimeValueTextBox.Text = "10"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(15, 42); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(97, 15); + this.label4.TabIndex = 1; + this.label4.Text = "报警时间阈值"; + // + // SetAlarmTimeValueButton + // + this.SetAlarmTimeValueButton.Location = new System.Drawing.Point(237, 24); + this.SetAlarmTimeValueButton.Name = "SetAlarmTimeValueButton"; + this.SetAlarmTimeValueButton.Size = new System.Drawing.Size(95, 50); + this.SetAlarmTimeValueButton.TabIndex = 2; + this.SetAlarmTimeValueButton.Text = "设置"; + this.SetAlarmTimeValueButton.UseVisualStyleBackColor = true; + this.SetAlarmTimeValueButton.Click += new System.EventHandler(this.SetAlarmTimeValueButton_Click); + // // FrmSetting // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1160, 819); + this.Controls.Add(this.Groupbox3); this.Controls.Add(this.label3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.btnSave); @@ -210,6 +256,8 @@ this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); + this.Groupbox3.ResumeLayout(false); + this.Groupbox3.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -231,5 +279,9 @@ private System.Windows.Forms.DataGridViewTextBoxColumn Yellow; private System.Windows.Forms.DataGridViewTextBoxColumn Red; private System.Windows.Forms.Label label3; + private System.Windows.Forms.GroupBox Groupbox3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox AlarmTimeValueTextBox; + private System.Windows.Forms.Button SetAlarmTimeValueButton; } } \ No newline at end of file diff --git a/NDSD-Screwdriver/FrmSetting.cs b/NDSD-Screwdriver/FrmSetting.cs index ff1fa24..aaa1e50 100644 --- a/NDSD-Screwdriver/FrmSetting.cs +++ b/NDSD-Screwdriver/FrmSetting.cs @@ -1,6 +1,7 @@ using Chloe; using DNSD_DB; +using DNSD_DB.Entity; using NewLife.Data; using NewLife.Reflection; @@ -27,19 +28,17 @@ namespace NDSD_Screwdriver 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(); + var list = ctx.Query().Where(x => x.IsEnable == true).ToList(); // dataGridView1.DataSource = list;//DataGridView的行可以添加删除(只有允许添加行、删除行) - dataGridView1.DataSource = new BindingList(list);//DataGridView的行可以添加删除(只有允许添加行、删除行) + dataGridView1.DataSource = new BindingList(list);//DataGridView的行可以添加删除(只有允许添加行、删除行) dataGridView1.AllowUserToAddRows = true; dataGridView1.AllowUserToDeleteRows = true; @@ -83,13 +82,13 @@ namespace NDSD_Screwdriver private void btnSave_Click(object sender, EventArgs e) { - List list = new List(); + List list = new List(); foreach (DataGridViewRow row in dataGridView1.Rows) { // 检查行的类型,确保不是新行或者标题行 if (!row.IsNewRow && row.Cells[0].Value != null) { - RfidSetting rfidSetting = new RfidSetting(); + RFIDConfigEntity RFIDConfigEntity = new RFIDConfigEntity(); // 获取当前行的值,并添加到列表中 string rfid = row.Cells[0].Value.ToString(); @@ -103,9 +102,9 @@ namespace NDSD_Screwdriver return; } - rfidSetting.IsEnable = true; - rfidSetting.CreateDateTime = DateTime.Now; - rfidSetting.RfidNo = rfid; + RFIDConfigEntity.IsEnable = true; + RFIDConfigEntity.CreateDateTime = DateTime.Now; + RFIDConfigEntity.RfidNo = rfid; if (string.IsNullOrEmpty(green)) { @@ -123,7 +122,7 @@ namespace NDSD_Screwdriver } } - rfidSetting.Green = green; + RFIDConfigEntity.Green = green; @@ -143,7 +142,7 @@ namespace NDSD_Screwdriver } } - rfidSetting.Yellow = yellow; + RFIDConfigEntity.Yellow = yellow; if (string.IsNullOrEmpty(red)) { @@ -161,8 +160,8 @@ namespace NDSD_Screwdriver } } - rfidSetting.Red = red; - list.Add(rfidSetting); + RFIDConfigEntity.Red = red; + list.Add(RFIDConfigEntity); } } @@ -170,7 +169,7 @@ namespace NDSD_Screwdriver if (list.Count > 0) { var ctx = SqlLiteTool.GetDb(AppTool.GetDb()); - ctx.Update(a => a.IsEnable == true, a => new RfidSetting() + ctx.Update(a => a.IsEnable == true, a => new RFIDConfigEntity() { IsEnable = false }); @@ -195,6 +194,16 @@ namespace NDSD_Screwdriver MemorySetting.ServerIP = ServerIPTextbox.Text; MemorySetting.ServerPort = ServerPortTextbox.Text; } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void SetAlarmTimeValueButton_Click(object sender, EventArgs e) + { + MemorySetting.AlarmTimeValue = Convert.ToInt32(AlarmTimeValueTextBox.Text); + } } } diff --git a/NDSD-Screwdriver/MainForm.Designer.cs b/NDSD-Screwdriver/MainForm.Designer.cs index 9308f69..2ddc674 100644 --- a/NDSD-Screwdriver/MainForm.Designer.cs +++ b/NDSD-Screwdriver/MainForm.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { this.DOTest = new System.Windows.Forms.Button(); - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.LogDataGridView = new System.Windows.Forms.DataGridView(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.ScrewdriverMonitor = new DNSD_Controls.HslTable(); this.TestButton = new System.Windows.Forms.Button(); @@ -38,7 +38,9 @@ this.ServerRestartButton = new System.Windows.Forms.Button(); this.StartServerButton = new System.Windows.Forms.Button(); this.ServerStopButton = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.logTime = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.LogValue = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).BeginInit(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // @@ -52,20 +54,24 @@ this.DOTest.UseVisualStyleBackColor = true; this.DOTest.Click += new System.EventHandler(this.DOTest_Click); // - // dataGridView1 + // LogDataGridView // - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridView1.Location = new System.Drawing.Point(3, 21); - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersWidth = 51; - this.dataGridView1.RowTemplate.Height = 27; - this.dataGridView1.Size = new System.Drawing.Size(388, 826); - this.dataGridView1.TabIndex = 1; + this.LogDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.LogDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.logTime, + this.LogValue}); + this.LogDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.LogDataGridView.Location = new System.Drawing.Point(3, 21); + this.LogDataGridView.Name = "LogDataGridView"; + this.LogDataGridView.RowHeadersWidth = 51; + this.LogDataGridView.RowTemplate.Height = 27; + this.LogDataGridView.Size = new System.Drawing.Size(388, 826); + this.LogDataGridView.TabIndex = 1; // // groupBox1 // - this.groupBox1.Controls.Add(this.dataGridView1); + this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.groupBox1.Controls.Add(this.LogDataGridView); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Location = new System.Drawing.Point(754, 0); this.groupBox1.Name = "groupBox1"; @@ -163,6 +169,19 @@ this.ServerStopButton.UseVisualStyleBackColor = true; this.ServerStopButton.Click += new System.EventHandler(this.ServerStopButton_Click); // + // logTime + // + this.logTime.HeaderText = "日志时间"; + this.logTime.MinimumWidth = 6; + this.logTime.Name = "logTime"; + // + // LogValue + // + this.LogValue.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.LogValue.HeaderText = "日志内容"; + this.LogValue.MinimumWidth = 6; + this.LogValue.Name = "LogValue"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); @@ -180,7 +199,7 @@ this.Name = "MainForm"; this.Text = "MainForm"; this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).EndInit(); this.groupBox1.ResumeLayout(false); this.ResumeLayout(false); @@ -189,7 +208,7 @@ #endregion private System.Windows.Forms.Button DOTest; - private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridView LogDataGridView; private System.Windows.Forms.GroupBox groupBox1; private DNSD_Controls.HslTable ScrewdriverMonitor; private System.Windows.Forms.Button TestButton; @@ -198,5 +217,7 @@ private System.Windows.Forms.Button ServerRestartButton; private System.Windows.Forms.Button StartServerButton; private System.Windows.Forms.Button ServerStopButton; + private System.Windows.Forms.DataGridViewTextBoxColumn logTime; + private System.Windows.Forms.DataGridViewTextBoxColumn LogValue; } } \ No newline at end of file diff --git a/NDSD-Screwdriver/MainForm.cs b/NDSD-Screwdriver/MainForm.cs index 1ccbdaf..beb6d2a 100644 --- a/NDSD-Screwdriver/MainForm.cs +++ b/NDSD-Screwdriver/MainForm.cs @@ -1,7 +1,7 @@ -using DNSD_DB; -using NDSD_Screwdriver.Entity; +using Chloe; +using DNSD_DB; +using DNSD_DB.Entity; using NDSD_Screwdriver.Tool; - using NDSD_TouchSocket; using System; using System.Collections.Generic; @@ -35,7 +35,7 @@ namespace NDSD_Screwdriver /// private List monitorEntities; - private List rfidSettings; + private List RFIDConfigEntitys; private Random rand = new Random(); @@ -55,29 +55,50 @@ namespace NDSD_Screwdriver public int ReadyRowIndex = 0; /// - /// RFID列表 + /// RFID状态列表 /// - public string[] RFIDs; + public List RFIDStatesEntities; + /// + /// 报警灯配置实例 + /// public List lightsEntities; + /// + /// 日志实例 + /// + public List RFIDLogsEntitys; + + /// + /// 日志数据库操作实例 + /// + public IDbContext LogContext; + Thread thread; bool flag = false; + bool IsFirst = true; + SerialPortFactory serialPort; private CancellationTokenSource cancellationTokenSource; private int textindex = 0; + public int textRFID; + public MainForm() { + SqlLiteTool.CreateTable(AppTool.GetDb()); InitializeComponent(); + LogContext = SqlLiteTool.GetDb(AppTool.GetDb()); + RFIDLogsEntitys = LogContext.Query().ToList(); DOperate = new DOperate(); if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort)) { MessageBox.Show("服务端打开失败!"); + FormUtils.LogInsert(LogContext, "服务端打开失败"); } FlashThread(); serialPort = new SerialPortFactory(); @@ -91,10 +112,13 @@ namespace NDSD_Screwdriver if (!server.ServerStop()) { MessageBox.Show("服务端关闭失败!"); + FormUtils.LogInsert(LogContext, "服务端关闭失败"); + } if (!server.ServerDispose()) { MessageBox.Show("服务端释放失败!"); + FormUtils.LogInsert(LogContext, "服务端释放失败"); } } } @@ -122,22 +146,20 @@ namespace NDSD_Screwdriver /// private void TestButton1_Click(object sender, EventArgs e) { - if (RFIDs.Length == 0) + if (RFIDStatesEntities.Count == 0) { MessageBox.Show("没有值,请先设置。"); } - - - SetNowWorkRow(RFIDs[textindex]); + SetNowWorkRow(RFIDStatesEntities[NowRowIndex].RFIDValue); SetNowRowsLightState(1); if (flag && thread.ThreadState == ThreadState.Suspended) { thread.Resume(); } RefreshRoll(); - if (++textindex >= RFIDs.Length) + if (++NowRowIndex >= RFIDStatesEntities.Count) { - textindex = 0; + NowRowIndex = 0; } } @@ -151,8 +173,16 @@ namespace NDSD_Screwdriver NowRowIndex = 0; //读取rfid数据 var ctx = SqlLiteTool.GetDb(AppTool.GetDb()); - var list = ctx.Query().Where(x => x.IsEnable == true).ToList(); - RFIDs = list.Select(x => x.RfidNo).ToArray(); + var list = ctx.Query().Where(x => x.IsEnable == true).ToList(); + var strs = list.Select(x => x.RfidNo).ToArray(); + RFIDStatesEntities = new List(); + foreach (var a in strs) + { + RFIDStatesEntities.Add(new RFIDStatesEntity() + { + RFIDValue = a, + }); + } //读取报警灯数据 lightsEntities = new List(); for (int i = 0; i < list.Count; i++) @@ -166,7 +196,7 @@ namespace NDSD_Screwdriver } //初始化列表框架 monitorEntities = new List(); - for (int i = 0; i < RFIDs.Length; i++) + for (int i = 0; i < RFIDStatesEntities.Count; i++) { monitorEntities.Add(new MonitorEntity() { @@ -179,9 +209,9 @@ namespace NDSD_Screwdriver thread.Suspend(); } //更新值 - for (int i = 0; i < RFIDs.Length; i++) + for (int i = 0; i < RFIDStatesEntities.Count; i++) { - monitorEntities[i].RowEntitys[1].Value = RFIDs[i]; + monitorEntities[i].RowEntitys[1].Value = RFIDStatesEntities[i].RFIDValue; } RefreshRoll(); } @@ -279,7 +309,7 @@ namespace NDSD_Screwdriver /// private void RefreshRoll() { - for (int i = 0; i < RFIDs.Length; i++) + for (int i = 0; i < RFIDStatesEntities.Count; i++) { ScrewdriverMonitor.AddRowTop(new string[]{ "", @@ -315,7 +345,7 @@ namespace NDSD_Screwdriver } monitorEntities[NowRowIndex].RowEntitys[2].Color = brush; SetNextRowsFlash(); - for (int i = 0; i < RFIDs.Length; i++) + for (int i = 0; i < RFIDStatesEntities.Count; i++) { monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : ""; } @@ -326,8 +356,7 @@ namespace NDSD_Screwdriver /// private void SetNextRowsFlash() { - ReadyRowIndex = NowRowIndex + 1; - if (ReadyRowIndex >= RFIDs.Length) + if (ReadyRowIndex >= RFIDStatesEntities.Count) { ReadyRowIndex = 0; thread.Suspend(); @@ -347,24 +376,46 @@ namespace NDSD_Screwdriver /// 读取到的RFID private void SetNowWorkRow(string rfid) { - for (int i = 0; i < RFIDs.Length; i++) - { - if (monitorEntities[i].RowEntitys[1].Value == rfid) + ReadyRowIndex = NowRowIndex + 1; + //RFIDStatesEntities[ReadyRowIndex].RFIDState = 2; + //if (IsFirst) + //{ + // IsFirst = false; + for (int i = 0; i < RFIDStatesEntities.Count; i++) { - NowRowIndex = i; - return; + if (monitorEntities[i].RowEntitys[1].Value == rfid) + { + NowRowIndex = i; + return; + } } - } + //} + //else + //{ + // for (int i = 0; i < RFIDStatesEntities.Count; i++) + // { + // if (RFIDStatesEntities[i].RFIDState == 2) + // { + // NowRowIndex = i; + // return; + // } + // } + //} } - + /// - /// 根据IO口控制灯的开关 + /// IO控制 /// private void LightControl() { } + private void ComDataAnalysis(string str) + { + + } + /// /// 列表回调函数 /// @@ -402,8 +453,9 @@ namespace NDSD_Screwdriver { while (!cancellationTokenSource.Token.IsCancellationRequested) { + // 这里是你的长期运行逻辑 - Thread.Sleep(1000); // 模拟一些长时间的工作 + Thread.Sleep(rand.Next(4, 16) * 1000); // 模拟一些长时间的工作 } }, cancellationTokenSource.Token); } diff --git a/NDSD-Screwdriver/MainForm.resx b/NDSD-Screwdriver/MainForm.resx index 1af7de1..30452e0 100644 --- a/NDSD-Screwdriver/MainForm.resx +++ b/NDSD-Screwdriver/MainForm.resx @@ -117,4 +117,16 @@ 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/MemorySetting.cs b/NDSD-Screwdriver/MemorySetting.cs index 253e022..9c84bf2 100644 --- a/NDSD-Screwdriver/MemorySetting.cs +++ b/NDSD-Screwdriver/MemorySetting.cs @@ -8,8 +8,19 @@ namespace NDSD_Screwdriver { public static class MemorySetting { + /// + /// 服务端IP + /// public static string ServerIP { get; set; } = "192.168.0.101"; + /// + /// 服务端端口 + /// public static string ServerPort { get; set; } = "6001"; + + /// + /// 超时报警时间 + /// + public static int AlarmTimeValue { get; set; } = 10; } } diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj index 343bb22..a810930 100644 --- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj +++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj @@ -102,7 +102,6 @@ - Form @@ -115,7 +114,6 @@ MainForm.cs -