📄 form_khcjcx.cs
字号:
{
ChartDataSeries series = dat.SeriesList.AddNewSeries();
series.PointData.Length = 1;
series.PointData[0] = new PointF(1f, SliceValue[slice]);
series.LineStyle.Color = ColorValue[slice];
C1.Win.C1Chart.Label lab = Chart_dktj.ChartLabels.LabelsCollection.AddNewLabel();
lab.AttachMethod = AttachMethodEnum.DataIndex;
AttachMethodData amd = lab.AttachMethodData;
amd.GroupIndex = 0;
amd.PointIndex = 0;
amd.SeriesIndex = slice;
if(slice==0)
{lab.Text="合格"+n+"人";}
else
{lab.Text="不合格"+m+"人";}
lab.Compass = LabelCompassEnum.Radial;
lab.Connected = true;
lab.Offset = 3;
lab.Visible = true;
}
Chart_dktj.ChartArea.PlotArea.View3D.Depth = 25;
Chart_dktj.ChartArea.PlotArea.View3D.Elevation =40;
if(dsdktj.Tables[0].Rows.Count==0)
{
txt_kskm1.Text="";
txt_bmksrs1.Text="";
txt_hgrs1.Text="";
txt_bhgrs1.Text="";
txt_hgl1.Text="";
Chart_dktj.Reset();
MessageBox.Show("没有您要统计的数据,请重试。");
}
else
{
float c;
c=(n*100)/(n+m);
txt_kskm1.Text=cbo_nbkskm.Text;
txt_bmksrs1.Text=j.ToString();
txt_hgrs1.Text=n.ToString();
txt_bhgrs1.Text=m.ToString();
txt_hgl1.Text=c.ToString()+"%";
dg2.DataSource=dsdktj.Tables[0];
}
}
else
{
Chart_ndtj.Reset();//连接数据库,选出数据,填充数据集
SqlCommand cmdndtj = new SqlCommand("select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and year(examInfo.exaI_examTime)='"+dtp_time.Value.Date.Year+"' and exaI_score is not null",contj);
SqlDataAdapter adndtj = new SqlDataAdapter(cmdndtj);
DataSet dsndtj = new DataSet();
adndtj.Fill(dsndtj);
int j;
j=dsndtj.Tables[0].Rows.Count;
float[] fs=new float [j];
int i=0;
foreach(DataRow dr in dsndtj.Tables[0].Rows)//将字段导入数组
{
fs[i]=float.Parse(dr["考试成绩"].ToString());
i++;
}
int m=0,n=0;
for(i=0;i<j;i++)
{
if(fs[i]<60)
{
m++;
}
else
{
n++;
}
}
ChartGroup grp = Chart_ndtj.ChartGroups[0];//定义CHARTGROUP
grp.ChartType = Chart2DTypeEnum.Pie;//图表类型为饼图
ChartData dat = grp.ChartData;
dat.SeriesList.Clear();//将原来的SeriesList删除
int [] SliceValue=new int[]{n,m};
Color [] ColorValue = new Color []{Color.LightGreen,Color.Red};
for(int slice=0; slice < SliceValue.Length; slice++)
{ //生成新的series,实现CHART图表
ChartDataSeries series = dat.SeriesList.AddNewSeries();
series.PointData.Length = 1;
series.PointData[0] = new PointF(1f, SliceValue[slice]);
series.LineStyle.Color = ColorValue[slice];
C1.Win.C1Chart.Label lab = Chart_ndtj.ChartLabels.LabelsCollection.AddNewLabel();
lab.AttachMethod = AttachMethodEnum.DataIndex;
AttachMethodData amd = lab.AttachMethodData;
amd.GroupIndex = 0;
amd.PointIndex = 0;
amd.SeriesIndex = slice;
if(slice==0)
{lab.Text="合格"+n+"人";}
else
{lab.Text="不合格"+m+"人";}
lab.Compass = LabelCompassEnum.Radial;
lab.Connected = true;
lab.Offset = 3;
lab.Visible = true;
}
Chart_ndtj.ChartArea.PlotArea.View3D.Depth = 25;
Chart_ndtj.ChartArea.PlotArea.View3D.Elevation =40;
if(dsndtj.Tables[0].Rows.Count==0)
{
txt_kskm2.Text="";
txt_bmksrs2.Text="";
txt_hgrs2.Text="";
txt_bhgrs2.Text="";
txt_hgl2.Text="";
Chart_ndtj.Reset();
MessageBox.Show("没有您要统计的数据,请重试。");
}
else
{
float c;
c=(n*100)/(n+m);
txt_kskm2.Text=cbo_nbkskm.Text;
txt_bmksrs2.Text=j.ToString();
txt_hgrs2.Text=n.ToString();
txt_bhgrs2.Text=m.ToString();
txt_hgl2.Text=c.ToString()+"%";
dg2.DataSource=dsndtj.Tables[0];
}
}
}
}
catch(System.Exception d)
{
MessageBox.Show(d.Message);
}
}
private void chk_name_CheckedChanged(object sender, System.EventArgs e)
{
if(chk_name.Checked)
{
txt_name.Enabled=true;
chk_kscj.Checked=false;
chk_kscj.Enabled=false;
}
else
{
txt_name.Enabled=false;
txt_name.Text="";
chk_kscj.Enabled=true;
}
}
private void chk_id_CheckedChanged(object sender, System.EventArgs e)
{
if(chk_id.Checked)
{
txt_id.Enabled=true;
chk_name.Checked=false;
chk_name.Enabled=false;
chk_kscj.Checked=false;
chk_kscj.Enabled=false;
}
else
{
txt_id.Enabled=false;
txt_id.Text="";
chk_name.Enabled=true;
chk_kscj.Enabled=true;
}
}
private void chk_kscj_CheckedChanged(object sender, System.EventArgs e)
{
if(chk_kscj.Checked)
{
cbo_kscj.Enabled=true;
chk_name.Checked=false;
chk_name.Enabled=false;
chk_id.Checked=false;
chk_id.Enabled=false;
lbl_jsrq.Visible=true;
dtp_jsrq.Visible=true;
lbl_ksrq.Text="启始日期";
}
else
{
cbo_kscj.Enabled=false;
cbo_kscj.Text="";
chk_name.Enabled=true;
chk_id.Enabled=true;
lbl_jsrq.Visible=false;
dtp_jsrq.Visible=false;
lbl_ksrq.Text="考试日期";
}
}
private void btn_query2_Click(object sender, System.EventArgs e)
{
//按选择条件实现查询功能
SqlConnection conquery = new SqlConnection();
conquery.ConnectionString=db.connStr;
SqlCommand cmdquery = new SqlCommand();
cmdquery.CommandText="";
cmdquery.Connection=conquery;
if(cbo_nbkskm.Text=="")
{
MessageBox.Show("请选择考试科目");
}
else
{
if(chk_name.Checked)
{
if(txt_name.Text=="")
{
MessageBox.Show("请填入姓名");
}
else
{
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and Student.stu_name='"+txt_name.Text+"'";
cmdquery.Connection=conquery;
}
}
else
{
if(chk_id.Checked)
{
if(txt_id.Text=="")
{
MessageBox.Show("请填入身份证号");
}
else
{
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and Student.stu_identityNo='"+txt_id.Text+"'";
cmdquery.Connection=conquery;
}
}
else
{
if(chk_kscj.Checked)
{
if(cbo_kscj.Text=="")
{
MessageBox.Show("请选择考试成绩分数段");
}
else
{
switch(cbo_kscj.SelectedIndex)
{
case 0:
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and examInfo.exaI_score<60 and examInfo.exaI_examTime>='"+dtp_time.Value.Date+"' and examInfo.exaI_examTime<='"+dtp_jsrq.Value.Date+"'";
cmdquery.Connection=conquery;
break;
case 1:
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and examInfo.exaI_score>=60 and examInfo.exaI_score<=69 and examInfo.exaI_examTime>='"+dtp_time.Value.Date+"' and examInfo.exaI_examTime<='"+dtp_jsrq.Value.Date+"'";
cmdquery.Connection=conquery;
break;
case 2:
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and examInfo.exaI_score>=70 and examInfo.exaI_score<=79 and examInfo.exaI_examTime>='"+dtp_time.Value.Date+"' and examInfo.exaI_examTime<='"+dtp_jsrq.Value.Date+"'";
cmdquery.Connection=conquery;
break;
case 3:
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and examInfo.exaI_score>=80 and examInfo.exaI_score<=89 and examInfo.exaI_examTime>='"+dtp_time.Value.Date+"' and examInfo.exaI_examTime<='"+dtp_jsrq.Value.Date+"'";
cmdquery.Connection=conquery;
break;
default:
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and examInfo.exaI_score>=90 and examInfo.exaI_examTime>='"+dtp_time.Value.Date+"' and examInfo.exaI_examTime<='"+dtp_jsrq.Value.Date+"'";
cmdquery.Connection=conquery;
break;
}
}
}
else
{
cmdquery.CommandText="select examInfo.stu_id 学号,stu_name 姓名,stu_identityNo 身份证号, cou_name 考试科目,exaI_examTime 考试时间,exaI_score 考试成绩 from Course,examInfo,Student where examInfo.cou_no=Course.cou_no and examInfo.stu_id=Student.stu_id and Course.cou_name='"+cbo_nbkskm.Text+"' and examInfo.exaI_examTime='"+dtp_time.Value.Date+"'";
cmdquery.Connection=conquery;
}
}
}
}
if(cmdquery.CommandText!="")
{
SqlDataAdapter adquery = new SqlDataAdapter(cmdquery);
DataSet dsquery = new DataSet();
adquery.Fill(dsquery);
if(dsquery.Tables[0].Rows.Count==0)
{
dg2.DataSource=null;
MessageBox.Show("没有您要查询的数据,请重试。");
}
else
{
dg2.DataSource=dsquery.Tables[0];
}
}
}
private void panel_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -