protected void btnExamSeatArrange_Click(object sender, EventArgs e) { List<string> listStudent = new List<string>(); if (ddlCourses.SelectedValue != "-1") { DalOperationUsers dou = new DalOperationUsers(); DataTable dt1 = dou.SearchStudentByCourseNo(ddlCourses.SelectedValue.Trim()).Tables[0]; Session["examSeatArrange_dt1"] = dt1; for (int i = 0; i < dt1.Rows.Count;i++ ) { listStudent.Add(dt1.Rows[i]["studentNo"].ToString().Trim() + "_" + dt1.Rows[i]["studentName"].ToString().Trim()); } DalOperationAboutGradeCheck dal = new DalOperationAboutGradeCheck(); DataTable dt2 = dal.GetStudentGradeCheckApplyAccordByCourse(ddlCourses.SelectedValue).Tables[0]; Session["examSeatArrange_dt2"] = dt2; for (int j = 0; j < dt2.Rows.Count; j++) { listStudent.Add(dt2.Rows[j]["studentNo"].ToString().Trim() + "_" + dt2.Rows[j]["studentName"].ToString().Trim()); } //总学生人数 int studentsNum = dt1.Rows.Count + dt2.Rows.Count; //座位行数 int rows = int.Parse(txtRows.Text.Trim()); //座位列数 int cols = -1; if (studentsNum % rows == 0) { cols = studentsNum / rows; } else { cols = (studentsNum / rows) + 1; } Table tb = new Table(); tb.CssClass = "datagrid2"; tb.Width = Unit.Percentage(100); TableRow tr1 = new TableRow(); TableHeaderCell th = new TableHeaderCell(); th.Style["text-align"] = "center"; th.ColumnSpan = cols; th.Text = ddlCourses.SelectedItem.Text + "(当前共" + rows.ToString() + "行" + cols.ToString() + "列" + studentsNum + "名学生)"; tr1.Cells.Add(th); tb.Rows.Add(tr1); for (int x = 0; x < rows; x++) { TableRow tr = new TableRow(); for (int k = 0; k < cols; k++) { TableCell td = new TableCell(); td.HorizontalAlign = HorizontalAlign.Center; if (studentsNum > 0) { List<string> listStudentCopy = listStudent; List<string> newList = new List<string>(); while (listStudentCopy.Count > 0) { Random random = new Random(); int _index = random.Next(listStudentCopy.Count); newList.Insert(0, listStudentCopy[_index]); listStudentCopy.RemoveAt(_index); } listStudent = newList; int _rdm = GenerateRandom(studentsNum); string _studentNo = listStudent[_rdm].Split("_".ToCharArray())[0]; string _studentName = listStudent[_rdm].Split("_".ToCharArray())[1]; td.Text = _studentName + "<br />(" + _studentNo + ")"; listStudent.RemoveAt(_rdm); studentsNum--; } tr.Cells.Add(td); } tb.Rows.Add(tr); } phExamSeats.Controls.Add(tb); outputExcel.Visible = true; } else { Javascript.GoHistory(-1, "请选择课程:)", Page); } }
protected string WordDataBind() { Response.CacheControl = "no-cache"; string termTagCourseNoClassID = Request["termTagCourseNoClassID"]; string termTag = Request["termTag"]; //获取对应课程的重修重考学生信息 DalOperationAboutGradeCheck dal = new DalOperationAboutGradeCheck(); DataSet ds = dal.GetStudentGradeCheckApplyAccordByCourse(termTagCourseNoClassID); DataTable dt = ds.Tables[0]; StringBuilder sb = new StringBuilder(); if (dt.Rows.Count == 0) { Response.Write("当前课程未找到重修重考记录:("); return string.Empty; } //每页包含的重修重考记录数 int pagesize = 12; int limitCount = (dt.Rows.Count % pagesize == 0 ? dt.Rows.Count / pagesize : dt.Rows.Count / pagesize + 1); //目前表格只能容纳13行记录 for (int x = 0; x < limitCount; x++) { //获取课程数据 DalOperationAboutCourses dalCourses = new DalOperationAboutCourses(); DataTable dtCourses = dalCourses.GetCoursesByTermTagCourseNoClassID(termTagCourseNoClassID).Tables[0]; //拼接课程抬头信息 sb.Append("<table width=\"100%\" cellspacing=\"3\"><tr><td colspan=\"4\" align=\"center\" style=\"font-size:19pt;font-family:'宋体';\" cell>中国科学技术大学研究生重修重考申请表</td></tr>"); sb.Append("<tr><td colspan=\"4\" align=\"center\" style=\"font-size:11.5pt;font-family:'宋体';font-family:'黑体';\">" + CommonUtility.FormatTermTag(termTag) + "</td></tr>"); if (dtCourses.Rows.Count > 0) { string _location = (dtCourses.Rows[0]["ClassID"].ToString().Trim().Contains("合肥") ? "软件学院合肥" : "软件学院苏州"); sb.Append(string.Format("<tr><td style=\"font-size:11.5pt;font-family:'宋体';\">研究生所在系(室):</td><td style=\"font-size:11.5pt;font-family:'宋体';border-bottom:black 1px solid;\">{0}</td><td style=\"font-size:11.5pt;font-family:'宋体';\">开课系(室):</td><td style=\"font-size:11.5pt;font-family:'宋体';border-bottom:black 1px solid;\">{1}</td></tr>", _location, _location)); sb.Append(string.Format("<tr><td style=\"font-size:11.5pt;font-family:'宋体';\">课 程 编 号:</td><td style=\"font-size:11.5pt;font-family:'宋体';border-bottom:black 1px solid;\">{0}</td><td style=\"font-size:11.5pt;font-family:'宋体';\">总 学 时:</td><td style=\"font-size:11.5pt;font-family:'宋体';border-bottom:black 1px solid;\">{1}</td></tr>", dtCourses.Rows[0]["courseNo"].ToString().Trim(), dtCourses.Rows[0]["period"].ToString().Trim() + "/" + dtCourses.Rows[0]["TestHours"].ToString().Trim())); sb.Append(string.Format("<tr><td style=\"font-size:11.5pt;font-family:'宋体';\">课 程 名 称:</td><td style=\"font-size:11.5pt;font-family:'宋体';border-bottom:black 1px solid;\">{0}</td><td style=\"font-size:11.5pt;font-family:'宋体';\">学 分:</td><td style=\"font-size:11.5pt;font-family:'宋体';border-bottom:black 1px solid;\">{1}</td></tr>", dtCourses.Rows[0]["courseName"].ToString().Trim(), dtCourses.Rows[0]["credit"].ToString().Trim())); string _teacherName = string.Empty; DataTable _dtTeachers = dalCourses.GetTeachersByTermTagCourseNoClassID(termTagCourseNoClassID).Tables[0]; if (_dtTeachers.Rows.Count > 0) { sb.Append(string.Format("<tr><td style=\"font-size:11.5pt;font-family:'宋体';\">主 讲 老 师:</td><td style=\"font-size:11.5pt;font-family:'宋体';border-bottom:black 1px solid;\">{0}</td><td></td><td></td></tr>", _dtTeachers.Rows[0]["teacherName"].ToString().Trim())); } } sb.Append("</table>"); //拼接重修重考记录表格 sb.Append("<table width=\"100%\" cellSpacing=\"0\" style=\"font-size:'小四';border-left:black 1px solid;border-top:black 1px solid;margin-top:20px;\"><tr><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:8%;\">序号</td><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:15%;\">学号</td><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:10%;\">姓名</td><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:20%;\">班级</td><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:20%;\">重修重考原因</td><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:10%;\">重修 Or 重考</td><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:10%;\">备注</td><td valign=\"top\" style=\"border-right:black 1px solid;border-bottom:black 1px solid;width:7%;\">成绩</td></tr>"); for (int i = 0; i < pagesize; i++) { int _itemIndex = x * pagesize + i; if (_itemIndex < dt.Rows.Count) { sb.Append(string.Format("<tr><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{0}</td><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{1}</td><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{2}</td><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{3}</td><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{4}</td><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{5}</td><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{6}</td><td style=\"padding-left:3px;border-right:black 1px solid;border-bottom:black 1px solid;\">{7}</td></tr>", i + 1 + x*pagesize, dt.Rows[_itemIndex]["studentNo"].ToString().Trim(), dt.Rows[_itemIndex]["studentName"].ToString().Trim(), dt.Rows[_itemIndex]["SchoolClassName"].ToString().Trim(), dt.Rows[_itemIndex]["applyReason"].ToString().Trim(), dt.Rows[_itemIndex]["gradeCheckApplyType"].ToString().Trim(), dt.Rows[_itemIndex]["applyChecKSuggestion"].ToString().Trim(), string.Empty)); } } sb.Append("</table>"); //拼接重修重考页脚信息 sb.Append("<table width=\"100%\"><tr><td colspan=\"4\" style=\"font-size:8.5pt;font-family:'宋体';margin-top:20px;\">注:为确保成绩登记无误,请教学秘书务必参照“硕士研究生课程一览表”准确填写课程编号和名称。</td></tr>"); sb.Append("<tr><td style=\"font-size:11.5pt;font-family:'宋体';\">任课教师签字:</td><td style=\"font-size:11.5pt;font-family:'宋体';\">年</td><td style=\"font-size:11.5pt;font-family:'宋体';\">月</td><td style=\"font-size:11.5pt;font-family:'宋体';\">日</td></tr>"); sb.Append("</table>"); } return sb.ToString(); }