//修改课程 public bool ChangeCourse(CourseModel objCourseModel) { #region // //public bool ChangeCourse(string Course, string CourseNum, string CourseName, string Credit, string ProOrPub, string NeedOrOpt) //{ // string SQLString; // SQLString = "update Course set CourseNum='" + CourseNum + "',CourseName='" + CourseName + "'"; // SQLString += ",Credit='" + Credit + "',ProOrPub='" + ProOrPub + "'"; // SQLString += ",NeedOrOpt='" + NeedOrOpt + "'where CourseNum='" + Course + "'"; // DataBaseOperateClass objDataBase = new DataBaseOperateClass(); // if (objDataBase.GetExecute(SQLString)) // return (true); // else // return (false); //} #endregion #region 使用实体类在各层之间传递数据 string SQLString; SQLString = "update Course set CourseNum='" + objCourseModel.CourseNum + "',CourseName='" + objCourseModel.CourseName + "',Credit='" + objCourseModel.Credit + "',ProOrPub='" + objCourseModel.ProOrPub + "',NeedOrOpt='" + objCourseModel.NeedOrOpt + "',DeptNum='"+ objCourseModel.DeptNum+"' where CourseNum='" + objCourseModel.CourseNum + "'"; DataBaseOperaClass objDataBase = new DataBaseOperaClass(); if (objDataBase.GetExecute(SQLString)) return (true); else return (false); #endregion }
//添加课程的业务逻辑 public bool AddCourse(CourseModel objCourseModel) { CourseDAL objCourseDAL = new CourseDAL(); if (objCourseDAL.SearchCoursebool(objCourseModel)==true) { MessageBox.Show("课程已存在,不能添加"); return (false); } else { return (objCourseDAL.AddCourse(objCourseModel)); } #region // //public bool AddCourse(string CourseNum, string CourseName, string Credit, string ProOrPub, string NeedOrOpt) //{ // CourseDALClass objCourseDAL = new CourseDALClass(); // if (objCourseDAL.SearchCourse(CourseNum) == true) // { // MessageBox.Show("课程已存在,不能添加"); // return(false); // } // else // { // return (objCourseDAL.AddCourse(CourseNum,CourseName,Credit,ProOrPub,NeedOrOpt)); // } //} #endregion }
public CourseInfo(CourseModel cModel, TeacherModel tModel, PlaceModel pModel, String precName) { this.cModel = cModel; this.tModel = tModel; this.pModel = pModel; this.precourseName = precName; updateCourseInfo(); }
//返回结果: public DataTable SearchCourse(CourseModel objCourseModel) { string SqlString = "Select * from Course where CourseNum='" + objCourseModel.CourseNum + "'"; DataBaseOperateClass2 objDataBaseOperateClass2=new DataBaseOperateClass2(); DataTable objDataTable; return objDataTable = objDataTable = objDataBaseOperateClass2.ShowTable(SqlString); }
//查找课程 public bool SearchCoursebool(CourseModel objCourseModel) { string SqlString = "Select * from Course where CourseNum='" + objCourseModel.CourseNum + "'"; DataBaseOperateClass2 objDataBaseOperateClass2 = new DataBaseOperateClass2(); if (objDataBaseOperateClass2.GetDataRow(SqlString) != null) return (true); else return (false); }
public bool AddCourse( CourseModel objCourseModel) { #region 使用实体类在各层之间传递数据 string SqlString = "Insert into Course(CourseNum,CourseName,Credit,ProOrPub,NeedOrOpt,DeptNum) values('" + objCourseModel.CourseNum + "','" + objCourseModel.CourseName + "','" + objCourseModel.Credit + "','" + objCourseModel.ProOrPub + "','" + objCourseModel.DeptNum + "','"+objCourseModel.DeptNum+"')"; DataBaseOperaClass objDataBase = new DataBaseOperaClass(); if (objDataBase.GetExecute(SqlString)) return (true); else return (false); #endregion }
//新增课程 private void button1_Click(object sender, EventArgs e) { if (this.tb_cname.Text != "" && this.tb_credit.Text != "" && this.cb_week.Text != "请选择周次" && this.cb_tid.Text != "请选择教师" && this.cb_section.Text != "请选择时间" && this.cb_pid.Text != "请选择地点") { cname = this.tb_cname.Text; credit = int.Parse(this.tb_credit.Text); week = this.cb_section.SelectedIndex + 1;//1:1-16 2:1-8 3:9-16 section = this.cb_section.SelectedIndex+1; tid = int.Parse(this.cb_tid.SelectedValue.ToString()); pid = int.Parse(this.cb_pid.SelectedValue.ToString()); maxstu = int.Parse(this.tb_maxstu.Text); if (this.tb_precourse.Text != "") { precourse = int.Parse(this.tb_precourse.Text); } else { precourse = 0; } int cid = 0; CourseBusiness couBusiness = new CourseBusiness(); CourseModel courseModel = new CourseModel(cid,cname,credit,week,section,tid,pid,precourse,maxstu); cid = couBusiness.addCourse(courseModel); if (cid != 0) { MessageBox.Show("成功!"); } else { MessageBox.Show("失败,请重试!"); } this.Dispose(); } else { MessageBox.Show("请填写所有信息!"); } }
public int insert(CourseModel courseModel) { MySqlConnection conn = GetConn.getConn(); try { conn.Open(); MySqlCommand cmd = new MySqlCommand("insert into `tb_course` (cname,credit,week,section,tid,pid,precourse,maxstu) values (@cname,@credit,@week,@section,@tid,@pid,@precourse,@maxstu)", conn); cmd.Parameters.AddWithValue("@cname", courseModel.Cname); cmd.Parameters.AddWithValue("@credit", courseModel.Credit); cmd.Parameters.AddWithValue("@week", courseModel.Week); cmd.Parameters.AddWithValue("@section", courseModel.Section); cmd.Parameters.AddWithValue("@tid", courseModel.Tid); cmd.Parameters.AddWithValue("@pid", courseModel.Pid); cmd.Parameters.AddWithValue("@precourse", courseModel.Precourse); cmd.Parameters.AddWithValue("@maxstu", courseModel.Maxstu); cmd.ExecuteNonQuery(); cmd.Dispose(); return 1; } catch (Exception) { conn.Close(); return 0; } }
public bool DelCourse(CourseModel objCourseModel) { CourseDAL objCourseDAL = new CourseDAL(); return (objCourseDAL.DeletCourse(objCourseModel)); }
//删除课程 public bool DeletCourse(CourseModel objCourseModel ) { string SqlString = "DELETE FROM Course WHERE CourseNum='" + objCourseModel.CourseNum + "'"; DataBaseOperaClass objDataBase = new DataBaseOperaClass(); return (objDataBase.GetExecute(SqlString)); }
private void Del_Click(object sender, EventArgs e) { if (txtCourseNum.Text == "") { MessageBox.Show("课程号不能为空!\n 请重新输入!"); } else { CourseBLL objCourseBLL = new CourseBLL(); CourseModel objCourseModel = new CourseModel(); objCourseModel.CourseNum = txtCourseNum.Text; if (objCourseBLL.DelCourse(objCourseModel) == true) { MessageBox.Show("成功删除!!"); } else { MessageBox.Show("删除失败!"); } ShowCourseInfo(); } }
public int updatecourse(CourseModel couModel) { return new CourseService().update(couModel); }
public int addCourse(CourseModel courseModel) { return new CourseService().insert(courseModel); }
public int update(CourseModel couModel) { MySqlConnection conn = GetConn.getConn(); try { conn.Open(); MySqlCommand cmd = new MySqlCommand("update `tb_course` set `cname`=@cname, `credit`=@credit, `week`=@week, `section`=@section, `tid`=@tid, `pid`=@pid, `precourse`=@precourse, `maxstu`=@maxstu where `cid`=@cid", conn); cmd.Parameters.AddWithValue("@cname", couModel.Cname); cmd.Parameters.AddWithValue("@credit", couModel.Credit); cmd.Parameters.AddWithValue("@week", couModel.Week); cmd.Parameters.AddWithValue("@section", couModel.Section); cmd.Parameters.AddWithValue("@tid", couModel.Tid); cmd.Parameters.AddWithValue("@pid", couModel.Pid); cmd.Parameters.AddWithValue("@precourse", couModel.Precourse); cmd.Parameters.AddWithValue("@maxstu", couModel.Maxstu); cmd.Parameters.AddWithValue("@cid", couModel.Cid); int result = cmd.ExecuteNonQuery(); cmd.Dispose(); return result; } catch (Exception) { conn.Close(); return 0; } }
public bool ChangeCourse(CourseModel objCourseModel) { CourseDAL objCourseDAL = new CourseDAL(); return (objCourseDAL.ChangeCourse(objCourseModel)); }
public CourseModel getCoursebyCid(int cid) { MySqlConnection conn = GetConn.getConn(); CourseModel cModel = new CourseModel(); try { conn.Open(); MySqlCommand cmd = new MySqlCommand("select * from `tb_course` where cid = @cid", conn); cmd.Parameters.AddWithValue("@cid", cid); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { cModel.Cid = int.Parse(reader["cid"].ToString()); cModel.Cname = reader["cname"].ToString(); cModel.Credit = int.Parse(reader["credit"].ToString()); cModel.Week = int.Parse(reader["week"].ToString()); cModel.Section = int.Parse(reader["section"].ToString()); cModel.Tid = int.Parse(reader["tid"].ToString()); cModel.Pid = int.Parse(reader["pid"].ToString()); cModel.Precourse = int.Parse(reader["precourse"].ToString()); //cModel.Maxstu = int.Parse(reader["maxstu"].ToString()); } conn.Close(); return cModel; } catch (Exception) { conn.Close(); return null; } }
//课程列表更新 编辑后保存 private void dataGridView3_CellEndEdit(object sender, DataGridViewCellEventArgs e) { CourseModel couModelToBeUpdated = new CourseModel(); CourseBusiness couBusiness = new CourseBusiness(); couModelToBeUpdated.Cid = int.Parse(this.dataGridView3.CurrentRow.Cells["cid"].Value.ToString()); couModelToBeUpdated.Cname = this.dataGridView3.CurrentRow.Cells["cname"].Value.ToString(); couModelToBeUpdated.Credit = int.Parse(this.dataGridView3.CurrentRow.Cells["credit"].Value.ToString()); if (this.dataGridView3.CurrentCell.ColumnIndex == this.dataGridView3.Columns["pid"].Index) { couModelToBeUpdated.Pid = int.Parse(this.dataGridView3.CurrentRow.Cells["pid"].Value.ToString()); } else { couModelToBeUpdated.Pid = int.Parse(this.dataGridView3.CurrentRow.Cells["placeid"].Value.ToString()); } if (this.dataGridView3.CurrentCell.ColumnIndex == this.dataGridView3.Columns["ctid"].Index) { couModelToBeUpdated.Tid = int.Parse(this.dataGridView3.CurrentRow.Cells["ctid"].Value.ToString()); } else { couModelToBeUpdated.Tid = int.Parse(this.dataGridView3.CurrentRow.Cells["teacherid"].Value.ToString()); } switch (this.dataGridView3.CurrentRow.Cells["section"].Value.ToString()) { case "周一(1)": couModelToBeUpdated.Section = 1; break; case "周一(2)": couModelToBeUpdated.Section = 2; break; case "周一(3)": couModelToBeUpdated.Section = 3; break; case "周一(4)": couModelToBeUpdated.Section = 4; break; case "周一(5)": couModelToBeUpdated.Section = 5; break; case "周一(6)": couModelToBeUpdated.Section = 6; break; case "周二(1)": couModelToBeUpdated.Section = 7; break; case "周二(2)": couModelToBeUpdated.Section = 8; break; case "周二(3)": couModelToBeUpdated.Section = 9; break; case "周二(4)": couModelToBeUpdated.Section = 10; break; case "周二(5)": couModelToBeUpdated.Section = 11; break; case "周二(6)": couModelToBeUpdated.Section = 12; break; case "周三(1)": couModelToBeUpdated.Section = 13; break; case "周三(2)": couModelToBeUpdated.Section = 14; break; case "周三(3)": couModelToBeUpdated.Section = 15; break; case "周三(4)": couModelToBeUpdated.Section = 16; break; case "周三(5)": couModelToBeUpdated.Section = 17; break; case "周三(6)": couModelToBeUpdated.Section = 18; break; case "周四(1)": couModelToBeUpdated.Section = 19; break; case "周四(2)": couModelToBeUpdated.Section = 20; break; case "周四(3)": couModelToBeUpdated.Section = 21; break; case "周四(4)": couModelToBeUpdated.Section = 22; break; case "周四(5)": couModelToBeUpdated.Section = 23; break; case "周四(6)": couModelToBeUpdated.Section = 24; break; case "周五(1)": couModelToBeUpdated.Section = 25; break; case "周五(2)": couModelToBeUpdated.Section = 26; break; case "周五(3)": couModelToBeUpdated.Section = 27; break; case "周五(4)": couModelToBeUpdated.Section = 28; break; case "周五(5)": couModelToBeUpdated.Section = 29; break; case "周五(6)": couModelToBeUpdated.Section = 30; break; case "周六(1)": couModelToBeUpdated.Section = 31; break; case "周六(2)": couModelToBeUpdated.Section = 32; break; case "周六(3)": couModelToBeUpdated.Section = 33; break; case "周六(4)": couModelToBeUpdated.Section = 34; break; case "周六(5)": couModelToBeUpdated.Section = 35; break; case "周六(6)": couModelToBeUpdated.Section = 36; break; case "周日(1)": couModelToBeUpdated.Section = 37; break; case "周日(2)": couModelToBeUpdated.Section = 38; break; case "周日(3)": couModelToBeUpdated.Section = 39; break; case "周日(4)": couModelToBeUpdated.Section = 40; break; case "周日(5)": couModelToBeUpdated.Section = 41; break; case "周日(6)": couModelToBeUpdated.Section = 42; break; } //couModelToBeUpdated.Section = int.Parse(this.dataGridView3.CurrentRow.Cells["section"].Value.ToString()); if (this.dataGridView3.CurrentRow.Cells["week"].Value.ToString() == "1-16") { couModelToBeUpdated.Week = 1; } else if (this.dataGridView3.CurrentRow.Cells["week"].Value.ToString() == "1-8") { couModelToBeUpdated.Week = 2; } else { couModelToBeUpdated.Week = 3; } couModelToBeUpdated.Precourse = int.Parse(this.dataGridView3.CurrentRow.Cells["precourse"].Value.ToString()); couModelToBeUpdated.Maxstu = int.Parse(this.dataGridView3.CurrentRow.Cells["maxstu"].Value.ToString()); int result = couBusiness.updatecourse(couModelToBeUpdated); if (result != 0) { MessageBox.Show("更新成功"); } else { MessageBox.Show("更新失败"); } }