void deleteClass() { if (dGClassInfo.SelectedRows.Count > 0) { try { int n = dGClassInfo.SelectedRows.Count; DialogResult result = MessageBox.Show("确认删除这" + Convert.ToString(n) + "项吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { for (int i = dGClassInfo.SelectedRows.Count - 1; i >= 0; i--) { String ClassID = dGClassInfo.SelectedRows[i].Cells["班级序号"].Value.ToString(); string sqlstr = "delete from Classes where Classes_ID=@0"; DataBaseHelper.ExecNoneQuery(sqlstr, ClassID); dGClassInfo.Rows.Remove(dGClassInfo.SelectedRows[i]); } } } catch { MessageBox.Show("该班还有学生信息,无法删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("请选择要删除的班级信息", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { if (tabControl1.SelectedIndex == 0) { string sql = "delete from ChangeTypes where ChangeTypes_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, (int)this.gridXueJi.SelectedRows[0].Cells[0].Value); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_girdXueJi(); } else if (tabControl1.SelectedIndex == 1) { string sql = "delete from PunishmentAwardTypes where PunishmentAwardTypes_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, (int)this.gridPunishmentAwards.SelectedRows[0].Cells[0].Value); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridPunishmentAwards(); } }
private void btnSpeYears_Click(object sender, EventArgs e) { if (btnSpeYears.Text == "点击添加") { txtSpecName.Enabled = true; txtSpecYear.Enabled = true; btnSpeYears.Text = "添加学制"; txtSpecName.Text = ""; txtSpecYear.Text = ""; } else { if (!CheckTextBoxValue(this.txtSpecName, "学制名称")) { return; } if (!CheckTextBoxValue(this.txtSpecYear, "学制时间")) { return; } string sql = "insert into SpeYears values(@0,@1)"; int i = DataBaseHelper.ExecNoneQuery(sql, this.txtSpecName.Text.Trim(), this.txtSpecYear.Text.Trim()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_gridSpeYears(); } }
private void btnOK_Click(object sender, EventArgs e) { try { if (!checkMessageinfo()) { return; } string sql = "update Students set Student_Name=@0, Student_Sex=@1,StudentClass=@2,StudentNum=@3,StudentOrigin=@4, StudentEnterYear=@5,StudentBirthDay=@6,StudentCard=@7, StudentAddress=@8,FamilyTel=@9,Mobile=@10,QQ=@11 where Student_ID=@12"; int r = DataBaseHelper.ExecNoneQuery(sql, txtBoxName.Text, rdoBtnMale.Checked ? "男" : "女", cmbBoxClass.SelectedValue.ToString(), txtBoxNum.Text, txtBoxNative.Text, dateTimePickerEnterDate.Value, dateTimePickerBirth.Value, txtBoxIDCardNum.Text, txtBoxHomeAdd.Text, txtBoxHomeTel.Text, txtBoxMobile.Text, txtBoxQQ.Text, StudentID); if (r > 0) { MessageBox.Show("修改成功!"); this.Close(); } else { MessageBox.Show("修改失败!"); } } catch { MessageBox.Show("修改数据遇到严重的错误!该学生的学号可能与其他学生重复,请更换学号后再试!"); //this.Close(); } }
private void btnInsertSubject_Click(object sender, EventArgs e) { if (btnInsertSubject.Text == "点击添加") { btnInsertSubject.Text = "添加学科"; txtSubjectName.Enabled = true; txtSubjectName.Text = ""; } else { if (!CheckTextBoxValue(this.txtSubjectName, "学科名称")) { return; } string sql = "insert into Subjects values(@0)"; int i = DataBaseHelper.ExecNoneQuery(sql, this.txtSubjectName.Text.Trim()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_gridSubjects(); } }
private void btnDeletePunishment_Click(object sender, EventArgs e) { if (dgvPunishments.SelectedRows.Count > 0) { try { string sql = "delete PunishmentAwardsRecode where PunishmentAwardsRecode_ID=@0"; int sucess = 0, error = 0, r; foreach (DataGridViewRow row in dgvPunishments.SelectedRows) { r = DataBaseHelper.ExecNoneQuery(sql, row.Cells["处分编号"].Value); if (r > 0) { sucess++; } else { error++; } } string msg = string.Format("总共需要删除{0}个对象,已经成功 删除{1}个对象,共有{2}个对象操作失败!", sucess + error, sucess, error); BinderPunishment(); MessageBox.Show(msg); } catch { MessageBox.Show("添加数据遇到严重错误,请检测你的相关数据是否正确!"); } } else { MessageBox.Show("请选择要删除的记录!"); } }
private void pBStudentImage_DoubleClick(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "*jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP"; if (ofd.ShowDialog() == DialogResult.OK) { string filePath = ofd.FileName;//图片路径 FileStream fs = new FileStream(filePath, FileMode.Open); images = new byte[fs.Length]; BinaryReader br = new BinaryReader(fs); images = br.ReadBytes(Convert.ToInt32(fs.Length));//图片转换成二进制流 string sql = "update StudentImage set Images=@0 where Image_Student=@1"; int r = DataBaseHelper.ExecNoneQuery(sql, images, StudentID); if (r > 0) { MessageBox.Show("更改照片成功!", "提示!"); MemoryStream ms = new MemoryStream(images); Bitmap bmp = new Bitmap(ms); pBStudentImage.Image = bmp; } else { MessageBox.Show("更改照片失败!", "错误!"); pBStudentImage.Image = null; } } else { MessageBox.Show("未选择任何照片", "提示!"); pBStudentImage.Image = null; images = null; } }
private void btnDeleteChange_Click(object sender, EventArgs e) { if (dgvChanges.SelectedRows.Count > 0) { try { string sql = "delete ChangeTypesRecode where ChangeTypesRecode_ID=@0"; int sucess = 0, error = 0, r; foreach (DataGridViewRow row in dgvChanges.SelectedRows) { r = DataBaseHelper.ExecNoneQuery(sql, row.Cells["异动编号"].Value); if (r > 0) { sucess++; } else { error++; } } string msg = string.Format("总共需要删除{0}个对象,已经成功 删除{1}个对象,共有{2}个对象操作失败!", sucess + error, sucess, error); BinderStudentinfo(StudentID); MessageBox.Show(msg); } catch { MessageBox.Show("删除数据遇到严重错误,请及时与技术人员取 得联系,以获得此错误的解决方法!"); } } else { MessageBox.Show("请先选择要删除的记录!"); } }
private void btnSetSubject_Click(object sender, EventArgs e) { string sql = "insert into Sepc_Subjects values(@0,@1)"; try { int i = DataBaseHelper.ExecNoneQuery(sql, Spec_ID, this.cbbSubject.SelectedValue.ToString()); if (i == 1) { MessageBox.Show("添加成功!"); if (cbbSubject.SelectedIndex < cbbSubject.Items.Count) { cbbSubject.SelectedIndex++; } } else { MessageBox.Show("添加失败!"); } Bind_gridSpecSubject(); } catch { MessageBox.Show("此学科已存在!"); } }
private void bunOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtNewPwd.Text.Trim())) { MessageBox.Show("新密码不能为空!"); return; } if (this.txtNewPwd.Text != this.txtRePwd.Text) { MessageBox.Show("两次密码输入不一致!"); return; } MainForm main = (MainForm)this.Owner; string sql = "update AdminInfo set Admin_Password=@0 where Admin_Password=@1 and Admin_ID=@2"; int i = DataBaseHelper.ExecNoneQuery(sql, this.txtNewPwd.Text, this.txtOldPwd.Text, main.adminID); if (i == 1) { MessageBox.Show("修改密码成功!"); } else { MessageBox.Show("密码输入错误"); } }
private void btnOk_Click(object sender, EventArgs e) { if (tabControl1.SelectedIndex == 0) { tabControl1.SelectedIndex = 1; } else if (tabControl1.SelectedIndex == 1) { tabControl1.SelectedIndex = 2; } else { try { if (!checkMessageinfo()) { return; } string sql = "insert into Students(Student_Name,Student_Sex,StudentClass,StudentNum,StudentOrigin,StudentEnterYear,StudentBirthDay,StudentCard,StudentAddress,FamilyTel,Mobile,QQ) values (@0,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11) "; int r = DataBaseHelper.ExecNoneQuery(sql, txtBoxName.Text, rdoBtnMale.Checked ? "男 " : "女", cmbBoxClass.SelectedValue.ToString(), txtBoxStuID.Text, txtBoxNative.Text, dtpEnterYear.Value, dateTimePickerBirth.Value, txtBoxIDCardNum.Text, txtBoxHomeAdd.Text, txtBoxHomeTel.Text, txtBoxMobile.Text, txtBoxQQ.Text); if (r > 0) { if (images != null) { MessageBox.Show("添加成功,即将插入图片"); string sql1 = "select Student_ID from Students where Student_Name=@0"; int studentID = (int)DataBaseHelper.ExecScalar(sql1, txtBoxName.Text); string sql2 = "update StudentImage set Images=@0 where Image_Student=@1"; int r2 = DataBaseHelper.ExecNoneQuery(sql2, images, studentID); if (r2 > 0) { MessageBox.Show("插入图片成功"); } else { MessageBox.Show("插入图片失败"); } } else { MessageBox.Show("添加成功!"); } this.Close(); } else { MessageBox.Show("添加失败!"); } } catch { MessageBox.Show("添加数据时出现重大错误!请确保你添加的数据合法!"); } } }
private void btnInsertSpec_Click(object sender, EventArgs e) { if (btnInsertSpec.Text == "点击添加") { control_Enabled(true); btnInsertSpec.Text = "添加专业"; btnUpdateSpec.Visible = false; this.cbbCollege.Text = ""; this.txtSpecialityID.Text = ""; this.txtSpecialityName.Text = ""; this.cbbSpecYears.Text = ""; } else { if (!CheckIDLenght(this.txtSpecialityID, 2)) { return; } if (!CheckTextBoxValue(this.txtSpecialityName, "专业名称")) { return; } if (!CheckCbbValue(this.cbbCollege, "没有学院信息,请到'学院设置'添加学院!")) { return; } if (!CheckCbbValue(this.cbbSpecYears, "没有学制信息,请到'学制设置'添加学制!")) { return; } string SpecialityID = this.cbbCollege.SelectedValue.ToString() + this.txtSpecialityID.Text.Trim(); try { string sql = "insert into Speciality values(@0,@1,@2,@3)"; int i = DataBaseHelper.ExecNoneQuery(sql, SpecialityID, this.txtSpecialityName.Text.Trim(), this.cbbCollege.SelectedValue.ToString(), this.cbbSpecYears.SelectedValue.ToString()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_gridSpeciality(); } catch { MessageBox.Show("ID为" + SpecialityID + "的编号已存在,请另选编号"); } } }
//添加 private void btnInsertTeacher_Click(object sender, EventArgs e) { if (btnInsertTeacher.Text == "点击添加") { btnUpdateTeacher.Visible = false; btnInsertTeacher.Text = "添加班主任"; this.txtTeaName.Enabled = true; this.txtTel.Enabled = true; this.cbbSex.Enabled = true; this.dtpInTime.Enabled = true; this.dtpBirthday.Enabled = true; this.txtOrgin.Enabled = true; this.txtTeaName.Text = ""; this.txtTel.Text = ""; this.cbbSex.Text = ""; this.dtpInTime.Value = DateTime.Now; this.dtpBirthday.Value = DateTime.Now; this.txtOrgin.Text = ""; } else { if (!CheckTextBoxValue(this.txtTeaName, "班主任名称")) { return; } if (!CheckTextBoxValue(this.txtTel, "电话")) { return; } if (!CheckTextBoxValue(this.txtOrgin, "籍贯")) { return; } string sql = "insert into Teachers values(@0,@1,@2,@3,@4,@5)"; string dtb = dtpBirthday.Value.ToString("yyyy-MM-dd"); string dti = dtpInTime.Value.ToString("yyyy-MM-dd"); //int i = DataBaseHelper.ExecNoneQuery(sql,this.txtTeaName.Text.Trim(), this.txtTel.Text, this.cbbSex.Text.Trim(),this.dtpInTime.Value, this.dtpBirthday.Value, this.txtOrgin.Text.Trim()); int i = DataBaseHelper.ExecNoneQuery(sql, this.txtTeaName.Text.Trim(), this.txtTel.Text, this.cbbSex.Text.Trim(), dti, dtb, this.txtOrgin.Text.Trim()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_gridTeachers(); } }
private void btnDelSubject_Click(object sender, EventArgs e) { string sql = "Delete from Sepc_Subjects where Subjects_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, this.gridSpecSubject.SelectedRows[0].Cells[0].Value.ToString()); if (i == 1) { MessageBox.Show(" 删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridSpecSubject(); }
private void btnUpdateSpec_Click(object sender, EventArgs e) { if (btnUpdateSpec.Text == "点击修改") { btnInsertSpec.Visible = false; btnUpdateSpec.Text = "修改专业"; control_Enabled(true); } else { if (!CheckIDLenght(this.txtSpecialityID, 2)) { return; } if (!CheckTextBoxValue(this.txtSpecialityName, "专业名称")) { return; } if (!CheckCbbValue(this.cbbCollege, "没有学院信息,请到'学院设置'添加学院!")) { return; } if (!CheckCbbValue(this.cbbSpecYears, "没有学制信息,请到'学制设置'添加学制!")) { return; } string SpecialityID = this.lbSpecCollegeID.Text + this.txtSpecialityID.Text.Trim(); try { string sql = "update Speciality set Speciality_ID=@0,Speciality_Name=@1,Speciality_College=@2,Speciality_Years=@3 where Speciality_ID=@4"; int i = DataBaseHelper.ExecNoneQuery(sql, SpecialityID, this.txtSpecialityName.Text.Trim(), this.cbbCollege.SelectedValue.ToString(), this.cbbSpecYears.SelectedValue.ToString(), this.gridSpeciatity.SelectedRows[0].Cells["专业编号"].Value); if (i == 1) { MessageBox.Show("修改成功!"); } else { MessageBox.Show("修改失败!"); } Bind_gridSpeciality(); } catch { MessageBox.Show("ID为" + SpecialityID + "的编号已存在,请另选编号"); } } }
private void btnOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtUserName.Text.Trim())) { MessageBox.Show("用户名不能为空!"); return; } if (string.IsNullOrEmpty(this.txtPwd.Text.Trim())) { MessageBox.Show("密码不能为空!"); return; } //判断此管理员名是否已存在 string sql = "select Admin_Name from AdminInfo where Admin_Name=@0"; SqlDataReader sdr = DataBaseHelper.ExecReader(sql, this.txtUserName.Text.Trim()); if (sdr.Read()) { MessageBox.Show("此用户名已存在!"); return; } sdr.Close(); //添加管理员 if (this.txtPwd.Text.Trim() != this.txtRePwd.Text.Trim()) { MessageBox.Show("两次密码输入不一致!"); return; } string sql1 = "insert into AdminInfo (Admin_Name,Admin_Password,Admin_Level, Admin_Rember , Admin_AutoLogin) values(@0,@1,@2,@3,@4)"; int i = DataBaseHelper.ExecNoneQuery(sql1, this.txtUserName.Text.Trim(), this.txtPwd.Text.Trim(), this.cbbLevel.SelectedIndex, checkBox1.Checked ? "1" : "0", checkBox2.Checked ? "1" : "0"); if (i == 1) { MessageBox.Show("添加用户成功!"); } else { MessageBox.Show("添加用户失败!"); } this.txtUserName.Text = ""; this.txtPwd.Text = ""; this.txtRePwd.Text = ""; this.cbbLevel.SelectedIndex = 0; }
private void btnOK_Click(object sender, EventArgs e) { if (this.cmbUserName.Text.Trim() == "") { MessageBox.Show("请先输入用户名!"); return; } else if (this.txtUserPwd.Text.Trim() == "") { MessageBox.Show("请先输入用户密码!"); return; } else { MainForm mf = (MainForm)this.Owner; string sql = "select Admin_ID, Admin_Level from AdminInfo where Admin_Name=@0 and Admin_Password=@1"; SqlDataReader sdr = DataBaseHelper.ExecReader(sql, this.cmbUserName.Text, this.txtUserPwd.Text); if (sdr.Read()) { string level = sdr["Admin_Level"].ToString(); //获取用户权限 mf.adminID = (int)sdr["Admin_id"]; //存储用户编号 sdr.Close(); if (level == "1") { this.DialogResult = DialogResult.Yes; } else { this.DialogResult = DialogResult.No; } string updatesql = "update AdminInfo set Admin_Rember=@0,Admin_AutoLogin=@1 where Admin_ID=@2 "; int r = DataBaseHelper.ExecNoneQuery(updatesql, checkBox1.Checked ? "1" : "0", checkBox2.Checked ? "1" : "0", cmbUserName.SelectedValue); islogin = true; this.Close(); } else { sdr.Close(); MessageBox.Show("用户名或密码有误!", "错误"); return; } } }
private void btnUpdate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtName.Text.Trim())) { MessageBox.Show("用户名不能为空!"); return; } if (string.IsNullOrEmpty(this.txtPassword.Text.Trim())) { MessageBox.Show("密码不能为空!"); return; } //判断此管理员名是否已存在 if (txtName.Enabled) { string sql = "select Admin_Name from AdminInfo where Admin_Name=@0"; SqlDataReader sdr = DataBaseHelper.ExecReader(sql, this.txtName.Text.Trim()); if (sdr.Read()) { MessageBox.Show("此用户名已存在!"); return; } sdr.Close(); } //保存更改 if (this.txtPassword.Text.Trim() != this.txtPassword2.Text.Trim()) { MessageBox.Show("两次密码输入不一致!"); return; } string sql1 = "update AdminInfo set Admin_Name=@0,Admin_Password=@1,Admin_Level=@2, Admin_Rember=@3 , Admin_AutoLogin=@4 where Admin_ID=@5"; int i = DataBaseHelper.ExecNoneQuery(sql1, this.txtName.Text.Trim(), this.txtPassword.Text.Trim(), this.cmbLevel.SelectedIndex, cBremeber.Checked ? "1" : "0", cBauto.Checked ? "1" : "0", adminID); if (i == 1) { MessageBox.Show("更新用户成功!"); } else { MessageBox.Show("更新用户失败!"); } }
private void btnUpdateClass_Click(object sender, EventArgs e) { if (btnUpdateClass.Text == "点击修改") { btnUpdateClass.Text = "修改班级"; btnInsertClass.Visible = false; this.cbbClassCollege.Enabled = true; this.cbbClassSpeciality.Enabled = true; this.txtClassID.Enabled = true; this.txtClassName.Enabled = true; this.cbbTeachers.Enabled = true; } else { if (!CheckIDLenght(this.txtClassID, 4)) { return; } if (!CheckTextBoxValue(this.txtClassName, "班级名称")) { return; } string ClassID = this.lbClassIDCollegeSpec.Text + this.txtClassID.Text.Trim(); try { string sql = "update Classes set Classes_ID=@0,Classes_Name=@1,Classes_Speciality=@2,ClassHeadTeacher=@3 where Classes_ID=@4"; int i = DataBaseHelper.ExecNoneQuery(sql, ClassID, this.txtClassName.Text.Trim(), lbClassIDCollegeSpec.Text, this.cbbTeachers.SelectedValue.ToString(), this.gridClasses.SelectedRows[0].Cells[0].Value.ToString()); if (i == 1) { MessageBox.Show("修改成功!"); } else { MessageBox.Show("修改失败!"); } Bind_gridClasses(); } catch { MessageBox.Show("ID为" + ClassID + "的编号已存在,请另选编号"); } } }
private void btnUpdateTeacher_Click(object sender, EventArgs e) { if (btnUpdateTeacher.Text == "点击修改") { btnInsertTeacher.Visible = false; btnUpdateTeacher.Text = "修改班主任"; this.txtTeaName.Enabled = true; this.txtTel.Enabled = true; this.cbbSex.Enabled = true; this.dtpInTime.Enabled = true; this.dtpBirthday.Enabled = true; this.txtOrgin.Enabled = true; } else { if (!CheckTextBoxValue(this.txtTeaName, "班主任名称")) { return; } if (!CheckTextBoxValue(this.txtTel, "电话")) { return; } if (!CheckTextBoxValue(this.txtOrgin, "籍贯")) { return; } string sql = "update Teachers set Teacher_Name=@0,Teacher_Tel=@1,Teacher_Sex=@2,Teacher_InDate=@3,Teacher_Birthday=@4,Teacher_Origin=@5 where Teacher_ID=@6"; string dtb = dtpBirthday.Value.ToString("yyyy-MM-dd"); string dti = dtpInTime.Value.ToString("yyyy-MM-dd"); int i = DataBaseHelper.ExecNoneQuery(sql, this.txtTeaName.Text.Trim(), this.txtTel.Text, this.cbbSex.Text, dti, dtb, this.txtOrgin.Text.Trim(), (int)this.gridTeachers.SelectedRows[0].Cells[0].Value); if (i == 1) { MessageBox.Show("修改成功!"); } else { MessageBox.Show("修改失败!"); } Bind_gridTeachers(); } }
private void btnInsertCollege_Click(object sender, EventArgs e) { if (btnInsertCollege.Text == "点击添加") { btnInsertCollege.Text = "添加学院"; btnUpdateCollege.Text = ""; btnUpdateCollege.Visible = false; txtCollegeID.Enabled = true; txtCollegeName.Enabled = true; txtCollegeID.Text = ""; txtCollegeName.Text = ""; } else { if (!CheckIDLenght(this.txtCollegeID, 2)) { return; } if (!CheckTextBoxValue(this.txtCollegeName, "学院名称")) { return; } try { string sql = "insert into Colleges values(@0,@1)"; int i = DataBaseHelper.ExecNoneQuery(sql, this.txtCollegeID.Text.Trim(), this.txtCollegeName.Text.Trim()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_gridCollege(); } catch { MessageBox.Show("ID为" + this.txtCollegeID.Text.Trim() + "的编号已存在,请另选编号"); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtXueJiName.Text.Trim())) { MessageBox.Show("请输入学籍变动类型名称!"); return; } string sql = "insert into ChangeTypes values(@0)"; int i = DataBaseHelper.ExecNoneQuery(sql, this.txtXueJiName.Text.Trim()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_girdXueJi(); }
private void btnUpdateCollege_Click(object sender, EventArgs e) { if (btnUpdateCollege.Text == "点击修改") { btnUpdateCollege.Text = "修改学院"; btnInsertCollege.Text = ""; btnInsertCollege.Visible = false; txtCollegeID.Enabled = true; txtCollegeName.Enabled = true; } else { if (!CheckIDLenght(this.txtCollegeID, 2)) { return; } if (!CheckTextBoxValue(this.txtCollegeName, "学院名称")) { return; } try { string sql = "update Colleges set College_ID=@0,College_Name=@1 where College_ID=@2"; int i = DataBaseHelper.ExecNoneQuery(sql, this.txtCollegeID.Text.Trim(), this.txtCollegeName.Text.Trim(), this.gridCollege.SelectedRows[0].Cells["学院编号"].Value); if (i == 1) { MessageBox.Show("修改成功!"); } else { MessageBox.Show("修改失败!"); } Bind_gridCollege(); } catch { MessageBox.Show("ID为" + this.txtCollegeID.Text.Trim() + "的编号已存在,请另选编号"); } } }
private void btnAddChange_Click(object sender, EventArgs e) { string sql = "insert into ChangeTypesRecode(ChangeTypes_ID, ChangeReason,ChangeStudentID,ChangeDate) values(@0,@1,@2,@3)"; try { int r = DataBaseHelper.ExecNoneQuery(sql, cmbChangeType.SelectedValue, txtChangeReason.Text, StudentID, dateTimeChange.Value); if (r > 0) { MessageBox.Show("添加成功!"); BinderStudentinfo(StudentID); } else { MessageBox.Show("添加失败!"); } } catch { MessageBox.Show("添加数据遇到严重错误!请检测你的相关数据是否合法!"); } }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { MainForm mf = (MainForm)this.Owner; if ((int)this.gridAdmin.SelectedRows[0].Cells["管理员编号"].Value == mf.adminID) { MessageBox.Show("您无权删除此管理员!"); return; } string sql = "delete from AdminInfo where Admin_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, (int)this.gridAdmin.CurrentRow.Cells[0].Value); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridAdmin(); }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { if (lvStudentsinfo.SelectedItems.Count > 0) { int dm = lvStudentsinfo.SelectedItems.Count; if (MessageBox.Show("确定删除这" + dm + "个学生的信息?", "警告!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { string sql = "delete Students where Student_ID=@0"; int sucess = 0, error = 0, r = 0; foreach (ListViewItem item in lvStudentsinfo.SelectedItems) { r = DataBaseHelper.ExecNoneQuery(sql, item.Name); if (r > 0) { sucess++; } else { error++; } } string msg = string.Format("总共需要删除{0}个学生信息 \n成功删除{1}个学生信息 \n共有{2}个学生信息删除失败!", sucess + error, sucess, error); MessageBox.Show(msg); 刷新ToolStripMenuItem_Click(sender, e); } catch { MessageBox.Show("删除数据遇到严重错误!", "警告!"); } } } else { MessageBox.Show("请选择要删除的学生!"); } }
private void btnAddPunishment_Click(object sender, EventArgs e) { try { string sql = "select min(PunishmentAwardsRecode_ID) from PunishmentAwardsRecode"; object obj = DataBaseHelper.ExecScalar(sql); int id = -1; if (!string.IsNullOrEmpty(obj.ToString())) { id = (int)obj; } if (id > -1) { id = -1; } else { id--; } sql = "insert into PunishmentAwardsRecode(PunishmentAwardsRecode_ID, PunishmentAwardsType_ID,PunishmentAwardStudentID, PunishmentAwardContent,PunishmentAwardReason,PunishmentAwardDate) values(@0,@1,@2,@3,@4,@5)"; int r = DataBaseHelper.ExecNoneQuery(sql, id, cmbPunishmentType.SelectedValue.ToString(), StudentID, txtBoxPunishmentAwardContent.Text, txtPunishmentReason.Text, dateTimePunishment.Value); if (r > 0) { MessageBox.Show("添加成功!"); BinderPunishment(); } else { MessageBox.Show("添加失败!"); } } catch { MessageBox.Show("添加数据遇到严重错误,请检测你的相关数据是否正确!"); } }
private void btnInsertClass_Click(object sender, EventArgs e) { if (btnInsertClass.Text == "点击添加") { if (this.cbbClassCollege.Items.Count != 0) { this.cbbClassCollege.SelectedIndex = 0; } else { MessageBox.Show("警告!数据库中还没有学院的记录,请到’学院设置’添加学院"); } if (this.cbbClassSpeciality.Items.Count != 0) { this.cbbClassSpeciality.SelectedIndex = 0; } else { MessageBox.Show("警告!数据库中" + this.cbbClassCollege.Text + "还没有添加专业的记录,请到专业设置添加"); } if (this.cbbTeachers.Items.Count != 0) { this.cbbTeachers.SelectedIndex = 0; } else { MessageBox.Show("警告!数据库中还没有班主任的记录,请到学院设置添加班主任"); } btnInsertClass.Text = "添加班级"; btnUpdateClass.Visible = false; this.cbbClassCollege.Enabled = true; this.cbbClassSpeciality.Enabled = true; this.txtClassID.Enabled = true; this.txtClassName.Enabled = true; this.cbbTeachers.Enabled = true; this.cbbClassCollege.SelectedIndex = 0; this.cbbClassSpeciality.SelectedIndex = 0; this.txtClassID.Text = ""; this.txtClassName.Text = ""; this.cbbTeachers.SelectedIndex = 0; } else { if (!CheckIDLenght(this.txtClassID, 4)) { return; } if (!CheckTextBoxValue(this.txtClassName, "班级名称")) { return; } if (!CheckCbbValue(this.cbbClassCollege, "没有学院信息,请到'学院设置'添加学院!")) { return; } if (!CheckCbbValue(this.cbbClassSpeciality, "没有专业信息,请到'专业设置'添加专业!")) { return; } if (!CheckCbbValue(this.cbbTeachers, "没有班主任信息,请到'班主任设置'添加班主任!")) { return; } string ClassID = lbClassIDCollegeSpec.Text + this.txtClassID.Text.Trim(); try { string sql = "insert into Classes(Classes_ID,Classes_Name,Classes_Speciality,ClassHeadTeacher) values(@0,@1,@2,@3)"; int i = DataBaseHelper.ExecNoneQuery(sql, ClassID, this.txtClassName.Text.Trim(), lbClassIDCollegeSpec.Text, this.cbbTeachers.SelectedValue.ToString()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_gridClasses(); } catch { MessageBox.Show("ID为" + ClassID + "的编号已存在,请另选编号"); } } }
private void btnOK_Click(object sender, EventArgs e) { if (FormText == null) { if (cbCollege.Text.ToString() == "") { MessageBox.Show("学院信息不允许空!请添加学院信息", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cbSpeciality.Text.ToString() == "") { MessageBox.Show("专业信息不允许空!请添加专业信息", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtClassID.Text.Trim() == "") { MessageBox.Show("班级编号不允许空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtClassName.Text.Trim() == "") { MessageBox.Show("班级名称不允许空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cbHeadMaster.Text.ToString() == "") { MessageBox.Show("班主任信息不允许空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtClassID.Text.Trim().Length != 4) { MessageBox.Show("班级编号需写四位!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { string cid = lblPre.Text.Trim() + txtClassID.Text.Trim(); //班级编号 string cname = txtClassName.Text.Trim(); //班级名称 string c_s = cbSpeciality.SelectedValue.ToString(); //专业编号 string c_t = cbHeadMaster.SelectedValue.ToString(); //班主任编号 string sqlstr = "insert into Classes(Classes_ID,Classes_Name,Classes_Speciality,ClassHeadTeacher,Classes_PS) values(@0,@1,@2,@3,@4)"; int i = DataBaseHelper.ExecNoneQuery(sqlstr, cid, cname, c_s, c_t, txtPS.Text); if (i > 0) { MessageBox.Show("添加班级成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.None); txtClassID.Text = ""; txtClassName.Text = ""; } else { MessageBox.Show("添加班级失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("已经存在该班级编号,请重新填写!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.None); } } if (FormText == "修改班级信息") { string sqlstr = "update Classes set Classes_Name=@0,ClassHeadTeacher=@1,Classes_PS=@2 where Classes_ID=@3"; string cname = txtClassName.Text.Trim(); string tid = cbHeadMaster.SelectedValue.ToString(); string ps = txtPS.Text; string cid = lblPre.Text.Trim() + txtClassID.Text.Trim(); int i = DataBaseHelper.ExecNoneQuery(sqlstr, cname, tid, ps, cid); if (i > 0) { MessageBox.Show("修改班级信息成功!", "信息提示"); } else { MessageBox.Show("修改班级信息失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); } }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { //删除学院 if (tabControl1.SelectedIndex == 0) { try { string sql = "delete from Colleges where College_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, this.gridCollege.SelectedRows[0].Cells["学院编号"].Value.ToString()); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridCollege(); } catch { MessageBox.Show("该学院中有学生,删除失败"); } } else if (tabControl1.SelectedIndex == 1) { try { string sql = "Delete from Speciality where Speciality_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, this.gridSpeciatity.SelectedRows[0].Cells[0].Value); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridSpeciality(); } catch { MessageBox.Show("该专业中有学生,删除失败"); } } else if (tabControl1.SelectedIndex == 2) { try { string sql = "delete from SpeYears where SpeYears_id=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, this.gridSpeYears.SelectedRows[0].Cells[0].Value.ToString()); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridSpeYears(); } catch { MessageBox.Show("该学制中有学科,删除失败"); } } else if (tabControl1.SelectedIndex == 3) { try { string sql = "Delete from Subjects where Subjects_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, this.gridSubjects.SelectedRows[0].Cells[0].Value.ToString()); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridSubjects(); } catch { MessageBox.Show("该学科中有学生,删除失败"); } } else if (tabControl1.SelectedIndex == 4) { try { string sql = "Delete from Teachers where Teacher_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, this.gridTeachers.SelectedRows[0].Cells[0].Value.ToString()); if (i == 1) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } Bind_gridTeachers(); } catch { MessageBox.Show("该班主任带有班级,删除失败"); } } else if (tabControl1.SelectedIndex == 5) { try { string sql = "Delete from Classes where Classes_ID=@0"; int i = DataBaseHelper.ExecNoneQuery(sql, this.gridClasses.SelectedRows[0].Cells[0].Value.ToString()); if (i == 1) { MessageBox.Show("修改成功!"); } else { MessageBox.Show("修改失败!"); } Bind_gridClasses(); } catch { MessageBox.Show("该班级下有学生,删除失败"); } } }