Exemplo n.º 1
0
        internal void ExportNW(int projektId)
        {
            log.Info("ExportNW");
            var pi = GetProjektInfo(projektId);

            if (pi == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "ProjektInfo with id {0} doesn't exist in  Database!", projektId));
            }
            log.Debug("Getting Excel.Application");
            _MyApp = new Excel.Application();
            log.Debug("Got Excel.Application");
            try
            {
                _WorkBook = _MyApp.Workbooks.Open(_TemplateFile, Missing.Value, ReadOnly: false); //, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                //_MyApp.Visible = true;
                //_MyApp.ScreenUpdating = true;
                _SheetNW   = GetWorksheet("Template_Nutzwertfestlegung");
                _SheetPari = GetWorksheet("Template_Parifizierung");

                _WohnungInfos.Clear();
                var wohnungen = _Database.GetWohnungen(projektId);
                foreach (var w in wohnungen)
                {
                    _WohnungInfos[w.Top] = w;
                }

                WriteNW(projektId, pi);
                WritePari(projektId, pi); // Nutzflächenanteile

                log.Debug("Deleting Template-Sheets.");
                _MyApp.DisplayAlerts = false;
                _SheetNW.Delete();
                _SheetPari.Delete();
                _MyApp.DisplayAlerts = true;

                if (_TargetFile != null)
                {
                    log.Debug(string.Format(CultureInfo.InvariantCulture, "Saving to '{0}'", _TargetFile));
                    _WorkBook.SaveAs(_TargetFile);
                }
            }
            finally
            {
                if (_TargetFile == null)
                {
                    log.Debug("_MyApp.Visible = true;");
                    _MyApp.Visible = true;
                    log.Debug("_MyApp.ScreenUpdating = true;");
                    _MyApp.ScreenUpdating = true;
                }
            }
        }
Exemplo n.º 2
0
        internal void ExportNf(int projektId)
        {
            log.Info("ExportNF");
            var pi = GetProjektInfo(projektId);

            if (pi == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "ProjektInfo with id {0} doesn't exist in  Database!", projektId));
            }
            log.Debug("Getting Excel.Application");
            _MyApp = new Excel.Application();
            log.Debug("Got Excel.Application");
            try
            {
                _WorkBook = _MyApp.Workbooks.Open(_TemplateFile, Missing.Value, ReadOnly: false); //, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                //_MyApp.Visible = true;
                //_MyApp.ScreenUpdating = true;
                _SheetSumme     = GetWorksheet("Template_Summe");
                _SheetAllgemein = GetWorksheet("Template_Allgemein");
                _SheetTop       = GetWorksheet("Template_Top");
                var topSheet = GetWorksheet("Top");
                _SheetAbstell = GetWorksheet("Template_Abstellplätze");

                _WohnungInfos.Clear();
                var wohnungen = _Database.GetWohnungen(projektId);
                foreach (var w in wohnungen)
                {
                    _WohnungInfos[w.Top] = w;
                }

                // Here it starts
                var summeSheet = WriteSumme(projektId, pi);
                WriteAllgemein(projektId, pi);
                WriteTops(projektId, pi, summeSheet);
                WriteAbstell(projektId, pi);

                // Cleanup sheets
                log.Debug("Deleting Template-Sheets.");
                _MyApp.DisplayAlerts = false;
                _SheetSumme.Delete();
                _SheetAllgemein.Delete();
                _SheetTop.Delete();
                _SheetAbstell.Delete();
                topSheet.Delete();
                _MyApp.DisplayAlerts = true;

                if (_TargetFile != null)
                {
                    log.Debug(string.Format(CultureInfo.InvariantCulture, "Saving to '{0}'", _TargetFile));
                    _WorkBook.SaveAs(_TargetFile);
                }
            }
            finally
            {
                if (_TargetFile == null)
                {
                    log.Debug("_MyApp.Visible = true;");
                    _MyApp.Visible = true;
                    log.Debug("_MyApp.ScreenUpdating = true;");
                    _MyApp.ScreenUpdating = true;
                }
            }
        }