Ejemplo n.º 1
0
        private void CourseAdd_Click(object sender, EventArgs e)//添加按钮功能
        {
            Course course = new Course()
            {
                cno      = Cno.Text,
                cname    = Cname.Text,
                credit   = Credit.Text,
                category = Category.Text,
                deptno   = Deptno.Text
            };
            CourseBLL courseBLL = new CourseBLL();

            #region 添加
            if (CourseAdd.Text.Equals("添加"))
            {
                if (courseBLL.Add(course))
                {
                    MessageBox.Show("添加成功");

                    LoadCourseList();
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
            #endregion
            #region 修改
            else
            {
                if (courseBLL.Edit(course))
                {
                    MessageBox.Show("修改成功");
                    LoadCourseList();
                    Cno.ReadOnly   = false;
                    CourseAdd.Text = "添加";
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
            #endregion
            Cno.Text      = "";
            Cname.Text    = "";
            Credit.Text   = "";
            Category.Text = "";
            Deptno.Text   = "";
        }