// รายงานผลงานพนักงาน public ActionResult EmployeesWorkingReportView(int?page) { string month = Request.Params["month"]; if (!String.IsNullOrEmpty(month)) { List <UsersModel> lusModel = new List <UsersModel>(); Database db = new Database(); UsersDAO usDAO = new UsersDAO(db); lusModel = usDAO.FindByMonthYear(month); db.Close(); foreach (var u in lusModel) { db = new Database(); RepairDAO rDAO = new RepairDAO(db); u.REPAIR = new WorkingEmployeesViewModel(); u.REPAIR.SUCCESS_REP = rDAO.CountByUserIDSuccess(u.USER_NO, month); db.Close(); db = new Database(); rDAO = new RepairDAO(db); u.REPAIR.WAIT_REP = rDAO.CountByUserIDWait(u.USER_NO, month); db.Close(); db = new Database(); rDAO = new RepairDAO(db); u.REPAIR.NOW_REP = rDAO.CountByUserIDNowWorking(u.USER_NO, month); db.Close(); db = new Database(); rDAO = new RepairDAO(db); u.REPAIR.CANNOT_REP = rDAO.CountByUserIDFail(u.USER_NO, month); db.Close(); } var numage = page ?? 1; ViewBag.USER = lusModel.ToPagedList(numage, 20); } return(View()); }
public ActionResult ExportEmployeesWorkingReport(string month) { List <UsersModel> lusModel = new List <UsersModel>(); Database db = new Database(); UsersDAO usDAO = new UsersDAO(db); lusModel = usDAO.FindByMonthYear(month); db.Close(); foreach (var u in lusModel) { db = new Database(); RepairDAO rDAO = new RepairDAO(db); u.REPAIR = new WorkingEmployeesViewModel(); u.REPAIR.SUCCESS_REP = rDAO.CountByUserIDSuccess(u.USER_NO); db.Close(); db = new Database(); rDAO = new RepairDAO(db); u.REPAIR.WAIT_REP = rDAO.CountByUserIDWait(u.USER_NO); db.Close(); db = new Database(); rDAO = new RepairDAO(db); u.REPAIR.NOW_REP = rDAO.CountByUserIDNowWorking(u.USER_NO); db.Close(); db = new Database(); rDAO = new RepairDAO(db); u.REPAIR.CANNOT_REP = rDAO.CountByUserIDFail(u.USER_NO); db.Close(); } string type = "excel"; LocalReport lr = new LocalReport(); string path = Server.MapPath("~/Reportor/EmployeeWorkingReport.rdlc"); if (System.IO.File.Exists(path)) { lr.ReportPath = path; } var data = lusModel.Select(d => new { UID = d.USER_UID, NAME = d.NAME + " " + d.LASTNAME, WAIT = d.REPAIR.WAIT_REP, NOW = d.REPAIR.NOW_REP, SUCCESS = d.REPAIR.SUCCESS_REP, CANNOT = d.REPAIR.CANNOT_REP }).ToList(); ConvertClass cv = new ConvertClass(); string[] x = month.Split('-'); ReportParameter rpm = new ReportParameter() { Name = "MONTH", Values = { cv.monthToStringMonth(Int32.Parse(x[1])) + " " + x[0] } // ชื่อรายงาน }; ReportDataSource rds = new ReportDataSource("WorkingDataSetReport", data); lr.SetParameters(rpm); lr.DataSources.Add(rds); lr.DisplayName = "รายงานผลงานประจำ" + cv.monthToStringMonth(Int32.Parse(x[1])) + " " + x[0]; // ชื่อรายงาน string reportType = type; string mimeType; string encoding; string fileNameExtension; string deviceInfoA4 = "<DeviceInfo>" + " <OutputFormat>" + type + "</OutputFormat>" + " <PageWidth>21cm</PageWidth>" + " <PageHeight>29.7cm</PageHeight>" + " <MarginTop>1cm</MarginTop>" + " <MarginLeft>0.5in</MarginLeft>" + " <MarginRight>0.5in</MarginRight>" + " <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes; renderedBytes = lr.Render(reportType, "", out mimeType, out encoding, out fileNameExtension, out streams, out warnings); return(File(renderedBytes, mimeType)); }