📄 borrowbooks.cs
字号:
this.groupBox6.Controls.Add(this.textBox10);
this.groupBox6.Controls.Add(this.textBox9);
this.groupBox6.Controls.Add(this.textBox8);
this.groupBox6.Controls.Add(this.label13);
this.groupBox6.Controls.Add(this.label12);
this.groupBox6.Controls.Add(this.label11);
this.groupBox6.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox6.Location = new System.Drawing.Point(336, 136);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(416, 120);
this.groupBox6.TabIndex = 4;
this.groupBox6.TabStop = false;
this.groupBox6.Text = "图书信息";
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(112, 86);
this.textBox10.Name = "textBox10";
this.textBox10.ReadOnly = true;
this.textBox10.Size = new System.Drawing.Size(256, 21);
this.textBox10.TabIndex = 11;
this.textBox10.Text = "";
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(112, 54);
this.textBox9.Name = "textBox9";
this.textBox9.ReadOnly = true;
this.textBox9.Size = new System.Drawing.Size(256, 21);
this.textBox9.TabIndex = 10;
this.textBox9.Text = "";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(112, 22);
this.textBox8.Name = "textBox8";
this.textBox8.ReadOnly = true;
this.textBox8.Size = new System.Drawing.Size(256, 21);
this.textBox8.TabIndex = 9;
this.textBox8.Text = "";
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(32, 88);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(42, 17);
this.label13.TabIndex = 6;
this.label13.Text = "出版社";
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(32, 56);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(29, 17);
this.label12.TabIndex = 5;
this.label12.Text = "作者";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(32, 24);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(29, 17);
this.label11.TabIndex = 4;
this.label11.Text = "书名";
//
// groupBox7
//
this.groupBox7.Controls.Add(this.label16);
this.groupBox7.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox7.Location = new System.Drawing.Point(32, 392);
this.groupBox7.Name = "groupBox7";
this.groupBox7.Size = new System.Drawing.Size(261, 104);
this.groupBox7.TabIndex = 14;
this.groupBox7.TabStop = false;
this.groupBox7.Text = "罚款信息";
//
// label16
//
this.label16.AutoSize = true;
this.label16.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label16.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label16.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label16.ForeColor = System.Drawing.Color.Red;
this.label16.Location = new System.Drawing.Point(24, 25);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(26, 20);
this.label16.TabIndex = 0;
this.label16.Text = "...";
this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// BorrowBooks
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(790, 503);
this.ControlBox = false;
this.Controls.Add(this.groupBox7);
this.Controls.Add(this.groupBox6);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "BorrowBooks";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "借阅图书";
this.Load += new System.EventHandler(this.BorrowBooks_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.groupBox6.ResumeLayout(false);
this.groupBox7.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button2_Click(object sender, System.EventArgs e)
{
Global.BorrowBooks = false;
Global.sbpGlobal.Text = "就绪";
this.Close();
}
/// <summary>
/// 初始化
/// </summary>
private void initializeScreen()
{
i = 0;
dc = 0;
rc = 0;
listView1.Items.Clear();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox1.Focus();
}
/// <summary>
/// 窗口加载代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BorrowBooks_Load(object sender, System.EventArgs e)
{
cmd = Global.conn.CreateCommand();
initializeScreen();
}
/// <summary>
/// 借书
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnBorrow_Click(object sender, System.EventArgs e)
{
string str = "";
string str1 = "";
if(textBox6.Text == "0")
{
MessageBox.Show("该读者证已经借满!不能继续借书!");
initializeScreen();
return;
}
else if(canBorrow)
{
str = "insert into 流通 values('" + textBox1.Text + "','" + textBox7.Text + "','" +
DateTime.Now.Date.ToShortDateString() + "','" + DateTime.Now.Date.AddDays(dc).ToShortDateString() + "',0,0)";
str1 = "update 图书资料 set 借阅次数=借阅次数+1 where 条形码='" + textBox7.Text + "'";
//创建事务
SqlTransaction trans = Global.conn.BeginTransaction();
cmd.Transaction = trans;
try
{
cmd.CommandText = str;
cmd.ExecuteNonQuery();
cmd.CommandText = str1;
cmd.ExecuteNonQuery();
trans.Commit();
}
catch
{
try
{
trans.Rollback();
}
catch (SqlException ex)
{
if (trans.Connection != null)
{
MessageBox.Show(ex.ToString());
}
}
MessageBox.Show("发生错误!图书借阅未成功!");
initializeScreen();
return;
}
if(MessageBox.Show("借阅成功!\n\n是否继续借阅?","提示与询问",MessageBoxButtons.YesNo)==DialogResult.Yes)
{
canBorrow = false;
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
CheckReaderCard();
}
else
{
Global.sbpGlobal.Text = "就绪";
Global.BorrowBooks = false;
this.Close();
}
}
else
{
MessageBox.Show("此图书已经借出!暂时不能借阅!");
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox7.Focus();
return;
}
}
/// <summary>
/// 检验读者证
/// </summary>
private void CheckReaderCard()
{
string str = "";
i=0;
rc=0;
dc=0;
listView1.Items.Clear();
ListViewItem item = null;
str = "select * from V_借书证 where 借书证号='" + textBox1.Text + "'";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
/*
if(dr.GetInt32(3)!=0)
{
if(dr!=null)dr.Close();
MessageBox.Show("此借书证已经被挂失!您无权借阅图书!");
return;
}
else
{
textBox2.Text = dr.GetString(1);
textBox3.Text = dr.GetString(2);
textBox4.Text = dr.GetString(3);
dc = dr.GetInt32(4);
textBox5.Text = dr.GetInt32(5).ToString();
rc = dr.GetInt32(5);
textBox7.Focus();//焦点转移
}*/
textBox2.Text = dr.GetString(1);
textBox3.Text = dr.GetString(2);
textBox4.Text = dr.GetString(3);
dc = dr.GetInt32(4);
textBox5.Text = dr.GetInt32(5).ToString();
rc = dr.GetInt32(5);
textBox7.Focus();//焦点转移
}
else
{
dr.Close();
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox1.Focus();//焦点转移
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null)dr.Close();
MessageBox.Show(ex.ToString(),"错误");
return;
}
str = "select * from 读者借书 where 借书证号='" + textBox1.Text + "' and 归还标志=1";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
while(dr.Read())
{
i++;
item = new ListViewItem(dr.GetString(0));
item.SubItems.Add(dr.GetString(2));
item.SubItems.Add(dr.GetString(3));
item.SubItems.Add(dr.GetString(5));
item.SubItems.Add(dr.GetDateTime(7).ToShortDateString());
item.SubItems.Add(dr.GetDateTime(8).ToShortDateString());
listView1.Items.Add(item);
}
if(i<=rc)
{
textBox6.Text = (rc-i).ToString();
}
else
{
textBox6.Text = "0";
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null)dr.Close();
MessageBox.Show(ex.ToString(),"错误");
return;
}
}
/// <summary>
/// 读者证验证
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyValue == 13)
{
CheckReaderCard();
}
}
/// <summary>
/// 图书条码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox7_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyValue == 13)
{
string str = "select * from 图书资料 where 条形码='" + textBox7.Text + "'";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
textBox8.Text = dr.GetString(3);
textBox9.Text = dr.GetString(5);
textBox10.Text = dr.GetString(7);
}
else
{
dr.Close();
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
canBorrow = false;
textBox7.Focus();
textBox7.SelectAll();
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null)dr.Close();
MessageBox.Show(ex.ToString(),"错误");
return;
}
str = "select * from 流通 where 图书条码号='" + textBox7.Text + "' and 归还标志=0";//此处设置归还标志,0表示是在借阅状态;1表示已归还
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows==false)
{
if(dr!=null)dr.Close();
//canBorrow = true;
//btnBorrow.Focus();//焦点转移
}
else
{
if(dr!=null)dr.Close();
MessageBox.Show("此图书已经借出!暂时不能借阅!");
initializeScreen();
}
if(dr!=null)dr.Close();
}
catch(Exception ex)
{
if(dr!=null)dr.Close();
MessageBox.Show("发生如下错误:\n\t" + ex.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
str = @"select * from 流通 where 还书日期<'" + DateTime.Now.Year.ToString() + "-"
+ DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString() + "' and 借书证号='" + this.textBox1.Text.Trim() + "'";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows==false)
{
if(dr!=null)dr.Close();
canBorrow = true;
btnBorrow.Focus();//焦点转移
}
else
{
if(dr!=null)dr.Close();
MessageBox.Show("此借书证中存在超期图书!暂时不能借书!\n\n请尽快将超期图书归还!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
textBox7.Focus();
textBox7.SelectAll();
}
if(dr!=null)dr.Close();
}
catch(Exception ex)
{
if(dr!=null)dr.Close();
MessageBox.Show("发生如下错误:\n\t" + ex.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
}
/// <summary>
/// 让出服务给新的读者,并清空界面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRefresh_Click(object sender, System.EventArgs e)
{
initializeScreen();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -