Ejemplo n.º 1
0
        /// <summary>
        /// rebuild the parameter sheet, replace it if it already exists.
        /// </summary>
        /// <param name="application">
        /// The excel application object that contains the <see cref="Workbook"/> in which the parameter sheet is to be rebuilt.
        /// </param>
        /// <param name="workbook">
        /// The <see cref="Workbook"/> in which the parameter sheet is to be rebuilt.
        /// </param>
        /// <param name="clones">
        /// The <see cref="Thing"/>s that have been changed on the Parameter sheet that need to be kept
        /// </param>
        public void Rebuild(Application application, Workbook workbook, IReadOnlyDictionary <Guid, ProcessedValueSet> processedValueSets)
        {
            var sw = new Stopwatch();

            sw.Start();

            this.excelApplication = application;

            this.excelApplication.StatusBar = "Rebuilding Parameter Sheet";

            this.listSeparator = (string)application.International(XlApplicationInternational.xlListSeparator);
            this.xlCountryCode = Convert.ToInt32(application.International(XlApplicationInternational.xlCountryCode));
            this.SetLanguageSpecificVariables();
            this.SetSwitchString();

            var enabledEvents  = application.EnableEvents;
            var displayAlerts  = application.DisplayAlerts;
            var screenupdating = application.ScreenUpdating;
            var calculation    = application.Calculation;

            application.EnableEvents   = false;
            application.DisplayAlerts  = false;
            application.Calculation    = XlCalculation.xlCalculationManual;
            application.ScreenUpdating = false;

            try
            {
                application.Cursor = XlMousePointer.xlWait;

                this.parameterSheet = ParameterSheetUtilities.RetrieveParameterSheet(workbook, true);

                ParameterSheetUtilities.ApplyLocking(this.parameterSheet, false);

                this.PopulateSheetArrays(processedValueSets);
                this.WriteParameterSheet();
                this.ApplySheetSettings();

                ParameterSheetUtilities.ApplyLocking(this.parameterSheet, true);

                this.excelApplication.StatusBar = $"CDP4: Parameter Sheet rebuilt in {sw.ElapsedMilliseconds} [ms]";
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                this.excelApplication.StatusBar = $"CDP4: The following error occured while rebuilding the sheet: {ex.Message}";
            }
            finally
            {
                application.EnableEvents   = enabledEvents;
                application.DisplayAlerts  = displayAlerts;
                application.Calculation    = calculation;
                application.ScreenUpdating = screenupdating;

                application.Cursor = XlMousePointer.xlDefault;
            }
        }
        /// <summary>
        /// Write the <see cref="Option"/> sheets to the <see cref="Workbook"/>
        /// </summary>
        /// <param name="workbook">
        /// The <see cref="Workbook"/> in which the <see cref="Option"/> sheets are to be rebuilt.
        /// </param>
        protected override void Write(Workbook workbook)
        {
            foreach (var item in this.iteration.Option)
            {
                var option = (Option)item;
                Logger.Info("Writing Option sheet {0} to the workbook", option.ShortName);

                var optionSheet = ParameterSheetUtilities.RetrieveOptionSheet(workbook, option);
                ParameterSheetUtilities.ApplyLocking(optionSheet, false);

                var headerEndRow = this.PopulateAndWriteHeaderArray(optionSheet, option);
                var startrow     = headerEndRow + 2;
                this.PopulateAndWriteParameterArray(optionSheet, option, startrow);

                this.ApplySheetSettings(optionSheet);

                ParameterSheetUtilities.ApplyLocking(optionSheet, true);
            }
        }