예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

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

            Manage.Teacher.Teacher objTea = new Manage.Teacher.Teacher(strConnection);
            objTeacher.TeaNo   = txtTeaNo.Text.Replace("'", "''");
            objTeacher.TeaNo   = objTeacher.TeaNo.Trim();
            objTeacher.TeaName = txtTeaName.Text.Replace("'", "''");
            objTeacher.TeaName = objTeacher.TeaName.Trim();
            if (objTeacher.TeaNo == "" || objTeacher.TeaName == "")
            {
                MessageBox.Show("请将信息填写完整!");
            }
            else
            {
                if (rabMan.Checked == true)
                {
                    objTeacher.Sex = "男";
                }
                else
                {
                    objTeacher.Sex = "女";
                }
                objTeacher.Age        = int.Parse(nudAge.Value.ToString());
                objTeacher.Rank       = cmbRank.SelectedItem.ToString();
                objTeacher.Degree     = cmbDegree.SelectedItem.ToString();
                objTeacher.TeaAddress = txtAddress.Text.Replace("'", "''");
                objTeacher.TeaTel     = txtTel.Text.Replace("'", "''");
                objTeacher.Remark     = txtRemark.Text.Replace("'", "''");
                int iTeaNo = objTea.JudgeTeaNo(objTeacher.TeaNo);                                  //判断教师编号间是否重复
                int iR     = objTea.JudgeTeaNoLikeStuNo(objTeacher.TeaNo);                         //判断教师编号与学生编号是否重复
                if (iTeaNo == 0)
                {
                    MessageBox.Show("此编号的教师已经存在,添加失败");
                }
                else if (iR == 0)
                {
                    MessageBox.Show("存在一个此编号的学生,教师编号不能和学生编号相同");
                }
                else
                {
                    int iRent = objTea.AddTea(objTeacher, out strErr);
                    if (iRent == 0)
                    {
                        MessageBox.Show(strErr);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("添加成功");
                        this.Visible = false;
                    }
                }
            }
        }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string strErr;
            string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString;

            Model.Teacher.Teacher  objTea       = new Model.Teacher.Teacher();
            Manage.Teacher.Teacher objTeaManage = new Manage.Teacher.Teacher(strConnection);
            objTea.TeaNo      = txtTeaNo.Text.Replace("'", "''");
            objTea.TeaNo      = txtTeaNo.Text.Trim();
            objTea.TeaName    = txtTeaName.Text.Replace("'", "''");
            objTea.TeaName    = txtTeaName.Text.Trim();
            objTea.Age        = int.Parse(nudAge.Value.ToString());
            objTea.Rank       = cmbRank.Text;
            objTea.TeaTel     = txtTel.Text.Replace("'", "''");
            objTea.TeaTel     = txtTel.Text.Trim();
            objTea.TeaAddress = txtAddress.Text.Replace("'", "''");
            objTea.TeaAddress = txtAddress.Text.Trim();
            objTea.Degree     = cmbDegree.Text;
            objTea.Remark     = txtRemark.Text.Replace("'", "''");
            objTea.Remark     = txtRemark.Text.Trim();


            if (rdbMan.Checked == true)
            {
                objTea.Sex = "男";
            }
            else
            {
                objTea.Sex = "女";
            }
            if (txtTeaNo.Text == "" || txtTeaName.Text == "")
            {
                MessageBox.Show("教师编号和姓名不能为空");
                txtTeaNo.Text   = strTeaNo;
                txtTeaName.Text = strTeaName;
            }
            else if (objTea.TeaNo == strTeaNo)
            {
                int iRent = objTeaManage.ModifyTea(strTeaNo, objTea, out strErr);
                if (iRent == 0)
                {
                    MessageBox.Show(strErr);
                    return;
                }
                else
                {
                    MessageBox.Show("修改成功");
                    this.Visible = false;
                }
            }
            else
            {
                int j = objTeaManage.JudgeTeaNo(objTea.TeaNo);
                int i = objTeaManage.JudgeTeaNoLikeStuNo(objTea.TeaNo);
                if (i == 1 && j == 1)
                {
                    int iRent = objTeaManage.ModifyTea(strTeaNo, objTea, out strErr);
                    if (iRent == 0)
                    {
                        MessageBox.Show(strErr);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("修改成功");
                        this.Visible = false;
                    }
                }
                else
                {
                    MessageBox.Show("已经存在一个编号相同的教师或者学生,修改失败");
                    txtTeaNo.Text = strTeaNo;
                }
            }
        }