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

📄 frmbooktype.cs

📁 采用C#和SQL Server 2000开发 功能比较全面的图书馆管理系统
💻 CS
字号:
using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Windows.Forms;using System.Data;using System.Data.SqlClient;namespace 图书馆管理系统{	public class frmBookType : 图书馆管理系统.frmBase	{
		internal System.Windows.Forms.GroupBox GroupBox1;
		internal System.Windows.Forms.TextBox txbDays;
		internal System.Windows.Forms.Label Label6;
		internal System.Windows.Forms.TextBox txbName;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.TextBox txbCode;
		internal System.Windows.Forms.Label Label4;
		private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
		private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
		private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
		private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		private 图书馆管理系统.DataSet1 dataSet11;		private System.ComponentModel.IContainer components = null;		public frmBookType()		{			// 该调用是 Windows 窗体设计器所必需的。			InitializeComponent();			// TODO: 在 InitializeComponent 调用后添加任何初始化		}		/// <summary>		/// 清理所有正在使用的资源。		/// </summary>		protected override void Dispose( bool disposing )		{			if( disposing )			{				if (components != null) 				{					components.Dispose();				}			}			base.Dispose( disposing );		}		#region 设计器生成的代码		/// <summary>		/// 设计器支持所需的方法 - 不要使用代码编辑器修改		/// 此方法的内容。		/// </summary>		private void InitializeComponent()		{			this.GroupBox1 = new System.Windows.Forms.GroupBox();
			this.txbDays = new System.Windows.Forms.TextBox();
			this.Label6 = new System.Windows.Forms.Label();
			this.txbName = new System.Windows.Forms.TextBox();
			this.Label5 = new System.Windows.Forms.Label();
			this.txbCode = new System.Windows.Forms.TextBox();
			this.Label4 = new System.Windows.Forms.Label();
			this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
			this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
			this.dataSet11 = new 图书馆管理系统.DataSet1();
			((System.ComponentModel.ISupportInitialize)(this.dgdList)).BeginInit();
			this.GroupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
			this.SuspendLayout();
			// 
			// dgdList
			// 
			this.dgdList.Location = new System.Drawing.Point(6, 76);
			this.dgdList.Name = "dgdList";
			this.dgdList.Size = new System.Drawing.Size(478, 84);
			// 
			// GroupBox1
			// 
			this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.GroupBox1.Controls.Add(this.txbDays);
			this.GroupBox1.Controls.Add(this.Label6);
			this.GroupBox1.Controls.Add(this.txbName);
			this.GroupBox1.Controls.Add(this.Label5);
			this.GroupBox1.Controls.Add(this.txbCode);
			this.GroupBox1.Controls.Add(this.Label4);
			this.GroupBox1.Location = new System.Drawing.Point(8, 158);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(472, 75);
			this.GroupBox1.TabIndex = 8;
			this.GroupBox1.TabStop = false;
			// 
			// txbDays
			// 
			this.txbDays.Location = new System.Drawing.Point(320, 45);
			this.txbDays.Name = "txbDays";
			this.txbDays.Size = new System.Drawing.Size(83, 20);
			this.txbDays.TabIndex = 5;
			this.txbDays.Text = "";
			// 
			// Label6
			// 
			this.Label6.Location = new System.Drawing.Point(320, 22);
			this.Label6.Name = "Label6";
			this.Label6.Size = new System.Drawing.Size(47, 14);
			this.Label6.TabIndex = 4;
			this.Label6.Text = "可借天数";
			// 
			// txbName
			// 
			this.txbName.Location = new System.Drawing.Point(120, 45);
			this.txbName.Name = "txbName";
			this.txbName.Size = new System.Drawing.Size(180, 20);
			this.txbName.TabIndex = 3;
			this.txbName.Text = "";
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(120, 22);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(47, 14);
			this.Label5.TabIndex = 2;
			this.Label5.Text = "类型名称";
			// 
			// txbCode
			// 
			this.txbCode.Location = new System.Drawing.Point(20, 45);
			this.txbCode.Name = "txbCode";
			this.txbCode.Size = new System.Drawing.Size(76, 20);
			this.txbCode.TabIndex = 1;
			this.txbCode.Text = "";
			// 
			// Label4
			// 
			this.Label4.Location = new System.Drawing.Point(20, 22);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(47, 14);
			this.Label4.TabIndex = 0;
			this.Label4.Text = "类型编号";
			// 
			// sqlDataAdapter1
			// 
			this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
			this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
			this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
			this.sqlDataAdapter1.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("可借天数", "可借天数")})});
			this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = "DELETE FROM 图书类型 WHERE (类型编号 = @Original_类型编号) AND (可借天数 = @Original_可借天数 OR @Ori" +
				"ginal_可借天数 IS NULL AND 可借天数 IS NULL) AND (类型名称 = @Original_类型名称 OR @Original_类型名" +
				"称 IS NULL AND 类型名称 IS NULL)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_类型编号", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "类型编号", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_可借天数", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "可借天数", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_类型名称", System.Data.SqlDbType.VarChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "类型名称", System.Data.DataRowVersion.Original, null));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=JEFF;packet size=4096;integrated security=SSPI;data source=JEFF;pe" +
				"rsist security info=False;initial catalog=libbook";
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO 图书类型(类型编号, 类型名称, 可借天数) VALUES (@类型编号, @类型名称, @可借天数); SELECT 类型编号, 类型名" +
				"称, 可借天数 FROM 图书类型 WHERE (类型编号 = @类型编号)";
			this.sqlInsertCommand1.Connection = this.sqlConnection1;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@类型编号", System.Data.SqlDbType.VarChar, 50, "类型编号"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@类型名称", System.Data.SqlDbType.VarChar, 100, "类型名称"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@可借天数", System.Data.SqlDbType.Int, 4, "可借天数"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 类型编号, 类型名称, 可借天数 FROM 图书类型";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = @"UPDATE 图书类型 SET 类型编号 = @类型编号, 类型名称 = @类型名称, 可借天数 = @可借天数 WHERE (类型编号 = @Original_类型编号) AND (可借天数 = @Original_可借天数 OR @Original_可借天数 IS NULL AND 可借天数 IS NULL) AND (类型名称 = @Original_类型名称 OR @Original_类型名称 IS NULL AND 类型名称 IS NULL); SELECT 类型编号, 类型名称, 可借天数 FROM 图书类型 WHERE (类型编号 = @类型编号)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@类型编号", System.Data.SqlDbType.VarChar, 50, "类型编号"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@类型名称", System.Data.SqlDbType.VarChar, 100, "类型名称"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@可借天数", System.Data.SqlDbType.Int, 4, "可借天数"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_类型编号", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "类型编号", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_可借天数", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "可借天数", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_类型名称", System.Data.SqlDbType.VarChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "类型名称", System.Data.DataRowVersion.Original, null));
			// 
			// dataSet11
			// 
			this.dataSet11.DataSetName = "DataSet1";
			this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// frmBookType
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(488, 245);
			this.Controls.Add(this.GroupBox1);
			this.Name = "frmBookType";
			this.Controls.SetChildIndex(this.dgdList, 0);
			this.Controls.SetChildIndex(this.GroupBox1, 0);
			((System.ComponentModel.ISupportInitialize)(this.dgdList)).EndInit();
			this.GroupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
			this.ResumeLayout(false);

		}		#endregion		public override void Prepare()
		{
			this.Text = "图书类型设置";
			Label1.Text = "类型";
			Label2.Visible =false;
			Label3.Visible = false;
			txbTwo.Visible = false;
			txbThree.Visible = false;
		}

		public override void LoadData()
		{
			string strFilter = "";
			if ( txbOne.Text.Trim().Length != 0 )
			{
				if ( txbTwo.Text.Trim().Length == 0 )
					strFilter += "where 类型名称 like '" + txbTwo.Text.Trim() + "%'";
			}
			else
			{
				strFilter = "where 类型编号 like'" + txbOne.Text.Trim() + "%'";
				if ( txbTwo.Text.Trim().Length != 0 )
					strFilter += "and 类型名称 like '" + txbTwo.Text.Trim() + "%'";
			}
			dataSet11.Clear();
			sqlConnection1.ConnectionString = DataBase.sConn;
			sqlDataAdapter1.SelectCommand.CommandText = "select * from 图书类型  " + strFilter;
			sqlDataAdapter1.Fill( dataSet11 );
			dtData = dataSet11.Tables[ "图书类型" ];
			bmData = this.BindingContext[ dataSet11, "图书类型" ];
			if ( bmData.Count != 0 )
			{
				bmData.Position = 0;
			}
		}
		public override void SetDataGrid()
		{
			LoadData();
			DataGridTableStyle ts = new DataGridTableStyle();
			DataGridTextBoxColumn aCol;
			int numCols = dtData.Columns.Count;
			for ( int i = 0; i < numCols; i ++ )
			{
				aCol = new DataGridTextBoxColumn();
				aCol.MappingName = dtData.Columns[ i ].ColumnName;
				aCol.HeaderText = dtData.Columns[ i ].ColumnName;
				aCol.NullText = "";
				aCol.ReadOnly = true;
				ts.GridColumnStyles.Add( aCol );
			}
			ts.AlternatingBackColor = Color.LightGray;
			ts.AllowSorting = false;
			ts.MappingName = dtData.TableName;
			dgdList.TableStyles.Clear();
			dgdList.TableStyles.Add( ts );
			DataView dv = dtData.DefaultView;
			dv.AllowNew = false;
			dv.AllowDelete = false;
			dgdList.DataSource = dv;
			bmData = this.BindingContext[ dataSet11, "图书类型" ];
			lblCount.Text = "记录数:" + dtData.Rows.Count.ToString();
		}		public override void SetTextBoxState(bool bState)
		{
			GroupBox1.Enabled = !bState;
		}
		public override void SaveForUpdate()
		{
			try
			{
				int row = dgdList.CurrentCell.RowNumber;
				dgdList.CurrentCell = new DataGridCell( ( row + 1 ) % bmData.Count, 0 );
				if ( dataSet11.HasChanges() )
					sqlDataAdapter1.Update( dataSet11 );
			}
			catch ( Exception ex )
			{
				MessageBox.Show( ex.ToString() );
			}
		}		public override void DeleteData()
		{
			try
			{
				dataSet11.Tables[ "图书类型" ].Rows[ bmData.Position ].Delete();
				if ( dataSet11.HasChanges() )
					sqlDataAdapter1.Update( dataSet11 );
			}
			catch ( Exception ex )
			{
				MessageBox.Show( ex.ToString() );
			}
		}	}}

⌨️ 快捷键说明

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