private void button1_Click(object sender, EventArgs e) { string strErr = ""; Model.Teacher_Course.Teacher_Course objTeCo = new Model.Teacher_Course.Teacher_Course(); Model.Teacher_Class.Teacher_Class objTeCl = new Model.Teacher_Class.Teacher_Class(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Teacher_Course_Class.T_C_C objTCC = new Manage.Teacher_Course_Class.T_C_C(strConnection); objTeCl.ClassId = int.Parse(cmbClassName.SelectedValue.ToString()); objTeCo.CourseId = int.Parse(cmbCourseName.SelectedValue.ToString()); if (OldClass != cmbClassName.SelectedValue.ToString() && OldCourse != cmbCourseName.SelectedValue.ToString()) { MessageBox.Show("只能在班级和课程中修改一个"); } else if (OldClass == cmbClassName.SelectedValue.ToString() && OldCourse == cmbCourseName.SelectedValue.ToString()) { MessageBox.Show("班级和课程没有改变,没有修改"); this.Visible = false; } else { int iR = objTCC.JudgeClassCourse(objTeCo.CourseId, objTeCl.ClassId); if (iR == 0) { MessageBox.Show("此班级的这门课程已经安排教师,请安排给其他的班级"); } else { if (OldClass == cmbClassName.SelectedValue.ToString() && OldCourse != cmbCourseName.SelectedValue.ToString()) { int iRent = objTCC.ModifyTCC1(strTeaNo, OldClassId, OldCourseId, objTeCl, objTeCo, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } else if (OldCourse == cmbCourseName.SelectedValue.ToString() && OldClass != cmbClassName.SelectedValue.ToString()) { int iRent = objTCC.ModifyTCC(strTeaNo, OldClassId, OldCourseId, objTeCl, objTeCo, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } } } }
private void btnSearch_Click(object sender, EventArgs e) { string strErr = ""; DataTable objDataTable = new DataTable(); Manage.Teacher_Course_Class.T_C_C objT_C_C = new Manage.Teacher_Course_Class.T_C_C(strConnection); string strTeaNo = txtTeaSearchNo.Text; strTeaNo = strTeaNo.Replace("%", @"\%"); strTeaNo = strTeaNo.Replace("_", @"\_"); strTeaNo = strTeaNo.Replace("'", @"\''"); strTeaNo = strTeaNo.Trim(); string strTeaName = txtTeaSearchName.Text; strTeaName = strTeaName.Replace("%", @"\%"); strTeaName = strTeaName.Replace("_", @"\_"); strTeaName = strTeaName.Replace("'", @"\''"); strTeaName = strTeaName.Trim(); string strClassName = txtClassSearchName.Text; strClassName = strClassName.Replace("%", @"\%"); strClassName = strClassName.Replace("_", @"\_"); strClassName = strClassName.Replace("'", @"\''"); strClassName = strClassName.Trim(); string strCourseName = txtCourseSearchName.Text; strCourseName = strCourseName.Replace("%", @"\%"); strCourseName = strCourseName.Replace("_", @"\_"); strCourseName = strCourseName.Replace("'", @"\''"); strCourseName = strCourseName.Trim(); int iRent = objT_C_C.SearchTCC1(strTeaNo, strTeaName, strCourseName, strClassName, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { if (objDataTable.Rows.Count == 0) { MessageBox.Show("没有符合你要查询的记录"); } else { dataGridView.DataSource = objDataTable; } txtTeaSearchNo.Text = ""; txtTeaSearchName.Text = ""; txtClassSearchName.Text = ""; txtCourseSearchName.Text = ""; } }
private void btnAddTeaEdu_Click(object sender, EventArgs e) { if (cmbClassName.Text == "" || cmbCourseName.Text == "" || txtTeaNo.Text == "") { MessageBox.Show("教师、班级和课程不能为空,请先选择"); } else { string strErr = ""; DataTable objDataTable = new DataTable(); Manage.Teacher_Course_Class.T_C_C objT_C_C = new Manage.Teacher_Course_Class.T_C_C(strConnection); Model.Teacher_Class.Teacher_Class objT_Class = new Model.Teacher_Class.Teacher_Class(); Model.Teacher_Course.Teacher_Course objT_Course = new Model.Teacher_Course.Teacher_Course(); objT_Class.ClassId = int.Parse(cmbClassName.SelectedValue.ToString()); objT_Course.CourseId = int.Parse(cmbCourseName.SelectedValue.ToString()); string strTeaNo1 = txtTeaNo.Text; teaId = objT_C_C.GetTeaId(strTeaNo1); int iRen = objT_C_C.JudgeTeaClassCourse(teaId, objT_Course.CourseId, objT_Class.ClassId); //判断增加的这条记录是否存在 if (iRen == 0) { MessageBox.Show("此记录已经存在"); } else { int iR = objT_C_C.JudgeClassCourse(objT_Course.CourseId, objT_Class.ClassId); //判断此班级的这门课程是否已经安排教师 if (iR == 0) { MessageBox.Show("此班级的这门课程已经安排教师,请安排给其他班级"); } else { int iRent = objT_C_C.AddTeacherC_C(objT_Course, objT_Class, teaId, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("添加成功"); BindDataGridView(); } } } } }
void BindDataGridView() { string strErr = ""; DataTable objDataTable = new DataTable(); Manage.Teacher_Course_Class.T_C_C objT_C_C = new Manage.Teacher_Course_Class.T_C_C(strConnection); int iRent = objT_C_C.SearchTCC(out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { dataGridView.DataSource = objDataTable; } }
private void btnDel_Click(object sender, EventArgs e) { int i = dataGridView.SelectedRows.Count; if (i == 0) { MessageBox.Show("请先选中你要删除的一行"); } else { //if (DialogResult.Yes == MessageBox.Show("真的要删除吗?", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) //{ for (int j = 0; j < dataGridView.SelectedRows.Count; j++) { Manage.Teacher_Course_Class.T_C_C objT_C_C = new Manage.Teacher_Course_Class.T_C_C(strConnection); Model.Teacher_Class.Teacher_Class objT_Class = new Model.Teacher_Class.Teacher_Class(); Model.Teacher_Course.Teacher_Course objT_Course = new Model.Teacher_Course.Teacher_Course(); objT_Class.ClassId = int.Parse(cmbClassName.SelectedValue.ToString()); objT_Course.CourseId = int.Parse(cmbCourseName.SelectedValue.ToString()); string strTeaNo1 = dataGridView.SelectedCells[0].Value.ToString(); teaId = objT_C_C.GetTeaId(strTeaNo1); string strTeacherNo = dataGridView.SelectedRows[j].Cells["教师编号"].Value.ToString(); string strClassNo = dataGridView.SelectedRows[j].Cells["班级编号"].Value.ToString(); string strCourseNo = dataGridView.SelectedRows[j].Cells["课程编号"].Value.ToString(); string strErr = ""; int j1 = objT_C_C.JudgeClassCourse(strCourseNo, strClassNo, out strErr); int j2 = objT_C_C.JudgeTeaClass(strTeacherNo, strClassNo, out strErr); int j3 = objT_C_C.JudgeTeaCourse(strTeacherNo, strCourseNo, out strErr); int iRent = objT_C_C.DelTCC(strTeacherNo, strClassNo, strCourseNo, out strErr); if (j1 > 1) { for (int sum1 = 0; sum1 < j1 - 1; sum1++) { int iRent1 = objT_C_C.AddClassCourse(objT_Course, objT_Class, teaId, out strErr); if (iRent1 == 0) { MessageBox.Show(strErr); return; } } } if (j2 > 1) { for (int sum2 = 0; sum2 < j2 - 1; sum2++) { int iRent2 = objT_C_C.AddTeacherClass(objT_Class, teaId, out strErr); if (iRent2 == 0) { MessageBox.Show(strErr); return; } } } if (j3 > 1) { for (int sum3 = 0; sum3 < j3 - 1; sum3++) { int iRent3 = objT_C_C.AddTeacherCourse(objT_Course, teaId, out strErr); if (iRent3 == 0) { MessageBox.Show(strErr); return; } } } if (iRent == 0) { MessageBox.Show(strErr); return; } BindDataGridView(); } MessageBox.Show("删除成功"); } //} }