예제 #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;
            }
        }
예제 #2
0
        public ReportEditViewModel(IEventAggregator aggregator,
                                   IDataService <LabDbEntities> labDbData,
                                   IReportService reportService,
                                   IReportingService reportingService) : base()
        {
            _labDbData        = labDbData;
            _editMode         = false;
            _eventAggregator  = aggregator;
            _projectChanged   = false;
            _reportService    = reportService;
            _reportingService = reportingService;

            AddFileCommand = new DelegateCommand(
                () =>
            {
                OpenFileDialog fileDialog = new OpenFileDialog
                {
                    InitialDirectory = UserSettings.ReportPath,
                    Multiselect      = true
                };

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    foreach (string pth in fileDialog.FileNames)
                    {
                        ReportFile temp  = new ReportFile();
                        temp.Path        = pth;
                        temp.Description = "";
                        temp.reportID    = _instance.ID;
                        temp.Create();
                    }

                    RaisePropertyChanged("FileList");
                }
            },
                () => CanModify);

            AddTestsCommand = new DelegateCommand(
                () =>
            {
                if (_reportService.AddTestsToReport(_instance))
                {
                    TestList = new List <TestWrapper>(_instance.TestRecord.Tests.Select(tst => new TestWrapper(tst)));
                }
            },
                () => CanModify);

            GenerateRawDataSheetCommand = new DelegateCommand(
                () =>
            {
                _reportingService.PrintReportDataSheet(_instance);
            });

            OpenFileCommand = new DelegateCommand(
                () =>
            {
                try
                {
                    System.Diagnostics.Process.Start(_selectedFile.Path);
                }
                catch (Exception)
                {
                    _eventAggregator.GetEvent <StatusNotificationIssued>().Publish("File non trovato");
                }
            },
                () => _selectedFile != null);

            RemoveFileCommand = new DelegateCommand(
                () =>
            {
                _selectedFile.Delete();
                SelectedFile = null;

                RaisePropertyChanged("FileList");
            },
                () => CanModify && _selectedFile != null);

            RemoveTestCommand = new DelegateCommand <Test>(
                testItem =>
            {
                TaskItem tempTaskItem = testItem.GetTaskItem();
                testItem.Delete();

                if (tempTaskItem != null)
                {
                    throw new NotImplementedException();
                }

                TestList = new List <TestWrapper>(_instance.TestRecord.Tests.Select(tst => new TestWrapper(tst)));
            },
                testItem => EditMode);

            _save = new DelegateCommand(
                () =>
            {
                // Update the tests
                _testList.Select(tiw => tiw.TestInstance)
                .Update();

                // Update the report instance

                _instance.Update();

                // If the project was modified, update the material

                if (_projectChanged)
                {
                    _instance.SetProject(_selectedProject);
                }

                EditMode = false;
            },
                () => _editMode);

            StartEditCommand = new DelegateCommand(
                () =>
            {
                EditMode = true;
            },
                () => !_editMode && CanModify);

            #region EventSubscriptions

            _eventAggregator.GetEvent <ProjectChanged>()
            .Subscribe(ect =>
            {
                _projectList = null;
                RaisePropertyChanged("ProjectList");
            });

            #endregion EventSubscriptions
        }