private void InitTree(TreeNodeCollection Nds, string parentId) { DataView dv = new DataView(); TreeNode tmpNd; string intId; if (local) { DataSet ds = GetDataSet("select * from staff_info"); dv.Table = ds.Tables[0]; } else { DataTable dt = MySQLConnection.GetDataTableValue("select * from staff_info"); dt.TableName = "staff_info"; dv.Table = dt; } dv.RowFilter = "parent_id='" + parentId + "'"; foreach (DataRowView drv in dv) { tmpNd = new TreeNode(); tmpNd.Tag = drv["id"].ToString(); tmpNd.Text = drv["last_name"].ToString(); if (drv["parent_id"].ToString() == "1") //10 means admin { tmpNd.ImageIndex = tmpNd.SelectedImageIndex = 0; } else { tmpNd.ImageIndex = tmpNd.SelectedImageIndex = 1; } Nds.Add(tmpNd); intId = drv["parent_id"].ToString(); InitTree(tmpNd.Nodes, tmpNd.Tag.ToString()); } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Action == TreeViewAction.ByMouse) { DataView dv = new DataView(); if (local) { DataSet ds = GetDataSet("select * from staff_info where id = '" + e.Node.Tag + "'"); dv.Table = ds.Tables[0]; } else { DataTable dt = MySQLConnection.GetDataTableValue("select * from staff_info where id = '" + e.Node.Tag + "'"); dt.TableName = "staff_info"; dv.Table = dt; } DataRowView drv = dv[0]; if (e.Node.Parent != null) { txt_name.Text = drv["last_name"].ToString(); if (drv["gender"].ToString() == "male") { comBox_gender.SelectedIndex = 0; } else { comBox_gender.SelectedIndex = 1; } txt_SSN.Text = drv["ssn"].ToString(); if (drv["parent_id"].ToString() == "1") { cmb_position.SelectedIndex = 0; } if (drv["parent_id"].ToString() == "2") { cmb_position.SelectedIndex = 1; } if (drv["parent_id"].ToString() == "3") { cmb_position.SelectedIndex = 2; } if (drv["parent_id"].ToString() == "4") { cmb_position.SelectedIndex = 3; } txt_Phone.Text = drv["phone"].ToString(); txt_Address.Text = drv["address_id"].ToString(); //txt_Birthday.Text = drv["Birthday"].ToString(); txt_Email.Text = drv["email"].ToString(); toolStripButton2.Enabled = true; btn_del.Enabled = true; } else { toolStripButton2.Enabled = false; btn_del.Enabled = false; } } }