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

📄 form_jzgcx.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace bizdb
{
	/// <summary>
	/// Form_jzg2 的摘要说明。
	/// </summary>
	public class Form_jzgcx : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lbl_cxtj;
		private System.Windows.Forms.DataGrid dgd_jzgcx;
		private System.Windows.Forms.CheckBox ckb_xm;
		private System.Windows.Forms.CheckBox ckb_xb;
		private System.Windows.Forms.CheckBox ckb_mz;
		private System.Windows.Forms.Button btn_cx;
		private System.Windows.Forms.TextBox txt_xm;
		private System.Windows.Forms.Label lbl_xm;
		private System.Windows.Forms.Label lbl_xb;
		private System.Windows.Forms.Label lbl_mz;
		private System.Windows.Forms.ComboBox cbb_xb;
		private System.Windows.Forms.ComboBox cbb_mz;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form_jzgcx()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.lbl_cxtj = new System.Windows.Forms.Label();
			this.dgd_jzgcx = new System.Windows.Forms.DataGrid();
			this.ckb_xm = new System.Windows.Forms.CheckBox();
			this.ckb_xb = new System.Windows.Forms.CheckBox();
			this.ckb_mz = new System.Windows.Forms.CheckBox();
			this.btn_cx = new System.Windows.Forms.Button();
			this.txt_xm = new System.Windows.Forms.TextBox();
			this.lbl_xm = new System.Windows.Forms.Label();
			this.lbl_xb = new System.Windows.Forms.Label();
			this.lbl_mz = new System.Windows.Forms.Label();
			this.cbb_xb = new System.Windows.Forms.ComboBox();
			this.cbb_mz = new System.Windows.Forms.ComboBox();
			((System.ComponentModel.ISupportInitialize)(this.dgd_jzgcx)).BeginInit();
			this.SuspendLayout();
			// 
			// lbl_cxtj
			// 
			this.lbl_cxtj.Location = new System.Drawing.Point(192, 40);
			this.lbl_cxtj.Name = "lbl_cxtj";
			this.lbl_cxtj.Size = new System.Drawing.Size(80, 16);
			this.lbl_cxtj.TabIndex = 0;
			this.lbl_cxtj.Text = "查询条件:";
			// 
			// dgd_jzgcx
			// 
			this.dgd_jzgcx.DataMember = "";
			this.dgd_jzgcx.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgd_jzgcx.Location = new System.Drawing.Point(0, 248);
			this.dgd_jzgcx.Name = "dgd_jzgcx";
			this.dgd_jzgcx.ReadOnly = true;
			this.dgd_jzgcx.Size = new System.Drawing.Size(792, 320);
			this.dgd_jzgcx.TabIndex = 1;
			this.dgd_jzgcx.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dgd_jzgcx_MouseDown);
			this.dgd_jzgcx.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgd_jzgcx_MouseUp);
			// 
			// ckb_xm
			// 
			this.ckb_xm.Location = new System.Drawing.Point(256, 64);
			this.ckb_xm.Name = "ckb_xm";
			this.ckb_xm.Size = new System.Drawing.Size(16, 24);
			this.ckb_xm.TabIndex = 2;
			this.ckb_xm.CheckedChanged += new System.EventHandler(this.ckb_xm_CheckedChanged);
			// 
			// ckb_xb
			// 
			this.ckb_xb.Location = new System.Drawing.Point(256, 104);
			this.ckb_xb.Name = "ckb_xb";
			this.ckb_xb.Size = new System.Drawing.Size(16, 24);
			this.ckb_xb.TabIndex = 3;
			this.ckb_xb.CheckedChanged += new System.EventHandler(this.ckb_xb_CheckedChanged);
			// 
			// ckb_mz
			// 
			this.ckb_mz.Location = new System.Drawing.Point(256, 144);
			this.ckb_mz.Name = "ckb_mz";
			this.ckb_mz.Size = new System.Drawing.Size(16, 24);
			this.ckb_mz.TabIndex = 4;
			this.ckb_mz.CheckedChanged += new System.EventHandler(this.ckb_mz_CheckedChanged);
			// 
			// btn_cx
			// 
			this.btn_cx.Location = new System.Drawing.Point(472, 104);
			this.btn_cx.Name = "btn_cx";
			this.btn_cx.Size = new System.Drawing.Size(56, 23);
			this.btn_cx.TabIndex = 6;
			this.btn_cx.Text = "查询";
			this.btn_cx.Click += new System.EventHandler(this.btn_cx_Click);
			// 
			// txt_xm
			// 
			this.txt_xm.Location = new System.Drawing.Point(280, 64);
			this.txt_xm.Name = "txt_xm";
			this.txt_xm.TabIndex = 7;
			this.txt_xm.Text = "";
			// 
			// lbl_xm
			// 
			this.lbl_xm.Location = new System.Drawing.Point(392, 64);
			this.lbl_xm.Name = "lbl_xm";
			this.lbl_xm.Size = new System.Drawing.Size(32, 16);
			this.lbl_xm.TabIndex = 10;
			this.lbl_xm.Text = "姓名";
			// 
			// lbl_xb
			// 
			this.lbl_xb.Location = new System.Drawing.Point(392, 104);
			this.lbl_xb.Name = "lbl_xb";
			this.lbl_xb.Size = new System.Drawing.Size(32, 16);
			this.lbl_xb.TabIndex = 11;
			this.lbl_xb.Text = "性别";
			// 
			// lbl_mz
			// 
			this.lbl_mz.Location = new System.Drawing.Point(392, 144);
			this.lbl_mz.Name = "lbl_mz";
			this.lbl_mz.Size = new System.Drawing.Size(32, 16);
			this.lbl_mz.TabIndex = 12;
			this.lbl_mz.Text = "民族";
			// 
			// cbb_xb
			// 
			this.cbb_xb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cbb_xb.Location = new System.Drawing.Point(280, 104);
			this.cbb_xb.Name = "cbb_xb";
			this.cbb_xb.Size = new System.Drawing.Size(104, 20);
			this.cbb_xb.TabIndex = 13;
			// 
			// cbb_mz
			// 
			this.cbb_mz.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cbb_mz.Location = new System.Drawing.Point(280, 144);
			this.cbb_mz.Name = "cbb_mz";
			this.cbb_mz.Size = new System.Drawing.Size(104, 20);
			this.cbb_mz.TabIndex = 14;
			// 
			// Form_jzgcx
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.cbb_mz,
																		  this.cbb_xb,
																		  this.lbl_mz,
																		  this.lbl_xb,
																		  this.lbl_xm,
																		  this.txt_xm,
																		  this.btn_cx,
																		  this.ckb_mz,
																		  this.ckb_xb,
																		  this.ckb_xm,
																		  this.dgd_jzgcx,
																		  this.lbl_cxtj});
			this.Name = "Form_jzgcx";
			this.Text = "教职工资料查询";
			this.Load += new System.EventHandler(this.Form_jzgcx_Load);
			((System.ComponentModel.ISupportInitialize)(this.dgd_jzgcx)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void Form_jzgcx_Load(object sender, System.EventArgs e)
		{
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.ControlBox = false;
			this.cbb_mz.Enabled = false;
			this.cbb_xb.Enabled=false;
			this.txt_xm.Enabled=false;
			this.Combo_Add();
		}

		private void btn_cx_Click(object sender, System.EventArgs e)
		{
			dbAccess dba=new dbAccess();
			string sel="";
			string select="Select emp_id as '教职工编号',emp_name as '姓名',sex.sex_name as '性别',nation.nat_name as '民族',"
				+"emp_birthday as '出生年月',nativePlace.natp_name as '籍贯',PoliticalFeature.polf_name as '政治面貌',"
				+"Maritalstatus.mars_name as '婚姻状况',emp_identityNo as '身份证号',emp_address as '联系地址',"
				+"emp_tel as '联系电话',emp_email as '电子邮箱',emp_postcode as '邮政编码',emp_hometel as '家庭住址',"
				+"emp_hometel as '家庭电话',cultureDegree.culd_name as '文化程度',emp_college as '毕业院校',"
				+"emp_speciality as '专业',technicalPosition.tecp_name as '专业技术职务',emp_CertificateNo as '教师资格证编号',"
				+"emp_certificateDate as '发证日期',emp_certificateDept as '发证部门',emp_isTeacher as '是否教师',"
				+"emp_propositionFirst as '首次参与命题时间',emp_propositionRecent as '最近参与命题时间',"
				+"role.rol_name as '角色',emp_memo as '备注' from Employee,sex,nation,technicalPosition,Maritalstatus,role,"
				+"PoliticalFeature,cultureDegree,nativePlace where sex.sex_code=Employee.sex_code and"
				+" nation.nat_code=Employee.nat_code and technicalPosition.tecp_code=Employee.tecp_code "
				+"and Maritalstatus.mars_code=Employee.mars_code and PoliticalFeature.polf_code=Employee.polf_code "
				+"and cultureDegree.culd_code=Employee.culd_code and nativePlace.natp_code = Employee.natp_code"
				+" and role.rol_no=Employee.rol_no";
			if (this.ckb_xm.Checked)
				select += " and Employee.emp_name like '%" + this.txt_xm.Text+"%'";
			if (this.ckb_xb.Checked)
				select += " and sex.sex_name like '%" + this.cbb_xb.Text+"%'";
			if (this.ckb_mz.Checked)
				select += " and nation.nat_name like '%" + this.cbb_mz.Text+"%'";
			if (select.Length > 469)
			{
				try
				{
					sel=select;
					System.Data.SqlClient.SqlConnection sqlcon=new System.Data.SqlClient.SqlConnection(dba.connStr);
					sqlcon.Open();
					System.Data.SqlClient.SqlDataAdapter sqldat=new System.Data.SqlClient.SqlDataAdapter(sel,sqlcon);
					System.Data.DataSet dst=new System.Data.DataSet();
					sqldat.Fill(dst,"Employee");
					this.dgd_jzgcx.DataSource=dst;
					this.dgd_jzgcx.DataMember="Employee";
					sqlcon.Close();
					for (int i=0;i<dst.Tables["Employee"].Rows.Count;i++)
					{
						if (dst.Tables["Employee"].Rows[i]["是否教师"].ToString()=="0")
						{
							dst.Tables["Employee"].Rows[i]["是否教师"]='是';
						}	
						else
						{
							dst.Tables["Employee"].Rows[i]["是否教师"]='否';
						}		
					}
				}
				catch(System.Exception error)
				{
					MessageBox.Show(error.Message);
				}
			}
			else
			{
				try
				{
					sel=select.Substring(0,select.Length-5);
					System.Data.SqlClient.SqlConnection sqlcon_all=new System.Data.SqlClient.SqlConnection(dba.connStr);
					sqlcon_all.Open();
					System.Data.SqlClient.SqlDataAdapter sqldat_all=new System.Data.SqlClient.SqlDataAdapter(sel,sqlcon_all);
					System.Data.DataSet dst_all=new System.Data.DataSet();
					sqldat_all.Fill(dst_all,"Employee");
					this.dgd_jzgcx.DataSource=dst_all;
					this.dgd_jzgcx.DataMember="Employee";
					sqlcon_all.Close();
					for (int i=0;i<dst_all.Tables["Employee"].Rows.Count;i++)
					{
						if (dst_all.Tables["Employee"].Rows[i]["是否教师"].ToString()=="0")
						{
							dst_all.Tables["Employee"].Rows[i]["是否教师"]='是';
						}	
						else
						{
							dst_all.Tables["Employee"].Rows[i]["是否教师"]='否';
						}		
					}
				}
				catch(System.Exception error)
				{
					MessageBox.Show(error.Message);
				}
			}
		}

		private void ckb_xm_CheckedChanged(object sender, System.EventArgs e)
		{
			if(this.ckb_xm.Checked)
				this.txt_xm.Enabled=true;
			else
			{
				this.txt_xm.Enabled=false;
				this.txt_xm.Text="";
			}
		}

		private void ckb_xb_CheckedChanged(object sender, System.EventArgs e)
		{
			if(this.ckb_xb.Checked)
				this.cbb_xb.Enabled=true;
			else
			{
				this.cbb_xb.Enabled=false;
				this.cbb_xb.Text="";
			}
		}

		private void ckb_mz_CheckedChanged(object sender, System.EventArgs e)
		{
			if(this.ckb_mz.Checked)
				this.cbb_mz.Enabled=true;
			else
			{
				this.cbb_mz.Enabled=false;
				this.cbb_mz.Text="";
			}
		}

		private void dgd_jzgcx_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
		
		}

		private void dgd_jzgcx_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button==System.Windows.Forms.MouseButtons.Left)
			{
				Point pt = new Point(e.X,e.Y);
				DataGrid.HitTestInfo hit = this.dgd_jzgcx.HitTest(pt);
				if(hit.Type == DataGrid.HitTestType.Cell)
				{
					this.dgd_jzgcx.Select(hit.Row);
				}
			}
		}
		private void Combo_Add()
		{
			dbAccess dba=new dbAccess();
			try
			{
				System.Data.DataSet dat_mb=new System.Data.DataSet();
				System.Data.SqlClient.SqlCommand sqlcom_sex=new System.Data.SqlClient.SqlCommand();
				System.Data.SqlClient.SqlConnection sqlcon=new System.Data.SqlClient.SqlConnection();
				System.Data.SqlClient.SqlDataAdapter sqlada_mb=new System.Data.SqlClient.SqlDataAdapter("select * from sex",
					dba.connStr);
				sqlada_mb.Fill(dat_mb,"sex");
				foreach (System.Data.DataRow dater in dat_mb.Tables["sex"].Rows )
				{
					this.cbb_xb.Items.Add(dater[1]);
				}
			}
			catch(System.Exception m)
			{
				MessageBox.Show(m.Message);
			}
			try
			{
				System.Data.DataSet dat_mb=new System.Data.DataSet();
				System.Data.SqlClient.SqlCommand sqlcom_sex=new System.Data.SqlClient.SqlCommand();
				System.Data.SqlClient.SqlConnection sqlcon=new System.Data.SqlClient.SqlConnection();
				System.Data.SqlClient.SqlDataAdapter sqlada_mb=new System.Data.SqlClient.SqlDataAdapter("select * from nation",
					dba.connStr);
				sqlada_mb.Fill(dat_mb,"nation");
				foreach (System.Data.DataRow dater in dat_mb.Tables["nation"].Rows )
				{
					this.cbb_mz.Items.Add(dater[1]);
				}
			}
			catch(System.Exception m)
			{
				MessageBox.Show(m.Message);
			}
		}
	}
}

⌨️ 快捷键说明

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