diff --git a/StuMgmClient/StuMgmClient.csproj b/StuMgmClient/StuMgmClient.csproj index 9b7da46..1ad4f86 100644 --- a/StuMgmClient/StuMgmClient.csproj +++ b/StuMgmClient/StuMgmClient.csproj @@ -9,7 +9,7 @@ Properties StuMgmLib StuMgmClient - v2.0 + v4.0 512 diff --git a/StuMgmClient/StudentForm.cs b/StuMgmClient/StudentForm.cs index ee17b4f..538fba8 100644 --- a/StuMgmClient/StudentForm.cs +++ b/StuMgmClient/StudentForm.cs @@ -9,10 +9,10 @@ namespace StuMgmClient int m_token; public StudentForm(short job_id, int token) { - InitializeComponent(); m_token = token; if (SystemCtrl.RefreshUserCourseInfo(job_id, token) != ErrCode.Success) throw new Exception("获取用户信息异常,请重新启动"); + InitializeComponent(); } diff --git a/StuMgmClient/StudentTree.cs b/StuMgmClient/StudentTree.cs index 9eae5fa..0ec67d6 100644 --- a/StuMgmClient/StudentTree.cs +++ b/StuMgmClient/StudentTree.cs @@ -14,6 +14,8 @@ namespace StuMgmClient { InitializeComponent(); } + DataTable db = null; + ////个人信息 //private DataSet ds = null; //public DataSet Ds @@ -26,52 +28,51 @@ namespace StuMgmClient ////dataRows转化成的table //DataTable tableClone = null; //Data da = new Data(); - //private void StudentTree_Load(object sender, EventArgs e) - //{ - // dgvStudent.Visible = false; - // BindRoot(); - // //da.GetNodesDic(table); - //} - private void StudentTree_Load(object sender, EventArgs e) { } + private void StudentTree_Load(object sender, EventArgs e) + { + db = SystemCtrl.GetStreeTable(); + 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 = table.Select("pid=0");//取根 - // foreach (DataRow dRow in rows) - // { - // TreeNode rootNode = new TreeNode(); - // rootNode.Tag = dRow; - // rootNode.Text = dRow["name"].ToString(); - // //把此节点放入树中 - // StudenTree.Nodes.Add(rootNode); - // //绑定子节点 - // BindChildAreas(rootNode);//调用添加子节点的方法 - // } - //} + private void BindRoot() + { + //ClientMysql cm = new ClientMysql(); + // DataSet ds = cm.SelectNode(); + //table = Ds.Tables["course_info"]; + DataRow[] rows = db.Select("FirstNode=0");//取根 + foreach (DataRow dRow in rows) + { + TreeNode rootNode = new TreeNode(); + rootNode.Tag = dRow; + rootNode.Text = dRow["Name"].ToString(); + //把此节点放入树中 + StudenTree.Nodes.Add(rootNode); + //绑定子节点 + BindChildAreas(rootNode);//调用添加子节点的方法 + } + } ////添加子节点的方法、递归绑定子区域 - //private void BindChildAreas(TreeNode fNode) - //{ - // DataRow dr = (DataRow)fNode.Tag;//父节点数据关联的数据行 - // int fAreaId = Convert.ToInt32(dr["id"]); //父节点ID - // DataRow[] rows1 = table.Select("pid =" + fAreaId);//子区域 - // if (rows1.Length == 0) //递归终止,区域不包含子区域时 - // { - // return; - // } - // foreach (DataRow dRow in rows1) - // { - // TreeNode node = new TreeNode(); - // node.Tag = dRow; - // node.Text = dRow["name"].ToString(); - // //添加子节点 - // fNode.Nodes.Add(node); - // } - //} + private void BindChildAreas(TreeNode fNode) + { + DataRow dr = (DataRow)fNode.Tag;//父节点数据关联的数据行 + int fAreaId = Convert.ToInt32(dr["Id"]); //父节点ID + DataRow[] rows1 = db.Select("SecondNode =" + fAreaId);//子区域 + if (rows1.Length == 0) //递归终止,区域不包含子区域时 + { + return; + } + foreach (DataRow dRow in rows1) + { + TreeNode node = new TreeNode(); + node.Tag = dRow; + node.Text = dRow["Name"].ToString(); + //添加子节点 + fNode.Nodes.Add(node); + } + } ////子节点单击显示内容 //private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { } diff --git a/StuMgmClient/SystemCtrl.cs b/StuMgmClient/SystemCtrl.cs index aefd5d9..05a1d0c 100644 --- a/StuMgmClient/SystemCtrl.cs +++ b/StuMgmClient/SystemCtrl.cs @@ -4,6 +4,7 @@ using System.Text; using StuMgmClient; using StuMgmLib.MyNameSpace; using System.Diagnostics; +using System.Data; namespace StuMgmClient { @@ -44,7 +45,7 @@ namespace StuMgmClient if (!(o.Object is List)) return ErrCode.ErrData; - //courseInfo = (List)o; + courseInfo = (List)o.Object; return ErrCode.Success; } @@ -85,11 +86,9 @@ namespace StuMgmClient return ErrCode.Success; } - - - - - - + internal static DataTable GetStreeTable() + { + return SystemData.StreeTable(); + } } } diff --git a/StuMgmClient/SystemData.cs b/StuMgmClient/SystemData.cs index 3a5547b..dcd6d93 100644 --- a/StuMgmClient/SystemData.cs +++ b/StuMgmClient/SystemData.cs @@ -2,13 +2,18 @@ using System.Collections.Generic; using System.Text; using StuMgmLib.MyNameSpace; +using System.Linq; +using System.Data; +using System.ComponentModel; +using System.Collections; +using System.Reflection; namespace StuMgmClient { class SystemData { static Dictionary allCourseInfo; static Dictionary allCourseStatus; - + static List allStreeDatas; internal static ErrCode InitSystemData() { ErrCode err; @@ -25,17 +30,18 @@ namespace StuMgmClient if (err != ErrCode.Success) return err; //将List转为Dictionary - //allCourseInfo = courseInfo.ToDictionary(key => key.Id, value => value); + allCourseInfo = courseInfo.ToDictionary(key => key.Id, value => value); return ErrCode.Success; } internal static ErrCode RefreshUserCourseInfo(UserCourseInfo info) { //将UserCourseInfo转为Dictionary + allCourseStatus = new Dictionary(); int num = 0; short oldTem = 0; //切割字符串 - string[] sArray = info.Details.Split(new char[2] { ':', ';' }); + string[] sArray = info.Status.Split(new char[2] { ':', ';' }); foreach (string i in sArray) { if (i.Equals("")) { break; } @@ -54,6 +60,55 @@ 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) + { + DataTable dt = new DataTable(); + dt.Columns.Add("Id", typeof(int)); + dt.Columns.Add("Name", typeof(string)); + dt.Columns.Add("Pid", typeof(int)); + dt.Columns.Add("Content", typeof(string)); + dt.Columns.Add("Statu", typeof(int)); + dt.Columns.Add("FirstNode", typeof(int)); + dt.Columns.Add("SecondNode", typeof(int)); + for (int i = 0; i < list.Count; i++) + { + DataRow dr = dt.NewRow(); + dr[0] = list[i].Id; + 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); + } } } diff --git a/StuMgmClient/app.config b/StuMgmClient/app.config index 2fa6e95..fcd0c93 100644 --- a/StuMgmClient/app.config +++ b/StuMgmClient/app.config @@ -1,3 +1,3 @@ - + diff --git a/StuMgmLib/MyNameSpace/CommonData.cs b/StuMgmLib/MyNameSpace/CommonData.cs index b5226ae..4612efa 100644 --- a/StuMgmLib/MyNameSpace/CommonData.cs +++ b/StuMgmLib/MyNameSpace/CommonData.cs @@ -83,6 +83,7 @@ namespace StuMgmLib.MyNameSpace { public short JobId;//工号 public string Name;//姓名 + public string Status; // 课程状态 public string Details;//信息描述 } @@ -99,8 +100,15 @@ namespace StuMgmLib.MyNameSpace Object = obj; } } - - - + public class StreeDatas + { + public int Id; + public string Name; + public int Pid; + public string Content; + public int Statu; + public int FirstNode; + public int SecondNode; + } }