///<summary> /// We check if a ColumnName includes an "-" Character, /// if so, suround it with []</summary> ///<param name="SharpQueryNodeColumn">a ColumnNode</param> /// <returns>a valid ColumnName</returns> /* * private static string InferColumnName(string node) { * string colName; * if (node != null) { * if (node.IndexOf("-",StringComparison.Ordinal) > -1 ){ * // colName = node.Replace(".",".[") + "]"; * colName = "[" + node + "]"; * } else { * colName = node; * } * } else { * colName = String.Empty; * } * return colName; * } */ // check witch type of node we dragg private static NodeType CheckCurrentNode(IDatabaseObjectBase node) { NodeType enm; if (node is IColumn) { enm = NodeType.ColumnImage; } else if (node is ICSharpCode.Data.Core.Interfaces.ITable) { enm = NodeType.TableImage; } else if (node is IProcedure) { enm = NodeType.ProcedureImage; } else if (node is IView) { enm = NodeType.ViewImage; } else { enm = NodeType.NodeError; } return(enm); }
private void databasesTree_SelectedItemChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs <object> e) { if (e.NewValue is IDatabaseObjectBase) { IDatabase parentDatabase = e.NewValue as IDatabase; if (parentDatabase == null) { IDatabaseObjectBase currentDatabaseObject = e.NewValue as IDatabaseObjectBase; while (parentDatabase == null) { if (currentDatabaseObject.Parent == null) { break; } else if (currentDatabaseObject.Parent is IDatabase) { parentDatabase = currentDatabaseObject.Parent as IDatabase; break; } else { currentDatabaseObject = currentDatabaseObject.Parent; } } } if (parentDatabase != null) { this.currentNode = parentDatabase; } if (this.currentNode is IDatabase) { if (parentDatabase != null) { this.connectionString = "Provider=" + parentDatabase.Datasource.DatabaseDriver.ODBCProviderName + ";" + parentDatabase.ConnectionString; this.txtSqlString.Enabled = true; if (this.firstDrag) { this.txtSqlString.Text = string.Empty; } firstDrag = false; } } else { this.EnableNext = false; } } }
private void TxtSqlStringDragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if (firstDrag == true) { this.txtSqlString.Clear(); firstDrag = false; } // Drag and drop isn't working via e.Data.GetData, so I'm using reflection here - took me a lot of time to figure out how this works... // Still don't know why they implemented dnd so buggy and uncomfortable... string draggedFormat = e.Data.GetFormats()[0]; IDatabaseObjectBase draggedObject = null; if (e.Data.GetDataPresent(draggedFormat)) { object tempDraggedObject = null; FieldInfo info; info = e.Data.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance); tempDraggedObject = info.GetValue(e.Data); info = tempDraggedObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance); System.Windows.DataObject dataObject = info.GetValue(tempDraggedObject) as System.Windows.DataObject; draggedObject = dataObject.GetData(draggedFormat) as IDatabaseObjectBase; } switch (CheckCurrentNode(draggedObject)) { case NodeType.TableImage: // we insert Select * from.... otherwise we have to scan //the whole string for incorrect columnNames this.txtSqlString.Clear(); this.txtSqlString.Text = "SELECT * FROM " + (draggedObject as ICSharpCode.Data.Core.Interfaces.ITable).Name; reportStructure.CommandType = CommandType.Text; break; case NodeType.ColumnImage: string colName = (draggedObject as IColumn).Name; if (this.txtSqlString.Text.Length == 0) { this.txtSqlString.AppendText("SELECT "); this.txtSqlString.AppendText(colName); } else if (this.txtSqlString.Text.ToUpper(CultureInfo.InvariantCulture).IndexOf("where", StringComparison.OrdinalIgnoreCase) > 0) { this.txtSqlString.AppendText(colName + " = ?"); } else { this.txtSqlString.AppendText(", "); this.txtSqlString.AppendText(colName); } reportStructure.CommandType = CommandType.Text; break; case NodeType.ProcedureImage: this.txtSqlString.Clear(); // we can't use the dragobject because it returns an string like 'EXECUTE ProcName' IProcedure procedure = draggedObject as IProcedure; this.txtSqlString.Text = "EXECUTE " + procedure.Name; reportStructure.CommandType = CommandType.StoredProcedure; // reportStructure.SharpQueryProcedure = new SharpQueryProcedure(new SharpQuery.Connection.OLEDBConnectionWrapper(this.connectionString), procedure.Parent.Name, procedure.SchemaName, string.Empty, procedure.Name); break; case NodeType.ViewImage: this.txtSqlString.Text = String.Empty; this.txtSqlString.Text = "No idea how to handle views"; break; default: break; } base.EnableNext = true; }
// check witch type of node we dragg private static NodeType CheckCurrentNode (IDatabaseObjectBase node) { NodeType enm; if (node is IColumn) { enm = NodeType.ColumnImage; } else if (node is ITable) { enm = NodeType.TableImage; } else if (node is IProcedure) { enm = NodeType.ProcedureImage; } else if (node is IView) { enm = NodeType.ViewImage; } else { enm = NodeType.NodeError; } return enm; }
private void databasesTree_SelectedItemChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<object> e) { if (e.NewValue is IDatabaseObjectBase) { IDatabase parentDatabase = e.NewValue as IDatabase; if (parentDatabase == null) { IDatabaseObjectBase currentDatabaseObject = e.NewValue as IDatabaseObjectBase; while (parentDatabase == null) { if (currentDatabaseObject.Parent == null) break; else if (currentDatabaseObject.Parent is IDatabase) { parentDatabase = currentDatabaseObject.Parent as IDatabase; break; } else currentDatabaseObject = currentDatabaseObject.Parent; } } if (parentDatabase != null) this.currentNode = parentDatabase; if (this.currentNode is IDatabase) { if (parentDatabase != null) { this.connectionString = parentDatabase.ConnectionString; this.txtSqlString.Enabled = true; if (this.firstDrag) this.txtSqlString.Text = string.Empty; firstDrag = false; } } else { this.EnableNext = false; } } }
public DatabaseObjectsCollection(IDatabaseObjectBase parent) { _parent = parent; }