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.

127 rivejä
3.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. namespace StuMgmClient
  5. {
  6. enum ErrCode
  7. {
  8. Success,
  9. FailSerial,
  10. FailDeserial,
  11. FailSend,
  12. FailReceive,
  13. ErrData,
  14. }
  15. public enum Roles
  16. {
  17. NotFound = -1,
  18. Error = -2,
  19. Admin = 1,
  20. Teacher = 2,
  21. Student = 3,
  22. }
  23. [Serializable]
  24. public class UserInfo
  25. {
  26. public string Account;
  27. public string Password;
  28. public Roles UserRole;
  29. public UserInfo(string account, string password)
  30. {
  31. Account = account;
  32. Password = password;
  33. }
  34. }
  35. [Serializable]
  36. public class ServerSend
  37. {
  38. public short permission { get; set; }
  39. public DataSet ds { get; set; }
  40. }
  41. }
  42. namespace StuMgmClient
  43. {
  44. class Data
  45. {
  46. //状态值字符串转字典
  47. public Dictionary<int, int> StateParsing(DataTable table)
  48. {
  49. Dictionary<int, int> myDictionary = new Dictionary<int, int>();
  50. ClientMysql cm = new ClientMysql();
  51. DataSet ds = cm.SelectState();
  52. DataRow dr = ds.Tables["user_info"].Rows[0];
  53. string state = dr["course_status"].ToString();
  54. int num = 0;
  55. int oldTem = 0;
  56. //切割字符串
  57. string[] sArray = state.Split(new char[2] { ':', ';' });
  58. foreach (string i in sArray)
  59. {
  60. if (i.Equals("")) { break; }
  61. int tem = Convert.ToInt32(i);
  62. num++;
  63. if (num % 2 != 0)
  64. {
  65. myDictionary.Add(tem, 0);
  66. oldTem = tem;
  67. }
  68. else
  69. {
  70. myDictionary[oldTem] = tem;
  71. }
  72. }
  73. return myDictionary;
  74. }
  75. //字典转字符串
  76. public string DicParsing(Dictionary<int, int> dic)
  77. {
  78. string stateText = "";
  79. foreach (var item in dic)
  80. {
  81. stateText = stateText + item.Key + ":" + item.Value + ";";
  82. }
  83. return stateText;
  84. }
  85. //查询所有子节点
  86. public void GetAllNodes(string id, DataTable table, ref Dictionary<int, int> nodesDic)
  87. {
  88. //把父节点的数据筛选出来
  89. DataRow[] rows = table.Select("pid =" + id);//取根
  90. if (rows.Length <= 0)
  91. {
  92. nodesDic.Add(Convert.ToInt32(id), 0);
  93. return;
  94. }
  95. foreach (DataRow dr in rows)
  96. {
  97. GetAllNodes(dr["id"].ToString(), table, ref nodesDic);
  98. }
  99. }
  100. //获取所有子节点Dictionary
  101. public Dictionary<int, int> GetNodesDic(DataTable table)
  102. {
  103. Dictionary<int, int> nodesDic = new Dictionary<int, int>();
  104. GetAllNodes("0", table, ref nodesDic);
  105. return nodesDic;
  106. }
  107. }
  108. }