private void btnAdd_Click(object sender, EventArgs e) { int i = 0; if (tbTeachCourseNo.Text.Trim().Equals("")) { MessageBox.Show("开课号不能为空", "提示"); tbTeachCourseNo.Focus(); return; } if (tbAmount.Text.Trim().Equals("")) { MessageBox.Show("学分不能为空", "提示"); tbAmount.Focus(); return; } if (tbTeacher.Text.Trim().Equals("")) { MessageBox.Show("学分不能为空", "提示"); tbTeacher.Focus(); return; } OpenCourse oc = new OpenCourse(tbTeachCourseNo.Text, cbCourseName.Text, tbTeacher.Text, int.Parse(tbAmount.Text), int.Parse(cbStartWeek.Text), int.Parse(cbEndWeek.Text)); CourseManageAction cma = new CourseManageAction(); cma.setOpenCourse(oc); if (isUpdate == false) { i = cma.addOpenCourse(); if (i > 0) { MessageBox.Show(string.Format("增加了{0}条记录", i)); foreach (Control ctrl in groupBox2.Controls) { if (!(ctrl is Label)) { ctrl.Text = ""; } } } else { MessageBox.Show("添加不成功"); } } else { i = cma.updateOpenCourse(); if (i > 0) { MessageBox.Show(string.Format("更新了{0}条记录", i)); this.Close(); } else { MessageBox.Show("更新不成功"); } } this.Close(); }