diff --git a/NDSD-Screwdriver/FrmSetting.Designer.cs b/NDSD-Screwdriver/FrmSetting.Designer.cs index 2e8773b..1ef7167 100644 --- a/NDSD-Screwdriver/FrmSetting.Designer.cs +++ b/NDSD-Screwdriver/FrmSetting.Designer.cs @@ -29,14 +29,21 @@ 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(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.btnSave = new System.Windows.Forms.Button(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.SetServerIPButton = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.ServerPortTextbox = new System.Windows.Forms.TextBox(); + this.ServerIPTextbox = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // dataGridView1 @@ -48,33 +55,14 @@ this.Yellow, this.Red}); this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridView1.Location = new System.Drawing.Point(3, 24); + this.dataGridView1.Location = new System.Drawing.Point(3, 20); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowHeadersWidth = 62; this.dataGridView1.RowTemplate.Height = 30; - this.dataGridView1.Size = new System.Drawing.Size(693, 788); + this.dataGridView1.Size = new System.Drawing.Size(615, 657); 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"; @@ -115,17 +103,102 @@ this.Red.Resizable = System.Windows.Forms.DataGridViewTriState.False; this.Red.Width = 80; // + // groupBox1 + // + this.groupBox1.Controls.Add(this.dataGridView1); + this.groupBox1.Location = new System.Drawing.Point(24, 27); + this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBox1.Size = new System.Drawing.Size(621, 679); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "报警灯设置"; + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(27, 753); + this.btnSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(163, 75); + this.btnSave.TabIndex = 2; + this.btnSave.Text = "保存报警灯"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.SetServerIPButton); + this.groupBox2.Controls.Add(this.label2); + this.groupBox2.Controls.Add(this.label1); + this.groupBox2.Controls.Add(this.ServerPortTextbox); + this.groupBox2.Controls.Add(this.ServerIPTextbox); + this.groupBox2.Location = new System.Drawing.Point(651, 27); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(487, 65); + this.groupBox2.TabIndex = 3; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "服务端IP设置"; + // + // SetServerIPButton + // + this.SetServerIPButton.Location = new System.Drawing.Point(394, 24); + this.SetServerIPButton.Name = "SetServerIPButton"; + this.SetServerIPButton.Size = new System.Drawing.Size(75, 25); + this.SetServerIPButton.TabIndex = 4; + this.SetServerIPButton.Text = "设置"; + this.SetServerIPButton.UseVisualStyleBackColor = true; + this.SetServerIPButton.Click += new System.EventHandler(this.SetServerIPButton_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(223, 29); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(87, 15); + this.label2.TabIndex = 3; + this.label2.Text = "ServerPort"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(71, 15); + this.label1.TabIndex = 2; + this.label1.Text = "ServerIP"; + // + // ServerPortTextbox + // + this.ServerPortTextbox.Location = new System.Drawing.Point(316, 24); + this.ServerPortTextbox.Name = "ServerPortTextbox"; + this.ServerPortTextbox.Size = new System.Drawing.Size(63, 25); + this.ServerPortTextbox.TabIndex = 1; + this.ServerPortTextbox.Text = "6001"; + // + // ServerIPTextbox + // + this.ServerIPTextbox.Location = new System.Drawing.Point(83, 24); + this.ServerIPTextbox.Name = "ServerIPTextbox"; + this.ServerIPTextbox.Size = new System.Drawing.Size(134, 25); + this.ServerIPTextbox.TabIndex = 0; + this.ServerIPTextbox.Text = "192.168.0.101"; + // // FrmSetting // - this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(2021, 1124); + this.ClientSize = new System.Drawing.Size(1796, 937); + this.Controls.Add(this.groupBox2); this.Controls.Add(this.btnSave); this.Controls.Add(this.groupBox1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FrmSetting"; this.Text = "参数设置"; ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.groupBox1.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); this.ResumeLayout(false); } @@ -139,5 +212,11 @@ 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.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox ServerPortTextbox; + private System.Windows.Forms.TextBox ServerIPTextbox; + private System.Windows.Forms.Button SetServerIPButton; } } \ No newline at end of file diff --git a/NDSD-Screwdriver/FrmSetting.cs b/NDSD-Screwdriver/FrmSetting.cs index acf3781..56f25fe 100644 --- a/NDSD-Screwdriver/FrmSetting.cs +++ b/NDSD-Screwdriver/FrmSetting.cs @@ -19,6 +19,8 @@ namespace NDSD_Screwdriver { public partial class FrmSetting : Form { + + public FrmSetting() { InitializeComponent(); @@ -28,28 +30,29 @@ namespace NDSD_Screwdriver - + 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 = list;//DataGridView的行可以添加删除(只有允许添加行、删除行) dataGridView1.DataSource = new BindingList(list);//DataGridView的行可以添加删除(只有允许添加行、删除行) dataGridView1.AllowUserToAddRows = true; - + dataGridView1.AllowUserToDeleteRows = true; } - - private DataTable GetTable() { - + + private DataTable GetTable() + { + DataTable table = new DataTable(); - table.Columns.Add("DisplayMember",typeof(string)); + table.Columns.Add("DisplayMember", typeof(string)); table.Columns.Add("ValueMember", typeof(string)); - var dr=table.NewRow(); + var dr = table.NewRow(); dr[0] = "绿色"; dr[1] = "1"; @@ -103,7 +106,7 @@ namespace NDSD_Screwdriver rfidSetting.CreateDateTime = DateTime.Now; rfidSetting.RfidNo = rfid; - if (string.IsNullOrEmpty(green)) + if (string.IsNullOrEmpty(green)) { MessageBox.Show("请输入绿灯"); @@ -167,9 +170,9 @@ namespace NDSD_Screwdriver { var ctx = SqlLiteTool.GetDb(AppTool.GetDb()); ctx.Update(a => a.IsEnable == true, a => new RfidSetting() - { + { IsEnable = false - }); + }); ctx.InsertRange(list); } @@ -179,11 +182,18 @@ namespace NDSD_Screwdriver } - bool IsInRange(int x) + bool IsInRange(int x) { int a = 1; int b = 16; return x >= a && x <= b; } + + private void SetServerIPButton_Click(object sender, EventArgs e) + { + MemorySetting.ServerIP = ServerIPTextbox.Text; + MemorySetting.ServerPort = ServerPortTextbox.Text; + } } + } diff --git a/NDSD-Screwdriver/FrmSetting.resx b/NDSD-Screwdriver/FrmSetting.resx index 8cf7a32..11f9ba2 100644 --- a/NDSD-Screwdriver/FrmSetting.resx +++ b/NDSD-Screwdriver/FrmSetting.resx @@ -129,4 +129,16 @@ True + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/NDSD-Screwdriver/MainForm.Designer.cs b/NDSD-Screwdriver/MainForm.Designer.cs index 677f14b..9308f69 100644 --- a/NDSD-Screwdriver/MainForm.Designer.cs +++ b/NDSD-Screwdriver/MainForm.Designer.cs @@ -34,6 +34,10 @@ this.ScrewdriverMonitor = new DNSD_Controls.HslTable(); this.TestButton = new System.Windows.Forms.Button(); this.InitButton = new System.Windows.Forms.Button(); + this.SettingButton = new System.Windows.Forms.Button(); + 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.groupBox1.SuspendLayout(); this.SuspendLayout(); @@ -119,11 +123,55 @@ this.InitButton.UseVisualStyleBackColor = true; this.InitButton.Click += new System.EventHandler(this.InitButton_Click); // + // SettingButton + // + this.SettingButton.Location = new System.Drawing.Point(673, 769); + this.SettingButton.Name = "SettingButton"; + this.SettingButton.Size = new System.Drawing.Size(75, 69); + this.SettingButton.TabIndex = 8; + this.SettingButton.Text = "设置"; + this.SettingButton.UseVisualStyleBackColor = true; + this.SettingButton.Click += new System.EventHandler(this.SettingButton_Click); + // + // ServerRestartButton + // + this.ServerRestartButton.Location = new System.Drawing.Point(673, 708); + this.ServerRestartButton.Name = "ServerRestartButton"; + this.ServerRestartButton.Size = new System.Drawing.Size(75, 55); + this.ServerRestartButton.TabIndex = 9; + this.ServerRestartButton.Text = "重启服务器"; + this.ServerRestartButton.UseVisualStyleBackColor = true; + this.ServerRestartButton.Click += new System.EventHandler(this.ServerRestartButton_Click); + // + // StartServerButton + // + this.StartServerButton.Location = new System.Drawing.Point(673, 586); + this.StartServerButton.Name = "StartServerButton"; + this.StartServerButton.Size = new System.Drawing.Size(75, 55); + this.StartServerButton.TabIndex = 10; + this.StartServerButton.Text = "手动启动服务器"; + this.StartServerButton.UseVisualStyleBackColor = true; + this.StartServerButton.Click += new System.EventHandler(this.StartServerButton_Click); + // + // ServerStopButton + // + this.ServerStopButton.Location = new System.Drawing.Point(673, 647); + this.ServerStopButton.Name = "ServerStopButton"; + this.ServerStopButton.Size = new System.Drawing.Size(75, 55); + this.ServerStopButton.TabIndex = 11; + this.ServerStopButton.Text = "手动关闭服务器"; + this.ServerStopButton.UseVisualStyleBackColor = true; + this.ServerStopButton.Click += new System.EventHandler(this.ServerStopButton_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.ServerStopButton); + this.Controls.Add(this.StartServerButton); + this.Controls.Add(this.ServerRestartButton); + this.Controls.Add(this.SettingButton); this.Controls.Add(this.InitButton); this.Controls.Add(this.TestButton); this.Controls.Add(this.ScrewdriverMonitor); @@ -146,5 +194,9 @@ private DNSD_Controls.HslTable ScrewdriverMonitor; private System.Windows.Forms.Button TestButton; private System.Windows.Forms.Button InitButton; + private System.Windows.Forms.Button SettingButton; + private System.Windows.Forms.Button ServerRestartButton; + private System.Windows.Forms.Button StartServerButton; + private System.Windows.Forms.Button ServerStopButton; } } \ No newline at end of file diff --git a/NDSD-Screwdriver/MainForm.cs b/NDSD-Screwdriver/MainForm.cs index f92e947..1bfc8c8 100644 --- a/NDSD-Screwdriver/MainForm.cs +++ b/NDSD-Screwdriver/MainForm.cs @@ -59,7 +59,7 @@ namespace NDSD_Screwdriver { InitializeComponent(); DOperate = new DOperate(); - if (!server.ServerOpen("192.168.0.101", "6001")) + if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort)) { MessageBox.Show("服务端打开失败!"); } @@ -126,7 +126,7 @@ namespace NDSD_Screwdriver /// private void TestButton1_Click(object sender, EventArgs e) { - if(RFIDs.Length == 0) + if (RFIDs.Length == 0) { MessageBox.Show("没有值,请先设置。"); } @@ -232,6 +232,50 @@ namespace NDSD_Screwdriver } } - + private void SettingButton_Click(object sender, EventArgs e) + { + FrmSetting frmSetting = new FrmSetting(); + frmSetting.Show(); + } + + private void ServerRestartButton_Click(object sender, EventArgs e) + { + if (server.ServerRestart(MemorySetting.ServerIP, MemorySetting.ServerPort)) + { + MessageBox.Show("服务器重启成功!"); + } + else + { + MessageBox.Show("服务器重启失败!请手动启动服务器。"); + } + + } + + private void StartServerButton_Click(object sender, EventArgs e) + { + if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort)) + { + MessageBox.Show("服务端打开失败!"); + } + else + { + MessageBox.Show("服务器启动成功"); + } + } + + private void ServerStopButton_Click(object sender, EventArgs e) + { + if (server != null) + { + if (!server.ServerStop()) + { + MessageBox.Show("服务端关闭失败!"); + } + if (!server.ServerDispose()) + { + MessageBox.Show("服务端释放失败!"); + } + } + } } } diff --git a/NDSD-Screwdriver/MemorySetting.cs b/NDSD-Screwdriver/MemorySetting.cs new file mode 100644 index 0000000..253e022 --- /dev/null +++ b/NDSD-Screwdriver/MemorySetting.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NDSD_Screwdriver +{ + public static class MemorySetting + { + public static string ServerIP { get; set; } = "192.168.0.101"; + + public static string ServerPort { get; set; } = "6001"; + } +} diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj index 2f60c7e..3fb4dfa 100644 --- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj +++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj @@ -82,6 +82,7 @@ MainForm.cs + diff --git a/NDSD-TouchSocket/TcpServer.cs b/NDSD-TouchSocket/TcpServer.cs index 3aecdab..707be32 100644 --- a/NDSD-TouchSocket/TcpServer.cs +++ b/NDSD-TouchSocket/TcpServer.cs @@ -17,10 +17,13 @@ namespace NDSD_TouchSocket string ClientIP; string ClientPort; - TcpService service = new TcpService(); + TcpService service; public bool ServerOpen(string ip, string port) { + + service = new TcpService(); + try { service.Connecting = (client, e) => @@ -160,6 +163,21 @@ namespace NDSD_TouchSocket } } + public bool ServerRestart(string ip, string port) + { + try + { + service.Stop(); + service.Dispose(); + ServerOpen(ip, port); + return true; + } + catch (Exception ex) + { + return false; + } + } + //private void BufferMemory(byte[] bytes) //{ // if (bytes[4] == 0x00 && bytes[5] == 0xB9)