⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cancelreader.cs

📁 图书馆信息管理系统 Library Information Management System
💻 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>
	/// CancelReader 的摘要说明。
	/// </summary>
	public class CancelReader : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnOK;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		private SqlCommand cmd;
		private SqlDataReader dr;

		public CancelReader()
		{
			//
			// 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.groupBox1 = new System.Windows.Forms.GroupBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.btnClose = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.textBox1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(256, 128);
			this.groupBox1.TabIndex = 5;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "注销读者资料";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(28, 72);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(196, 21);
			this.textBox1.TabIndex = 9;
			this.textBox1.Text = "";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(28, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(66, 17);
			this.label2.TabIndex = 8;
			this.label2.Text = "借书证号码";
			// 
			// btnClose
			// 
			this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnClose.Location = new System.Drawing.Point(192, 160);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 6;
			this.btnClose.Text = "关闭";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// btnOK
			// 
			this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnOK.Location = new System.Drawing.Point(96, 160);
			this.btnOK.Name = "btnOK";
			this.btnOK.TabIndex = 7;
			this.btnOK.Text = "确定";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// CancelReader
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(290, 200);
			this.ControlBox = false;
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "CancelReader";
			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.CancelReader_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void initializeScreen()
		{
			textBox1.Text = "";
			textBox1.Focus();
		}
		/// <summary>
		/// 删除读者记录
		/// </summary>
		/// <param name="id">读者证号码</param>
		private void deleteReader(string id)
		{
			string str = "";
			if(MessageBox.Show("注销借书证会将所有与之相关联的记录全部删除!\n此操作不可恢复!\n\n是否继续?","操作存在风险",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
			{
				str = "delete from 借书证 where 借书证号='" + textBox1.Text + "'";
				//创建事务
				SqlTransaction trans = Global.conn.BeginTransaction();
				cmd.Transaction = trans;
				try
				{
					cmd.CommandText = str;
					cmd.ExecuteNonQuery();
					str = "delete from 流通 where 借书证号='" + textBox1.Text + "'";
					cmd.CommandText = str;
					cmd.ExecuteNonQuery();
					trans.Commit();
					MessageBox.Show("成功删除记录!");
				}
				catch
				{
					try
					{
						trans.Rollback();
					}
					catch (SqlException ex)
					{
						if (trans.Connection != null)
						{
							MessageBox.Show(ex.ToString());
						}
					}
					MessageBox.Show("发生错误!图书借阅未成功!");
					initializeScreen();
					return;
				}
			}
			//string str = "delete";
		}
		/// <summary>
		/// 检查是否存在此借书证
		/// </summary>
		/// <param name="id"></param>
		private void checkCardID(string id)
		{
			string str = "select * from 借书证 where 借书证号='" + id + "'";
			cmd.CommandText = str;
			try
			{
				dr = cmd.ExecuteReader();
				dr.Read();
				if(!dr.HasRows)
				{
					if(dr!=null)dr.Close();
					MessageBox.Show("数据库不存在此借书证!请确保借书证号码填写正确!","错误");
					textBox1.Focus();
					textBox1.SelectAll();
					return;
				}
				if(dr!=null)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 btnClose_Click(object sender, System.EventArgs e)
		{
			Global.sbpGlobal.Text = "就绪";
			this.Close();
		}
		/// <summary>
		/// 确定
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			if(textBox1.Text == "")
			{
				MessageBox.Show("借书证号码不能为空!");
				textBox1.Focus();
			}
			else
			{
				deleteReader(textBox1.Text);
			}
		}
		/// <summary>
		/// 窗体加载代码
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void CancelReader_Load(object sender, System.EventArgs e)
		{
			cmd = Global.conn.CreateCommand();
			initializeScreen();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -