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.

83 rivejä
2.4 KiB

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