using System; using System.Text; using StuMgmLib.MyNameSpace; using System.Linq; using System.Data; using System.ComponentModel; using System.Collections; using System.Reflection; using System.Collections.Generic; namespace StuMgmClient { class SystemData { static Dictionary allCourseInfo; static Dictionary allCourseStatus; static List courseInfo; internal static ErrCode InitSystemData() { ErrCode err; err = InitCourseInfo(); if (err != ErrCode.Success) return err; return ErrCode.Success; } static ErrCode InitCourseInfo() { ErrCode err; //List courseInfo = new List(); err = SystemCtrl.GetCourseInfo(out courseInfo); if (err != ErrCode.Success) return err; //将List转为Dictionary 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.Status.Split(new char[2] { ':', ';' }); foreach (string i in sArray) { if (i.Equals("")) { break; } short tem = Convert.ToInt16(i); num++; if (num % 2 != 0) { allCourseStatus.Add(tem, CourseStatusEnum.NoStart); oldTem = tem; } else { allCourseStatus[oldTem] = (CourseStatusEnum)tem; } } return ErrCode.Success; } //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)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Pid", typeof(int)); dt.Columns.Add("Content", typeof(string)); dt.Columns.Add("Statu", 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; dt.Rows.Add(dr); } return dt; } internal static DataTable StreeTable() { return ListToDb(courseInfo); } internal static Dictionary StreeCourseStatus() { return allCourseStatus; } } }