?? selectbook.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace 圖書館管理系統
{
/// <summary>
/// SelectBook 的摘要說明。
/// </summary>
public class SelectBook : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Data.SqlClient.SqlDataAdapter da1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private 圖書館管理系統.DataSet2 dataSet21;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.TextBox txt1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txt2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txt3;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public SelectBook()
{
//
// 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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SelectBook));
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet21 = new 圖書館管理系統.DataSet2();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnSearch = new System.Windows.Forms.Button();
this.txt1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txt2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txt3 = new System.Windows.Forms.TextBox();
this.da1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "圖書信息";
this.dataGrid1.DataSource = this.dataSet21;
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(504, 368);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.DoubleClick += new System.EventHandler(this.dataGrid1_DoubleClick);
//
// dataSet21
//
this.dataSet21.DataSetName = "DataSet2";
this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnSearch);
this.groupBox1.Controls.Add(this.txt1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.txt2);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.txt3);
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(504, 80);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
//
// 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, 24);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(96, 40);
this.btnSearch.TabIndex = 3;
this.btnSearch.Text = " 搜索";
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// txt1
//
this.txt1.Location = new System.Drawing.Point(128, 40);
this.txt1.Name = "txt1";
this.txt1.TabIndex = 7;
this.txt1.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(128, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 5;
this.label2.Text = "圖書名稱";
//
// label1
//
this.label1.Location = new System.Drawing.Point(248, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 16);
this.label1.TabIndex = 4;
this.label1.Text = "圖書作者";
//
// txt2
//
this.txt2.Location = new System.Drawing.Point(248, 40);
this.txt2.Name = "txt2";
this.txt2.TabIndex = 6;
this.txt2.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(368, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 16);
this.label3.TabIndex = 4;
this.label3.Text = "圖書編號";
//
// txt3
//
this.txt3.Location = new System.Drawing.Point(368, 40);
this.txt3.Name = "txt3";
this.txt3.TabIndex = 6;
this.txt3.Text = "";
//
// da1
//
this.da1.SelectCommand = this.sqlSelectCommand1;
this.da1.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("譯者", "譯者"),
new System.Data.Common.DataColumnMapping("ISBN", "ISBN"),
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("簡介", "簡介"),
new System.Data.Common.DataColumnMapping("是否注銷", "是否注銷")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 編號, 書名, 條形碼, 類型, 作者, 譯者, ISBN, 出版社, 價格, 頁碼, 書架名稱, 現存量, 庫存總量, 簡介, 是否注銷 FROM" +
" 圖書信息 WHERE (書名 LIKE @Param4) AND (作者 LIKE @Param5) AND (編號 LIKE @Param6) AND (是" +
"否注銷 = \'0\')";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 200, "書名"));
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param5", System.Data.SqlDbType.VarChar, 100, "作者"));
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param6", System.Data.SqlDbType.VarChar, 50, "編號"));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=libbook;";
//
// SelectBook
//
this.AcceptButton = this.btnSearch;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(504, 445);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.dataGrid1);
this.Name = "SelectBook";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SelectBook";
this.Load += new System.EventHandler(this.SelectBook_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//--------------根據輸入信息選擇圖書---------------
private void btnSearch_Click(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%";
da1.SelectCommand.Parameters[1].Value="%";
da1.SelectCommand.Parameters[2].Value="%";
if(txt1.Text.Trim()!="")
{
da1.SelectCommand.Parameters[0].Value='%'+txt1.Text.Trim()+'%';
}
if(txt2.Text.Trim()!="")
{
da1.SelectCommand.Parameters[1].Value='%'+txt2.Text.Trim()+'%';
}
if(txt3.Text.Trim()!="")
{
da1.SelectCommand.Parameters[2].Value='%'+txt3.Text.Trim()+'%';
}
dataSet21.Clear();//刷新圖書信息
da1.Fill(dataSet21);
}
//--------------讀入全部圖書數據------------------
private void SelectBook_Load(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%";
da1.SelectCommand.Parameters[1].Value="%";
da1.SelectCommand.Parameters[2].Value="%";
da1.Fill(dataSet21);
}
//-------------雙擊選擇圖書-----------------
private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
{
int curRow=dataGrid1.CurrentCell.RowNumber;
BookSubscribe.bookID=dataGrid1[curRow,0].ToString();
BookSubscribe.bookName=dataGrid1[curRow,1].ToString();
this.Close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -