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

📄 副本 addsortform.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>
	/// addSort 的摘要说明。
	/// </summary>
	public class addSort : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button returnBtn;
		internal System.Windows.Forms.Button add_updateBtn;
		internal System.Windows.Forms.TextBox SNPYtextBox;
		private System.Windows.Forms.Label SNPYlabel;
		internal System.Windows.Forms.TextBox SNtextBox;
		private System.Windows.Forms.Label SNlabel;
		internal System.Windows.Forms.TextBox SortCo;

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

		public addSort()
		{
			//
			// 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.returnBtn = new System.Windows.Forms.Button();
			this.add_updateBtn = new System.Windows.Forms.Button();
			this.SNPYtextBox = new System.Windows.Forms.TextBox();
			this.SNPYlabel = new System.Windows.Forms.Label();
			this.SNtextBox = new System.Windows.Forms.TextBox();
			this.SNlabel = new System.Windows.Forms.Label();
			this.SortCo = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// returnBtn
			// 
			this.returnBtn.Location = new System.Drawing.Point(456, 279);
			this.returnBtn.Name = "returnBtn";
			this.returnBtn.Size = new System.Drawing.Size(144, 56);
			this.returnBtn.TabIndex = 11;
			this.returnBtn.Text = "返回";
			this.returnBtn.Click += new System.EventHandler(this.returnBtn_Click);
			// 
			// add_updateBtn
			// 
			this.add_updateBtn.Location = new System.Drawing.Point(224, 279);
			this.add_updateBtn.Name = "add_updateBtn";
			this.add_updateBtn.Size = new System.Drawing.Size(144, 56);
			this.add_updateBtn.TabIndex = 10;
			this.add_updateBtn.Text = "添加";
			this.add_updateBtn.Click += new System.EventHandler(this.add_updateBtn_Click);
			// 
			// SNPYtextBox
			// 
			this.SNPYtextBox.Location = new System.Drawing.Point(376, 151);
			this.SNPYtextBox.Name = "SNPYtextBox";
			this.SNPYtextBox.Size = new System.Drawing.Size(200, 30);
			this.SNPYtextBox.TabIndex = 9;
			this.SNPYtextBox.Text = "";
			// 
			// SNPYlabel
			// 
			this.SNPYlabel.Location = new System.Drawing.Point(104, 128);
			this.SNPYlabel.Name = "SNPYlabel";
			this.SNPYlabel.Size = new System.Drawing.Size(224, 96);
			this.SNPYlabel.TabIndex = 8;
			this.SNPYlabel.Text = "请输入分类名称的拼音的缩写(如:每个字拼音的第一个字母大写组合):";
			// 
			// SNtextBox
			// 
			this.SNtextBox.Location = new System.Drawing.Point(376, 39);
			this.SNtextBox.Name = "SNtextBox";
			this.SNtextBox.Size = new System.Drawing.Size(200, 30);
			this.SNtextBox.TabIndex = 7;
			this.SNtextBox.Text = "";
			// 
			// SNlabel
			// 
			this.SNlabel.Location = new System.Drawing.Point(112, 39);
			this.SNlabel.Name = "SNlabel";
			this.SNlabel.Size = new System.Drawing.Size(216, 40);
			this.SNlabel.TabIndex = 6;
			this.SNlabel.Text = "请输入分类的名称:";
			// 
			// SortCo
			// 
			this.SortCo.Location = new System.Drawing.Point(552, 88);
			this.SortCo.Name = "SortCo";
			this.SortCo.Size = new System.Drawing.Size(88, 30);
			this.SortCo.TabIndex = 12;
			this.SortCo.Text = "";
			this.SortCo.Visible = false;
			// 
			// addSort
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(11, 23);
			this.ClientSize = new System.Drawing.Size(704, 374);
			this.Controls.Add(this.SortCo);
			this.Controls.Add(this.returnBtn);
			this.Controls.Add(this.add_updateBtn);
			this.Controls.Add(this.SNPYtextBox);
			this.Controls.Add(this.SNPYlabel);
			this.Controls.Add(this.SNtextBox);
			this.Controls.Add(this.SNlabel);
			this.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.Name = "addSort";
			this.Text = "添加分类";
			this.ResumeLayout(false);

		}
		#endregion

		private void add_updateBtn_Click(object sender, System.EventArgs e)
		{
			//string connString = "user id=sa;data source=\".\";initial catalog=KTMIS";
			//SortConnection = new SqlConnection(connString);
			if(add_updateBtn.Text == "添加")
			{
				SortCommand = new SqlCommand("InsertSort",SortConnection);
				SortCommand.CommandType = CommandType.StoredProcedure;
				SortCommand.Parameters.Add("@SortCo",SqlDbType.Int);
				SortCommand.Parameters.Add("@SortNa",SqlDbType.VarChar,10);
				SortCommand.Parameters.Add("@SortPY",SqlDbType.VarChar,5);
				SortCommand.Parameters["@SortCo"].Direction = System.Data.ParameterDirection.Output;
				SortCommand.Parameters["@SortNa"].Value = SNtextBox.Text.ToString().Trim();
				SortCommand.Parameters["@SortPY"].Value = SNPYtextBox.Text.ToString().Trim();
				try
				{
					SortConnection.Open();
					SortCommand.ExecuteNonQuery();

					arrayList = new ArrayList();
					arrayList.Add(SortCommand.Parameters["@SortCo"].Value);
					arrayList.Add(SNtextBox.Text.ToString().Trim());

					MessageBox.Show("添加成功!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
				catch(Exception ex)
				{
					MessageBox.Show("添加失败,原因是:"+ex.ToString(),"系统提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
				}
				finally
				{
					SortConnection.Close();
				}
				
			}
			else if(add_updateBtn.Text == "修改")
			{
				SortCommand = new SqlCommand("UpdateSort",SortConnection);
				SortCommand.CommandType = CommandType.StoredProcedure;
				SortCommand.Parameters.Add("@SortCo",SqlDbType.Int);
				SortCommand.Parameters.Add("@SortNa",SqlDbType.VarChar,10);
				SortCommand.Parameters.Add("@SortPY",SqlDbType.VarChar,5);
				SortCommand.Parameters["@SortCo"].Value = Convert.ToInt16(SortCo.Text.ToString().Trim());
				SortCommand.Parameters["@SortNa"].Value = SNtextBox.Text.ToString().Trim();
				SortCommand.Parameters["@SortPY"].Value = SNPYtextBox.Text.ToString().Trim();
				try
				{
					SortConnection.Open();
					SortCommand.ExecuteNonQuery();
					MessageBox.Show("修改成功!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
				catch(Exception ex)
				{
					MessageBox.Show("修改失败,原因是:"+ex.ToString(),"系统提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
				}
				finally
				{
					SortConnection.Close();
				}
				
				
			}
		}

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

		public ArrayList GetArrayList()
		{
			return arrayList;
		}

		public void SetSNText(string text)
		{
			SNtextBox.Text = text;
		}

		public void SetSortCoText(string text)
		{
			SortCo.Text = text;
		}

		public void SetSNPYText(string text)
		{
			SNPYtextBox.Text = text;
		}

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

		public void SetBtnText(string text)
		{
			add_updateBtn.Text = text;
		}

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

⌨️ 快捷键说明

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