Пример #1
0
        public ActionResult GetReportC70A([DataSourceRequest] DataSourceRequest request, Ins_SearchC70AReportModel model)
        {
            var isDataTable = false;
            object obj = new Ins_C70aReportEntity();
            var service = new Ins_InsuranceReportServices();
            ListQueryModel lstModel = new ListQueryModel
            {
                PageIndex = request.Page,
                PageSize = request.PageSize,
                Filters = ExtractFilterAttributes(request),
                Sorts = ExtractSortAttributes(request)
            };

            var result = service.GetReportC70A(model.DateMonth, model.DateStart, model.DateEnd, model.OrgStructureID, model.CutOffDurationName, model.IsCreateTemplate);
            if (model.IsCreateTemplateForDynamicGrid)
            {
                obj = result;
                isDataTable = true;
            }
            if (model != null && model.IsCreateTemplate)
            {
                var path = Common.GetPath("Templates");
                ExportService exportService = new ExportService();
                ConfigExport cfgExport = new ConfigExport()
                {
                    Object = obj,
                    FileName = "Ins_C70aReportModel",
                    OutPutPath = path,
                    DownloadPath = Hrm_Main_Web + "Templates",
                    IsDataTable = isDataTable

                };
                var str = exportService.CreateTemplate(cfgExport);
                return Json(str);
            }

            if (model.ExportId != Guid.Empty)
            {
                if (result.Rows.Count > 0)
                {
                    foreach (DataRow row in result.Rows)
                    {
                        if (Enum.IsDefined(typeof(InsuranceRecordType), row[Ins_C70aReportModel.FieldNames.Status].ToString()))
                        {
                            row[Ins_C70aReportModel.FieldNames.Status] = row[Ins_C70aReportModel.FieldNames.Status].ToString().TranslateString();
                        }
                        if (Enum.IsDefined(typeof(InsuranceRecordType), row[Ins_C70aReportModel.FieldNames.CodeEmp].ToString()))
                        {
                            row[Ins_C70aReportModel.FieldNames.CodeEmp] = row[Ins_C70aReportModel.FieldNames.CodeEmp].ToString().TranslateString();
                        }
                        if (Enum.IsDefined(typeof(InsuranceRecordType), row[Ins_C70aReportModel.FieldNames.GroupName].ToString()))
                        {
                            row[Ins_C70aReportModel.FieldNames.GroupName] = row[Ins_C70aReportModel.FieldNames.GroupName].ToString().TranslateString();
                        }
                    }
                }

                var fullPath = ExportService.Export(model.ExportId, result, null, model.ExportType);
                return Json(fullPath);
            }

            #region mapping dataTable to dataList
            //List<Ins_C70aReportModel> dataList = new List<Ins_C70aReportModel>();
            //Ins_C70aReportModel aTSource = null;
            //if (result.Rows.Count > 0)
            //{
            //    const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
            //    var objFieldNames = (from PropertyInfo aProp in typeof(Ins_C70aReportModel).GetProperties(flags)
            //                         select new
            //                         {
            //                             Name = aProp.Name,
            //                             Type = Nullable.GetUnderlyingType(aProp.PropertyType) ?? aProp.PropertyType
            //                         }).ToList();
            //    var dataTblFieldNames = (from DataColumn aHeader in result.Columns
            //                             select new { Name = aHeader.ColumnName, Type = aHeader.DataType }).ToList();
            //    var commonFields = objFieldNames.Intersect(dataTblFieldNames).ToList();
            //    foreach (DataRow dataRow in result.AsEnumerable().ToList())
            //    {
            //        aTSource = new Ins_C70aReportModel();
            //        foreach (var aField in commonFields)
            //        {
            //            PropertyInfo propertyInfos = aTSource.GetType().GetProperty(aField.Name);
            //            if (dataRow[aField.Name] == DBNull.Value)
            //                continue;
            //            propertyInfos.SetValue(aTSource, dataRow[aField.Name], null);
            //        }
            //        dataList.Add(aTSource);
            //    }
            //}
            #endregion

            return Json(result.ToDataSourceResult(request));
        }