You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 line
6.6 KiB

  1. using System;
  2. using System.Text;
  3. using StuMgmLib.MyNameSpace;
  4. using System.Linq;
  5. using System.Data;
  6. using System.ComponentModel;
  7. using System.Collections;
  8. using System.Reflection;
  9. using System.Collections.Generic;
  10. namespace StuMgmClient
  11. {
  12. class SystemData
  13. {
  14. static Dictionary<short, CourseInfo> allCourseInfo;
  15. internal static Dictionary<short, CourseStatusEnum> allCourseStatus;
  16. static List<CourseInfo> courseInfo;
  17. static Dictionary<short, UserCourseInfo> allUserCourseInfo;
  18. internal static ErrCode InitSystemData()
  19. {
  20. ErrCode err;
  21. err = InitCourseInfo();
  22. if (err != ErrCode.Success)
  23. return err;
  24. return ErrCode.Success;
  25. }
  26. static ErrCode InitCourseInfo()
  27. {
  28. ErrCode err;
  29. //List<CourseInfo>
  30. courseInfo = new List<CourseInfo>();
  31. err = SystemCtrl.GetCourseInfo(out courseInfo);
  32. if (err != ErrCode.Success)
  33. return err;
  34. //将List<CourseInfo>转为Dictionary<short, CourseInfo>
  35. allCourseInfo = courseInfo.ToDictionary(key => key.Id, value => value);
  36. return ErrCode.Success;
  37. }
  38. internal static ErrCode RefreshUserCourseInfo(UserCourseInfo info)
  39. {
  40. //将UserCourseInfo转为Dictionary<short,CourseStatusEnum>
  41. allCourseStatus = new Dictionary<short, CourseStatusEnum>();
  42. int num = 0;
  43. short oldTem = 0;
  44. //切割字符串
  45. string[] sArray = info.Status.Split(new char[2] { ':', ';' });
  46. foreach (string i in sArray)
  47. {
  48. if (i.Equals("")) { break; }
  49. short tem = Convert.ToInt16(i);
  50. num++;
  51. if (num % 2 != 0)
  52. {
  53. allCourseStatus.Add(tem, CourseStatusEnum.NoStart);
  54. oldTem = tem;
  55. }
  56. else
  57. {
  58. allCourseStatus[oldTem] = (CourseStatusEnum)tem;
  59. }
  60. }
  61. return ErrCode.Success;
  62. }
  63. internal static ErrCode RefreshAllUserCourseInfo(List<UserCourseInfo> info)
  64. {
  65. //将List<UserCourseInfo>转为Dictionary<short,UserCourseInfo>
  66. foreach (var item in info)
  67. {
  68. allUserCourseInfo=new Dictionary<short,UserCourseInfo>();
  69. allUserCourseInfo.Add(item.JobId, item);
  70. }
  71. return ErrCode.Success;
  72. }
  73. //internal static void StreeList()
  74. //{
  75. // allStreeDatas = new Dictionary<short,UserCourseDetail>();
  76. // foreach (var item in allCourseStatus)
  77. // {
  78. // UserCourseDetail courseDetail = new UserCourseDetail();
  79. // CourseInfo info = allCourseInfo[item.Key];//找到状态对应的课程表信息
  80. // courseDetail.Id = info.Id;
  81. // courseDetail.Name = info.Name;
  82. // courseDetail.Status = (int)item.Value;
  83. // courseDetail.Content = info.Content;
  84. // allStreeDatas.Add(info.Pid,courseDetail);
  85. // }
  86. //}
  87. //internal static UserCourseDetail r(CourseInfo info, ref Dictionary<short, UserCourseDetail> allCourseStatus)
  88. //{
  89. // UserCourseDetail sel;
  90. // if (allCourseStatus.TryGetValue(info.Id, out sel))
  91. // return sel;
  92. // UserCourseDetail m = new UserCourseDetail();
  93. // //info->m
  94. // allCourseStatus.Add(info.Id, m);
  95. // if (info.Pid != 0)
  96. // {
  97. // UserCourseDetail father = r(allCourseInfo[info.Pid], ref allCourseStatus);
  98. // father.Children.Add(m);
  99. // }
  100. // return m;
  101. //}
  102. //internal static void rr(UserCourseDetail u, TreeNode n)
  103. //{
  104. // foreach(UserCourseDetail child in u.Children)
  105. // {
  106. // TreeNode node = new TreeNode(child);
  107. // n.add(node);
  108. // rr(child, node);
  109. // }
  110. //}
  111. //internal static void aa (List<string> keys,List<string> values)
  112. //{
  113. // Dictionary<short, UserCourseDetail> allCourseStatus=new Dictionary<short,UserCourseDetail>();
  114. // for (short i = 0; i < keys.Count; i++)
  115. // r(allCourseInfo[i], ref allCourseStatus);
  116. // List<UserCourseDetail> lst = new List<UserCourseDetail>();
  117. // //
  118. // //TreeNode all;
  119. // List<TreeNode> all;
  120. // foreach(UserCourseDetail u in lst)
  121. // {
  122. // TreeNode n = new TreeNode();
  123. // rr(u, n);
  124. // all.add(n);
  125. // }
  126. //}
  127. static DataTable ListToDb(List<CourseInfo> list)
  128. {
  129. DataTable dt = new DataTable();
  130. dt.Columns.Add("Id", typeof(int));
  131. dt.Columns.Add("Name", typeof(string));
  132. dt.Columns.Add("Pid", typeof(int));
  133. dt.Columns.Add("Content", typeof(string));
  134. dt.Columns.Add("Statu", typeof(int));
  135. for (int i = 0; i < list.Count; i++)
  136. {
  137. DataRow dr = dt.NewRow();
  138. dr[0] = list[i].Id;
  139. dr[1] = list[i].Name;
  140. dr[2] = list[i].Pid;
  141. dr[3] = list[i].Content;
  142. try
  143. {
  144. dr[4] = (int)allCourseStatus[(short)list[i].Id];
  145. }
  146. catch
  147. {
  148. dr[4] = -1;
  149. }
  150. dt.Rows.Add(dr);
  151. }
  152. return dt;
  153. }
  154. static DataTable ListToDb(List<UserCourseInfo> list)
  155. {
  156. DataTable dt = new DataTable();
  157. dt.Columns.Add("job_id", typeof(short));
  158. dt.Columns.Add("name", typeof(string));
  159. dt.Columns.Add("status", typeof(string));
  160. dt.Columns.Add("details", typeof(string));
  161. for (int i = 0; i < list.Count; i++)
  162. {
  163. DataRow dr = dt.NewRow();
  164. dr[0] = list[i].JobId;
  165. dr[1] = list[i].Name;
  166. dr[2] = list[i].Status;
  167. dr[3] = list[i].Details;
  168. dt.Rows.Add(dr);
  169. }
  170. return dt;
  171. }
  172. internal static DataTable StreeTable()
  173. {
  174. return ListToDb(courseInfo);
  175. }
  176. internal static Dictionary<short, CourseStatusEnum> StreeCourseStatus()
  177. {
  178. return allCourseStatus;
  179. }
  180. }
  181. }