public void UpdateHelpText(ObjectGroupingItemData data) { if (ConnParams == null) { throw new NullPropertyException("Connection parameters is null!"); } if (data == null) { return; } using (SqlConnection conn = new SqlConnection(_connParams.ConnectionString)) { string cmdText = ResManager.GetDBScript("spPragmaSQL_ObjectGroup_UpdateDescription"); SqlCommand cmd = new SqlCommand(cmdText, conn); cmd.CommandTimeout = 0; AddParam(cmd, "@ObjectID", SqlDbType.Int, data.ID); AddParam(cmd, "@Description", SqlDbType.Text, data.HelpText); AddParam(cmd, "@DescriptionFormat", SqlDbType.VarChar, data.HelpTextFormat); AddParam(cmd, "@UpdatedBy", SqlDbType.VarChar, _connParams.CurrentUsername); conn.Open(); cmd.ExecuteNonQuery(); data.UpdatedBy = _connParams.CurrentUsername; } }
public bool CanOpenSelectedObjects( ) { bool result = false; if (tv.SelectedNodes.Count == 0) { return(result); } foreach (TreeNode node in tv.SelectedNodes) { ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node); if (data == null) { continue; } if (DBConstants.DoesObjectTypeHoldsData(data.Type ?? -1)) { result = true; break; } } return(result); }
public void SaveHelpText(bool confirmSave) { TreeNode selNode = SelectedNode; ObjectGroupingItemData selData = ObjectGroupingItemDataFactory.GetNodeData(SelectedNode); if (selData == null) { return; } if (confirmSave) { DialogResult dlgRes = MessageBox.Show("Save changes to help text?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgRes == DialogResult.No) { _helpTextChanged = false; return; } } selData.HelpText = CurrentHelpText; try { _grpFacade.UpdateHelpText(selData); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateSelectedItemInfo(); _helpTextChanged = false; }
public void AddItem(ObjectGroupingItemData data, string desc, string descFormat) { if (ConnParams == null) { throw new NullPropertyException("Connection parameters is null!"); } if (data == null) { throw new NullParameterException("Item data is null!"); } using (SqlConnection conn = new SqlConnection(_connParams.ConnectionString)) { string cmdText = ResManager.GetDBScript("spPragmaSQL_ObjectGroup_Insert"); SqlCommand cmd = new SqlCommand(cmdText, conn); cmd.CommandTimeout = 0; AddParam(cmd, "@ParentID", SqlDbType.Int, data.ParentID); AddParam(cmd, "@Name", SqlDbType.VarChar, data.Name); AddParam(cmd, "@ParentObjName", SqlDbType.VarChar, data.ParentObjectName); AddParam(cmd, "@Description", SqlDbType.Text, desc); AddParam(cmd, "@DescriptionFormat", SqlDbType.VarChar, descFormat); AddParam(cmd, "@ObjType", SqlDbType.Int, data.Type); AddParam(cmd, "@CreatedBy", SqlDbType.VarChar, _connParams.CurrentUsername); SqlParameter param = cmd.Parameters.Add("@ObjectID", System.Data.SqlDbType.Int); param.Direction = System.Data.ParameterDirection.Output; conn.Open(); cmd.ExecuteNonQuery(); data.ID = (int?)param.Value; } }
private TreeNode AddNode(TreeNode parentNode, ObjectGroupingItemData data) { if (data == null) { return(null); } TreeNodeCollection parentCol = null; if (parentNode != null) { parentCol = parentNode.Nodes; } else { parentCol = tv.Nodes; } TreeNode result = parentCol.Add(data.Name); if (!data.DbObjectMissing) { result.ImageIndex = data.Type ?? -1; } else { result.ImageIndex = DBObjectType.Error; } result.SelectedImageIndex = result.ImageIndex; result.Tag = data; return(result); }
private void AddObjectToGroup() { TreeNode selNode = og.SelectedNode; if (selNode == null) { ShowError("Please select an object grouping folder!"); return; } ObjectGroupingItemData selData = ObjectGroupingItemDataFactory.GetNodeData(selNode); if (selData.Type != DBObjectType.GroupingFolderY) { ShowError("Please select an object grouping folder!"); return; } try { og.AddObjectToGroup(_objInfo, selNode, true); } catch (Exception ex) { GenericErrorDialog.ShowError("Object Grouping Error", "Object can not be added to the selected group folder.", ex.Message); } this.DialogResult = DialogResult.OK; }
private void DeleteItem(TreeNode node) { ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node); if (node == null || data == null) { return; } try { tv.BeginUpdate(); _grpFacade.DeleteItem(data); node.Nodes.Clear(); TreeNodeCollection parentNodeCol = null; if (node.Parent == null) { parentNodeCol = tv.Nodes; } else { parentNodeCol = node.Parent.Nodes; } parentNodeCol.Remove(node); } finally { tv.EndUpdate(); } }
public void AddItem(ObjectGroupingItemData data, string desc, string descFormat) { if (ConnParams == null) { throw new NullPropertyException("Connection parameters is null!"); } using (SqlConnection conn = new SqlConnection(_connParams.ConnectionString)) { string cmdText = global::PragmaSQL.Scripts.Properties.Resources.spPragmaSQL_ObjectGroup_Insert; SqlCommand cmd = new SqlCommand(cmdText, conn); cmd.Parameters.AddWithValue("@ParentID", data.ParentID); cmd.Parameters.AddWithValue("@Name", data.Name); cmd.Parameters.AddWithValue("@TableName", data.TableName); cmd.Parameters.AddWithValue("@Description", desc); cmd.Parameters.AddWithValue("@DescriptionFormat", descFormat); cmd.Parameters.AddWithValue("@ObjType", data.Type); cmd.Parameters.AddWithValue("@CreatedBy", data.CreatedBy); SqlParameter param = cmd.Parameters.Add("@ObjectID", System.Data.SqlDbType.Int); param.Direction = System.Data.ParameterDirection.Output; conn.Open(); cmd.ExecuteNonQuery(); data.ID = (int?)param.Value; } }
public void DeleteItem(ObjectGroupingItemData data) { if (data == null) { return; } DeleteItem(data.ID); }
public void DeleteItem(ObjectGroupingItemData data) { if (data == null) { throw new NullParameterException("Item data is null!"); } DeleteItem(data.ID); }
public IList <ObjectGroupingItemData> GetChildren(int?parentID) { if (ConnParams == null) { throw new NullPropertyException("Connection parameters is null!"); } IList <ObjectGroupingItemData> result = new List <ObjectGroupingItemData>(); using (SqlConnection conn = new SqlConnection(_connParams.ConnectionString)) { string cmdText = ResManager.GetDBScript("spPragmaSQL_ObjectGroup_List"); SqlCommand cmd = new SqlCommand(cmdText, conn); cmd.CommandTimeout = 0; AddParam(cmd, "@ParentID", System.Data.SqlDbType.Int, parentID); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); string name = String.Empty; int? type = null; int? id = null; string parentObjName = String.Empty; string createdBy = String.Empty; string updatedBy = String.Empty; string helpText = String.Empty; string helpTextFormat = String.Empty; ObjectGroupingItemData data = null; try { while (reader.Read()) { name = reader["Name"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Name"]; type = reader["ObjType"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjType"]; id = reader["ObjectID"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjectID"]; parentObjName = reader["ParentObjName"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["ParentObjName"]; createdBy = reader["CreatedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["CreatedBy"]; updatedBy = reader["UpdatedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["UpdatedBy"]; helpText = reader["Description"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Description"]; helpTextFormat = reader["DescriptionFormat"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["DescriptionFormat"]; data = ObjectGroupingItemDataFactory.Create(name, type, id, parentObjName, parentID, createdBy); data.HelpText = helpText; data.HelpTextFormat = helpTextFormat; data.UpdatedBy = updatedBy; result.Add(data); } } finally { reader.Close(); } } return(result); }
public static ObjectGroupingItemData Create(string name, int?type, int?id, string parentObjectName, int?parentID, string createdBy) { ObjectGroupingItemData result = new ObjectGroupingItemData(type); result.Name = name; result.ID = id; result.ParentObjectName = parentObjectName; result.ParentID = parentID; result.CreatedBy = createdBy; return(result); }
private void LoadHelpText(TreeNode node) { ObjectGroupingItemData nodeData = ObjectGroupingItemDataFactory.GetNodeData(node); if (nodeData == null) { CurrentHelpText = String.Empty; _helpTextChanged = false; HelpTextVisible = false; lblHelpText.Text = "Help Text {?}"; return; } _isInitializing = true; _rtbHelpText.RichTextBox.Rtf = nodeData.HelpText; _isInitializing = false; }
public ObjectGroupingItemData CreateCopy( ) { ObjectGroupingItemData result = new ObjectGroupingItemData(this.Type); result.Name = this.Name; result.Populated = this.Populated; result.ID = this.ID; result.ParentID = this.ParentID; result.ParentObjectName = this.ParentObjectName; result.CreatedBy = this.CreatedBy; result.UpdatedBy = this.UpdatedBy; result.HelpText = this.HelpText; result.HelpTextFormat = this.HelpTextFormat; return(result); }
public IList <ObjectGroupingItemData> GetChildItemsOf(int?parentID) { if (ConnParams == null) { throw new NullPropertyException("Connection parameters is null!"); } IList <ObjectGroupingItemData> result = new List <ObjectGroupingItemData>(); using (SqlConnection conn = new SqlConnection(_connParams.ConnectionString)) { string cmdText = global::PragmaSQL.Scripts.Properties.Resources.spPragmaSQL_ObjectGroup_List; SqlCommand cmd = new SqlCommand(cmdText, conn); cmd.Parameters.Add("@ParentID", System.Data.SqlDbType.Int); cmd.Parameters["@ParentID"].Value = parentID; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); string name = String.Empty; int? type = null; int? id = null; string tableName = String.Empty; string createdBy = String.Empty; ObjectGroupingItemData data = null; try { while (reader.Read()) { name = reader["Name"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Name"]; type = reader["ObjType"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjType"]; id = reader["ObjectID"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjectID"]; tableName = reader["TableName"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["TableName"]; createdBy = reader["CreatedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["CreatedBy"]; data = ObjectGroupingItemDataFactory.Create(name, type, id, tableName, parentID, createdBy); result.Add(data); } } finally { reader.Close(); } } return(result); }
public void AddFolder(TreeNode parentNode) { string name = String.Empty; int? parentID = null; ObjectGroupingItemData parentData = ObjectGroupingItemDataFactory.GetNodeData(parentNode); if (parentData != null) { parentID = parentData.ID; } DialogResult dlgRes = InputDialog.ShowDialog("New Folder", "Folder Name", ref name); if (dlgRes != DialogResult.OK || String.IsNullOrEmpty(name)) { return; } try { tv.BeginUpdate(); ObjectGroupingItemData newFolderData = ObjectGroupingItemDataFactory.Create(name, DBObjectType.GroupingFolderY, null, String.Empty, parentID, _connParams.CurrentUsername); newFolderData.ParentID = parentID; try { _grpFacade.AddItem(newFolderData); TreeNode newFolder = AddNode(parentNode, newFolderData); AddEmptyNode(newFolder); if (parentNode != null && !parentNode.IsExpanded) { parentNode.Expand(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { UpdateSelectedItemInfo(); tv.EndUpdate(); } }
private void AddNodesToSelectedObjectGroup() { TreeNode selNode = og.SelectedNode; if (selNode == null) { ShowError("Please select an object grouping folder!"); return; } ObjectGroupingItemData selData = ObjectGroupingItemDataFactory.GetNodeData(selNode); if (selData.Type != DBObjectType.GroupingFolderY) { ShowError("Please select an object grouping folder!"); return; } StringBuilder sb = new StringBuilder(); foreach (TreeNode node in _nodes) { try { if (_isImport) { og.ImportObject(node, selNode, true); } else { og.AddObjectFromObjectExplorer(node, selNode, true); } } catch (Exception ex) { sb.AppendLine("-> " + ex.Message); } } if (sb.Length > 0) { GenericErrorDialog.ShowError("Object Grouping Error", "Some objects can not be added to selected group folder.", sb.ToString()); } this.DialogResult = DialogResult.OK; }
public void OpenSelectedObjects( ) { string error = String.Empty; IList <frmDataViewer> viewers = new List <frmDataViewer>(); foreach (TreeNode node in tv.SelectedNodes) { ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node); if (data == null) { continue; } ObjectInfo objInfo = ProgrammabilityHelper.GetObjectInfo(_connParams, String.Empty, data.Name); if (objInfo == null) { error += " - " + data.Name + "\r\n"; continue; } if (!DBConstants.DoesObjectTypeHoldsData(data.Type ?? -1)) { continue; } string caption = data.Name + "{" + cmbDatabases.Text + " on " + cmbServers.Text + "}"; string script = " select * from [" + data.Name + "]"; bool isReadOnly = (data.Type == DBObjectType.View) ? true : false; frmDataViewer viewer = DataViewerFactory.CreateDataViewer(_connParams, cmbDatabases.Text, data.Name, caption, script, isReadOnly, false); viewers.Add(viewer); } foreach (frmDataViewer viewer in viewers) { viewer.LoadData(true); DataViewerFactory.ShowDataViewer(viewer); } if (!String.IsNullOrEmpty(error)) { MessageService.ShowError("Objects listed below do not exist in the database!\r\n" + error); } }
private void UpdateSelectedItemInfo( ) { ObjectGroupingItemData data = SelectedNodeData; if (data == null) { lblItemName.Text = String.Empty; lblCreatedBy.Text = String.Empty; lblUpdatedBy.Text = String.Empty; lblHelpText.Text = "Help Text {?}"; } else { lblItemName.Text = "Item Name: " + data.Name; lblCreatedBy.Text = "Created By: " + data.CreatedBy; lblUpdatedBy.Text = "Updated By: " + data.UpdatedBy; lblHelpText.Text = "Help Text {" + data.Name + "}"; } }
public void RenameItem( ) { string name = String.Empty; string prevName = String.Empty; ObjectGroupingItemData selNodeData = SelectedNodeData; TreeNode selNode = SelectedNode; if (selNode == null || selNodeData == null) { return; } try { name = selNodeData.Name; prevName = name; DialogResult dlgRes = InputDialog.ShowDialog("Rename Folder", "Folder Name", ref name); if (dlgRes != DialogResult.OK || String.IsNullOrEmpty(name)) { return; } tv.BeginUpdate(); try { selNodeData.Name = name; _grpFacade.UpdateItem(selNodeData); selNode.Text = name; } catch (Exception ex) { selNodeData.Name = prevName; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { UpdateSelectedItemInfo(); tv.EndUpdate(); } }
public void ModifySelectedObjects( ) { string error = String.Empty; IList <frmScriptEditor> editors = new List <frmScriptEditor>(); foreach (TreeNode node in tv.SelectedNodes) { ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node); if (data == null) { continue; } ObjectInfo objInfo = ProgrammabilityHelper.GetObjectInfo(_connParams, String.Empty, data.Name); if (objInfo == null) { error += " - " + data.Name + "\r\n"; continue; } if (!DBConstants.DoesObjectTypeHasScript(data.Type ?? -1)) { continue; } string script = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objInfo.ObjectID, objInfo.ObjectType); frmScriptEditor editor = ScriptEditorFactory.Create(objInfo.ObjectName, script, objInfo.ObjectID, objInfo.ObjectType, _connParams, cmbDatabases.Text); editors.Add(editor); } foreach (frmScriptEditor editor in editors) { ScriptEditorFactory.ShowScriptEditor(editor); } if (!String.IsNullOrEmpty(error)) { MessageService.ShowError("Objects listed below do not exist in the database!\r\n" + error); } }
public void LoadChildren(TreeNode node, bool forceRefresh) { ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node); if (data == null) { return; } if ((data.Populated && !forceRefresh) || data.Type != DBObjectType.GroupingFolderY) { return; } try { tv.BeginUpdate(); TreeNode childNode = null; node.Nodes.Clear(); IList <ObjectGroupingItemData> children = _grpFacade.GetChildren(data.ID); foreach (ObjectGroupingItemData childData in children) { childNode = AddNode(node, childData); data.Populated = true; if (childData.Type == DBObjectType.GroupingFolderY) { AddEmptyNode(childNode); } } } finally { UpdateSelectedItemInfo(); tv.EndUpdate(); } }
public bool CanPerformFolderOnlyAction( ) { ObjectGroupingItemData data = SelectedNodeData; return(data != null && (data.Type == DBObjectType.GroupingFolderY)); }
private void tv_DragOver(object sender, DragEventArgs e) { Hashtable sourceNodes = e.Data.GetData(typeof(Hashtable)) as Hashtable; if (sourceNodes == null || sourceNodes.Count == 0) { e.Effect = DragDropEffects.None; return; } TreeNode firstNode = null; foreach (TreeNode node in sourceNodes.Values) { firstNode = node; if (firstNode != null) { break; } } if (firstNode == null) { e.Effect = DragDropEffects.None; return; } Point pos = new Point(); pos.X = e.X; pos.Y = e.Y; pos = tv.PointToClient(pos); TreeNode dropNode = tv.GetNodeAt(pos); if (dropNode == null) { e.Effect = DragDropEffects.None; return; } // This is an object from ObjectExplorer if (firstNode.Tag is NodeData) { foreach (TreeNode node in sourceNodes.Values) { NodeData sourceData = NodeDataFactory.GetNodeData(node); if (sourceData == null || sourceData.ConnParams == null || _connParams == null) { e.Effect = DragDropEffects.None; return; } if ( (sourceData.ConnParams.Server.ToLowerInvariant() != _connParams.Server.ToLowerInvariant()) || (sourceData.DBName.ToLowerInvariant() != _connParams.Database.ToLowerInvariant()) ) { e.Effect = DragDropEffects.None; return; } } e.Effect = DragDropEffects.Copy; } // This is a node from own MWTreeView else if (firstNode.Tag is ObjectGroupingItemData) { ObjectGroupingItemData dropData = ObjectGroupingItemDataFactory.GetNodeData(dropNode); ObjectGroupingItemData firstNodeData = ObjectGroupingItemDataFactory.GetNodeData(firstNode); if (dropData == null || (firstNodeData.ID == dropData.ParentID || firstNodeData.ID == dropData.ID)) { e.Effect = DragDropEffects.None; return; } if (dropData == null || dropData.Type != DBObjectType.GroupingFolderY) { e.Effect = DragDropEffects.None; return; } e.Effect = DragDropEffects.Move; } // Unknown else { e.Effect = DragDropEffects.None; } }
private void tv_DragDrop(object sender, DragEventArgs e) { Hashtable sourceNodes = e.Data.GetData(typeof(Hashtable)) as Hashtable; if (sourceNodes == null || sourceNodes.Count == 0) { e.Effect = DragDropEffects.None; return; } TreeNode firstNode = null; foreach (TreeNode node in sourceNodes.Values) { firstNode = node; if (firstNode != null) { break; } } if (firstNode == null) { e.Effect = DragDropEffects.None; return; } Point pos = new Point(); pos.X = e.X; pos.Y = e.Y; pos = tv.PointToClient(pos); TreeNode dropNode = tv.GetNodeAt(pos); if (firstNode.Tag is NodeData) { foreach (TreeNode node in sourceNodes.Values) { AddObjectFromObjectExplorer(node, dropNode); } e.Effect = DragDropEffects.Copy; tv.SelectedNodes.Clear(); } // This is a node from own MWTreeView else if (firstNode.Tag is ObjectGroupingItemData) { ObjectGroupingItemData dropData = ObjectGroupingItemDataFactory.GetNodeData(dropNode); ObjectGroupingItemData firstNodeData = ObjectGroupingItemDataFactory.GetNodeData(firstNode); if (dropData != null && firstNodeData != null) { List <string> parents = _grpFacade.GetAllParents(dropData.ID.Value); if (parents != null && parents.Contains(firstNodeData.ID.ToString())) { MessageBox.Show(String.Format("Source node '{0}' is parent of the target node '{1}'!", firstNodeData.Name, dropData.Name), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } e.Effect = DragDropEffects.Move; foreach (TreeNode node in sourceNodes.Values) { ChangeNodeParent(node, dropNode); } tv.SelectedNodes.Clear(); } }
public void AddItem(ObjectGroupingItemData data) { AddItem(data, String.Empty, String.Empty); }
public void AddObjectFromObjectExplorer(TreeNode source, TreeNode dropNode) { if (source == null) { return; } NodeData sourceData = NodeDataFactory.GetNodeData(source); if (sourceData == null) { return; } try { tv.BeginUpdate(); ObjectGroupingItemData dropData = ObjectGroupingItemDataFactory.GetNodeData(dropNode); int? parentID = null; TreeNode parentNode = null; if (dropNode != null && dropData != null) { if (dropData.Type == DBObjectType.GroupingFolderY) { parentID = dropData.ID; parentNode = dropNode; } else { parentID = dropData.ParentID; parentNode = dropNode.Parent; } } string tableName = String.Empty; if (sourceData.Type == DBObjectType.Trigger) { tableName = sourceData.ParentName; } ObjectGroupingItemData data = ObjectGroupingItemDataFactory.Create(sourceData.Name, sourceData.Type, null, tableName, parentID, _connParams.CurrentUsername); try { _grpFacade.AddItem(data); AddNode(parentNode, data); if (parentNode != null && !parentNode.IsExpanded) { parentNode.Expand(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { tv.EndUpdate(); UpdateSelectedItemInfo(); } }
public void ChangeNodeParent(TreeNode source, TreeNode dropNode) { if (source == null) { return; } ObjectGroupingItemData sourceData = ObjectGroupingItemDataFactory.GetNodeData(source); if (sourceData == null) { return; } try { int? parentID = null; TreeNode parentNode = null; ObjectGroupingItemData dropData = ObjectGroupingItemDataFactory.GetNodeData(dropNode); if (dropNode != null && dropData != null) { parentID = dropData.ID; parentNode = dropNode; } tv.BeginUpdate(); try { sourceData.ParentID = parentID; _grpFacade.UpdateItem(sourceData); if (source.Parent != null) { source.Parent.Nodes.Remove(source); } else { tv.Nodes.Remove(source); } if (parentNode != null) { parentNode.Nodes.Add(source); if (!parentNode.IsExpanded) { parentNode.Expand(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { tv.EndUpdate(); } }