Beispiel #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var name = (sender as Control).Name;

            if (sender == ButtonCancel)
            {
                Cancelled = true;
                Close();
            }
            else if (sender == ButtonPasteHtml)
            {
                CreateTableFromClipboardHtml();
            }
            else if (sender == ButtonImportCsv)
            {
                var form = new TableEditorCsvImport();
                form.Owner = this;
                form.ShowDialog();

                if (form.IsCancelled)
                {
                    return;
                }

                var parser = new TableParserHtml();

                bool   deleteCsvFile = false;
                string csvFile       = form.CsvFilename;

                if (form.ImportFromClipboard)
                {
                    string csvText = ClipboardHelper.GetText();
                    csvFile = Path.GetTempFileName();
                    csvFile = Path.ChangeExtension(csvFile, "csv");
                    File.WriteAllText(csvFile, csvText);
                    deleteCsvFile = true;
                }


                var data = parser.ParseCsvFileToData(csvFile, form.CsvSeparator);
                if (data == null || data.Headers.Count < 1 && data.Rows.Count < 1)
                {
                    AppModel.Window.ShowStatusError($"Couldn\'t open file {csvFile} or the file is empty.");
                    return;
                }

                TableData = data;
                RenderTable();

                if (deleteCsvFile)
                {
                    File.Delete(csvFile);
                }
            }
        }
Beispiel #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var name = (sender as Control).Name;

            if (sender == ButtonOk)
            {
                var parser = new TableParser();

                if (TableMode == "Grid Table")
                {
                    TableHtml = parser.ToGridTableMarkdown(TableData);
                }
                else if (TableMode == "HTML Table")
                {
                    TableHtml = parser.ToTableHtml(TableData);
                }
                else
                {
                    TableHtml = parser.ToPipeTableMarkdown(TableData);
                }

                Cancelled    = false;
                DialogResult = true;
                Close();
            }
            else if (sender == ButtonCancel)
            {
                Cancelled = true;
                Close();
            }
            else if (sender == ButtonPasteHtml)
            {
                CreateTableFromClipboardHtml();
            }
            else if (sender == ButtonImportCsv)
            {
                var form = new TableEditorCsvImport();
                form.Owner = this;
                form.ShowDialog();

                if (form.IsCancelled)
                {
                    return;
                }

                var parser = new TableParser();

                bool   deleteCsvFile = false;
                string csvFile       = form.CsvFilename;

                if (form.ImportFromClipboard)
                {
                    string csvText = ClipboardHelper.GetText();
                    csvFile = Path.GetTempFileName();
                    csvFile = Path.ChangeExtension(csvFile, "csv");
                    File.WriteAllText(csvFile, csvText);
                    deleteCsvFile = true;
                }


                var data = parser.ParseCsvFileToData(csvFile, form.CsvSeparator);
                if (data == null || data.Count < 1)
                {
                    AppModel.Window.ShowStatusError($"Couldn\'t open file {csvFile} or the file is empty.");
                    return;
                }

                TableData = data;
                DataGridTableEditor.TableSource = TableData;

                if (deleteCsvFile)
                {
                    File.Delete(csvFile);
                }
            }

            var focusedTextBox = FocusManager.GetFocusedElement(this) as TextBox;

            if (focusedTextBox == null)
            {
                return;
            }

            if ("MenuInsertColumnRight" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Right);
            }
            else if ("MenuInsertColumnLeft" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Left);
            }
            else if ("MenuDeleteColumn" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteColumn(pos.Row, pos.Column);
            }
            else if ("MenuInsertRowBelow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Below);
            }
            else if ("MenuInsertRowAbove" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Above);
            }
            else if ("MenuDeleteRow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteRow(pos.Row, pos.Column);
            }
        }