⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessionform.cs

📁 c#编写的人事管理系统源码 写得不错 值得收藏
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace PM
{
	/// <summary>
	/// sessionForm 的摘要说明。
	/// </summary>
	public class sessionForm : System.Windows.Forms.Form
	{
		public System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.Button Break_bt;
		private System.Windows.Forms.Button close_bt;
		private System.Windows.Forms.ImageList imageList1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.ContextMenu contextMenu1;


        //选中的部门名称
		public string sessionId = string.Empty;
		public static sessionForm sf;
		public sessionForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
            sf = this;
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(sessionForm));
			this.treeView1 = new System.Windows.Forms.TreeView();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.Break_bt = new System.Windows.Forms.Button();
			this.close_bt = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// treeView1
			// 
			this.treeView1.ContextMenu = this.contextMenu1;
			this.treeView1.ImageList = this.imageList1;
			this.treeView1.Location = new System.Drawing.Point(8, 16);
			this.treeView1.Name = "treeView1";
			this.treeView1.Size = new System.Drawing.Size(168, 256);
			this.treeView1.TabIndex = 0;
			// 
			// contextMenu1
			// 
			this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// Break_bt
			// 
			this.Break_bt.Location = new System.Drawing.Point(200, 176);
			this.Break_bt.Name = "Break_bt";
			this.Break_bt.TabIndex = 1;
			this.Break_bt.Text = "刷新";
			this.Break_bt.Click += new System.EventHandler(this.Break_bt_Click);
			// 
			// close_bt
			// 
			this.close_bt.Location = new System.Drawing.Point(200, 224);
			this.close_bt.Name = "close_bt";
			this.close_bt.TabIndex = 5;
			this.close_bt.Text = "关闭";
			this.close_bt.Click += new System.EventHandler(this.close_bt_Click);
			// 
			// button1
			// 
			this.button1.ContextMenu = this.contextMenu1;
			this.button1.Location = new System.Drawing.Point(200, 24);
			this.button1.Name = "button1";
			this.button1.TabIndex = 6;
			this.button1.Text = "功能↓";
			this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown);
			// 
			// sessionForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(296, 285);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.close_bt);
			this.Controls.Add(this.Break_bt);
			this.Controls.Add(this.treeView1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "sessionForm";
			this.Text = "部门设置";
			this.Load += new System.EventHandler(this.sessionForm_Load);
			this.ResumeLayout(false);

		}
		#endregion

		#region  窗体加载时填充数据到树型控件中
		public void sessionForm_Load(object sender, System.EventArgs e)
		{
			this.treeView1.Nodes.Clear();
		    TreeNode newNode = new TreeNode("部门");
			this.treeView1.Nodes.Add(newNode);
			this.Addsub(newNode,"select * from SectionInfo");
			this.treeView1.ExpandAll();
		}
		#endregion

        #region  添加子树项
		private void Addsub(TreeNode parentNode,string str)
		{
		    Base bb = new Base();
			DataTable dt = new DataTable();
			dt = bb.ExeSQLdt(str);
			for(int i = 0 ; i < dt.Rows.Count ; i ++)
			{
			    parentNode.Nodes.Add(dt.Rows[i][1].ToString());
			}
		}
		#endregion

        #region  刷新
		private void Break_bt_Click(object sender, System.EventArgs e)
		{
			this.treeView1.ExpandAll();
		}
		#endregion

		#region  修改部门
		private void update_dt_click(object sender, System.EventArgs e)
		{
			if(this.treeView1.SelectedNode.Text == "部门")
			{
				MessageBox.Show("请选择具体的部门!");
			}
			else
			{
				if(mainForm.mf.CheckForm("TreeNodeForm") == true)
				{
					return ;
				}
				else
				{
					string str = "select * from SectionInfo where sName='" + this.treeView1.SelectedNode.Text + "'";
					DataTable dt = new DataTable();
					Base bb = new Base();
					dt = bb.ExeSQLdt(str);
					this.sessionId = dt.Rows[0]["sId"].ToString();
					TreeNodeForm tnf = new TreeNodeForm();
					tnf.MdiParent = mainForm.mf;
					tnf.Show();
					TreeNodeForm.tnf.label1.Text = "请输入新部门名称";
					TreeNodeForm.tnf.textBox1.Text = this.treeView1.SelectedNode.Text;
				}

			}
		}
		#endregion

        #region  添加部门
		private void Insersub_bt_Click(object sender, System.EventArgs e)
		{
			if(mainForm.mf.CheckForm("TreeNodeForm") == true)
			{
				return ;
			}
			else
			{
			    TreeNodeForm tnf = new TreeNodeForm();
				tnf.MdiParent = mainForm.mf;
				tnf.Show();
				TreeNodeForm.tnf.label1.Text = "请输入部门名称";
			}
		}
		#endregion

        #region  关闭
		private void close_bt_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		#endregion

        #region  删除
		private void delete_bt_Click(object sender, System.EventArgs e)
		{
			if(this.treeView1.SelectedNode.Text == "部门")
			{
				DialogResult result = MessageBox.Show("是否真的删除全部部门?","提示!",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
				if(result == DialogResult.Yes)
				{
					string s = "delete from SectionInfo";
					Base b = new Base();
					b.ExeSQL(s);
					this.treeView1.SelectedNode.Remove();
				}
				else if(result == DialogResult.No)
				{
					return ;
				}
			}
			else
			{
				DialogResult result = MessageBox.Show("是否真的删除?   " +this.treeView1.SelectedNode.Text,"提示!",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
				if(result == DialogResult.Yes)
				{
					string s = "select * from SectionInfo where sName='" + this.treeView1.SelectedNode.Text + "'";
					DataTable dt = new DataTable();
					Base b1 = new Base();
					dt = b1.ExeSQLdt(s);
					string id = dt.Rows[0]["sId"].ToString();
					string str = "delete from SectionInfo where sId=" + int.Parse(id);
					Base b2 = new Base();
					b2.ExeSQL(str);
                    this.treeView1.SelectedNode.Remove();
				}
				else if(result == DialogResult.No)
				{
					return ;
				}
			}
		}
		#endregion

		#region  功能按钮的菜单事件
		private void contextMenu1_Popup(object sender, System.EventArgs e)
		{
			if(this.contextMenu1.SourceControl == this.button1)
			{
				this.contextMenu1.MenuItems.Clear();
				this.contextMenu1.MenuItems.Add("刷新",new EventHandler(this.Break_bt_Click));
				this.contextMenu1.MenuItems.Add("-");
			    this.contextMenu1.MenuItems.Add("添加部门",new EventHandler(this.Insersub_bt_Click));
				this.contextMenu1.MenuItems.Add("删除部门",new EventHandler(this.delete_bt_Click));
				this.contextMenu1.MenuItems.Add("修改部门",new EventHandler(this.update_dt_click));
				this.contextMenu1.MenuItems.Add("-");
				this.contextMenu1.MenuItems.Add("退出",new EventHandler(this.close_bt_Click));
			}
			if(this.contextMenu1.SourceControl == this.treeView1)
			{
				this.contextMenu1.MenuItems.Clear();
				this.contextMenu1.MenuItems.Add("刷新",new EventHandler(this.Break_bt_Click));
				this.contextMenu1.MenuItems.Add("-");
				this.contextMenu1.MenuItems.Add("添加部门",new EventHandler(this.Insersub_bt_Click));
				this.contextMenu1.MenuItems.Add("删除部门",new EventHandler(this.delete_bt_Click));
				this.contextMenu1.MenuItems.Add("修改部门",new EventHandler(this.update_dt_click));
				this.contextMenu1.MenuItems.Add("-");
				this.contextMenu1.MenuItems.Add("退出",new EventHandler(this.close_bt_Click));
			}
		}
		#endregion

		#region 按下功能按钮时获取按钮的坐标,并显示菜单
		private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(e.Button == MouseButtons.Left)
			{
			    Point pos = new Point(e.X,e.Y);
				this.contextMenu1.Show(this.button1,pos);
			}
		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -