?? registerloss.cs
字號:
using System;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Library
{
/// <summary>
/// RegisterLoss 的摘要說明。
/// </summary>
public class RegisterLoss : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btnRegLoss;
private System.Windows.Forms.Label label2;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
private SqlCommand cmd;
private SqlDataReader dr;
public RegisterLoss()
{
//
// Windows 窗體設計器支持所必需的
//
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.btnClose = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.btnRegLoss = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnClose
//
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnClose.Location = new System.Drawing.Point(208, 120);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 2;
this.btnClose.Text = "關閉";
this.btnClose.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(32, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 17);
this.label1.TabIndex = 1;
this.label1.Text = "讀者證號碼:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(32, 64);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(216, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// btnRegLoss
//
this.btnRegLoss.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnRegLoss.Location = new System.Drawing.Point(112, 120);
this.btnRegLoss.Name = "btnRegLoss";
this.btnRegLoss.TabIndex = 1;
this.btnRegLoss.Text = "掛失";
this.btnRegLoss.Click += new System.EventHandler(this.btnRegLoss_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.ForeColor = System.Drawing.Color.Red;
this.label2.Location = new System.Drawing.Point(248, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 17);
this.label2.TabIndex = 4;
this.label2.Text = "<Enter>";
//
// RegisterLoss
//
this.AcceptButton = this.btnRegLoss;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(306, 168);
this.ControlBox = false;
this.Controls.Add(this.label2);
this.Controls.Add(this.btnRegLoss);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnClose);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "RegisterLoss";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "借書證掛失";
this.Load += new System.EventHandler(this.RegisterLoss_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 關閉
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
Global.sbpGlobal.Text = "就緒";
this.Close();
}
private void btnRegLoss_Click(object sender, System.EventArgs e)
{
string str = "select * from 借書證 where 借書證號='" + textBox1.Text + "'";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows!=true)
{
if(dr!=null)dr.Close();
MessageBox.Show("此借書證不存在!請檢查輸入","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
textBox1.SelectAll();
textBox1.Focus();
return;
}
if(dr!=null)dr.Close();
}
catch(Exception ex)
{
if(dr!=null)dr.Close();
MessageBox.Show(ex.ToString(),"錯誤",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
str = "update 借書證 set 借書證狀態=1 where 借書證號='" + textBox1.Text + "'";
cmd.CommandText = str;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("成功掛失此借書證!","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
textBox1.Text = "";
textBox1.Focus();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(),"錯誤",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
/// <summary>
/// 窗體加載代碼
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RegisterLoss_Load(object sender, System.EventArgs e)
{
cmd = Global.conn.CreateCommand();
textBox1.Text = "";
textBox1.Focus();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -