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

📄 formadddepartment.cs

📁 蓝山人事管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Security .Cryptography ;

namespace BlueHill.BlueHillWindows.DepartmentManagement
{
	/// <summary>
	/// FormAddDepartment 的摘要说明。
	/// </summary>
	public class FormAddDepartment : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button btnListEmployee;
		private System.Windows.Forms.TextBox txtManagerID;
		private System.Windows.Forms.TextBox txtDeptDescription;
		private System.Windows.Forms.Label MangerLb;
		private System.Windows.Forms.Label deptLb;
		private System.Windows.Forms.TextBox txtDeptName;
		private System.Windows.Forms.Label label1;
		private System.Data.SqlClient.SqlCommand cmdDepartment;
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		private System.Data.SqlClient.SqlCommand cmdIsExist;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormAddDepartment()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// 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.btnCancel = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnListEmployee = new System.Windows.Forms.Button();
			this.txtManagerID = new System.Windows.Forms.TextBox();
			this.txtDeptDescription = new System.Windows.Forms.TextBox();
			this.MangerLb = new System.Windows.Forms.Label();
			this.deptLb = new System.Windows.Forms.Label();
			this.txtDeptName = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.cmdDepartment = new System.Data.SqlClient.SqlCommand();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.cmdIsExist = new System.Data.SqlClient.SqlCommand();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(280, 264);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 9;
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(168, 264);
			this.btnOK.Name = "btnOK";
			this.btnOK.TabIndex = 8;
			this.btnOK.Text = "确定";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.btnListEmployee);
			this.groupBox1.Controls.Add(this.txtManagerID);
			this.groupBox1.Controls.Add(this.txtDeptDescription);
			this.groupBox1.Controls.Add(this.MangerLb);
			this.groupBox1.Controls.Add(this.deptLb);
			this.groupBox1.Location = new System.Drawing.Point(8, 64);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(342, 184);
			this.groupBox1.TabIndex = 7;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "部门信息";
			// 
			// btnListEmployee
			// 
			this.btnListEmployee.Location = new System.Drawing.Point(192, 112);
			this.btnListEmployee.Name = "btnListEmployee";
			this.btnListEmployee.Size = new System.Drawing.Size(32, 23);
			this.btnListEmployee.TabIndex = 4;
			this.btnListEmployee.Text = "...";
			this.btnListEmployee.Click += new System.EventHandler(this.btnListEmployee_Click);
			// 
			// txtManagerID
			// 
			this.txtManagerID.Location = new System.Drawing.Point(104, 112);
			this.txtManagerID.Name = "txtManagerID";
			this.txtManagerID.ReadOnly = true;
			this.txtManagerID.Size = new System.Drawing.Size(72, 21);
			this.txtManagerID.TabIndex = 3;
			this.txtManagerID.Text = "";
			// 
			// txtDeptDescription
			// 
			this.txtDeptDescription.AutoSize = false;
			this.txtDeptDescription.Location = new System.Drawing.Point(104, 32);
			this.txtDeptDescription.Name = "txtDeptDescription";
			this.txtDeptDescription.Size = new System.Drawing.Size(200, 48);
			this.txtDeptDescription.TabIndex = 2;
			this.txtDeptDescription.Text = "";
			// 
			// MangerLb
			// 
			this.MangerLb.Location = new System.Drawing.Point(24, 112);
			this.MangerLb.Name = "MangerLb";
			this.MangerLb.Size = new System.Drawing.Size(48, 23);
			this.MangerLb.TabIndex = 1;
			this.MangerLb.Text = "经理";
			// 
			// deptLb
			// 
			this.deptLb.Location = new System.Drawing.Point(16, 32);
			this.deptLb.Name = "deptLb";
			this.deptLb.Size = new System.Drawing.Size(56, 23);
			this.deptLb.TabIndex = 0;
			this.deptLb.Text = "部门描述";
			// 
			// txtDeptName
			// 
			this.txtDeptName.Location = new System.Drawing.Point(106, 21);
			this.txtDeptName.Name = "txtDeptName";
			this.txtDeptName.Size = new System.Drawing.Size(160, 21);
			this.txtDeptName.TabIndex = 6;
			this.txtDeptName.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(34, 21);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 5;
			this.label1.Text = "部门名称";
			// 
			// cmdDepartment
			// 
			this.cmdDepartment.CommandText = "dbo.[spwinCreateDepartment]";
			this.cmdDepartment.CommandType = System.Data.CommandType.StoredProcedure;
			this.cmdDepartment.Connection = this.sqlConnection1;
			this.cmdDepartment.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));
			this.cmdDepartment.Parameters.Add(new System.Data.SqlClient.SqlParameter("@DeptName", System.Data.SqlDbType.NVarChar, 10));
			this.cmdDepartment.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Description", System.Data.SqlDbType.NVarChar, 50));
			this.cmdDepartment.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ManagerID", System.Data.SqlDbType.Int, 4));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=Stuffbe;packet size=4096;integrated security=SSPI;initial catalog=" +
				"BlueHill;persist security info=False";
			// 
			// cmdIsExist
			// 
			this.cmdIsExist.Connection = this.sqlConnection1;
			// 
			// FormAddDepartment
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(376, 293);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.txtDeptName);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "FormAddDepartment";
			this.Text = "创建部门";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnOK_Click(object sender, System.EventArgs e)
		{	
			try 
			{			
				
				this.cmdIsExist.CommandText="select count(*) from tblDepartment where DeptName='";
				this.cmdIsExist.CommandText+=this.txtDeptName.Text.Trim();
				this.cmdIsExist.CommandText+="'";
				this.cmdIsExist.Connection.Open();
				
				if (0<(int)this.cmdIsExist.ExecuteScalar()) 
				{
					this.cmdIsExist.Connection.Close();
					MessageBox.Show("同名部门已经存在","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
					return;
				}
				this.cmdIsExist.Connection.Close();
					
				
				this.cmdDepartment.Connection.Open();
				this.cmdDepartment.Parameters["@DeptName"].Value=this.txtDeptName.Text.Trim();
				this.cmdDepartment.Parameters["@Description"].Value=this.txtDeptDescription.Text;
				this.cmdDepartment.Parameters["@ManagerID"].Value=int.Parse(this.txtManagerID.Text.Trim());
				this.cmdDepartment.ExecuteNonQuery();
				MessageBox.Show ("添加部门成功");
			}
			catch 
			{
				MessageBox.Show("创建新部门失败","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
			finally 
			{
				this.cmdDepartment.Connection.Close();
				this.cmdIsExist.Connection.Close();
				this.Close();
			}

		}	

		private void btnListEmployee_Click(object sender, System.EventArgs e)
		{
			FormEmpList frm5=new FormEmpList();
			frm5.ShowDialog();
			this.txtManagerID.Text=frm5.managerID.ToString();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

⌨️ 快捷键说明

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