Ejemplo n.º 1
0
        //添加成绩信息
        private void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            Model.Class.Class     objClass1   = new Model.Class.Class();
            Model.Student.Student objStudent1 = new Model.Student.Student();
            Model.Course.Course   objCourse1  = new Model.Course.Course();
            objClass1.ClassNo   = cmbClassName.SelectedValue.ToString();
            objStudent1.StuId   = int.Parse(cmbStuNo.SelectedValue.ToString());
            objCourse1.CourseId = int.Parse(cmbCourseName.SelectedValue.ToString());
            string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString;

            Manage.Score.Score objSco = new Manage.Score.Score(strConnection);

            int i = objSco.Judge(objStudent1, objCourse1);        // 判断是否存在所选的成绩,如果为0,表示不存在记录,可以增加。为1表示存在记录,不能重复插入成绩。

            if (i == 0)
            {
                Model.Score.Score     objScore   = new Model.Score.Score();
                Model.Student.Student objStudent = new Model.Student.Student();
                Model.Course.Course   objCourse  = new Model.Course.Course();

                objScore.CourseId = int.Parse(cmbCourseName.SelectedValue.ToString());
                objScore.StuId    = int.Parse(cmbStuNo.SelectedValue.ToString());
                objScore.score    = float.Parse(nudScore.Value.ToString());
                objScore.StuName  = txtStuName.Text;
                int iRent = objSco.AddScore(objScore, out strErr);
                if (iRent == 0)
                {
                    MessageBox.Show(strErr);
                    return;
                }
                else
                {
                    MessageBox.Show("添加成功");
                    this.Visible = false;
                    BindClassId();
                    BindStuId();
                    BindCourseId();
                }
            }
            else
            {
                MessageBox.Show("不能重复插入分数");
            }
        }
Ejemplo n.º 2
0
        //修改成绩信息
        private void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            Model.Student.Student objStudent1 = new Model.Student.Student();
            Model.Course.Course   objCourse1  = new Model.Course.Course();
            objStudent1.StuId   = int.Parse(txtStuNo.ToString());
            objCourse1.CourseId = int.Parse(txtCourseNo.ToString());
            string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString;

            Manage.Score.Score objSco = new Manage.Score.Score(strConnection);
            int i = objSco.Judge(objStudent1, objCourse1);     //返回为0,表示不存在该成绩记录,不能修改。返回为1,表示存在记录,可以修改。

            if (i == 1)
            {
                if (DialogResult.Yes == MessageBox.Show("真的要修改该成绩吗?", "确认修改", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    string                strEr      = "";
                    Model.Score.Score     objScore   = new Model.Score.Score();
                    Model.Student.Student objStudent = new Model.Student.Student();
                    Model.Course.Course   objCourse  = new Model.Course.Course();
                    objScore.CourseId = int.Parse(txtCourseNo.ToString());
                    objScore.StuId    = int.Parse(txtStuNo.ToString());
                    objScore.score    = float.Parse(nudScore.Value.ToString());
                    int iRent = objSco.ModifyScore(objScore, out strErr);
                    if (iRent == 0)
                    {
                        MessageBox.Show(strEr);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("修改成功");
                        //BindDataGridView();
                        this.Visible = false;
                    }
                }
            }
            else if (i == 0)
            {
                MessageBox.Show("当前要修改的成绩不存在,请确定后再修改");
            }
        }