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

📄 frmlendreturn.cs

📁 小型图书管理系统,C#和SQlServer构建,Winform桌面应用程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

using library.VisiteDB;

namespace library.Forms
{
	/// <summary>
	/// frmLend 的摘要说明。
	/// </summary>
	public class frmLendReturn : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ListBox ltbUser;
		private System.Windows.Forms.TextBox tbPassword;
		private System.Windows.Forms.ListBox ltbBook;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancle;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private DataEngine de = new DataEngine();
		public static string state = "";

		public frmLendReturn()
		{
			InitializeComponent();
			this.fillData();
		}

		public void fillData()
		{
			DataSet ds = new DataSet();

//			de.getAvailableUser(ds);
//			for(int i = 0; i < ds.Tables["AvailableUser"].Rows.Count; i++)
//			{
//				ltbUser.Items.Add(ds.Tables["AvailableUser"].Rows[i].ItemArray[0]);
//			}
//
//			de.getAvailableBook(ds);
//			for(int i = 0; i < ds.Tables["AvailableBook"].Rows.Count; i++)
//			{
//				ltbBook.Items.Add(ds.Tables["AvailableBook"].Rows[i].ItemArray[1]);
//			}
			
			if(state == "lend")
			{
				this.Text = "借书";

				de.getNotLendUser(ds);
				ltbUser.DataSource=ds.Tables["NotLendUser"];
				ltbUser.DisplayMember="username";
				ltbUser.ValueMember="userid";

				de.getNotLendBook(ds);
				ltbBook.DataSource=ds.Tables["NotLendBook"];
				ltbBook.DisplayMember="bookname";
				ltbBook.ValueMember="bookid";
			}
			else if(state == "return")
			{
				this.Text = "还书";

				de.getHasLendUser(ds);
				ltbUser.DataSource=ds.Tables["HasLendUser"];
				ltbUser.DisplayMember="username";
				ltbUser.ValueMember="userid";

				de.getHasLendBook(ds);
				ltbBook.DataSource=ds.Tables["HasLendBook"];
				ltbBook.DisplayMember="bookname";
				ltbBook.ValueMember="bookid";
			}
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.tbPassword = new System.Windows.Forms.TextBox();
			this.ltbUser = new System.Windows.Forms.ListBox();
			this.ltbBook = new System.Windows.Forms.ListBox();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCancle = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 24);
			this.label1.TabIndex = 0;
			this.label1.Text = "用户";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.Location = new System.Drawing.Point(16, 192);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 24);
			this.label2.TabIndex = 1;
			this.label2.Text = "密码";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(16, 104);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(40, 24);
			this.label3.TabIndex = 2;
			this.label3.Text = "图书";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// tbPassword
			// 
			this.tbPassword.Location = new System.Drawing.Point(88, 192);
			this.tbPassword.Name = "tbPassword";
			this.tbPassword.PasswordChar = '*';
			this.tbPassword.Size = new System.Drawing.Size(168, 21);
			this.tbPassword.TabIndex = 5;
			this.tbPassword.Text = "";
			// 
			// ltbUser
			// 
			this.ltbUser.ItemHeight = 12;
			this.ltbUser.Location = new System.Drawing.Point(88, 16);
			this.ltbUser.Name = "ltbUser";
			this.ltbUser.ScrollAlwaysVisible = true;
			this.ltbUser.Size = new System.Drawing.Size(168, 64);
			this.ltbUser.TabIndex = 6;
			// 
			// ltbBook
			// 
			this.ltbBook.ItemHeight = 12;
			this.ltbBook.Location = new System.Drawing.Point(88, 96);
			this.ltbBook.Name = "ltbBook";
			this.ltbBook.ScrollAlwaysVisible = true;
			this.ltbBook.Size = new System.Drawing.Size(168, 76);
			this.ltbBook.TabIndex = 7;
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(48, 248);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(72, 24);
			this.btnOK.TabIndex = 8;
			this.btnOK.Text = "提交";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnCancle
			// 
			this.btnCancle.Location = new System.Drawing.Point(168, 248);
			this.btnCancle.Name = "btnCancle";
			this.btnCancle.Size = new System.Drawing.Size(72, 24);
			this.btnCancle.TabIndex = 9;
			this.btnCancle.Text = "取消";
			this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
			// 
			// frmLend
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(304, 294);
			this.Controls.Add(this.btnCancle);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.ltbBook);
			this.Controls.Add(this.ltbUser);
			this.Controls.Add(this.tbPassword);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "frmLend";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			if(ltbUser.SelectedIndex == -1)
			{
				MessageBox.Show("请选择用户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			else if(ltbBook.SelectedIndex == -1)
			{
				MessageBox.Show("请选择图书!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			else if(tbPassword.Text == "")
			{
				MessageBox.Show("请输入密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}

			string strUser = ltbUser.Text;
			string strBook = ltbBook.Text;
			int bookId=int.Parse(ltbBook.SelectedValue.ToString());
			int userId=int.Parse(ltbUser.SelectedValue.ToString());
			bool result = de.checkUser(strUser, tbPassword.Text);

			if(result == true && state == "lend")
			{
				de.LendBook(userId, bookId);
				this.Dispose();
			}

			else if(result == true && frmLendReturn.state == "return")
			{
				de.ReturnBook(userId, bookId);
				this.Dispose();
			}

			else
			{
				MessageBox.Show("密码错误, 重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
			}
		}

		private void btnCancle_Click(object sender, System.EventArgs e)
		{
			this.Dispose();
		}
	}
}

⌨️ 快捷键说明

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