Esempio n. 1
0
        public override bool Calculate(DAL.MYResult entity)
        {
            /*
             *                  <option value="养老保险">养老保险</option>
             *                  <option value="医疗保险">医疗保险</option>
             *                  <option value="失业保险">失业保险</option>
             *                  <option value="工伤保险">工伤保险</option>
             *                  <option value="生育保险">生育保险</option>
             *                  <option value="住房公积金">住房公积金</option>
             *                  <option value="补充养老保险">补充养老保险</option>
             *                  <option value="大病或者特种病">大病或者特种病</option>
             */
            //获取养老的政策
            PoliceInsuranceBLL pi   = new PoliceInsuranceBLL();
            PoliceInsurance    data = new PoliceInsurance();
            var policeInsurance     = pi.GetByVertion(entity.Vertion, entity.InsuranceId, list[City].Value, list[InsuranceStyle].Value);

            //以下为修改的地方
            data = policeInsurance.Where(w => w.InsuranceKindId == "养老保险").FirstOrDefault();
            if (data != null)
            {
                list[10].Red       = Between(data, "企业", list[10].Value);
                list[11].Calculate = data.CompanyPercent.ToString() + "%";
                list[12].Calculate = Scale(data, "企业", list[10].Value);
                list[13].Calculate = data.EmployeePercent.ToString() + "%";
                list[14].Calculate = Scale(data, "个人", list[10].Value);
                //list[11].Red = Different(data, "企业", list[11].Value);//错误配置,因为在第34行已经为其赋值了,就会自动对比是否相同
            }

            data = policeInsurance.Where(w => w.InsuranceKindId == "医疗保险").FirstOrDefault();
            if (data != null)
            {
                list[15].Red       = Between(data, "企业", list[15].Value);
                list[16].Calculate = data.CompanyPercent.ToString() + "%";
                list[17].Calculate = Scale(data, "企业", list[15].Value);
                list[18].Calculate = data.EmployeePercent.ToString() + "%";
                list[19].Calculate = Scale(data, "个人", list[15].Value);
            }

            data = policeInsurance.Where(w => w.InsuranceKindId == "失业保险").FirstOrDefault();
            if (data != null)
            {
                list[20].Red       = Between(data, "企业", list[20].Value);
                list[21].Calculate = data.CompanyPercent.ToString() + "%";
                list[22].Calculate = Scale(data, "企业", list[20].Value);
                list[23].Calculate = data.EmployeePercent.ToString() + "%";
                list[24].Calculate = Scale(data, "个人", list[20].Value);
            }

            data = policeInsurance.Where(w => w.InsuranceKindId == "生育保险").FirstOrDefault();
            if (data != null)
            {
                list[25].Red       = Between(data, "企业", list[25].Value);
                list[26].Calculate = data.CompanyPercent.ToString() + "%";
                list[27].Calculate = Scale(data, "企业", list[25].Value);
            }

            data = policeInsurance.Where(w => w.InsuranceKindId == "工伤保险").FirstOrDefault();
            if (data != null)
            {
                list[28].Red       = Between(data, "企业", list[28].Value);
                list[29].Calculate = data.CompanyPercent.ToString() + "%";
                list[30].Calculate = Scale(data, "企业", list[28].Value);
            }

            data = policeInsurance.Where(w => w.InsuranceKindId == "住房公积金").FirstOrDefault();
            if (data != null)
            {
                list[31].Red       = Between(data, "企业", list[31].Value);
                list[32].Calculate = data.CompanyPercent.ToString() + "%";
                list[33].Calculate = Scale(data, "企业", list[31].Value);
                list[34].Calculate = data.EmployeePercent.ToString() + "%";
                list[35].Calculate = Scale(data, "个人", list[31].Value);
            }
            return(true);
        }
Esempio n. 2
0
 public virtual bool Calculate(DAL.MYResult entity)
 {
     return(true);
 }
Esempio n. 3
0
        public static string Make(DAL.MYResult entity)
        {
            string err = string.Empty;

            try
            {
                string pathmy = @"D:\SheBaoHeXiao\App";

                HSSFWorkbook _book    = new HSSFWorkbook();
                string       xlsPath  = pathmy + entity.GoldTempFullPath;
                FileStream   file     = new FileStream(xlsPath, FileMode.Open, FileAccess.Read);
                IWorkbook    workbook = WorkbookFactory.Create(file);
                ISheet       sheet    = workbook.GetSheetAt(0);

                ICell                  cell;
                List <Standard>        list     = new List <Standard>();
                Standard               standard = null;
                IDictionary <int, int> relation = DataFactory.CreateRelation(entity.GoldTempId);

                //循环excel的行数
                for (int i = 2; i <= sheet.LastRowNum; i++)
                {
                    standard = DataFactory.CreateStandard(entity.Vertion);
                    //标准模板
                    foreach (var item in relation.Values.Distinct())
                    {
                        standard.list.Add(item, new CalculateResult());
                    }
                    //循环
                    foreach (var item in relation)
                    {
                        cell = sheet.GetRow(i).GetCell(item.Key - 1);
                        if (cell != null)
                        {
                            switch (cell.CellType)
                            {
                            case CellType.Unknown:
                                break;

                            case CellType.Numeric:
                                var formatCode = cell.CellStyle.GetDataFormatString();
                                if (formatCode.EndsWith("%"))
                                {
                                    standard[item.Value].Value  += string.Format("{0:" + formatCode + "}", cell.NumericCellValue);   //得到5.88%
                                    standard[item.Value].Percent = formatCode;
                                }
                                else
                                {
                                    standard[item.Value].Value += cell.NumericCellValue;
                                }

                                break;

                            case CellType.String:
                                standard[item.Value].Value += cell.StringCellValue;
                                break;

                            case CellType.Formula:
                                standard[item.Value].Value += cell.NumericCellValue;
                                break;

                            case CellType.Blank:
                                break;

                            case CellType.Boolean:
                                break;

                            case CellType.Error:
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            err = "没有这一列";
                        }
                    }
                    //进行计算
                    standard.Calculate(entity);
                    list.Add(standard);
                }
                //写入excel

                //string xlsxPath = @"D:\HeXiao\Solution\App\up\standard\5.xlsx";

                string xlsxPath = pathmy + @"\up\standard\" + entity.Vertion + ".xlsx";

                FileStream fileStandard      = new FileStream(xlsxPath, FileMode.Open, FileAccess.Read);
                IWorkbook  workbookStandard  = WorkbookFactory.Create(fileStandard);
                ISheet     sheetfileStandard = workbookStandard.GetSheetAt(0);
                //红色单元格
                ICellStyle style = null;


                ISheet sheetfileStandard1 = workbookStandard.GetSheetAt(1);


                for (int i = 0; i < list.Count; i++)
                {
                    var dataRow  = sheetfileStandard.CreateRow(i + 2);
                    var dataRow1 = sheetfileStandard1.CreateRow(i + 2);
                    if (null != (list[i]))
                    {
                        foreach (var item in list[i].list)
                        {
                            var cellStandard  = dataRow.CreateCell(item.Key - 1);
                            var cellStandard1 = dataRow1.CreateCell(item.Key - 1);
                            //红色单元格
                            style = workbookStandard.CreateCellStyle();
                            if (item.Value.Red || string.IsNullOrWhiteSpace(item.Value.Value))
                            {
                                style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Red.Index;
                                style.FillPattern         = FillPattern.SolidForeground;
                                cellStandard.CellStyle    = style;
                                cellStandard1.CellStyle   = style;
                            }
                            if ((!string.IsNullOrWhiteSpace(item.Value.Value)) && item.Value.Value.Contains('%'))
                            {
                                cellStandard.CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat(item.Value.Percent);
                            }
                            if ((!string.IsNullOrWhiteSpace(item.Value.Calculate)) && item.Value.Calculate.Contains('%'))
                            {
                                cellStandard1.CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");
                            }

                            cellStandard.SetCellValue(item.Value.Value);

                            if (string.IsNullOrWhiteSpace(item.Value.Calculate))
                            {
                                cellStandard1.SetCellValue(item.Value.Value);
                            }
                            else
                            {
                                cellStandard1.SetCellValue(item.Value.Calculate);
                            }
                        }
                    }
                }

                string guid = Common.Result.GetNewId();

                var saveFileName = entity.GoldTempFullPath.Path(guid);
                entity.Result = saveFileName;
                string xlsPathFileName = pathmy + @"\up\Result\" + saveFileName;
                using (FileStream fileWrite = new FileStream(xlsPathFileName, FileMode.Create))
                {
                    workbookStandard.Write(fileWrite);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(err);
        }