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.

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