|
(1、) //導(dǎo)出事件(導(dǎo)出時(shí)不能用ajax事件,否則導(dǎo)出失敗) function Initexport() { $("#BtnExport").click(function() { var url = "/OptionSetUp/SuggestionExport?kind=1"; var selectStatus = document.getElementById("selectStatus").value; // var l = document.getElementById("Location").value; var startTime = document.getElementById("SuggestionTimeBegin").value; var endTime = document.getElementById("SuggestionTimeEnd").value; var employeeName = document.getElementById("TextEmployeeName").value; var employeeNo = document.getElementById("TextEmployeeNo").value; var suggestionContent = document.getElementById("TextSugeestionContent").value; if (selectStatus != "") url = url + "&selectStatus=" + encodeURIComponent(selectStatus); // if (l != "") // url = url + "&location=" + l; if (startTime != "") url = url + "&startTime=" + encodeURIComponent(startTime); if (endTime != "") url = url + "&endTime=" + encodeURIComponent(endTime); if (employeeName != "") url = url + "&employeeName=" + encodeURIComponent(employeeName); if (employeeNo != "") url = url + "&employeeNo=" + encodeURIComponent(employeeNo); if (suggestionContent != "") url = url + "&suggestionContent=" + encodeURIComponent(suggestionContent); location.href = url; }); } /// <summary> /// 導(dǎo)出建議 /// </summary> /// <returns></returns> public void SuggestionExport() { V_IRS_SuggestionResult vepr = new V_IRS_SuggestionResult(); //EntityList vepr = new EntityList(); int status = 0; string employeeNo = ""; string employeeName = ""; string sugContent = ""; DateTime startTime = new DateTime(); DateTime endTime = new DateTime(); string kind = Request.QueryString["kind"].ToString(); if (Request.QueryString["selectStatus"] != null) status = Convert.ToInt32(Request.QueryString["selectStatus"]); //if (Request.QueryString["location"] != null) // location = Request.QueryString["location"]; if (Request.QueryString["suggestionContent"] != null) sugContent = Request.QueryString["suggestionContent"]; if (Request.QueryString["employeeName"] != null) employeeName = Request.QueryString["employeeName"]; if (Request.QueryString["employeeName"] != null) employeeNo = Request.QueryString["employeeNo"]; if (Request.QueryString["employeeNo"] != null) startTime = Convert.ToDateTime(Request.QueryString["startTime"]); if (Request.QueryString["endTime"] != null) endTime = Convert.ToDateTime(Request.QueryString["endTime"]).AddDays(1); int start = Convert.ToInt32(Request.QueryString["start"]); int limit = Convert.ToInt32(Request.QueryString["limit"]); //判斷當(dāng)前人是否是管理員 List<V_IRS_Suggestion> list = new List<V_IRS_Suggestion>(); try { string auth = this.prizeLogic.IsExistAuth(CurrentUserInfo.UserID); if (Session["IRSUserInfo"] != null && userLogic.isReceiveAuth(CurrentUserInfo.UserID)) { list = this.sugLogic.GetSuggestionWhere(employeeNo, employeeName, sugContent, startTime, endTime, status); } else { Response.Redirect("/Home/Home"); } List<V_IRS_Suggestion> listReturn = new List<V_IRS_Suggestion>(); for (int i = 0; i < list.Count; i++) { listReturn.Add(list[i]); } vepr.totalCount = list.Count; vepr.suggestion = listReturn; vepr.success = true; } catch (Exception e) { } if (list.Count > 0) { try { string filePath = Server.MapPath("../Temp/Report.xls"); FileInfo downloadFile = new FileInfo(filePath); if (downloadFile.Exists) { System.IO.File.Delete(filePath); } HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.CreateSheet("UserSuggestionReport"); HSSFCellStyle cellStyle = workbook.CreateCellStyle(); // HSSFDataFormat format = workbook.CreateDataFormat(); cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");//設(shè)置日期格式 @代表文本類型 //填充表頭 HSSFRow dataRow = sheet.CreateRow(0); dataRow.CreateCell(0).SetCellValue("員工工號(hào)"); dataRow.CreateCell(1).SetCellValue("員工姓名"); dataRow.CreateCell(2).SetCellValue("工作地點(diǎn)"); dataRow.CreateCell(3).SetCellValue("員工BU"); dataRow.CreateCell(4).SetCellValue("建議日期"); dataRow.CreateCell(5).SetCellValue("建議內(nèi)容"); dataRow.CreateCell(6).SetCellValue("建議分類"); //填充內(nèi)容 V_IRS_Suggestion item = null; string jobName = ""; for (int i = 0; i < list.Count; i++) { item = list[i]; dataRow = sheet.CreateRow(i + 1); dataRow.CreateCell(0).SetCellValue(item.employee_no == null ? "" : item.employee_no.ToString());//推薦人工號(hào) dataRow.CreateCell(1).SetCellValue(item.user_name == null ? "" : item.user_name.ToString());//推薦人姓名 dataRow.CreateCell(2).SetCellValue(item.location_name == null ? "" : item.location_name.ToString());//工作地點(diǎn) dataRow.CreateCell(3).SetCellValue(item.BU == null ? "" : item.BU.ToString());//推薦人BU //dataRow.CreateCell(4).SetCellValue(item.suggestion_time == null ? "" : item.suggestion_time.ToString());//建議日期 dataRow.CreateCell(5).SetCellValue(item.suggestion == null ? "" : item.suggestion.ToString());//建議內(nèi)容BU dataRow.CreateCell(6).SetCellValue(item.suggestion_type == null ? "" : item.suggestion_type.ToString());//建議分類 if (item.suggestion_time == null) { dataRow.CreateCell(4).SetCellValue("");//建議日期 } else { dataRow.CreateCell(4).SetCellValue(((DateTime)item.suggestion_time).ToString("yyyy-MM-dd"));//建議日期 } ////候選人狀態(tài) //if (Convert.ToInt32(item.suggestion_type) == 1 || Convert.ToInt32(item.suggestion_type) == 11 || Convert.ToInt32(item.suggestion_type) == 15) //{ // dataRow.CreateCell(6).SetCellValue("未答復(fù)"); //} //else if (Convert.ToInt32(item.suggestion_type) == 2) //{ // dataRow.CreateCell(6).SetCellValue("已答復(fù)"); ; //} dataRow.GetCell(4).CellStyle = cellStyle; } //保存 using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { workbook.Write(fs); } workbook.Dispose(); Thread.Sleep(3000); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/ms-excel"; Response.AppendHeader("Content-Disposition", "attachment;filename=ReportList.xls"); Response.BinaryWrite(System.IO.File.ReadAllBytes(filePath)); System.IO.File.Delete(filePath); } catch (Exception ex) { logLogic.AddLog(ex, "導(dǎo)出時(shí)異常", "Method:ReportExport"); Response.Redirect("/Help/ErrorPage"); } } else { Response.Redirect("IRSReport"); } } (2、) //導(dǎo)出事件(導(dǎo)出時(shí)不能用ajax事件,否則導(dǎo)出失敗) function Initexport() { $("#BtnExport").click(function() { var url = "/OptionSetUp/GradeExport?"; var startTime = document.getElementById("GradeTimeBegin").value; var endTime = document.getElementById("GradeTimeEnd").value; if (startTime != "") url = url + "startTime=" + startTime; if (endTime != "") url = url + "&endTime=" + endTime; location.href = url; }); } /// <summary> /// 員工評(píng)分導(dǎo)出 /// </summary> /// <returns></returns> public void GradeExport() { List<Avg_GradeAnswerScore> list = new List<Avg_GradeAnswerScore>(); DateTime startTime = DateTime.Now.AddDays(-1000); DateTime endTime = DateTime.Now; if (Request.QueryString["startTime"] != null) { startTime = Convert.ToDateTime(Request.QueryString["startTime"]); } if (Request.QueryString["endTime"] != null) { endTime = Convert.ToDateTime(Request.QueryString["endTime"]); } list = gradeLogic.EmpGradeAnswerScoreByDate(startTime.ToString(), endTime.ToString()); if (list.Count > 0) { try { string filePath = Server.MapPath("../Temp/GradeReport.xls"); //FileInfo downloadFile = new FileInfo(filePath); //if (downloadFile.Exists) //{ // System.IO.File.Delete(filePath); //} string sql = ""; sql = @"INSERT INTO [Sheet1$]([題目號(hào)], [平均分]) VALUES(@question_id, @avg_score)"; System.IO.File.Copy(Server.MapPath("~/Template/GradeDemo.xls"), filePath); using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=Excel 8.0;")) { conn.Open(); foreach (var item in list) { OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.Parameters.AddWithValue("@question_id", item.Question_id == null ? 0 : item.Question_id); cmd.Parameters.AddWithValue("@avg_score", item.avg_score == null ? 0 : item.avg_score); cmd.ExecuteNonQuery(); } conn.Close(); conn.Dispose(); GC.Collect(); } Thread.Sleep(3000); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/ms-excel"; Response.AppendHeader("Content-Disposition", "attachment;filename=GradeList.xls"); Response.BinaryWrite(System.IO.File.ReadAllBytes(filePath)); System.IO.File.Delete(filePath); } catch (Exception ex) { logLogic.AddLog(ex, "導(dǎo)出員工評(píng)分時(shí)異常", "Method:GradeExport"); Response.Redirect("/Help/ErrorPage"); } } else { Response.Redirect("EmployeeGrade"); } } |
|
|