Пример #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     //修改成绩
     try
     {
         //要修改成绩的学生编号
         string sid = lblStuID.Text;
         if (sid != "0")
         {
             string        sqlstr = "update Examination set ExamScore={0} where StudentID={1} and SubjectsID={2} ";
             StringBuilder sql    = new StringBuilder();
             int           i      = 0;
             foreach (Control c in gbSubjects.Controls)
             {
                 Subjects sub = (Subjects)c;
                 if (sub.txtScore.Enabled)
                 {
                     string score = sub.txtScore.Text.Trim();
                     sql.AppendFormat(sqlstr, score, sid, arrSubjects[i].ToString());
                     sub.txtScore.Enabled = false;
                 }
                 i++;
             }
             DataBaseHelper.BeginTranExecNoneQuery(sql.ToString());
             int r = DataBaseHelper.EndTranExecNoneQuery(i);
             if (r == i)
             {
                 MessageBox.Show("修改成功!", "信息提示");
             }
             else
             {
                 MessageBox.Show("修改失败!", "信息提示");
             }
         }
         else
         {
             MessageBox.Show("请选择学生!", "信息提示");
         }
     }
     catch
     {
         MessageBox.Show("分数格式错误");
     }
 }
Пример #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     //提交成绩
     try
     {
         int           count  = gbSubjects.Controls.Count;
         string        sqlstr = "insert into Examination(StudentID,SubjectsID, ExamScore) values({0},{1},{2})";
         StringBuilder sql    = new StringBuilder();
         string        score  = "";
         for (int i = 0; i < count; i++)
         {
             Subjects sub = (Subjects)(gbSubjects.Controls[i]);
             if (sub.txtScore.Text.Trim() == "")
             {
                 score = "0";
             }
             else
             {
                 score = sub.txtScore.Text.Trim();
             }
             sql.AppendFormat(sqlstr,
                              cbStuName.SelectedValue.ToString(), arrSubjects[i], score);
         }
         DataBaseHelper.BeginTranExecNoneQuery(sql.ToString());
         int result = DataBaseHelper.EndTranExecNoneQuery(count);
         if (result == count)
         {
             MessageBox.Show("提交成绩成功!", "信息提示");
         }
         else
         {
             MessageBox.Show("提交成绩失败!", "信息提示");
         }
     }
     catch
     {
         MessageBox.Show("分数格式错误");
     }
 }