您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

124 行
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. using StuMgmLib.MyNameSpace;
  9. namespace StuMgmClient
  10. {
  11. public partial class StudentTree : UserControl
  12. {
  13. public StudentTree()
  14. {
  15. InitializeComponent();
  16. }
  17. internal short Job_id;
  18. internal int Token;
  19. DataTable db = null;
  20. //dataRows转化成的table
  21. DataTable tableClone = null;
  22. //Data da = new Data();
  23. private void StudentTree_Load(object sender, EventArgs e)
  24. {
  25. db = SystemCtrl.GetTable();
  26. dgvStudent.Visible = false;
  27. BindRoot();
  28. }
  29. //添加父节点的方法
  30. private void BindRoot()
  31. {
  32. //把父节点的数据帅选出来
  33. DataRow[] rows = db.Select("Pid=0");//取根
  34. foreach (DataRow dRow in rows)
  35. {
  36. TreeNode rootNode = new TreeNode();
  37. rootNode.Tag = dRow;
  38. rootNode.Text = dRow["Name"].ToString();
  39. //把此节点放入树中
  40. StudenTree.Nodes.Add(rootNode);
  41. //绑定子节点
  42. BindChildAreas(rootNode);//调用添加子节点的方法
  43. }
  44. }
  45. //添加子节点的方法、递归绑定子区域
  46. private void BindChildAreas(TreeNode fNode)
  47. {
  48. DataRow dr = (DataRow)fNode.Tag;//父节点数据关联的数据行
  49. int fAreaId = Convert.ToInt32(dr["Id"]); //父节点ID
  50. DataRow[] rows1 = db.Select("Pid =" + fAreaId);//子区域
  51. if (rows1.Length == 0) //递归终止,区域不包含子区域时
  52. {
  53. return;
  54. }
  55. foreach (DataRow dRow in rows1)
  56. {
  57. TreeNode node = new TreeNode();
  58. node.Tag = dRow;
  59. node.Text = dRow["Name"].ToString();
  60. //添加子节点
  61. fNode.Nodes.Add(node);
  62. }
  63. }
  64. //子节点单击显示内容
  65. private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  66. {
  67. if (e.Button == System.Windows.Forms.MouseButtons.Left) //单击鼠标左键才响应
  68. {
  69. if (e.Node.Level == 1) //判断子节点才响应
  70. {
  71. SystemCtrl.RefreshUserCourseInfo(Job_id, Token);
  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 == 2 && e.RowIndex != -1)
  91. {
  92. DataRow drViews = tableClone.Rows[e.RowIndex];
  93. SelectFrom sf = new SelectFrom(drViews,Job_id, Token);
  94. //string test = da.DicParsing(stateDic);
  95. sf.ShowDialog();
  96. db = SystemCtrl.GetTable();
  97. }
  98. }
  99. private void DgvStudent_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  100. {
  101. Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgvStudent.RowHeadersWidth - 4, e.RowBounds.Height);
  102. TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgvStudent.RowHeadersDefaultCellStyle.Font, rectangle, dgvStudent.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  103. }
  104. //我的任务_将状态int值格式转换string
  105. private void DgvStudent_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  106. {
  107. if (e.ColumnIndex == 1)
  108. {
  109. e.Value = Utility.InitState((int)e.Value);
  110. }
  111. }
  112. }
  113. }