Beispiel #1
0
        private void Import(ExportTableRecord job,
                            IFlyoutProvider fop,
                            AdminShell.Submodel sm, AdminShell.AdministrationShellEnv env)
        {
            // get the import file
            var dlg = new Microsoft.Win32.OpenFileDialog();

            try
            {
                dlg.InitialDirectory = System.IO.Path.GetDirectoryName(
                    System.AppDomain.CurrentDomain.BaseDirectory);
            }
            catch (Exception ex)
            {
                AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
            }
            dlg.Title = "Select text file to be exported";

            if (job.Format == (int)ExportTableRecord.FormatEnum.TSF)
            {
                dlg.DefaultExt = "*.txt";
                dlg.Filter     =
                    "Tab separated file (*.txt)|*.txt|Tab separated file (*.tsf)|*.tsf|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.LaTex)
            {
                dlg.DefaultExt = "*.tex";
                dlg.Filter     = "LaTex file (*.tex)|*.tex|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
            {
                dlg.DefaultExt = "*.xlsx";
                dlg.Filter     = "Microsoft Excel (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
            {
                dlg.DefaultExt = "*.docx";
                dlg.Filter     = "Microsoft Word (*.docx)|*.docx|All files (*.*)|*.*";
            }

            fop?.StartFlyover(new EmptyFlyout());
            var res = dlg.ShowDialog(fop?.GetWin32Window());

            fop?.CloseFlyover();

            if (true != res)
            {
                return;
            }

            // try import
            try
            {
                Log.Info("Importing table: {0}", dlg.FileName);
                var success = false;
                try
                {
                    if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
                    {
                        success = true;
                        var pop = new ImportPopulateByTable(Log, job, sm, env, options);
                        using (var stream = File.Open(dlg.FileName, FileMode.Open,
                                                      FileAccess.Read, FileShare.ReadWrite))
                            foreach (var tp in ImportTableWordProvider.CreateProviders(stream))
                            {
                                pop.PopulateBy(tp);
                            }
                    }

                    if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
                    {
                        success = true;
                        var pop = new ImportPopulateByTable(Log, job, sm, env, options);
                        foreach (var tp in ImportTableExcelProvider.CreateProviders(dlg.FileName))
                        {
                            pop.PopulateBy(tp);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log?.Error(ex, "importing table");
                    success = false;
                }

                if (!success)
                {
                    fop?.MessageBoxFlyoutShow(
                        "Some error occured while importing the table. Please refer to the log messages.",
                        "Error", AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Exclamation);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "When exporting table, an error occurred");
            }
        }
Beispiel #2
0
        private void Export(ExportTableRecord job,
                            IFlyoutProvider fop,
                            AdminShell.Submodel sm, AdminShell.AdministrationShellEnv env)
        {
            // prepare list of items to be exported
            var list = new List <ExportTableAasEntitiesList>();

            ExportTable_EnumerateSubmodel(list, env, broadSearch: false,
                                          actInHierarchy: job.ActInHierarchy, depth: 1, sm: sm, sme: null);

            // get the output file
            var dlg = new Microsoft.Win32.SaveFileDialog();

            try
            {
                dlg.InitialDirectory = System.IO.Path.GetDirectoryName(
                    System.AppDomain.CurrentDomain.BaseDirectory);
            }
            catch (Exception ex)
            {
                AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
            }
            dlg.Title = "Select text file to be exported";

            if (job.Format == (int)ExportTableRecord.FormatEnum.TSF)
            {
                dlg.FileName   = "new.txt";
                dlg.DefaultExt = "*.txt";
                dlg.Filter     =
                    "Tab separated file (*.txt)|*.txt|Tab separated file (*.tsf)|*.tsf|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.LaTex)
            {
                dlg.FileName   = "new.tex";
                dlg.DefaultExt = "*.tex";
                dlg.Filter     = "LaTex file (*.tex)|*.tex|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
            {
                dlg.FileName   = "new.xlsx";
                dlg.DefaultExt = "*.xlsx";
                dlg.Filter     = "Microsoft Excel (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
            {
                dlg.FileName   = "new.docx";
                dlg.DefaultExt = "*.docx";
                dlg.Filter     = "Microsoft Word (*.docx)|*.docx|All files (*.*)|*.*";
            }

            fop?.StartFlyover(new EmptyFlyout());
            var res = dlg.ShowDialog(fop?.GetWin32Window());

            fop?.CloseFlyover();

            try
            {
                if (res == true)
                {
                    Log.Info("Exporting table: {0}", dlg.FileName);
                    var success = false;
                    try
                    {
                        if (job.Format == (int)ExportTableRecord.FormatEnum.TSF)
                        {
                            success = job.ExportTabSeparated(dlg.FileName, list);
                        }
                        if (job.Format == (int)ExportTableRecord.FormatEnum.LaTex)
                        {
                            success = job.ExportLaTex(dlg.FileName, list);
                        }
                        if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
                        {
                            success = job.ExportExcel(dlg.FileName, list);
                        }
                        if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
                        {
                            success = job.ExportWord(dlg.FileName, list);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "performing data format export");
                        success = false;
                    }

                    if (!success)
                    {
                        fop?.MessageBoxFlyoutShow(
                            "Some error occured while exporting the table. Please refer to the log messages.",
                            "Error", AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Exclamation);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "When exporting table, an error occurred");
            }
        }