📄 frmborrow.cs
字号:
// Label2
//
this.Label2.Location = new System.Drawing.Point(288, 35);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(32, 16);
this.Label2.TabIndex = 5;
this.Label2.Text = "姓名";
//
// txbName
//
this.txbName.Location = new System.Drawing.Point(320, 30);
this.txbName.Name = "txbName";
this.txbName.Size = new System.Drawing.Size(56, 21);
this.txbName.TabIndex = 4;
this.txbName.Text = "";
//
// Label1
//
this.Label1.Location = new System.Drawing.Point(192, 37);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(80, 16);
this.Label1.TabIndex = 3;
this.Label1.Text = "回车确认输入";
//
// txbReader
//
this.txbReader.Location = new System.Drawing.Point(88, 32);
this.txbReader.Name = "txbReader";
this.txbReader.TabIndex = 2;
this.txbReader.Text = "";
this.txbReader.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txbReader_KeyDown);
//
// rbnReaderCode
//
this.rbnReaderCode.Location = new System.Drawing.Point(16, 41);
this.rbnReaderCode.Name = "rbnReaderCode";
this.rbnReaderCode.Size = new System.Drawing.Size(64, 24);
this.rbnReaderCode.TabIndex = 1;
this.rbnReaderCode.Text = "条形码";
//
// rbnReaderNumber
//
this.rbnReaderNumber.Checked = true;
this.rbnReaderNumber.Location = new System.Drawing.Point(16, 16);
this.rbnReaderNumber.Name = "rbnReaderNumber";
this.rbnReaderNumber.Size = new System.Drawing.Size(64, 24);
this.rbnReaderNumber.TabIndex = 0;
this.rbnReaderNumber.TabStop = true;
this.rbnReaderNumber.Text = "编号";
//
// frmBorrow
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(692, 310);
this.Controls.Add(this.GroupBox2);
this.Controls.Add(this.GroupBox1);
this.Controls.Add(this.ToolBar1);
this.Name = "frmBorrow";
this.Text = "图书借阅";
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmBorrow_Closing);
this.Load += new System.EventHandler(this.frmBorrow_Load);
this.GroupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgdList)).EndInit();
this.GroupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void txbBook_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
{
if ( dtData.Rows.Count >= Int32.Parse( txbCount.Text.Trim() ) )
MessageBox.Show( "你借阅数量已经超过可借数量" );
DataBase db = new DataBase();
string strSQL = "";
strSQL += "select 编号,书名,出版社,价格,b.可借天数 from";
strSQL += " 图书信息 as a , 图书类型 as b ";
strSQL += "where a.类型 = b.类型名称";
if ( rbnBookNumber.Checked )
strSQL += " and 编号='" + txbBook.Text.Trim() + "'";
else
strSQL += " and 条形码='" + txbBook.Text.Trim() + "'";
DataView dv = db.RunSelectSQL( strSQL );
string strNumber, strName, strPress, strPrice, strDays;
if ( dv.Count != 0 )
{
foreach ( DataRow tmpdr in dtData.Rows )
{
if ( tmpdr[ "编号" ].ToString().Trim() == dv[ 0 ][ "编号" ].ToString().Trim() )
{
MessageBox.Show( "图书已经借给该读者!" );
return;
}
}
strNumber = dv[ 0 ][ "编号" ].ToString().Trim();
strName = dv[ 0 ][ "书名" ].ToString().Trim();
strPress = dv[ 0 ][ "出版社" ].ToString().Trim();
strPrice = dv[ 0 ][ "价格" ].ToString().Trim();
strDays = dv[ 0 ][ "可借天数" ].ToString().Trim();
DataRow dr = dtData.NewRow();
dr[ "状态" ] = "新借";
dr[ "编号" ] = strNumber;
dr[ "借阅时间" ] = DateTime.Today.ToString( "yyyy-MM-dd" );
dr[ "应还事件" ] = DateTime.Now.AddDays( Int32.Parse( strDays ) ).ToString( "yyyy-MM-dd" );
dr[ "出版社" ] = strPress;
dr[ "价格" ] = strPrice;
dtData.Rows.Add( dr );
dtData.DefaultView.AllowNew = false;
dtData.DefaultView.AllowDelete = false;
dtData.DefaultView.AllowEdit = false;
dgdList.DataSource = dtData.DefaultView;
}
db.Dispose();
}
}
private void txbReader_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
{
if ( dtData.Rows.Count != 0 )
{
if ( MessageBox.Show( "未保存数据", "提示", MessageBoxButtons.YesNo )
== DialogResult.Yes )
dtData.Rows.Clear();
else
return;
}
}
DataBase db = new DataBase();
string strSQL ="select 姓名,编号,a.类型,图书册书 from 读者类型";
strSQL += " as a , 读者信息 as b where a.类型 = b.类型";
if ( rbnReaderNumber.Checked )
strSQL += " and 编号='" + txbReader.Text.Trim() + "'";
else
strSQL += " and 条形码='" + txbReader.Text.Trim() + "'";
DataView dv = db.RunSelectSQL( strSQL );
if ( dv.Count != 0 )
{
txbName.Text = dv[ 0 ][ "姓名" ].ToString().Trim();
txbType.Text = dv[ 0 ][ "类型" ].ToString().Trim();
txbCount.Text = dv[ 0 ][ "图书册书" ].ToString().Trim();
strSQL = "select 状态,编号,书名,借阅时间,应还时间,出版社,";
strSQL += "价格 from 图书信息 as a , 图书借阅 as b where";
strSQL += " a.编号 = b.图书编号 and 状态 = '未还' and " ;
strSQL += "读者编号 ='" + dv[ 0 ][ "编号" ].ToString().Trim() + "'";
dv = db.RunSelectSQL( strSQL );
if ( dv.Count != 0 )
{
dv.AllowNew =false;
dv.AllowDelete = false;
dv.AllowEdit = false;
dtData = dv.Table;
dgdList.DataSource = dv;
}
txbReader.ReadOnly = true;
txbBook.Focus();
}
else
{
txbName.Text = "";
txbType.Text = "";
txbCount.Text = "";
txbReader.Focus();
}
db.Dispose();
}
private void SetTextBox( bool bState )
{
txbName.ReadOnly = bState;
txbCount.ReadOnly = bState;
txbType.ReadOnly = bState;
}
private void frmBorrow_Load(object sender, System.EventArgs e)
{
SetTextBox( true );
InitDataTable();
}
private void InitDataTable()
{
dtData = new DataTable();
dtData.Columns.Add( "状态" );
dtData.Columns.Add( "编号" );
dtData.Columns.Add( "书名" );
dtData.Columns.Add( "借阅时间" );
dtData.Columns.Add( "应还时间" );
dtData.Columns.Add( "出版社" );
dtData.Columns.Add( "价格" );
}
private void frmBorrow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if ( dtData.Rows.Count!= 0 )
{
foreach ( DataRow tmpdr in dtData.Rows )
{
if ( tmpdr[ "状态" ].ToString().Trim() == "新借" )
{
if ( MessageBox.Show( "未保存数据", "提示", MessageBoxButtons.YesNo )
== DialogResult.No )
{
e.Cancel = true;
dtData.Dispose();
}
}
}
}
}
private void ToolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch ( e.Button.Text )
{
case "确定借书" :
if ( dtData.Rows.Count != 0 )
{
string strSQL = "";
foreach ( DataRow tmpdr in dtData.Rows )
{
if ( tmpdr[ "状态" ].ToString().Trim() == "新借" )
{
strSQL = " insert into 图书借阅(图书编号,";
strSQL += "读者编号,借阅时间,应还时间,";
strSQL += "续借次数,操作员,状态) values('";
strSQL += tmpdr[ "编号" ] + "','";
strSQL += txbReader.Text.Trim();
strSQL += "','" + tmpdr[ "借阅时间" ] + "','";
strSQL += tmpdr[ "应还时间"] + "'";
strSQL += ",0,'操作员','新借')";
}
}
if ( strSQL.Length != 0 )
{
DataBase db = new DataBase();
db.RunDelOrInsSQL( strSQL );
db.RunDelOrInsSQL( "sf_图书借阅" );
db.Dispose();
}
}
break;
case "退出":
this.Close();
break;
}
txbName.Text = "";
txbType.Text = "";
txbBook.Text = "";
txbReader.Text = "";
txbCount.Text = "";
dtData.DefaultView.AllowNew = false;
dtData.DefaultView.AllowDelete = false;
dtData.DefaultView.AllowEdit = false;
dgdList.DataSource = dtData.DefaultView;
txbReader.ReadOnly = false;
txbReader.Focus();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -