private void btnDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 0) { MessageBox.Show("请先选中要删除的行"); } else { string strErr = ""; string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Course.Course objManageCourse = new Manage.Course.Course(strConnection); for (int i = 0; i < dataGridView.SelectedRows.Count; i++) { //int iCourseId = int.Parse(dataGridView.SelectedRows[i].Cells["课程ID"].Value.ToString()); string strCourseNo = dataGridView.SelectedRows[i].Cells["课程编号"].Value.ToString(); //int iRent = objManageCourse.DelCourse(iCourseId,out strErr); int iRent = objManageCourse.DelCourse(strCourseNo, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } } BindDataGridView(); } }
private void btnSearch_Click(object sender, EventArgs e) { string strCourseNo = txtCourseNo.Text.Replace(@"\", @"\\"); strCourseNo = strCourseNo.Replace("%", @"\%"); strCourseNo = strCourseNo.Replace("_", @"\_"); strCourseNo = strCourseNo.Replace("'", @"\''"); strCourseNo = strCourseNo.Trim(); string strCourseName = txtCourseName.Text.Replace(@"\", @"\\"); strCourseName = strCourseName.Replace("%", @"\%"); strCourseName = strCourseName.Replace("_", @"\_"); strCourseName = strCourseName.Replace("'", @"\''"); strCourseName = strCourseName.Trim(); string strClassName = txtClassName.Text.Replace(@"\", @"\\"); strClassName = strClassName.Replace("%", @"\%"); strClassName = strClassName.Replace("_", @"\_"); strClassName = strClassName.Replace("'", @"\''"); strClassName = strClassName.Trim(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Course.Course objManageCourse = new Manage.Course.Course(strConnection); string strErr = ""; if (strCourseNo == "" && strCourseName == "" && strClassName == "") { BindDataGridView(); } else { DataTable objDataTable = new DataTable(); //DataTable objDataTable = new DataTable(); int iRent = objManageCourse.SearchCourse(iRight, strUserNo, strCourseNo, strCourseName, strClassName, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); } else { if (objDataTable.Rows.Count == 0) { MessageBox.Show("没有您要查询的记录"); dataGridView.DataSource = objDataTable; } else { dataGridView.DataSource = objDataTable; } } txtCourseNo.Text = ""; txtCourseName.Text = ""; txtClassName.Text = ""; } }
void BindDataGridView() { string strErr = ""; DataTable objDataTable = new DataTable(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Course.Course objManageCourse = new Manage.Course.Course(strConnection); int iRent = objManageCourse.SearchCourseAll(iRight, strUserNo, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { dataGridView.DataSource = objDataTable; } }
void BindCourseName() { string strErr = ""; DataTable objDataTable = new DataTable(); Manage.Course.Course objCourse = new Manage.Course.Course(strConnection); int iRent = objCourse.SearchCourse1(out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { cmbCourseName.DataSource = objDataTable; cmbCourseName.DisplayMember = "课程名称"; cmbCourseName.ValueMember = "课程ID"; } }
void BindCourseId() { string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Course.Course objCourse = new Manage.Course.Course(strConnection); string strErr = ""; DataTable objDataTable = new DataTable(); int iRent = objCourse.SearchCourse3(out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { cmbCourseName.DataSource = objDataTable; cmbCourseName.DisplayMember = "CourseName"; cmbCourseName.ValueMember = "CourseId"; } }
private void btnSubmit_Click(object sender, EventArgs e) { string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Course.Course objManageCourse = new Manage.Course.Course(strConnection); string strErr = ""; Model.Course.Course objCourse = new Model.Course.Course(); objCourse.CourseNo = txtCourseNo1.Text.Replace("'", "''"); objCourse.CourseNo = objCourse.CourseNo.Trim(); objCourse.CourseName = txtCourseName.Text.Replace("'", "''"); objCourse.CourseName = objCourse.CourseName.Trim(); //objCourse.Points = float.Parse(this.txtPoints.Text.ToString().Replace("'", "''")); //objCourse.Points = objCourse.Points.Trim(); objCourse.Remark = txtRemark.Text.Replace("'", "''"); objCourse.Remark = objCourse.Remark.Trim(); if (this.txtPoints.Text != "") { try { objCourse.Points = float.Parse(this.txtPoints.Text.ToString().Replace("'", "''")); if (this.txtPoints.Text.IndexOf('.') == 0) { MessageBox.Show("小数点之前没有数字"); return; } if (this.txtPoints.Text.Length - this.txtPoints.Text.IndexOf('.') - 1 == 0) { MessageBox.Show("小数点后没有数字"); return; } else { objCourse.Points = float.Parse(this.txtPoints.Text.ToString().Replace("'", "''")); } if (objCourse.Points < 0) { MessageBox.Show("请输入正数"); return; } } catch { MessageBox.Show("请输入正确的学分"); this.txtPoints.Text = ""; this.txtPoints.Focus(); return; } } //objCourse.CourseNo = txtCourseNo.Text.Replace("'", "''"); //objCourse.CourseNo = objCourse.CourseNo.Trim(); //objCourse.CourseName = txtCourseName.Text.Replace("'", "''"); //objCourse.CourseName = objCourse.CourseName.Trim(); //objCourse.Points = float.Parse(this.txtPoints.Text.ToString().Replace("'", "''")); //objCourse.Points = objCourse.Points.Trim(); //objCourse.Remark = txtRemark.Text.Replace("'", "''"); //objCourse.Remark = objCourse.Remark.Trim(); if (txtCourseName.Text == "" || txtCourseNo1.Text == "") { MessageBox.Show("请将课程编号和名称填写完整"); } else if (courseno == objCourse.CourseNo && coursename == objCourse.CourseName) { int iRent = objManageCourse.ModifyCourse(strCourseNumber, objCourse, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } else { int iCourseNo1 = objManageCourse.JudgeCourseNo(objCourse.CourseNo, out strErr); int iCourseNo2 = objManageCourse.JudgeCourseName(objCourse.CourseName, out strErr); if (courseno != objCourse.CourseNo && coursename == objCourse.CourseName) { if (iCourseNo1 == 0) { int iRent = objManageCourse.ModifyCourse(strCourseNumber, objCourse, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } else { MessageBox.Show("当前课程编号已经存在,修改失败"); txtCourseNo.Text = courseno; } } else if (courseno == objCourse.CourseNo && coursename != objCourse.CourseName) { if (iCourseNo2 == 0) { int iRent = objManageCourse.ModifyCourse(strCourseNumber, objCourse, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } else { MessageBox.Show("当前课程名称已经存在,修改失败"); txtCourseNo.Text = courseno; } } else { if (iCourseNo1 == 0 && iCourseNo2 == 0) { int iRent = objManageCourse.ModifyCourse(strCourseNumber, objCourse, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } else { MessageBox.Show("当前课程编号和名称都已经存在,修改失败"); txtCourseNo.Text = courseno; } } } }