📄 addscore.cs
字号:
this.label9.Location = new System.Drawing.Point(75, 82);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(160, 29);
this.label9.TabIndex = 19;
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(576, 278);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 41);
this.button1.TabIndex = 20;
this.button1.Text = "录入成绩";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.Location = new System.Drawing.Point(725, 278);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(96, 41);
this.button2.TabIndex = 21;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label10
//
this.label10.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label10.Location = new System.Drawing.Point(75, 134);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(160, 28);
this.label10.TabIndex = 23;
//
// label11
//
this.label11.AutoSize = true;
this.label11.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label11.Location = new System.Drawing.Point(21, 134);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(36, 21);
this.label11.TabIndex = 22;
this.label11.Text = "学期";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.label12);
this.groupBox4.Controls.Add(this.label6);
this.groupBox4.Controls.Add(this.label8);
this.groupBox4.Controls.Add(this.label9);
this.groupBox4.Controls.Add(this.label7);
this.groupBox4.Controls.Add(this.label10);
this.groupBox4.Controls.Add(this.label11);
this.groupBox4.Controls.Add(this.label4);
this.groupBox4.Controls.Add(this.textBox1);
this.groupBox4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.groupBox4.Location = new System.Drawing.Point(565, 10);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(267, 237);
this.groupBox4.TabIndex = 24;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "成绩";
//
// label12
//
this.label12.AutoSize = true;
this.label12.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label12.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label12.Location = new System.Drawing.Point(245, 72);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(0, 26);
this.label12.TabIndex = 24;
this.label12.Visible = false;
//
// cn1
//
this.cn1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
"OLEDB.4.0;";
//
// AddScore
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(874, 376);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label5);
this.Name = "AddScore";
this.Text = "添加成绩";
this.Load += new System.EventHandler(this.AddScore_Load);
this.Closed += new System.EventHandler(this.tjcj_Closed);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void AddScore_Load(object sender, System.EventArgs e)
{
cn.Open();
OleDbDataAdapter adp=new OleDbDataAdapter("select specialtyname from specialtyinfo",cn);
DataSet ds=new DataSet();
adp.Fill(ds,"specialtyinfo");
comboBox1.DataSource=ds.Tables["specialtyinfo"].DefaultView;
comboBox1.DisplayMember="specialtyname";
comboBox1.ValueMember="specialtyname";
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (comboBox1.Text.Trim()!="")
{
string sql="select classid,classname from classinfo where specialtyname='"+comboBox1.Text.Trim()+"'";
OleDbDataAdapter adp=new OleDbDataAdapter(sql,cn);
DataSet ds=new DataSet();
adp.Fill(ds,"class");
if (ds.Tables["class"].Rows.Count!=0)
{
comboBox2.DisplayMember="classname";
comboBox2.ValueMember="classid";
comboBox2.DataSource=ds.Tables["class"].DefaultView;
}
else
{
comboBox2.DataSource=null;
comboBox2.SelectedIndex=-1;
}
}
else
{
comboBox2.DataSource=null;
comboBox2.SelectedIndex=-1;
}
}
private void comboBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (comboBox2.DataSource!=null && comboBox2.Text.Trim()!="")
{
OleDbConnection cn1=new OleDbConnection("Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
cn1.Open();
string sql="select year(enrolmenttime) from classinfo where classid="+comboBox2.SelectedValue;
OleDbCommand cmd=new OleDbCommand(sql,cn1);
int rxnf=Int32.Parse(cmd.ExecuteScalar().ToString());
sql="select length from classinfo where classid="+comboBox2.SelectedValue.ToString().Trim();
cmd.CommandText=sql;
int nianzhi=Int32.Parse(cmd.ExecuteScalar().ToString());
int nf=rxnf;
comboBox3.Items.Clear();
for (int i=1;i<=nianzhi*2;i++)
{
comboBox3.Items.Add(nf+""+((i+1)%2+1));
if (i%2==0) nf++;
}
listView1.Items.Clear();
sql="select Studentnumber,name from StudentInfo where classid="+comboBox2.SelectedValue;
cmd.CommandText=sql;
OleDbDataReader dr=cmd.ExecuteReader();
while (dr.Read())
{
ListViewItem item1=new ListViewItem();
item1.Text=dr.GetString(1)+"("+dr.GetString(0)+")";
item1.Tag=dr.GetString(0);
item1.ImageIndex=0;
listView1.Items.Add(item1);
}
cn1.Close();
}
else
{
comboBox3.Items.Clear();
comboBox3.SelectedIndex=-1;
listView1.Clear();
}
}
private void comboBox3_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (comboBox3.Text.Trim()!="")
{
OleDbConnection cn1=new OleDbConnection("Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
cn1.Open();
string sql="select course from courseinfo where classid="+comboBox2.SelectedValue+" and semester='"+comboBox3.Text.Trim()+"'";
OleDbCommand cmd=new OleDbCommand(sql,cn1);
OleDbDataReader rd=cmd.ExecuteReader();
listView2.Clear();
while (rd.Read())
{
ListViewItem item1=new ListViewItem();
item1.Text=rd.GetString(0);
item1.ImageIndex=1;
listView2.Items.Add(item1);
}
rd.Close();
cn1.Close();
}
else
{MessageBox(0,comboBox2.SelectedValue.ToString(),"",0);
comboBox3.Items.Clear();
listView2.Clear();
}
label10.Text=comboBox3.Text.Trim();
}
private void listView2_SelectedIndexChanged(object sender, System.EventArgs e)
{
//label8.Text=listView2;
label8.Text=listView2.Items[listView2.FocusedItem.Index].Text.Trim();
}
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
label9.Text=listView1.Items[listView1.FocusedItem.Index].Text.Trim();
label12.Text=listView1.Items[listView1.FocusedItem.Index].Tag.ToString().Trim();
}
private void comboBox2_TextChanged(object sender, System.EventArgs e)
{
//MessageBox(0,comboBox2.SelectedText.Trim(),"",0);
//if ((comboBox2.DataSource==null) || (comboBox2.SelectedIndex<0))
// comboBox3.Items.Clear();
}
private void comboBox3_TextChanged(object sender, System.EventArgs e)
{
//MessageBox(0,"","",0);
}
public int strisnumber(string s)
{
int n=0;
for (int i=0;i<=s.Length-1;i++)
{
if (!System.Char.IsNumber(s[i]))
{
n=-1;
break;
}
else
n++;
}
if (n>=1)
return (int.Parse(s));
else
return (-1);
}
private void button1_Click(object sender, System.EventArgs e)
{
if (label8.Text.Trim()=="" || label9.Text.Trim()=="" || label10.Text.Trim()=="" || textBox1.Text.Trim()=="")
{
MessageBox(0,"成绩信息不完整","提示",0);
}
else
{
if (strisnumber(textBox1.Text.Trim())>=0 && strisnumber(textBox1.Text.Trim())<=100)
{
string sql="select * from scoreinfo where course='"+label8.Text.Trim()+"' and studentnumber='"+label12.Text.Trim()+"' and semester='"+label10.Text.Trim()+"'";
OleDbCommand cmd=new OleDbCommand(sql,cn);
if (null==cmd.ExecuteScalar())
{
sql="insert into scoreinfo (course,studentnumber,semester,score) values ('"+label8.Text.Trim()+"','"+label12.Text.Trim()+"','"+label10.Text.Trim()+"',"+textBox1.Text.Trim()+")";
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
MessageBox(0,"添加成功","提示",0);
}
else
MessageBox(0,"成绩不能重复录入","错误提示",0);
}
else
MessageBox(0,"成绩非法","错误提示",0);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void tjcj_Closed(object sender, System.EventArgs e)
{
cn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -