Przeglądaj źródła

服务器等待联调

Server
Somuns 4 lat temu
rodzic
commit
ebe607160d
14 zmienionych plików z 484 dodań i 109 usunięć
  1. +1
    -5
      StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs
  2. +8
    -2
      StuMgmServer/StuMgmLib/MyNameSpace/CommonData.cs
  3. +15
    -13
      StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs
  4. +23
    -11
      StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs
  5. +1
    -1
      StuMgmServer/StuMgmLib/StuMgmLib.csproj
  6. +124
    -0
      StuMgmServer/StuMgmServer/Exit.Designer.cs
  7. +18
    -0
      StuMgmServer/StuMgmServer/Exit.cs
  8. +120
    -0
      StuMgmServer/StuMgmServer/Exit.resx
  9. +104
    -48
      StuMgmServer/StuMgmServer/Server.Designer.cs
  10. +25
    -7
      StuMgmServer/StuMgmServer/Server.cs
  11. +3
    -0
      StuMgmServer/StuMgmServer/Server.resx
  12. +9
    -0
      StuMgmServer/StuMgmServer/StuMgmServer.csproj
  13. +10
    -7
      StuMgmServer/Test/Form1.Designer.cs
  14. +23
    -15
      StuMgmServer/Test/Form1.cs

+ 1
- 5
StuMgmServer/StuMgmLib/MyNameSpace/BinaryED.cs Wyświetl plik

@@ -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
{


StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs → StuMgmServer/StuMgmLib/MyNameSpace/CommonData.cs Wyświetl plik

@@ -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

}


+ 15
- 13
StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs Wyświetl plik

@@ -27,8 +27,9 @@ namespace StuMgmLib.MyNameSpace
* Account Permission (SqlOperate)
*
* Send: ____________________________________________________________________
* | Permission | DataSet |
* |___short________DS_______________________________________________________________|
* | Permission | DataSet |
* |___short________DS___________________________________________________|
*
*/

/// <summary>
@@ -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;
}


/// <summary>
/// 登录验证,若失败,则返回错误码;若身份验证成功,则返回用户权限;
/// </summary>
@@ -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
/// <summary>
/// 改
/// </summary>
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;
}


+ 23
- 11
StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs Wyświetl plik

@@ -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






}
}

+ 1
- 1
StuMgmServer/StuMgmLib/StuMgmLib.csproj Wyświetl plik

@@ -45,7 +45,7 @@
<ItemGroup>
<Compile Include="MyNameSpace\BinaryED.cs" />
<Compile Include="MyNameSpace\DataAnalyze.cs" />
<Compile Include="MyNameSpace\StuMgmSer.cs" />
<Compile Include="MyNameSpace\CommonData.cs" />
<Compile Include="MyNameSpace\TcpConn.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>


+ 124
- 0
StuMgmServer/StuMgmServer/Exit.Designer.cs Wyświetl plik

@@ -0,0 +1,124 @@
namespace StuMgmLib
{
partial class Exit
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;

}
}

+ 18
- 0
StuMgmServer/StuMgmServer/Exit.cs Wyświetl plik

@@ -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();
}
}
}

+ 120
- 0
StuMgmServer/StuMgmServer/Exit.resx Wyświetl plik

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<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>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

+ 104
- 48
StuMgmServer/StuMgmServer/Server.Designer.cs Wyświetl plik

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


+ 25
- 7
StuMgmServer/StuMgmServer/Server.cs Wyświetl plik

@@ -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);
}
/// <summary>
/// 委托:更新界面方法
@@ -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);

}





}
}

+ 3
- 0
StuMgmServer/StuMgmServer/Server.resx Wyświetl plik

@@ -123,4 +123,7 @@
<metadata name="tmr.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>159, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>68</value>
</metadata>
</root>

+ 9
- 0
StuMgmServer/StuMgmServer/StuMgmServer.csproj Wyświetl plik

@@ -43,6 +43,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Exit.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Exit.Designer.cs">
<DependentUpon>Exit.cs</DependentUpon>
</Compile>
<Compile Include="Server.cs">
<SubType>Form</SubType>
</Compile>
@@ -51,6 +57,9 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Exit.resx">
<DependentUpon>Exit.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>


+ 10
- 7
StuMgmServer/Test/Form1.Designer.cs Wyświetl plik

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


+ 23
- 15
StuMgmServer/Test/Form1.cs Wyświetl plik

@@ -30,27 +30,35 @@ namespace Test
cs.account = 01941;
cs.password = "980505";
cs.sqlStr = null;
byte[] send = BinaryED.Serialize<Info.ClientSend>(cs);
socket.Send(send);
byte[] recv = new byte[65535];
socket.Receive(recv);
Info.ServerSend ss = BinaryED.Deserialize<Info.ServerSend>(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<Info.ClientSend>(cs);
socket.Send(send);
byte[] recv = new byte[65535];
socket.Receive(recv);
Info.ServerSend ss = BinaryED.Deserialize<Info.ServerSend>(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);


Ładowanie…
Anuluj
Zapisz