Example #1
0
        public ActionResult GetReportProfileInformation([DataSourceRequest] DataSourceRequest request, Hre_ReportGeneralSearchModel model)
        {
            #region Validate
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ReportGeneralSearchModel>(model, "Hre_ReportGeneral", ref message);
            if (!checkValidate)
            {
                var ls = new object[] { "error", message };
                return Json(ls);
            }
            #endregion

            Hre_ReportServices Services = new Hre_ReportServices();
            string NameTable = "ReportProfileInformation";
            List<Guid> listOrgID = new List<Guid>();

            if (model.OrgStructureID != null)
            {
                listOrgID = model.OrgStructureID.StringToList();
            }

            DataTable Table = Services.GetReportProfileInformation(listOrgID, (DateTime)model.DateStart,
                (DateTime)model.DateEnd, model.CodeEmp, model.ProfileName, model.IsCreateTemplate, NameTable, UserLogin);



            #region Xử lý cách export mới
            var isDataTable = false;
            DataTable obj = null;
            if (model.IsCreateTemplateForDynamicGrid)
            {
                var col = Table.Columns.Count;
                Table.Columns.RemoveAt(col - 1);
                obj = Table;
                isDataTable = true;
            }
            HeaderInfo headerInfo1 = new HeaderInfo() { Name = "DateStart", Value = model.DateStart };
            HeaderInfo headerInfo2 = new HeaderInfo() { Name = "DateEnd", Value = model.DateEnd };
            List<HeaderInfo> listHeaderInfo = new List<HeaderInfo>() { headerInfo1, headerInfo2 };

            if (model != null && model.IsCreateTemplate)
            {
                var path = Common.GetPath("Templates");
                ExportService exportService = new ExportService();

                ConfigExport cfgExport = new ConfigExport()
                {
                    Object = obj,
                    FileName = NameTable,
                    OutPutPath = path,
                    HeaderInfo = listHeaderInfo,
                    DownloadPath = Hrm_Main_Web + "Templates",
                    IsDataTable = isDataTable
                };
                var str = exportService.CreateTemplate(cfgExport);
                return Json(str);
            }

            if (model.ExportID != Guid.Empty)
            {
                var fullPath = ExportService.Export(model.ExportID, Table, listHeaderInfo, ExportFileType.Excel);
                return Json(fullPath);
            }
            #endregion

            return new JsonResult() { Data = Table.ToDataSourceResult(request), MaxJsonLength = Int32.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }