add - 前端界面逻辑完备

master
SoulStar 1 month ago
parent bde4126d67
commit 11a501e7fb

@ -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
{
/// <summary>
/// 每一行中元素的集合
/// </summary>
public List<RowEntity> RowEntitys { get; set; }
/// <summary>
/// 行编号
/// </summary>
public int RowIndex { get; set; }
}
public class RowEntity
{
/// <summary>
/// 列编号
/// </summary>
public int ColumnIndex { get; set; }
/// <summary>
/// 方格颜色
/// </summary>
public Brush Color { get; set; } = Brushes.Transparent;
/// <summary>
/// 方格值
/// </summary>
public string Value { get; set; } = "";
}
}

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

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

@ -13,13 +13,44 @@ namespace NDSD_Screwdriver
{
public partial class MainForm : Form
{
DOperate DOperate;
TcpServer server = TcpServer.Instance;
List<MonitorEntity> monitorEntities;
Random rand = new Random();
/// <summary>
/// 输出端口操作
/// </summary>
private DOperate DOperate;
/// <summary>
/// TCP服务器
/// </summary>
private TcpServer server = TcpServer.Instance;
/// <summary>
/// 前端列表集合
/// </summary>
private List<MonitorEntity> monitorEntities;
private Random rand = new Random();
///// <summary>
///// 判断是否是第一次初始化
///// </summary>
//private int flag = 0;
/// <summary>
/// 判断现在操作哪一行
/// </summary>
public int NowRowIndex = 0;
/// <summary>
/// RFID列表
/// </summary>
string[] RFIDs = new string[]
{
"1111222233334444",
"2222222233334444",
"3333222233334444",
"4444222233334444",
"5555222233334444"
};
public MainForm()
{
@ -29,86 +60,13 @@ namespace NDSD_Screwdriver
{
MessageBox.Show("服务端打开失败!");
}
monitorEntities = new List<MonitorEntity>()
{
new MonitorEntity()
{
RowEneieys = new List<RowEneiey>()
{
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<RowEneiey>()
{
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<RowEneiey>()
{
new RowEneiey()
{
ColumnIndex = 0,
Color = Brushes.Transparent
},
new RowEneiey()
{
ColumnIndex = 1,
Value = "33333333",
Color = Brushes.Transparent
},
new RowEneiey()
{
ColumnIndex = 2,
},
},
RowIndex = 2,
},
};
}
/// <summary>
/// 打开DO测试
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DOTest_Click(object sender, EventArgs e)
{
ScrewdriverTest screwdriverTest = new ScrewdriverTest(server, DOperate);
@ -127,55 +85,63 @@ namespace NDSD_Screwdriver
{
MessageBox.Show("服务端释放失败!");
}
}
}
/// <summary>
/// 列表回调函数
/// </summary>
/// <param name="g"></param>
/// <param name="rowIndex"></param>
/// <param name="colIndex"></param>
/// <param name="rectangle"></param>
/// <param name="value"></param>
/// <param name="sf"></param>
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)
/// <summary>
/// 测试按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
/// <summary>
/// 刷新列表
/// </summary>
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
});
}
}
/// <summary>
/// 初始化整个列表
/// </summary>
private void InitMonitirIntity()
{
monitorEntities = new List<MonitorEntity>();
for (int i = 0; i < RFIDs.Length; i++)
{
monitorEntities.Add(new MonitorEntity()
{
RowIndex = i,
RowEntitys = InitRows(i)
});
}
RefreshRoll();
}
/// <summary>
/// 初始化一行
/// </summary>
/// <param name="rowNo">当前的初始化行数</param>
/// <returns></returns>
private List<RowEntity> InitRows(int rowNo)
{
List<RowEntity> rowEntities = new List<RowEntity>();
for (int i = 0; i < 3; i++)
{
rowEntities.Add(new RowEntity()
{
ColumnIndex = i,
});
}
return rowEntities;
}
/// <summary>
/// 初始化RFID数据
/// </summary>
/// <param name="rFIDvalue">RFID列表</param>
private void SetRFIDValue(string[] rFIDvalue)
{
for (int i = 0; i < rFIDvalue.Length; i++)
{
monitorEntities[i].RowEntitys[1].Value = rFIDvalue[i];
}
}
/// <summary>
/// 设置当前行指示灯的状态以及工作的行
/// </summary>
/// <param name="lightState"></param>
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 ? "=>" : "";
}
}
}
}

@ -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<RowEneiey> 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; } = "";
}
}

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

Loading…
Cancel
Save