add - 添加闪烁 优化代码 准备添加灯的逻辑

master
SoulStar 3 months ago
parent 5e6738ae64
commit 4bf8ca37cf

@ -58,11 +58,11 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Mapper\StudentMap.cs" /> <Compile Include="Mapper\Maps.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SQLiteContext.cs" /> <Compile Include="SQLiteContext.cs" />
<Compile Include="SqlLiteTool.cs" /> <Compile Include="SqlLiteTool.cs" />
<Compile Include="Student.cs" /> <Compile Include="Entitys.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />

@ -0,0 +1,42 @@
using System;
using System.ComponentModel;
using Chloe.Annotations;
namespace DNSD_DB
{
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; }
}
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; }
}
}

@ -2,22 +2,23 @@
namespace DNSD_DB.Mapper namespace DNSD_DB.Mapper
{ {
public class StudentMap:EntityTypeBuilder<Student>
public class RfidSettingMap : EntityTypeBuilder<RfidSetting>
{ {
public StudentMap() public RfidSettingMap()
{ {
this.MapTo("Student");
this.MapTo("RfidSetting");
this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey(); this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey();
} }
} }
public class RFIDLogMap : EntityTypeBuilder<RFIDLog>
public class RfidSettingMap : EntityTypeBuilder<RfidSetting>
{ {
public RfidSettingMap() public RFIDLogMap()
{ {
this.MapTo("RfidSetting"); this.MapTo("RFIDLog");
this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey(); this.Property(a => a.ID).IsAutoIncrement().IsPrimaryKey();
} }
} }

@ -13,8 +13,10 @@ namespace DNSD_DB
public static void CreateTable(string db) public static void CreateTable(string db)
{ {
DbConfiguration.UseTypeBuilders(typeof(StudentMap));
DbConfiguration.UseTypeBuilders(typeof(RfidSettingMap)); DbConfiguration.UseTypeBuilders(typeof(RfidSettingMap));
DbConfiguration.UseTypeBuilders(typeof(RFIDLogMap));
IDbContext dbContext = new SQLiteContext(new SQLiteConnectionFactory(db)); IDbContext dbContext = new SQLiteContext(new SQLiteConnectionFactory(db));
new SQLiteTableGenerator(dbContext).CreateTables(TableCreateMode.CreateIfNotExists); new SQLiteTableGenerator(dbContext).CreateTables(TableCreateMode.CreateIfNotExists);

@ -1,66 +0,0 @@
using System;
using System.ComponentModel;
using Chloe.Annotations;
namespace DNSD_DB
{
public class Student
{
/// <summary>
/// 学生ID [主键,自动递增]
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
[DisplayName("学生ID")]
public int ID { get; set; }
/// <summary>
/// 班级ID
/// </summary>
public int ClassID { get; set; }
/// <summary>
/// 学生姓名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 学生年龄
/// </summary>
public int Age { get; set; }
/// <summary>
/// 学生性别
/// </summary>
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,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NDSD_Screwdriver.Entity
{
public class LightsEntity
{
public int Green { get; set; }
public int Yellow { get; set; }
public int Red { get; set; }
}
}

@ -11,6 +11,10 @@ namespace NDSD_Screwdriver
{ {
public static Random r = new Random(); public static Random r = new Random();
/// <summary>
/// 随机颜色测试
/// </summary>
/// <returns></returns>
public static Brush TestRamColor() public static Brush TestRamColor()
{ {
int i = r.Next(0, 4); int i = r.Next(0, 4);
@ -22,9 +26,18 @@ namespace NDSD_Screwdriver
{ {
return Brushes.Yellow; return Brushes.Yellow;
} }
else return Brushes.Red; else /*if (i == 3)*/
{
return Brushes.Red;
}
//else return Brushes.Transparent;
} }
/// <summary>
/// 颜色枚举值转换为颜色
/// </summary>
/// <param name="lightState"></param>
/// <returns></returns>
public static Brush EnumColorToBrush(LightState lightState) public static Brush EnumColorToBrush(LightState lightState)
{ {
switch (lightState) switch (lightState)

@ -29,10 +29,6 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridView1 = new System.Windows.Forms.DataGridView();
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();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnSave = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox();
@ -41,6 +37,11 @@
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.ServerPortTextbox = new System.Windows.Forms.TextBox(); this.ServerPortTextbox = new System.Windows.Forms.TextBox();
this.ServerIPTextbox = new System.Windows.Forms.TextBox(); this.ServerIPTextbox = new System.Windows.Forms.TextBox();
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();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
@ -63,46 +64,6 @@
this.dataGridView1.Size = new System.Drawing.Size(615, 657); this.dataGridView1.Size = new System.Drawing.Size(615, 657);
this.dataGridView1.TabIndex = 0; this.dataGridView1.TabIndex = 0;
// //
// 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;
//
// groupBox1 // groupBox1
// //
this.groupBox1.Controls.Add(this.dataGridView1); this.groupBox1.Controls.Add(this.dataGridView1);
@ -117,7 +78,7 @@
// //
// btnSave // btnSave
// //
this.btnSave.Location = new System.Drawing.Point(27, 753); this.btnSave.Location = new System.Drawing.Point(27, 723);
this.btnSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.btnSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnSave.Name = "btnSave"; this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(163, 75); this.btnSave.Size = new System.Drawing.Size(163, 75);
@ -184,11 +145,61 @@
this.ServerIPTextbox.TabIndex = 0; this.ServerIPTextbox.TabIndex = 0;
this.ServerIPTextbox.Text = "192.168.0.101"; this.ServerIPTextbox.Text = "192.168.0.101";
// //
// RfidNo
//
this.RfidNo.DataPropertyName = "RfidNo";
this.RfidNo.HeaderText = "Rfid";
this.RfidNo.MaxInputLength = 20;
this.RfidNo.MinimumWidth = 20;
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;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(169, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(423, 15);
this.label3.TabIndex = 4;
this.label3.Text = "配置报警灯时,请按照:绿->黄->红 的顺序从大到小填写DO口";
//
// FrmSetting // FrmSetting
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1796, 937); this.ClientSize = new System.Drawing.Size(1160, 819);
this.Controls.Add(this.label3);
this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox2);
this.Controls.Add(this.btnSave); this.Controls.Add(this.btnSave);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
@ -200,6 +211,7 @@
this.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.groupBox2.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@ -208,15 +220,16 @@
private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnSave; 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;
private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox ServerPortTextbox; private System.Windows.Forms.TextBox ServerPortTextbox;
private System.Windows.Forms.TextBox ServerIPTextbox; private System.Windows.Forms.TextBox ServerIPTextbox;
private System.Windows.Forms.Button SetServerIPButton; private System.Windows.Forms.Button SetServerIPButton;
private System.Windows.Forms.DataGridViewTextBoxColumn RfidNo;
private System.Windows.Forms.DataGridViewTextBoxColumn Green;
private System.Windows.Forms.DataGridViewTextBoxColumn Yellow;
private System.Windows.Forms.DataGridViewTextBoxColumn Red;
private System.Windows.Forms.Label label3;
} }
} }

@ -14,6 +14,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml.Serialization;
namespace NDSD_Screwdriver namespace NDSD_Screwdriver
{ {
@ -34,6 +35,8 @@ namespace NDSD_Screwdriver
/// </summary> /// </summary>
private List<MonitorEntity> monitorEntities; private List<MonitorEntity> monitorEntities;
private List<RfidSetting> rfidSettings;
private Random rand = new Random(); private Random rand = new Random();
///// <summary> ///// <summary>
@ -46,23 +49,28 @@ namespace NDSD_Screwdriver
/// </summary> /// </summary>
public int NowRowIndex = 0; public int NowRowIndex = 0;
/// <summary>
/// 准备工作的行号
/// </summary>
public int ReadyRowIndex = 0;
/// <summary> /// <summary>
/// RFID列表 /// RFID列表
/// </summary> /// </summary>
public string[] RFIDs = new string[] public string[] RFIDs;
{
"1111222233334444", public List<LightsEntity> lightsEntities;
"2222222233334444",
"3333222233334444",
"4444222233334444",
"5555222233334444"
};
Thread thread;
bool flag = false;
SerialPortFactory serialPort; SerialPortFactory serialPort;
private CancellationTokenSource cancellationTokenSource; private CancellationTokenSource cancellationTokenSource;
private int textindex = 0;
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
@ -71,25 +79,27 @@ namespace NDSD_Screwdriver
{ {
MessageBox.Show("服务端打开失败!"); MessageBox.Show("服务端打开失败!");
} }
FlashThread();
serialPort = new SerialPortFactory(); serialPort = new SerialPortFactory();
StartLongRunningTask(); StartLongRunningTask();
} }
private void StartLongRunningTask() private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{ {
cancellationTokenSource = new CancellationTokenSource(); if (server != null)
Task.Run(() =>
{ {
while (!cancellationTokenSource.Token.IsCancellationRequested) if (!server.ServerStop())
{ {
// 这里是你的长期运行逻辑 MessageBox.Show("服务端关闭失败!");
Thread.Sleep(1000); // 模拟一些长时间的工作 }
if (!server.ServerDispose())
{
MessageBox.Show("服务端释放失败!");
}
} }
}, cancellationTokenSource.Token);
} }
#region 按钮
/// <summary> /// <summary>
/// 打开DO测试 /// 打开DO测试
@ -99,116 +109,152 @@ namespace NDSD_Screwdriver
private void DOTest_Click(object sender, EventArgs e) private void DOTest_Click(object sender, EventArgs e)
{ {
string str= serialPort.Read(); //string str = serialPort.Read();
ScrewdriverTest screwdriverTest = new ScrewdriverTest(server, DOperate); ScrewdriverTest screwdriverTest = new ScrewdriverTest(server, DOperate);
screwdriverTest.Show(); screwdriverTest.Show();
} }
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) /// <summary>
{ /// 测试按钮
if (server != null) /// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TestButton1_Click(object sender, EventArgs e)
{ {
if (!server.ServerStop()) if (RFIDs.Length == 0)
{ {
MessageBox.Show("服务端关闭失败!"); MessageBox.Show("没有值,请先设置。");
} }
if (!server.ServerDispose())
SetNowWorkRow(RFIDs[textindex]);
SetNowRowsLightState(1);
if (flag && thread.ThreadState == ThreadState.Suspended)
{ {
MessageBox.Show("服务端释放失败!"); thread.Resume();
} }
RefreshRoll();
if (++textindex >= RFIDs.Length)
{
textindex = 0;
} }
} }
/// <summary> /// <summary>
/// 列表回调函数 /// 初始化按钮
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="sender"></param>
/// <param name="rowIndex"></param> /// <param name="e"></param>
/// <param name="colIndex"></param> private void InitButton_Click(object sender, EventArgs e)
/// <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 (RowEntity rowEneiey in entity.RowEntitys) NowRowIndex = 0;
//读取rfid数据
var ctx = SqlLiteTool.GetDb(AppTool.GetDb());
var list = ctx.Query<RfidSetting>().Where(x => x.IsEnable == true).ToList();
RFIDs = list.Select(x => x.RfidNo).ToArray();
//读取报警灯数据
lightsEntities = new List<LightsEntity>();
for (int i = 0; i < list.Count; i++)
{
lightsEntities.Add(new LightsEntity()
{
Green = Convert.ToInt32(list[i].Green),
Yellow = Convert.ToInt32(list[i].Yellow),
Red = Convert.ToInt32(list[i].Red),
});
}
//初始化列表框架
monitorEntities = new List<MonitorEntity>();
for (int i = 0; i < RFIDs.Length; i++)
{ {
if (colIndex == rowEneiey.ColumnIndex) monitorEntities.Add(new MonitorEntity()
{ {
g.FillRectangle(rowEneiey.Color, rectangle); RowIndex = i,
g.DrawString(rowEneiey.Value, this.ScrewdriverMonitor.Font, Brushes.Black, rectangle, sf); RowEntitys = InitRows(i)
} });
} }
if (flag)
{
thread.Suspend();
} }
//更新值
for (int i = 0; i < RFIDs.Length; i++)
{
monitorEntities[i].RowEntitys[1].Value = RFIDs[i];
} }
RefreshRoll();
} }
/// <summary> /// <summary>
/// 测试按钮 /// 打开设置界面
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void TestButton1_Click(object sender, EventArgs e) private void SettingButton_Click(object sender, EventArgs e)
{
if (RFIDs.Length == 0)
{ {
MessageBox.Show("没有值,请先设置。"); FrmSetting frmSetting = new FrmSetting();
frmSetting.Show();
} }
SetNowRowsLightState(FormUtils.TestRamColor()); /// <summary>
/// 服务端重启按钮
RefreshRoll(); /// </summary>
if (++NowRowIndex >= RFIDs.Length) /// <param name="sender"></param>
/// <param name="e"></param>
private void ServerRestartButton_Click(object sender, EventArgs e)
{ {
NowRowIndex = 0; if (server.ServerRestart(MemorySetting.ServerIP, MemorySetting.ServerPort))
{
MessageBox.Show("服务器重启成功!");
} }
else
{
MessageBox.Show("服务器重启失败!请手动启动服务器。");
} }
private void InitButton_Click(object sender, EventArgs e)
{
NowRowIndex = 0;
InitMonitirIntity();
//var ctx = SqlLiteTool.GetDb(AppTool.GetDb());
//var list = ctx.Query<RfidSetting>().Where(x => x.IsEnable == true).ToList();
//RFIDs = list.Select(x => x.RfidNo).ToArray();
SetRFIDValue(RFIDs);
} }
/// <summary> /// <summary>
/// 刷新列表 /// 服务端手动启动
/// </summary> /// </summary>
private void RefreshRoll() /// <param name="sender"></param>
/// <param name="e"></param>
private void StartServerButton_Click(object sender, EventArgs e)
{ {
for (int i = 0; i < RFIDs.Length; i++) if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort))
{ {
ScrewdriverMonitor.AddRowTop(new string[]{ MessageBox.Show("服务端打开失败!");
"", }
"", else
"" {
}); MessageBox.Show("服务器启动成功");
} }
} }
/// <summary> /// <summary>
/// 初始化整个列表 /// 服务端手动停止
/// </summary> /// </summary>
private void InitMonitirIntity() /// <param name="sender"></param>
/// <param name="e"></param>
private void ServerStopButton_Click(object sender, EventArgs e)
{ {
monitorEntities = new List<MonitorEntity>(); if (server != null)
for (int i = 0; i < RFIDs.Length; i++)
{ {
monitorEntities.Add(new MonitorEntity() if (!server.ServerStop())
{ {
RowIndex = i, MessageBox.Show("服务端关闭失败!");
RowEntitys = InitRows(i) }
}); if (!server.ServerDispose())
{
MessageBox.Show("服务端释放失败!");
} }
RefreshRoll();
} }
}
#endregion
#region 功能性方法
/// <summary> /// <summary>
/// 初始化一行 /// 初始化一行
@ -229,84 +275,162 @@ namespace NDSD_Screwdriver
} }
/// <summary> /// <summary>
/// 初始化RFID数据 /// 刷新列表
/// </summary> /// </summary>
/// <param name="rFIDvalue">RFID列表</param> private void RefreshRoll()
private void SetRFIDValue(string[] rFIDvalue)
{ {
for (int i = 0; i < rFIDvalue.Length; i++) for (int i = 0; i < RFIDs.Length; i++)
{ {
monitorEntities[i].RowEntitys[1].Value = rFIDvalue[i]; ScrewdriverMonitor.AddRowTop(new string[]{
"",
"",
""
});
} }
} }
/// <summary> /// <summary>
/// 设置当前行指示灯的状态以及工作的行 /// 设置当前行指示灯的状态以及工作的行的标识 输入枚举类
/// </summary> /// </summary>
/// <param name="lightState"></param> /// <param name="lightState"></param>
private void SetNowRowsLightState(LightState lightState) private void SetNowRowsLightState(LightState lightState)
{ {
monitorEntities[NowRowIndex].RowEntitys[2].Color = FormUtils.EnumColorToBrush(lightState); SetNowRowsLightState(FormUtils.EnumColorToBrush(lightState));
}
for (int i = 0; i < RFIDs.Length; i++) private void SetNowRowsLightState(int lightState)
{ {
monitorEntities[NowRowIndex].RowEntitys[0].Value = i == NowRowIndex ? "=>" : ""; SetNowRowsLightState((LightState)lightState);
}
} }
/// <summary>
/// 设置当前行指示灯的状态以及工作的行的标识 输入Brush
/// </summary>
/// <param name="brush"></param>
private void SetNowRowsLightState(Brush brush) private void SetNowRowsLightState(Brush brush)
{ {
if (monitorEntities.Count == 0)
{
return;
}
monitorEntities[NowRowIndex].RowEntitys[2].Color = brush; monitorEntities[NowRowIndex].RowEntitys[2].Color = brush;
SetNextRowsFlash();
for (int i = 0; i < RFIDs.Length; i++) for (int i = 0; i < RFIDs.Length; i++)
{ {
monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : ""; monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : "";
} }
} }
private void SettingButton_Click(object sender, EventArgs e) /// <summary>
/// 设置待工作灯闪烁
/// </summary>
private void SetNextRowsFlash()
{ {
FrmSetting frmSetting = new FrmSetting(); ReadyRowIndex = NowRowIndex + 1;
frmSetting.Show(); if (ReadyRowIndex >= RFIDs.Length)
{
ReadyRowIndex = 0;
thread.Suspend();
return;
}
if (!flag)
{
thread.Start();
flag = true;
}
} }
private void ServerRestartButton_Click(object sender, EventArgs e)
/// <summary>
/// 根据读取到的RFID条码设置当前工作的行
/// </summary>
/// <param name="rfid">读取到的RFID</param>
private void SetNowWorkRow(string rfid)
{ {
if (server.ServerRestart(MemorySetting.ServerIP, MemorySetting.ServerPort)) for (int i = 0; i < RFIDs.Length; i++)
{ {
MessageBox.Show("服务器重启成功!"); if (monitorEntities[i].RowEntitys[1].Value == rfid)
}
else
{ {
MessageBox.Show("服务器重启失败!请手动启动服务器。"); NowRowIndex = i;
return;
}
}
} }
/// <summary>
/// 根据IO口控制灯的开关
/// </summary>
private void LightControl()
{
} }
private void StartServerButton_Click(object sender, EventArgs e) /// <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)
{ {
if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort)) foreach (MonitorEntity entity in monitorEntities)
{ {
MessageBox.Show("服务端打开失败!"); if (rowIndex == entity.RowIndex)
}
else
{ {
MessageBox.Show("服务器启动成功"); foreach (RowEntity rowEneiey in entity.RowEntitys)
{
if (colIndex == rowEneiey.ColumnIndex)
{
g.FillRectangle(rowEneiey.Color, rectangle);
g.DrawString(rowEneiey.Value, this.ScrewdriverMonitor.Font, Brushes.Black, rectangle, sf);
}
}
}
} }
} }
private void ServerStopButton_Click(object sender, EventArgs e) /// <summary>
/// RFID刷新任务
/// </summary>
private void StartLongRunningTask()
{ {
if (server != null) cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{ {
if (!server.ServerStop()) while (!cancellationTokenSource.Token.IsCancellationRequested)
{ {
MessageBox.Show("服务端关闭失败!"); // 这里是你的长期运行逻辑
Thread.Sleep(1000); // 模拟一些长时间的工作
} }
if (!server.ServerDispose()) }, cancellationTokenSource.Token);
{
MessageBox.Show("服务端释放失败!");
} }
/// <summary>
/// 等待工作指示灯闪烁进程
/// </summary>
private void FlashThread()
{
//等待闪烁线程
thread = new Thread(() =>
{
while (true)
{
DOperate.DTimeOpen(1, 1);
monitorEntities[ReadyRowIndex].RowEntitys[2].Color = Brushes.Yellow;
RefreshRoll();
Thread.Sleep(1000);
monitorEntities[ReadyRowIndex].RowEntitys[2].Color = Brushes.Transparent;
RefreshRoll();
Thread.Sleep(1000);
} }
});
} }
#endregion
} }
} }

@ -102,6 +102,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AppTool.cs" /> <Compile Include="AppTool.cs" />
<Compile Include="Entity\LightsEntity.cs" />
<Compile Include="FrmSetting.cs"> <Compile Include="FrmSetting.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

Loading…
Cancel
Save