Пример #1
0
        private void CreateExcelDoc(int CRId, CRPlanning crp)
        {
            try
            {
                string templateFileName;
                C.eReportTemplateTypes templateType = C.eReportTemplateTypes.SANTE;
                string templateFileNamePPT;
                string templateFilePath;
                string templateFilePathPPT;
                string prevProvisionFile;
                string crFileName;
                string crFileNamePPT;
                string crFilePath;
                string crFilePathPPT;
                int    yearsToCalc      = 1;
                bool   reportWithOption = false;

                //new name of the Exel file
                crFileName    = Name + ".xlsm";
                crFileNamePPT = Name + ".pptm";

                //copy & rename the appropriate Template File from the ReportTemplates folder to the ExcelCR folder
                if (ReportLevelId.HasValue)
                {
                    templateFileName    = ReportTemplate.GetTemplateFileNameForId(ReportLevelId.Value);
                    templateType        = ReportTemplate.GetTemplateTypeForId(ReportLevelId.Value);
                    templateFileNamePPT = templateFileName.Replace(".xlsm", ".pptm");
                    yearsToCalc         = ReportTemplate.GetYearsToCalcForId(ReportLevelId.Value);
                    reportWithOption    = ReportTemplate.GetWithOptionFlag(ReportLevelId.Value);
                }
                else
                {
                    throw new Exception("No report template is associated with the specified CR!");
                }

                //templateFileName = C.ExcelTemplateGlobalCompany;
                //if (ReportType == C.eReportTypes.GlobalEnt || ReportType == C.eReportTypes.GlobalSubsid)
                //{
                //    if (IsPrev)
                //    {
                //        templateFileName = C.ExcelTemplateGlobalCompanyPrevoyance;
                //    }
                //    else
                //    {
                //        templateFileName = C.ExcelTemplateGlobalCompanySante;
                //    }
                //}


                templateFilePath    = Path.Combine(ExcelTemplatePath, templateFileName);
                templateFilePathPPT = Path.Combine(ExcelTemplatePath, templateFileNamePPT);
                prevProvisionFile   = Path.Combine(ExcelTemplatePath, C.cPrevProvisionFileName);
                crFilePath          = Path.Combine(ExcelCRPath, crFileName);
                crFilePathPPT       = Path.Combine(ExcelCRPath, crFileNamePPT);


                string newPrevProvPath = Path.Combine(ExcelCRPath, C.cPrevProvisionFileName);

                //### display warning if the destination file already exists or should we just overwrtie the file ???

                if (File.Exists(templateFilePath))
                {
                    File.Copy(templateFilePath, crFilePath, true);
                }
                else
                {
                    throw new Exception("The specified Excel template file does not exist: " + templateFileName);
                }

                if (ReportType == C.eReportTypes.Standard)
                {
                    if (File.Exists(templateFilePathPPT))
                    {
                        File.Copy(templateFilePathPPT, crFilePathPPT, true);
                    }
                    else
                    {
                        throw new Exception("The specified PPT template file does not exist: " + templateFileNamePPT);
                    }
                }

                if (templateType == C.eReportTemplateTypes.PREV)
                {
                    if (File.Exists(prevProvisionFile))
                    {
                        File.Copy(prevProvisionFile, newPrevProvPath, true);
                    }
                    else
                    {
                        throw new Exception("The 'PrevProvision.xlsm' file does not exist in the ReportTemplates folder!");
                    }
                }

                if (CRExists)
                {
                    ReportFile.Delete(CRId, C.eReportFileTypes.Excel.ToString());
                }

                ReportFile repFile = new ReportFile {
                    CRId = CRId, FileType = C.eReportFileTypes.Excel.ToString(), FileLocation = crFileName
                };
                int repId = ReportFile.Insert(repFile);

                ReportFiles.Add(repFile);

                //modify the excel file => update various Data Sheets
                FileInfo fiExcelFile = new FileInfo(crFilePath);

                string college;
                if (CollegeId.HasValue)
                {
                    college = College.GetCollegeNameForId(CollegeId.Value);
                }
                else
                {
                    throw new Exception("CreateExcelDoc:: CollegeId does not contain any value");
                }

                //the Presta Data will be required for several methods, so we extract it only once here
                DateTime debutPeriod;
                DateTime finPeriod;
                DateTime dateArret;

                //### change debutPeriode if we are using Template 1 => check DB value in ReportFile Table
                //DateTime dtNewDebut = null;

                if (crp.DebutPeriode.HasValue)
                {
                    debutPeriod = crp.DebutPeriode.Value;
                }
                else
                {
                    throw new Exception("CreateExcelDoc:: No date was provided for 'DebutPériode'!");
                }

                if (crp.FinPeriode.HasValue)
                {
                    finPeriod = crp.FinPeriode.Value;
                }
                else
                {
                    throw new Exception("CreateExcelDoc:: No date was provided for 'FinPériode'!");
                }

                if (crp.DateArret.HasValue)
                {
                    dateArret = crp.DateArret.Value;
                }
                else
                {
                    throw new Exception("CreateExcelDoc:: No date was provided for 'DateArret'!");
                }

                if (ReportType == C.eReportTypes.Standard)
                {
                    if (templateType == C.eReportTemplateTypes.SANTE)
                    {
                        CreateExcelSANTEData(fiExcelFile, AssurNames, ParentCompanyNames, SubsidNames, ContractNames, debutPeriod, finPeriod, yearsToCalc, college,
                                             dateArret, crp, crFilePathPPT, crFilePath, templateType, reportWithOption);
                    }

                    else if (templateType == C.eReportTemplateTypes.PREV)
                    {
                        CreateExcelPREVData(fiExcelFile, AssurNames, ParentCompanyNames, SubsidNames, ContractNames, debutPeriod, finPeriod, college,
                                            dateArret, crp, crFilePathPPT, crFilePath, templateType, yearsToCalc, CalculateProvision);
                    }
                }
                else
                {
                    CreateExcelGLOBALData(fiExcelFile, ParentCompanyNames, SubsidNames, debutPeriod, finPeriod, dateArret, ReportType, templateType);
                }
            }
            catch (Exception ex)
            {
                log.Error("CreateExcelDoc :: " + ex.Message);
                throw ex;
            }
        }