From 11a501e7fbb3fe5f9e2a179bfa08ad25184f8728 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Wed, 14 Aug 2024 14:57:14 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E5=89=8D=E7=AB=AF=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=AE=8C=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NDSD-Screwdriver/Entity/MonitorEntity.cs | 40 ++++ NDSD-Screwdriver/FormUtils.cs | 23 ++- NDSD-Screwdriver/MainForm.Designer.cs | 57 ++---- NDSD-Screwdriver/MainForm.cs | 249 +++++++++++++---------- NDSD-Screwdriver/MonitorEntity.cs | 25 --- NDSD-Screwdriver/Program.cs | 2 +- 6 files changed, 227 insertions(+), 169 deletions(-) create mode 100644 NDSD-Screwdriver/Entity/MonitorEntity.cs delete mode 100644 NDSD-Screwdriver/MonitorEntity.cs diff --git a/NDSD-Screwdriver/Entity/MonitorEntity.cs b/NDSD-Screwdriver/Entity/MonitorEntity.cs new file mode 100644 index 0000000..e6dd96e --- /dev/null +++ b/NDSD-Screwdriver/Entity/MonitorEntity.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NDSD_Screwdriver +{ + public class MonitorEntity + { + /// + /// 每一行中元素的集合 + /// + public List RowEntitys { get; set; } + + /// + /// 行编号 + /// + public int RowIndex { get; set; } + } + + public class RowEntity + { + /// + /// 列编号 + /// + public int ColumnIndex { get; set; } + + /// + /// 方格颜色 + /// + public Brush Color { get; set; } = Brushes.Transparent; + + /// + /// 方格值 + /// + public string Value { get; set; } = ""; + } +} diff --git a/NDSD-Screwdriver/FormUtils.cs b/NDSD-Screwdriver/FormUtils.cs index 4ee2068..d699a02 100644 --- a/NDSD-Screwdriver/FormUtils.cs +++ b/NDSD-Screwdriver/FormUtils.cs @@ -23,6 +23,27 @@ namespace NDSD_Screwdriver return Brushes.Yellow; } else return Brushes.Red; - } + } + + public static Brush EnumColorToBrush(LightState lightState) + { + switch (lightState) + { + case LightState.Green: + return Brushes.Green; + case LightState.Yellow: + return Brushes.Yellow; + case LightState.Red: + return Brushes.Red; + default: return Brushes.Transparent; + } + } + } + + public enum LightState + { + Green = 0, + Yellow, + Red, } } diff --git a/NDSD-Screwdriver/MainForm.Designer.cs b/NDSD-Screwdriver/MainForm.Designer.cs index 4dee2d1..677f14b 100644 --- a/NDSD-Screwdriver/MainForm.Designer.cs +++ b/NDSD-Screwdriver/MainForm.Designer.cs @@ -32,9 +32,8 @@ this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.ScrewdriverMonitor = new DNSD_Controls.HslTable(); - this.TestButton1 = new System.Windows.Forms.Button(); - this.TestButton2 = new System.Windows.Forms.Button(); - this.TestButton3 = new System.Windows.Forms.Button(); + this.TestButton = new System.Windows.Forms.Button(); + this.InitButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); @@ -100,44 +99,33 @@ this.ScrewdriverMonitor.TopHeaderTextSize = 18F; this.ScrewdriverMonitor.OnDrawCellTextEvent += new DNSD_Controls.HslTable.DrawCellTextDelegate(this.ScrewdriverMonitor_OnDrawCellTextEvent); // - // TestButton1 + // TestButton // - this.TestButton1.Location = new System.Drawing.Point(673, 41); - this.TestButton1.Name = "TestButton1"; - this.TestButton1.Size = new System.Drawing.Size(75, 23); - this.TestButton1.TabIndex = 4; - this.TestButton1.Text = "测试1"; - this.TestButton1.UseVisualStyleBackColor = true; - this.TestButton1.Click += new System.EventHandler(this.TestButton1_Click); + this.TestButton.Location = new System.Drawing.Point(673, 70); + this.TestButton.Name = "TestButton"; + this.TestButton.Size = new System.Drawing.Size(75, 23); + this.TestButton.TabIndex = 4; + this.TestButton.Text = "测试"; + this.TestButton.UseVisualStyleBackColor = true; + this.TestButton.Click += new System.EventHandler(this.TestButton1_Click); // - // TestButton2 + // InitButton // - this.TestButton2.Location = new System.Drawing.Point(673, 70); - this.TestButton2.Name = "TestButton2"; - this.TestButton2.Size = new System.Drawing.Size(75, 23); - this.TestButton2.TabIndex = 5; - this.TestButton2.Text = "测试2"; - this.TestButton2.UseVisualStyleBackColor = true; - this.TestButton2.Click += new System.EventHandler(this.TestButton2_Click); - // - // TestButton3 - // - this.TestButton3.Location = new System.Drawing.Point(673, 99); - this.TestButton3.Name = "TestButton3"; - this.TestButton3.Size = new System.Drawing.Size(75, 23); - this.TestButton3.TabIndex = 6; - this.TestButton3.Text = "测试3"; - this.TestButton3.UseVisualStyleBackColor = true; - this.TestButton3.Click += new System.EventHandler(this.TestButton3_Click); + this.InitButton.Location = new System.Drawing.Point(673, 41); + this.InitButton.Name = "InitButton"; + this.InitButton.Size = new System.Drawing.Size(75, 23); + this.InitButton.TabIndex = 7; + this.InitButton.Text = "初始化表"; + this.InitButton.UseVisualStyleBackColor = true; + this.InitButton.Click += new System.EventHandler(this.InitButton_Click); // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1148, 850); - this.Controls.Add(this.TestButton3); - this.Controls.Add(this.TestButton2); - this.Controls.Add(this.TestButton1); + this.Controls.Add(this.InitButton); + this.Controls.Add(this.TestButton); this.Controls.Add(this.ScrewdriverMonitor); this.Controls.Add(this.groupBox1); this.Controls.Add(this.DOTest); @@ -156,8 +144,7 @@ private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.GroupBox groupBox1; private DNSD_Controls.HslTable ScrewdriverMonitor; - private System.Windows.Forms.Button TestButton1; - private System.Windows.Forms.Button TestButton2; - private System.Windows.Forms.Button TestButton3; + private System.Windows.Forms.Button TestButton; + private System.Windows.Forms.Button InitButton; } } \ No newline at end of file diff --git a/NDSD-Screwdriver/MainForm.cs b/NDSD-Screwdriver/MainForm.cs index 909985b..f267c9a 100644 --- a/NDSD-Screwdriver/MainForm.cs +++ b/NDSD-Screwdriver/MainForm.cs @@ -13,13 +13,44 @@ namespace NDSD_Screwdriver { public partial class MainForm : Form { - DOperate DOperate; - - TcpServer server = TcpServer.Instance; - - List monitorEntities; - - Random rand = new Random(); + /// + /// 输出端口操作 + /// + private DOperate DOperate; + + /// + /// TCP服务器 + /// + private TcpServer server = TcpServer.Instance; + + /// + /// 前端列表集合 + /// + private List monitorEntities; + + private Random rand = new Random(); + + ///// + ///// 判断是否是第一次初始化 + ///// + //private int flag = 0; + + /// + /// 判断现在操作哪一行 + /// + public int NowRowIndex = 0; + + /// + /// RFID列表 + /// + string[] RFIDs = new string[] + { + "1111222233334444", + "2222222233334444", + "3333222233334444", + "4444222233334444", + "5555222233334444" + }; public MainForm() { @@ -29,86 +60,13 @@ namespace NDSD_Screwdriver { MessageBox.Show("服务端打开失败!"); } - monitorEntities = new List() - { - new MonitorEntity() - { - RowEneieys = new List() - { - new RowEneiey() - { - ColumnIndex = 0, - Color = Brushes.Transparent - }, - - new RowEneiey() - { - ColumnIndex = 1, - Value = "11111111", - Color = Brushes.Transparent - }, - - new RowEneiey() - { - ColumnIndex = 2, - }, - }, - RowIndex = 0, - }, - - new MonitorEntity() - { - RowEneieys = new List() - { - new RowEneiey() - { - ColumnIndex = 0, - Color = Brushes.Transparent - }, - - new RowEneiey() - { - ColumnIndex = 1, - Value = "22222222", - Color = Brushes.Transparent - }, - - new RowEneiey() - { - ColumnIndex = 2, - }, - }, - RowIndex = 1, - }, - - new MonitorEntity() - { - RowEneieys = new List() - { - new RowEneiey() - { - ColumnIndex = 0, - Color = Brushes.Transparent - }, - - new RowEneiey() - { - ColumnIndex = 1, - Value = "33333333", - Color = Brushes.Transparent - }, - - new RowEneiey() - { - ColumnIndex = 2, - }, - }, - RowIndex = 2, - }, - - }; } + /// + /// 打开DO测试 + /// + /// + /// private void DOTest_Click(object sender, EventArgs e) { ScrewdriverTest screwdriverTest = new ScrewdriverTest(server, DOperate); @@ -127,55 +85,63 @@ namespace NDSD_Screwdriver { MessageBox.Show("服务端释放失败!"); } - - } } + /// + /// 列表回调函数 + /// + /// + /// + /// + /// + /// + /// private void ScrewdriverMonitor_OnDrawCellTextEvent(Graphics g, int rowIndex, int colIndex, RectangleF rectangle, string value, StringFormat sf) { foreach (MonitorEntity entity in monitorEntities) { if (rowIndex == entity.RowIndex) { - foreach (RowEneiey rowEneiey in entity.RowEneieys) + foreach (RowEntity rowEneiey in entity.RowEntitys) { if (colIndex == rowEneiey.ColumnIndex) { - if (colIndex == 2) - { - g.FillRectangle(FormUtils.TestRamColor(), rectangle); - g.DrawString(rowEneiey.Value, this.ScrewdriverMonitor.Font, Brushes.Black, rectangle, sf); - } - else - { - g.FillRectangle(rowEneiey.Color, rectangle); - g.DrawString(rowEneiey.Value, this.ScrewdriverMonitor.Font, Brushes.Black, rectangle, sf); - } + g.FillRectangle(rowEneiey.Color, rectangle); + g.DrawString(rowEneiey.Value, this.ScrewdriverMonitor.Font, Brushes.Black, rectangle, sf); } } } } - - } - private void TestButton1_Click(object sender, EventArgs e) - { - RefreshRoll(); } - private void TestButton2_Click(object sender, EventArgs e) + /// + /// 测试按钮 + /// + /// + /// + private void TestButton1_Click(object sender, EventArgs e) { + SetNowRowsLightState(FormUtils.TestRamColor()); RefreshRoll(); + if (++NowRowIndex >= RFIDs.Length) + { + NowRowIndex = 0; + } } - private void TestButton3_Click(object sender, EventArgs e) + private void InitButton_Click(object sender, EventArgs e) { - RefreshRoll(); + InitMonitirIntity(); + SetRFIDValue(RFIDs); } + /// + /// 刷新列表 + /// private void RefreshRoll() { - for (int i = 0; i < 5; i++) + for (int i = 0; i < RFIDs.Length; i++) { ScrewdriverMonitor.AddRowTop(new string[]{ "", @@ -184,5 +150,74 @@ namespace NDSD_Screwdriver }); } } + + /// + /// 初始化整个列表 + /// + private void InitMonitirIntity() + { + monitorEntities = new List(); + for (int i = 0; i < RFIDs.Length; i++) + { + monitorEntities.Add(new MonitorEntity() + { + RowIndex = i, + RowEntitys = InitRows(i) + }); + } + RefreshRoll(); + } + + /// + /// 初始化一行 + /// + /// 当前的初始化行数 + /// + private List InitRows(int rowNo) + { + List rowEntities = new List(); + for (int i = 0; i < 3; i++) + { + rowEntities.Add(new RowEntity() + { + ColumnIndex = i, + }); + } + return rowEntities; + } + + /// + /// 初始化RFID数据 + /// + /// RFID列表 + private void SetRFIDValue(string[] rFIDvalue) + { + for (int i = 0; i < rFIDvalue.Length; i++) + { + monitorEntities[i].RowEntitys[1].Value = rFIDvalue[i]; + } + } + + /// + /// 设置当前行指示灯的状态以及工作的行 + /// + /// + private void SetNowRowsLightState(LightState lightState) + { + monitorEntities[NowRowIndex].RowEntitys[2].Color = FormUtils.EnumColorToBrush(lightState); + for (int i = 0; i < RFIDs.Length; i++) + { + monitorEntities[NowRowIndex].RowEntitys[0].Value = i == NowRowIndex ? "=>" : ""; + } + } + + private void SetNowRowsLightState(Brush brush) + { + monitorEntities[NowRowIndex].RowEntitys[2].Color = brush; + for (int i = 0; i < RFIDs.Length; i++) + { + monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : ""; + } + } } } diff --git a/NDSD-Screwdriver/MonitorEntity.cs b/NDSD-Screwdriver/MonitorEntity.cs deleted file mode 100644 index 96ba86c..0000000 --- a/NDSD-Screwdriver/MonitorEntity.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NDSD_Screwdriver -{ - public class MonitorEntity - { - public List RowEneieys { get; set; } - - public int RowIndex { get; set; } - } - - public class RowEneiey - { - public int ColumnIndex { get; set; } - - public Brush Color { get; set; } = Brushes.Transparent; - - public string Value { get; set; } = ""; - } -} diff --git a/NDSD-Screwdriver/Program.cs b/NDSD-Screwdriver/Program.cs index 4fba7fc..6c0c939 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 FrmSetting()); + Application.Run(new MainForm()); } } }