|
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using StuMgmLib.MyNameSpace;
- namespace StuMgmClient
- {
- public partial class StudentTree : UserControl
- {
- public StudentTree()
- {
- InitializeComponent();
- }
- internal short Job_id;
- internal int Token;
- DataTable db = null;
- //dataRows转化成的table
- DataTable tableClone = null;
- //Data da = new Data();
- private void StudentTree_Load(object sender, EventArgs e)
- {
- db = SystemCtrl.GetTable();
- dgvStudent.Visible = false;
- BindRoot();
- }
- //添加父节点的方法
- private void BindRoot()
- {
- //把父节点的数据帅选出来
- DataRow[] rows = db.Select("Pid=0");//取根
- foreach (DataRow dRow in rows)
- {
- TreeNode rootNode = new TreeNode();
- rootNode.Tag = dRow;
- rootNode.Text = dRow["Name"].ToString();
- //把此节点放入树中
- StudenTree.Nodes.Add(rootNode);
- //绑定子节点
- BindChildAreas(rootNode);//调用添加子节点的方法
- }
- }
-
- //添加子节点的方法、递归绑定子区域
- private void BindChildAreas(TreeNode fNode)
- {
- DataRow dr = (DataRow)fNode.Tag;//父节点数据关联的数据行
- int fAreaId = Convert.ToInt32(dr["Id"]); //父节点ID
- DataRow[] rows1 = db.Select("Pid =" + fAreaId);//子区域
- if (rows1.Length == 0) //递归终止,区域不包含子区域时
- {
- return;
- }
- foreach (DataRow dRow in rows1)
- {
- TreeNode node = new TreeNode();
- node.Tag = dRow;
- node.Text = dRow["Name"].ToString();
- //添加子节点
- fNode.Nodes.Add(node);
- }
- }
-
- //子节点单击显示内容
- private void StudentTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- if (e.Button == System.Windows.Forms.MouseButtons.Left) //单击鼠标左键才响应
- {
- if (e.Node.Level == 1) //判断子节点才响应
- {
- SystemCtrl.RefreshUserCourseInfo(Job_id, Token);
- dgvStudent.Visible = true;
- DataRow dr = (DataRow)e.Node.Tag;
- int fAreaId = Convert.ToInt32(dr["id"]); //子节点ID
- DataRow[] drows = db.Select("pid =" + fAreaId);//取根
- tableClone = db.Clone();//克隆表结构
- foreach (DataRow drr in drows)
- {
- tableClone.ImportRow(drr);
- }
- dgvStudent.AutoGenerateColumns = false;
- dgvStudent.AllowUserToAddRows = false;
- dgvStudent.DataSource = tableClone;
- }
- }
- }
-
-
- ////我的任务_查看按钮方法
- private void DgvStudent_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.ColumnIndex == 2 && e.RowIndex != -1)
- {
- DataRow drViews = tableClone.Rows[e.RowIndex];
-
- SelectFrom sf = new SelectFrom(drViews,Job_id, Token);
- //string test = da.DicParsing(stateDic);
- sf.ShowDialog();
- db = SystemCtrl.GetTable();
-
- }
- }
-
-
- private void DgvStudent_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
- {
- Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgvStudent.RowHeadersWidth - 4, e.RowBounds.Height);
- TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgvStudent.RowHeadersDefaultCellStyle.Font, rectangle, dgvStudent.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
- }
-
-
- //我的任务_将状态int值格式转换string
- private void DgvStudent_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
- {
- if (e.ColumnIndex == 1)
- {
- e.Value = Utility.InitState((int)e.Value);
- }
- }
- }
- }
|