Пример #1
0
        /// <summary>
        /// Exporte le projet.
        /// </summary>
        /// <param name="sheet">La feuille.</param>
        private void ExportProject(WorksheetPart sheet)
        {
            var project       = _data.Project;
            var cellReference = new CellReference();

            // Nom
            _file.SetCellValue(sheet, cellReference, project.Label);
            cellReference.NewLine();

            // Description
            _file.SetCellValue(sheet, cellReference, project.Description);
            cellReference.NewLine();

            // Utilisateur
            _file.SetCellValue(sheet, cellReference, SecurityContext.CurrentUser.FullName);
            cellReference.NewLine();

            // Objectif
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_Objective",
                          project.Objective != null ? project.Objective.LongLabel : project.OtherObjectiveLabel);

            // Atelier
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_Workshop", project.Workshop);

            // Custom Labels
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Text1", project.CustomTextLabel);
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Text2", project.CustomTextLabel2);
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Text3", project.CustomTextLabel3);
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Text4", project.CustomTextLabel4);
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Numeric1", project.CustomNumericLabel);
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Numeric2", project.CustomNumericLabel2);
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Numeric3", project.CustomNumericLabel3);
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_CustomLabel_Numeric4", project.CustomNumericLabel4);

            // Version
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_ApplicationVersion", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());

            // Precision
            SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Project_Precision", (int)TimeSpan.FromTicks(project.TimeScale).TotalMilliseconds);


            // Summary
            /////////////////////////
            cellReference.NewLine();
            cellReference.NewLine();


            var dataGrid = new System.Windows.Controls.DataGrid();

            SummaryBuilder.BuildScenarios(project.ScenariosCriticalPath, dataGrid);

            var headers = dataGrid.Columns.Select(column => column.Header);

            if (dataGrid.ItemsSource is object[][] dataSource)
            {
                foreach (var header in headers)
                {
                    _file.SetCellValue(sheet, cellReference, header.SafeToString());
                    cellReference.MoveRight();
                }

                cellReference.NewLine();
                foreach (var row in dataSource)
                {
                    foreach (var cell in row)
                    {
                        if (cell != null)
                        {
                            if (cell is SummaryBuilder.CellContent)
                            {
                                _file.SetCellValue(sheet, cellReference, ((SummaryBuilder.CellContent)cell).Content.SafeToString());
                            }
                            else
                            {
                                _file.SetCellValue(sheet, cellReference, cell.ToString());
                            }
                        }
                        cellReference.MoveRight();
                    }
                    cellReference.NewLine();
                }
            }
        }