|
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
-
- namespace StuMgmClient
- {
- public partial class StudentTree : UserControl
- {
- public StudentTree()
- {
- InitializeComponent();
- }
- //个人信息
- private DataSet ds = null;
- public DataSet Ds
- {
- get { return ds; }
- set { ds = value; }
- }
- //节点table
- DataTable table = null;
- //dataRows转化成的table
- DataTable tableClone = null;
- Data da = new Data();
- private void StudentTree_Load(object sender, EventArgs e)
- {
- dgvStudent.Visible = false;
- BindRoot();
- //da.GetNodesDic(table);
- }
-
- //添加父节点的方法
- private void BindRoot()
- {
- //ClientMysql cm = new ClientMysql();
- // DataSet ds = cm.SelectNode();
- table = Ds.Tables["course_info"];
- //把父节点的数据帅选出来
- DataRow[] rows = table.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 = table.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) //判断子节点才响应
- {
- dgvStudent.Visible = true;
- DataRow dr = (DataRow)e.Node.Tag;
- int fAreaId = Convert.ToInt32(dr["id"]); //子节点ID
- DataRow[] drows = table.Select("pid =" + fAreaId);//取根
- tableClone = table.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 == 1 && e.RowIndex != -1)
- {
- //Dictionary<int, int> stateDic = da.StateParsing(table);
- Dictionary<int, int> stateDic = da.GetNodesDic(table);
- // string s=da.DicParsing(stateDic);
- DataRow drViews = tableClone.Rows[e.RowIndex];
- int state = stateDic[Convert.ToInt32((drViews["id"]))];
- SelectFrom sf = new SelectFrom(drViews, state);
- //string test = da.DicParsing(stateDic);
- sf.ShowDialog();
- // ShowData();
- }
- }
-
- }
- }
|