From daa8ba7e1851fc17998f252c02e3cd340417a436 Mon Sep 17 00:00:00 2001 From: Somuns Date: Mon, 11 Jan 2021 16:57:27 +0800 Subject: [PATCH] =?UTF-8?q?MySqlData.Dll=202.0=20=E4=B8=8EMySql=20Server8.?= =?UTF-8?q?0=20=EF=BC=88=E5=8A=A0=E5=AF=86=E6=96=B9=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=89=20=E5=88=86=E6=9E=90=E7=B1=BB=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StuMgmLib/MyNameSpace/DataAnalyze.cs | 88 ++++++++++++- .../StuMgmLib/MyNameSpace/StuMgmSer.cs | 118 ++++++++++++++++++ StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs | 14 +-- StuMgmServer/StuMgmLib/StuMgmLib.csproj | 9 ++ StuMgmServer/StuMgmServer/Server.Designer.cs | 22 ++-- StuMgmServer/StuMgmServer/Server.cs | 4 +- StuMgmServer/StuMgmServer/Server.resx | 8 +- StuMgmServer/StuMgmServer/StuMgmSer.cs | 24 ++-- StuMgmServer/StuMgmServer/StuMgmServer.csproj | 3 +- 9 files changed, 243 insertions(+), 47 deletions(-) create mode 100644 StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs index 6a5d101..4f98ba8 100644 --- a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs +++ b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs @@ -1,19 +1,99 @@ -using System; +using MySql.Data.MySqlClient; +using System; using System.Collections.Generic; +using System.Data; using System.Text; +using System.Windows.Forms; namespace StuMgmLib.MyNameSpace { public class DataAnalyze { - public void Analyze(byte[] data) + const string conStr = "data source=localhost; initial catalog=xinje; user id=root; pwd=980505"; + + public static void GetFunc(byte[] dataRecv) { + short account = 01941; + string psw = "980505"; + bool res = LoginVerify(account, psw); + res = !res; + + + // 对buf数据处理,判断身份验证还是数据库操作 + //switch () + //{ + // case :break; + // case :break; + // case :break; + // default:break; + //} + } + public static bool LoginVerify(short account, string psw) + { + string qStu = "select * from user where account = " + account + " and password = '" + psw + "'"; + MySqlConnection con = new MySqlConnection(conStr); + try + { + con.Open(); + MySqlCommand mCmd = new MySqlCommand(qStu, con); + MySqlDataReader mReader = mCmd.ExecuteReader(); + if (mReader.HasRows) + return true; + else + return false; + //DataTable dt = new DataTable(); + //dt.Load(mReader); + //Random r = new Random(); + } + catch (MySqlException mySqlEx) + { + MessageBox.Show(mySqlEx.Message); + return false; + } + finally + { + con.Close(); + } } - private void mysqlUse() + private static DataTable mysqlUse() { // 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; + } + 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; + } + catch (MySqlException mySqlEx) + { + MessageBox.Show(mySqlEx.Message); + return null; + } + finally + { + con.Close(); + } } + } -} +} \ No newline at end of file diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs b/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs new file mode 100644 index 0000000..4a49e0f --- /dev/null +++ b/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs @@ -0,0 +1,118 @@ +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; + +namespace StuMgmLib +{ + + #region 题目信息 + [Serializable] + public class CourseInfo + { + public short Id; + public short Pid; + public int Time; + public string Name; + public string Content; + } + #endregion + + #region 学生题目信息一览 + public enum CourseStatusEnum + { + undo, // 未开始 + doing, // 进行中 + waiting, // 等待验收 + failed, // 验收失败 + preSharing, // 准备分享 + pass // 验收通过 + } + + [Serializable] + public class CourseStatus + { + public short CourseId; + public CourseStatusEnum Status; + } + [Serializable] + public class UserInfo + { + public short JobId; + public string Name; + public List CourseStatus; + } + #endregion + + #region 学生单题详细信息 + public class HistoryInfo + { + DateTime Time; + string Describe; + } + public class DetailInfo + { + public short CourseId; + public short JobId; + List Describes; + } + #endregion + + + + class Server + { + //List GetCourseInfo(); + //UserInfo GetUserInfo(short jobId); + //DetailInfo GetDetailInfo(short jobId, short courseId); + + public byte[] GetUser(short jobId) + { + UserInfo info = new UserInfo(); + info.JobId = 111; + info.Name = "aaaa"; + info.CourseStatus = new List(); + CourseStatus aa = new CourseStatus(); + aa.CourseId = 222; + aa.Status = CourseStatusEnum.undo; // 做题状态 + info.CourseStatus.Add(aa); + + + + 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; + } + } + + class StudentInfo + { + //List GetCourseInfo(); + //UserInfo GetUserInfo(short jobId); + //DetailInfo GetDetailInfo(short jobId, short courseId); + } + + + class Program + { + //static void Main(string[] args) + //{ + // Server s = new Server(); + // byte[] buf = s.GetUser(0); + // UserInfo aa = s.Parse(buf); + //} + } +} diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs index c3e39ab..135a048 100644 --- a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs +++ b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs @@ -5,21 +5,12 @@ using System.Net.Sockets; namespace StuMgmLib.MyNameSpace { + public class TcpConn { private IPEndPoint IPP = null; private Socket socket = null; private Socket socketClient = null; - //private Thread tAccept = null; - - #region 连接状态字段 - private bool my_connect = false; - public bool Connect - { - get { return my_connect; } - set { my_connect = value; } - } - #endregion private bool my_SocketExist = false; /// @@ -72,13 +63,14 @@ namespace StuMgmLib.MyNameSpace #region 接收数据 public string acpMsg() { - byte[] arrDataRecv = new byte[1024]; // 定义接收数组 + byte[] arrDataRecv = 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"; } diff --git a/StuMgmServer/StuMgmLib/StuMgmLib.csproj b/StuMgmServer/StuMgmLib/StuMgmLib.csproj index ce1eb55..96ca8b2 100644 --- a/StuMgmServer/StuMgmLib/StuMgmLib.csproj +++ b/StuMgmServer/StuMgmLib/StuMgmLib.csproj @@ -11,6 +11,7 @@ StuMgmLib v2.0 512 + true @@ -20,6 +21,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -28,14 +30,21 @@ TRACE prompt 4 + false + + False + ..\..\..\MySql.Data.dll + + + diff --git a/StuMgmServer/StuMgmServer/Server.Designer.cs b/StuMgmServer/StuMgmServer/Server.Designer.cs index ea89c5c..17693a4 100644 --- a/StuMgmServer/StuMgmServer/Server.Designer.cs +++ b/StuMgmServer/StuMgmServer/Server.Designer.cs @@ -30,7 +30,7 @@ { this.components = new System.ComponentModel.Container(); this.tlpAll = new System.Windows.Forms.TableLayoutPanel(); - this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + 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(); @@ -47,7 +47,7 @@ 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.richTextBox1, 0, 0); + 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); @@ -58,15 +58,15 @@ this.tlpAll.Size = new System.Drawing.Size(1075, 413); this.tlpAll.TabIndex = 0; // - // richTextBox1 + // rtxHistory // - this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.richTextBox1.Font = new System.Drawing.Font("Calibri", 10.8F); - this.richTextBox1.Location = new System.Drawing.Point(295, 3); - this.richTextBox1.Name = "richTextBox1"; - this.richTextBox1.Size = new System.Drawing.Size(777, 407); - this.richTextBox1.TabIndex = 2; - this.richTextBox1.Text = ""; + 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(295, 3); + this.rtxHistory.Name = "rtxHistory"; + this.rtxHistory.Size = new System.Drawing.Size(777, 407); + this.rtxHistory.TabIndex = 2; + this.rtxHistory.Text = ""; // // tableLayoutPanel1 // @@ -175,7 +175,7 @@ private System.Windows.Forms.Label lblPort; private System.Windows.Forms.TextBox txtPort; private System.Windows.Forms.Timer tmr; - private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.RichTextBox rtxHistory; } } diff --git a/StuMgmServer/StuMgmServer/Server.cs b/StuMgmServer/StuMgmServer/Server.cs index 5ce076f..9d5d13a 100644 --- a/StuMgmServer/StuMgmServer/Server.cs +++ b/StuMgmServer/StuMgmServer/Server.cs @@ -24,14 +24,14 @@ namespace StuMgmServer /// private void setText(string text) { - if (richTextBox1.InvokeRequired) + if (rtxHistory.InvokeRequired) { SetTextCallback method = new SetTextCallback(setText); Invoke(method, new object[] { text }); } else { - richTextBox1.Text += text; + rtxHistory.Text = text + rtxHistory.Text; } } diff --git a/StuMgmServer/StuMgmServer/Server.resx b/StuMgmServer/StuMgmServer/Server.resx index f769c72..06b0953 100644 --- a/StuMgmServer/StuMgmServer/Server.resx +++ b/StuMgmServer/StuMgmServer/Server.resx @@ -112,15 +112,15 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, 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 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - + 159, 17 \ No newline at end of file diff --git a/StuMgmServer/StuMgmServer/StuMgmSer.cs b/StuMgmServer/StuMgmServer/StuMgmSer.cs index 286b0b6..d6ec126 100644 --- a/StuMgmServer/StuMgmServer/StuMgmSer.cs +++ b/StuMgmServer/StuMgmServer/StuMgmSer.cs @@ -6,7 +6,7 @@ using System.Runtime.Serialization.Formatters.Binary; using System.Text; //using System.Threading.Tasks; -namespace ConsoleApplication1 +namespace StuMgmLib { #region 题目信息 @@ -64,9 +64,9 @@ namespace ConsoleApplication1 class Server { - //List GetCourseInfo(); - //UserInfo GetUserInfo(short jobId); - //DetailInfo GetDetailInfo(short jobId, short courseId); + List GetCourseInfo(); + UserInfo GetUserInfo(short jobId); + DetailInfo GetDetailInfo(short jobId, short courseId); public byte[] GetUser(short jobId) { @@ -95,12 +95,8 @@ namespace ConsoleApplication1 UserInfo obj = (UserInfo)iFormatter.Deserialize(ms); return obj; } - - - } - class StudentInfo { //List GetCourseInfo(); @@ -111,11 +107,11 @@ namespace ConsoleApplication1 class Program { - //static void Main(string[] args) - //{ - // Server s = new Server(); - // byte[] buf = s.GetUser(0); - // UserInfo aa = s.Prase(buf); - //} + static void Main(string[] args) + { + Server s = new Server(); + byte[] buf = s.GetUser(0); + UserInfo aa = s.Prase(buf); + } } } diff --git a/StuMgmServer/StuMgmServer/StuMgmServer.csproj b/StuMgmServer/StuMgmServer/StuMgmServer.csproj index f9db7cd..77a5bbe 100644 --- a/StuMgmServer/StuMgmServer/StuMgmServer.csproj +++ b/StuMgmServer/StuMgmServer/StuMgmServer.csproj @@ -22,6 +22,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -31,6 +32,7 @@ TRACE prompt 4 + false @@ -49,7 +51,6 @@ - ResXFileCodeGenerator Resources.Designer.cs