//新增课程 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("请填写所有信息!"); } }
//获取全部课程 private void btn_refreshCL_Click(object sender, EventArgs e) { CourseBusiness couBusiness = new CourseBusiness(this.studentModel.Sid); DataTable dt = new DataTable(); //没有过滤条件 if (this.cb_filter_week.Text=="全部周次" && this.cb_filter_section.Text=="全部时间") { dt = couBusiness.getAllCourse(); } else { int section = 0, week = 0; switch (this.cb_filter_section.Text) { case "周一(1)": section = 1; break; case "周一(2)": section = 2; break; case "周一(3)": section = 3; break; case "周一(4)": section = 4; break; case "周一(5)": section = 5; break; case "周一(6)": section = 6; break; case "周二(1)": section = 7; break; case "周二(2)": section = 8; break; case "周二(3)": section = 9; break; case "周二(4)": section = 10; break; case "周二(5)": section = 11; break; case "周二(6)": section = 12; break; case "周三(1)": section = 13; break; case "周三(2)": section = 14; break; case "周三(3)": section = 15; break; case "周三(4)": section = 16; break; case "周三(5)": section = 17; break; case "周三(6)": section = 18; break; case "周四(1)": section = 19; break; case "周四(2)": section = 20; break; case "周四(3)": section = 21; break; case "周四(4)": section = 22; break; case "周四(5)": section = 23; break; case "周四(6)": section = 24; break; case "周五(1)": section = 25; break; case "周五(2)": section = 26; break; case "周五(3)": section = 27; break; case "周五(4)": section = 28; break; case "周五(5)": section = 29; break; case "周五(6)": section = 30; break; case "周六(1)": section = 31; break; case "周六(2)": section = 32; break; case "周六(3)": section = 33; break; case "周六(4)": section = 34; break; case "周六(5)": section = 35; break; case "周六(6)": section = 36; break; case "周日(1)": section = 37; break; case "周日(2)": section = 38; break; case "周日(3)": section = 39; break; case "周日(4)": section = 40; break; case "周日(5)": section = 41; break; case "周日(6)": section = 42; break; case "全部时间": section = 0; break; } if (this.cb_filter_week.Text.ToString() == "1-16") { week = 1; } else if (this.cb_filter_week.Text.ToString() == "1-8") { week = 2; } else if (this.cb_filter_week.Text.ToString() == "9-16") { week = 3; } else { week = 0; } dt = couBusiness.getAllCourseWithFilter(week,section); } this.dataGridView1.AutoGenerateColumns = false; this.dataGridView1.DataSource = dt; }
//获取课程详细信息 private void dataGridView1_MouseClick(object sender, MouseEventArgs e) { DataGridViewSelectedRowCollection selectedRow = this.dataGridView1.SelectedRows; foreach (DataGridViewRow row in selectedRow) { CourseInfo courseInfo = new CourseBusiness().getCourseInfobyCid(int.Parse(row.Cells["cid"].Value.ToString())); this.textBox1.Text = "课程简介: " + courseInfo.getBriefIntro(); } }
//获得已选课 private void button3_Click(object sender, EventArgs e) { CourseBusiness couBusiness = new CourseBusiness(); DataTable dt = couBusiness.getSelectedCourse(this.studentModel.Sid); this.dataGridView2.AutoGenerateColumns = false; this.dataGridView2.DataSource = dt; }
//选课 private void btn_select_Click(object sender, EventArgs e) { DataGridViewSelectedRowCollection selectedRow = this.dataGridView1.SelectedRows; if (selectedRow != null) { foreach (DataGridViewRow row in selectedRow) { CourseBusiness courseBusiness = new CourseBusiness(); int isSelected = courseBusiness.selectCourse(this.studentModel.Sid, int.Parse(row.Cells["cid"].Value.ToString())); if (isSelected == 2) { MessageBox.Show("您还没有修此课的先修课程,不能选此课。"); } else if (isSelected == 3) { MessageBox.Show("时间冲突,请重新选择!"); } else if (isSelected == 1) { MessageBox.Show("选课成功!"); } else if (isSelected == 0) { MessageBox.Show("您已选中此课"); } else if (isSelected == -1) { MessageBox.Show("选课失败,请再试一次"); } } } }
//删除选中课程 private void button15_Click(object sender, EventArgs e) { if (MessageBox.Show("确定要删除吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes) { bool isDeleteOk = true; CourseBusiness couBusiness = new CourseBusiness(); DataGridViewSelectedRowCollection toBeDeletedRowsCollection = this.dataGridView3.SelectedRows; DataGridViewRow[] tobedeletedrows = new DataGridViewRow[toBeDeletedRowsCollection.Count]; toBeDeletedRowsCollection.CopyTo(tobedeletedrows, 0); foreach (DataGridViewRow temp in tobedeletedrows) { if (couBusiness.deleteCourse(int.Parse(temp.Cells["cid"].Value.ToString())) == 0) isDeleteOk = false; } if (isDeleteOk) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除出现错误,请刷新列表后重试!"); } } }
//课程列表更新 编辑后保存 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("更新失败"); } }
//刷新课程列表 private void button17_Click(object sender, EventArgs e) { CourseBusiness couBusiness = new CourseBusiness(); DataTable dt = couBusiness.getAllCourse(); this.dataGridView3.AutoGenerateColumns = false; this.dataGridView3.DataSource = dt; DataGridViewComboBoxColumn cob1 = new DataGridViewComboBoxColumn(); cob1 = (DataGridViewComboBoxColumn)this.dataGridView3.Columns["pid"]; cob1.DataSource = new PlaceBusiness().getAllPlace(); cob1.DisplayMember = "pname"; cob1.ValueMember = "pid"; DataGridViewComboBoxColumn cob2 = new DataGridViewComboBoxColumn(); cob2 = (DataGridViewComboBoxColumn)this.dataGridView3.Columns["ctid"]; cob2.DataSource = new TeacherBusiness().getAllTeacher(); cob2.DisplayMember = "tname"; cob2.ValueMember = "tid"; }
//刷新教师的课程 private void button5_Click(object sender, EventArgs e) { CourseBusiness couBusiness = new CourseBusiness(); DataTable dt = couBusiness.getAllCourseByTid(new TeacherBusiness().getTidByUid(this.userModel.Uid)); this.dataGridView1.AutoGenerateColumns = false; this.dataGridView1.DataSource = dt; DataGridViewComboBoxColumn cob1 = new DataGridViewComboBoxColumn(); cob1 = (DataGridViewComboBoxColumn)this.dataGridView1.Columns["pid"]; cob1.DataSource = new PlaceBusiness().getAllPlace(); cob1.DisplayMember = "pname"; cob1.ValueMember = "pid"; }