Exemple #1
0
        //增加学生和账号
        public int AddStu(Model.Student.Student objStudent, out string strErr)
        {
            int iRent = 0;

            strErr = "";
            SqlCommand sqlCom = new SqlCommand();
            string     strSql = "insert into student(classid,stuno,stuname,sex,birthdate,entrancetime,stutel,stuaddress,remark,type)";

            strSql            += "values(" + objStudent.ClassId + ",'" + objStudent.StuNo + "','" + objStudent.StuName + "','" + objStudent.Sex + "','" + objStudent.BirthDate.ToShortDateString() + "',";
            strSql            += "'" + objStudent.EntranceTime.ToShortDateString() + "','" + objStudent.StuTel + "','" + objStudent.StuAddress + "','" + objStudent.Remark + "',1)  ";
            strSql            += "insert into users(userno,username,password,rights,type) values ('" + objStudent.StuNo + "','" + objStudent.StuName + "','" + objStudent.StuNo + "',3,1);";
            sqlCom.CommandText = strSql;
            try
            {
                sqlCon.Open();
                sqlCom.Connection = sqlCon;
                sqlCom.ExecuteNonQuery();
                iRent = 1;
            }
            catch (Exception exErr)
            {
                strErr = exErr.ToString();
                iRent  = 0;
            }
            finally
            {
                sqlCon.Close();
                sqlCom.Dispose();
            }
            return(iRent);
        }
Exemple #2
0
        //修改学生信息同时修改账号
        public int ModifyStu(string stu, string studentno, Model.Student.Student objStudent, out string strErr)
        {
            int iRent = 0;

            strErr = "";
            SqlCommand sqlCom = new SqlCommand();
            string     strSql = "update student ";

            strSql            += "set classid=" + objStudent.ClassId.ToString() + ",stuno='" + objStudent.StuNo + "',stuname='" + objStudent.StuName + "',sex='" + objStudent.Sex + "',birthdate='" + objStudent.BirthDate.ToShortDateString() + "',";
            strSql            += "entrancetime='" + objStudent.EntranceTime.ToShortDateString() + "',stutel='" + objStudent.StuTel + "',stuaddress='" + objStudent.StuAddress + "',remark='" + objStudent.Remark + "' where stuno ='" + stu + "' and type=1  ";
            strSql            += " update users set userno ='" + objStudent.StuNo + "',username ='******',password='******' where userno='" + stu + "'  and type=1 ";
            sqlCom.CommandText = strSql;
            try
            {
                sqlCon.Open();
                sqlCom.Connection = sqlCon;
                sqlCom.ExecuteNonQuery();
                iRent = 1;
            }
            catch (Exception exErr)
            {
                strErr = exErr.ToString();
                iRent  = 0;
            }
            finally
            {
                sqlCon.Close();
                sqlCom.Dispose();
            }
            return(iRent);
        }
Exemple #3
0
        public void LoadData()
        {
            string strErr = "";

            Model.Student.Student objStudent = new Model.Student.Student();
            DataSet       ds            = new DataSet();
            DataTable     dt            = new DataTable();
            string        strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString;
            string        strSql        = "select * from student where stuno='" + stu + "' and type =1";
            SqlConnection conn          = new SqlConnection();

            conn.ConnectionString = strConnection;
            conn.Open();
            SqlCommand     sqlcomd = new SqlCommand();
            SqlDataAdapter da      = new SqlDataAdapter(strSql, conn);

            try
            {
                da.Fill(ds);
            }
            catch (Exception exce)
            {
                strErr = exce.ToString();
            }
            finally
            {
                conn.Close();
            }
            DataRow dr = ds.Tables[0].Rows[0];

            studentno                 = this.txtStuNo.Text = dr["StuNo"].ToString();
            this.txtStuName.Text      = dr["StuName"].ToString();
            this.txtAddress.Text      = dr["StuAddress"].ToString();
            this.txtRemark.Text       = dr["Remark"].ToString();
            this.dtpBirthDate.Text    = dr["BirthDate"].ToString();
            this.dtpEntranceTime.Text = dr["EntranceTime"].ToString();
            //string str =dr["ClassId"].ToString ();
            //this.cmbClassId.ValueMember= dr["ClassId"].ToString ();
            //this.cmbClassId.DisplayMember =dr["ClassName"];
            //this.txtStuTel.Text = dr["StuTel"].ToString();

            this.cmbClassId.SelectedValue = dr["ClassId"].ToString();
            if (dr["sex"].ToString() == "男")
            {
                this.rabMan.Checked = true;
            }
            else
            {
                this.rabWoman.Checked = true;
            }
        }
Exemple #4
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("不能重复插入分数");
            }
        }
Exemple #5
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("当前要修改的成绩不存在,请确定后再修改");
            }
        }
Exemple #6
0
        }//学生登陆后,绑定表里显示的数据

        public int Judge(Model.Student.Student objStuId, Model.Course.Course objCourseId)
        {
            string strErr = "";

            Model.Score.Score objScore      = new Model.Score.Score();
            DataSet           ds            = new DataSet();
            string            strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString;
            string            strSql        = "select Score from score where stuid='" + objStuId.StuId.ToString() + "'and CourseId='" + objCourseId.CourseId + "'and type =1";
            SqlConnection     sqlCon        = new SqlConnection();

            sqlCon.ConnectionString = strConnection;
            sqlCon.Open();
            SqlCommand     sqlCom = new SqlCommand();
            SqlDataAdapter da     = new SqlDataAdapter(strSql, sqlCon);

            try
            {
                da.Fill(ds);
            }
            catch (Exception exce)
            {
                strErr = exce.ToString();
            }
            finally
            {
                sqlCon.Close();
            }

            if (ds.Tables[0].Rows.Count != 0)
            {
                return(1);
            }

            else
            {
                return(0);
            }
        }
Exemple #7
0
        }//管理员按班级查询班级内所有学生的成绩。

        public int SearchScoreStudent(string StuNo, out DataTable objDataTable, out string strErr)
        {
            int iReturn = 0;

            strErr = "";
            SqlCommand sqlCom = new SqlCommand();
            string     strCom;

            objDataTable = new DataTable();
            Model.Student.Student objStudent = new Model.Student.Student();

            strCom  = "select student.stuNo 学生编号,student.stuName 姓名,course.courseNo 课程编号,course.courseName 课程名称,score.score 得分 from student,score,course where student.stuNo like '%";
            strCom += StuNo.ToString() + "%'escape '\\'and score.stuId = student.stuId and  course.courseId = score.courseId and score.Type = 1 and student.Type = 1";


            //strCom = "select student.stuNo 学生编号,student.stuName 姓名,course.courseNo 课程编号,course.courseName 课程名称,score.score 得分 from student,score,course where student.StuName like '%";
            //strCom += StuName.ToString() + "%'escape '\\'and score.stuId = student.stuId and  course.courseId = score.courseId and score.Type = 1 and student.Type = 1";
            sqlCom.CommandText = strCom;
            sqlCom.Connection  = sqlCon;
            SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCom);

            try
            {
                sqlDa.Fill(objDataTable);
                iReturn = 1;
            }
            catch (Exception ex)
            {
                strErr  = ex.ToString();
                iReturn = 0;
            }
            finally
            {
                sqlDa.Dispose();
                sqlCom.Dispose();
            }
            return(iReturn);
        }//管理员按学生编号查询该学生的各科成绩。
Exemple #8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            Model.Student.Student objStudent = new Model.Student.Student();
            string strConnection             = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString;

            Manage.Student.Student objStu = new Manage.Student.Student(strConnection);
            int Ar = objStu.JudgeClassExist();

            if (Ar == 0)
            {
                MessageBox.Show("不存在班级,将不能添加学生");
            }
            else
            {
                objStudent.StuNo   = txtStuNo.Text.Replace("'", "''");
                objStudent.StuNo   = objStudent.StuNo.Trim();
                objStudent.StuName = txtStuName.Text.Replace("'", "''");
                objStudent.StuName = objStudent.StuName.Trim();
                if (objStudent.StuNo == "" || objStudent.StuName == "")
                {
                    MessageBox.Show("请将信息填写完整!");
                }
                else
                {
                    if (rabWoman.Checked == true)
                    {
                        objStudent.Sex = "女";
                    }
                    else
                    {
                        objStudent.Sex = "男";
                    }
                    objStudent.BirthDate    = dtpBirthDate.Value;
                    objStudent.EntranceTime = dtpEntranceTime.Value;
                    //objStudent.StuTel = txtStuTel.Text.ToString();
                    //objStudent.StuTel = txtStuTel.Text.Replace("'", "''");
                    if (this.txtStuTel.Text != "")
                    {
                        string patten = @"(13\d{9}(;13\d{9})*)|(15\d{9}(;15\d{9})*)|(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}(;(\(\d{3,4}\)|\d{3,4}-)?\d{7,8})*";
                        Regex  r      = new Regex(patten);
                        Match  m      = r.Match(txtStuTel.Text);
                        if (!m.Success)
                        {
                            MessageBox.Show("请输入正确的电话号码");
                            this.txtStuTel.Text = "";
                            this.txtStuTel.Focus();
                            return;
                        }
                        else
                        {
                            objStudent.StuTel = txtStuTel.Text.ToString();
                        }
                    }

                    objStudent.StuAddress = txtAddress.Text.Replace("'", "''");
                    objStudent.Remark     = txtRemark.Text.Replace("'", "''");

                    objStudent.ClassId = int.Parse(cmbClassId.SelectedValue.ToString());
                    //int Ar= objStu. JudgeClassExist();

                    int iExist = objStu.JudgeStuNo(objStudent.StuNo);
                    int R      = objStu.JudgeStuNoLikeTeaNo(objStudent.StuNo);
                    if (iExist == 1)
                    {
                        MessageBox.Show("此编号的学生已经存在,请重新为此学生编号");
                    }
                    else if (R == 1)
                    {
                        MessageBox.Show("存在一个此编号的教师,学生编号不能和教师编号相同");
                    }
                    else
                    {
                        int iRent = objStu.AddStu(objStudent, out strErr);
                        if (iRent == 0)
                        {
                            MessageBox.Show(strErr);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("添加学生信息成功,同时系统为此学生创建账号成功");
                            this.Visible = false;
                        }
                    }
                }
            }
        }
Exemple #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            Model.Student.Student objStudent = new Model.Student.Student();
            string strConnection             = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString;

            Manage.Student.Student objStu = new Manage.Student.Student(strConnection);
            objStudent.StuNo   = txtStuNo.Text.Replace("'", "''");
            objStudent.StuNo   = objStudent.StuNo.Trim();
            objStudent.StuName = txtStuName.Text.Replace("'", "''");
            objStudent.StuName = objStudent.StuName.Trim();
            if (objStudent.StuName == "" || objStudent.StuNo == "")
            {
                MessageBox.Show("请将信息填写完整!");
            }
            else
            {
                if (this.rabWoman.Checked == true)
                {
                    objStudent.Sex = "女";
                }
                else
                {
                    objStudent.Sex = "男";
                }
                objStudent.BirthDate    = dtpBirthDate.Value;
                objStudent.EntranceTime = dtpEntranceTime.Value;
                //objStudent.StuTel = txtStuTel.Text.Replace("'", "''");
                if (this.txtStuTel.Text != "")
                {
                    string patten = @"(13\d{9}(;13\d{9})*)|(15\d{9}(;15\d{9})*)|(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}(;(\(\d{3,4}\)|\d{3,4}-)?\d{7,8})*";
                    Regex  r      = new Regex(patten);
                    Match  m      = r.Match(txtStuTel.Text);
                    if (!m.Success)
                    {
                        MessageBox.Show("请输入正确的电话号码");
                        this.txtStuTel.Text = "";
                        this.txtStuTel.Focus();
                        return;
                    }
                    else
                    {
                        objStudent.StuTel = txtStuTel.Text.ToString();
                    }
                }

                objStudent.StuAddress = txtAddress.Text.Replace("'", "''");
                objStudent.Remark     = txtRemark.Text.Replace("'", "''");
                objStudent.ClassId    = int.Parse(cmbClassId.SelectedValue.ToString());
                if (studentno == objStudent.StuNo)
                {
                    int iRent = objStu.ModifyStu(stu, studentno, objStudent, out strErr);
                    if (iRent == 0)
                    {
                        MessageBox.Show(strErr);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("修改成功!");
                        this.Visible = false;
                    }
                }
                else
                {
                    int iExist = objStu.JudgeStuNo(objStudent.StuNo);
                    int i      = objStu.JudgeStuNoLikeTeaNo(objStudent.StuNo);
                    if (iExist == 0 && i == 0)
                    {
                        int iRent = objStu.ModifyStu(stu, studentno, objStudent, out strErr);
                        if (iRent == 0)
                        {
                            MessageBox.Show(strErr);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("修改成功,同时此学生的账号和密码也修改成功!");
                            this.Visible = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("已经存在一个编号相同的学生或者教师,修改失败");
                        txtStuNo.Text = studentno;
                    }
                }
            }
        }