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

📄 usercontrol1.cs

📁 图书管理系统,.net2003+sql2000,分为三个模块,用户端,操作员端,系统管理员端.基本上是用自定义控件dll来完成,内含完整sql语句,包括存储过程.
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace 查询Dll
{
	/// <summary>
	/// UserControl1 的摘要说明。
	/// </summary>
	public class UserControl1 : System.Windows.Forms.UserControl
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.RadioButton radioButton1;
		private System.Windows.Forms.RadioButton radioButton2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button button2;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public UserControl1()
		{
			// 该调用是 Windows.Forms 窗体设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitComponent 调用后添加任何初始化

		}
		public UserControl1(string str)
		{
			// 该调用是 Windows.Forms 窗体设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitComponent 调用后添加任何初始化

		}


		/// <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.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
			this.button1 = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 18);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "查询类型";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(184, 18);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "查询内容";
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "题名",
														   "著者",
														   "索取号",
														   ""});
			this.comboBox1.Location = new System.Drawing.Point(88, 16);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(72, 20);
			this.comboBox1.TabIndex = 2;
			this.comboBox1.Text = "题名";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(256, 16);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(104, 21);
			this.textBox1.TabIndex = 3;
			this.textBox1.Text = "";
			// 
			// radioButton1
			// 
			this.radioButton1.Checked = true;
			this.radioButton1.Location = new System.Drawing.Point(24, 48);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(80, 24);
			this.radioButton1.TabIndex = 4;
			this.radioButton1.TabStop = true;
			this.radioButton1.Text = "前方一致";
			// 
			// radioButton2
			// 
			this.radioButton2.Location = new System.Drawing.Point(120, 48);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(72, 24);
			this.radioButton2.TabIndex = 5;
			this.radioButton2.Text = "任意匹配";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.dataGrid1);
			this.groupBox1.Location = new System.Drawing.Point(8, 80);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(752, 440);
			this.groupBox1.TabIndex = 6;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "查询结果";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(8, 16);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(728, 408);
			this.dataGrid1.TabIndex = 0;
			this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
																								  this.dataGridTableStyle1});
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			this.dataGrid1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseMove);
			this.dataGrid1.MouseLeave += new System.EventHandler(this.dataGrid1_MouseLeave);
			// 
			// dataGridTableStyle1
			// 
			this.dataGridTableStyle1.DataGrid = this.dataGrid1;
			this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle1.MappingName = "Bookinfo";
			this.dataGridTableStyle1.PreferredColumnWidth = 150;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(288, 48);
			this.button1.Name = "button1";
			this.button1.TabIndex = 7;
			this.button1.Text = "查询";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(440, 16);
			this.label3.Name = "label3";
			this.label3.TabIndex = 0;
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(400, 48);
			this.button2.Name = "button2";
			this.button2.TabIndex = 8;
			this.button2.Text = "返回";
			this.button2.Visible = false;
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// UserControl1
			// 
			this.Controls.Add(this.button2);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.radioButton2);
			this.Controls.Add(this.radioButton1);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "UserControl1";
			this.Size = new System.Drawing.Size(768, 536);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		private bool clear;//为了对进一步查询进行而设置的变量
		static private bool cleartable=false;//
		private void button1_Click(object sender, System.EventArgs e)
		{
			clear=true;
			cleartable=false;
			this.button2.Visible=false;
			公共数据dll.Store.ds.Clear();
			if(radioButton1.Checked)
			公共数据dll.Store.sqlStr="select distinct 索取号,题名,著者,出版信息 from Bookinfoview where "+comboBox1.Text+" like '"+textBox1.Text+"%'";
			else
				公共数据dll.Store.sqlStr="select distinct 索取号,题名,著者,出版信息 from Bookinfoview where "+comboBox1.Text+" like '%"+textBox1.Text+"%'";
			公共数据dll.Store.cn=new System.Data.SqlClient.SqlConnection(公共数据dll.Store.cnStr);
			公共数据dll.Store.cn.Open();
			公共数据dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
			公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"Bookinfo");
			this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"Bookinfo");
			公共数据dll.Store.cn.Close();
		}
        
		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			if(cleartable==true&&this.button2.Visible!=true)
			{
				公共数据dll.Store.ds.Tables["detail"].Clear();
			}
			if(clear==true)
			{   ///////////////显示button2使它可以返回上一次查询
				this.button2.Visible=true;
			    cleartable=true;
				MessageBox.Show(dataGrid1.CurrentRowIndex.ToString()+dataGrid1.CurrentCell.ToString());
				this.dataGrid1.Size = new System.Drawing.Size(728, 300);//////////改变dataGrid 的大小
				this.label3.Visible=true;
				///////////////////////////////////////////////////////////详细信息的显示
				string s=dataGrid1[dataGrid1.CurrentRowIndex,0].ToString();
				MessageBox.Show(s);
				公共数据dll.Store.sqlStr="select distinct 索取号,条码号,题名,著者,馆藏地,出版信息,书刊状态,书刊借阅状态 from Bookinfoview where 索取号='"+s+"'"; 
				公共数据dll.Store.cn.Open();
				公共数据dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
				公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"detail");
				this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"detail");
				clear=true;
				///////////////////////////////////////////////////////////对附注项的输出
				this.label3.Location = new System.Drawing.Point(20, 400);
				this.label3.Name = "label3";
				this.label3.Size = new System.Drawing.Size(500, 70);
				this.label3.TabIndex = 8;
				this.label3.Text = "本书介绍\n";
				公共数据dll.Store.sqlStr="select 附注项 from Book where 索取号='"+s+"'"; 
				公共数据dll.Store.cmd=new System.Data.SqlClient.SqlCommand(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
				公共数据dll.Store.dr=公共数据dll.Store.cmd.ExecuteReader();
				while(公共数据dll.Store.dr.Read())
				{
					s=公共数据dll.Store.dr["附注项"].ToString();
					this.label3.Text+=s;
				}
				公共数据dll.Store.cn.Close();
				clear=false;
			 }
			
		}

		private void dataGrid1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			DataGrid.HitTestInfo hti=this.dataGrid1.HitTest(e.X,e.Y);
			if(hti.Type==DataGrid.HitTestType.Cell)
			{
					if(hti.Column==1)
					this.Cursor=System.Windows.Forms.Cursors.Hand;
			}
			else
			{
				this.Cursor=System.Windows.Forms.Cursors.Default;
			}
		}

		private void dataGrid1_MouseLeave(object sender, System.EventArgs e)
		{
		}
        //对返回按钮的设置
		private void button2_Click(object sender, System.EventArgs e)
		{
			this.dataGrid1.Size = new System.Drawing.Size(728, 408);
			公共数据dll.Store.cn.Open();
			this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"bookinfo");
			公共数据dll.Store.cn.Close();
			this.button2.Visible=false;
			clear=true;
			this.label3.Visible=false;
		}

	}
}

⌨️ 快捷键说明

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