diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs
index 3ac2f89..dd5f1d3 100644
--- a/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs
+++ b/StuMgmServer/StuMgmLib/MyNameSpace/DataAnalyze.cs
@@ -1,8 +1,5 @@
using MySql.Data.MySqlClient;
-using System;
-using System.Collections.Generic;
using System.Data;
-using System.Text;
using System.Windows.Forms;
namespace StuMgmLib.MyNameSpace
@@ -12,7 +9,7 @@ namespace StuMgmLib.MyNameSpace
///
public class DataAnalyze
{
-
+
private enum verifyCode : short
{
error = -1,
@@ -25,7 +22,7 @@ namespace StuMgmLib.MyNameSpace
/* Recv: ___________________________________________________________________
* | Account | Password | (SqlOperate) |
- * |___short_____string______string________________________________________|
+ * |___short_____string______string[]________________________________________|
* Analyze:
* Account Permission (SqlOperate)
*
@@ -40,15 +37,18 @@ namespace StuMgmLib.MyNameSpace
public static Info.ServerSend ClientSendAnalyze(Info.ClientSend cs)
{
Info.ServerSend ss = new Info.ServerSend();
- ss.permission = LoginVerify(cs.account, cs.password); // 验证身份
+ ss.permission = loginVerify(cs.account, cs.password); // 验证身份
if (ss.permission < 0) // 小于0,则权限有误
{
ss.ds = null;
return ss;
}
- // if(operationCode != 0)
- // 写数据表操作
- // To do sth here ........
+ bool sqlRes = false;
+ if (cs.sqlStr != null) // sql语句为空,则表示仅登录验证,应
+ {
+ sqlRes = mySqlModify(cs.sqlStr);
+ }
+
string[] tbName;
bool stuFlag = false;
switch (ss.permission)
@@ -74,7 +74,7 @@ namespace StuMgmLib.MyNameSpace
///
/// 登录验证,若失败,则返回错误码;若身份验证成功,则返回用户权限;
///
- private static short LoginVerify(short account, string psw)
+ private static short loginVerify(short account, string psw)
{
short notFound = -1;
short error = -2;
@@ -107,9 +107,28 @@ namespace StuMgmLib.MyNameSpace
///
/// 改
///
- private static void mySqlModify()
+ private static bool mySqlModify(string[] sqlStr)
{
-
+ MySqlConnection con = new MySqlConnection(conStr);
+ try
+ {
+ con.Open();
+ 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 ......
+ }
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ finally
+ {
+ con.Close();
+ }
}
///
@@ -125,7 +144,7 @@ namespace StuMgmLib.MyNameSpace
DataSet ds = new DataSet();
for (int index = 0; index < tbName.Length; index++)
{
- string newStr = str + tbName[index];
+ string newStr = str + " " + tbName[index];
if ((stuFlag == true) && (tbName[index] == "user_info"))
{
newStr += "where job_id = " + account.ToString();
diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs b/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs
index 86eb6d0..7b2a40a 100644
--- a/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs
+++ b/StuMgmServer/StuMgmLib/MyNameSpace/StuMgmSer.cs
@@ -11,7 +11,7 @@ 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
@@ -74,7 +74,7 @@ namespace StuMgmLib.MyNameSpace
//}
#endregion
-
+ #region 未使用
class Server
{
@@ -128,4 +128,5 @@ namespace StuMgmLib.MyNameSpace
// UserInfo aa = s.Parse(buf);
//}
}
+ #endregion
}
diff --git a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs
index d41c3dc..a5a0f88 100644
--- a/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs
+++ b/StuMgmServer/StuMgmLib/MyNameSpace/TcpConn.cs
@@ -26,7 +26,7 @@ namespace StuMgmLib.MyNameSpace
#region 开启服务器
public void OpenServer(int port)
{
- IPP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
+ IPP = new IPEndPoint(IPAddress.Parse("10.10.0.44"), port);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(IPP);
socket.Listen(0);
@@ -49,7 +49,7 @@ namespace StuMgmLib.MyNameSpace
///
/// 接收客户端连接
///
- public string acceptConnection()
+ public string AcceptConn()
{
try
{
@@ -64,13 +64,14 @@ namespace StuMgmLib.MyNameSpace
#endregion
const int recvTimeOut = 3000; // 设置接收超时时间
+ const int recvLength = 65535;
#region 接收数据
///
/// 接收数据
///
- public string acpMsg()
+ public string AcpMsg()
{
- byte[] dataRecv = new byte[4096]; // 定义接收数组
+ byte[] dataRecv = new byte[recvLength]; // 定义接收数组
string reEdPoint = "";
try
{
diff --git a/StuMgmServer/StuMgmServer/Server.Designer.cs b/StuMgmServer/StuMgmServer/Server.Designer.cs
index 17693a4..cfce97d 100644
--- a/StuMgmServer/StuMgmServer/Server.Designer.cs
+++ b/StuMgmServer/StuMgmServer/Server.Designer.cs
@@ -143,7 +143,6 @@
// tmr
//
this.tmr.Enabled = true;
- this.tmr.Interval = 500;
this.tmr.Tick += new System.EventHandler(this.tmr_Tick);
//
// Server
diff --git a/StuMgmServer/StuMgmServer/Server.cs b/StuMgmServer/StuMgmServer/Server.cs
index 4fa089d..52d2beb 100644
--- a/StuMgmServer/StuMgmServer/Server.cs
+++ b/StuMgmServer/StuMgmServer/Server.cs
@@ -17,7 +17,11 @@ namespace StuMgmServer
}
private void Server_FormClosed(object sender, FormClosedEventArgs e)
{
- System.Environment.Exit(0);
+ DialogResult dr = MessageBox.Show("确认退出程序?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+ if (dr == DialogResult.OK)
+ {
+ System.Environment.Exit(0);
+ }
}
///
/// 委托:更新界面方法
@@ -66,8 +70,8 @@ namespace StuMgmServer
{
while (tcpConn.SocketExist)
{
- setText(tcpConn.acceptConnection());
- setText(tcpConn.acpMsg());
+ setText(tcpConn.AcceptConn());
+ setText(tcpConn.AcpMsg());
}
}
@@ -83,8 +87,5 @@ namespace StuMgmServer
}
-
-
-
}
}
diff --git a/StuMgmServer/Test/Form1.Designer.cs b/StuMgmServer/Test/Form1.Designer.cs
index 9013fcf..e6186bd 100644
--- a/StuMgmServer/Test/Form1.Designer.cs
+++ b/StuMgmServer/Test/Form1.Designer.cs
@@ -3,14 +3,14 @@
partial class Form1
{
///
- /// 必需的设计器变量。
+ /// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
- /// 清理所有正在使用的资源。
+ /// Clean up any resources being used.
///
- /// 如果应释放托管资源,为 true;否则为 false。
+ /// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
@@ -20,160 +20,137 @@
base.Dispose(disposing);
}
- #region Windows 窗体设计器生成的代码
+ #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.components = new System.ComponentModel.Container();
- this.tlpAll = new System.Windows.Forms.TableLayoutPanel();
- this.rtxHistory = new System.Windows.Forms.RichTextBox();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.dataGridView2 = new System.Windows.Forms.DataGridView();
+ this.dataGridView3 = new System.Windows.Forms.DataGridView();
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.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).BeginInit();
this.tableLayoutPanel1.SuspendLayout();
+ this.tableLayoutPanel2.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 = "";
+ // button1
+ //
+ this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.button1.Location = new System.Drawing.Point(557, 3);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(549, 55);
+ this.button1.TabIndex = 0;
+ this.button1.Text = "button1";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.button1_Click);
+ //
+ // button2
+ //
+ this.button2.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.button2.Location = new System.Drawing.Point(3, 3);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(548, 55);
+ this.button2.TabIndex = 1;
+ this.button2.Text = "button2";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.button2_Click);
+ //
+ // dataGridView1
+ //
+ 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.TabIndex = 2;
+ //
+ // dataGridView2
+ //
+ 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.Name = "dataGridView2";
+ this.dataGridView2.Size = new System.Drawing.Size(1103, 156);
+ this.dataGridView2.TabIndex = 3;
+ //
+ // dataGridView3
+ //
+ 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.Name = "dataGridView3";
+ this.dataGridView3.Size = new System.Drawing.Size(1103, 153);
+ this.dataGridView3.TabIndex = 4;
//
// 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.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel1.Controls.Add(this.button2, 0, 0);
+ this.tableLayoutPanel1.Controls.Add(this.button1, 1, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Top;
- this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
- this.tableLayoutPanel1.RowCount = 2;
+ this.tableLayoutPanel1.RowCount = 1;
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);
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(1109, 61);
+ this.tableLayoutPanel1.TabIndex = 5;
+ //
+ // 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.dataGridView1, 0, 0);
+ this.tableLayoutPanel2.Controls.Add(this.dataGridView3, 0, 1);
+ this.tableLayoutPanel2.Controls.Add(this.dataGridView2, 0, 2);
+ this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 61);
+ this.tableLayoutPanel2.Name = "tableLayoutPanel2";
+ this.tableLayoutPanel2.RowCount = 3;
+ 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.TabIndex = 6;
//
// 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.ClientSize = new System.Drawing.Size(1109, 541);
+ this.Controls.Add(this.tableLayoutPanel2);
+ this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form1";
this.Text = "Form1";
- this.tlpAll.ResumeLayout(false);
+ this.Load += new System.EventHandler(this.Form1_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).EndInit();
this.tableLayoutPanel1.ResumeLayout(false);
- this.tableLayoutPanel1.PerformLayout();
+ this.tableLayoutPanel2.ResumeLayout(false);
this.ResumeLayout(false);
- this.PerformLayout();
}
#endregion
- private System.Windows.Forms.TableLayoutPanel tlpAll;
- private System.Windows.Forms.RichTextBox rtxHistory;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.DataGridView dataGridView1;
+ private System.Windows.Forms.DataGridView dataGridView2;
+ private System.Windows.Forms.DataGridView dataGridView3;
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;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
}
-}
-
+}
\ No newline at end of file
diff --git a/StuMgmServer/Test/Form1.cs b/StuMgmServer/Test/Form1.cs
index bf9b0eb..b85e7d5 100644
--- a/StuMgmServer/Test/Form1.cs
+++ b/StuMgmServer/Test/Form1.cs
@@ -1,5 +1,11 @@
using System;
-using System.Threading;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
using System.Windows.Forms;
using StuMgmLib.MyNameSpace;
@@ -7,84 +13,54 @@ namespace Test
{
public partial class Form1 : Form
{
- TcpConn tcpConn = new TcpConn();
- Thread tUpdateUi = null;
- private delegate void SetTextCallback(string text);
-
+ IPEndPoint IPP = null;
+ Socket socket = null;
public Form1()
{
InitializeComponent();
}
- private void Server_FormClosed(object sender, FormClosedEventArgs e)
+ private void Form1_Load(object sender, EventArgs e)
{
- System.Environment.Exit(0);
+
}
- ///
- /// 委托:更新界面方法
- ///
- private void setText(string text)
+
+ private void button1_Click(object sender, EventArgs e)
{
- if (rtxHistory.InvokeRequired)
- {
- SetTextCallback method = new SetTextCallback(setText);
- Invoke(method, new object[] { text });
- }
- else
- {
- rtxHistory.Text = text + rtxHistory.Text;
- }
+ Info.ClientSend cs = new Info.ClientSend();
+ 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;
}
- ///
- /// btn开关点击事件:开启、关闭服务器
- ///
- private void btnSerSwitch_Click(object sender, EventArgs e)
+ private void button2_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);
+ string ip = "127.0.0.1";
+ int port = 502;
+ IPP = new IPEndPoint(IPAddress.Parse(ip), port);
+ socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ socket.Connect(IPP);
}
- }
-
- ///
- /// 线程:接收客户端连接,接收数据,数据处理;更新历史界面
- ///
- private void updateHistory()
- {
- while (tcpConn.SocketExist)
+ catch (Exception econnect)
{
- setText(tcpConn.acceptConnection());
- setText(tcpConn.acpMsg());
+ MessageBox.Show(econnect.Message);
}
}
- ///
- /// 定时器更新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
index 1a2920d..7080a7d 100644
--- a/StuMgmServer/Test/Form1.resx
+++ b/StuMgmServer/Test/Form1.resx
@@ -117,10 +117,4 @@
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