private void btnDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 0) { MessageBox.Show("请先选中一行"); } else { if (DialogResult.Yes == MessageBox.Show("确定要删除吗?同时将删除此学生的系统账号及成绩信息\n ", "确认删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Student.Student objStudent = new Manage.Student.Student(strConnection); string strErr = ""; for (int i = 0; i < dataGridView.SelectedRows.Count; i++) { //int iStuId = int.Parse(dataGridView.SelectedRows[i].Cells["学生ID"].Value.ToString()); string strStuNo = dataGridView.SelectedRows[i].Cells["学生编号"].Value.ToString(); int iRent = objStudent.DelStu(strStuNo, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } } BindDataGridView(); } } }
private void btnSearch_Click(object sender, EventArgs e) { string strStuNo = txtStuNo.Text.Replace("'", "''"); strStuNo = strStuNo.Replace(@"\", @"\\"); strStuNo = strStuNo.Replace("%", @"\%"); strStuNo = strStuNo.Replace("_", @"\_"); strStuNo = strStuNo.Trim(); string strStuName = txtStuName.Text.Replace("'", "''"); strStuName = strStuName.Replace(@"\", @"\\"); strStuName = strStuName.Replace("%", @"\%"); strStuName = strStuName.Replace("_", @"\_"); strStuName = strStuName.Trim(); string strClassName = txtClassName.Text.Replace("'", "''"); strClassName = strClassName.Replace(@"\", @"\\"); strClassName = strClassName.Replace("%", @"\%"); strClassName = strClassName.Replace("_", @"\_"); strClassName = strClassName.Trim(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Student.Student objStudent = new Manage.Student.Student(strConnection); string strErr = ""; if (strStuNo == "" && strStuName == "" && strClassName == "") { BindDataGridView(); } else { DataTable objDataTable = new DataTable(); int iRent = objStudent.SearchStuBy(iRight, strUserNo, strStuNo, strStuName, strClassName, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); } else { if (objDataTable.Rows.Count == 0) { MessageBox.Show("没有您要查询的记录"); dataGridView.DataSource = objDataTable; } else { dataGridView.DataSource = objDataTable; } } txtStuNo.Text = ""; txtStuName.Text = ""; txtClassName.Text = ""; } }
void BindDataGridView() { string strErr = ""; string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Student.Student objStudent = new Manage.Student.Student(strConnection); DataTable objDataTable = new DataTable(); int iRent = objStudent.SearchStuAll(iRight, strUserNo, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { dataGridView.DataSource = objDataTable; } }
void BindStuId() { string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Student.Student objStu = new Manage.Student.Student(strConnection); string strErr = ""; DataTable objDataTable = new DataTable(); int iRent = objStu.SearchStudent3(out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { cmbStuNo.DataSource = objDataTable; cmbStuNo.DisplayMember = "StuNo"; cmbStuNo.ValueMember = "StuId"; } }
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; } } } } }
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; } } } }