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

📄 addlevelform.cs

📁 《数据库原理及应用》-刘玉宝主编-源代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;

namespace KTMIS
{
	/// <summary>
	/// AddLevel 的摘要说明。
	/// </summary>
	public class AddLevel : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.TextBox LevelCoTextBox;
		private System.Windows.Forms.Button returnBtn;
		internal System.Windows.Forms.Button add_updateLevelBtn;
		internal System.Windows.Forms.TextBox LevelSNPYtextBox;
		private System.Windows.Forms.Label LevelSNPYlabel;
		internal System.Windows.Forms.TextBox LevelSNtextBox;
		private System.Windows.Forms.Label LevelSNlabel;

		private SqlConnection LevelConnection = null;
		private SqlCommand LevelCommand = null;
		private ArrayList arrayList = null;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public AddLevel()
		{
			//
			// 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.LevelCoTextBox = new System.Windows.Forms.TextBox();
			this.returnBtn = new System.Windows.Forms.Button();
			this.add_updateLevelBtn = new System.Windows.Forms.Button();
			this.LevelSNPYtextBox = new System.Windows.Forms.TextBox();
			this.LevelSNPYlabel = new System.Windows.Forms.Label();
			this.LevelSNtextBox = new System.Windows.Forms.TextBox();
			this.LevelSNlabel = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// LevelCoTextBox
			// 
			this.LevelCoTextBox.Location = new System.Drawing.Point(472, 72);
			this.LevelCoTextBox.Name = "LevelCoTextBox";
			this.LevelCoTextBox.Size = new System.Drawing.Size(88, 30);
			this.LevelCoTextBox.TabIndex = 19;
			this.LevelCoTextBox.Text = "";
			this.LevelCoTextBox.Visible = false;
			// 
			// returnBtn
			// 
			this.returnBtn.Location = new System.Drawing.Point(376, 256);
			this.returnBtn.Name = "returnBtn";
			this.returnBtn.Size = new System.Drawing.Size(144, 56);
			this.returnBtn.TabIndex = 18;
			this.returnBtn.Text = "返回";
			this.returnBtn.Click += new System.EventHandler(this.returnBtn_Click);
			// 
			// add_updateLevelBtn
			// 
			this.add_updateLevelBtn.Location = new System.Drawing.Point(144, 256);
			this.add_updateLevelBtn.Name = "add_updateLevelBtn";
			this.add_updateLevelBtn.Size = new System.Drawing.Size(144, 56);
			this.add_updateLevelBtn.TabIndex = 17;
			this.add_updateLevelBtn.Text = "添加";
			this.add_updateLevelBtn.Click += new System.EventHandler(this.add_updateLevelBtn_Click);
			// 
			// LevelSNPYtextBox
			// 
			this.LevelSNPYtextBox.Location = new System.Drawing.Point(296, 128);
			this.LevelSNPYtextBox.Name = "LevelSNPYtextBox";
			this.LevelSNPYtextBox.Size = new System.Drawing.Size(200, 30);
			this.LevelSNPYtextBox.TabIndex = 16;
			this.LevelSNPYtextBox.Text = "";
			// 
			// LevelSNPYlabel
			// 
			this.LevelSNPYlabel.Location = new System.Drawing.Point(24, 112);
			this.LevelSNPYlabel.Name = "LevelSNPYlabel";
			this.LevelSNPYlabel.Size = new System.Drawing.Size(224, 96);
			this.LevelSNPYlabel.TabIndex = 15;
			this.LevelSNPYlabel.Text = "请输入级别名称的拼音的缩写(如:每个字拼音的第一个字母大写组合):";
			// 
			// LevelSNtextBox
			// 
			this.LevelSNtextBox.Location = new System.Drawing.Point(296, 16);
			this.LevelSNtextBox.Name = "LevelSNtextBox";
			this.LevelSNtextBox.Size = new System.Drawing.Size(200, 30);
			this.LevelSNtextBox.TabIndex = 14;
			this.LevelSNtextBox.Text = "";
			// 
			// LevelSNlabel
			// 
			this.LevelSNlabel.Location = new System.Drawing.Point(32, 16);
			this.LevelSNlabel.Name = "LevelSNlabel";
			this.LevelSNlabel.Size = new System.Drawing.Size(216, 40);
			this.LevelSNlabel.TabIndex = 13;
			this.LevelSNlabel.Text = "请输入级别的名称:";
			// 
			// AddLevel
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(11, 23);
			this.ClientSize = new System.Drawing.Size(608, 350);
			this.Controls.Add(this.LevelCoTextBox);
			this.Controls.Add(this.returnBtn);
			this.Controls.Add(this.add_updateLevelBtn);
			this.Controls.Add(this.LevelSNPYtextBox);
			this.Controls.Add(this.LevelSNPYlabel);
			this.Controls.Add(this.LevelSNtextBox);
			this.Controls.Add(this.LevelSNlabel);
			this.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.Name = "AddLevel";
			this.Text = "添加级别";
			this.ResumeLayout(false);

		}
		#endregion

		private void add_updateLevelBtn_Click(object sender, System.EventArgs e)
		{
			//string connString = "user id=sa;data source=\".\";initial catalog=KTMIS";
			//LevelConnection = new SqlConnection(connString);
			if(add_updateLevelBtn.Text == "添加")
			{
				LevelCommand = new SqlCommand("InsertLevel",LevelConnection);
				LevelCommand.CommandType = CommandType.StoredProcedure;
				LevelCommand.Parameters.Add("@LevelCo",SqlDbType.Int);
				LevelCommand.Parameters.Add("@LevelNa",SqlDbType.VarChar,10);
				LevelCommand.Parameters.Add("@LevelPY",SqlDbType.VarChar,5);
				LevelCommand.Parameters["@LevelCo"].Direction = System.Data.ParameterDirection.Output;
				LevelCommand.Parameters["@LevelNa"].Value = LevelSNtextBox.Text.ToString().Trim();
				LevelCommand.Parameters["@LevelPY"].Value = LevelSNPYtextBox.Text.ToString().Trim();
				try
				{
					LevelConnection.Open();
					LevelCommand.ExecuteNonQuery();

					arrayList = new ArrayList();
					arrayList.Add(LevelCommand.Parameters["@LevelCo"].Value);
					arrayList.Add(LevelSNtextBox.Text.ToString().Trim());
					MessageBox.Show("添加成功!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
				catch(Exception ex)
				{
					MessageBox.Show("添加失败,原因是:"+ex.ToString(),"系统提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
				}
				finally
				{
					LevelConnection.Close();
				}
				
			}
			else if(add_updateLevelBtn.Text == "修改")
			{
				LevelCommand = new SqlCommand("UpdateLevel",LevelConnection);
				LevelCommand.CommandType = CommandType.StoredProcedure;
				LevelCommand.Parameters.Add("@LevelCo",SqlDbType.Int);
				LevelCommand.Parameters.Add("@LevelNa",SqlDbType.VarChar,10);
				LevelCommand.Parameters.Add("@LevelPY",SqlDbType.VarChar,5);
				LevelCommand.Parameters["@LevelCo"].Value = Convert.ToInt16(LevelCoTextBox.Text.ToString().Trim());
				LevelCommand.Parameters["@LevelNa"].Value = LevelSNtextBox.Text.ToString().Trim();
				LevelCommand.Parameters["@LevelPY"].Value = LevelSNPYtextBox.Text.ToString().Trim();
				try
				{
					LevelConnection.Open();
					LevelCommand.ExecuteNonQuery();
					MessageBox.Show("修改成功!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
				catch(Exception ex)
				{
					MessageBox.Show("修改失败,原因是:"+ex.ToString(),"系统提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
				}
				finally
				{
					LevelConnection.Close();
				}
				
				
			}
		}

		public ArrayList GetArrayList()
		{
			return arrayList;
		}

		public void SetLevelSNText(string text)
		{
			LevelSNtextBox.Text = text;
		}

		public void SetLevelCoText(string text)
		{
			LevelCoTextBox.Text = text;
		}

		public void SetLevelSNPYText(string text)
		{
			LevelSNPYtextBox.Text = text;
		}

		public void SetFormTital(string tital)
		{
			this.Text = tital;
		}

		public void SetLevelBtnText(string text)
		{
			add_updateLevelBtn.Text = text;
		}

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

		public System.Data.SqlClient.SqlConnection Connection
		{
			set
			{
				this.LevelConnection = value;
			}
		}
	}
}

⌨️ 快捷键说明

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