add - 添加服务器操作

master
SoulStar 1 month ago
parent 821cf907f6
commit 3888dcb9fa

@ -29,14 +29,21 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.dataGridView1 = new System.Windows.Forms.DataGridView(); 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.RfidNo = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Green = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Green = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Yellow = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Yellow = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Red = 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(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// dataGridView1 // dataGridView1
@ -48,33 +55,14 @@
this.Yellow, this.Yellow,
this.Red}); this.Red});
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; 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.Name = "dataGridView1";
this.dataGridView1.RowHeadersWidth = 62; this.dataGridView1.RowHeadersWidth = 62;
this.dataGridView1.RowTemplate.Height = 30; 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; 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 // RfidNo
// //
this.RfidNo.DataPropertyName = "RfidNo"; this.RfidNo.DataPropertyName = "RfidNo";
@ -115,17 +103,102 @@
this.Red.Resizable = System.Windows.Forms.DataGridViewTriState.False; this.Red.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.Red.Width = 80; 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 // 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.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.btnSave);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FrmSetting"; this.Name = "FrmSetting";
this.Text = "参数设置"; this.Text = "参数设置";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -139,5 +212,11 @@
private System.Windows.Forms.DataGridViewTextBoxColumn Green; private System.Windows.Forms.DataGridViewTextBoxColumn Green;
private System.Windows.Forms.DataGridViewTextBoxColumn Yellow; private System.Windows.Forms.DataGridViewTextBoxColumn Yellow;
private System.Windows.Forms.DataGridViewTextBoxColumn Red; 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;
} }
} }

@ -19,6 +19,8 @@ namespace NDSD_Screwdriver
{ {
public partial class FrmSetting : Form public partial class FrmSetting : Form
{ {
public FrmSetting() public FrmSetting()
{ {
InitializeComponent(); InitializeComponent();
@ -43,7 +45,8 @@ namespace NDSD_Screwdriver
} }
private DataTable GetTable() { private DataTable GetTable()
{
DataTable table = new DataTable(); DataTable table = new DataTable();
table.Columns.Add("DisplayMember", typeof(string)); table.Columns.Add("DisplayMember", typeof(string));
@ -185,5 +188,12 @@ namespace NDSD_Screwdriver
int b = 16; int b = 16;
return x >= a && x <= b; return x >= a && x <= b;
} }
private void SetServerIPButton_Click(object sender, EventArgs e)
{
MemorySetting.ServerIP = ServerIPTextbox.Text;
MemorySetting.ServerPort = ServerPortTextbox.Text;
}
} }
} }

@ -129,4 +129,16 @@
<metadata name="Red.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Red.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="RfidNo.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Green.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Yellow.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Red.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>

@ -34,6 +34,10 @@
this.ScrewdriverMonitor = new DNSD_Controls.HslTable(); this.ScrewdriverMonitor = new DNSD_Controls.HslTable();
this.TestButton = new System.Windows.Forms.Button(); this.TestButton = new System.Windows.Forms.Button();
this.InitButton = 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(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -119,11 +123,55 @@
this.InitButton.UseVisualStyleBackColor = true; this.InitButton.UseVisualStyleBackColor = true;
this.InitButton.Click += new System.EventHandler(this.InitButton_Click); 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 // MainForm
// //
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(1148, 850); 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.InitButton);
this.Controls.Add(this.TestButton); this.Controls.Add(this.TestButton);
this.Controls.Add(this.ScrewdriverMonitor); this.Controls.Add(this.ScrewdriverMonitor);
@ -146,5 +194,9 @@
private DNSD_Controls.HslTable ScrewdriverMonitor; private DNSD_Controls.HslTable ScrewdriverMonitor;
private System.Windows.Forms.Button TestButton; private System.Windows.Forms.Button TestButton;
private System.Windows.Forms.Button InitButton; 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;
} }
} }

@ -59,7 +59,7 @@ namespace NDSD_Screwdriver
{ {
InitializeComponent(); InitializeComponent();
DOperate = new DOperate(); DOperate = new DOperate();
if (!server.ServerOpen("192.168.0.101", "6001")) if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort))
{ {
MessageBox.Show("服务端打开失败!"); 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("服务端释放失败!");
}
}
}
}
} }

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

@ -82,6 +82,7 @@
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Entity\MonitorEntity.cs" /> <Compile Include="Entity\MonitorEntity.cs" />
<Compile Include="MemorySetting.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScrewdriverTest.cs"> <Compile Include="ScrewdriverTest.cs">

@ -17,10 +17,13 @@ namespace NDSD_TouchSocket
string ClientIP; string ClientIP;
string ClientPort; string ClientPort;
TcpService service = new TcpService(); TcpService service;
public bool ServerOpen(string ip, string port) public bool ServerOpen(string ip, string port)
{ {
service = new TcpService();
try try
{ {
service.Connecting = (client, e) => 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) //private void BufferMemory(byte[] bytes)
//{ //{
// if (bytes[4] == 0x00 && bytes[5] == 0xB9) // if (bytes[4] == 0x00 && bytes[5] == 0xB9)

Loading…
Cancel
Save