//添加按钮 private void button1_Click(object sender, EventArgs e) { if (TB_course_ID.Text.Trim() == "" || TB_course_NAME.Text.Trim() == "") { MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { try { string count = "select count(*) from SC_result where cour_id='" + TB_course_ID.Text + "'"; if (operate.HumanNum(count) == 0) { MessageBox.Show("此课程为此学期的一个新课程"); string strAdd = "insert into Coures values ('" + TB_course_ID.Text + "','" + TB_course_NAME.Text + "','" + CBB_semester.Text + "')"; operate.OperateData(strAdd); } string sqlstr = "INSERT into [dbo].[SC_result] ([Stu_Id],[Cour_Id],[Cour_Name]) select distinct A.Stu_Id,'" + TB_course_ID.Text + "','" + TB_course_NAME.Text + "' from Student as A join SC_result AS B on A.Stu_Id=B.stu_id join Coures AS C on B.Cour_Id=C.Cour_Id where C.Cour_Semester='" + CBB_semester.Text.ToString() + "' and A.stu_class='" + CBB_class.Text.ToString() + "'"; int i = operate.OperateData(sqlstr);//更新数据库内容 if (i > 0) { MessageBox.Show("添加用户信息成功", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); button2_Click(sender, e); return;//关闭事件 } } catch { MessageBox.Show("此班本学期已使用此课程号", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
//删除按钮 private void button3_Click(object sender, EventArgs e) { try { if (this.dataGridView1.SelectedCells.Count == 0) { MessageBox.Show("请选择要删除的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { string stuclass = dataGridView1.SelectedCells[0].Value.ToString(); //得到班级信息 string CourID = dataGridView1.SelectedCells[1].Value.ToString(); //得到课程信息 //string count = "select count(*) from SC_result join student on student.stu_id=SC_result.stu_id join Coures on Coures.cour_id=SC_result.cour_id where SC_result.Cour_Id='" + CourID + "' and student.stu_class='" + cbbClass.SelectedItem.ToString() + "' and Coures.Cour_Semester='" + cbbSemester.SelectedItem.ToString() + "'"; string count = "select count(*) from SC_result where cour_id='" + CourID + "'"; string Delsql = "delete from SC_result where Cour_Id='" + CourID + "' and Stu_Id in (select stu_id from Student where stu_class='" + stuclass + "')"; operate.OperateData(Delsql);//删除成绩信息 if (operate.HumanNum(count) == 0) { string delCID = "delete from Coures where Cour_Id='" + CourID + "'"; operate.OperateData(delCID);//删除课程信息 } MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//关闭按钮事件 private void btn_close_Click(object sender, EventArgs e) { string str = "select count(Score) from SC_result where Score='暂无成绩' and stu_id='" + XTID + "'"; int b = operate.HumanNum(str); MessageBox.Show(b.ToString()); if (b != 0) { MessageBox.Show("你还有信息未填写!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("填写完毕!"); this.Close(); } }
//保存按钮(学生)--差导入成绩 private void btn_keep_stu_Click(object sender, EventArgs e) { if (TB_stu_ID.Text.Trim() == "" || TB_stu_name.Text.Trim() == "" || TB_stu_enter.Text.Trim() == "") { MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { string str = "select count(*) from student where stu_ID='" + TB_stu_ID.Text.Trim() + "'"; int i = operate.HumanNum(str); try { string strsql = "INSERT INTO [dbo].[student] ([stu_id],[stu_class],[stu_name],[stu_sex],[stu_birthday],[stu_MCCP],[stu_Enterscore],[stu_nativeplace]) VALUES ('" + TB_stu_ID.Text.ToString() + "','" + CBB_stu_class.Text.ToString() + "','" + TB_stu_name.Text.ToString() + "','" + CBB_stu_sex.Text.ToString() + "','" + Time_stu_birth.Value.ToString("yyyy年MM月d日") + "','" + CBB_stu_MCCP.Text.ToString() + "','" + TB_stu_enter.Text.ToString() + "','" + CBB_stu_nation.Text.ToString() + "')"; int num = operate.OperateData(strsql); operate.StuSaveImages(TB_stu_ID.Text.Trim(), openFileDialog1); string time = DateTime.Now.ToString(); //获取当前系统事件字符串 string sql = "insert into wang_User values('" + TB_stu_ID.Text.ToString() + "','" + password + "','" + "学生" + "','" + time + "')"; operate.OperateData(sql); //更新数据库内容 if (num > 0) { //添加控的成绩信息 string sqlstr = "INSERT into [dbo].[SC_result] ([Stu_Id],[Cour_Id],[Cour_Name]) select distinct '" + TB_stu_ID.Text.ToString() + "',Coures.Cour_Id,Coures.Cour_Name from Student join SC_result on SC_result.Stu_Id=Student.stu_id join Coures on Coures.Cour_Id=Coures.Cour_Id where Student.stu_class='" + CBB_stu_class.Text.ToString() + "'"; operate.OperateData(sqlstr); //更新数据库内容 FormCheckuser_Z_score ee = new FormCheckuser_Z_score(); ee.XTID = TB_stu_ID.Text.ToString(); //传值给成绩录入表 ee.ShowDialog(); //打开成绩录入对话框 } } catch { MessageBox.Show("填写信息有误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }