Example #1
0
        public ActionResult GetReportInsuranceList([DataSourceRequest] DataSourceRequest request, Ins_ReportInsuranceTotalSearchModel model)
        {
            string status = string.Empty;
            //var isDataTable = false;
            var service = new BaseService();
            //object obj = new Hre_ProfileModel();
            ListQueryModel lstModel = new ListQueryModel
            {
                PageSize = int.MaxValue - 1,
                PageIndex = 1,
                Filters = ExtractFilterAttributes(request),
                Sorts = ExtractSortAttributes(request),
                AdvanceFilters = ExtractAdvanceFilterAttributes(model)
            };
            //    List<Hre_ProfileEntity> listProfile = service.GetData<Hre_ProfileEntity>(lstModel, ConstantSql.hrm_sal_sp_getdata_Profile, ref status);
            var ReportServices = new Ins_InsuranceReportServices();
            DateTime _DateFrom = DateTime.MinValue;
            DateTime _DateTo = DateTime.MaxValue;
            if (model != null && model.DateFrom != null)
            {
                _DateFrom = model.DateFrom.Value;
            }
            if (model != null && model.DateTo != null)
            {
                _DateTo = model.DateTo.Value;
            }
            var result = ReportServices.BC_INSURANCETOTAL(_DateFrom, _DateTo, model.OrgStructureIDs, model.SocialInsPlaceIDs, UserLogin);
            var isDataTable = false;
            object obj = new DataTable();
            if (model.IsCreateTemplateForDynamicGrid)
            {
                var col = result.Columns.Count;
                result.Columns.RemoveAt(col - 1);
                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_ReportInsuranceTotalEntity",
                    OutPutPath = path,
                    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, result, null, model.ExportType);
                return Json(fullPath);
            }
            //return new JsonResult() { Data = result.ToDataSourceResult(request), MaxJsonLength = int.MaxValue };
            #region mapping dataTable to dataList
            List<Ins_ReportInsuranceTotalModel> dataList = new List<Ins_ReportInsuranceTotalModel>();
            Ins_ReportInsuranceTotalModel aTSource = null;

            if (result.Rows.Count > 0)
            {
                const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
                var objFieldNames = (from PropertyInfo aProp in typeof(Ins_ReportInsuranceTotalModel).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_ReportInsuranceTotalModel();
                    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(dataList.ToDataSourceResult(request));
        }