📄 payfine.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Library
{
/// <summary>
/// PayFine 的摘要说明。
/// </summary>
public class PayFine : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label6;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private SqlCommand cmd = null;
private SqlDataReader dr = null;
private bool is_ReturnBooks = false;
public PayFine(string R_ID,string B_ID,string Reason)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
cmd = Global.conn.CreateCommand();
//
//
//
textBox1.Text = R_ID;
textBox1.ReadOnly = false;
textBox2.Text = B_ID;
textBox2.ReadOnly = false;
textBox3.Text = "";
textBox3.ReadOnly = false;
textBox4.Text = Reason;
textBox4.ReadOnly = false;
is_ReturnBooks = false;
}
public PayFine(string R_ID,string B_ID,double Pay,string Reason)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
cmd = Global.conn.CreateCommand();
//
//
//
textBox1.Text = R_ID;
textBox1.ReadOnly = true;
textBox2.Text = B_ID;
textBox2.ReadOnly = true;
textBox3.Text = Pay.ToString();
textBox3.ReadOnly = true;
textBox4.Text = Reason;
textBox4.ReadOnly = false;
is_ReturnBooks = true;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
if(cmd!=null)
{
cmd.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(96, 200);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "缴纳";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button2.Location = new System.Drawing.Point(192, 200);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "关闭";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 17);
this.label1.TabIndex = 2;
this.label1.Text = "借书证号";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(24, 61);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(66, 17);
this.label2.TabIndex = 3;
this.label2.Text = "图书条形码";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(24, 98);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 17);
this.label3.TabIndex = 4;
this.label3.Text = "金额";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(24, 135);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(54, 17);
this.label5.TabIndex = 6;
this.label5.Text = "罚款原因";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 22);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(168, 21);
this.textBox1.TabIndex = 7;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(96, 60);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(168, 21);
this.textBox2.TabIndex = 8;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(96, 98);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(128, 21);
this.textBox3.TabIndex = 9;
this.textBox3.Text = "";
this.textBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(96, 135);
this.textBox4.Multiline = true;
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(168, 40);
this.textBox4.TabIndex = 10;
this.textBox4.Text = "";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(232, 100);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(17, 17);
this.label6.TabIndex = 12;
this.label6.Text = "元";
//
// PayFine
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(290, 240);
this.ControlBox = false;
this.Controls.Add(this.label6);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label5);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "PayFine";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "缴纳罚款";
this.ResumeLayout(false);
}
#endregion
/// <summary>
///
/// </summary>
private void initializeScreen()
{
textBox1.Text = "";
textBox1.ReadOnly = false;
textBox2.Text = "";
textBox2.ReadOnly = false;
textBox3.Text = "";
textBox3.ReadOnly = false;
textBox4.Text = "";
textBox4.ReadOnly = false;
}
/// <summary>
/// 缴纳罚款
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
string str = "";
if(textBox1.Text=="")
{
MessageBox.Show("借书证号不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
textBox1.Focus();
return;
}
if(textBox2.Text=="")
{
MessageBox.Show("图书条形码不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
textBox2.Focus();
return;
}
if(textBox3.Text=="")
{
MessageBox.Show("罚款金额不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
textBox3.Focus();
return;
}
if(textBox4.Text=="")
{
MessageBox.Show("罚款原因不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
textBox4.Focus();
return;
}
string name = "";
str = "select 姓名 from V_借书证 where 借书证号='" + textBox1.Text + "'";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
name = dr.GetString(0);
}
if(dr!=null)dr.Close();
}
catch(Exception ex)
{
if(dr!=null)dr.Close();
MessageBox.Show("发生如下错误:\n\n" + ex.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
str = "insert into 罚款 values('"
+ textBox2.Text + "',"
+ Convert.ToDecimal(textBox3.Text) + ",'"
+ textBox4.Text + "','"
+ name + "','" + DateTime.Now.ToShortDateString() + "')";
cmd.CommandText = str;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("成功缴纳罚款!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
catch(Exception ex)
{
MessageBox.Show("发生如下错误:\n\n" + ex.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
if(is_ReturnBooks)
{
str = "update 流通 set 归还标志=0 where 借书证号='" + textBox1.Text
+ "' and 图书条码号='" + textBox2.Text + "'";
cmd.CommandText = str;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("成功归还图书!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show("发生如下错误:\n\n" + ex.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -