Exemple #1
0
        private string GetInfoName(DatabaseObjectDisplayInfo info)
        {
            string name = info.Name;

            if (string.IsNullOrEmpty(name))
            {
                if (info.IsNew)
                {
                    string prefix = "";

                    if (info.DisplayType == DatabaseObjectDisplayType.Script)
                    {
                        prefix = "SQLQuery";
                    }
                    else if (info.DisplayType == DatabaseObjectDisplayType.TableDesigner)
                    {
                        prefix = "Table";
                    }

                    int num = this.GetNewMaxNameNumber(prefix);

                    name = prefix + (num + 1);

                    info.Name = name;
                }
            }

            return(name);
        }
Exemple #2
0
        public void ShowContent(DatabaseObjectDisplayInfo info)
        {
            this.Visible = true;

            TabPage page = this.FindTabPage(info);

            string title = this.GetFormatTabHeaderText(this.GetInfoName(info));

            if (page == null)
            {
                page = new TabPage(title)
                {
                };

                this.tabControl1.TabPages.Insert(0, page);

                this.tabControl1.SelectedTab = page;
            }
            else
            {
                this.tabControl1.SelectedTab = page;
            }

            page.Tag = info;

            page.BackColor = Color.Transparent;

            this.SetTabPageContent(info, page);

            this.SetTabPageTooltip(page);
        }
Exemple #3
0
        private void dgvResult_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            if (e.ColumnIndex == this.colInvalidRecordCount.Index)
            {
                DiagnoseResultItem resultItem = this.dgvResult.Rows[e.RowIndex].Tag as DiagnoseResultItem;

                string sql = resultItem.Sql;

                frmSqlQuery form = new frmSqlQuery()
                {
                    ReadOnly = true, ShowEditorMessage = false, SplitterDistance = 80
                };

                form.Init();

                DatabaseObjectDisplayInfo displayInfo = new DatabaseObjectDisplayInfo()
                {
                    DatabaseType   = this.DatabaseType,
                    ConnectionInfo = this.ConnectionInfo,
                    Content        = sql
                };

                form.Query(displayInfo);

                form.ShowDialog();
            }
        }
Exemple #4
0
        public void RunScripts()
        {
            if (this.tabControl1.TabCount == 0)
            {
                return;
            }

            TabPage tabPage = this.tabControl1.SelectedTab;

            if (tabPage == null)
            {
                return;
            }

            DatabaseObjectDisplayInfo data = tabPage.Tag as DatabaseObjectDisplayInfo;

            if (data == null || data.DisplayType != DatabaseObjectDisplayType.Script)
            {
                return;
            }

            UC_SqlQuery sqlQuery = this.GetUcControl <UC_SqlQuery>(tabPage);

            sqlQuery.RunScripts(data);
        }
Exemple #5
0
        private int GetNewMaxNameNumber(string prefix)
        {
            if (string.IsNullOrEmpty(prefix))
            {
                return(0);
            }

            List <string> names = new List <string>();

            foreach (TabPage page in this.tabControl1.TabPages)
            {
                DatabaseObjectDisplayInfo data = page.Tag as DatabaseObjectDisplayInfo;

                if (data.Name.Trim().StartsWith(prefix))
                {
                    names.Add(data.Name.Trim());
                }
            }

            string maxName = names.OrderByDescending(item => item.Length).ThenByDescending(item => item).FirstOrDefault();

            int num = 0;

            if (!string.IsNullOrEmpty(maxName))
            {
                string strNum = maxName.Replace(prefix, "");

                if (int.TryParse(strNum, out num))
                {
                }
            }

            return(num);
        }
 private void ShowContent(DatabaseObjectDisplayInfo info)
 {
     if (this.OnShowContent != null)
     {
         this.OnShowContent(info);
     }
 }
        public DatabaseObjectDisplayInfo GetDisplayInfo()
        {
            TreeNode node = this.tvDbObjects.SelectedNode;

            DatabaseObjectDisplayInfo info = new DatabaseObjectDisplayInfo()
            {
                DatabaseType = this.DatabaseType
            };

            if (node != null)
            {
                if (node.Tag is DatabaseObject dbObject)
                {
                    info.Name           = dbObject.Name;
                    info.DatabaseObject = dbObject;
                }

                TreeNode databaseNode = this.GetDatabaseNode(node);

                if (databaseNode != null)
                {
                    info.ConnectionInfo = this.GetConnectionInfo(databaseNode.Name);
                }
                else
                {
                    info.ConnectionInfo = this.connectionInfo;
                }
            }

            return(info);
        }
        private async void LoadData(DatabaseObjectDisplayInfo displayInfo, long pageNum = 1, bool isSort = false)
        {
            this.displayInfo = displayInfo;

            this.pagination.PageNum = pageNum;

            Table table = displayInfo.DatabaseObject as Table;

            int pageSize = this.pagination.PageSize;

            DbInterpreter dbInterpreter = DbInterpreterHelper.GetDbInterpreter(displayInfo.DatabaseType, displayInfo.ConnectionInfo, new DbInterpreterOption());

            string orderColumns = "";

            if (this.dgvData.SortedColumn != null)
            {
                string sortOrder = (this.sortOrder == SortOrder.Descending ? "DESC" : "ASC");
                orderColumns = $"{dbInterpreter.GetQuotedString(this.dgvData.SortedColumn.Name)} {sortOrder}";
            }

            string conditionClause = "";

            if (this.conditionBuilder != null && this.conditionBuilder.Conditions.Count > 0)
            {
                this.conditionBuilder.QuotationLeftChar  = dbInterpreter.QuotationLeftChar;
                this.conditionBuilder.QuotationRightChar = dbInterpreter.QuotationRightChar;

                conditionClause = "WHERE " + this.conditionBuilder.ToString();
            }

            (long Total, DataTable Data)result = await dbInterpreter.GetPagedDataTableAsync(table, orderColumns, pageSize, pageNum, conditionClause);

            this.pagination.TotalCount = result.Total;

            this.dgvData.DataSource = DataGridViewHelper.ConvertDataTable(result.Data);

            foreach (DataGridViewColumn column in this.dgvData.Columns)
            {
                Type valueType = column.ValueType;

                if (valueType == typeof(byte[]) || valueType.Name == "SqlGeography")
                {
                    column.SortMode = DataGridViewColumnSortMode.NotSortable;
                }
            }

            if (this.sortedColumnIndex != -1)
            {
                DataGridViewColumn column = this.dgvData.Columns[this.sortedColumnIndex];

                this.isSorting = true;

                ListSortDirection sortDirection = this.GetSortDirection(this.sortOrder);

                this.dgvData.Sort(column, sortDirection);

                this.isSorting = false;
            }
        }
Exemple #9
0
        public void Query(DatabaseObjectDisplayInfo displayInfo)
        {
            this.ucSqlQuery.Editor.AppendText(displayInfo.Content);

            RichTextBoxHelper.Highlighting(this.ucSqlQuery.Editor, displayInfo.DatabaseType, false);

            this.ucSqlQuery.RunScripts(displayInfo);
        }
        public DatabaseObjectDisplayInfo GetDisplayInfo()
        {
            DatabaseObjectDisplayInfo info = this.tvDbObjects.GetDisplayInfo();

            info.DatabaseType = this.DatabaseType;

            return(info);
        }
        private void DbConverter_OnTranslated(DatabaseType dbType, DatabaseObject dbObject, TranslateResult result)
        {
            DatabaseObjectDisplayInfo info = new DatabaseObjectDisplayInfo()
            {
                Name = dbObject.Name, DatabaseType = dbType, DatabaseObject = dbObject, Content = result.Data?.ToString(), ConnectionInfo = null, Error = result.Error
            };

            this.ShowContent(info);
        }
        public void Show(DatabaseObjectDisplayInfo displayInfo)
        {
            this.displayInfo                = displayInfo;
            this.ucColumns.DatabaseType     = displayInfo.DatabaseType;
            this.ucIndexes.DatabaseType     = displayInfo.DatabaseType;
            this.ucForeignKeys.DatabaseType = displayInfo.DatabaseType;
            this.ucConstraints.DatabaseType = displayInfo.DatabaseType;

            this.InitControls();
        }
Exemple #13
0
        private void SetTabPageContent(DatabaseObjectDisplayInfo info, TabPage tabPage)
        {
            if (info.DisplayType == DatabaseObjectDisplayType.Script)
            {
                UC_SqlQuery sqlQuery = this.GetUcControl <UC_SqlQuery>(tabPage);

                if (sqlQuery == null)
                {
                    sqlQuery = this.AddControlToTabPage <UC_SqlQuery>(tabPage);
                }

                sqlQuery.Show(info);

                if (!string.IsNullOrEmpty(sqlQuery.Editor.Text))
                {
                    RichTextBoxHelper.Highlighting(sqlQuery.Editor, info.DatabaseType, false);

                    if (info.Error != null)
                    {
                        RichTextBoxHelper.HighlightingError(sqlQuery.Editor, info.Error);
                    }
                }
                else
                {
                    sqlQuery.Editor.Focus();
                }
            }
            else if (info.DisplayType == DatabaseObjectDisplayType.Data)
            {
                UC_DataViewer dataViewer = this.GetUcControl <UC_DataViewer>(tabPage);

                if (dataViewer == null)
                {
                    dataViewer = this.AddControlToTabPage <UC_DataViewer>(tabPage);
                    dataViewer.OnDataFilter += this.DataFilter;
                }

                dataViewer.Show(info);
            }
            else if (info.DisplayType == DatabaseObjectDisplayType.TableDesigner)
            {
                UC_TableDesigner tableDesigner = this.GetUcControl <UC_TableDesigner>(tabPage);

                if (tableDesigner == null)
                {
                    tableDesigner             = this.AddControlToTabPage <UC_TableDesigner>(tabPage);
                    tableDesigner.OnFeedback += this.Feedback;
                }

                tableDesigner.Show(info);
            }
        }
Exemple #14
0
        private void SetTabPageTooltip(TabPage page)
        {
            DatabaseObjectDisplayInfo info = page.Tag as DatabaseObjectDisplayInfo;

            if (info != null)
            {
                string database = info.ConnectionInfo == null ? "" : $@": {info.ConnectionInfo?.Server}-{info.ConnectionInfo?.Database}";

                string filePath = File.Exists(info.FilePath) ? (info.FilePath + "  -  ") : "";

                page.ToolTipText = $@"{filePath}{info.DatabaseType}{database}";
            }
        }
Exemple #15
0
        public TabPage FindTabPage(DatabaseObjectDisplayInfo displayInfo)
        {
            foreach (TabPage page in this.tabControl1.TabPages)
            {
                DatabaseObjectDisplayInfo data = page.Tag as DatabaseObjectDisplayInfo;

                if (data.Name == displayInfo.Name && displayInfo.DatabaseType == data.DatabaseType && displayInfo.DisplayType == data.DisplayType)
                {
                    return(page);
                }
            }

            return(null);
        }
        private void DoScript(DatabaseObjectType databaseObjectType, ScriptAction scriptAction)
        {
            DbInterpreter dbInterpreter = DbInterpreterHelper.GetDbInterpreter(this.databaseType, new ConnectionInfo(), new DbInterpreterOption());

            ScriptTemplate scriptTemplate = new ScriptTemplate(dbInterpreter);

            DatabaseObjectDisplayInfo displayInfo = this.GetDisplayInfo();

            displayInfo.IsNew        = true;
            displayInfo.Content      = scriptTemplate.GetTemplateContent(databaseObjectType, scriptAction);
            displayInfo.ScriptAction = scriptAction;

            this.ShowContent(displayInfo);
        }
Exemple #17
0
        private void LoadFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            DatabaseObjectDisplayInfo info = this.navigator.GetDisplayInfo();

            info.DisplayType = DatabaseObjectDisplayType.Script;
            info.FilePath    = filePath;
            info.Name        = Path.GetFileNameWithoutExtension(info.FilePath);

            this.ucContent.ShowContent(info);
        }
Exemple #18
0
        private bool CloseTabPage(int tabPageIndex)
        {
            bool canClose = true;

            TabPage tabPage = this.tabControl1.TabPages[tabPageIndex];

            DatabaseObjectDisplayInfo info = tabPage.Tag as DatabaseObjectDisplayInfo;

            if (info != null && info.IsNew)
            {
                IDbObjContentDisplayer control = this.GetUcControlInterface(tabPage);

                bool saveRequired = false;

                if (control is UC_SqlQuery sqlQuery)
                {
                    if (sqlQuery.Editor.Text.Trim().Length > 0)
                    {
                        saveRequired = true;
                    }
                }

                if (saveRequired)
                {
                    DialogResult result = MessageBox.Show($"Do you want to save {info.Name}?", "Confirm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        this.Save();
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        canClose = false;
                    }
                }
            }

            if (canClose)
            {
                this.tabControl1.TabPages.RemoveAt(tabPageIndex);
                this.dictCloseButtonRectangle.Remove(tabPageIndex);
            }

            this.SetControlVisible();

            return(canClose);
        }
Exemple #19
0
        private void tsBtnAddQuery_Click(object sender, EventArgs e)
        {
            ConnectionInfo connectionInfo = this.navigator.GetCurrentConnectionInfo();

            if (connectionInfo != null)
            {
                DatabaseObjectDisplayInfo info = new DatabaseObjectDisplayInfo()
                {
                    IsNew = true, DisplayType = DatabaseObjectDisplayType.Script, DatabaseType = this.navigator.DatabaseType
                };

                info.ConnectionInfo = connectionInfo;

                this.ShowDbObjectContent(info);
            }
            else
            {
                MessageBox.Show("Please select a database from left navigator first.");
            }
        }
        private void ShowContent(DatabaseObjectDisplayType displayType, bool isNew = true)
        {
            DatabaseObjectDisplayInfo info = new DatabaseObjectDisplayInfo()
            {
                IsNew = isNew, DisplayType = displayType, DatabaseType = this.DatabaseType
            };

            if (!isNew)
            {
                DatabaseObject dbObject = this.tvDbObjects.SelectedNode.Tag as DatabaseObject;

                if (dbObject != null)
                {
                    info.DatabaseObject = dbObject;
                    info.Name           = dbObject.Name;
                }
            }

            info.ConnectionInfo = this.GetCurrentConnectionInfo();

            this.ShowContent(info);
        }
Exemple #21
0
        public void Show(DatabaseObjectDisplayInfo displayInfo)
        {
            this.displayInfo = displayInfo;

            this.Editor.Clear();

            if (!string.IsNullOrEmpty(displayInfo.Content))
            {
                this.Editor.AppendText(displayInfo.Content);
            }
            else if (File.Exists(displayInfo.FilePath))
            {
                this.Editor.AppendText(File.ReadAllText(displayInfo.FilePath));
            }

            this.queryEditor.DatabaseType = this.displayInfo.DatabaseType;

            if (displayInfo.ConnectionInfo != null && !string.IsNullOrEmpty(displayInfo.ConnectionInfo.Database))
            {
                this.SetupIntellisence();
            }
        }
Exemple #22
0
        public async void RunScripts(DatabaseObjectDisplayInfo data)
        {
            this.displayInfo = data;

            string script = this.Editor.SelectionLength > 0 ? this.Editor.SelectedText : this.Editor.Text;

            if (script.Trim().Length == 0)
            {
                return;
            }

            this.ClearResults();

            this.scriptRunner = new ScriptRunner();
            this.scriptRunner.Subscribe(this);

            if (this.CheckConnection())
            {
                QueryResult result = await scriptRunner.Run(data.DatabaseType, data.ConnectionInfo, script);

                this.ShowResult(result);
            }
        }
Exemple #23
0
        private void Save()
        {
            if (this.tabControl1.TabCount < 1)
            {
                return;
            }

            TabPage tabPage = this.tabControl1.SelectedTab;

            if (tabPage == null)
            {
                return;
            }

            DatabaseObjectDisplayInfo displayInfo = tabPage.Tag as DatabaseObjectDisplayInfo;

            if (displayInfo == null)
            {
                return;
            }

            DatabaseObjectDisplayType displayType = displayInfo.DisplayType;

            if (displayType == DatabaseObjectDisplayType.Script || displayType == DatabaseObjectDisplayType.Data)
            {
                if (File.Exists(displayInfo.FilePath))
                {
                    this.SaveToFile(tabPage, displayInfo.FilePath);
                    return;
                }

                if (this.dlgSave == null)
                {
                    this.dlgSave = new SaveFileDialog();
                }

                this.dlgSave.FileName = tabPage.Text.Trim();

                if (displayType == DatabaseObjectDisplayType.Script)
                {
                    this.dlgSave.Filter = "sql file|*.sql|txt file|*.txt";
                }
                else if (displayType == DatabaseObjectDisplayType.Data)
                {
                    this.dlgSave.Filter = "csv file|*.csv|txt file|*.txt";
                }

                DialogResult result = this.dlgSave.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string filePath = this.dlgSave.FileName;

                    this.SaveToFile(tabPage, filePath);

                    displayInfo.FilePath = filePath;

                    string name = Path.GetFileNameWithoutExtension(filePath);

                    displayInfo.IsNew = false;
                    displayInfo.Name  = name;

                    tabPage.Text = this.GetFormatTabHeaderText(name);

                    this.SetTabPageTooltip(tabPage);
                }
            }
            else if (displayType == DatabaseObjectDisplayType.TableDesigner)
            {
                UC_TableDesigner  tableDesigner = this.GetUcControl <UC_TableDesigner>(tabPage);
                ContentSaveResult result        = tableDesigner.Save(new ContentSaveInfo()
                {
                });

                if (result.IsOK)
                {
                    Table table = result.ResultData as Table;

                    displayInfo.IsNew = false;
                    displayInfo.Name  = table.Name;

                    tabPage.Text = this.GetFormatTabHeaderText(displayInfo.Name);

                    this.SetTabPageTooltip(tabPage);
                }
            }
        }
Exemple #24
0
 private void ShowDbObjectContent(DatabaseObjectDisplayInfo content)
 {
     this.ucContent.ShowContent(content);
 }
 public void Show(DatabaseObjectDisplayInfo displayInfo)
 {
     this.LoadData(displayInfo);
 }