From 7233f754265475b9317e9154085932a4bc2cba8d Mon Sep 17 00:00:00 2001 From: "WIN-G7N5C0B818G\\Administrator" <971785472@qq.com> Date: Wed, 27 Jan 2021 08:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E8=87=AA=E5=B7=B1=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E5=8A=A8=E6=80=81=E6=98=BE=E7=A4=BAtreeview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StuMgmClient/SelectFrom.cs | 61 ++++++++-------- StuMgmClient/StudentForm.cs | 1 + StuMgmClient/StudentTree.cs | 105 ++++++++++++---------------- StuMgmClient/SystemCtrl.cs | 5 +- StuMgmClient/SystemData.cs | 102 +++++++++++++++++++-------- StuMgmLib/MyNameSpace/CommonData.cs | 16 +++-- 6 files changed, 160 insertions(+), 130 deletions(-) diff --git a/StuMgmClient/SelectFrom.cs b/StuMgmClient/SelectFrom.cs index a966149..d252583 100644 --- a/StuMgmClient/SelectFrom.cs +++ b/StuMgmClient/SelectFrom.cs @@ -11,7 +11,6 @@ namespace StuMgmClient public partial class SelectFrom : Form { Dictionary dic = new Dictionary(); - Dictionary dic2 = new Dictionary(); DataRow dr = null; int stateN = 0; public SelectFrom(DataRow drView,int state) @@ -20,11 +19,9 @@ namespace StuMgmClient dr=drView; stateN = state; dic.Add(0, "未开始"); dic.Add(1, "进行中"); dic.Add(2, "待验收"); dic.Add(3, "等待验收中"); dic.Add(4, "验收中"); dic.Add(5, "验收完成"); dic.Add(6, "超时"); dic.Add(7, "预习"); - dic2.Add(0, "基础学习(一阶段)"); dic2.Add(1, "四则运算(一阶段)"); dic2.Add(2, "算法题(一阶段)"); dic2.Add(3, "Modbus(一阶段)"); dic2.Add(4, "待定(二阶段)"); dic2.Add(5, "待定(二阶段)"); } private void SelectFrom_Load(object sender, EventArgs e) { - //MssionPower(); ShowData(dr); } //数据回显 @@ -59,34 +56,34 @@ namespace StuMgmClient this.Dispose(); } } - //状态值改变控件 - public void MssionPower() - { - //任务权限 - int stateNum = Convert.ToInt32(dr["State"]); - switch (stateNum) - { - case 0: - dr["Content"] = "当前不可查看"; - lblTime.Visible = false; - lblState.Visible = false; - btnSumit.Visible = false; - break; - case 1: - btnSumit.Visible = true; - break; - case 2: - case 3: - case 4: - case 5: - case 6: - btnSumit.Visible = false; - break; - case 7: - lblTime.Visible = false; - btnSumit.Visible = false; - break; - } - } + ////状态值改变控件 + //public void MssionPower() + //{ + // //任务权限 + // int stateNum = Convert.ToInt32(dr["State"]); + // switch (stateNum) + // { + // case 0: + // dr["Content"] = "当前不可查看"; + // lblTime.Visible = false; + // lblState.Visible = false; + // btnSumit.Visible = false; + // break; + // case 1: + // btnSumit.Visible = true; + // break; + // case 2: + // case 3: + // case 4: + // case 5: + // case 6: + // btnSumit.Visible = false; + // break; + // case 7: + // lblTime.Visible = false; + // btnSumit.Visible = false; + // break; + // } + //} } } diff --git a/StuMgmClient/StudentForm.cs b/StuMgmClient/StudentForm.cs index 538fba8..6d4426a 100644 --- a/StuMgmClient/StudentForm.cs +++ b/StuMgmClient/StudentForm.cs @@ -7,6 +7,7 @@ namespace StuMgmClient public partial class StudentForm : Form { int m_token; + int m_jobId; public StudentForm(short job_id, int token) { m_token = token; diff --git a/StuMgmClient/StudentTree.cs b/StuMgmClient/StudentTree.cs index 0ec67d6..22bdb36 100644 --- a/StuMgmClient/StudentTree.cs +++ b/StuMgmClient/StudentTree.cs @@ -5,6 +5,7 @@ using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; +using StuMgmLib.MyNameSpace; namespace StuMgmClient { @@ -15,33 +16,23 @@ namespace StuMgmClient InitializeComponent(); } DataTable db = null; - - ////个人信息 - //private DataSet ds = null; - //public DataSet Ds - //{ - // get { return ds; } - // set { ds = value; } - //} - ////节点table - //DataTable table = null; - ////dataRows转化成的table - //DataTable tableClone = null; + Dictionary allCourseStatus = null; + //dataRows转化成的table + DataTable tableClone = null; //Data da = new Data(); private void StudentTree_Load(object sender, EventArgs e) { - db = SystemCtrl.GetStreeTable(); + db = SystemCtrl.GetTable(); + allCourseStatus= SystemData.StreeCourseStatus(); dgvStudent.Visible = false; BindRoot(); //da.GetNodesDic(table); } - ////添加父节点的方法 + //添加父节点的方法 private void BindRoot() { - //ClientMysql cm = new ClientMysql(); - // DataSet ds = cm.SelectNode(); - //table = Ds.Tables["course_info"]; - DataRow[] rows = db.Select("FirstNode=0");//取根 + //把父节点的数据帅选出来 + DataRow[] rows = db.Select("Pid=0");//取根 foreach (DataRow dRow in rows) { TreeNode rootNode = new TreeNode(); @@ -54,12 +45,12 @@ namespace StuMgmClient } } - ////添加子节点的方法、递归绑定子区域 + //添加子节点的方法、递归绑定子区域 private void BindChildAreas(TreeNode fNode) { DataRow dr = (DataRow)fNode.Tag;//父节点数据关联的数据行 int fAreaId = Convert.ToInt32(dr["Id"]); //父节点ID - DataRow[] rows1 = db.Select("SecondNode =" + fAreaId);//子区域 + DataRow[] rows1 = db.Select("Pid =" + fAreaId);//子区域 if (rows1.Length == 0) //递归终止,区域不包含子区域时 { return; @@ -73,48 +64,42 @@ namespace StuMgmClient fNode.Nodes.Add(node); } } - ////子节点单击显示内容 - //private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) - private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { } - //{ - // if (e.Button == System.Windows.Forms.MouseButtons.Left) //单击鼠标左键才响应 - // { - // if (e.Node.Level == 1) //判断子节点才响应 - // { - // dgvStudent.Visible = true; - // DataRow dr = (DataRow)e.Node.Tag; - // int fAreaId = Convert.ToInt32(dr["id"]); //子节点ID - // DataRow[] drows = table.Select("pid =" + fAreaId);//取根 - // tableClone = table.Clone();//克隆表结构 - // foreach (DataRow drr in drows) - // { - // tableClone.ImportRow(drr); - // } - // dgvStudent.AutoGenerateColumns = false; - // dgvStudent.AllowUserToAddRows = false; - // dgvStudent.DataSource = tableClone; - // } - // } - //} - private void DgvStudent_CellContentClick(object sender, DataGridViewCellEventArgs e) - { } + //子节点单击显示内容 + private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) + { + if (e.Button == System.Windows.Forms.MouseButtons.Left) //单击鼠标左键才响应 + { + if (e.Node.Level == 1) //判断子节点才响应 + { + dgvStudent.Visible = true; + DataRow dr = (DataRow)e.Node.Tag; + int fAreaId = Convert.ToInt32(dr["id"]); //子节点ID + DataRow[] drows = db.Select("pid =" + fAreaId);//取根 + tableClone = db.Clone();//克隆表结构 + foreach (DataRow drr in drows) + { + tableClone.ImportRow(drr); + } + dgvStudent.AutoGenerateColumns = false; + dgvStudent.AllowUserToAddRows = false; + dgvStudent.DataSource = tableClone; + } + } + } ////我的任务_查看按钮方法 - //private void DgvStudent_CellContentClick(object sender, DataGridViewCellEventArgs e) - //{ - // if (e.ColumnIndex == 1 && e.RowIndex != -1) - // { - // //Dictionary stateDic = da.StateParsing(table); - // Dictionary stateDic = da.GetNodesDic(table); - // // string s=da.DicParsing(stateDic); - // DataRow drViews = tableClone.Rows[e.RowIndex]; - // int state = stateDic[Convert.ToInt32((drViews["id"]))]; - // SelectFrom sf = new SelectFrom(drViews, state); - // //string test = da.DicParsing(stateDic); - // sf.ShowDialog(); - // // ShowData(); - // } - //} + private void DgvStudent_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex == 1 && e.RowIndex != -1) + { + DataRow drViews = tableClone.Rows[e.RowIndex]; + short idState = Convert.ToInt16((drViews["id"])); + int state=(int)allCourseStatus[idState]; + SelectFrom sf = new SelectFrom(drViews, state); + //string test = da.DicParsing(stateDic); + sf.ShowDialog(); + } + } } } diff --git a/StuMgmClient/SystemCtrl.cs b/StuMgmClient/SystemCtrl.cs index 05a1d0c..2d93d9e 100644 --- a/StuMgmClient/SystemCtrl.cs +++ b/StuMgmClient/SystemCtrl.cs @@ -86,9 +86,10 @@ namespace StuMgmClient return ErrCode.Success; } - internal static DataTable GetStreeTable() + internal static DataTable GetTable() { - return SystemData.StreeTable(); + return SystemData.StreeTable(); } + } } diff --git a/StuMgmClient/SystemData.cs b/StuMgmClient/SystemData.cs index dcd6d93..836c5f4 100644 --- a/StuMgmClient/SystemData.cs +++ b/StuMgmClient/SystemData.cs @@ -13,7 +13,7 @@ namespace StuMgmClient { static Dictionary allCourseInfo; static Dictionary allCourseStatus; - static List allStreeDatas; + static List courseInfo; internal static ErrCode InitSystemData() { ErrCode err; @@ -25,7 +25,8 @@ namespace StuMgmClient static ErrCode InitCourseInfo() { ErrCode err; - List courseInfo; + //List + courseInfo = new List(); ; err = SystemCtrl.GetCourseInfo(out courseInfo); if (err != ErrCode.Success) return err; @@ -60,27 +61,71 @@ namespace StuMgmClient return ErrCode.Success; } - static void StreeList() - { - allStreeDatas = new List(); - StreeDatas sd=null; - foreach (var item in allCourseStatus) - { - sd = new StreeDatas(); - CourseInfo infoTwo = allCourseInfo[item.Key];//找到状态对应的课程表信息 - sd.SecondNode = infoTwo.Pid;//二级节点9 - CourseInfo infoOne = allCourseInfo[infoTwo.Pid]; - CourseInfo infoThree = allCourseInfo[infoOne.Pid]; - sd.FirstNode = infoThree.Pid; - sd.Id = infoTwo.Id; - sd.Name = infoTwo.Name; - sd.Pid = infoTwo.Pid; - sd.Statu = (int)item.Value; - sd.Content = infoTwo.Content; - allStreeDatas.Add(sd); - } - } - static DataTable ListToDb(List list) + //internal static void StreeList() + //{ + // allStreeDatas = new Dictionary(); + + // foreach (var item in allCourseStatus) + // { + // UserCourseDetail courseDetail = new UserCourseDetail(); + // CourseInfo info = allCourseInfo[item.Key];//找到状态对应的课程表信息 + // courseDetail.Id = info.Id; + // courseDetail.Name = info.Name; + // courseDetail.Status = (int)item.Value; + // courseDetail.Content = info.Content; + // allStreeDatas.Add(info.Pid,courseDetail); + // } + + //} + + + //internal static UserCourseDetail r(CourseInfo info, ref Dictionary allCourseStatus) + //{ + // UserCourseDetail sel; + + // if (allCourseStatus.TryGetValue(info.Id, out sel)) + // return sel; + + // UserCourseDetail m = new UserCourseDetail(); + // //info->m + + // allCourseStatus.Add(info.Id, m); + // if (info.Pid != 0) + // { + // UserCourseDetail father = r(allCourseInfo[info.Pid], ref allCourseStatus); + // father.Children.Add(m); + // } + // return m; + //} + + //internal static void rr(UserCourseDetail u, TreeNode n) + //{ + // foreach(UserCourseDetail child in u.Children) + // { + // TreeNode node = new TreeNode(child); + // n.add(node); + // rr(child, node); + // } + //} + + //internal static void aa (List keys,List values) + //{ + // Dictionary allCourseStatus=new Dictionary(); + // for (short i = 0; i < keys.Count; i++) + // r(allCourseInfo[i], ref allCourseStatus); + // List lst = new List(); + // // + // //TreeNode all; + // List all; + // foreach(UserCourseDetail u in lst) + // { + // TreeNode n = new TreeNode(); + // rr(u, n); + // all.add(n); + // } + //} + + static DataTable ListToDb(List list) { DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); @@ -97,18 +142,17 @@ namespace StuMgmClient dr[1] = list[i].Name; dr[2] = list[i].Pid; dr[3] = list[i].Content; - dr[4] = list[i].Statu; - dr[5] = list[i].FirstNode; - dr[6] = list[i].SecondNode; dt.Rows.Add(dr); } return dt; } - internal static DataTable StreeTable() { - StreeList(); - return ListToDb(allStreeDatas); + return ListToDb(courseInfo); + } + internal static Dictionary StreeCourseStatus() + { + return allCourseStatus; } } } diff --git a/StuMgmLib/MyNameSpace/CommonData.cs b/StuMgmLib/MyNameSpace/CommonData.cs index 4612efa..ddbcbb6 100644 --- a/StuMgmLib/MyNameSpace/CommonData.cs +++ b/StuMgmLib/MyNameSpace/CommonData.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; @@ -70,7 +71,8 @@ namespace StuMgmLib.MyNameSpace [Serializable] public enum CourseStatusEnum { - NoStart = 0, + Null = 0, + NoStart, Begin, WaitCheckig, CheckigSuccess, @@ -100,15 +102,15 @@ namespace StuMgmLib.MyNameSpace Object = obj; } } - public class StreeDatas + + public class UserCourseDetail { - public int Id; + public short Id; public string Name; - public int Pid; public string Content; - public int Statu; - public int FirstNode; - public int SecondNode; + public int Time; + public int Status; + public List Children; } }