protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string strStationID = ConfigurationManager.AppSettings["StationID"]; if (strStationID == "200") { lblDate.Text = PrjPub.GetRailName() + "·þÎñÆ÷"; } else { OrganizationBLL orgBll = new OrganizationBLL(); Organization organization = orgBll.GetOrganization(Convert.ToInt32(strStationID)); lblDate.Text = organization.ShortName + "·þÎñÆ÷"; } string strSql = "select * from Computer_Server where Computer_Server_No='" + PrjPub.ServerNo + "'"; OracleAccess db = new OracleAccess(); DataSet ds = db.RunSqlDataSet(strSql); if (ds.Tables[0].Rows.Count > 0) { lblServerName.Text = ds.Tables[0].Rows[0]["Computer_Server_Name"].ToString(); } lblServerNo.Text = PrjPub.ServerNo.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string strStationID = ConfigurationManager.AppSettings["StationID"]; lbl.Text = "当前服务器为:"; if (strStationID == "200") { lbl.Text += PrjPub.GetRailName() + "服务器"; } else { OrganizationBLL orgBll = new OrganizationBLL(); RailExam.Model.Organization organization = orgBll.GetOrganization(Convert.ToInt32(strStationID)); lbl.Text += organization.ShortName + "服务器"; } lbl.Text += " 服务器编号为:" + PrjPub.ServerNo; } }
private string GetExamOutString(string strId, string orgid) { ExamResultBLL examResultBLL = new ExamResultBLL(); PaperBLL kBLL = new PaperBLL(); RailExam.Model.ExamResult examResult = new RailExam.Model.ExamResult(); if (ViewState["NowOrgID"].ToString() == orgid) { examResult = examResultBLL.GetExamResult(Convert.ToInt32(strId)); } else { examResult = examResultBLL.GetExamResultByOrgID(Convert.ToInt32(strId), Convert.ToInt32(orgid)); } RailExam.Model.Paper paper = null; EmployeeBLL ebLL = new EmployeeBLL(); RailExam.Model.Employee Employee = ebLL.GetEmployee(examResult.ExamineeId); paper = kBLL.GetPaper(examResult.PaperId); PaperItemBLL paperItemBLL = new PaperItemBLL(); IList <RailExam.Model.PaperItem> paperItems = paperItemBLL.GetItemsByPaperId(paper.PaperId); int nItemCount = paperItems.Count; decimal nTotalScore = 0; for (int i = 0; i < paperItems.Count; i++) { nTotalScore += paperItems[i].Score; } string strOrgName = Employee.OrgName; string strStationName = ""; string strOrgName1 = ""; int n = strOrgName.IndexOf("-"); if (n != -1) { strStationName = strOrgName.Substring(0, n); strOrgName1 = strOrgName.Substring(n + 1); } else { strStationName = strOrgName; strOrgName1 = ""; } string str = "<div style='text-align:center;font-size:18pt;'>" + PrjPub.GetRailName() + "考试试卷</div>"; str += "<div style='text-align:left;font-size:10.5pt;'>考试名称:" + paper.PaperName + " </div>"; str += "<div style='text-align:right;font-size:10.5pt;'>总共" + nItemCount + "题,共 " + nTotalScore + "分</div>"; str += "<div style='text-align:center;'><table width='100%' border='1' cellpadding='0' cellspacing='0' >"; str += "<tr><td width='7%' style='font-size:10.5pt' >单位:</td>"; str += "<td width='26%' style='font-size:10.5pt' align='left' >" + strStationName + "</td>"; str += "<td width='7%' style='font-size:10.5pt' >车间:</td>"; str += "<td width='27%' style='font-size:10.5pt' align='left' >" + strOrgName1 + "</td>"; str += "<td width='7%' style='font-size:10.5pt' >职名:</td>"; str += "<td width='26%' style='font-size:10.5pt' align='left' >" + Employee.PostName + "</td></tr>"; str += "<tr><td width='7%' style='font-size:10.5pt' >姓名:</td>"; str += "<td width='26%' style='font-size:10.5pt' align='left' >" + Employee.EmployeeName + "</td>"; str += "<td width='7%' style='font-size:10.5pt' >时间:</td>"; str += "<td width='27%' style='font-size:10.5pt' align='left' >" + examResult.BeginDateTime.ToString("yyyy-MM-dd HH:mm") + "</td>"; str += "<td width='7%' style='font-size:10.5pt' >成绩:</td>"; str += "<td width='26%' style='font-size:10.5pt' align='left' >" + examResult.Score + "</td></tr></table></div>"; str += "<br>"; str += GetFillExamPaperString(strId, orgid); string strReplace; if (PrjPub.IsServerCenter) { strReplace = "http://" + ConfigurationManager.AppSettings["ServerIP"] + "/RailExamBao/"; } else { strReplace = "http://" + ConfigurationManager.AppSettings["StationIP"] + "/RailExamBao/"; } str = str.Replace("/RailExamBao/", strReplace); return(str); }
protected void btnOutPut_Click(object sender, ImageClickEventArgs e) { DataSet ds = GetDataSet(); DataTable dt = ds.Tables[0]; int orgID = Convert.ToInt32(Request.QueryString.Get("OrgID")); string OrgName = ""; if (orgID != 1) { OrganizationBLL orgBll = new OrganizationBLL(); Organization org = orgBll.GetOrganization(orgID); OrgName = org.ShortName; } string strExamName = ""; string strExamTime = ""; string qsExamId = Request.QueryString.Get("eid"); ExamBLL examBll = new ExamBLL(); RailExam.Model.Exam exam = examBll.GetExam(int.Parse(qsExamId)); if (exam != null) { strExamName = exam.ExamName; strExamTime = exam.BeginTime.ToString() + "--" + exam.EndTime.ToString(); } SpreadsheetClass xlsheet = new SpreadsheetClass(); Worksheet ws = (Worksheet)xlsheet.Worksheets[1]; ws.Cells.Font.set_Size(10); ws.Cells.Font.set_Name("宋体"); ws.Cells[1, 1] = PrjPub.GetRailName() + OrgName; Range rang1 = ws.get_Range(ws.Cells[1, 1], ws.Cells[2, 13]); rang1.set_MergeCells(true); rang1.set_HorizontalAlignment(XlHAlign.xlHAlignCenter); rang1.Font.set_Bold(true); rang1.Font.set_Size(17); rang1.Font.set_Name("宋体"); ws.Cells[3, 1] = strExamName + "学员成绩登记表"; rang1 = ws.get_Range(ws.Cells[3, 1], ws.Cells[3, 13]); rang1.set_MergeCells(true); rang1.set_HorizontalAlignment(XlHAlign.xlHAlignCenter); rang1.Font.set_Bold(true); rang1.Font.set_Size(12); rang1.Font.set_Name("宋体"); ws.Cells[4, 1] = "考试日期: " + strExamTime; rang1 = ws.get_Range(ws.Cells[4, 1], ws.Cells[4, 13]); rang1.set_MergeCells(true); rang1.set_HorizontalAlignment(XlHAlign.xlHAlignRight); rang1.Font.set_Name("宋体"); //write headertext ws.Cells[5, 1] = "序号"; ((Range)ws.Cells[5, 1]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter); ws.Cells[5, 2] = "姓名"; ws.get_Range(ws.Cells[5, 2], ws.Cells[5, 4]).set_MergeCells(true); ws.get_Range(ws.Cells[5, 2], ws.Cells[5, 4]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter); ws.Cells[5, 5] = "组织机构(车间)"; ws.get_Range(ws.Cells[5, 5], ws.Cells[5, 7]).set_MergeCells(true); ws.get_Range(ws.Cells[5, 5], ws.Cells[5, 7]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter); ws.Cells[5, 8] = "职名"; ws.get_Range(ws.Cells[5, 8], ws.Cells[5, 10]).set_MergeCells(true); ws.get_Range(ws.Cells[5, 8], ws.Cells[5, 10]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter); ws.Cells[5, 11] = "分数"; ws.get_Range(ws.Cells[5, 11], ws.Cells[5, 13]).set_MergeCells(true); ws.get_Range(ws.Cells[5, 11], ws.Cells[5, 13]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter); decimal decScore = 0; for (int j = 0; j < dt.Rows.Count; j++) { ws.Cells[6 + j, 1] = j + 1; ws.Cells[6 + j, 2] = dt.Rows[j]["ExamineeName"].ToString(); ws.get_Range(ws.Cells[6 + j, 2], ws.Cells[6 + j, 4]).set_MergeCells(true); ws.get_Range(ws.Cells[6 + j, 2], ws.Cells[6 + j, 4]).set_HorizontalAlignment(XlHAlign.xlHAlignLeft); ws.Cells[6 + j, 5] = dt.Rows[j]["OrganizationName"].ToString(); ws.get_Range(ws.Cells[6 + j, 5], ws.Cells[6 + j, 7]).set_MergeCells(true); ws.get_Range(ws.Cells[6 + j, 5], ws.Cells[6 + j, 7]).set_HorizontalAlignment(XlHAlign.xlHAlignLeft); ws.Cells[6 + j, 8] = dt.Rows[j]["PostName"].ToString(); ws.get_Range(ws.Cells[6 + j, 8], ws.Cells[6 + j, 10]).set_MergeCells(true); ws.get_Range(ws.Cells[6 + j, 8], ws.Cells[6 + j, 10]).set_HorizontalAlignment(XlHAlign.xlHAlignLeft); decScore += decimal.Parse(dt.Rows[j]["Score"].ToString()); ws.Cells[6 + j, 11] = dt.Rows[j]["Score"].ToString(); ws.get_Range(ws.Cells[6 + j, 11], ws.Cells[6 + j, 13]).set_MergeCells(true); ws.get_Range(ws.Cells[6 + j, 11], ws.Cells[6 + j, 13]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter); } decimal dec1 = 0; if (dt.Rows.Count > 0) { dec1 = decScore / dt.Rows.Count; } ws.Cells[6 + dt.Rows.Count, 1] = "平均分:"; ((Range)ws.Cells[5, 1]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter); ws.Cells[6 + dt.Rows.Count, 2] = dec1.ToString("0.00"); ws.get_Range(ws.Cells[6 + dt.Rows.Count, 2], ws.Cells[6 + dt.Rows.Count, 13]).set_MergeCells(true); ws.get_Range(ws.Cells[6 + dt.Rows.Count, 2], ws.Cells[6 + dt.Rows.Count, 13]).set_HorizontalAlignment(XlHAlign.xlHAlignRight); for (int k = 1; k <= 13; k++) { for (int j = 5; j <= 6 + dt.Rows.Count; j++) { ((Range)ws.Cells[j, k]).BorderAround(1, XlBorderWeight.xlThin, XlColorIndex.xlColorIndexAutomatic, Missing.Value); } } ws.Name = "1-1"; ws.Cells.Columns.AutoFit(); try { ((Worksheet)xlsheet.Worksheets[1]).Activate(); string path = Server.MapPath("../Excel/Excel.xls"); if (File.Exists(path)) { File.Delete(path); } xlsheet.Export(path, SheetExportActionEnum.ssExportActionNone, SheetExportFormat.ssExportAsAppropriate); System.IO.FileInfo file = new System.IO.FileInfo(path); this.Response.Clear(); this.Response.Buffer = true; this.Response.Charset = "utf-7"; this.Response.ContentEncoding = System.Text.Encoding.UTF7; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 this.Response.AddHeader("Content-Disposition", "attachment; filename=" + "Excel.xls"); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 this.Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 this.Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端 this.Response.WriteFile(file.FullName); } catch { SessionSet.PageMessage = "系统错误,导出Excel文件失败!"; } }