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.

121 rivejä
4.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace StuMgmClient
  9. {
  10. public partial class StudentTree : UserControl
  11. {
  12. public StudentTree()
  13. {
  14. InitializeComponent();
  15. }
  16. DataTable db = null;
  17. ////个人信息
  18. //private DataSet ds = null;
  19. //public DataSet Ds
  20. //{
  21. // get { return ds; }
  22. // set { ds = value; }
  23. //}
  24. ////节点table
  25. //DataTable table = null;
  26. ////dataRows转化成的table
  27. //DataTable tableClone = null;
  28. //Data da = new Data();
  29. private void StudentTree_Load(object sender, EventArgs e)
  30. {
  31. db = SystemCtrl.GetStreeTable();
  32. dgvStudent.Visible = false;
  33. BindRoot();
  34. //da.GetNodesDic(table);
  35. }
  36. ////添加父节点的方法
  37. private void BindRoot()
  38. {
  39. //ClientMysql cm = new ClientMysql();
  40. // DataSet ds = cm.SelectNode();
  41. //table = Ds.Tables["course_info"];
  42. DataRow[] rows = db.Select("FirstNode=0");//取根
  43. foreach (DataRow dRow in rows)
  44. {
  45. TreeNode rootNode = new TreeNode();
  46. rootNode.Tag = dRow;
  47. rootNode.Text = dRow["Name"].ToString();
  48. //把此节点放入树中
  49. StudenTree.Nodes.Add(rootNode);
  50. //绑定子节点
  51. BindChildAreas(rootNode);//调用添加子节点的方法
  52. }
  53. }
  54. ////添加子节点的方法、递归绑定子区域
  55. private void BindChildAreas(TreeNode fNode)
  56. {
  57. DataRow dr = (DataRow)fNode.Tag;//父节点数据关联的数据行
  58. int fAreaId = Convert.ToInt32(dr["Id"]); //父节点ID
  59. DataRow[] rows1 = db.Select("SecondNode =" + fAreaId);//子区域
  60. if (rows1.Length == 0) //递归终止,区域不包含子区域时
  61. {
  62. return;
  63. }
  64. foreach (DataRow dRow in rows1)
  65. {
  66. TreeNode node = new TreeNode();
  67. node.Tag = dRow;
  68. node.Text = dRow["Name"].ToString();
  69. //添加子节点
  70. fNode.Nodes.Add(node);
  71. }
  72. }
  73. ////子节点单击显示内容
  74. //private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  75. private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { }
  76. //{
  77. // if (e.Button == System.Windows.Forms.MouseButtons.Left) //单击鼠标左键才响应
  78. // {
  79. // if (e.Node.Level == 1) //判断子节点才响应
  80. // {
  81. // dgvStudent.Visible = true;
  82. // DataRow dr = (DataRow)e.Node.Tag;
  83. // int fAreaId = Convert.ToInt32(dr["id"]); //子节点ID
  84. // DataRow[] drows = table.Select("pid =" + fAreaId);//取根
  85. // tableClone = table.Clone();//克隆表结构
  86. // foreach (DataRow drr in drows)
  87. // {
  88. // tableClone.ImportRow(drr);
  89. // }
  90. // dgvStudent.AutoGenerateColumns = false;
  91. // dgvStudent.AllowUserToAddRows = false;
  92. // dgvStudent.DataSource = tableClone;
  93. // }
  94. // }
  95. //}
  96. private void DgvStudent_CellContentClick(object sender, DataGridViewCellEventArgs e)
  97. { }
  98. ////我的任务_查看按钮方法
  99. //private void DgvStudent_CellContentClick(object sender, DataGridViewCellEventArgs e)
  100. //{
  101. // if (e.ColumnIndex == 1 && e.RowIndex != -1)
  102. // {
  103. // //Dictionary<int, int> stateDic = da.StateParsing(table);
  104. // Dictionary<int, int> stateDic = da.GetNodesDic(table);
  105. // // string s=da.DicParsing(stateDic);
  106. // DataRow drViews = tableClone.Rows[e.RowIndex];
  107. // int state = stateDic[Convert.ToInt32((drViews["id"]))];
  108. // SelectFrom sf = new SelectFrom(drViews, state);
  109. // //string test = da.DicParsing(stateDic);
  110. // sf.ShowDialog();
  111. // // ShowData();
  112. // }
  113. //}
  114. }
  115. }