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.

115 rivejä
3.9 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using StuMgmLib.MyNameSpace;
  5. using System.Linq;
  6. using System.Data;
  7. using System.ComponentModel;
  8. using System.Collections;
  9. using System.Reflection;
  10. namespace StuMgmClient
  11. {
  12. class SystemData
  13. {
  14. static Dictionary<short, CourseInfo> allCourseInfo;
  15. static Dictionary<short,CourseStatusEnum> allCourseStatus;
  16. static List<StreeDatas> allStreeDatas;
  17. internal static ErrCode InitSystemData()
  18. {
  19. ErrCode err;
  20. err = InitCourseInfo();
  21. if (err != ErrCode.Success)
  22. return err;
  23. return ErrCode.Success;
  24. }
  25. static ErrCode InitCourseInfo()
  26. {
  27. ErrCode err;
  28. List<CourseInfo> courseInfo;
  29. err = SystemCtrl.GetCourseInfo(out courseInfo);
  30. if (err != ErrCode.Success)
  31. return err;
  32. //将List<CourseInfo>转为Dictionary<short, CourseInfo>
  33. allCourseInfo = courseInfo.ToDictionary(key => key.Id, value => value);
  34. return ErrCode.Success;
  35. }
  36. internal static ErrCode RefreshUserCourseInfo(UserCourseInfo info)
  37. {
  38. //将UserCourseInfo转为Dictionary<short,CourseStatusEnum>
  39. allCourseStatus = new Dictionary<short, CourseStatusEnum>();
  40. int num = 0;
  41. short oldTem = 0;
  42. //切割字符串
  43. string[] sArray = info.Status.Split(new char[2] { ':', ';' });
  44. foreach (string i in sArray)
  45. {
  46. if (i.Equals("")) { break; }
  47. short tem = Convert.ToInt16(i);
  48. num++;
  49. if (num % 2 != 0)
  50. {
  51. allCourseStatus.Add(tem, CourseStatusEnum.NoStart);
  52. oldTem = tem;
  53. }
  54. else
  55. {
  56. allCourseStatus[oldTem] = (CourseStatusEnum)tem;
  57. }
  58. }
  59. return ErrCode.Success;
  60. }
  61. static void StreeList()
  62. {
  63. allStreeDatas = new List<StreeDatas>();
  64. StreeDatas sd=null;
  65. foreach (var item in allCourseStatus)
  66. {
  67. sd = new StreeDatas();
  68. CourseInfo infoTwo = allCourseInfo[item.Key];//找到状态对应的课程表信息
  69. sd.SecondNode = infoTwo.Pid;//二级节点9
  70. CourseInfo infoOne = allCourseInfo[infoTwo.Pid];
  71. CourseInfo infoThree = allCourseInfo[infoOne.Pid];
  72. sd.FirstNode = infoThree.Pid;
  73. sd.Id = infoTwo.Id;
  74. sd.Name = infoTwo.Name;
  75. sd.Pid = infoTwo.Pid;
  76. sd.Statu = (int)item.Value;
  77. sd.Content = infoTwo.Content;
  78. allStreeDatas.Add(sd);
  79. }
  80. }
  81. static DataTable ListToDb(List<StreeDatas> list)
  82. {
  83. DataTable dt = new DataTable();
  84. dt.Columns.Add("Id", typeof(int));
  85. dt.Columns.Add("Name", typeof(string));
  86. dt.Columns.Add("Pid", typeof(int));
  87. dt.Columns.Add("Content", typeof(string));
  88. dt.Columns.Add("Statu", typeof(int));
  89. dt.Columns.Add("FirstNode", typeof(int));
  90. dt.Columns.Add("SecondNode", typeof(int));
  91. for (int i = 0; i < list.Count; i++)
  92. {
  93. DataRow dr = dt.NewRow();
  94. dr[0] = list[i].Id;
  95. dr[1] = list[i].Name;
  96. dr[2] = list[i].Pid;
  97. dr[3] = list[i].Content;
  98. dr[4] = list[i].Statu;
  99. dr[5] = list[i].FirstNode;
  100. dr[6] = list[i].SecondNode;
  101. dt.Rows.Add(dr);
  102. }
  103. return dt;
  104. }
  105. internal static DataTable StreeTable()
  106. {
  107. StreeList();
  108. return ListToDb(allStreeDatas);
  109. }
  110. }
  111. }