?? borrowreturn.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using Library.UserInterface;
namespace Library.UserInterface
{
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class BorrowReturn : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private DataSet dataSet1=new DataSet();
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnLoad;
private System.Windows.Forms.Button btnBorrow;
private System.Windows.Forms.Button btnReturn;
private System.Windows.Forms.TextBox textInformation;
private System.Windows.Forms.Label lblReaderID;
private System.Windows.Forms.Label lblBookID;
private System.Windows.Forms.Label lblInfomation;
private System.Windows.Forms.TextBox textReaderID;
private System.Windows.Forms.TextBox textBookID;
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 Library.UserInterface.DataSetBorrowReturn objDataSetBorrowReturn;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public BorrowReturn()
{
//
// 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(BorrowReturn));
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn4 = new System.Windows.Forms.DataGridTextBoxColumn();
this.btnExit = new System.Windows.Forms.Button();
this.textReaderID = new System.Windows.Forms.TextBox();
this.btnLoad = new System.Windows.Forms.Button();
this.btnBorrow = new System.Windows.Forms.Button();
this.textBookID = new System.Windows.Forms.TextBox();
this.btnReturn = new System.Windows.Forms.Button();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.textInformation = new System.Windows.Forms.TextBox();
this.lblReaderID = new System.Windows.Forms.Label();
this.lblBookID = new System.Windows.Forms.Label();
this.lblInfomation = new System.Windows.Forms.Label();
this.objDataSetBorrowReturn = new Library.UserInterface.DataSetBorrowReturn();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.objDataSetBorrowReturn)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.AlternatingBackColor = System.Drawing.Color.White;
this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid1.BackColor = System.Drawing.Color.White;
this.dataGrid1.BackgroundColor = System.Drawing.Color.Gainsboro;
this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dataGrid1.CaptionBackColor = System.Drawing.Color.Silver;
this.dataGrid1.CaptionFont = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Bold);
this.dataGrid1.CaptionForeColor = System.Drawing.Color.Black;
this.dataGrid1.DataMember = "";
this.dataGrid1.Enabled = false;
this.dataGrid1.FlatMode = true;
this.dataGrid1.Font = new System.Drawing.Font("Courier New", 9F);
this.dataGrid1.ForeColor = System.Drawing.Color.DarkSlateGray;
this.dataGrid1.GridLineColor = System.Drawing.Color.DarkGray;
this.dataGrid1.HeaderBackColor = System.Drawing.Color.DarkGreen;
this.dataGrid1.HeaderFont = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Bold);
this.dataGrid1.HeaderForeColor = System.Drawing.Color.White;
this.dataGrid1.LinkColor = System.Drawing.Color.DarkGreen;
this.dataGrid1.Location = new System.Drawing.Point(152, 104);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.Black;
this.dataGrid1.ReadOnly = true;
this.dataGrid1.SelectionBackColor = System.Drawing.Color.DarkSeaGreen;
this.dataGrid1.SelectionForeColor = System.Drawing.Color.Black;
this.dataGrid1.Size = new System.Drawing.Size(304, 196);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle1});
this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1,
this.dataGridTextBoxColumn2,
this.dataGridTextBoxColumn3,
this.dataGridTextBoxColumn4});
this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "BorrowBook";
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "讀者";
this.dataGridTextBoxColumn1.MappingName = "ReaderID";
this.dataGridTextBoxColumn1.Width = 50;
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.HeaderText = "書號";
this.dataGridTextBoxColumn2.MappingName = "BookID";
this.dataGridTextBoxColumn2.Width = 50;
//
// dataGridTextBoxColumn3
//
this.dataGridTextBoxColumn3.Format = "";
this.dataGridTextBoxColumn3.FormatInfo = null;
this.dataGridTextBoxColumn3.HeaderText = "借書日期";
this.dataGridTextBoxColumn3.MappingName = "BorrowDate";
this.dataGridTextBoxColumn3.Width = 75;
//
// dataGridTextBoxColumn4
//
this.dataGridTextBoxColumn4.Format = "";
this.dataGridTextBoxColumn4.FormatInfo = null;
this.dataGridTextBoxColumn4.HeaderText = "應還書日期";
this.dataGridTextBoxColumn4.MappingName = "ReturnDate";
this.dataGridTextBoxColumn4.Width = 75;
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(400, 32);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 32);
this.btnExit.TabIndex = 1;
this.btnExit.Text = "退出窗口";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// textReaderID
//
this.textReaderID.Location = new System.Drawing.Point(80, 16);
this.textReaderID.Name = "textReaderID";
this.textReaderID.Size = new System.Drawing.Size(96, 21);
this.textReaderID.TabIndex = 2;
this.textReaderID.Text = "";
//
// btnLoad
//
this.btnLoad.Location = new System.Drawing.Point(192, 32);
this.btnLoad.Name = "btnLoad";
this.btnLoad.Size = new System.Drawing.Size(75, 32);
this.btnLoad.TabIndex = 3;
this.btnLoad.Text = "借閱記錄";
this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
//
// btnBorrow
//
this.btnBorrow.Location = new System.Drawing.Point(296, 16);
this.btnBorrow.Name = "btnBorrow";
this.btnBorrow.Size = new System.Drawing.Size(75, 24);
this.btnBorrow.TabIndex = 4;
this.btnBorrow.Text = "借閱圖書";
this.btnBorrow.Click += new System.EventHandler(this.btnBorrow_Click);
//
// textBookID
//
this.textBookID.Location = new System.Drawing.Point(80, 56);
this.textBookID.Name = "textBookID";
this.textBookID.Size = new System.Drawing.Size(96, 21);
this.textBookID.TabIndex = 5;
this.textBookID.Text = "";
//
// btnReturn
//
this.btnReturn.Location = new System.Drawing.Point(296, 56);
this.btnReturn.Name = "btnReturn";
this.btnReturn.Size = new System.Drawing.Size(75, 24);
this.btnReturn.TabIndex = 6;
this.btnReturn.Text = "歸還圖書";
this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;data source=lo" +
"calhost;persist security info=False;initial catalog=BookManager";
//
// 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", "BorrowBook", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ReaderID", "ReaderID"),
new System.Data.Common.DataColumnMapping("BookID", "BookID"),
new System.Data.Common.DataColumnMapping("BorrowDate", "BorrowDate"),
new System.Data.Common.DataColumnMapping("ReturnDate", "ReturnDate"),
new System.Data.Common.DataColumnMapping("FactReturnDate", "FactReturnDate")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM BorrowBook WHERE (BookID = @Original_BookID) AND (ReaderID = @Original_ReaderID) AND (BorrowDate = @Original_BorrowDate OR @Original_BorrowDate IS NULL AND BorrowDate IS NULL) AND (FactReturnDate = @Original_FactReturnDate OR @Original_FactReturnDate IS NULL AND FactReturnDate IS NULL) AND (ReturnDate = @Original_ReturnDate OR @Original_ReturnDate IS NULL AND ReturnDate IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_BookID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "BookID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ReaderID", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ReaderID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_BorrowDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "BorrowDate", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactReturnDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactReturnDate", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ReturnDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ReturnDate", System.Data.DataRowVersion.Original, null));
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = @"INSERT INTO BorrowBook(ReaderID, BookID, BorrowDate, ReturnDate, FactReturnDate) VALUES (@ReaderID, @BookID, @BorrowDate, @ReturnDate, @FactReturnDate); SELECT ReaderID, BookID, BorrowDate, ReturnDate, FactReturnDate FROM BorrowBook WHERE (BookID = @BookID) AND (ReaderID = @ReaderID)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ReaderID", System.Data.SqlDbType.VarChar, 6, "ReaderID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BookID", System.Data.SqlDbType.VarChar, 10, "BookID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BorrowDate", System.Data.SqlDbType.DateTime, 8, "BorrowDate"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ReturnDate", System.Data.SqlDbType.DateTime, 8, "ReturnDate"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactReturnDate", System.Data.SqlDbType.DateTime, 8, "FactReturnDate"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT ReaderID, BookID, BorrowDate, ReturnDate, FactReturnDate FROM BorrowBook";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE BorrowBook SET ReaderID = @ReaderID, BookID = @BookID, BorrowDate = @BorrowDate, ReturnDate = @ReturnDate, FactReturnDate = @FactReturnDate WHERE (BookID = @Original_BookID) AND (ReaderID = @Original_ReaderID) AND (BorrowDate = @Original_BorrowDate OR @Original_BorrowDate IS NULL AND BorrowDate IS NULL) AND (FactReturnDate = @Original_FactReturnDate OR @Original_FactReturnDate IS NULL AND FactReturnDate IS NULL) AND (ReturnDate = @Original_ReturnDate OR @Original_ReturnDate IS NULL AND ReturnDate IS NULL); SELECT ReaderID, BookID, BorrowDate, ReturnDate, FactReturnDate FROM BorrowBook WHERE (BookID = @BookID) AND (ReaderID = @ReaderID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ReaderID", System.Data.SqlDbType.VarChar, 6, "ReaderID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BookID", System.Data.SqlDbType.VarChar, 10, "BookID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BorrowDate", System.Data.SqlDbType.DateTime, 8, "BorrowDate"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ReturnDate", System.Data.SqlDbType.DateTime, 8, "ReturnDate"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactReturnDate", System.Data.SqlDbType.DateTime, 8, "FactReturnDate"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_BookID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "BookID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ReaderID", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ReaderID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_BorrowDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "BorrowDate", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactReturnDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactReturnDate", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ReturnDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ReturnDate", System.Data.DataRowVersion.Original, null));
//
// textInformation
//
this.textInformation.Enabled = false;
this.textInformation.Location = new System.Drawing.Point(8, 160);
this.textInformation.Multiline = true;
this.textInformation.Name = "textInformation";
this.textInformation.Size = new System.Drawing.Size(112, 112);
this.textInformation.TabIndex = 7;
this.textInformation.Text = "";
//
// lblReaderID
//
this.lblReaderID.Location = new System.Drawing.Point(8, 24);
this.lblReaderID.Name = "lblReaderID";
this.lblReaderID.Size = new System.Drawing.Size(56, 16);
this.lblReaderID.TabIndex = 8;
this.lblReaderID.Text = "讀者號碼";
//
// lblBookID
//
this.lblBookID.Location = new System.Drawing.Point(8, 56);
this.lblBookID.Name = "lblBookID";
this.lblBookID.Size = new System.Drawing.Size(56, 16);
this.lblBookID.TabIndex = 9;
this.lblBookID.Text = "圖書號碼";
//
// lblInfomation
//
this.lblInfomation.Location = new System.Drawing.Point(40, 128);
this.lblInfomation.Name = "lblInfomation";
this.lblInfomation.Size = new System.Drawing.Size(56, 16);
this.lblInfomation.TabIndex = 10;
this.lblInfomation.Text = "信息提示";
//
// objDataSetBorrowReturn
//
this.objDataSetBorrowReturn.DataSetName = "DataSetBorrowReturn";
this.objDataSetBorrowReturn.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// BorrowReturn
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(488, 325);
this.Controls.Add(this.lblInfomation);
this.Controls.Add(this.lblBookID);
this.Controls.Add(this.lblReaderID);
this.Controls.Add(this.textInformation);
this.Controls.Add(this.btnReturn);
this.Controls.Add(this.textBookID);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -