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

📄 department.cs

📁 医院系统管理
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Hospital_Manage
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class frmDepartment : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblDep;
		private System.Windows.Forms.Label lblAddress;
		private System.Windows.Forms.Label lblTel;
		private System.Windows.Forms.TextBox tbDepName;
		private System.Windows.Forms.TextBox tbAddress;
		private System.Windows.Forms.TextBox tbTel;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnDelete;
		private System.Windows.Forms.Button btnModify;
		//声明类变量
		private string insCmd;
		private string delCmd;
		private string modCmd;
		
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmDepartment()
		{
			//
			// 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.lblDep = new System.Windows.Forms.Label();
			this.lblAddress = new System.Windows.Forms.Label();
			this.lblTel = new System.Windows.Forms.Label();
			this.tbDepName = new System.Windows.Forms.TextBox();
			this.tbAddress = new System.Windows.Forms.TextBox();
			this.tbTel = new System.Windows.Forms.TextBox();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnDelete = new System.Windows.Forms.Button();
			this.btnModify = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// lblDep
			// 
			this.lblDep.AutoSize = true;
			this.lblDep.Location = new System.Drawing.Point(24, 32);
			this.lblDep.Name = "lblDep";
			this.lblDep.Size = new System.Drawing.Size(42, 17);
			this.lblDep.TabIndex = 0;
			this.lblDep.Text = "科名:";
			// 
			// lblAddress
			// 
			this.lblAddress.AutoSize = true;
			this.lblAddress.Location = new System.Drawing.Point(24, 88);
			this.lblAddress.Name = "lblAddress";
			this.lblAddress.Size = new System.Drawing.Size(42, 17);
			this.lblAddress.TabIndex = 1;
			this.lblAddress.Text = "位置:";
			// 
			// lblTel
			// 
			this.lblTel.AutoSize = true;
			this.lblTel.Location = new System.Drawing.Point(264, 32);
			this.lblTel.Name = "lblTel";
			this.lblTel.Size = new System.Drawing.Size(42, 17);
			this.lblTel.TabIndex = 2;
			this.lblTel.Text = "电话:";
			// 
			// tbDepName
			// 
			this.tbDepName.Location = new System.Drawing.Point(80, 32);
			this.tbDepName.Name = "tbDepName";
			this.tbDepName.Size = new System.Drawing.Size(168, 21);
			this.tbDepName.TabIndex = 3;
			this.tbDepName.Text = "";
			this.tbDepName.TextChanged += new System.EventHandler(this.tbDepName_TextChanged);
			// 
			// tbAddress
			// 
			this.tbAddress.Location = new System.Drawing.Point(80, 88);
			this.tbAddress.Name = "tbAddress";
			this.tbAddress.Size = new System.Drawing.Size(336, 21);
			this.tbAddress.TabIndex = 4;
			this.tbAddress.Text = "";
			// 
			// tbTel
			// 
			this.tbTel.Location = new System.Drawing.Point(320, 32);
			this.tbTel.Name = "tbTel";
			this.tbTel.TabIndex = 5;
			this.tbTel.Text = "";
			// 
			// btnAdd
			// 
			this.btnAdd.Location = new System.Drawing.Point(24, 152);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.TabIndex = 6;
			this.btnAdd.Text = "添加(&A)";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(352, 152);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 8;
			this.btnCancel.Text = "取消(&C)";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnDelete
			// 
			this.btnDelete.Location = new System.Drawing.Point(136, 152);
			this.btnDelete.Name = "btnDelete";
			this.btnDelete.TabIndex = 9;
			this.btnDelete.Text = "删除(&D)";
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			// 
			// btnModify
			// 
			this.btnModify.Location = new System.Drawing.Point(248, 152);
			this.btnModify.Name = "btnModify";
			this.btnModify.TabIndex = 10;
			this.btnModify.Text = "修改(&M)";
			this.btnModify.Click += new System.EventHandler(this.btnModify_Click);
			// 
			// frmDepartment
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(448, 197);
			this.Controls.Add(this.btnModify);
			this.Controls.Add(this.btnDelete);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.tbTel);
			this.Controls.Add(this.tbAddress);
			this.Controls.Add(this.tbDepName);
			this.Controls.Add(this.lblTel);
			this.Controls.Add(this.lblAddress);
			this.Controls.Add(this.lblDep);
			this.Name = "frmDepartment";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "科室信息管理";
			this.Load += new System.EventHandler(this.frmDepartment_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmDepartment());
		}

		private void frmDepartment_Load(object sender, System.EventArgs e)
		{
			this.btnDelete.Enabled=false;
			this.btnModify.Enabled=false;
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			if(checkInput())
			{
				insCmd="insert into departmentInfo values('"+this.tbDepName.Text.ToString()+"','"+this.tbAddress.Text.ToString()+"','"+this.tbTel.Text.ToString()+"')";
				CDataBase.ExecuteSql(insCmd);
				MessageBox.Show("已成功添加新科室!");
				this.tbDepName.Enabled=false;
				this.btnDelete.Enabled=true;
				this.btnModify.Enabled=true;
			}
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			delCmd="delete from departmentInfo where depName='"+this.tbDepName.Text.ToString()+"'";
			DialogResult objDialogResult=MessageBox.Show("确定要删除当前记录吗?","确定",MessageBoxButtons.YesNo);
			if(objDialogResult.Equals(DialogResult.Yes))
			{
				CDataBase.ExecuteSql(delCmd);
				MessageBox.Show("已删除记录!");
				this.btnModify.Enabled=false;
				this.btnDelete.Enabled=false;
				this.tbDepName.Enabled=true;
				this.tbDepName.Text="";
				this.tbAddress.Text="";
				this.tbTel.Text="";
			}
		}

		private void tbDepName_TextChanged(object sender, System.EventArgs e)
		{
			this.btnDelete.Enabled=true;
		}
		//检查文本框是否有输入
		private bool checkInput()
		{
			if(this.tbDepName.Text.Trim()==String.Empty||this.tbAddress.Text.Trim()==String.Empty||this.tbTel.Text.Trim()==String.Empty)
			{
				MessageBox.Show("输入框不能为空!");
				return false;
			}
			else
			{
				return true;
			}
		}

		private void btnModify_Click(object sender, System.EventArgs e)
		{
			if(checkInput())
			{
				modCmd="update departmentInfo set address='"+this.tbAddress.Text.ToString()+"',telephone='"+this.tbTel.Text.ToString()+"' where depName='"+this.tbDepName.Text.ToString()+"'";
				CDataBase.ExecuteSql(modCmd);
				MessageBox.Show("已成功修改该记录!");
			}
		}
	}
}

⌨️ 快捷键说明

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