|
- 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<short, CourseInfo> allCourseInfo;
- internal static Dictionary<short, CourseStatusEnum> allCourseStatus;
- static List<CourseInfo> courseInfo;
- static Dictionary<short, UserCourseInfo> allUserCourseInfo;
- internal static ErrCode InitSystemData()
- {
- ErrCode err;
- err = InitCourseInfo();
- if (err != ErrCode.Success)
- return err;
- return ErrCode.Success;
- }
- static ErrCode InitCourseInfo()
- {
- ErrCode err;
- //List<CourseInfo>
- courseInfo = new List<CourseInfo>();
- err = SystemCtrl.GetCourseInfo(out courseInfo);
- if (err != ErrCode.Success)
- return err;
- //将List<CourseInfo>转为Dictionary<short, CourseInfo>
- allCourseInfo = courseInfo.ToDictionary(key => key.Id, value => value);
- return ErrCode.Success;
- }
-
- internal static ErrCode RefreshUserCourseInfo(UserCourseInfo info)
- {
- //将UserCourseInfo转为Dictionary<short,CourseStatusEnum>
- allCourseStatus = new Dictionary<short, CourseStatusEnum>();
- 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 ErrCode RefreshAllUserCourseInfo(List<UserCourseInfo> info)
- {
- //将List<UserCourseInfo>转为Dictionary<short,UserCourseInfo>
- foreach (var item in info)
- {
- allUserCourseInfo=new Dictionary<short,UserCourseInfo>();
- allUserCourseInfo.Add(item.JobId, item);
- }
- return ErrCode.Success;
-
- }
-
- //internal static void StreeList()
- //{
- // allStreeDatas = new Dictionary<short,UserCourseDetail>();
-
- // 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<short, UserCourseDetail> 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<string> keys,List<string> values)
- //{
- // Dictionary<short, UserCourseDetail> allCourseStatus=new Dictionary<short,UserCourseDetail>();
- // for (short i = 0; i < keys.Count; i++)
- // r(allCourseInfo[i], ref allCourseStatus);
- // List<UserCourseDetail> lst = new List<UserCourseDetail>();
- // //
- // //TreeNode all;
- // List<TreeNode> all;
- // foreach(UserCourseDetail u in lst)
- // {
- // TreeNode n = new TreeNode();
- // rr(u, n);
- // all.add(n);
- // }
- //}
-
- static DataTable ListToDb(List<CourseInfo> 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;
- try
- {
- dr[4] = (int)allCourseStatus[(short)list[i].Id];
- }
- catch
- {
- dr[4] = -1;
- }
- dt.Rows.Add(dr);
- }
- return dt;
- }
- static DataTable ListToDb(List<UserCourseInfo> list)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("job_id", typeof(short));
- dt.Columns.Add("name", typeof(string));
- dt.Columns.Add("status", typeof(string));
- dt.Columns.Add("details", typeof(string));
- for (int i = 0; i < list.Count; i++)
- {
- DataRow dr = dt.NewRow();
- dr[0] = list[i].JobId;
- dr[1] = list[i].Name;
- dr[2] = list[i].Status;
- dr[3] = list[i].Details;
- dt.Rows.Add(dr);
- }
- return dt;
- }
- internal static DataTable StreeTable()
- {
- return ListToDb(courseInfo);
- }
- internal static Dictionary<short, CourseStatusEnum> StreeCourseStatus()
- {
- return allCourseStatus;
- }
-
- }
- }
|