📄 deptmanagement.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.SqlClient;
using System.IO;
namespace BlueHill_Win_
{
public partial class DeptManagement : Form
{
public DeptManagement()
{
InitializeComponent();
}
//变量
//string Table_Name;
//string Date_Column_Name;
public static string Select_String;
public void TreeView_Select(string Table_Name, string Date_Column_Name)
{
//SqlConnection con = DB.connection();
//con.Open();
//SqlCommand cmd = new SqlCommand("select 部门名称 from 部门表", con);
//SqlDataAdapter sda=new SqlDataAdapter();
//DataTable sdt = new DataTable();
}
private void btnQuit_Click(object sender, EventArgs e)
{
//this.Hide();
//Main M = new Main();
//M.Show();
this.Close();
}
private void btnAddDept_Click(object sender, EventArgs e)
{
this.Hide();
AddDept AD = new AddDept();
AD.Show();
}
private void btnDeleteDept_Click(object sender, EventArgs e)
{
string DD = tvDept.SelectedNode.Text;
//MessageBox.Show(DD.ToString());
SqlConnection con = DB.connection();
con.Open();
SqlCommand cmd = new SqlCommand("delete from 部门表 where 部门名称='" + DD + "'", con);
int count = Convert.ToInt32(cmd.ExecuteNonQuery());
if (count > 0)
{
DialogResult = MessageBox.Show("删除成功!", "提示");
this.Hide();
DeptManagement DM = new DeptManagement();
DM.Show();
}
else
DialogResult = MessageBox.Show("操作失败!", "提示");
con.Close();
}
private void btnDeptDetinfo_Click(object sender, EventArgs e)
{
Select_String = tvDept.SelectedNode.Text;
if(Select_String =="")
{
DialogResult = MessageBox.Show("请选择你要查看的部门!", "提示");
}
else
this.Hide();
DeptDetail DP = new DeptDetail();
DP.Show();
}
private void DeptManagement_Load(object sender, EventArgs e)
{
SqlConnection con = DB.connection();
con.Open();
SqlCommand cmd = new SqlCommand("select * from 部门表",con);
SqlDataReader bm = cmd.ExecuteReader();
while (bm.Read())
{
tvDept.Nodes.Add(bm["部门名称"].ToString());
}
con.Close();
/*//tvDept.DataBindings.ToString();
SqlDataAdapter bm = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
bm.Fill(ds);
}
catch
{
}
finally
{
cmd = null;
con.Close();
}
//往TreeView中添加树节点
TreeNode tn = new TreeNode();
tn.Text = "所有产品";
tn.Name = "0";//Name作为ID
tn.Tag = "0";//Tag作为RootID
tn.ImageIndex = 0;
tn.SelectedImageIndex = 0;
tvDept.Nodes.Add(tn);//该TreeView命名为tv
tvDept.SelectedNode = tvDept.TopNode;
//把其他节点加上去
if (ds != null)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
tn = new TreeNode();
tn.Text = dr["Product"].ToString();
tn.Name = dr["CateID"].ToString();//Name作为CateID
tn.Tag = dr["RootID"].ToString();//Tag作为RootID
tn.ImageIndex = 1;
tn.SelectedImageIndex = 1;
//判断是否为主节点
if (dr["CateID"].ToString() == dr["RootID"].ToString())
{
//主节点
tvDept.SelectedNode = tvDept.TopNode;
}
else
{
//其他节点
if (tvDept.SelectedNode.Name != dr["ParentID"].ToString())
{
TreeNode[] tn_temp = tvDept.Nodes.Find(dr["ParentID"].ToString(), true); //通过ParentID查找父节点
if (tn_temp.Length > 0)
{
tvDept.SelectedNode = tn_temp[0]; //选中查找到的节点
}
}
}
tvDept.SelectedNode.Nodes.Add(tn);
}
//tv.ExpandAll();//展开TreeView
tvDept.SelectedNode = tvDept.TopNode; //最顶端节点选中
}*/
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -