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

📄 bookreturn.cs

📁 简单的图书管理系统1、系统功能的基本要求: (1)图书信息的输入
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 图书馆管理系统
{
	/// <summary>
	/// BookReturn 的摘要说明。
	/// </summary>
	public class BookReturn : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button btnSearch;
		private System.Windows.Forms.TextBox txt1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txt2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txt3;
		private System.Data.SqlClient.SqlDataAdapter da1;
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		private 图书馆管理系统.DataSet2 dataSet21;
		private System.Windows.Forms.Button btnReturn;
		private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public BookReturn()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(BookReturn));
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnSearch = new System.Windows.Forms.Button();
			this.txt1 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.txt2 = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.txt3 = new System.Windows.Forms.TextBox();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.dataSet21 = new 图书馆管理系统.DataSet2();
			this.btnReturn = new System.Windows.Forms.Button();
			this.da1 = new System.Data.SqlClient.SqlDataAdapter();
			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.btnSearch);
			this.groupBox1.Controls.Add(this.txt1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.txt2);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.txt3);
			this.groupBox1.Location = new System.Drawing.Point(6, 4);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(642, 60);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			// 
			// btnSearch
			// 
			this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
			this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnSearch.Location = new System.Drawing.Point(16, 26);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new System.Drawing.Size(72, 23);
			this.btnSearch.TabIndex = 3;
			this.btnSearch.Text = " 搜索";
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			// 
			// txt1
			// 
			this.txt1.Location = new System.Drawing.Point(155, 25);
			this.txt1.Name = "txt1";
			this.txt1.TabIndex = 8;
			this.txt1.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(104, 29);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 6;
			this.label2.Text = "读者编号";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(288, 29);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 4;
			this.label1.Text = "图书编号";
			// 
			// txt2
			// 
			this.txt2.Location = new System.Drawing.Point(347, 25);
			this.txt2.Name = "txt2";
			this.txt2.TabIndex = 9;
			this.txt2.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(472, 29);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 16);
			this.label3.TabIndex = 5;
			this.label3.Text = "读者姓名";
			// 
			// txt3
			// 
			this.txt3.Location = new System.Drawing.Point(528, 25);
			this.txt3.Name = "txt3";
			this.txt3.TabIndex = 7;
			this.txt3.Text = "";
			// 
			// dataGrid1
			// 
			this.dataGrid1.CaptionVisible = false;
			this.dataGrid1.DataMember = "图书借阅";
			this.dataGrid1.DataSource = this.dataSet21;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(8, 64);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(640, 360);
			this.dataGrid1.TabIndex = 1;
			// 
			// dataSet21
			// 
			this.dataSet21.DataSetName = "DataSet2";
			this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// btnReturn
			// 
			this.btnReturn.Location = new System.Drawing.Point(144, 448);
			this.btnReturn.Name = "btnReturn";
			this.btnReturn.Size = new System.Drawing.Size(144, 40);
			this.btnReturn.TabIndex = 2;
			this.btnReturn.Text = "归还选中图书";
			this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
			// 
			// da1
			// 
			this.da1.SelectCommand = this.sqlSelectCommand1;
			this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																						  new System.Data.Common.DataTableMapping("Table", "图书借阅", new System.Data.Common.DataColumnMapping[] {
																																																  new System.Data.Common.DataColumnMapping("借阅编号", "借阅编号"),
																																																  new System.Data.Common.DataColumnMapping("姓名", "姓名"),
																																																  new System.Data.Common.DataColumnMapping("读者编号", "读者编号"),
																																																  new System.Data.Common.DataColumnMapping("图书编号", "图书编号"),
																																																  new System.Data.Common.DataColumnMapping("书名", "书名"),
																																																  new System.Data.Common.DataColumnMapping("借阅时间", "借阅时间"),
																																																  new System.Data.Common.DataColumnMapping("应还时间", "应还时间"),
																																																  new System.Data.Common.DataColumnMapping("续借次数", "续借次数"),
																																																  new System.Data.Common.DataColumnMapping("操作员", "操作员"),
																																																  new System.Data.Common.DataColumnMapping("状态", "状态")})});
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = @"SELECT a.借阅编号, b.姓名, a.读者编号, a.图书编号, c.书名, a.借阅时间, a.应还时间, a.续借次数, a.操作员, a.状态 FROM 图书借阅 a INNER JOIN 读者信息 b ON a.读者编号 = b.编号 INNER JOIN 图书信息 c ON a.图书编号 = c.编号 WHERE (a.读者编号 LIKE @Param14) AND (a.图书编号 LIKE @Param15) AND (b.姓名 LIKE @Param16) AND (a.状态 = '未还')";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param14", System.Data.SqlDbType.VarChar, 40, "读者编号"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param15", System.Data.SqlDbType.VarChar, 50, "图书编号"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param16", System.Data.SqlDbType.VarChar, 20, "姓名"));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=libbook;";
			// 
			// BookReturn
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(656, 510);
			this.Controls.Add(this.btnReturn);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.groupBox1);
			this.Name = "BookReturn";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "【图书归还】";
			this.Load += new System.EventHandler(this.BookReturn_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		//------------初始化窗体时,填充数据-------------
		private void BookReturn_Load(object sender, System.EventArgs e)
		{
			da1.SelectCommand.Parameters[0].Value="%%";
			da1.SelectCommand.Parameters[1].Value="%%";
			da1.SelectCommand.Parameters[2].Value="%%";
			da1.Fill(dataSet21);
		
		}

		//-----------搜索借书记录-----------
		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			da1.SelectCommand.Parameters[0].Value="%%";
			da1.SelectCommand.Parameters[1].Value="%%";
			da1.SelectCommand.Parameters[2].Value="%%";
			if(txt1.Text!="")
			{
				da1.SelectCommand.Parameters[0].Value="%"+txt1.Text+"%";
			}
			if(txt2.Text!="")
			{
				da1.SelectCommand.Parameters[1].Value="%"+txt2.Text+"%";
			}
			if(txt3.Text!="")
			{
				da1.SelectCommand.Parameters[2].Value="%"+txt3.Text+"%";
			}
			dataSet21.图书借阅.Clear();
			da1.Fill(dataSet21);
		}

		//--------读者还书----------
		private void btnReturn_Click(object sender, System.EventArgs e)
		{
			int curRow=dataGrid1.CurrentCell.RowNumber;
			string borrowID=dataGrid1[curRow,0].ToString().Trim();//借阅编号
			DateTime returnTime=Convert.ToDateTime(dataGrid1[curRow,6]);//应还时间
			decimal penalty=0;
			if(returnTime<System.DateTime.Now)
			{
				penalty=calPenalty(returnTime);
			}
			if(penalty!=0)//提示需要支付罚金的读者
			{
				string msg="该图书应于"+returnTime+"归还,必须支付过期罚金"+penalty.ToString()+"元";
				MessageBox.Show(msg,"图书过期",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
			string strConn = "workstation id=localhost;Integrated Security=SSPI;database=libbook";
			SqlConnection cn=new SqlConnection(strConn);
			cn.Open();
			SqlCommand cmd=cn.CreateCommand();
			cmd.CommandText="exec sf_图书归还 "+borrowID+","+penalty.ToString();
			cmd.ExecuteNonQuery();
			dataSet21.图书借阅.Clear();
			da1.Fill(dataSet21);
			
			
			
		}
		//-----------计算过期书罚金------------
		private decimal calPenalty(DateTime rTime)
		{
            //计算过期天数
			int overDays=365*(System.DateTime.Now.Year-rTime.Year)+System.DateTime.Now.DayOfYear-rTime.DayOfYear;
			//根据过期天数计算罚金,本实例中定为每天0.2元
			decimal fee=(decimal) 0.2*overDays;
			return(fee);			
		}
	}
}

⌨️ 快捷键说明

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