myTree

//myTree.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsApplication1
{
    public partial class myTree : Form
    {
        private OleDbDataAdapter oda;
        private DataSet ds;
        baseClass.OleDbClass oledbclass = new WindowsApplication1.baseClass.OleDbClass();
        private DataTable treeTab = new DataTable();
        public myTree()
        {
            InitializeComponent();
        }
        private void myTree_Load(object sender, EventArgs e)
        {
            this.oda = oledbclass.OleDa("select * from tb_dept order by deptId");
            this.oda.Fill(treeTab);
            DataTable temptab = treeTab.Copy();
            DataView myView = new DataView(temptab);
            myView.RowFilter = "ParentIndex=-1";
            if (myView.Count > 0)
            {
                foreach (DataRowView myRow in myView)
                {
                    string strDeptName = myRow["DeptName"].ToString().Trim();
                    this.treevDept.Nodes.Add(new TreeNode(strDeptName));
                    myTreeView(strDeptName, treevDept.Nodes[0], myRow);
                    treevDept.SelectedNode = treevDept.Nodes[0];

                }
            }
        }
        private void myTreeView(string parentPart, TreeNode parentNode, DataRowView parentRow)
        {
            string strDeptNode = "";
            DataTable temptab = treeTab.Copy();
            DataView myView = new DataView(treeTab);
            myView.RowFilter = "ParentIndex='" + parentRow["deptId"].ToString().Trim() + "'";
            foreach (DataRowView myRow in myView)
            {
                string strDeptName = myRow["DeptName"].ToString().Trim();
                TreeNode myNode = new TreeNode(strDeptName);
                parentNode.Nodes.Add(myNode);
                myTreeView(strDeptName, myNode, myRow);
            }
        }
        //选中部门
        private void treevDept_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.txtDeptName.Text = e.Node.Text.Trim();
            ds = oledbclass.OleDs("select * from tb_dept where deptName='" + this.txtDeptName.Text + "'", "tb_dept");
            DataRowView rowview=ds.Tables["tb_dept"].DefaultView[0];
            this.txtDeptDirector.Text = rowview["deptDirector"].ToString();
            this.txtDeptId.Text = rowview["deptId"].ToString();
            this.txtDeptPhone.Text = rowview["deptPhone"].ToString();
            this.txtParentIndex.Text = rowview["ParentIndex"].ToString();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace WindowsApplication1.baseClass
{
    class OleDbClass
    {
        private OleDbConnection conn;
        private OleDbDataAdapter oda;
        private DataSet ds;
        private OleDbCommand ocmd;
        public OleDbConnection oleDbConn()
        {
            conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Jet OLEDB:Database Password=00000;Data Source=" + @"|datadirectory|\hr.mdb");
            return conn;
        }
        public DataSet OleDs(string strsql,string strtab)
        {
            conn = this.oleDbConn();
            oda = new OleDbDataAdapter(strsql,conn);
            ds = new DataSet();
            oda.Fill(ds, strtab);
            conn.Close();
            return ds;
        }
        public OleDbDataAdapter OleDa(string strsql)
        {
            conn = this.oleDbConn();
            oda = new OleDbDataAdapter(strsql,conn);
            return oda;
        }
        public void OleCmd(string strsql)
        {
            conn = this.oleDbConn();
            conn.Open();
            ocmd = new OleDbCommand(strsql,conn);
            ocmd.ExecuteNonQuery();
            conn.Close();

        }
    }
}

转载于:https://www.cnblogs.com/tgyun/archive/2009/01/09/1372287.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值