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

📄 stud_search.cs

📁 学生管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace chaxun
{
	/// <summary>
	/// Stud_search 的摘要说明。
	/// </summary>
	public class Stud_search : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox txt_count;
		private System.Windows.Forms.TextBox txt_tel;
		private System.Windows.Forms.TextBox txt_csrq;
		private System.Windows.Forms.TextBox txt_addr;
		private System.Windows.Forms.TextBox txt_sex;
		private System.Windows.Forms.TextBox txt_Xm;
		private System.Windows.Forms.TextBox txt_Xh;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;

		private Class1 link = new Class1 ();
		private string sendSQL=" select xh as 学号,xm as 姓名,xb as 性别 ,csrq as 出生日期,txdz as 家庭地址,lxdf as 电话号码,QQhm as QQ号码 from student ";
		private string sendtable="student";
		private CurrencyManager cmAmend;
		private DataTable myTable=new DataTable ();		
		private DataSet ds=new DataSet();
		private System.Windows.Forms.TextBox txt_qqhm;


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

		public Stud_search()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.ds=link.SelectDataBase(sendSQL,sendtable);
			this.myTable=ds.Tables[0];
			//
			// 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()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.txt_count = new System.Windows.Forms.TextBox();
			this.txt_tel = new System.Windows.Forms.TextBox();
			this.txt_csrq = new System.Windows.Forms.TextBox();
			this.txt_addr = new System.Windows.Forms.TextBox();
			this.txt_sex = new System.Windows.Forms.TextBox();
			this.txt_qqhm = new System.Windows.Forms.TextBox();
			this.txt_Xm = new System.Windows.Forms.TextBox();
			this.txt_Xh = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.txt_count);
			this.groupBox1.Controls.Add(this.txt_tel);
			this.groupBox1.Controls.Add(this.txt_csrq);
			this.groupBox1.Controls.Add(this.txt_addr);
			this.groupBox1.Controls.Add(this.txt_sex);
			this.groupBox1.Controls.Add(this.txt_qqhm);
			this.groupBox1.Controls.Add(this.txt_Xm);
			this.groupBox1.Controls.Add(this.txt_Xh);
			this.groupBox1.Controls.Add(this.label6);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.label8);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.label7);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(6, 187);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(432, 155);
			this.groupBox1.TabIndex = 11;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "信息";
			// 
			// txt_count
			// 
			this.txt_count.Location = new System.Drawing.Point(270, 124);
			this.txt_count.Name = "txt_count";
			this.txt_count.ReadOnly = true;
			this.txt_count.Size = new System.Drawing.Size(138, 21);
			this.txt_count.TabIndex = 15;
			this.txt_count.Text = "";
			// 
			// txt_tel
			// 
			this.txt_tel.Location = new System.Drawing.Point(270, 92);
			this.txt_tel.Name = "txt_tel";
			this.txt_tel.ReadOnly = true;
			this.txt_tel.Size = new System.Drawing.Size(138, 21);
			this.txt_tel.TabIndex = 14;
			this.txt_tel.Text = "";
			// 
			// txt_csrq
			// 
			this.txt_csrq.Location = new System.Drawing.Point(270, 54);
			this.txt_csrq.Name = "txt_csrq";
			this.txt_csrq.ReadOnly = true;
			this.txt_csrq.Size = new System.Drawing.Size(138, 21);
			this.txt_csrq.TabIndex = 13;
			this.txt_csrq.Text = "";
			// 
			// txt_addr
			// 
			this.txt_addr.Location = new System.Drawing.Point(270, 23);
			this.txt_addr.Name = "txt_addr";
			this.txt_addr.ReadOnly = true;
			this.txt_addr.Size = new System.Drawing.Size(138, 21);
			this.txt_addr.TabIndex = 12;
			this.txt_addr.Text = "";
			// 
			// txt_sex
			// 
			this.txt_sex.Location = new System.Drawing.Point(90, 124);
			this.txt_sex.Name = "txt_sex";
			this.txt_sex.ReadOnly = true;
			this.txt_sex.Size = new System.Drawing.Size(84, 21);
			this.txt_sex.TabIndex = 11;
			this.txt_sex.Text = "";
			// 
			// txt_qqhm
			// 
			this.txt_qqhm.Location = new System.Drawing.Point(90, 92);
			this.txt_qqhm.Name = "txt_qqhm";
			this.txt_qqhm.ReadOnly = true;
			this.txt_qqhm.Size = new System.Drawing.Size(84, 21);
			this.txt_qqhm.TabIndex = 10;
			this.txt_qqhm.Text = "";
			// 
			// txt_Xm
			// 
			this.txt_Xm.Location = new System.Drawing.Point(90, 54);
			this.txt_Xm.Name = "txt_Xm";
			this.txt_Xm.ReadOnly = true;
			this.txt_Xm.Size = new System.Drawing.Size(84, 21);
			this.txt_Xm.TabIndex = 9;
			this.txt_Xm.Text = "";
			// 
			// txt_Xh
			// 
			this.txt_Xh.Location = new System.Drawing.Point(90, 23);
			this.txt_Xh.Name = "txt_Xh";
			this.txt_Xh.ReadOnly = true;
			this.txt_Xh.Size = new System.Drawing.Size(84, 21);
			this.txt_Xh.TabIndex = 8;
			this.txt_Xh.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(204, 56);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(54, 18);
			this.label6.TabIndex = 5;
			this.label6.Text = "出生日期";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 93);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(54, 18);
			this.label3.TabIndex = 2;
			this.label3.Text = "QQ号码";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(204, 25);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(54, 18);
			this.label5.TabIndex = 4;
			this.label5.Text = "地    址";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(204, 126);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(54, 18);
			this.label8.TabIndex = 7;
			this.label8.Text = "记录条数";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(24, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(54, 18);
			this.label2.TabIndex = 1;
			this.label2.Text = "姓    名";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 126);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(54, 18);
			this.label4.TabIndex = 3;
			this.label4.Text = "性    别";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(204, 93);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(54, 18);
			this.label7.TabIndex = 6;
			this.label7.Text = "联系电话";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 25);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(60, 18);
			this.label1.TabIndex = 0;
			this.label1.Text = "学    号";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(6, 6);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(432, 174);
			this.dataGrid1.TabIndex = 10;
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(36, 361);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(108, 25);
			this.button1.TabIndex = 12;
			this.button1.Text = "输入查询条件";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(162, 361);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(108, 25);
			this.button2.TabIndex = 13;
			this.button2.Text = "确定查询";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(294, 361);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(108, 25);
			this.button3.TabIndex = 14;
			this.button3.Text = "退出";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// Stud_search
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(444, 391);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.dataGrid1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.Name = "Stud_search";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "学生信息查询";
			this.Load += new System.EventHandler(this.Stud_search_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			this.txt_Xm.ReadOnly = this.txt_Xh.ReadOnly = this.txt_tel.ReadOnly = this.txt_sex.ReadOnly = this.txt_addr.ReadOnly = this.txt_csrq.ReadOnly = this.txt_qqhm.ReadOnly = false;
			this.txt_Xm.Text = this.txt_Xh.Text = this.txt_tel.Text = this.txt_sex.Text = this.txt_addr.Text = this.txt_csrq.Text = this.txt_qqhm.Text = "";
			
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			string strRowFilter="";	
		

			if(this.txt_addr.Text.Trim()!="")
				strRowFilter +="Convert(家庭地址,'System.String') like'%"+this.txt_addr.Text.Trim()+"%' and ";
			if(this.txt_qqhm.Text .Trim()!="")
				strRowFilter +="Convert(QQ号码,'System.String') like'%"+this.txt_qqhm.Text .Trim()+"%' and ";
			if(this.txt_csrq.Text .Trim()!="")
				strRowFilter +="Convert(出生日期,'System.String') like'%"+this.txt_csrq.Text .Trim()+"%' and ";
			if(this.txt_sex.Text .Trim()!="")
				strRowFilter +="Convert(性别,'System.String') like'%"+this.txt_sex.Text .Trim()+"%' and ";

			if(this.txt_tel.Text.Trim()!="")
				strRowFilter +="Convert(电话号码,'System.String') like'%"+this.txt_tel.Text.Trim()+"%' and ";
			if(this.txt_Xh.Text .Trim()!="")
				strRowFilter +="Convert(学号,'System.String') like'%"+this.txt_Xh.Text .Trim()+"%' and ";
			if(this.txt_Xm.Text .Trim()!="")
				strRowFilter +="Convert(姓名,'System.String') like'%"+this.txt_Xm.Text .Trim()+"%' and ";

			if(strRowFilter!="")
				strRowFilter=strRowFilter.Substring(0,strRowFilter.Length-5);

			myTable.DefaultView.RowFilter=strRowFilter;	
			this.txt_Xm.ReadOnly = this.txt_Xh.ReadOnly = this.txt_tel.ReadOnly = this.txt_sex.ReadOnly = this.txt_addr.ReadOnly = this.txt_csrq.ReadOnly = this.txt_qqhm.ReadOnly = true;
			this.txt_count.Text = myTable.DefaultView.Count.ToString();

		}

		private void Stud_search_Load(object sender, System.EventArgs e)
		{
			dataGrid1.DataSource = myTable.DefaultView;	
//			DataBindingsFunction();
//			cmAmend=(CurrencyManager) BindingContext[myTable];
//				
//		}
//		private void DataBindingsFunction()
//		{
//			this.txt_Xh.DataBindings.Add("Text",myTable,"学号");
//			this.txt_Xm.DataBindings.Add("Text",myTable,"姓名");
//			this.txt_sex.DataBindings.Add("Text",myTable,"性别");
//			this.txt_csrq.DataBindings.Add("Text",myTable,"出生日期");
//
//			this.txt_addr.DataBindings.Add("Text",myTable,"家庭地址");
//			this.txt_tel.DataBindings.Add("Text",myTable,"电话号码");
//			this.txt_qqhm.DataBindings.Add("Text",myTable,"QQ号码");
			this.txt_count.Text = myTable.DefaultView.Count.ToString();

		}

		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
//			if(this.myTable.Rows .Count>0)
//			{
//				int currentRowNumber=this.dataGrid1.CurrentCell.RowNumber;
//				if(currentRowNumber>=0&&currentRowNumber<cmAmend.Count)
//				{
//					cmAmend.Position=currentRowNumber;
//				}
//			}
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

⌨️ 快捷键说明

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