fm_imformq.cs
来自「招聘考试成绩管理系统,自己做的,C#的,我的软件工程作业」· CS 代码 · 共 254 行
CS
254 行
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace 招聘考试成绩管理系统
{
/// <summary>
/// fm_imformq 的摘要说明。
/// </summary>
public class fm_imformq : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private 招聘考试成绩管理系统.DataSet1 dataSet11;
private System.Data.SqlClient.SqlCommand sqlCommand1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btquery;
private System.Windows.Forms.ComboBox comboBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public fm_imformq()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// 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.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new 招聘考试成绩管理系统.DataSet1();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.textBox1 = new System.Windows.Forms.TextBox();
this.comboBox = new System.Windows.Forms.ComboBox();
this.btquery = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"GHX-82E19EF0633\";packet size=4096;integrated security=SSPI;data s" +
"ource=\".\";persist security info=False;initial catalog=zhaopin";
//
// sqlDataAdapter1
//
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", "vstudent", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("准考证号", "准考证号"),
new System.Data.Common.DataColumnMapping("姓名", "姓名"),
new System.Data.Common.DataColumnMapping("性别", "性别"),
new System.Data.Common.DataColumnMapping("生日", "生日"),
new System.Data.Common.DataColumnMapping("地址", "地址"),
new System.Data.Common.DataColumnMapping("身份证", "身份证"),
new System.Data.Common.DataColumnMapping("电话", "电话")})});
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO vstudent(准考证号, 姓名, 性别, 生日, 地址, 身份证, 电话) VALUES (@准考证号, @姓名, @性别, @生日," +
" @地址, @身份证, @电话); SELECT 准考证号, 姓名, 性别, 生日, 地址, 身份证, 电话 FROM vstudent";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@准考证号", System.Data.SqlDbType.VarChar, 6, "准考证号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@姓名", System.Data.SqlDbType.VarChar, 10, "姓名"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@性别", System.Data.SqlDbType.VarChar, 10, "性别"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@生日", System.Data.SqlDbType.VarChar, 20, "生日"));
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, 20, "身份证"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@电话", System.Data.SqlDbType.VarChar, 20, "电话"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 准考证号, 姓名, 性别, 生日, 地址, 身份证, 电话 FROM vstudent";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// sqlCommand1
//
this.sqlCommand1.Connection = this.sqlConnection1;
this.sqlCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Zno", System.Data.SqlDbType.Char, 6));
this.sqlCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.Char, 10));
//
// dataGrid1
//
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.DataSource = this.dataSet11.vstudent;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 104);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.RowHeadersVisible = false;
this.dataGrid1.Size = new System.Drawing.Size(530, 264);
this.dataGrid1.TabIndex = 1;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(296, 74);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// comboBox
//
this.comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox.ForeColor = System.Drawing.SystemColors.WindowFrame;
this.comboBox.Items.AddRange(new object[] {
"姓名",
"准考证号码"});
this.comboBox.Location = new System.Drawing.Point(88, 75);
this.comboBox.Name = "comboBox";
this.comboBox.Size = new System.Drawing.Size(121, 20);
this.comboBox.Sorted = true;
this.comboBox.TabIndex = 3;
//
// btquery
//
this.btquery.Location = new System.Drawing.Point(416, 72);
this.btquery.Name = "btquery";
this.btquery.TabIndex = 4;
this.btquery.Text = "查询";
this.btquery.Click += new System.EventHandler(this.btquery_Click);
//
// label2
//
this.label2.Font = new System.Drawing.Font("华文楷体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(192, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(136, 24);
this.label2.TabIndex = 5;
this.label2.Text = "考生信息查询";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 79);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 16);
this.label3.TabIndex = 6;
this.label3.Text = "查询类型:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(224, 79);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 16);
this.label4.TabIndex = 7;
this.label4.Text = "关键字:";
//
// fm_imformq
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(560, 374);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.btquery);
this.Controls.Add(this.comboBox);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.dataGrid1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "fm_imformq";
this.Text = "考生信息查询";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.fm_imformq_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void fm_imformq_Load(object sender, System.EventArgs e)
{
this.comboBox.SelectedIndex =1;
sqlDataAdapter1.Fill(dataSet11,"vstudent");
}
private void btquery_Click(object sender, System.EventArgs e)
{
try
{
this.sqlCommand1.Parameters[0].Value="%"+this.textBox1.Text+"%";
this.sqlCommand1.Parameters[1].Value="%"+this.textBox1.Text+"%";
string str ="select * from vstudent ";
if(this.comboBox.SelectedIndex==0)
str += "where 姓名 like @Name";
else
str += "where 准考证号 like @Zno ";
this.sqlCommand1.CommandType=CommandType.Text;
this.sqlDataAdapter1.SelectCommand = sqlCommand1;
sqlCommand1.CommandText=str;
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11,"vstudent");
}
catch(Exception oe)
{
this.textBox1.Text=oe.Message;
MessageBox.Show(oe.Message,"Error");
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?