Exemplo n.º 1
0
        //课程列表更新 编辑后保存
        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("更新失败");
            }
        }