private void tvDbObjects_ItemDrag(object sender, ItemDragEventArgs e) { if (e.Button == MouseButtons.Left) { TreeNode treeNode = e.Item as TreeNode; if (treeNode != null && treeNode.Tag is DatabaseObject) { string text = treeNode.Text; int index = text.IndexOf('('); if (index > 0) { text = text.Substring(0, index); } DbInterpreter dbInterpreter = this.GetDbInterpreter(this.GetDatabaseNode(treeNode).Name); string[] items = text.Trim().Split('.'); items[items.Length - 1] = dbInterpreter.GetQuotedString(items[items.Length - 1]); DoDragDrop(string.Join(".", items), DragDropEffects.Move); } } }
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; } }
protected virtual string GetTableColumnEmptySql(DbInterpreter interpreter, TableColumn column, bool isCount) { string tableName = $"{column.Owner}.{interpreter.GetQuotedString(column.TableName)}"; string selectColumn = isCount ? $"{this.GetStringNullFunction()}(COUNT(1),0) AS {interpreter.GetQuotedString("Count")}" : "*"; string sql = $"SELECT {selectColumn} FROM {tableName} WHERE {this.GetStringLengthFunction()}({interpreter.GetQuotedString(column.Name)})=0"; return(sql); }
protected virtual string GetTableColumnReferenceSql(DbInterpreter interpreter, TableForeignKey foreignKey, bool isCount) { string tableName = $"{foreignKey.Owner}.{interpreter.GetQuotedString(foreignKey.TableName)}"; string selectColumn = isCount ? $"{this.GetStringNullFunction()}(COUNT(1),0) AS {interpreter.GetQuotedString("Count")}" : "*"; string whereClause = string.Join(" AND ", foreignKey.Columns.Select(item => $"{interpreter.GetQuotedString(item.ColumnName)}={interpreter.GetQuotedString(item.ReferencedColumnName)}")); string sql = $"SELECT {selectColumn} FROM {tableName} WHERE ({whereClause})"; return(sql); }