?? returnbooks.cs
字號(hào):
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(352, 128);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(416, 125);
this.groupBox6.TabIndex = 11;
this.groupBox6.TabStop = false;
this.groupBox6.Text = "圖書信息";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(112, 22);
this.textBox7.Name = "textBox7";
this.textBox7.ReadOnly = true;
this.textBox7.Size = new System.Drawing.Size(256, 21);
this.textBox7.TabIndex = 1;
this.textBox7.Text = "";
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(112, 86);
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, 54);
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.label19);
this.groupBox7.Controls.Add(this.label18);
this.groupBox7.Controls.Add(this.label17);
this.groupBox7.Controls.Add(this.label14);
this.groupBox7.Controls.Add(this.label2);
this.groupBox7.Controls.Add(this.label16);
this.groupBox7.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox7.Location = new System.Drawing.Point(576, 256);
this.groupBox7.Name = "groupBox7";
this.groupBox7.Size = new System.Drawing.Size(192, 152);
this.groupBox7.TabIndex = 14;
this.groupBox7.TabStop = false;
this.groupBox7.Text = "罰款信息";
//
// label19
//
this.label19.AutoSize = true;
this.label19.Font = new System.Drawing.Font("宋體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label19.ForeColor = System.Drawing.SystemColors.ControlText;
this.label19.Location = new System.Drawing.Point(152, 64);
this.label19.Name = "label19";
this.label19.Size = new System.Drawing.Size(17, 17);
this.label19.TabIndex = 5;
this.label19.Text = "元";
this.label19.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label18
//
this.label18.AutoSize = true;
this.label18.Font = new System.Drawing.Font("宋體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label18.ForeColor = System.Drawing.SystemColors.ControlText;
this.label18.Location = new System.Drawing.Point(152, 24);
this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(17, 17);
this.label18.TabIndex = 4;
this.label18.Text = "天";
this.label18.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label17
//
this.label17.AutoSize = true;
this.label17.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label17.Font = new System.Drawing.Font("宋體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label17.ForeColor = System.Drawing.SystemColors.ControlText;
this.label17.Location = new System.Drawing.Point(88, 64);
this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(25, 20);
this.label17.TabIndex = 3;
this.label17.Text = "...";
this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label14
//
this.label14.AutoSize = true;
this.label14.Font = new System.Drawing.Font("宋體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label14.ForeColor = System.Drawing.SystemColors.ControlText;
this.label14.Location = new System.Drawing.Point(24, 64);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(60, 17);
this.label14.TabIndex = 2;
this.label14.Text = "應(yīng)罰金額:";
this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.AutoSize = true;
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Font = new System.Drawing.Font("宋體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.label2.Location = new System.Drawing.Point(88, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(25, 20);
this.label2.TabIndex = 1;
this.label2.Text = "...";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label16
//
this.label16.AutoSize = true;
this.label16.Font = new System.Drawing.Font("宋體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label16.ForeColor = System.Drawing.SystemColors.ControlText;
this.label16.Location = new System.Drawing.Point(24, 25);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(60, 17);
this.label16.TabIndex = 0;
this.label16.Text = "超期天數(shù):";
this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ReturnBooks
//
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.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox6);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ReturnBooks";
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.ReturnBooks_Load);
this.groupBox3.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.groupBox6.ResumeLayout(false);
this.groupBox7.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 初始化
/// </summary>
private void initializeScreen()
{
r_ID = "";
rc = 0;
dc = 0;
book_ID = "";
btnReturn.Enabled = true;
btnForfeit.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
label2.Text = "";
label17.Text = "";
listView1.Items.Clear();
isU=false;
//ListViewItem item = null;
}
/// <summary>
/// 關(guān)閉
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnClose_Click(object sender, System.EventArgs e)
{
Global.sbpGlobal.Text = "就緒";
Global.ReturnBooks = false;
this.Close();
}
/// <summary>
/// 窗體加載代碼
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ReturnBooks_Load(object sender, System.EventArgs e)
{
cmd = Global.conn.CreateCommand();
initializeScreen();
}
/// <summary>
/// 歸還圖書
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnReturn_Click(object sender, System.EventArgs e)
{
if(isU)
{
MessageBox.Show("此圖書已經(jīng)超期!");
initializeScreen();
return;
}
else
{
string str = "update 流通 set 歸還標(biāo)志=1 where 圖書條碼號(hào)='" + book_ID + "'";
cmd.CommandText = str;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("成功歸還圖書!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
initializeScreen();
}
catch(Exception ex)
{
MessageBox.Show("發(fā)生如下錯(cuò)誤:\n\n" + ex.ToString(),"錯(cuò)誤",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
}
/// <summary>
/// 罰款
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnForfeit_Click(object sender, System.EventArgs e)
{
string str = "insert into 罰款 values('" + book_ID + "'," + Convert.ToDecimal(label17.Text) + ",'"
+ "圖書超期','" + textBox2.Text + "','" + DateTime.Now.ToShortDateString() + "')";
cmd.CommandText = str;
//創(chuàng)建事務(wù)
SqlTransaction trans = Global.conn.BeginTransaction();
cmd.Transaction = trans;
try
{
cmd.CommandText = str;
cmd.ExecuteNonQuery();
str = "update 流通 set 歸還標(biāo)志=1 where 圖書條碼號(hào)='" + book_ID + "'";
cmd.CommandText = str;
cmd.ExecuteNonQuery();
trans.Commit();
MessageBox.Show("此圖書成功歸還并且繳納罰金!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
initializeScreen();
}
catch
{
try
{
trans.Rollback();
}
catch (SqlException ex)
{
if (trans.Connection != null)
{
MessageBox.Show("發(fā)生如下錯(cuò)誤:\n\t" + ex.ToString(),"錯(cuò)誤",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
MessageBox.Show("發(fā)生錯(cuò)誤!圖書借閱未成功!");
initializeScreen();
return;
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyData == Keys.Enter)
{
book_ID = textBox1.Text;
string str = "select * from V_還書 where 圖書條碼號(hào)='" + book_ID + "' and 歸還標(biāo)志=0";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
r_ID = dr.GetString(1);
textBox2.Text = dr.GetString(2);
textBox3.Text = dr.GetString(3);
textBox5.Text = dr.GetInt32(7).ToString();
textBox7.Text = dr.GetString(9);
textBox8.Text = dr.GetString(11);
textBox9.Text = dr.GetString(13);
dc = dr.GetInt32(6);
rc = dr.GetInt32(7);
textBox4.Text = rc.ToString();
if(dr.GetDateTime(17)<DateTime.Now)
{
string cd = Convert.ToString(DateTime.Now.Date-dr.GetDateTime(17).Date).Remove(Convert.ToString(DateTime.Now.Date-dr.GetDateTime(17).Date).IndexOf("."),9);
label2.Text = cd;
label17.Text = Convert.ToString(Convert.ToInt32(cd)*Convert.ToDouble(dr.GetDecimal(8)));
btnReturn.Enabled = false;
btnForfeit.Enabled = true;
isU = true;
}
else
{
btnForfeit.Enabled = false;
btnReturn.Enabled = true;
label2.Text = "0";
label17.Text = "0.00";
isU= false;
}
}
else
{
if(dr!=null)dr.Close();
MessageBox.Show("此條碼對(duì)應(yīng)的圖書未被借出或條形碼錄入錯(cuò)誤!請(qǐng)重新檢查輸入!","錯(cuò)誤",MessageBoxButtons.OK,MessageBoxIcon.Error);
textBox1.SelectAll();
textBox1.Focus();
return;
}
if(dr!=null)dr.Close();
}
catch(Exception ex)
{
if(dr!=null)dr.Close();
MessageBox.Show("發(fā)生錯(cuò)誤!錯(cuò)誤信息如下:\n\t" + ex.ToString(),"錯(cuò)誤",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
listView1.Items.Clear();
ListViewItem item = null;
str = "select * from V_還書 where 借書證號(hào)='" + r_ID + "' and 歸還標(biāo)志=0";
cmd.CommandText = str;
try
{
int i = 0;
dr = cmd.ExecuteReader();
while(dr.Read())
{
i++;
item = new ListViewItem(dr.GetString(0));
item.SubItems.Add(dr.GetString(9));
if(dr.GetDateTime(17)<DateTime.Now)
{
item.SubItems.Add("是");
}
else
{
item.SubItems.Add("否");
}
item.SubItems.Add(dr.GetString(10));
item.SubItems.Add(dr.GetString(11));
item.SubItems.Add(dr.GetDecimal(12).ToString());
item.SubItems.Add(dr.GetString(13));
item.SubItems.Add(dr.GetString(14));
listView1.Items.Add(item);
textBox6.Text = (rc-i).ToString();
}
if(dr!=null)dr.Close();
}
catch(Exception ex)
{
if(dr!=null)dr.Close();
MessageBox.Show("發(fā)生如下錯(cuò)誤:\n\t" + ex.ToString(),"錯(cuò)誤",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -