📄 stud_search.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>
/// 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_Bj;
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 Student_Xh as 学号,Student_Xm as 姓名,Student_Sex as 性别 ,Student_Csrq as 出生日期,Student_Addr as 家庭地址,Student_Tel as 电话号码,Student_Class as 班级 from student ";
private string sendtable="student";
private CurrencyManager cmAmend;
private DataTable myTable=new DataTable ();
private DataSet ds=new DataSet();
/// <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_Bj = 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_Bj);
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(8, 240);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(576, 200);
this.groupBox1.TabIndex = 11;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "信息";
//
// txt_count
//
this.txt_count.Location = new System.Drawing.Point(360, 160);
this.txt_count.Name = "txt_count";
this.txt_count.ReadOnly = true;
this.txt_count.Size = new System.Drawing.Size(184, 25);
this.txt_count.TabIndex = 15;
this.txt_count.Text = "";
//
// txt_tel
//
this.txt_tel.Location = new System.Drawing.Point(360, 118);
this.txt_tel.Name = "txt_tel";
this.txt_tel.ReadOnly = true;
this.txt_tel.Size = new System.Drawing.Size(184, 25);
this.txt_tel.TabIndex = 14;
this.txt_tel.Text = "";
//
// txt_csrq
//
this.txt_csrq.Location = new System.Drawing.Point(360, 70);
this.txt_csrq.Name = "txt_csrq";
this.txt_csrq.ReadOnly = true;
this.txt_csrq.Size = new System.Drawing.Size(184, 25);
this.txt_csrq.TabIndex = 13;
this.txt_csrq.Text = "";
//
// txt_addr
//
this.txt_addr.Location = new System.Drawing.Point(360, 30);
this.txt_addr.Name = "txt_addr";
this.txt_addr.ReadOnly = true;
this.txt_addr.Size = new System.Drawing.Size(184, 25);
this.txt_addr.TabIndex = 12;
this.txt_addr.Text = "";
//
// txt_sex
//
this.txt_sex.Location = new System.Drawing.Point(120, 160);
this.txt_sex.Name = "txt_sex";
this.txt_sex.ReadOnly = true;
this.txt_sex.Size = new System.Drawing.Size(112, 25);
this.txt_sex.TabIndex = 11;
this.txt_sex.Text = "";
//
// txt_Bj
//
this.txt_Bj.Location = new System.Drawing.Point(120, 118);
this.txt_Bj.Name = "txt_Bj";
this.txt_Bj.ReadOnly = true;
this.txt_Bj.Size = new System.Drawing.Size(112, 25);
this.txt_Bj.TabIndex = 10;
this.txt_Bj.Text = "";
//
// txt_Xm
//
this.txt_Xm.Location = new System.Drawing.Point(120, 70);
this.txt_Xm.Name = "txt_Xm";
this.txt_Xm.ReadOnly = true;
this.txt_Xm.Size = new System.Drawing.Size(112, 25);
this.txt_Xm.TabIndex = 9;
this.txt_Xm.Text = "";
//
// txt_Xh
//
this.txt_Xh.Location = new System.Drawing.Point(120, 30);
this.txt_Xh.Name = "txt_Xh";
this.txt_Xh.ReadOnly = true;
this.txt_Xh.Size = new System.Drawing.Size(112, 25);
this.txt_Xh.TabIndex = 8;
this.txt_Xh.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(272, 72);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(72, 23);
this.label6.TabIndex = 5;
this.label6.Text = "出生日期";
//
// label3
//
this.label3.Location = new System.Drawing.Point(32, 120);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 23);
this.label3.TabIndex = 2;
this.label3.Text = "班 级";
//
// label5
//
this.label5.Location = new System.Drawing.Point(272, 32);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(72, 23);
this.label5.TabIndex = 4;
this.label5.Text = "地 址";
//
// label8
//
this.label8.Location = new System.Drawing.Point(272, 162);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(72, 23);
this.label8.TabIndex = 7;
this.label8.Text = "记录条数";
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 1;
this.label2.Text = "姓 名";
//
// label4
//
this.label4.Location = new System.Drawing.Point(32, 162);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 23);
this.label4.TabIndex = 3;
this.label4.Text = "性 别";
//
// label7
//
this.label7.Location = new System.Drawing.Point(272, 120);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(72, 23);
this.label7.TabIndex = 6;
this.label7.Text = "联系电话";
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
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(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(576, 224);
this.dataGrid1.TabIndex = 10;
this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 464);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(144, 32);
this.button1.TabIndex = 12;
this.button1.Text = "输入查询条件";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(216, 464);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(144, 32);
this.button2.TabIndex = 13;
this.button2.Text = "确定查询";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(392, 464);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(144, 32);
this.button3.TabIndex = 14;
this.button3.Text = "退出";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Stud_search
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(592, 503);
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_Bj.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_Bj.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_Bj.Text .Trim()!="")
strRowFilter +="Convert(班级,'System.String') like'%"+this.txt_Bj.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_Bj.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_Bj.DataBindings.Add("Text",myTable,"班级");
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&¤tRowNumber<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 + -