Example #1
0
        public static API_VistaDB add_Viewer_StoredProcedures <T>(this API_VistaDB vistaDB, T control)
            where T : Control
        {
            control.clear();
            Database currentDatabase       = null;
            var      value                 = control.add_TextArea();
            var      storedProcedure_Names = value.insert_Left <Panel>(200).add_TreeView().sort();
            var      database_Names        = storedProcedure_Names.insert_Above <Panel>(100).add_TreeView().sort();

            var filter = storedProcedure_Names.insert_Above(20)
                         .add_TextBox("Filter:", "")
                         .onTextChange((text) => {
                storedProcedure_Names.clear();
                var result = (from storedProcedure in currentDatabase.StoredProcedures
                              where storedProcedure.Name.regEx(text)
                              select storedProcedure);
                storedProcedure_Names.add_Nodes(result);
            });

            database_Names.afterSelect <string>(
                (database_Name) => {
                value.set_Text("");
                currentDatabase = new Database(vistaDB, database_Name);
                currentDatabase.map_StoredProcedures();
                storedProcedure_Names.clear();
                storedProcedure_Names.add_Nodes(currentDatabase.StoredProcedures);
                storedProcedure_Names.selectFirst();
            });

            storedProcedure_Names.afterSelect <StoredProcedure>(
                (storedProcedure) => value.set_Text(storedProcedure.Value));

            database_Names.add_Nodes(vistaDB.database_Names());

            database_Names.selectFirst();
            return(vistaDB);
        }
Example #2
0
        public static API_VistaDB add_Viewer_TablesData <T>(this API_VistaDB vistaDB, T control)
            where T : Control
        {
            control.clear();
            var dataGridView = control.add_DataGridView();

            dataGridView.DataError += (sender, e) => {};           //" dataGridView error: {0}".error(e.Context);};
            var tables_Names   = dataGridView.insert_Left <Panel>(200).add_TreeView().sort();
            var database_Names = tables_Names.insert_Above <Panel>(100).add_TreeView().sort();
            var preloadAllData = false;

            tables_Names.insert_Below(20).add_CheckBox("Preload all data from database", 0, 0, (value) => preloadAllData = value).autoSize();       //.check();
            var rowData       = dataGridView.insert_Below <Panel>(100).add_SourceCodeViewer();
            var rowDataField  = rowData.insert_Left <Panel>(100).add_TreeView();
            var selectedField = "";

            rowDataField.afterSelect <DataGridViewCell>(
                (cell) => {
                selectedField    = rowDataField.selected().get_Text();
                var fieldContent = cell.Value.str().fix_CRLF();
                if (fieldContent.starts("<?xml"))
                {
                    "mapping xml".info();
                    fieldContent = fieldContent.xmlFormat();
                    rowData.set_Text(fieldContent, "a.xml");
                }
                else
                {
                    rowData.set_Text(fieldContent);
                }
            });

            dataGridView.afterSelect(
                (row) => {
                rowDataField.clear();
                //rowData.set_Text("");
                foreach (DataGridViewCell cell in row.Cells)
                {
                    var fieldName = dataGridView.Columns[cell.ColumnIndex].Name;
                    var node      = rowDataField.add_Node(fieldName, cell);
                    if (fieldName == selectedField)
                    {
                        node.selected();
                    }
                }
                if (rowDataField.selected().isNull())
                {
                    rowDataField.selectFirst();
                }
            });

            database_Names.afterSelect <string>(
                (database_Name) => {
                tables_Names.backColor(Color.Salmon);
                O2Thread.mtaThread(
                    () => {
                    var database = new Database(vistaDB, database_Name);
                    database.map_Tables();
                    if (preloadAllData)
                    {
                        database.map_Table_Data();
                    }
                    tables_Names.clear();
                    tables_Names.add_Nodes(database.Tables);
                    tables_Names.selectFirst();
                    tables_Names.backColor(Color.White);

                    database_Names.splitContainer().panel1Collapsed(true);
                });
            });

            Action <Table> loadTableData =
                (table) => {
                tables_Names.backColor(Color.Salmon);
                O2Thread.mtaThread(
                    () => {
                    rowDataField.clear();
                    rowData.set_Text("");
                    dataGridView.remove_Columns();
                    if (table.TableData.isNull())
                    {
                        vistaDB.map_Table_Data(table);
                    }
                    dataGridView.invokeOnThread(() => dataGridView.DataSource = table.TableData);
                    tables_Names.backColor(Color.White);
                });
            };

            tables_Names.afterSelect <Table>(
                (table) => {
                loadTableData(table);
            });

            database_Names.add_Nodes(vistaDB.database_Names());

            database_Names.selectFirst();


            tables_Names.add_ContextMenu().add_MenuItem("reload data",
                                                        () => {
                var selectedNode = tables_Names.selected();
                if (selectedNode.notNull())
                {
                    var table       = (Table)tables_Names.selected().get_Tag();
                    table.TableData = null;
                    loadTableData(table);
                }
            });
            return(vistaDB);
        }