using System; using System.Collections.Generic; using System.Data; namespace StuMgmClient { public enum Roles { NotFound = -1, Error = -2, Admin = 1, Teacher = 2, Student = 3, } class Data { //状态值字符串转字典 public Dictionary StateParsing(DataTable table) { Dictionary myDictionary = new Dictionary(); ClientMysql cm = new ClientMysql(); DataSet ds = cm.SelectState(); DataRow dr = ds.Tables["user_info"].Rows[0]; string state = dr["course_status"].ToString(); int num = 0; int oldTem = 0; //切割字符串 string[] sArray = state.Split(new char[2] { ':', ';' }); foreach (string i in sArray) { if (i.Equals("")) { break; } int tem = Convert.ToInt32(i); num++; if (num % 2 != 0) { myDictionary.Add(tem, 0); oldTem = tem; } else { myDictionary[oldTem] = tem; } } return myDictionary; } //字典转字符串 public string DicParsing(Dictionary dic) { string stateText = ""; foreach (var item in dic) { stateText = stateText + item.Key + ":" + item.Value + ";"; } return stateText; } //查询所有子节点 public void GetAllNodes(string id, DataTable table, ref Dictionary nodesDic) { //把父节点的数据筛选出来 DataRow[] rows = table.Select("pid =" + id);//取根 if (rows.Length <= 0) { nodesDic.Add(Convert.ToInt32(id), 0); return; } foreach (DataRow dr in rows) { GetAllNodes(dr["id"].ToString(), table, ref nodesDic); } } //获取所有子节点Dictionary public Dictionary GetNodesDic(DataTable table) { Dictionary nodesDic = new Dictionary(); GetAllNodes("0", table, ref nodesDic); return nodesDic; } } }