📄 frmaddscore.cs
字号:
// label6
//
this.label6.Location = new System.Drawing.Point(24, 144);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 23);
this.label6.TabIndex = 3;
this.label6.Text = "学期";
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 96);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 23);
this.label5.TabIndex = 2;
this.label5.Text = "学生";
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 48);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(48, 23);
this.label4.TabIndex = 1;
this.label4.Text = "课程";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.listView1);
this.groupBox4.Location = new System.Drawing.Point(264, 40);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(232, 192);
this.groupBox4.TabIndex = 4;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "课程";
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(16, 32);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(192, 144);
this.listView1.SmallImageList = this.imageList1;
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.List;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
//
// btnCancle
//
this.btnCancle.Location = new System.Drawing.Point(664, 344);
this.btnCancle.Name = "btnCancle";
this.btnCancle.TabIndex = 5;
this.btnCancle.Text = "取消";
this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
//
// frmAddScore
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(786, 439);
this.Controls.Add(this.btnCancle);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "frmAddScore";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "添加成绩";
this.Load += new System.EventHandler(this.frmAddScore_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void frmAddScore_Load(object sender, System.EventArgs e)
{
string Sql = "select * from Class..SpecialtyInfo";
if(c.IsExits(Sql)==true)
{
string tableName = "SpecialtyInfo";
this.cboSpec.DataSource=da.ExecuteDataTable(Sql,tableName);
this.cboSpec.DisplayMember="SpecialtyName";
this.cboSpec.SelectedIndex=0;
}
else
{
this.cboSpec.Items.Add("尚未添加专业");
this.cboSpec.SelectedIndex=0;
}
}
private void cboSpec_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.cboClass.DataSource = null;
AddClass();
AddListStu();
this.Init();
}
private void AddClass()
{
string Sql = "select * from Class..ClassInfo where SpecialtyName = '"+this.cboSpec.Text+"' ";
string tableName = "ClassInfo";
if(c.IsExits(Sql)==true)
{
this.cboClass.DataSource=da.ExecuteDataTable(Sql,tableName);
this.cboClass.DisplayMember="ClassName";
this.cboClass.ValueMember="ClassID";
}
else
{
this.cboClass.Items.Add("尚未创建班级");
}
this.cboClass.SelectedIndex=0;
}
/// <summary>
/// 为学期附值
/// </summary>
private void getSeme(int year,int length)
{
for(int i=0;i<length;i++)
{
for(int j=1;j<=2;j++)
{
int Year =year+i;
this.cboSeme.Items.Add(Year.ToString()+j.ToString());
}
}
}
/// <summary>
/// 向学生的ListView添加数据
/// </summary>
private void AddListStu()
{
this.listView2.Items.Clear();
string Sql1 = "select * from Class..StudentInfo where ClassID = (select ClassID from Class..ClassInfo where ClassName = '"+this.cboClass.Text+"')";
ArrayList name = new ArrayList();
ArrayList Number = new ArrayList();
name=c.getDatas(Sql1,2);
Number = c.getDatas(Sql1,1);
for(int i = 0; i<name.Count;i++)
{
ListViewItem item1 = new ListViewItem();
item1.Text=name[i]+"("+Number[i]+")";
item1.Tag=Number[i];
item1.ImageIndex=0;
this.listView2.Items.Add(item1);
}
}
/// <summary>
/// 初始化控件
/// </summary>
private void Init()
{
this.txtStu.Text="";
this.txtSeme.Text="";
this.txtScore.Text="";
this.txtCourse.Text="";
}
/// <summary>
/// 向课程的ListView添加数据
/// </summary>
private void AddListCourse()
{
this.listView1.Items.Clear();
string Sql1 = "select * from Class..CourseInfo where ClassID = (select ClassID from Class..ClassInfo where ClassName = '"+this.cboClass.Text
+"') and Semester = '"+this.cboSeme.Text+"'";
ArrayList course = new ArrayList();
course=c.getDatas(Sql1,2);
for(int i = 0; i<course.Count;i++)
{
ListViewItem item1 = new ListViewItem();
item1.Text=course[i].ToString();
item1.ImageIndex=1;
this.listView1.Items.Add(item1);
}
}
private void cboClass_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.cboSeme.Items.Clear();
string Sql = "select * from Class..ClassInfo where ClassName = '"+this.cboClass.Text+"'";
if(c.IsExits(Sql)==true)
{
int length = int.Parse(c.getData(Sql,4));
DateTime year = DateTime.Parse(c.getData(Sql,6));
int year1 = year.Year;
this.getSeme(year1,length);
}
else
{
this.cboSeme.Items.Add("尚未创建学期");
}
this.cboSeme.SelectedIndex=0;
AddListStu();
AddListCourse();
this.Init();
}
private void cboSeme_SelectedIndexChanged(object sender, System.EventArgs e)
{
AddListCourse();
this.Init();
}
private void btnCancle_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.txtCourse.Text=this.listView1.Items[this.listView1.FocusedItem.Index].Text.Trim();
}
private void listView2_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.txtSeme.Text=this.cboSeme.Text;
this.txtStu.Text=this.listView2.Items[this.listView2.FocusedItem.Index].Text.Trim();
}
private void btnOK_Click(object sender, System.EventArgs e)
{
string Sql1 = "Select * from Class..ScoreInfo where Semester = '"+this.cboSeme.Text
+"' and StudentNumber = '"+this.listView2.Items[this.listView2.FocusedItem.Index].Tag.ToString()
+"' and Course = '"+this.txtCourse.Text+"' and State='已录入'";
if(this.txtCourse.Text==""||this.txtScore.Text==""||this.txtSeme.Text==""||this.txtStu.Text=="")
{
MessageBox.Show("请输入完整信息!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else if(c.IsYear(this.txtScore.Text)==false||int.Parse(this.txtScore.Text)<0||int.Parse(this.txtScore.Text)>100)
{
MessageBox.Show("请输入正确的成绩信息!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else if(c.IsExits(Sql1)==true)
{
MessageBox.Show("成绩不能重复录入!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else
{
string Sql = "update Class..ScoreInfo set Score ="+this.txtScore.Text+" ,State = '已录入' where StudentNumber = '"+this.listView2.Items[this.listView2.FocusedItem.Index].Tag.ToString()
+"' and Course = '"+this.txtCourse.Text+"'";
c.EditData(Sql);
MessageBox.Show("录入成功!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -