| @@ -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(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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> CourseStatus; | |||
| } | |||
| #endregion | |||
| #region 学生单题详细信息 | |||
| public class HistoryInfo | |||
| { | |||
| DateTime Time; | |||
| string Describe; | |||
| } | |||
| public class DetailInfo | |||
| { | |||
| public short CourseId; | |||
| public short JobId; | |||
| List<HistoryInfo> Describes; | |||
| } | |||
| #endregion | |||
| class Server | |||
| { | |||
| //List<CourseInfo> 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>(); | |||
| 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<CourseInfo> 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); | |||
| //} | |||
| } | |||
| } | |||
| @@ -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; | |||
| /// <summary> | |||
| @@ -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<byte> listDataRecv = new List<byte> { }; // 定义截取列表 | |||
| return reEdPoint + " " + len.ToString() + " 断开连接 \n"; | |||
| } | |||
| @@ -11,6 +11,7 @@ | |||
| <AssemblyName>StuMgmLib</AssemblyName> | |||
| <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> | |||
| <FileAlignment>512</FileAlignment> | |||
| <TargetFrameworkProfile /> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
| <DebugSymbols>true</DebugSymbols> | |||
| @@ -20,6 +21,7 @@ | |||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <Prefer32Bit>false</Prefer32Bit> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
| <DebugType>pdbonly</DebugType> | |||
| @@ -28,14 +30,21 @@ | |||
| <DefineConstants>TRACE</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <Prefer32Bit>false</Prefer32Bit> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Reference Include="MySql.Data, Version=8.0.21.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL"> | |||
| <SpecificVersion>False</SpecificVersion> | |||
| <HintPath>..\..\..\MySql.Data.dll</HintPath> | |||
| </Reference> | |||
| <Reference Include="System" /> | |||
| <Reference Include="System.Data" /> | |||
| <Reference Include="System.Windows.Forms" /> | |||
| <Reference Include="System.Xml" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Compile Include="MyNameSpace\DataAnalyze.cs" /> | |||
| <Compile Include="MyNameSpace\StuMgmSer.cs" /> | |||
| <Compile Include="MyNameSpace\TcpConn.cs" /> | |||
| <Compile Include="Properties\AssemblyInfo.cs" /> | |||
| </ItemGroup> | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -24,14 +24,14 @@ namespace StuMgmServer | |||
| /// </summary> | |||
| 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; | |||
| } | |||
| } | |||
| @@ -112,15 +112,15 @@ | |||
| <value>2.0</value> | |||
| </resheader> | |||
| <resheader name="reader"> | |||
| <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
| <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
| </resheader> | |||
| <resheader name="writer"> | |||
| <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
| <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
| </resheader> | |||
| <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | |||
| <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | |||
| <value>17, 17</value> | |||
| </metadata> | |||
| <metadata name="tmr.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | |||
| <metadata name="tmr.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | |||
| <value>159, 17</value> | |||
| </metadata> | |||
| </root> | |||
| @@ -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<CourseInfo> GetCourseInfo(); | |||
| //UserInfo GetUserInfo(short jobId); | |||
| //DetailInfo GetDetailInfo(short jobId, short courseId); | |||
| List<CourseInfo> 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<CourseInfo> 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); | |||
| } | |||
| } | |||
| } | |||
| @@ -22,6 +22,7 @@ | |||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <Prefer32Bit>false</Prefer32Bit> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
| <PlatformTarget>AnyCPU</PlatformTarget> | |||
| @@ -31,6 +32,7 @@ | |||
| <DefineConstants>TRACE</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <Prefer32Bit>false</Prefer32Bit> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Reference Include="System" /> | |||
| @@ -49,7 +51,6 @@ | |||
| </Compile> | |||
| <Compile Include="Program.cs" /> | |||
| <Compile Include="Properties\AssemblyInfo.cs" /> | |||
| <Compile Include="StuMgmSer.cs" /> | |||
| <EmbeddedResource Include="Properties\Resources.resx"> | |||
| <Generator>ResXFileCodeGenerator</Generator> | |||
| <LastGenOutput>Resources.Designer.cs</LastGenOutput> | |||