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

📄 form_xyfb.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
📖 第 1 页 / 共 2 页
字号:
		{
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.ControlBox = false;
			Cbo_yxfs.Enabled=false;
			Cbo_skdd.Enabled=false;
			Btn_add.Enabled=false;
			Btn_del.Enabled=false;
			Btn_addall.Enabled=false;
			Btn_delall.Enabled=false;
			Btn_commit.Enabled=false;
			
			//填充专业方向
			strcmd="select spe_name from speciality";
			intocbo(strcmd,"spe_name","专业方向",Cbo_zyb);


			//填充研修方式

			strcmd="select stu_studytype=(case stu_studytype when 1 then '全日制' when 2 then '半脱产' when 3 then '双休日' when 4 then '其他' end) from Student GROUP BY stu_studytype";
			intocbo(strcmd,"stu_studytype","研修方式",Cbo_yxfs);
			

			//填充上课地点
			strcmd="select add_name from address";
			intocbo(strcmd,"add_name","上课地点",Cbo_skdd);

		}

		private void Cbo_zyb_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//填充班级
			Cbo_xzbj.Text="";
			Cbo_xzbj.Items.Clear();
			if(Cbo_skdd.Enabled==true)
				strcmd="select claP_no from classPlan,speciality,knowledgeSystem,coursePlan,address where classPlan.spe_no=speciality.spe_no and speciality.spe_no=knowledgeSystem.spe_no and knowledgeSystem.cou_no=coursePlan.cou_no and coursePlan.add_code=address.add_code and address.add_name='"+Cbo_skdd.Text+"'";
			else
				strcmd="select claP_no from classPlan,speciality where speciality.spe_no=classPlan.spe_no and speciality.spe_name='"+Cbo_zyb.Text+"'";
			
			intocbo(strcmd,"claP_no","班级",Cbo_xzbj);
			Cbo_xzbj.Enabled=true;
			
		}

		private void Cbo_xzbj_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//填充班级学员
			lst_bjxy.Items.Clear();

			strcmd="select stu_name from Student,classes where Student.stu_id=classes.stu_id and classes.claP_no='"+int.Parse(Cbo_xzbj.Text)+"'";
			intolst(strcmd,"stu_name","班级学员",lst_bjxy);


			//填充DATAGRID
			
			cnserver.ConnectionString=db.connStr;
			strcmd="select Student.stu_id 学号,stu_name 姓名,classPlan.claP_no 班级,stu_speciality 专业,stu_studytype 研修方式,stu_registerdate 注册日期,stu_studydate 开课日期 from Student,classPlan,classes where student.stu_id=classes.stu_id and classes.claP_no=classPlan.claP_no and classPlan.claP_no='"+Cbo_xzbj.Text+"'";
			cmd.CommandText=strcmd;
			cmd.Connection=cnserver;
			ad.SelectCommand=cmd;
			
			ad.Fill(dataSet1,"table1");

//			DataGridTableStyle style=new DataGridTableStyle();
//			style.MappingName="table1";
//
//			DataGridTextBoxColumn stu_id = new DataGridTextBoxColumn();
//			stu_id.HeaderText = "学号";
//			stu_id.MappingName = "stu_id";
//			stu_id.Width = 120;
//
//			DataGridTextBoxColumn stu_name = new DataGridTextBoxColumn();
//			stu_name.HeaderText = "姓名";
//			stu_name.MappingName = "stu_name";
//			stu_name.Width = 100;
//
//			DataGridTextBoxColumn claP_no = new DataGridTextBoxColumn();
//			claP_no.HeaderText = "班级";
//			claP_no.MappingName = "claP_no";
//			claP_no.Width = 50;
//			
//			DataGridTextBoxColumn stu_speciality = new DataGridTextBoxColumn();
//			stu_speciality.HeaderText = "专业";
//			stu_speciality.MappingName = "stu_speciality";
//			stu_speciality.Width = 150;
//
//			DataGridTextBoxColumn stu_studytype = new DataGridTextBoxColumn();
//			stu_studytype.HeaderText = "研修方式";
//			stu_studytype.MappingName = "stu_studytype";
//			stu_studytype.Width = 100;
//
//			DataGridTextBoxColumn stu_registerdate = new DataGridTextBoxColumn();
//			stu_registerdate.HeaderText = "注册日期";
//			stu_registerdate.MappingName = "stu_registerdate";
//			stu_registerdate.Width = 150;
//
//			DataGridTextBoxColumn stu_studydate = new DataGridTextBoxColumn();
//			stu_studydate.HeaderText = "开课日期";
//			stu_studydate.MappingName = "stu_studydate";
//			stu_studydate.Width = 150;
//
//			style.GridColumnStyles.AddRange(new DataGridColumnStyle[]{stu_id,stu_name,claP_no,stu_speciality,stu_studytype,stu_registerdate,stu_studydate});
//			this.Grd_xyfb.TableStyles.Clear();
//			this.Grd_xyfb.TableStyles.Add (style);
			Grd_xyfb.DataSource=dataSet1.Tables["table1"];


			if(lst_bjxy.Items.Count!=0)
			{
				Btn_del.Enabled=true;
				Btn_delall.Enabled=true;
			}
			else
			{
				Btn_del.Enabled=false;
				Btn_delall.Enabled=false;
			}
			Cbo_xzbj.Enabled=false;
		}

		private void dtp_bmrq_ValueChanged(object sender, System.EventArgs e)
		{
			//填充学生列表
			lst_xybj.Items.Clear();
			if(Cbo_yxfs.Enabled==false)
			{
				strcmd="select stu_name from Student where Student.stu_id not in(select stu_id from classes) and stu_registerdate='"+dtp_bmrq.Value.Date+"'";
			}
			else
			{
				strcmd="select stu_name from Student where Student.stu_id not in(select stu_id from classes) and stu_registerdate='"+dtp_bmrq.Value.Date+"' and stu_studytype='"+(Cbo_yxfs.SelectedIndex+1)+"'";
			}
			intolst(strcmd,"stu_name","学生列表",lst_xybj);

			if(lst_xybj.Items.Count!=0)
			{
				Btn_add.Enabled=true;
				Btn_addall.Enabled=true;
			}
			else
			{
				Btn_add.Enabled=false;
				Btn_addall.Enabled=false;
			}
		}

		private void Btn_addall_Click(object sender, System.EventArgs e)
		{
			int i,index;
			index=lst_xybj.Items.Count;
			for(i=0;i<index;i++)
			{
				lst_bjxy.Items.Add(lst_xybj.Items[i]);
			}
			lst_xybj.Items.Clear();
			Btn_add.Enabled=false;
			Btn_addall.Enabled=false;
			Btn_commit.Enabled=true;
			Btn_del.Enabled=true;
			Btn_delall.Enabled=true;
		}

		private void Btn_add_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(Cbo_xzbj.Text=="")
				{
					MessageBox.Show("请选择一个班级","系统提示");
					return;		
				}
				else
				{
					lst_bjxy.Items.Add(lst_xybj.SelectedItem);
					lst_xybj.Items.RemoveAt(lst_xybj.SelectedIndex);
					lst_bjxy.ClearSelected();
					lst_xybj.ClearSelected();
					Btn_del.Enabled=true;
					Btn_delall.Enabled=true;
					Btn_commit.Enabled=true;
				}
				
			}
			catch
			{
				MessageBox.Show("请选择一个学员","系统提示");
			}
			if(lst_xybj.Items.Count!=0)
			{
				Btn_add.Enabled=true;
				Btn_addall.Enabled=true;
			}
			else
			{
				Btn_add.Enabled=false;
				Btn_addall.Enabled=false;
			}
	
		}

		private void Btn_del_Click(object sender, System.EventArgs e)
		{
			try
			{
				lst_xybj.Items.Add(lst_bjxy.SelectedItem);
				lst_bjxy.Items.RemoveAt(lst_bjxy.SelectedIndex);
				lst_xybj.ClearSelected();
				lst_bjxy.ClearSelected();
				Btn_add.Enabled=true;
				Btn_addall.Enabled=true;
				Btn_commit.Enabled=true;
			}
			catch
			{
				MessageBox.Show("请选择一个学员","系统提示");
			}
			if(lst_bjxy.Items.Count!=0)
			{
				Btn_del.Enabled=true;
				Btn_delall.Enabled=true;
			}
			else
			{
				Btn_del.Enabled=false;
				Btn_delall.Enabled=false;
			}
		}

		private void Btn_delall_Click(object sender, System.EventArgs e)
		{
			int i,index;
			index=lst_bjxy.Items.Count;
			for(i=0;i<index;i++)
			{
				lst_xybj.Items.Add(lst_bjxy.Items[i]);
			}
			lst_bjxy.Items.Clear();
			Btn_del.Enabled=false;
			Btn_delall.Enabled=false;
			Btn_commit.Enabled=true;
			Btn_add.Enabled=true;
			Btn_addall.Enabled=true;
		}

		private void chk_yxk_CheckedChanged(object sender, System.EventArgs e)
		{
			if(Cbo_yxfs.Enabled==false)
			{
				Cbo_yxfs.Enabled=true;
				Cbo_yxfs.Text="";
			}
			else
			{
				Cbo_yxfs.Enabled=false;
				Cbo_yxfs.Text="";
			}
		}

		private void chk_ybm_CheckedChanged(object sender, System.EventArgs e)
		{
			if(Cbo_skdd.Enabled==false)
			{
				Cbo_skdd.Enabled=true;
				Cbo_skdd.Text="";
			}
			else
			{
				Cbo_skdd.Enabled=false;
				Cbo_skdd.Text="";
			}
		}

		private void Cbo_skdd_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//填充班级
			Cbo_xzbj.Text="";
			Cbo_xzbj.Items.Clear();
			strcmd="select claP_no from classPlan,speciality,knowledgeSystem,coursePlan,address where classPlan.spe_no=speciality.spe_no and speciality.spe_no=knowledgeSystem.spe_no and knowledgeSystem.cou_no=coursePlan.cou_no and coursePlan.add_code=address.add_code and address.add_name='"+Cbo_skdd.Text+"'";
			intocbo(strcmd,"claP_no","班级",Cbo_xzbj);
		
			if(lst_xybj.Items.Count!=0)
			{
				Btn_del.Enabled=true;
				Btn_delall.Enabled=true;
			}
			else
			{
				Btn_del.Enabled=false;
				Btn_delall.Enabled=false;
			}
		}

		private void Cbo_yxfs_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//填充学生列表
			lst_xybj.Items.Clear();
			strcmd="select stu_name from Student where Student.stu_id not in(select stu_id from classes) and stu_registerdate='"+dtp_bmrq.Value.Date+"' and stu_studytype='"+(Cbo_yxfs.SelectedIndex+1)+"'";
			intolst(strcmd,"stu_name","学生列表1",lst_xybj);

			if(lst_xybj.Items.Count!=0)
			{
				Btn_add.Enabled=true;
				Btn_addall.Enabled=true;
			}
			else
			{
				Btn_add.Enabled=false;
				Btn_addall.Enabled=false;
			}
		}

		private void Btn_commit_Click(object sender, System.EventArgs e)
		{
			//提交		
			if(MessageBox.Show("您确定要提交数据更改数据吗","确认提交",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation)==DialogResult.OK)
			{
			
				cnserver.ConnectionString=db.connStr;
				string delcmd="delete classes where claP_no='"+Cbo_xzbj.Text+"'";
				string xsid;
				string cmd1;	
				string inscmd;	
				string stuname;
				int i;
				cnserver.Open();
				cmd.Connection=cnserver;
				cmd.CommandText=delcmd;	
				cmd.ExecuteNonQuery();	
				cnserver.Close();	
				int ind=lst_bjxy.Items.Count;
				for(i=0;i<ind;i++)
				{
					stuname=lst_bjxy.Items[i].ToString();
					cmd1="select stu_id from Student where stu_name='"+stuname.ToString()+"'";
					cmd.CommandText=cmd1;
					cnserver.Open();
					cmd.ExecuteNonQuery();
					cnserver.Close();
					ad.SelectCommand=cmd;
					ad.Fill(dataSet1,"abc");
					xsid=dataSet1.Tables["abc"].Rows[0]["stu_id"].ToString();
					dataSet1.Tables["abc"].Clear();
					try
					{
						inscmd="insert classes values('"+xsid+"','"+int.Parse(Cbo_xzbj.Text)+"','')";
						cmd.CommandText=inscmd;
						cnserver.Open();
						cmd.ExecuteNonQuery();
					}
					catch(System.Exception m)
					{MessageBox.Show(m.Message);}
					cnserver.Close();
				}
			}

			//填充DATAGRID
			
			dataSet1.Clear();
			strcmd="select Student.stu_id 学号,stu_name 姓名,classPlan.claP_no 班级,stu_speciality 专业,stu_studytype 研修方式,stu_registerdate 注册日期,stu_studydate 开课日期 from Student,classPlan,classes where student.stu_id=classes.stu_id and classes.claP_no=classPlan.claP_no and classPlan.claP_no='"+Cbo_xzbj.Text+"'";
			cmd.CommandText=strcmd;
			cmd.Connection=cnserver;
			ad.SelectCommand=cmd;

			ad.Fill(dataSet1);
			Grd_xyfb.DataSource=dataSet1.Tables["table"];
			
			Btn_commit.Enabled=false;
			Cbo_xzbj.Enabled=true;
		}

	}
}

⌨️ 快捷键说明

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