📄 form_khcj.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace bizdb
{
/// <summary>
/// Form_khcj 的摘要说明。
/// </summary>
public class Form_khcj : System.Windows.Forms.Form
{
private System.Data.DataColumn dataColumn1;
private System.Data.DataColumn dataColumn2;
private System.Data.DataColumn dataColumn3;
private System.Data.DataColumn dataColumn4;
private System.Data.DataColumn dataColumn5;
private System.Windows.Forms.Button btn_inside;
private System.Windows.Forms.DataGrid dg1;
private System.Windows.Forms.DateTimePicker dtp_ksrq1;
private System.Windows.Forms.Label lbl_ksrq1;
private System.Windows.Forms.ComboBox cbo_kskm;
private System.Windows.Forms.Label lbl_kskm;
private System.ComponentModel.IContainer components;
private dbAccess db = new dbAccess();
public Form_khcj()
{
//
// 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.btn_inside = new System.Windows.Forms.Button();
this.dg1 = new System.Windows.Forms.DataGrid();
this.dtp_ksrq1 = new System.Windows.Forms.DateTimePicker();
this.lbl_ksrq1 = new System.Windows.Forms.Label();
this.cbo_kskm = new System.Windows.Forms.ComboBox();
this.lbl_kskm = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dg1)).BeginInit();
this.SuspendLayout();
//
// btn_inside
//
this.btn_inside.Location = new System.Drawing.Point(616, 24);
this.btn_inside.Name = "btn_inside";
this.btn_inside.Size = new System.Drawing.Size(112, 23);
this.btn_inside.TabIndex = 30;
this.btn_inside.Text = "生成考试成绩";
this.btn_inside.Click += new System.EventHandler(this.btn_inside_Click_1);
//
// dg1
//
this.dg1.DataMember = "";
this.dg1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dg1.Location = new System.Drawing.Point(40, 56);
this.dg1.Name = "dg1";
this.dg1.ReadOnly = true;
this.dg1.Size = new System.Drawing.Size(712, 512);
this.dg1.TabIndex = 29;
//
// dtp_ksrq1
//
this.dtp_ksrq1.Location = new System.Drawing.Point(448, 24);
this.dtp_ksrq1.Name = "dtp_ksrq1";
this.dtp_ksrq1.Size = new System.Drawing.Size(120, 21);
this.dtp_ksrq1.TabIndex = 28;
this.dtp_ksrq1.ValueChanged += new System.EventHandler(this.dtp_ksrq1_ValueChanged);
//
// lbl_ksrq1
//
this.lbl_ksrq1.Location = new System.Drawing.Point(376, 24);
this.lbl_ksrq1.Name = "lbl_ksrq1";
this.lbl_ksrq1.Size = new System.Drawing.Size(56, 16);
this.lbl_ksrq1.TabIndex = 27;
this.lbl_ksrq1.Text = "考试日期";
//
// cbo_kskm
//
this.cbo_kskm.Location = new System.Drawing.Point(136, 24);
this.cbo_kskm.Name = "cbo_kskm";
this.cbo_kskm.Size = new System.Drawing.Size(216, 20);
this.cbo_kskm.TabIndex = 26;
this.cbo_kskm.SelectedIndexChanged += new System.EventHandler(this.cbo_kskm_SelectedIndexChanged);
//
// lbl_kskm
//
this.lbl_kskm.Location = new System.Drawing.Point(40, 24);
this.lbl_kskm.Name = "lbl_kskm";
this.lbl_kskm.Size = new System.Drawing.Size(80, 16);
this.lbl_kskm.TabIndex = 25;
this.lbl_kskm.Text = "内部考试科目";
//
// Form_khcj
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.btn_inside);
this.Controls.Add(this.dg1);
this.Controls.Add(this.dtp_ksrq1);
this.Controls.Add(this.lbl_ksrq1);
this.Controls.Add(this.cbo_kskm);
this.Controls.Add(this.lbl_kskm);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form_khcj";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form_khcj";
this.Load += new System.EventHandler(this.Form_khcj_Load);
((System.ComponentModel.ISupportInitialize)(this.dg1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void Form_khcj_Load(object sender, System.EventArgs e)
{ //填充cbo_kskm
SqlConnection conkskm = new SqlConnection();
conkskm.ConnectionString=db.connStr;
SqlCommand cmdkskm = new SqlCommand("select cou_name from Course,examInfo where examInfo.cou_no=Course.cou_no group by cou_name",conkskm);
SqlDataAdapter adkskm = new SqlDataAdapter(cmdkskm);
DataSet dskskm = new DataSet();
adkskm.Fill(dskskm,"kskm");
int i,j;
j=dskskm.Tables[0].Rows.Count;
for(i=0;i<j;i++)
{
cbo_kskm.Items.Add(dskskm.Tables[0].Rows[i]["cou_name"].ToString());
}
}
private void btn_inside_Click_1(object sender, System.EventArgs e)
{
try
{
if(cbo_kskm.Text=="")
{
MessageBox.Show("请选择考试科目");
}
else
{ //连接数据库,按条件生成学生成绩
SqlConnection coninside = new SqlConnection();
coninside.ConnectionString=db.connStr;
SqlCommand cmdinside = new SqlCommand("select stu_id,examPaper.cou_no,sum(exap_score) pap_score,cou_name from examPaper,course where examPaper.cou_no=course.cou_no and cou_name='"+cbo_kskm.Text+"' group by stu_id,examPaper.cou_no,pap_no,cou_name",coninside);
SqlDataAdapter adinside = new SqlDataAdapter(cmdinside);
DataSet ds = new DataSet();
adinside.Fill(ds,"table");
SqlCommand update = new SqlCommand();
int i,j;
j=ds.Tables[0].Rows.Count;
for(i=0;i<j;i++)
{ //将学生成绩填入相应数据库
float k;
string id,no;
k=float.Parse(ds.Tables[0].Rows[i]["pap_score"].ToString());
id=ds.Tables[0].Rows[i]["stu_id"].ToString();
no=ds.Tables[0].Rows[i]["cou_no"].ToString();
update.CommandText="update examInfo set exaI_score='"+k+"' where stu_id='"+id+"' and cou_no='"+no+"' and exaI_examTime='"+dtp_ksrq1.Value.Date+"'";
update.Connection=coninside;
coninside.Open();
update.ExecuteNonQuery();
coninside.Close();
}
//将生成的数据显示于DATAGRID中
SqlCommand cmdinside1 = new SqlCommand("select stu_id 学号,cou_name 课程名称,exaI_examTime 考试时间,exaI_score 考试成绩 from examInfo,course where course.cou_no=examInfo.cou_no and exaI_examTime='"+dtp_ksrq1.Value.Date+"' and cou_name='"+cbo_kskm.Text+"' and exaI_score is not null",coninside);
SqlDataAdapter adinside1 = new SqlDataAdapter(cmdinside1);
DataSet ds1 = new DataSet();
adinside1.Fill(ds1,"table");
if(ds1.Tables[0].Rows.Count==0)
{
MessageBox.Show("没有您要生成的数据,请重试。");
dg1.DataSource=null;
}
else
{
dg1.DataSource=ds1.Tables[0];
}
}
}
catch(System.Exception d)
{
MessageBox.Show(d.Message);
}
}
private void cbo_kskm_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void dtp_ksrq1_ValueChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -