private void btnSave_Click(object sender, EventArgs e) { string strErr = ""; string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Model.Class.Class objClass = new Model.Class.Class(); Manage.Class.Class objclass = new Manage.Class.Class(strConnection); objClass.ClassNo = txtClassNo.Text.Replace("'", "''"); objClass.ClassNo = objClass.ClassNo.Trim(); objClass.ClassName = txtClassName.Text.Replace("'", "''"); objClass.ClassName = objClass.ClassName.Trim(); objClass.Remark = txtRemark.Text.Replace("'", "''"); objClass.Remark = objClass.Remark.Trim(); if (objClass.ClassName == "" || objClass.ClassNo == "") { MessageBox.Show("请将信息填写完整!"); } else { int i = objclass.JudgeClassNo(objClass); int j = objclass.JudgeClassName(objClass); if (i == 0 && j == 0) { int iRent = objclass.AddClass(objClass, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("添加成功"); this.Visible = false; } } else if (i == 1 && j == 0) { MessageBox.Show("当前班级已经存在,新建失败"); } else if (i == 0 && j == 1) { MessageBox.Show("当前班级名称已经存在,新建失败"); } else { MessageBox.Show("班级编号和班级名称都已经存在,新建失败"); } } }
private void btnSave_Click(object sender, EventArgs e) //保存修改后的班级。如果修改后的班级编号和名称有相同的,修改失败 { string strErr = ""; string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Model.Class.Class objClass = new Model.Class.Class(); Manage.Class.Class objClassMan = new Manage.Class.Class(strConnection); objClass.ClassNo = txtClassNo.Text.Replace("'", "''"); objClass.ClassNo = objClass.ClassNo.Trim(); objClass.ClassName = txtClassName.Text.Replace("'", "''"); objClass.ClassName = objClass.ClassName.Trim(); objClass.Remark = txtRemark.Text.Replace("'", "''"); objClass.Remark = objClass.Remark.Trim(); string strClassNo = classNo.Replace("'", "''"); strClassNo = strClassNo.Trim(); string strClassName = className.Replace("'", "''"); strClassName = strClassName.Trim(); if (objClass.ClassName == "" || objClass.ClassNo == "") { MessageBox.Show("请将信息填写完整!"); } else { int i = objClassMan.JudgeClassNo(objClass); int j = objClassMan.JudgeClassName(objClass); if (strClassNo == objClass.ClassNo && strClassName == objClass.ClassName) { int iRent = objClassMan.ModifyClass(classNo, objClass, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { this.Visible = false; } } else if (strClassNo != objClass.ClassNo && strClassName == objClass.ClassName) { if (i == 0) { int iRent = objClassMan.ModifyClass(classNo, objClass, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { this.Visible = false; } } else { MessageBox.Show("当前班级编号已经存在,修改失败"); txtClassNo.Text = classNo; } } else if (strClassNo == objClass.ClassNo && strClassName != objClass.ClassName) { if (j == 0) { int iRent = objClassMan.ModifyClass(classNo, objClass, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { this.Visible = false; } } else { MessageBox.Show("当前班级名称已经存在,修改失败"); txtClassName.Text = className; } } else { if (i == 0 && j == 0) { int iRent = objClassMan.ModifyClass(classNo, objClass, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { this.Visible = false; } } else { MessageBox.Show("当前班级编号和名称都已经存在,修改失败"); txtClassNo.Text = classNo; } } } }