📄 frmexams.cs
字号:
this.gpSearch.Controls.Add(this.cmbSearchClass);
this.gpSearch.Controls.Add(this.label5);
this.gpSearch.Dock = System.Windows.Forms.DockStyle.Right;
this.gpSearch.Location = new System.Drawing.Point(344, 0);
this.gpSearch.Name = "gpSearch";
this.gpSearch.Size = new System.Drawing.Size(206, 302);
this.gpSearch.TabIndex = 8;
this.gpSearch.TabStop = false;
this.gpSearch.Text = "查找";
//
// button1
//
this.button1.Location = new System.Drawing.Point(124, 186);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 13;
this.button1.Text = "查找";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// cmbSearchCate
//
this.cmbSearchCate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbSearchCate.Location = new System.Drawing.Point(86, 142);
this.cmbSearchCate.Name = "cmbSearchCate";
this.cmbSearchCate.Size = new System.Drawing.Size(114, 20);
this.cmbSearchCate.TabIndex = 11;
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 144);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(60, 16);
this.label4.TabIndex = 10;
this.label4.Text = "考试科目";
//
// cmbSearchClass
//
this.cmbSearchClass.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbSearchClass.Location = new System.Drawing.Point(86, 110);
this.cmbSearchClass.Name = "cmbSearchClass";
this.cmbSearchClass.Size = new System.Drawing.Size(114, 20);
this.cmbSearchClass.TabIndex = 9;
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 112);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(60, 18);
this.label5.TabIndex = 8;
this.label5.Text = "考试班级:";
//
// panel3
//
this.panel3.Controls.Add(this.dlvExams);
this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel3.Location = new System.Drawing.Point(0, 302);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(550, 147);
this.panel3.TabIndex = 2;
//
// dlvExams
//
this.dlvExams.AutoColumnsWidth = false;
this.dlvExams.BindTable = null;
this.dlvExams.ColumnsWidth = 100;
this.dlvExams.Dock = System.Windows.Forms.DockStyle.Fill;
this.dlvExams.FullRowSelect = true;
this.dlvExams.LineNumWidth = 50;
this.dlvExams.Location = new System.Drawing.Point(0, 0);
this.dlvExams.MultiSelect = false;
this.dlvExams.Name = "dlvExams";
this.dlvExams.SelectedColor = System.Drawing.Color.DodgerBlue;
this.dlvExams.Size = new System.Drawing.Size(550, 147);
this.dlvExams.TabIndex = 0;
this.dlvExams.View = System.Windows.Forms.View.Details;
this.dlvExams.SelectedIndexChanged += new System.EventHandler(this.dlvExams_SelectedIndexChanged);
//
// FrmExams
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(550, 449);
this.Controls.Add(this.panel3);
this.Controls.Add(this.panel1);
this.Name = "FrmExams";
this.Text = "考试管理";
this.Load += new System.EventHandler(this.FrmExams_Load);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.nupTime)).EndInit();
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.nupLevel5)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupLevel4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupLevel3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupLevel2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nupLevel1)).EndInit();
this.panel5.ResumeLayout(false);
this.panel4.ResumeLayout(false);
this.gpSearch.ResumeLayout(false);
this.panel3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button5_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
if(btn.Text==">")
{
gpSearch.Visible=false;
btn.Text="<";
}
else
{
gpSearch.Visible=true;
btn.Text=">";
}
}
private void panel2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
/// <summary>
/// 判断是否有文本没有填入
/// </summary>
/// <returns></returns>
private bool hasEmpty()
{
if(this.txtName.Text.Trim()=="")
{
MessageBox.Show("请填入考试名称","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
txtName.Focus();
return true;
}
return false;
}
private string getTitles()
{
string resStr="";
for(int i=0;i<this.nums.Length;i++)
{
resStr+=nums[i].Value.ToString();
if(i<nums.Length-1)
{
resStr+=",";
}
}
return resStr;
}
private void FrmExams_Load(object sender, System.EventArgs e)
{
fillSelecter();
gpSearch.Visible=false;
button5.Text="<";
fillArr();
search();
enChange(false);
}
private void button4_Click(object sender, System.EventArgs e)
{
FrmAddExam frmAdd=new FrmAddExam();
frmAdd.ShowDialog();
if(frmAdd.HasAdd)
{
search();
clearText();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
search();
}
private void dlvExams_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(dlvExams.SelectedIndices.Count>0)
{
fillDisplay(dlvExams.SelectedIndices[0]);
enChange(true);
}
}
private void nupLevel1_ValueChanged(object sender, System.EventArgs e)
{
displayExamInfo();
}
private void btnChange_Click(object sender, System.EventArgs e)
{
if(dlvExams.SelectedIndices.Count<=0)
{
return;
}
if(!hasEmpty())
{
ExamFac examFac=new ExamFac();
int index=dlvExams.SelectedIndices[0];
DataTable dt=dlvExams.BindTable;
int examID=Convert.ToInt32(dt.Rows[index][0]);
string examName=this.txtName.Text;
int cateID=(int)this.cmbCate.SelectedValue;
int classID=(int)this.cmbClass.SelectedValue;
string titles=this.getTitles();
int examTime=(int)nupTime.Value;
SearchBooleans isEnd=SearchBooleans.False;
if(this.chkEnd.Checked)
{
isEnd=SearchBooleans.True;
}
try
{
if(examFac.updateExam(examID,examName,cateID,classID,titles,examTime,isEnd))
{
// item.SubItems[1].Text=examName;
// item.SubItems[2].Text=cmbClass.Text;
// item.SubItems[5].Text=cmbCate.Text;
// item.SubItems[7].Text=cateID.ToString();
// item.SubItems[8].Text=classID.ToString();
dt.Rows[index][1]=examName;
dt.Rows[index][2]=this.cmbClass.Text;
dt.Rows[index][4]=titles;
dt.Rows[index][5]=this.cmbCate.Text;
dt.Rows[index][6]=isEnd;
dt.Rows[index][7]=cateID;
dt.Rows[index][8]=classID;
dt.Rows[index][9]=examTime;
dlvExams.Items[index].SubItems[1].Text=examName;
dlvExams.Items[index].SubItems[2].Text=cmbClass.Text;
dlvExams.Items[index].SubItems[4].Text=cmbCate.Text;
if(isEnd==SearchBooleans.False)
{
dlvExams.Items[index].SubItems[5].Text="False";
}
else
{
dlvExams.Items[index].SubItems[5].Text="True";
}
MessageBox.Show("修改完毕","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("有重复的考试名","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
catch
{
MessageBox.Show("修改数据失败","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
if(dlvExams.SelectedIndices.Count<=0)
{
return;
}
int index=dlvExams.SelectedIndices[0];
DataTable dt=dlvExams.BindTable;
if(MessageBox.Show("是否要删除考试:"+dt.Rows[index][1].ToString(),"提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information)==DialogResult.Yes)
{
int examID=Convert.ToInt32(dt.Rows[index][0]);
ExamFac examFac=new ExamFac();
try
{
examFac.deleteExam(examID,"",-1,-1,"",SearchBooleans.NULL);
MessageBox.Show("删除完毕","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
dlvExams.Items.RemoveAt(index);
dt.Rows.RemoveAt(index);
dlvExams.RefreshLineNum();
}
catch
{
MessageBox.Show("删除数据失败","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
private void cmbClass_SelectedIndexChanged(object sender, System.EventArgs e)
{
// DataView dvCate=dsCate.Tables[0].DefaultView;
//
// fillCate(this.cmbCate,dvCate);
if(cmbClass.SelectedIndex<0)
{
return;
}
dvClass.RowFilter="ClassID="+cmbClass.SelectedValue.ToString();
if(dvClass.Count>0)
{
dvCate.RowFilter="GradeID="+dvClass[0]["Grade"].ToString()+" or GradeID=0";
}
}
private void cmbSearchClass_SelectedIndexChanged(object sender, System.EventArgs e)
{
// CateFac cateFac=new CateFac();
// DataSet dsCate=cateFac.getCate((int)cmbSearchClass.SelectedValue,"");
// fillSearchCate(this.cmbSearchCate,dsCate);
if(cmbClass.SelectedIndex<0)
{
return;
}
dvClass.RowFilter="ClassID="+cmbSearchClass.SelectedValue.ToString();
if(dvClass.Count>0)
{
dvSearchCate.RowFilter="GradeID="+dvClass[0]["Grade"].ToString()+" or CateID=-1 or GradeID=0";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -