LoginForm.cs
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data .SqlClient ;
namespace WindowsApplication2
...{
/**//// <summary>
/// Form1 的摘要說明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlCommand sqlCommand1;
/**//// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
...{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調用後添加任何構造函數代碼
//
}
/**//// <summary>
/// 清理所有正在使用的資源。
/// </summary>
static void Main()
...{
Form1 f=new Form1();
f.ShowDialog();
if(Form1.ShowForm==true)
...{
Application.Run(new MainForm());
}
}
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗體設計器生成的代碼#region Windows 窗體設計器生成的代碼
/**//// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
...{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 176);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "登入";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(128, 176);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "取消";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(104, 56);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(104, 120);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 23);
this.label1.TabIndex = 4;
this.label1.Text = "用戶名:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 120);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 16);
this.label2.TabIndex = 5;
this.label2.Text = "密碼:";
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id="W3-34";packet size=4096;user id=sa;data source="(local)";persist " +
"security info=False;initial catalog=DB";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(240, 229);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "LoginForm";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
public static bool ShowForm=false;
/**//// <summary>
/// 應用程序的主入口點。
/// </summary>
[STAThread]
private void button1_Click(object sender, System.EventArgs e)
...{
if (this.textBox1 .Text.ToString () =="" |this.textBox2 .Text.ToString () =="")
...{
MessageBox.Show ("請把您的帳號和密碼輸入完整!");
}
else
...{
try
...{
sqlCommand1=new SqlCommand ();
sqlCommand1.Connection =sqlConnection1;
this.sqlCommand1.CommandText="SELECT PWD FROM usertable WHERE userid='"+this.textBox1 .Text .ToString ().Trim ()+"'";
this.sqlConnection1 .Open ();
SqlDataReader
reader= sqlCommand1.ExecuteReader ();
reader.Read ();
string textpwd=reader.GetString (0);
if (this.textBox2 .Text .ToString ().Trim ()==textpwd.Trim ())
...{
ShowForm=true;
this.Close ();
}
else
...{
MessageBox.Show ("密碼輸入錯誤!");
ShowForm=false;
}
}
catch(System.Exception)
...{
MessageBox.Show ("沒有該用戶", "錯誤",MessageBoxButtons.OK ,MessageBoxIcon.Error );
}
}
this.sqlConnection1 .Close ();
}
private void Form1_Load(object sender, System.EventArgs e)
...{
}
}
}
Mainform .cs
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 圖書管理
...{
/**//// <summary>
/// Form1 的摘要說明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton tBtnFirst;
private System.Windows.Forms.ToolBarButton tBtnPre;
private System.Windows.Forms.ToolBarButton tBtnNext;
private System.Windows.Forms.ToolBarButton tBtnLast;
private System.Windows.Forms.ToolBarButton tBtnNew;
private System.Windows.Forms.ToolBarButton tBtnEdit;
private System.Windows.Forms.ToolBarButton tBtnDelete;
private System.Windows.Forms.ToolBarButton tBtnSubmit;
private System.Windows.Forms.ToolBarButton tBtnCancel;
private System.Windows.Forms.ToolBarButton tBtnQuit;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.TextBox txt1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txt2;
private System.Windows.Forms.TextBox txt3;
private System.Windows.Forms.TextBox txt4;
private System.Windows.Forms.TextBox txt5;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private 圖書管理.DataSet1 dataSet11;
private System.Windows.Forms.ImageList imageList1;
private CurrencyManager cmOrders;//數據導航
public string EditOrAdd="";
public Form1()
...{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調用後添加任何構造函數代碼
//
}
/**//// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗體設計器生成的代碼#region Windows 窗體設計器生成的代碼
/**//// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
...{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.tBtnFirst = new System.Windows.Forms.ToolBarButton();
this.tBtnPre = new System.Windows.Forms.ToolBarButton();
this.tBtnNext = new System.Windows.Forms.ToolBarButton();
this.tBtnLast = new System.Windows.Forms.ToolBarButton();
this.tBtnNew = new System.Windows.Forms.ToolBarButton();
this.tBtnEdit = new System.Windows.Forms.ToolBarButton();
this.tBtnDelete = new System.Windows.Forms.ToolBarButton();
this.tBtnSubmit = new System.Windows.Forms.ToolBarButton();
this.tBtnCancel = new System.Windows.Forms.ToolBarButton();
this.tBtnQuit = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.btnSearch = new System.Windows.Forms.Button();
this.txt1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet11 = new 圖書管理.DataSet1();
this.label1 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.txt2 = new System.Windows.Forms.TextBox();
this.txt3 = new System.Windows.Forms.TextBox();
this.txt4 = new System.Windows.Forms.TextBox();
this.txt5 = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] ...{
this.tBtnFirst,
this.tBtnPre,
this.tBtnNext,
this.tBtnLast,
this.tBtnNew,
this.tBtnEdit,
this.tBtnDelete,
this.tBtnSubmit,
this.tBtnCancel,
this.tBtnQuit});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(568, 41);
this.toolBar1.TabIndex = 32;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// tBtnFirst
//
this.tBtnFirst.ImageIndex = 0;
this.tBtnFirst.Text = "首記錄";
this.tBtnFirst.ToolTipText = "首記錄";
//
// tBtnPre
//
this.tBtnPre.ImageIndex = 1;
this.tBtnPre.Text = "上一記錄";
this.tBtnPre.ToolTipText = "上一記錄";
//
// tBtnNext
//
this.tBtnNext.ImageIndex = 2;
this.tBtnNext.Text = "下一記錄";
this.tBtnNext.ToolTipText = "下一記錄";
//
// tBtnLast
//
this.tBtnLast.ImageIndex = 3;
this.tBtnLast.Text = "尾記錄";
this.tBtnLast.ToolTipText = "尾記錄";
//
// tBtnNew
//
this.tBtnNew.ImageIndex = 4;
this.tBtnNew.Text = "新增";
this.tBtnNew.ToolTipText = "新增";
//
// tBtnEdit
//
this.tBtnEdit.ImageIndex = 5;
this.tBtnEdit.Text = "修改";
this.tBtnEdit.ToolTipText = "修改";
//
// tBtnDelete
//
this.tBtnDelete.ImageIndex = 6;
this.tBtnDelete.Text = "刪除";
this.tBtnDelete.ToolTipText = "刪除";
//
// tBtnSubmit
//
this.tBtnSubmit.ImageIndex = 7;
this.tBtnSubmit.Text = "提交";
this.tBtnSubmit.ToolTipText = "提交";
//
// tBtnCancel
//
this.tBtnCancel.ImageIndex = 8;
this.tBtnCancel.Text = "取消";
this.tBtnCancel.ToolTipText = "取消";
//
// tBtnQuit
//
this.tBtnQuit.ImageIndex = 9;
this.tBtnQuit.Text = "退出";
this.tBtnQuit.ToolTipText = "退出";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.SystemColors.ControlLightLight;
//
// btnSearch
//
this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnSearch.Location = new System.Drawing.Point(16, 48);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(72, 23);
this.btnSearch.TabIndex = 33;
this.btnSearch.Text = " 搜索";
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// txt1
//
this.txt1.Location = new System.Drawing.Point(168, 48);
this.txt1.Name = "txt1";
this.txt1.TabIndex = 34;
this.txt1.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(112, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 35;
this.label2.Text = "讀者類型";
//
// dataGrid1
//
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.DataSource = this.dataSet11.讀者類型;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 80);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(552, 216);
this.dataGrid1.TabIndex = 36;
this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 336);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 37;
this.label1.Text = "讀者類型";
//
// label3
//
this.label3.Location = new System.Drawing.Point(112, 336);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 16);
this.label3.TabIndex = 38;
this.label3.Text = "可借圖書冊數";
//
// label4
//
this.label4.Location = new System.Drawing.Point(200, 336);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96, 16);
this.label4.TabIndex = 39;
this.label4.Text = "可借期刊冊數";
//
// label5
//
this.label5.Location = new System.Drawing.Point(296, 336);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(96, 16);
this.label5.TabIndex = 40;
this.label5.Text = "允許續借次數";
//
// txt2
//
this.txt2.Location = new System.Drawing.Point(8, 360);
this.txt2.Name = "txt2";
this.txt2.ReadOnly = true;
this.txt2.Size = new System.Drawing.Size(88, 21);
this.txt2.TabIndex = 41;
this.txt2.Text = "";
//
// txt3
//
this.txt3.Location = new System.Drawing.Point(112, 360);
this.txt3.Name = "txt3";
this.txt3.ReadOnly = true;
this.txt3.Size = new System.Drawing.Size(80, 21);
this.txt3.TabIndex = 42;
this.txt3.Text = "";
//
// txt4
//
this.txt4.Location = new System.Drawing.Point(200, 360);
this.txt4.Name = "txt4";
this.txt4.ReadOnly = true;
this.txt4.Size = new System.Drawing.Size(88, 21);
this.txt4.TabIndex = 43;
this.txt4.Text = "";
//
// txt5
//
this.txt5.Location = new System.Drawing.Point(296, 360);
this.txt5.Name = "txt5";
this.txt5.ReadOnly = true;
this.txt5.TabIndex = 44;
this.txt5.Text = "";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.checkBox2);
this.groupBox3.Controls.Add(this.checkBox1);
this.groupBox3.Location = new System.Drawing.Point(16, 400);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(472, 48);
this.groupBox3.TabIndex = 45;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "借閱範圍";
//
// checkBox2
//
this.checkBox2.Location = new System.Drawing.Point(256, 16);
this.checkBox2.Name = "checkBox2";
this.checkBox2.TabIndex = 0;
this.checkBox2.Text = "限制期刊";
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(88, 16);
this.checkBox1.Name = "checkBox1";
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "限制圖書";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] ...{
new System.Data.Common.DataTableMapping("Table", "讀者類型", new System.Data.Common.DataColumnMapping[] ...{
new System.Data.Common.DataColumnMapping("類型", "類型"),
new System.Data.Common.DataColumnMapping("圖書冊書", "圖書冊書"),
new System.Data.Common.DataColumnMapping("期刊冊書", "期刊冊書"),
new System.Data.Common.DataColumnMapping("續借次數", "續借次數"),
new System.Data.Common.DataColumnMapping("限制圖書", "限制圖書"),
new System.Data.Common.DataColumnMapping("限制期刊", "限制期刊")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM 讀者類型 WHERE (類型 = @Original_類型) AND (圖書冊書 = @Original_圖書冊書 OR @Original_圖書冊書 IS NULL AND 圖書冊書 IS NULL) AND (期刊冊書 = @Original_期刊冊書 OR @Original_期刊冊書 IS NULL AND 期刊冊書 IS NULL) AND (續借次數 = @Original_續借次數 OR @Original_續借次數 IS NULL AND 續借次數 IS NULL) AND (限制圖書 = @Original_限制圖書 OR @Original_限制圖書 IS NULL AND 限制圖書 IS NULL) AND (限制期刊 = @Original_限制期刊 OR @Original_限制期刊 IS NULL AND 限制期刊 IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_類型", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "類型", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_圖書冊書", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "圖書冊書", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_期刊冊書", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "期刊冊書", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_續借次數", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "續借次數", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制圖書", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制圖書", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制期刊", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制期刊", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id="W3-TEACHER";packet size=4096;integrated security=SSPI;data source" +
"="W3-TEACHER";persist security info=False;initial catalog=book";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 讀者類型(類型, 圖書冊書, 期刊冊書, 續借次數, 限制圖書, 限制期刊) VALUES (@類型, @圖書冊書, @期刊冊書, @續借" +
"次數, @限制圖書, @限制期刊); SELECT 類型, 圖書冊書, 期刊冊書, 續借次數, 限制圖書, 限制期刊 FROM 讀者類型 WHERE (類型 =" +
" @類型)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@類型", System.Data.SqlDbType.VarChar, 20, "類型"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@圖書冊書", System.Data.SqlDbType.SmallInt, 2, "圖書冊書"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@期刊冊書", System.Data.SqlDbType.SmallInt, 2, "期刊冊書"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@續借次數", System.Data.SqlDbType.Int, 4, "續借次數"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制圖書", System.Data.SqlDbType.Bit, 1, "限制圖書"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制期刊", System.Data.SqlDbType.Bit, 1, "限制期刊"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 類型, 圖書冊書, 期刊冊書, 續借次數, 限制圖書, 限制期刊 FROM 讀者類型 WHERE (類型 LIKE @parameter)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@parameter", System.Data.SqlDbType.VarChar, 20, "類型"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE 讀者類型 SET 類型 = @類型, 圖書冊書 = @圖書冊書, 期刊冊書 = @期刊冊書, 續借次數 = @續借次數, 限制圖書 = @限制圖書, 限制期刊 = @限制期刊 WHERE (類型 = @Original_類型) AND (圖書冊書 = @Original_圖書冊書 OR @Original_圖書冊書 IS NULL AND 圖書冊書 IS NULL) AND (期刊冊書 = @Original_期刊冊書 OR @Original_期刊冊書 IS NULL AND 期刊冊書 IS NULL) AND (續借次數 = @Original_續借次數 OR @Original_續借次數 IS NULL AND 續借次數 IS NULL) AND (限制圖書 = @Original_限制圖書 OR @Original_限制圖書 IS NULL AND 限制圖書 IS NULL) AND (限制期刊 = @Original_限制期刊 OR @Original_限制期刊 IS NULL AND 限制期刊 IS NULL); SELECT 類型, 圖書冊書, 期刊冊書, 續借次數, 限制圖書, 限制期刊 FROM 讀者類型 WHERE (類型 = @類型)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@類型", System.Data.SqlDbType.VarChar, 20, "類型"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@圖書冊書", System.Data.SqlDbType.SmallInt, 2, "圖書冊書"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@期刊冊書", System.Data.SqlDbType.SmallInt, 2, "期刊冊書"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@續借次數", System.Data.SqlDbType.Int, 4, "續借次數"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制圖書", System.Data.SqlDbType.Bit, 1, "限制圖書"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制期刊", System.Data.SqlDbType.Bit, 1, "限制期刊"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_類型", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "類型", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_圖書冊書", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "圖書冊書", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_期刊冊書", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "期刊冊書", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_續借次數", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "續借次數", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制圖書", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制圖書", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制期刊", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制期刊", System.Data.DataRowVersion.Original, null));
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(568, 478);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.txt5);
this.Controls.Add(this.txt4);
this.Controls.Add(this.txt3);
this.Controls.Add(this.txt2);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.label2);
this.Controls.Add(this.btnSearch);
this.Controls.Add(this.txt1);
this.Controls.Add(this.toolBar1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 應用程序的主入口點。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
//--------------創建窗體時讀入全部數據--------------
private void Form1_Load(object sender, System.EventArgs e)
...{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value="%%";
this.sqlConnection1.Open();
this.sqlDataAdapter1.Fill(dataSet11);
this.sqlConnection1.Close();
//爲數據集添加數據項瀏覽控制
cmOrders=(CurrencyManager) BindingContext[dataSet11,"讀者類型"];
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
...{
if (e.Button.ToolTipText == "首記錄")
...{
this.dataGrid1.UnSelect(cmOrders.Position); //取消原選中的行
cmOrders.Position = 0;
this.dataGrid1.Select(cmOrders.Position); //選中當前行
this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移動表頭指示圖標
return;
}
if (e.Button.ToolTipText == "上一記錄")
...{
if (cmOrders.Position >= 0)
...{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position--;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
}
return;
}
if (e.Button.ToolTipText == "下一記錄")
...{
if (cmOrders.Position <= cmOrders.Count-1)
...{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position++;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
}
return;
}
if (e.Button.ToolTipText == "尾記錄")
...{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position = cmOrders.Count-1;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
return;
}
if(e.Button.ToolTipText=="新增")
...{
EditOrAdd="add";
SetModifyMode(true);
//設置默認值
txt3.Text="1";
txt4.Text="1";
txt5.Text="1";
}
if(e.Button.ToolTipText=="修改")
...{
EditOrAdd="edit";
this.txt2.Text=this.dataSet11.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][0].ToString().Trim();
this.txt3.Text=this.dataSet11.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][1].ToString().Trim();
this.txt4.Text=this.dataSet11.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][2].ToString().Trim();
this.txt5.Text=this.dataSet11.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][3].ToString().Trim();
if(this.dataSet11.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][4].ToString().Trim()=="True")
...{
this.checkBox1.Checked=true;
}
if(this.dataSet11.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][5].ToString().Trim()=="True")
...{
this.checkBox2.Checked=true;
}
SetModifyMode(true);
}
if(e.Button.ToolTipText=="刪除")
...{
DialogResult result=MessageBox.Show("確認刪除?","刪除數據",MessageBoxButtons.OKCancel);
if(result==DialogResult.OK)
if(cmOrders.Count>0)//立即從數據集中刪除
...{
cmOrders.RemoveAt(cmOrders.Position);
this.sqlDataAdapter1.Update(dataSet11);
}
else
MessageBox.Show("表中爲空,已無可刪除數據","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
// if(MessageBox.Show("刪除的行不可恢復,你確定要刪除嗎?","警告",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
// {
// int ReCount=this.dataSet11.Tables["讀者類型"].Rows.Count;
// for(int i=0;i<ReCount;i++)
// {
// if(this.dataGrid1.IsSelected(i))
// {
// this.dataSet11.Tables["讀者類型"].Rows[i]["類型"]="*";
// }
//
// }
// DataRow[] findRows=this.dataSet11.Tables["讀者類型"].Select("類型='*'");
// for(int i=0;i<findRows.Length;i++)
// {
// findRows[i].Delete();
// this.sqlDataAdapter1.Update(this.dataSet11,"讀者類型");
// }
// this.dataSet11.Tables["讀者類型"].AcceptChanges();
//
// }
}
if(e.Button.ToolTipText=="提交")
...{
if(EditOrAdd=="add")
...{
if(txt2.Text.Trim()=="")//檢查非空字段
...{
MessageBox.Show("類型名稱不能爲空","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
DataRow newRow=this.dataSet11.Tables[0].NewRow();
newRow[0]=this.txt2.Text.ToString().Trim();
newRow[1]=this.txt3.Text.ToString().Trim();
newRow[2]=this.txt4.Text.ToString().Trim();
newRow[3]=this.txt5.Text.ToString().Trim();
if(this.checkBox1.Checked)
...{
newRow[4]=1;
}
if(this.checkBox2.Checked)
...{
newRow[5]=1;
}
this.dataSet11.Tables[0].Rows.Add(newRow);
//MessageBox.Show(this.dataSet11.Tables[0].Rows.Count.ToString());
if(dataSet11.GetChanges()!=null)
...{
try
...{
this.sqlDataAdapter1.Update(dataSet11);
SetModifyMode(false);
}
catch(Exception express)
...{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
dataSet11.RejectChanges();
}
}
}
else if(EditOrAdd=="edit")
...{
}
EditOrAdd="";
return;
}
if (e.Button.ToolTipText == "取消")
...{
try
...{
cmOrders.CancelCurrentEdit(); //取消編輯
SetModifyMode(false);
}
catch(Exception express)
...{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return;
}
if(e.Button.ToolTipText=="退出")
...{
this.Close();
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
...{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value="%%";
if(txt1.Text.Trim()!="")
...{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%";
}
//清空數據表,並根據新設置的查詢參數重新填充
dataSet11.讀者類型.Clear();
this.sqlDataAdapter1.Fill(dataSet11);
}
private void SetModifyMode(bool blnEdit)
...{
//設置文本框和下拉列表框屬性
txt1.ReadOnly=!blnEdit;
txt2.ReadOnly=!blnEdit;
txt3.ReadOnly=!blnEdit;
txt4.ReadOnly=!blnEdit;
txt5.ReadOnly=!blnEdit;
//設置搜索按鈕屬性
btnSearch.Enabled=!blnEdit;
}
private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
...{
}
}
}