?? 副本 addcollegeform.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 + -