private void cbStuName_SelectedIndexChanged(object sender, EventArgs e) { //当选择学生后显示该学生的学号 if (locked) { return; } if (cbStuName.SelectedValue != null) { string sqlnum = "select StudentNum from Students where Student_ID=@0"; string Student_ID = cbStuName.SelectedValue.ToString(); lblStuID.Text = cbStuName.SelectedValue.ToString(); lblStuNum.Text = DataBaseHelper.ExecScalar(sqlnum, Student_ID).ToString(); //string sqlstr = "select Student_ID,Student_Name,StudentNum from Students where StudentClass=@0"; //DataTable students = DataBaseHelper.ExecDataTable(sqlstr, classid); } else { lblStuID.Text = "0"; } //如果该学生已经录入成绩则显示成绩,并不能填写成绩 string sqlstr = "select * from Examination where StudentID=@0"; DataTable dt = DataBaseHelper.ExecDataTable(sqlstr, lblStuID.Text); int i = 0; for (int j = 0; j < dt.Rows.Count; j++) { Subjects sub = (Subjects)(gbSubjects.Controls[j]); sub.txtScore.Text = dt.Rows[j]["ExamScore"].ToString(); sub.txtScore.Enabled = false; i++; } if (gbSubjects.Controls.Count > 0) { if (i == 0) //说明该学生没有成绩记录,应该提交成绩 { foreach (Control c in gbSubjects.Controls) { Subjects sub = (Subjects)c; sub.txtScore.Enabled = true; sub.txtScore.Text = ""; } button1.Enabled = true; button2.Enabled = false; } else//说明该学生有成绩记录,应该可以修改成绩 { button1.Enabled = false; button2.Enabled = true; } } else { button1.Enabled = false; button2.Enabled = false; } }
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 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 BinderSpeYears(string SpecialityID) { string yearssql = "select sy.SpeYears_Name from SpeYears as sy join Speciality as sp on sp.Speciality_Years=sy.SpeYears_ID where sp.Speciality_ID=@0 "; LableBoxStuType.Text = DataBaseHelper.ExecScalar(yearssql, SpecialityID).ToString(); }
//学制 private void BinderSpeYears(string SpecialityID) { string yearssql = "select SpeYears_Name from SpeYears join Speciality on Speciality.Speciality_Years=SpeYears.SpeYears_ID where Speciality.Speciality_ID=@0 "; labStuType.Text = DataBaseHelper.ExecScalar(yearssql, SpecialityID).ToString(); }
private void btnAddPA_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtPunishmentAwards.Text.Trim())) { MessageBox.Show("请输入奖惩类型名称!"); return; } int id = 0; if (cbbPunishmentAwards.Text == "奖励") { string sql = "select max(PunishmentAwardTypes_ID) from PunishmentAwardTypes "; object obj = DataBaseHelper.ExecScalar(sql); if (!string.IsNullOrEmpty(obj.ToString())) { id = int.Parse(obj.ToString()); if (id < 1) { id = 1; } else { id++; } } else { id = 1; } } else { string sql = "select min(PunishmentAwardTypes_ID) from PunishmentAwardTypes"; object obj = DataBaseHelper.ExecScalar(sql); if (!string.IsNullOrEmpty(obj.ToString())) { id = (int)obj; if (id > 0) { id = -1; } else { id--; } } else { id = -1; } } string sql1 = "insert into PunishmentAwardTypes values(@0,@1)"; int i = DataBaseHelper.ExecNoneQuery(sql1, id, this.txtPunishmentAwards.Text.Trim()); if (i == 1) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } Bind_gridPunishmentAwards(); }