diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs b/StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs index 103bbb3..43d68dd 100644 --- a/StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs +++ b/StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.IO; using System.Runtime.Serialization.Formatters.Binary; -using System.Text; -using System.Data; namespace StuMgmLib.MyNameSpace { diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs b/StuMgmServer/StuMgmLib/MyNameSpace/CommonData.cs similarity index 95% rename from StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs rename to StuMgmServer/StuMgmLib/MyNameSpace/CommonData.cs index 7b2a40a..a93d75f 100644 --- a/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs +++ b/StuMgmServer/StuMgmLib/MyNameSpace/CommonData.cs @@ -11,17 +11,19 @@ namespace StuMgmLib.MyNameSpace { public short account { get; set; } public string password { get; set; } - public string [] sqlStr { get; set; } + public string[] sqlStr { get; set; } } [Serializable] public class ServerSend { public short permission { get; set; } public DataSet ds { get; set; } + public bool sqlSucceed { get; set; } } } - + #region Unused + #region 题目信息 [Serializable] public class CourseInfo @@ -129,4 +131,8 @@ namespace StuMgmLib.MyNameSpace //} } #endregion + + #endregion + } + diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs index dd5f1d3..db8a62d 100644 --- a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs +++ b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs @@ -27,8 +27,9 @@ namespace StuMgmLib.MyNameSpace * Account Permission (SqlOperate) * * Send: ____________________________________________________________________ - * | Permission | DataSet | - * |___short________DS_______________________________________________________________| + * | Permission | DataSet | + * |___short________DS___________________________________________________| + * */ /// @@ -43,11 +44,6 @@ namespace StuMgmLib.MyNameSpace ss.ds = null; return ss; } - bool sqlRes = false; - if (cs.sqlStr != null) // sql语句为空,则表示仅登录验证,应 - { - sqlRes = mySqlModify(cs.sqlStr); - } string[] tbName; bool stuFlag = false; @@ -66,11 +62,18 @@ namespace StuMgmLib.MyNameSpace tbName = null; break; } + + ss.sqlSucceed = false; + if (cs.sqlStr != null) // sql语句为空,则表示仅登录验证;若不为空,则取数据库操作返回值,并返回SS; + { + ss.sqlSucceed = mySqlModify(tbName, cs.sqlStr); + return ss; + } + ss.ds = getDataSet(tbName, stuFlag, cs.account); return ss; } - /// /// 登录验证,若失败,则返回错误码;若身份验证成功,则返回用户权限; /// @@ -93,9 +96,8 @@ namespace StuMgmLib.MyNameSpace else return notFound; } - catch (MySqlException mySqlEx) + catch (MySqlException) { - MessageBox.Show(mySqlEx.Message); return error; } finally @@ -107,7 +109,7 @@ namespace StuMgmLib.MyNameSpace /// /// 改 /// - private static bool mySqlModify(string[] sqlStr) + private static bool mySqlModify(string[] tbName, string[] sqlStr) // Need to change ...... { MySqlConnection con = new MySqlConnection(conStr); try @@ -116,8 +118,8 @@ namespace StuMgmLib.MyNameSpace int len = sqlStr.Length; for (int index = 0; index < len; index++) { - MySqlCommand mCmd = new MySqlCommand(sqlStr[index], con); // Need to change ...... - // To do sth here ...... + MySqlCommand mCmd = new MySqlCommand(sqlStr[index], con); // 优化:所操作数据表是否匹配权限 + mCmd.ExecuteNonQuery(); } return true; } diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs index a5a0f88..9d8cabc 100644 --- a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs +++ b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs @@ -1,12 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Data; +/* Describtion : Class for Tcp Network Connection + * Company : Wuxi Xinje + * Author : Somuns + * DateTime : 2021/1/18 + */ +using System; using System.Net; using System.Net.Sockets; +using System.Windows.Forms; namespace StuMgmLib.MyNameSpace { - // 还有一种验证连接方式 Token + // 还有一种验证连接方式: Token public class TcpConn { private IPEndPoint IPP = null; @@ -23,10 +27,23 @@ namespace StuMgmLib.MyNameSpace private set { my_SocketExist = value; } } + public void GetIPAddress(ComboBox cb) + { + cb.Items.Clear(); + foreach (IPAddress ipAddr in Dns.GetHostEntry(Dns.GetHostName()).AddressList) + { + if (ipAddr.AddressFamily.ToString() == "InterNetwork") + { + cb.Items.Add(ipAddr.ToString()); + } + } + cb.Items.Add("127.0.0.1"); + } + #region 开启服务器 - public void OpenServer(int port) + public void OpenServer(string ipAddr, int port) { - IPP = new IPEndPoint(IPAddress.Parse("10.10.0.44"), port); + IPP = new IPEndPoint(IPAddress.Parse(ipAddr), port); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Bind(IPP); socket.Listen(0); @@ -101,10 +118,5 @@ namespace StuMgmLib.MyNameSpace } #endregion - - - - - } } diff --git a/StuMgmServer/StuMgmLib/StuMgmLib.csproj b/StuMgmServer/StuMgmLib/StuMgmLib.csproj index 30826aa..33fd607 100644 --- a/StuMgmServer/StuMgmLib/StuMgmLib.csproj +++ b/StuMgmServer/StuMgmLib/StuMgmLib.csproj @@ -45,7 +45,7 @@ - + diff --git a/StuMgmServer/StuMgmServer/Exit.Designer.cs b/StuMgmServer/StuMgmServer/Exit.Designer.cs new file mode 100644 index 0000000..26b1f9c --- /dev/null +++ b/StuMgmServer/StuMgmServer/Exit.Designer.cs @@ -0,0 +1,124 @@ +namespace StuMgmLib +{ + partial class Exit + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.tableLayoutPanel2.SuspendLayout(); + this.tableLayoutPanel3.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel2 + // + this.tableLayoutPanel2.ColumnCount = 1; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.Controls.Add(this.label1, 0, 1); + this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 12); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 2; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(232, 123); + this.tableLayoutPanel2.TabIndex = 1; + // + // tableLayoutPanel3 + // + this.tableLayoutPanel3.ColumnCount = 4; + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F)); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 35F)); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 35F)); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F)); + this.tableLayoutPanel3.Controls.Add(this.button1, 1, 0); + this.tableLayoutPanel3.Controls.Add(this.button2, 2, 0); + this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel3.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel3.Name = "tableLayoutPanel3"; + this.tableLayoutPanel3.RowCount = 1; + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel3.Size = new System.Drawing.Size(302, 193); + this.tableLayoutPanel3.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 61); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(56, 23); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(48, 3); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(99, 67); + this.button1.TabIndex = 1; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(129, 11); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(99, 55); + this.button2.TabIndex = 2; + this.button2.Text = "button2"; + this.button2.UseVisualStyleBackColor = true; + // + // Exit + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 22F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(302, 193); + this.Controls.Add(this.tableLayoutPanel3); + this.Controls.Add(this.tableLayoutPanel2); + this.Font = new System.Drawing.Font("Calibri", 10.8F); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "Exit"; + this.Text = "Exit"; + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); + this.tableLayoutPanel3.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + + } +} \ No newline at end of file diff --git a/StuMgmServer/StuMgmServer/Exit.cs b/StuMgmServer/StuMgmServer/Exit.cs new file mode 100644 index 0000000..57b7f87 --- /dev/null +++ b/StuMgmServer/StuMgmServer/Exit.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace StuMgmLib +{ + public partial class Exit : Form + { + public Exit() + { + InitializeComponent(); + } + } +} diff --git a/StuMgmServer/StuMgmServer/Exit.resx b/StuMgmServer/StuMgmServer/Exit.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/StuMgmServer/StuMgmServer/Exit.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/StuMgmServer/Server.Designer.cs b/StuMgmServer/StuMgmServer/Server.Designer.cs index cfce97d..fd0bd11 100644 --- a/StuMgmServer/StuMgmServer/Server.Designer.cs +++ b/StuMgmServer/StuMgmServer/Server.Designer.cs @@ -31,15 +31,20 @@ 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.tlpSettings = new System.Windows.Forms.TableLayoutPanel(); this.lblSwiSta = new System.Windows.Forms.Label(); this.btnSerSwitch = new System.Windows.Forms.Button(); this.lblPort = new System.Windows.Forms.Label(); + this.txtPort = new System.Windows.Forms.TextBox(); + this.lblIP = new System.Windows.Forms.Label(); + this.cbxIPAddr = new System.Windows.Forms.ComboBox(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.菜单ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.刷新IPToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tmr = new System.Windows.Forms.Timer(this.components); this.tlpAll.SuspendLayout(); - this.tableLayoutPanel1.SuspendLayout(); + this.tlpSettings.SuspendLayout(); + this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // tlpAll @@ -48,14 +53,14 @@ 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.Controls.Add(this.tlpSettings, 0, 0); this.tlpAll.Dock = System.Windows.Forms.DockStyle.Fill; - this.tlpAll.Location = new System.Drawing.Point(0, 24); + this.tlpAll.Location = new System.Drawing.Point(0, 28); 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, 413F)); - this.tlpAll.Size = new System.Drawing.Size(1075, 413); + this.tlpAll.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 409F)); + this.tlpAll.Size = new System.Drawing.Size(1075, 409); this.tlpAll.TabIndex = 0; // // rtxHistory @@ -64,45 +69,38 @@ 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.Size = new System.Drawing.Size(777, 403); 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(286, 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(134, 10); - this.txtPort.Name = "txtPort"; - this.txtPort.Size = new System.Drawing.Size(149, 29); - this.txtPort.TabIndex = 3; - this.txtPort.Text = "502"; - this.txtPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // tlpSettings + // + this.tlpSettings.ColumnCount = 2; + this.tlpSettings.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 45.8042F)); + this.tlpSettings.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 54.1958F)); + this.tlpSettings.Controls.Add(this.lblSwiSta, 0, 2); + this.tlpSettings.Controls.Add(this.btnSerSwitch, 1, 2); + this.tlpSettings.Controls.Add(this.lblPort, 0, 1); + this.tlpSettings.Controls.Add(this.txtPort, 1, 1); + this.tlpSettings.Controls.Add(this.lblIP, 0, 0); + this.tlpSettings.Controls.Add(this.cbxIPAddr, 1, 0); + this.tlpSettings.Dock = System.Windows.Forms.DockStyle.Top; + this.tlpSettings.Location = new System.Drawing.Point(3, 3); + this.tlpSettings.Name = "tlpSettings"; + this.tlpSettings.RowCount = 3; + this.tlpSettings.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tlpSettings.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tlpSettings.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tlpSettings.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tlpSettings.Size = new System.Drawing.Size(286, 178); + this.tlpSettings.TabIndex = 0; // // lblSwiSta // - this.lblSwiSta.Anchor = System.Windows.Forms.AnchorStyles.None; + this.lblSwiSta.Anchor = System.Windows.Forms.AnchorStyles.Left; this.lblSwiSta.AutoSize = true; this.lblSwiSta.Font = new System.Drawing.Font("Calibri", 10.8F); - this.lblSwiSta.Location = new System.Drawing.Point(10, 63); + this.lblSwiSta.Location = new System.Drawing.Point(3, 136); this.lblSwiSta.Name = "lblSwiSta"; this.lblSwiSta.Size = new System.Drawing.Size(110, 23); this.lblSwiSta.TabIndex = 1; @@ -110,11 +108,11 @@ // // btnSerSwitch // - this.btnSerSwitch.Dock = System.Windows.Forms.DockStyle.Fill; + this.btnSerSwitch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.btnSerSwitch.Font = new System.Drawing.Font("Calibri", 10.8F); - this.btnSerSwitch.Location = new System.Drawing.Point(134, 53); + this.btnSerSwitch.Location = new System.Drawing.Point(134, 121); this.btnSerSwitch.Name = "btnSerSwitch"; - this.btnSerSwitch.Size = new System.Drawing.Size(149, 44); + this.btnSerSwitch.Size = new System.Drawing.Size(149, 54); this.btnSerSwitch.TabIndex = 2; this.btnSerSwitch.Text = "开启服务器"; this.btnSerSwitch.UseVisualStyleBackColor = true; @@ -122,24 +120,75 @@ // // lblPort // - this.lblPort.Anchor = System.Windows.Forms.AnchorStyles.None; + this.lblPort.Anchor = System.Windows.Forms.AnchorStyles.Left; this.lblPort.AutoSize = true; this.lblPort.Font = new System.Drawing.Font("Calibri", 10.8F); - this.lblPort.Location = new System.Drawing.Point(20, 13); + this.lblPort.Location = new System.Drawing.Point(3, 77); this.lblPort.Name = "lblPort"; this.lblPort.Size = new System.Drawing.Size(90, 23); this.lblPort.TabIndex = 0; this.lblPort.Text = "本地端口"; // + // 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(134, 74); + this.txtPort.Name = "txtPort"; + this.txtPort.Size = new System.Drawing.Size(149, 29); + this.txtPort.TabIndex = 3; + this.txtPort.Text = "502"; + this.txtPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // lblIP + // + this.lblIP.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblIP.AutoSize = true; + this.lblIP.Font = new System.Drawing.Font("Calibri", 10.8F); + this.lblIP.Location = new System.Drawing.Point(3, 18); + this.lblIP.Name = "lblIP"; + this.lblIP.Size = new System.Drawing.Size(66, 23); + this.lblIP.TabIndex = 4; + this.lblIP.Text = "本机IP"; + // + // cbxIPAddr + // + this.cbxIPAddr.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.cbxIPAddr.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbxIPAddr.Font = new System.Drawing.Font("Calibri", 10.8F); + this.cbxIPAddr.FormattingEnabled = true; + this.cbxIPAddr.Location = new System.Drawing.Point(134, 14); + this.cbxIPAddr.Name = "cbxIPAddr"; + this.cbxIPAddr.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.cbxIPAddr.Size = new System.Drawing.Size(149, 30); + this.cbxIPAddr.TabIndex = 5; + // // menuStrip1 // this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.菜单ToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1075, 24); + this.menuStrip1.Size = new System.Drawing.Size(1075, 28); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // + // 菜单ToolStripMenuItem + // + this.菜单ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.刷新IPToolStripMenuItem}); + this.菜单ToolStripMenuItem.Name = "菜单ToolStripMenuItem"; + this.菜单ToolStripMenuItem.Size = new System.Drawing.Size(51, 24); + this.菜单ToolStripMenuItem.Text = "菜单"; + // + // 刷新IPToolStripMenuItem + // + this.刷新IPToolStripMenuItem.Name = "刷新IPToolStripMenuItem"; + this.刷新IPToolStripMenuItem.Size = new System.Drawing.Size(181, 26); + this.刷新IPToolStripMenuItem.Text = "刷新IP"; + this.刷新IPToolStripMenuItem.Click += new System.EventHandler(this.刷新IPToolStripMenuItem_Click); + // // tmr // this.tmr.Enabled = true; @@ -155,10 +204,13 @@ this.MainMenuStrip = this.menuStrip1; this.Name = "Server"; this.Text = "Server"; - this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Server_FormClosed); + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Server_FormClosing); + this.Load += new System.EventHandler(this.Server_Load); this.tlpAll.ResumeLayout(false); - this.tableLayoutPanel1.ResumeLayout(false); - this.tableLayoutPanel1.PerformLayout(); + this.tlpSettings.ResumeLayout(false); + this.tlpSettings.PerformLayout(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -169,12 +221,16 @@ private System.Windows.Forms.TableLayoutPanel tlpAll; private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.Label lblSwiSta; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.TableLayoutPanel tlpSettings; private System.Windows.Forms.Button btnSerSwitch; private System.Windows.Forms.Label lblPort; private System.Windows.Forms.TextBox txtPort; private System.Windows.Forms.Timer tmr; private System.Windows.Forms.RichTextBox rtxHistory; + private System.Windows.Forms.Label lblIP; + private System.Windows.Forms.ComboBox cbxIPAddr; + private System.Windows.Forms.ToolStripMenuItem 菜单ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 刷新IPToolStripMenuItem; } } diff --git a/StuMgmServer/StuMgmServer/Server.cs b/StuMgmServer/StuMgmServer/Server.cs index 52d2beb..84d6f45 100644 --- a/StuMgmServer/StuMgmServer/Server.cs +++ b/StuMgmServer/StuMgmServer/Server.cs @@ -2,6 +2,7 @@ using System.Threading; using System.Windows.Forms; using StuMgmLib.MyNameSpace; +using System.ComponentModel; namespace StuMgmServer { @@ -15,13 +16,9 @@ namespace StuMgmServer { InitializeComponent(); } - private void Server_FormClosed(object sender, FormClosedEventArgs e) + private void 刷新IPToolStripMenuItem_Click(object sender, EventArgs e) { - DialogResult dr = MessageBox.Show("确认退出程序?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (dr == DialogResult.OK) - { - System.Environment.Exit(0); - } + tcpConn.GetIPAddress(cbxIPAddr); } /// /// 委托:更新界面方法 @@ -52,7 +49,7 @@ namespace StuMgmServer else if (sFlag != true) { int port = Convert.ToInt16(txtPort.Text); - tcpConn.OpenServer(port); + tcpConn.OpenServer(cbxIPAddr.Text, port); tUpdateUi = new Thread(updateHistory); tUpdateUi.Start(); } @@ -86,6 +83,27 @@ namespace StuMgmServer btnSerSwitch.Text = "开启服务器"; } + private void Server_Load(object sender, EventArgs e) + { + tcpConn.GetIPAddress(cbxIPAddr); + } + + private void Server_FormClosing(object sender, FormClosingEventArgs e) + { + //DialogResult dr = MessageBox.Show("确认退出程序?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + //if (dr != DialogResult.Yes) + //e.Cancel = true; + //tmr.Dispose(); + //if (tUpdateUi != null) + // tUpdateUi.Abort(); + //if (MessageBox.Show("确认退出程序?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) + System.Environment.Exit(0); + + } + + + + } } diff --git a/StuMgmServer/StuMgmServer/Server.resx b/StuMgmServer/StuMgmServer/Server.resx index f769c72..28b6f15 100644 --- a/StuMgmServer/StuMgmServer/Server.resx +++ b/StuMgmServer/StuMgmServer/Server.resx @@ -123,4 +123,7 @@ 159, 17 + + 68 + \ No newline at end of file diff --git a/StuMgmServer/StuMgmServer/StuMgmServer.csproj b/StuMgmServer/StuMgmServer/StuMgmServer.csproj index 77a5bbe..e376c18 100644 --- a/StuMgmServer/StuMgmServer/StuMgmServer.csproj +++ b/StuMgmServer/StuMgmServer/StuMgmServer.csproj @@ -43,6 +43,12 @@ + + Form + + + Exit.cs + Form @@ -51,6 +57,9 @@ + + Exit.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/StuMgmServer/Test/Form1.Designer.cs b/StuMgmServer/Test/Form1.Designer.cs index e6186bd..571b2a2 100644 --- a/StuMgmServer/Test/Form1.Designer.cs +++ b/StuMgmServer/Test/Form1.Designer.cs @@ -66,30 +66,33 @@ // // dataGridView1 // + this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridView1.Location = new System.Drawing.Point(3, 3); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowTemplate.Height = 27; - this.dataGridView1.Size = new System.Drawing.Size(1103, 153); + this.dataGridView1.Size = new System.Drawing.Size(1103, 216); this.dataGridView1.TabIndex = 2; // // dataGridView2 // + this.dataGridView2.AllowUserToAddRows = false; this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView2.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridView2.Location = new System.Drawing.Point(3, 321); + this.dataGridView2.Location = new System.Drawing.Point(3, 447); this.dataGridView2.Name = "dataGridView2"; - this.dataGridView2.Size = new System.Drawing.Size(1103, 156); + this.dataGridView2.Size = new System.Drawing.Size(1103, 218); this.dataGridView2.TabIndex = 3; // // dataGridView3 // + this.dataGridView3.AllowUserToAddRows = false; this.dataGridView3.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView3.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridView3.Location = new System.Drawing.Point(3, 162); + this.dataGridView3.Location = new System.Drawing.Point(3, 225); this.dataGridView3.Name = "dataGridView3"; - this.dataGridView3.Size = new System.Drawing.Size(1103, 153); + this.dataGridView3.Size = new System.Drawing.Size(1103, 216); this.dataGridView3.TabIndex = 4; // // tableLayoutPanel1 @@ -121,14 +124,14 @@ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel2.Size = new System.Drawing.Size(1109, 480); + this.tableLayoutPanel2.Size = new System.Drawing.Size(1109, 668); this.tableLayoutPanel2.TabIndex = 6; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1109, 541); + this.ClientSize = new System.Drawing.Size(1109, 729); this.Controls.Add(this.tableLayoutPanel2); this.Controls.Add(this.tableLayoutPanel1); this.Name = "Form1"; diff --git a/StuMgmServer/Test/Form1.cs b/StuMgmServer/Test/Form1.cs index b85e7d5..1f58e7b 100644 --- a/StuMgmServer/Test/Form1.cs +++ b/StuMgmServer/Test/Form1.cs @@ -30,27 +30,35 @@ namespace Test cs.account = 01941; cs.password = "980505"; cs.sqlStr = null; - byte[] send = BinaryED.Serialize(cs); - socket.Send(send); - byte[] recv = new byte[65535]; - socket.Receive(recv); - Info.ServerSend ss = BinaryED.Deserialize(recv); - short per = ss.permission; - DataSet ds = ss.ds; - DataTable dt1 = ds.Tables["course_info"]; - DataTable dt2 = ds.Tables["user_info"]; - DataTable dt3 = ds.Tables["user"]; - - dataGridView1.DataSource = dt1; - dataGridView2.DataSource = dt2; - dataGridView3.DataSource = dt3; + //cs.sqlStr = new string[1]; + //cs.sqlStr[0] = "UPDATE user_info set course_status = '李俊阳是个憨憨' WHERE job_id=1941"; + if (socket != null) + { + byte[] send = BinaryED.Serialize(cs); + socket.Send(send); + byte[] recv = new byte[65535]; + socket.Receive(recv); + Info.ServerSend ss = BinaryED.Deserialize(recv); + //short per = ss.permission; + DataSet ds = ss.ds; + if (ds != null) + { + DataTable dt1 = ds.Tables["course_info"]; + DataTable dt2 = ds.Tables["user_info"]; + DataTable dt3 = ds.Tables["user"]; + dataGridView1.DataSource = dt1; + dataGridView2.DataSource = dt2; + dataGridView3.DataSource = dt3; + } + } + socket = null; } private void button2_Click(object sender, EventArgs e) { try { - string ip = "127.0.0.1"; + string ip = "10.10.0.44"; int port = 502; IPP = new IPEndPoint(IPAddress.Parse(ip), port); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);