?? addsortform.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 + -