diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs b/StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs
new file mode 100644
index 0000000..103bbb3
--- /dev/null
+++ b/StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Text;
+using System.Data;
+
+namespace StuMgmLib.MyNameSpace
+{
+ public class BinaryED // 序列化与反序列化
+ {
+ ///
+ /// 序列化
+ ///
+ public static byte[] Serialize(T c)
+ {
+ MemoryStream ms = new MemoryStream();
+ BinaryFormatter iFormatter = new BinaryFormatter();
+ iFormatter.Serialize(ms, c);
+ byte[] buf = ms.GetBuffer();
+ return buf;
+ }
+
+ ///
+ /// 反序列化
+ ///
+ public static T Deserialize(byte[] buf)
+ {
+ MemoryStream ms = new MemoryStream(buf);
+ BinaryFormatter iFormatter = new BinaryFormatter();
+ var obj = (T)iFormatter.Deserialize(ms);
+ return obj;
+ }
+ }
+
+
+
+
+}
diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs
index 4f98ba8..3ac2f89 100644
--- a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs
+++ b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs
@@ -7,30 +7,77 @@ using System.Windows.Forms;
namespace StuMgmLib.MyNameSpace
{
+ ///
+ /// 数据操作
+ ///
public class DataAnalyze
{
- const string conStr = "data source=localhost; initial catalog=xinje; user id=root; pwd=980505";
-
- public static void GetFunc(byte[] dataRecv)
+
+ private enum verifyCode : short
{
- short account = 01941;
- string psw = "980505";
- bool res = LoginVerify(account, psw);
- res = !res;
+ error = -1,
+ notFound = -2,
+ admin = 1,
+ teacher = 2,
+ student = 3,
+ }
+ private const string conStr = "data source=localhost; initial catalog=xinje; user id=root; pwd=980505;charset = utf8";
+ /* Recv: ___________________________________________________________________
+ * | Account | Password | (SqlOperate) |
+ * |___short_____string______string________________________________________|
+ * Analyze:
+ * Account Permission (SqlOperate)
+ *
+ * Send: ____________________________________________________________________
+ * | Permission | DataSet |
+ * |___short________DS_______________________________________________________________|
+ */
- // 对buf数据处理,判断身份验证还是数据库操作
- //switch ()
- //{
- // case :break;
- // case :break;
- // case :break;
- // default:break;
- //}
+ ///
+ /// 解析ClientSend
+ ///
+ public static Info.ServerSend ClientSendAnalyze(Info.ClientSend cs)
+ {
+ Info.ServerSend ss = new Info.ServerSend();
+ ss.permission = LoginVerify(cs.account, cs.password); // 验证身份
+ if (ss.permission < 0) // 小于0,则权限有误
+ {
+ ss.ds = null;
+ return ss;
+ }
+ // if(operationCode != 0)
+ // 写数据表操作
+ // To do sth here ........
+ string[] tbName;
+ bool stuFlag = false;
+ switch (ss.permission)
+ {
+ case (short)verifyCode.admin:
+ tbName = new string[] { "user_info", "course_info", "user" };
+ break;
+ case (short)verifyCode.teacher:
+ tbName = new string[] { "user_info", "course_info" };
+ break;
+ case (short)verifyCode.student:
+ tbName = new string[] { "user_info", "course_info" };
+ stuFlag = true; break;
+ default:
+ tbName = null;
+ break;
+ }
+ ss.ds = getDataSet(tbName, stuFlag, cs.account);
+ return ss;
}
- public static bool LoginVerify(short account, string psw)
+
+ ///
+ /// 登录验证,若失败,则返回错误码;若身份验证成功,则返回用户权限;
+ ///
+ private static short LoginVerify(short account, string psw)
{
+ short notFound = -1;
+ short error = -2;
string qStu = "select * from user where account = " + account + " and password = '" + psw + "'";
MySqlConnection con = new MySqlConnection(conStr);
try
@@ -39,17 +86,17 @@ namespace StuMgmLib.MyNameSpace
MySqlCommand mCmd = new MySqlCommand(qStu, con);
MySqlDataReader mReader = mCmd.ExecuteReader();
if (mReader.HasRows)
- return true;
+ {
+ mReader.Read();
+ return mReader.GetInt16("permission");
+ }
else
- return false;
- //DataTable dt = new DataTable();
- //dt.Load(mReader);
- //Random r = new Random();
+ return notFound;
}
catch (MySqlException mySqlEx)
{
MessageBox.Show(mySqlEx.Message);
- return false;
+ return error;
}
finally
{
@@ -57,32 +104,40 @@ namespace StuMgmLib.MyNameSpace
}
}
- private static DataTable mysqlUse()
+ ///
+ /// 改
+ ///
+ private static void mySqlModify()
{
- // mysql Query
- string key = "";
- string para = "";
- string qStu = "select * from staffs where "; // 验证登录信息
- switch (key)
- {
- case "Id":
- qStu += " Id =" + Convert.ToString(para);
- break;
- case "All":
- qStu = "select * from staffs "; break;
- default:
- qStu += key + "= '" + Convert.ToString(para) + "'";
- break;
- }
+
+ }
+
+ ///
+ /// 查 将各表填入dataset
+ ///
+ private static DataSet getDataSet(string[] tbName, bool stuFlag, int account)
+ {
+ string str = "select * from ";
MySqlConnection con = new MySqlConnection(conStr);
try
{
con.Open();
- MySqlCommand mCmd = new MySqlCommand(qStu, con);
- MySqlDataReader mReader = mCmd.ExecuteReader();
- DataTable dt = new DataTable();
- dt.Load(mReader);
- return dt;
+ DataSet ds = new DataSet();
+ for (int index = 0; index < tbName.Length; index++)
+ {
+ string newStr = str + tbName[index];
+ if ((stuFlag == true) && (tbName[index] == "user_info"))
+ {
+ newStr += "where job_id = " + account.ToString();
+ }
+ MySqlCommand mCmd = new MySqlCommand(newStr, con);
+ MySqlDataReader mReader = mCmd.ExecuteReader();
+ DataTable dt = new DataTable();
+ dt.Load(mReader);
+ dt.TableName = tbName[index];
+ ds.Tables.Add(dt);
+ }
+ return ds;
}
catch (MySqlException mySqlEx)
{
@@ -95,5 +150,8 @@ namespace StuMgmLib.MyNameSpace
}
}
+
+
}
+
}
\ No newline at end of file
diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs b/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs
index 4a49e0f..86eb6d0 100644
--- a/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs
+++ b/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs
@@ -1,13 +1,26 @@
using System;
using System.Collections.Generic;
-using System.IO;
-//using System.Linq;
-using System.Runtime.Serialization.Formatters.Binary;
-using System.Text;
-//using System.Threading.Tasks;
+using System.Data;
-namespace StuMgmLib
+namespace StuMgmLib.MyNameSpace
{
+ public class Info
+ {
+ [Serializable]
+ public class ClientSend
+ {
+ public short account { get; set; }
+ public string password { get; set; }
+ public string sqlStr { get; set; }
+ }
+ [Serializable]
+ public class ServerSend
+ {
+ public short permission { get; set; }
+ public DataSet ds { get; set; }
+ }
+ }
+
#region 题目信息
[Serializable]
@@ -48,17 +61,17 @@ namespace StuMgmLib
#endregion
#region 学生单题详细信息
- public class HistoryInfo
- {
- DateTime Time;
- string Describe;
- }
- public class DetailInfo
- {
- public short CourseId;
- public short JobId;
- List Describes;
- }
+ //public class HistoryInfo
+ //{
+ // DateTime Time;
+ // string Describe;
+ //}
+ //public class DetailInfo
+ //{
+ // public short CourseId;
+ // public short JobId;
+ // List Describes;
+ //}
#endregion
@@ -81,21 +94,21 @@ namespace StuMgmLib
info.CourseStatus.Add(aa);
+ return BinaryED.Serialize(info);
- MemoryStream ms = new MemoryStream();
- BinaryFormatter iFormatter = new BinaryFormatter();
- iFormatter.Serialize(ms, info);
- byte[] buff = ms.GetBuffer();
- return buff;
}
public UserInfo Parse(byte[] bt)
{
- MemoryStream ms = new MemoryStream(bt);
- BinaryFormatter iFormatter = new BinaryFormatter();
- UserInfo obj = (UserInfo)iFormatter.Deserialize(ms);
- return obj;
+ return BinaryED.Deserialize(bt);
+ //MemoryStream ms = new MemoryStream(bt);
+ //BinaryFormatter iFormatter = new BinaryFormatter();
+ //UserInfo obj = (UserInfo)iFormatter.Deserialize(ms);
+ //return obj;
}
+
+
+
}
class StudentInfo
diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs
index 135a048..d41c3dc 100644
--- a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs
+++ b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
+using System.Data;
using System.Net;
using System.Net.Sockets;
namespace StuMgmLib.MyNameSpace
{
-
+ // 还有一种验证连接方式 Token
public class TcpConn
{
private IPEndPoint IPP = null;
@@ -45,6 +46,9 @@ namespace StuMgmLib.MyNameSpace
#endregion
#region 接收客户端连接
+ ///
+ /// 接收客户端连接
+ ///
public string acceptConnection()
{
try
@@ -61,18 +65,25 @@ namespace StuMgmLib.MyNameSpace
const int recvTimeOut = 3000; // 设置接收超时时间
#region 接收数据
+ ///
+ /// 接收数据
+ ///
public string acpMsg()
{
- byte[] arrDataRecv = new byte[4096]; // 定义接收数组
+ byte[] dataRecv = new byte[4096]; // 定义接收数组
string reEdPoint = "";
try
{
reEdPoint = socketClient.RemoteEndPoint.ToString();
socketClient.ReceiveTimeout = recvTimeOut;
- int len = socketClient.Receive(arrDataRecv);
- DataAnalyze.GetFunc(arrDataRecv); // 解析
- List listDataRecv = new List { }; // 定义截取列表
- return reEdPoint + " " + len.ToString() + " 断开连接 \n";
+ socketClient.Receive(dataRecv);
+
+ var cs = BinaryED.Deserialize(dataRecv);
+ Info.ServerSend ss = DataAnalyze.ClientSendAnalyze(cs);
+ byte[] dataSend = BinaryED.Serialize(ss);
+ socketClient.Send(dataSend);
+
+ return reEdPoint + " 断开连接 \n";
}
catch // 客户端断开连接
{
diff --git a/StuMgmServer/StuMgmLib/StuMgmLib.csproj b/StuMgmServer/StuMgmLib/StuMgmLib.csproj
index 96ca8b2..30826aa 100644
--- a/StuMgmServer/StuMgmLib/StuMgmLib.csproj
+++ b/StuMgmServer/StuMgmLib/StuMgmLib.csproj
@@ -33,7 +33,7 @@
false
-
+
False
..\..\..\MySql.Data.dll
@@ -43,6 +43,7 @@
+
diff --git a/StuMgmServer/StuMgmServer.sln b/StuMgmServer/StuMgmServer.sln
index 70a6d25..6eb86ba 100644
--- a/StuMgmServer/StuMgmServer.sln
+++ b/StuMgmServer/StuMgmServer.sln
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StuMgmServer", "StuMgmServe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StuMgmLib", "StuMgmLib\StuMgmLib.csproj", "{725C2786-699E-424F-8F3E-FB5BB4E5A3A5}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{E3D7C7F1-F922-4C6B-A44A-86F4DC73951A}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{725C2786-699E-424F-8F3E-FB5BB4E5A3A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{725C2786-699E-424F-8F3E-FB5BB4E5A3A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{725C2786-699E-424F-8F3E-FB5BB4E5A3A5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E3D7C7F1-F922-4C6B-A44A-86F4DC73951A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E3D7C7F1-F922-4C6B-A44A-86F4DC73951A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E3D7C7F1-F922-4C6B-A44A-86F4DC73951A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E3D7C7F1-F922-4C6B-A44A-86F4DC73951A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/StuMgmServer/StuMgmServer/Server.cs b/StuMgmServer/StuMgmServer/Server.cs
index 9d5d13a..4fa089d 100644
--- a/StuMgmServer/StuMgmServer/Server.cs
+++ b/StuMgmServer/StuMgmServer/Server.cs
@@ -8,7 +8,7 @@ namespace StuMgmServer
public partial class Server : Form
{
TcpConn tcpConn = new TcpConn();
- Thread tAccept = null;
+ Thread tUpdateUi = null;
private delegate void SetTextCallback(string text);
public Server()
@@ -20,7 +20,7 @@ namespace StuMgmServer
System.Environment.Exit(0);
}
///
- /// 委托更新界面
+ /// 委托:更新界面方法
///
private void setText(string text)
{
@@ -35,7 +35,9 @@ namespace StuMgmServer
}
}
-
+ ///
+ /// btn开关点击事件:开启、关闭服务器
+ ///
private void btnSerSwitch_Click(object sender, EventArgs e)
{
bool sFlag = tcpConn.SocketExist;
@@ -47,8 +49,8 @@ namespace StuMgmServer
{
int port = Convert.ToInt16(txtPort.Text);
tcpConn.OpenServer(port);
- tAccept = new Thread(updateHistory);
- tAccept.Start();
+ tUpdateUi = new Thread(updateHistory);
+ tUpdateUi.Start();
}
}
catch (Exception ep)
@@ -57,6 +59,9 @@ namespace StuMgmServer
}
}
+ ///
+ /// 线程:接收客户端连接,接收数据,数据处理;更新历史界面
+ ///
private void updateHistory()
{
while (tcpConn.SocketExist)
@@ -66,6 +71,9 @@ namespace StuMgmServer
}
}
+ ///
+ /// 定时器更新btn开关服务器
+ ///
private void tmr_Tick(object sender, EventArgs e)
{
if (tcpConn.SocketExist)
diff --git a/StuMgmServer/StuMgmServer/Server.resx b/StuMgmServer/StuMgmServer/Server.resx
index 06b0953..f769c72 100644
--- a/StuMgmServer/StuMgmServer/Server.resx
+++ b/StuMgmServer/StuMgmServer/Server.resx
@@ -112,15 +112,15 @@
2.0
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
+
17, 17
-
+
159, 17
\ No newline at end of file
diff --git a/StuMgmServer/Test/Form1.Designer.cs b/StuMgmServer/Test/Form1.Designer.cs
new file mode 100644
index 0000000..9013fcf
--- /dev/null
+++ b/StuMgmServer/Test/Form1.Designer.cs
@@ -0,0 +1,179 @@
+namespace Test
+{
+ partial class Form1
+ {
+ ///
+ /// 必需的设计器变量。
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// 清理所有正在使用的资源。
+ ///
+ /// 如果应释放托管资源,为 true;否则为 false。
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows 窗体设计器生成的代码
+
+ ///
+ /// 设计器支持所需的方法 - 不要
+ /// 使用代码编辑器修改此方法的内容。
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.tlpAll = new System.Windows.Forms.TableLayoutPanel();
+ this.rtxHistory = new System.Windows.Forms.RichTextBox();
+ this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+ this.txtPort = new System.Windows.Forms.TextBox();
+ this.lblSwiSta = new System.Windows.Forms.Label();
+ this.btnSerSwitch = new System.Windows.Forms.Button();
+ this.lblPort = new System.Windows.Forms.Label();
+ this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+ this.tmr = new System.Windows.Forms.Timer(this.components);
+ this.tlpAll.SuspendLayout();
+ this.tableLayoutPanel1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // tlpAll
+ //
+ this.tlpAll.ColumnCount = 2;
+ this.tlpAll.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 27.25581F));
+ this.tlpAll.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 72.74419F));
+ this.tlpAll.Controls.Add(this.rtxHistory, 0, 0);
+ this.tlpAll.Controls.Add(this.tableLayoutPanel1, 0, 0);
+ this.tlpAll.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.tlpAll.Location = new System.Drawing.Point(0, 24);
+ this.tlpAll.Name = "tlpAll";
+ this.tlpAll.RowCount = 1;
+ this.tlpAll.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tlpAll.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 425F));
+ this.tlpAll.Size = new System.Drawing.Size(965, 425);
+ this.tlpAll.TabIndex = 2;
+ //
+ // rtxHistory
+ //
+ this.rtxHistory.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.rtxHistory.Font = new System.Drawing.Font("Calibri", 10.8F);
+ this.rtxHistory.Location = new System.Drawing.Point(266, 3);
+ this.rtxHistory.Name = "rtxHistory";
+ this.rtxHistory.Size = new System.Drawing.Size(696, 419);
+ this.rtxHistory.TabIndex = 2;
+ this.rtxHistory.Text = "";
+ //
+ // tableLayoutPanel1
+ //
+ this.tableLayoutPanel1.ColumnCount = 2;
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 45.8042F));
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 54.1958F));
+ this.tableLayoutPanel1.Controls.Add(this.txtPort, 1, 0);
+ this.tableLayoutPanel1.Controls.Add(this.lblSwiSta, 0, 1);
+ this.tableLayoutPanel1.Controls.Add(this.btnSerSwitch, 1, 1);
+ this.tableLayoutPanel1.Controls.Add(this.lblPort, 0, 0);
+ this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Top;
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);
+ this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+ this.tableLayoutPanel1.RowCount = 2;
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(257, 100);
+ this.tableLayoutPanel1.TabIndex = 0;
+ //
+ // txtPort
+ //
+ this.txtPort.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
+ this.txtPort.Font = new System.Drawing.Font("Calibri", 10.8F);
+ this.txtPort.Location = new System.Drawing.Point(120, 10);
+ this.txtPort.Name = "txtPort";
+ this.txtPort.Size = new System.Drawing.Size(134, 29);
+ this.txtPort.TabIndex = 3;
+ this.txtPort.Text = "502";
+ this.txtPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ //
+ // lblSwiSta
+ //
+ this.lblSwiSta.Anchor = System.Windows.Forms.AnchorStyles.None;
+ this.lblSwiSta.AutoSize = true;
+ this.lblSwiSta.Font = new System.Drawing.Font("Calibri", 10.8F);
+ this.lblSwiSta.Location = new System.Drawing.Point(3, 63);
+ this.lblSwiSta.Name = "lblSwiSta";
+ this.lblSwiSta.Size = new System.Drawing.Size(110, 23);
+ this.lblSwiSta.TabIndex = 1;
+ this.lblSwiSta.Text = "服务器状态";
+ //
+ // btnSerSwitch
+ //
+ this.btnSerSwitch.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.btnSerSwitch.Font = new System.Drawing.Font("Calibri", 10.8F);
+ this.btnSerSwitch.Location = new System.Drawing.Point(120, 53);
+ this.btnSerSwitch.Name = "btnSerSwitch";
+ this.btnSerSwitch.Size = new System.Drawing.Size(134, 44);
+ this.btnSerSwitch.TabIndex = 2;
+ this.btnSerSwitch.Text = "开启服务器";
+ this.btnSerSwitch.UseVisualStyleBackColor = true;
+ this.btnSerSwitch.Click += new System.EventHandler(this.btnSerSwitch_Click);
+ //
+ // lblPort
+ //
+ this.lblPort.Anchor = System.Windows.Forms.AnchorStyles.None;
+ this.lblPort.AutoSize = true;
+ this.lblPort.Font = new System.Drawing.Font("Calibri", 10.8F);
+ this.lblPort.Location = new System.Drawing.Point(13, 13);
+ this.lblPort.Name = "lblPort";
+ this.lblPort.Size = new System.Drawing.Size(90, 23);
+ this.lblPort.TabIndex = 0;
+ this.lblPort.Text = "本地端口";
+ //
+ // menuStrip1
+ //
+ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Size = new System.Drawing.Size(965, 24);
+ this.menuStrip1.TabIndex = 3;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // tmr
+ //
+ this.tmr.Enabled = true;
+ this.tmr.Interval = 500;
+ this.tmr.Tick += new System.EventHandler(this.tmr_Tick);
+ //
+ // Form1
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(965, 449);
+ this.Controls.Add(this.tlpAll);
+ this.Controls.Add(this.menuStrip1);
+ this.Name = "Form1";
+ this.Text = "Form1";
+ this.tlpAll.ResumeLayout(false);
+ this.tableLayoutPanel1.ResumeLayout(false);
+ this.tableLayoutPanel1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TableLayoutPanel tlpAll;
+ private System.Windows.Forms.RichTextBox rtxHistory;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
+ private System.Windows.Forms.TextBox txtPort;
+ private System.Windows.Forms.Label lblSwiSta;
+ private System.Windows.Forms.Button btnSerSwitch;
+ private System.Windows.Forms.Label lblPort;
+ private System.Windows.Forms.MenuStrip menuStrip1;
+ private System.Windows.Forms.Timer tmr;
+ }
+}
+
diff --git a/StuMgmServer/Test/Form1.cs b/StuMgmServer/Test/Form1.cs
new file mode 100644
index 0000000..bf9b0eb
--- /dev/null
+++ b/StuMgmServer/Test/Form1.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Threading;
+using System.Windows.Forms;
+using StuMgmLib.MyNameSpace;
+
+namespace Test
+{
+ public partial class Form1 : Form
+ {
+ TcpConn tcpConn = new TcpConn();
+ Thread tUpdateUi = null;
+ private delegate void SetTextCallback(string text);
+
+ public Form1()
+ {
+ InitializeComponent();
+ }
+ private void Server_FormClosed(object sender, FormClosedEventArgs e)
+ {
+ System.Environment.Exit(0);
+ }
+ ///
+ /// 委托:更新界面方法
+ ///
+ private void setText(string text)
+ {
+ if (rtxHistory.InvokeRequired)
+ {
+ SetTextCallback method = new SetTextCallback(setText);
+ Invoke(method, new object[] { text });
+ }
+ else
+ {
+ rtxHistory.Text = text + rtxHistory.Text;
+ }
+ }
+
+ ///
+ /// btn开关点击事件:开启、关闭服务器
+ ///
+ private void btnSerSwitch_Click(object sender, EventArgs e)
+ {
+ bool sFlag = tcpConn.SocketExist;
+ try
+ {
+ if (sFlag == true)
+ tcpConn.CloseServer();
+ else if (sFlag != true)
+ {
+ int port = Convert.ToInt16(txtPort.Text);
+ tcpConn.OpenServer(port);
+ tUpdateUi = new Thread(updateHistory);
+ tUpdateUi.Start();
+ }
+ }
+ catch (Exception ep)
+ {
+ MessageBox.Show(ep.Message);
+ }
+ }
+
+ ///
+ /// 线程:接收客户端连接,接收数据,数据处理;更新历史界面
+ ///
+ private void updateHistory()
+ {
+ while (tcpConn.SocketExist)
+ {
+ setText(tcpConn.acceptConnection());
+ setText(tcpConn.acpMsg());
+ }
+ }
+
+ ///
+ /// 定时器更新btn开关服务器
+ ///
+ private void tmr_Tick(object sender, EventArgs e)
+ {
+ if (tcpConn.SocketExist)
+ btnSerSwitch.Text = "关闭服务器";
+ else
+ btnSerSwitch.Text = "开启服务器";
+ }
+
+
+
+
+
+ }
+}
diff --git a/StuMgmServer/Test/Form1.resx b/StuMgmServer/Test/Form1.resx
new file mode 100644
index 0000000..1a2920d
--- /dev/null
+++ b/StuMgmServer/Test/Form1.resx
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 242, 17
+
+
+ 384, 17
+
+
\ No newline at end of file
diff --git a/StuMgmServer/Test/Program.cs b/StuMgmServer/Test/Program.cs
new file mode 100644
index 0000000..86fd0fb
--- /dev/null
+++ b/StuMgmServer/Test/Program.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+
+namespace Test
+{
+ static class Program
+ {
+ ///
+ /// 应用程序的主入口点。
+ ///
+ [STAThread]
+ static void Main()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new Form1());
+ }
+ }
+}
diff --git a/StuMgmServer/Test/Properties/AssemblyInfo.cs b/StuMgmServer/Test/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..510adb9
--- /dev/null
+++ b/StuMgmServer/Test/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过以下
+// 特性集控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Test")]
+[assembly: AssemblyCopyright("Copyright © 2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("39f78726-24f8-499a-86d5-1758f9b27e0f")]
+
+// 程序集的版本信息由下面四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/StuMgmServer/Test/Properties/Resources.Designer.cs b/StuMgmServer/Test/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..f32afcf
--- /dev/null
+++ b/StuMgmServer/Test/Properties/Resources.Designer.cs
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+//
+// 此代码由工具生成。
+// 运行时版本: 4.0.30319.42000
+//
+// 对此文件的更改可能会导致不正确的行为,并且如果
+// 重新生成代码,这些更改将丢失。
+//
+//------------------------------------------------------------------------------
+
+namespace Test.Properties
+{
+
+
+ ///
+ /// 一个强类型的资源类,用于查找本地化的字符串等。
+ ///
+ // 此类是由 StronglyTypedResourceBuilder
+ // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+ // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+ // (以 /str 作为命令选项),或重新生成 VS 项目。
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources
+ {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources()
+ {
+ }
+
+ ///
+ /// 返回此类使用的、缓存的 ResourceManager 实例。
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager
+ {
+ get
+ {
+ if ((resourceMan == null))
+ {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// 为所有资源查找重写当前线程的 CurrentUICulture 属性,
+ /// 方法是使用此强类型资源类。
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture
+ {
+ get
+ {
+ return resourceCulture;
+ }
+ set
+ {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/StuMgmServer/Test/Properties/Resources.resx b/StuMgmServer/Test/Properties/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/StuMgmServer/Test/Properties/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/StuMgmServer/Test/Properties/Settings.Designer.cs b/StuMgmServer/Test/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..a8cf573
--- /dev/null
+++ b/StuMgmServer/Test/Properties/Settings.Designer.cs
@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace Test.Properties
+{
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+ {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default
+ {
+ get
+ {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/StuMgmServer/Test/Properties/Settings.settings b/StuMgmServer/Test/Properties/Settings.settings
new file mode 100644
index 0000000..3964565
--- /dev/null
+++ b/StuMgmServer/Test/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/StuMgmServer/Test/Test.csproj b/StuMgmServer/Test/Test.csproj
new file mode 100644
index 0000000..13113c7
--- /dev/null
+++ b/StuMgmServer/Test/Test.csproj
@@ -0,0 +1,87 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {E3D7C7F1-F922-4C6B-A44A-86F4DC73951A}
+ WinExe
+ Properties
+ Test
+ Test
+ v2.0
+ 512
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ Form1.cs
+
+
+
+
+ Form1.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+ {725c2786-699e-424f-8f3e-fb5bb4e5a3a5}
+ StuMgmLib
+
+
+
+
+
\ No newline at end of file