?? registerlossbooks.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>
/// RegisterLossBooks 的摘要說明。
/// </summary>
public class RegisterLossBooks : 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.TextBox textBox1;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
private SqlCommand cmd;
private SqlDataReader dr;
public RegisterLossBooks()
{
//
// 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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(136, 104);
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(224, 104);
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.FlatStyle = System.Windows.Forms.FlatStyle.System;
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 = "圖書條碼";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(24, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(272, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
//
// RegisterLossBooks
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(322, 152);
this.ControlBox = false;
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "RegisterLossBooks";
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>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
string str = "";
str = "select * from 圖書資料 where 條形碼='" + textBox1.Text + "'";
str = "select * from 讀者借書 where 圖書條碼號='" + textBox1.Text + "'";
str = "update 圖書資料 set 掛失標志=1 where 條形碼='" + textBox1.Text + "'";
//創建事務
SqlTransaction trans = Global.conn.BeginTransaction();
cmd.Transaction = trans;
try
{
cmd.CommandText = str;
cmd.ExecuteNonQuery();
cmd.CommandText = str;
cmd.ExecuteNonQuery();
trans.Commit();
}
catch
{
try
{
trans.Rollback();
}
catch (SqlException ex)
{
if (trans.Connection != null)
{
MessageBox.Show(ex.ToString());
}
}
MessageBox.Show("發生錯誤!圖書借閱未成功!");
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 + -