//对应于批改作业/检查作业按钮的点击事件 private void btnHomeworkCorrect1_Click(object sender, RoutedEventArgs e)//检查作业按钮 { Button sonBtn = (Button)sender; Canvas stuCanvas = (Canvas)sonBtn.Parent; StudentCheck stuControl = (StudentCheck)stuCanvas.Parent; //获得学生姓名 string studentName = stuControl.lbStudentInfo2.Content.ToString(); //获得学生学号 string studentId = stuControl.lbStudentInfo1.Content.ToString(); //还需要写根据学号得作业提交描述 string postil = ts.getPostilByForm(tbClassInfo.Text, lbNotTitle.Content.ToString(), studentId); //MessageBox.Show(postil); int index = stuControl.index; string notTitle = lbNotTitle.Content.ToString(); string studentInfo = stuControl.lbStudentInfo1.Content.ToString() + " " + stuControl.lbStudentInfo2.Content.ToString(); bool ifCorrect; //表示是否进行了作业批改 if (stuControl.btnHomeworkCorrect1.Content.ToString() == "检查作业") //说明作业已被批改,需要查询出之前的批改记录 { ifCorrect = true; //需要传入的是已批改的homIds列表 TeacherHomeworkCheck newTeacherHomeworkCheck = new TeacherHomeworkCheck(homIdCorrecteds, index, notTitle, studentInfo, this.pngfile, ifCorrect); newTeacherHomeworkCheck.pngfile = this.pngfile; newTeacherHomeworkCheck.className = tbClassInfo1.Text; newTeacherHomeworkCheck.classSpecId = tbClassInfo.Text; newTeacherHomeworkCheck.description = textBlockDescription.Text; //有问题 newTeacherHomeworkCheck.tbTeacherSpecId.Text = tbTeacherInfo.Text; newTeacherHomeworkCheck.tbTeacherName.Text = tbTeacherInfo1.Text; //加载教师工号和姓名 newTeacherHomeworkCheck.Show(); } else { ifCorrect = false; //需要传入的是待批改的homIds列表 TeacherHomeworkCheck newTeacherHomeworkCheck = new TeacherHomeworkCheck(homIdNeedCorrects, index, notTitle, studentInfo, this.pngfile, ifCorrect); newTeacherHomeworkCheck.pngfile = this.pngfile; newTeacherHomeworkCheck.className = tbClassInfo1.Text; newTeacherHomeworkCheck.classSpecId = tbClassInfo.Text; newTeacherHomeworkCheck.description = textBlockDescription.Text; //有问题 newTeacherHomeworkCheck.tbTeacherSpecId.Text = tbTeacherInfo.Text; newTeacherHomeworkCheck.tbTeacherName.Text = tbTeacherInfo1.Text; //加载教师工号和姓名 newTeacherHomeworkCheck.Show(); } this.Visibility = System.Windows.Visibility.Hidden; }
//查询按钮的点击事件,实现查询功能 private void btnSearch_Click(object sender, RoutedEventArgs e) { //非空判断 if (tbStuNameSearch.Text == "" || tbStuNameSearch.Text == "请输入学生的完整姓名。")//此时不需要清空listview里的东西 { MessageBox.Show("请输入查询条件"); } else { //首先删除listview里面的东西 listViewChecked.Items.Clear(); listViewUnCheck.Items.Clear(); listViewUnFinish.Items.Clear(); string stuName = tbStuNameSearch.Text; int i1, i2, i3; //统计一下查询到结果的已批改、待批改、未完成人数(考虑到重名情况) int CorrectedNum = 0; int UnCorrectNum = 0; int UnFinishNum = 0; for (i1 = 0; i1 < stuNameCorrecteds.Length; i1++) //首先在已批改作业学生姓名中找 { if (stuNameCorrecteds[i1] == stuName) { StudentCheck sc = new StudentCheck(i1);//i恰好为在homIdCorrecteds中的下标(关于Correcteds的三个数组下标是对应的) sc.lbStudentInfo1.Content = stuSpecIdCorrecteds[i1]; sc.lbStudentInfo2.Content = stuNameCorrecteds[i1]; sc.lbHomeworkState1.Content = "已批改"; sc.btnHomeworkCorrect1.Content = "检查作业";//修改button名称 //查到当前学生的性别 DataTable tbSex = td.getSexByStuSpecId(stuSpecIdCorrecteds[i1]); if (Convert.ToInt32(tbSex.Rows[0][0]) == 1) { sc.pngfile = @"..\..\Resources\男生头像.png"; } else { sc.pngfile = @"..\..\Resources\女生头像.png"; } //设置该img控件的Source sc.headImage.Source = new BitmapImage(new Uri(System.IO.Path.GetFullPath(System.IO.Path.Combine(System.Environment.CurrentDirectory, @sc.pngfile)))); listViewChecked.Items.Add(sc); sc.btnHomeworkCorrect1.Click += new RoutedEventHandler(btnHomeworkCorrect1_Click); CorrectedNum++; } } if (CorrectedNum > 0)//查找到了已批改的人 { TbItemChecked.IsSelected = true; } TbItemChecked.Header = " 已批改 " + CorrectedNum; for (i2 = 0; i2 < stuNameNeedCorrects.Length; i2++)//然后在待批改作业学生姓名中找 { if (stuNameNeedCorrects[i2] == stuName) { StudentCheck sc = new StudentCheck(i2);//i恰好为在homIdCorrecteds中的下标(关于Correcteds的三个数组下标是对应的) sc.lbStudentInfo1.Content = stuSpecIdNeedCorrects[i2]; sc.lbStudentInfo2.Content = stuNameNeedCorrects[i2]; sc.lbHomeworkState1.Content = "待批改"; sc.btnHomeworkCorrect1.Content = "批改作业";//修改button名称 //查到当前学生的性别 DataTable tbSex = td.getSexByStuSpecId(stuSpecIdNeedCorrects[i2]); if (Convert.ToInt32(tbSex.Rows[0][0]) == 1) { sc.pngfile = @"..\..\Resources\男生头像.png"; } else { sc.pngfile = @"..\..\Resources\女生头像.png"; } //设置该img控件的Source sc.headImage.Source = new BitmapImage(new Uri(System.IO.Path.GetFullPath(System.IO.Path.Combine(System.Environment.CurrentDirectory, @sc.pngfile)))); listViewUnCheck.Items.Add(sc); sc.btnHomeworkCorrect1.Click += new RoutedEventHandler(btnHomeworkCorrect1_Click); UnCorrectNum++; } } if (UnCorrectNum > 0) //查找到了待批改的人 { if (TbItemChecked.IsSelected != true) //如果没有在已批改作业中找到该学生,才设置待批改属性值为true { TbItemUnCheck.IsSelected = true; } } TbItemUnCheck.Header = " 待批改 " + UnCorrectNum; for (i3 = 0; i3 < stuNameUnfinisheds.Length; i3++)//最后在未完成作业学生姓名中找 { if (stuNameUnfinisheds[i3] == stuName) { StudentCheck sc = new StudentCheck(i3);//i恰好为在homIdCorrecteds中的下标(关于Correcteds的三个数组下标是对应的) sc.lbStudentInfo1.Content = stuSpecIdUnfinisheds[i3]; sc.lbStudentInfo2.Content = stuNameUnfinisheds[i3]; sc.lbHomeworkState1.Content = ""; sc.btnHomeworkCorrect1.Content = "";//修改button名称 sc.btnHomeworkCorrect1.Visibility = Visibility.Hidden; //查到当前学生的性别 DataTable tbSex = td.getSexByStuSpecId(stuSpecIdUnfinisheds[i3]); if (int.Parse(tbSex.Rows[0][0].ToString()) == 1) { sc.pngfile = @"..\..\Resources\男生头像.png"; } else { sc.pngfile = @"..\..\Resources\女生头像.png"; } //设置该img控件的Source sc.headImage.Source = new BitmapImage(new Uri(System.IO.Path.GetFullPath(System.IO.Path.Combine(System.Environment.CurrentDirectory, @sc.pngfile)))); listViewUnFinish.Items.Add(sc); sc.btnHomeworkCorrect1.Click += new RoutedEventHandler(btnHomeworkCorrect1_Click); UnFinishNum++; } } if (UnFinishNum > 0) //查找到了未完成的人 { if (TbItemChecked.IsSelected != true || TbItemUnCheck.IsSelected != true) //如果没有在已批改作业或者待批改中找到该学生,才设置未完成属性值为true { TbItemUnFinish.IsSelected = true; } } TbItemUnFinish.Header = " 未完成 " + UnFinishNum; if (CorrectedNum == 0 && UnCorrectNum == 0 && UnFinishNum == 0)//说明没有在所有学生中找到 { MessageBox.Show("您所查找的学生不存在!"); } } }
//加载未完成学生信息 public void loadUnfinished(string classSpecId, string homeworkTitle) { DataTable table1 = td.getClassId(classSpecId); int classId = Convert.ToInt32(table1.Rows[0][0]); DataTable table2 = td.getNotIdByClassIdAndNotTitle(homeworkTitle, classId); //获得noteId this.notId = table2.Rows[0][0].ToString(); DataTable table3 = td.selectHomeworkUnfinishedInfo(notId); //MessageBox.Show(table3.Rows.Count.ToString()); int checkedNum = table3.Rows.Count; //加载已批改的动态控件 TbItemUnFinish.Header = " 未完成 " + checkedNum; int stuListLength = table3.Rows.Count; StudentCheck[] checkedStudent = new StudentCheck[stuListLength]; //定义存储学生列表对应homId的int数组 homIdUnfinisheds = new int[stuListLength]; //定义存储学生列表对应stuId的int数组 stuSpecIdUnfinisheds = new String[stuListLength]; //定义存储学生列表对应stuName的int数组 stuNameUnfinisheds = new String[stuListLength]; for (int i = 0; i < stuListLength; i++) { checkedStudent[i] = new StudentCheck(i); string stuId = table3.Rows[i][0].ToString(); DataTable table4 = td.getStudentNameAndIdByStuID(stuId); checkedStudent[i].lbStudentInfo1.Content = table4.Rows[0][0].ToString(); stuSpecIdUnfinisheds[i] = table4.Rows[0][0].ToString(); checkedStudent[i].lbStudentInfo2.Content = table4.Rows[0][1].ToString(); stuNameUnfinisheds[i] = table4.Rows[0][1].ToString(); //查到当前学生的性别 DataTable table10 = td.getSexByStuSpecId(table4.Rows[0][0].ToString()); if (Convert.ToInt32(table10.Rows[0][0]) == 1) { checkedStudent[i].pngfile = @"..\..\Resources\男生头像.png"; } else { checkedStudent[i].pngfile = @"..\..\Resources\女生头像.png"; } //设置该img控件的Source checkedStudent[i].headImage.Source = new BitmapImage(new Uri(System.IO.Path.GetFullPath(System.IO.Path.Combine(System.Environment.CurrentDirectory, @checkedStudent[i].pngfile)))); //检查作业的按钮隐藏 checkedStudent[i].btnHomeworkCorrect1.Visibility = Visibility.Hidden; checkedStudent[i].lbHomeworkState1.Content = ""; checkedStudent[i].btnHomeworkCorrect1.Content = "";//修改button名称 //为什么这里不能向listview中加数据 listViewUnFinish.Items.Add(checkedStudent[i]); //根据stuId和notId查询homId,然后保存在homIds这个数组中 DataTable tbHomId = td.getHomIdByStuIdAndNotId(stuId, notId); int homId = int.Parse(tbHomId.Rows[0][0].ToString()); homIdUnfinisheds[i] = homId;//保存homId到数组 } }
//加载已完成学生信息 public void loadCorrected(string classSpecId, string homeworkTitle) { DataTable table1 = ts.getClassId(classSpecId); int classId = Convert.ToInt32(table1.Rows[0][0]); DataTable table2 = ts.getNotIdByClassIdAndNotTitle(homeworkTitle, classId); //获得notId this.notId = table2.Rows[0][0].ToString(); DataTable table3 = ts.selectHomeworkCheckedInfo(notId); //MessageBox.Show(table3.Rows.Count.ToString()); int checkedNum = table3.Rows.Count; //加载已批改的动态控件 TbItemChecked.Header = " 已批改 " + checkedNum; //获取学生列表的长度 int stuListLength = table3.Rows.Count; //定义动态生成控件的数组,长度与学生列表长一致 StudentCheck[] checkedStudent = new StudentCheck[stuListLength]; //设置学生头像的不同性别 //设置该img控件的Source headImage.Source = new BitmapImage(new Uri(System.IO.Path.GetFullPath(System.IO.Path.Combine(System.Environment.CurrentDirectory, @pngfile)))); //定义存储学生列表对应homId的int数组 homIdCorrecteds = new int[stuListLength]; //定义存储学生列表对应stuId的int数组 stuSpecIdCorrecteds = new String[stuListLength]; //定义存储学生列表对应stuName的int数组 stuNameCorrecteds = new String[stuListLength]; for (int i = 0; i < stuListLength; i++) { checkedStudent[i] = new StudentCheck(i); String stuId = table3.Rows[i][0].ToString(); DataTable table4 = ts.getStudentNameAndIdByStuID(stuId); checkedStudent[i].lbStudentInfo1.Content = table4.Rows[0][0].ToString(); stuSpecIdCorrecteds[i] = table4.Rows[0][0].ToString(); checkedStudent[i].lbStudentInfo2.Content = table4.Rows[0][1].ToString(); stuNameCorrecteds[i] = table4.Rows[0][1].ToString(); //查到当前学生的性别 int sex = ss.getSexByStuSpecId(table4.Rows[0][0].ToString()); if (sex == 1) { checkedStudent[i].pngfile = @"..\..\Resources\男生头像.png"; } else { checkedStudent[i].pngfile = @"..\..\Resources\女生头像.png"; } //设置该img控件的Source checkedStudent[i].headImage.Source = new BitmapImage(new Uri(System.IO.Path.GetFullPath(System.IO.Path.Combine(System.Environment.CurrentDirectory, @checkedStudent[i].pngfile)))); checkedStudent[i].lbHomeworkState1.Content = "已批改"; //为什么这里不能向listview中加数据 listViewChecked.Items.Add(checkedStudent[i]); checkedStudent[i].btnHomeworkCorrect1.Click += new RoutedEventHandler(btnHomeworkCorrect1_Click); //根据stuId和notId查询homId,然后保存在homIds这个数组中 DataTable tbHomId = td.getHomIdByStuIdAndNotId(stuId, notId); int homId = int.Parse(tbHomId.Rows[0][0].ToString()); homIdCorrecteds[i] = homId;//保存homId到数组 } }