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

📄 addcollegeform.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>
	/// AddCollege 的摘要说明。
	/// </summary>
	public class AddCollege : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button returnBtn;
		internal System.Windows.Forms.TextBox collegeCoTextBox;
		internal System.Windows.Forms.TextBox collegeSNtextBox;
		private System.Windows.Forms.Label collegeSNlabel;

		private SqlConnection collegeConnection = null;
		private SqlCommand collegeCommand = null;
		private ArrayList arrayList = null;
		private System.Windows.Forms.Button add_updatecollegeBtn;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public AddCollege()
		{
			//
			// 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.collegeCoTextBox = new System.Windows.Forms.TextBox();
			this.returnBtn = new System.Windows.Forms.Button();
			this.collegeSNtextBox = new System.Windows.Forms.TextBox();
			this.collegeSNlabel = new System.Windows.Forms.Label();
			this.add_updatecollegeBtn = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// collegeCoTextBox
			// 
			this.collegeCoTextBox.Location = new System.Drawing.Point(448, 112);
			this.collegeCoTextBox.Name = "collegeCoTextBox";
			this.collegeCoTextBox.Size = new System.Drawing.Size(88, 30);
			this.collegeCoTextBox.TabIndex = 24;
			this.collegeCoTextBox.Text = "";
			this.collegeCoTextBox.Visible = false;
			// 
			// returnBtn
			// 
			this.returnBtn.Location = new System.Drawing.Point(280, 160);
			this.returnBtn.Name = "returnBtn";
			this.returnBtn.Size = new System.Drawing.Size(160, 48);
			this.returnBtn.TabIndex = 23;
			this.returnBtn.Text = "返回";
			this.returnBtn.Click += new System.EventHandler(this.returnBtn_Click);
			// 
			// collegeSNtextBox
			// 
			this.collegeSNtextBox.Location = new System.Drawing.Point(328, 64);
			this.collegeSNtextBox.Name = "collegeSNtextBox";
			this.collegeSNtextBox.Size = new System.Drawing.Size(200, 30);
			this.collegeSNtextBox.TabIndex = 21;
			this.collegeSNtextBox.Text = "";
			// 
			// collegeSNlabel
			// 
			this.collegeSNlabel.Location = new System.Drawing.Point(40, 64);
			this.collegeSNlabel.Name = "collegeSNlabel";
			this.collegeSNlabel.Size = new System.Drawing.Size(288, 40);
			this.collegeSNlabel.TabIndex = 20;
			this.collegeSNlabel.Text = "请输入所要添加的学院名称:";
			// 
			// add_updatecollegeBtn
			// 
			this.add_updatecollegeBtn.Location = new System.Drawing.Point(80, 160);
			this.add_updatecollegeBtn.Name = "add_updatecollegeBtn";
			this.add_updatecollegeBtn.Size = new System.Drawing.Size(160, 48);
			this.add_updatecollegeBtn.TabIndex = 25;
			this.add_updatecollegeBtn.Text = "添加";
			this.add_updatecollegeBtn.Click += new System.EventHandler(this.add_updatecollegeBtn_Click);
			// 
			// AddCollege
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(11, 23);
			this.ClientSize = new System.Drawing.Size(592, 318);
			this.Controls.Add(this.add_updatecollegeBtn);
			this.Controls.Add(this.collegeCoTextBox);
			this.Controls.Add(this.returnBtn);
			this.Controls.Add(this.collegeSNtextBox);
			this.Controls.Add(this.collegeSNlabel);
			this.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.Name = "AddCollege";
			this.Text = "添加学院";
			this.ResumeLayout(false);

		}
		#endregion


		public ArrayList GetArrayList()
		{
			return arrayList;
		}

		public void SetcollegeSNText(string text)
		{
			collegeSNtextBox.Text = text;
		}

		public void SetcollegeCoText(string text)
		{
			collegeCoTextBox.Text = text;
		}


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

		public void SetcollegeBtnText(string text)
		{
			add_updatecollegeBtn.Text = text;
		}

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

		private void add_updatecollegeBtn_Click(object sender, System.EventArgs e)
		{
			//string connString = "user id=sa;data source=\".\";initial catalog=KTMIS";
			//collegeConnection = new SqlConnection(connString);
			if(add_updatecollegeBtn.Text == "添加")
			{
				collegeCommand = new SqlCommand("InsertCollege",collegeConnection);
				collegeCommand.CommandType = CommandType.StoredProcedure;
				collegeCommand.Parameters.Add("@CollegeCo",SqlDbType.Int);
				collegeCommand.Parameters.Add("@CollegeNa",SqlDbType.VarChar,20);
				collegeCommand.Parameters["@CollegeCo"].Direction = System.Data.ParameterDirection.Output;
				collegeCommand.Parameters["@CollegeNa"].Value = collegeSNtextBox.Text.ToString().Trim();
				try
				{
					collegeConnection.Open();
					collegeCommand.ExecuteNonQuery();

					MessageBox.Show("添加成功!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);

					arrayList = new ArrayList();
					arrayList.Add(collegeCommand.Parameters["@CollegeCo"].Value);
					arrayList.Add(collegeSNtextBox.Text.ToString().Trim());

				}
				catch(Exception ex)
				{
					MessageBox.Show("添加失败,原因是:"+ex.ToString(),"系统提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
				}
				finally
				{
					collegeConnection.Close();
				}
			}
			else if(add_updatecollegeBtn.Text == "修改")
			{
				collegeCommand = new SqlCommand("UpdateCollege",collegeConnection);
				collegeCommand.CommandType = CommandType.StoredProcedure;
				collegeCommand.Parameters.Add("@CollegeCo",SqlDbType.Int);
				collegeCommand.Parameters.Add("@CollegeNa",SqlDbType.VarChar,20);
				collegeCommand.Parameters["@CollegeCo"].Value = Convert.ToInt16(collegeCoTextBox.Text.ToString().Trim());
				collegeCommand.Parameters["@CollegeNa"].Value = collegeSNtextBox.Text.ToString().Trim();
				try
				{
					collegeConnection.Open();
					collegeCommand.ExecuteNonQuery();
					MessageBox.Show("修改成功!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
				catch(Exception ex)
				{
					MessageBox.Show("修改失败,原因是:"+ex.ToString(),"系统提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
				}
				finally
				{
					collegeConnection.Close();
				}
				
			}
		}

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

⌨️ 快捷键说明

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