diff --git a/StuMgmClient/Data.cs b/StuMgmClient/Data.cs index f6f2ee4..71f3588 100644 --- a/StuMgmClient/Data.cs +++ b/StuMgmClient/Data.cs @@ -6,16 +6,24 @@ using System.Data; namespace StuMgmClient { + enum ErrCode { Success, FailSerial, FailDeserial, + FailConnect, FailSend, FailReceive, ErrData, } + public enum FuncCode + { + VerifLogin = 1, + GetCourseInfo, + GetUserCourseInfo, + } public enum Roles { NotFound = -1, @@ -25,11 +33,24 @@ namespace StuMgmClient Student = 3, } + [Serializable] + public class ClientRequest + { + public FuncCode Func; + public object Object; + public ClientRequest(FuncCode func, object obj) + { + Func = func; + Object = obj; + } + } + [Serializable] public class UserInfo { public string Account; public string Password; + public string Token; public Roles UserRole; public UserInfo(string account, string password) { @@ -38,16 +59,89 @@ namespace StuMgmClient } } + public class CourseInfo + { + public short Id; + public short Pid; + public int Time; + public string Name; + public string Content; + } - + [Serializable] + public enum CourseStatusEnum + { + lll, + ...// + } [Serializable] - public class ServerSend + public class UserCourseInfo + { + public short JobId;//工号 + public string Name;//姓名 + public string InfoDescribe;//信息描述 + } + + + + + + + + + + + + + + + + + + + + + + + + + /* + + + #region 学生题目信息一览 + + #endregion + + #region 学生单题详细信息 + public class HistoryInfo + { + DateTime Time; + string Describe; + } + public class DetailInfo { - public short permission { get; set; } - public DataSet ds { get; set; } + public short CourseId; + public short JobId; + List Describes; } + #endregion + + */ + + + + + + + + //[Serializable] + //public class ServerSend + //{ + // public short permission { get; set; } + // public DataSet ds { get; set; } + //} } @@ -56,71 +150,71 @@ namespace StuMgmClient namespace StuMgmClient { - class Data - { - //状态值字符串转字典 - public Dictionary StateParsing(DataTable table) - { - Dictionary myDictionary = new Dictionary(); - ClientMysql cm = new ClientMysql(); - DataSet ds = cm.SelectState(); - DataRow dr = ds.Tables["user_info"].Rows[0]; - string state = dr["course_status"].ToString(); - int num = 0; - int oldTem = 0; - //切割字符串 - string[] sArray = state.Split(new char[2] { ':', ';' }); - foreach (string i in sArray) - { - if (i.Equals("")) { break; } - int tem = Convert.ToInt32(i); - num++; - if (num % 2 != 0) - { - myDictionary.Add(tem, 0); - oldTem = tem; - } - else - { - myDictionary[oldTem] = tem; - } - } - return myDictionary; - } - //字典转字符串 - public string DicParsing(Dictionary dic) - { - string stateText = ""; - foreach (var item in dic) - { - stateText = stateText + item.Key + ":" + item.Value + ";"; - } - return stateText; - } - //查询所有子节点 - public void GetAllNodes(string id, DataTable table, ref Dictionary nodesDic) - { - - //把父节点的数据筛选出来 - DataRow[] rows = table.Select("pid =" + id);//取根 - if (rows.Length <= 0) - { - nodesDic.Add(Convert.ToInt32(id), 0); - return; - } - foreach (DataRow dr in rows) - { - GetAllNodes(dr["id"].ToString(), table, ref nodesDic); - } + //class Data + //{ + // //状态值字符串转字典 + // public Dictionary StateParsing(DataTable table) + // { + // Dictionary myDictionary = new Dictionary(); + // ClientMysql cm = new ClientMysql(); + // DataSet ds = cm.SelectState(); + // DataRow dr = ds.Tables["user_info"].Rows[0]; + // string state = dr["course_status"].ToString(); + // int num = 0; + // int oldTem = 0; + // //切割字符串 + // string[] sArray = state.Split(new char[2] { ':', ';' }); + // foreach (string i in sArray) + // { + // if (i.Equals("")) { break; } + // int tem = Convert.ToInt32(i); + // num++; + // if (num % 2 != 0) + // { + // myDictionary.Add(tem, 0); + // oldTem = tem; + // } + // else + // { + // myDictionary[oldTem] = tem; + // } + // } + // return myDictionary; + // } + // //字典转字符串 + // public string DicParsing(Dictionary dic) + // { + // string stateText = ""; + // foreach (var item in dic) + // { + // stateText = stateText + item.Key + ":" + item.Value + ";"; + // } + // return stateText; + // } + // //查询所有子节点 + // public void GetAllNodes(string id, DataTable table, ref Dictionary nodesDic) + // { + + // //把父节点的数据筛选出来 + // DataRow[] rows = table.Select("pid =" + id);//取根 + // if (rows.Length <= 0) + // { + // nodesDic.Add(Convert.ToInt32(id), 0); + // return; + // } + // foreach (DataRow dr in rows) + // { + // GetAllNodes(dr["id"].ToString(), table, ref nodesDic); + // } - } - //获取所有子节点Dictionary - public Dictionary GetNodesDic(DataTable table) - { - Dictionary nodesDic = new Dictionary(); - GetAllNodes("0", table, ref nodesDic); - return nodesDic; - } - } + // } + // //获取所有子节点Dictionary + // public Dictionary GetNodesDic(DataTable table) + // { + // Dictionary nodesDic = new Dictionary(); + // GetAllNodes("0", table, ref nodesDic); + // return nodesDic; + // } + //} } diff --git a/StuMgmClient/LoginForm.cs b/StuMgmClient/LoginForm.cs index a263b36..b57a8f8 100644 --- a/StuMgmClient/LoginForm.cs +++ b/StuMgmClient/LoginForm.cs @@ -1,22 +1,19 @@ using System; -using System.Data; -using System.Net.Sockets; -using System.Text.RegularExpressions; using System.Windows.Forms; -using StuMgmLib.MyNameSpace; namespace StuMgmClient { public partial class LoginForm : Form { + const string deaultIp = "10.10.0.44"; + const int deaultPort = 502; public LoginForm() { InitializeComponent(); + SystemComm.Init(deaultIp, deaultPort); + if(SystemData.InitSystemData()!= ErrCode.Success) + throw new Exception("初始化异常,请重新启动"); } - - - //DataSet ds = null; - ////账号密码正则校验 //public bool RegexUser(string u, string p) @@ -47,63 +44,40 @@ namespace StuMgmClient { } + private void btnSubmit_Click(object sender, EventArgs e) { - Login(); + Roles userRole; + string token; + + if (VerifLogin(out userRole, out token) != ErrCode.Success) + return; + + switch (userRole) + { + case Roles.Student: + ShowStudentForm(token); + break; + default: + MessageBox.Show(userRole.ToString()); + break; + } } - //登陆方法 - public void Login() + ErrCode VerifLogin(out Roles userRole, out string token) { - string userName = txtUserName.Text; - string pawssword = txtPassWord.Text; - Info.ServerSend ss = ConnectServer(); - - + ErrCode errcode = SystemCtrl.VerifLogin(txtUserName.Text, txtPassWord.Text, out userRole, out token); + if (errcode != ErrCode.Success) + MessageBox.Show(errcode.ToString()); + return errcode; } - - ////权限管理 - // int powerNum = (int)ss.permission; - // ds = ss.ds; - // switch (powerNum) - // { - // case (int)Roles.Student: - // StudentForm stu = new StudentForm(ds); - // stu.Show(); - // login.Hide(); - // break; - // case (int)Roles.Teacher: - // TeacherForm tf = new TeacherForm(ds); - // tf.Show(); - // login.Hide(); - // break; - // case (int)Roles.Admin: - // AdminForm af = new AdminForm(); - // af.Show(); - // login.Hide(); - // break; - // case (Int32)Roles.NotFound: - // MessageBox.Show("账号或用户名错误", "提示"); - // break; - // } - - - ////登陆连接服务器 - //public Info.ServerSend ConnectServer() - //{ - // Socket client= ClientConnect.Connect("10.10.0.44", 502); - // if (client== null) - // { - // MessageBox.Show("连接失败", "提示"); - // return null; - // } - // else - // { - // ClientConnect.Send(client); - // Info.ServerSend ss = ClientConnect.Receive(client); - // return ss; - // } - //} + void ShowStudentForm(string token) + { + this.Hide(); + StudentForm stu = new StudentForm(token); + stu.ShowDialog(); + this.Show(); + } } } diff --git a/StuMgmClient/LoginForm.designer.cs b/StuMgmClient/LoginForm.designer.cs index f8a8cd3..d9df3ec 100644 --- a/StuMgmClient/LoginForm.designer.cs +++ b/StuMgmClient/LoginForm.designer.cs @@ -275,7 +275,6 @@ this.Name = "LoginForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "信捷电气学员管理系统"; - this.Load += new System.EventHandler(this.LoginForm_Load); this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.PerformLayout(); this.tableLayoutPanel1.ResumeLayout(false); diff --git a/StuMgmClient/StuMgmClient.csproj b/StuMgmClient/StuMgmClient.csproj index 0056763..13a8340 100644 --- a/StuMgmClient/StuMgmClient.csproj +++ b/StuMgmClient/StuMgmClient.csproj @@ -55,7 +55,7 @@ - + Code @@ -91,6 +91,8 @@ StudentNavigation.cs + + SelectFrom.cs @@ -128,12 +130,6 @@ True - - - {34ad3363-1b1c-4f4a-898c-c1a1f215fddd} - StuMgmLib - -