📄 borrowreturn.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace Library
{
/// <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.DataSetBorrowReturn objDataSetBorrowReturn;
private System.Windows.Forms.Panel panel1;
/// <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()
{
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.objDataSetBorrowReturn = new Library.DataSetBorrowReturn();
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.panel1 = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.objDataSetBorrowReturn)).BeginInit();
this.panel1.SuspendLayout();
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(176, 8);
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 = 60;
//
// dataGridTextBoxColumn3
//
this.dataGridTextBoxColumn3.Format = "";
this.dataGridTextBoxColumn3.FormatInfo = null;
this.dataGridTextBoxColumn3.HeaderText = "借书日期";
this.dataGridTextBoxColumn3.MappingName = "BorrowDate";
this.dataGridTextBoxColumn3.Width = 80;
//
// dataGridTextBoxColumn4
//
this.dataGridTextBoxColumn4.Format = "";
this.dataGridTextBoxColumn4.FormatInfo = null;
this.dataGridTextBoxColumn4.HeaderText = "应还书日期";
this.dataGridTextBoxColumn4.MappingName = "ReturnDate";
this.dataGridTextBoxColumn4.Width = 80;
//
// 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, 24);
this.textReaderID.Name = "textReaderID";
this.textReaderID.Size = new System.Drawing.Size(96, 21);
this.textReaderID.TabIndex = 2;
this.textReaderID.Text = "";
//
// objDataSetBorrowReturn
//
this.objDataSetBorrowReturn.DataSetName = "DataSetBorrowReturn";
this.objDataSetBorrowReturn.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// 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, 24);
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, 54);
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=WJD;packet size=4096;integrated security=SSPI;data source=WJD;pers" +
"ist security info=False;initial catalog=BookManagement";
//
// 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.NVarChar, 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.NVarChar, 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.NVarChar, 6, "ReaderID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BookID", System.Data.SqlDbType.NVarChar, 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.NVarChar, 6, "ReaderID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BookID", System.Data.SqlDbType.NVarChar, 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.NVarChar, 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.NVarChar, 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(16, 48);
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(16, 26);
this.lblReaderID.Name = "lblReaderID";
this.lblReaderID.Size = new System.Drawing.Size(56, 16);
this.lblReaderID.TabIndex = 8;
this.lblReaderID.Text = "客户编号";
this.lblReaderID.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblBookID
//
this.lblBookID.Location = new System.Drawing.Point(16, 56);
this.lblBookID.Name = "lblBookID";
this.lblBookID.Size = new System.Drawing.Size(56, 16);
this.lblBookID.TabIndex = 9;
this.lblBookID.Text = "图书编号";
this.lblBookID.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblInfomation
//
this.lblInfomation.Location = new System.Drawing.Point(48, 16);
this.lblInfomation.Name = "lblInfomation";
this.lblInfomation.Size = new System.Drawing.Size(56, 16);
this.lblInfomation.TabIndex = 10;
this.lblInfomation.Text = "信息提示";
//
// panel1
//
this.panel1.Controls.Add(this.btnLoad);
this.panel1.Controls.Add(this.textReaderID);
this.panel1.Controls.Add(this.btnExit);
this.panel1.Controls.Add(this.lblBookID);
this.panel1.Controls.Add(this.lblReaderID);
this.panel1.Controls.Add(this.btnReturn);
this.panel1.Controls.Add(this.textBookID);
this.panel1.Controls.Add(this.btnBorrow);
this.panel1.Location = new System.Drawing.Point(0, 216);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(480, 88);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -