public void LoadDefaultData(string applicationPath) { _appPath = applicationPath; string fileName = applicationPath + Path.DirectorySeparatorChar + _fileName; string defaultFileName = Application.StartupPath + Path.DirectorySeparatorChar + _defaultFileName; try { if (File.Exists(fileName)) { _instance.ReadXml(fileName); } //if QueriesTree does not exist in the windows user application data folder //load the default values from the application folder else if (File.Exists(defaultFileName)) { TDSQueriesTree t = new TDSQueriesTree(); t.ReadXml(defaultFileName); _instance.QueryTypes.Merge(t.QueryTypes); _instance.QueryParameters.Merge(t.QueryParameters); MyZillaSettingsDataSet settings = MyZillaSettingsDataSet.GetInstance(); TDSettings.ConnectionDataTable connections = settings.GetActiveConnections(); foreach (TDSettings.ConnectionRow connection in connections) { CatalogueManager catalogues = CatalogueManager.Instance(); if (catalogues.GetCataloguesForConnection(connection.ConnectionId) != null) { BuildTreeStructureForUserId(t, connection); } } } else { throw (new IOException("Default queries configuration [" + fileName + "] is missing!")); } } catch (IOException) { throw (new IOException("File " + fileName + " not exist.")); } }
public void AddUserSubtree(TreeView treeView, TDSettings.ConnectionRow connectionRow) { DataRow[] rows; TreeNode nodeUser; //find the node in the tree corresponding to the user-connection TreeNode[] nodesUser = treeView.Nodes.Find("User " + connectionRow.ConnectionId.ToString(), true); if (nodesUser.GetLength(0) == 1) { nodeUser = nodesUser[0]; //find all folders of the user and sort them on LevelID rows = _instance.Folders.Select("UserID = " + Int16.Parse(nodeUser.Name.Replace("User", String.Empty)).ToString(), "LevelID, Name, ID, ParentID"); TreeNode node = new TreeNode(); if (rows.GetLength(0) == 0) { nodeUser.ForeColor = System.Drawing.Color.Gray; } //check if product list changed on the server CatalogueManager catalogues = CatalogueManager.Instance(); NameValueCollection products = catalogues.GetCataloguesForConnection(connectionRow.ConnectionId).catalogueProduct; string productName = String.Empty; FoldersRow productsRootFolder = GetFolderByName(connectionRow, "Product Queries"); if (productsRootFolder == null) { productsRootFolder = CreateFolder(connectionRow, "Product Queries", 0, -1); } //check if local user xml still contains deleted products // if contains one, delete it for (int i = rows.GetLength(0) - 1; i >= 0; i--) { FoldersRow folder = (FoldersRow)rows[i]; if ((folder.ParentID == productsRootFolder.ID) && (products[folder.Name + "," + folder.Name] == null)) { folder.Delete(); } } //check if new product is missing from the local user structure for (int i = 0; i < products.Count; i++) { productName = products.GetKey(i).Split(',')[1]; FoldersRow productFolder = GetFolderByName(connectionRow, productName); if (productFolder == null) { CreateProductFolderDefaultQueries(connectionRow, productsRootFolder.ID, productName); } } rows = _instance.Folders.Select("UserID = " + Int16.Parse(nodeUser.Name.Replace("User", String.Empty)).ToString(), "LevelID, Name, ID, ParentID"); //add each folder(except deleted ones) as a TreeNode in the TreeView foreach (DataRow dr in rows) { FoldersRow folder = (FoldersRow)dr; //protect agains folders that do not have the Deleted tag (protect agains null value) try { folder.Deleted = folder.Deleted; } catch { folder.Deleted = false; } if (!folder.Deleted) { if (folder.ParentID == -1) { node = nodeUser.Nodes.Add("folder " + folder.ID.ToString(), folder.Name, "Folder"); } else { FoldersRow parentFolder = _instance.Folders.FindByID(folder.ParentID); if (parentFolder.Deleted) { folder.Deleted = true; } TreeNode[] nodes = nodeUser.Nodes.Find("folder " + folder.ParentID.ToString(), true); if (nodes.GetLength(0) == 1) { node = nodes[0].Nodes.Add("folder " + folder.ID.ToString(), folder.Name, "Folder"); } } if (!folder.Deleted) { node.SelectedImageKey = "Folder"; node.Tag = new NodeDescription(NodeType.Folder, folder); //add queries associated with the folder as tree nodes DataRow[] queries = _instance.Queries.Select("FolderId = " + folder.ID); foreach (DataRow query in queries) { QueriesRow queryRow = (QueriesRow)query; AddQueryToTreeNode(node, queryRow); } } } } } }
/// <summary> /// Checks for the predefined folder structure and build it together with the predefined queries /// </summary> /// <param name="Connection"></param> public static void RefreshTreePerUser(TDSettings.ConnectionRow connectionRow) { int parentID; DataRow[] folders; FoldersRow folder, productFolder; //Check for the default structure of folders and queries //Check for folder "Product Queries" folder = GetFolderByName(connectionRow, "Product Queries"); if (folder == null) { //create product queries folder folder = CreateFolder(connectionRow, "Product Queries", 0, -1); if (folder == null) { throw new Exception("Queries folder structure is corrupted!"); } } parentID = folder.ID; DataRow[] Queries; string productName = String.Empty; QueriesRow query; #region add each product as a folder in the tree CatalogueManager catalogues = CatalogueManager.Instance(); NameValueCollection products = catalogues.GetCataloguesForConnection(connectionRow.ConnectionId).catalogueProduct; folders = _instance.Folders.Select("ParentID = " + parentID.ToString() + " AND UserID = " + connectionRow.ConnectionId.ToString()); for (int i = folders.GetLength(0) - 1; i >= 0; i--) { productFolder = (FoldersRow)folders[i]; //check if product belongs to the current user bool belongsToCurrentUser = false; for (int index = 0; index < products.Count; index++) { if (folder.Name == products.GetKey(index).Split(',')[1]) { belongsToCurrentUser = true; break; } } if (!belongsToCurrentUser) { productFolder.Delete(); //folder.Delete(); } } //generate new product folders for (int i = 0; i < products.Count; i++) { productName = products.GetKey(i).Split(',')[1]; CreateProductFolderDefaultQueries(connectionRow, parentID, productName); } #endregion //Check for the default folder "My Queries" folder = GetFolderByName(connectionRow, "My Queries"); if (folder == null) { //think about throuwing error folder = CreateFolder(connectionRow, "My Queries", 0, -1); if (folder == null) { throw new Exception("Queries folder structure is corrupted!"); } } #region Check if exists predefined query My Opened BUGS Queries = _instance.Queries.Select("Name = 'My opened bugs' AND FolderID = " + folder.ID); if (Queries.GetLength(0) == 0) { query = _instance.Queries.NewQueriesRow(); query.Name = "My opened bugs"; query.Description = "All my opened bugs for any product"; query.FolderID = folder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForOpenedBugsQuery(String.Empty, true, connectionRow.UserName)); } #endregion #region Check if exists predefined query My Closed BUGS Queries = _instance.Queries.Select("Name = 'My closed bugs' AND FolderID = " + folder.ID); if (Queries.GetLength(0) == 0) { query = _instance.Queries.NewQueriesRow(); query.Name = "My closed bugs"; query.Description = "All my closed bugs for any product"; query.FolderID = folder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForClosedBugsQuery(String.Empty, true, connectionRow.UserName)); } #endregion #region Check if exists predefined query My Fixed BUGS Queries = _instance.Queries.Select("Name = 'My fixed bugs' AND FolderID = " + folder.ID); if (Queries.GetLength(0) == 0) { query = _instance.Queries.NewQueriesRow(); query.Name = "My fixed bugs"; query.Description = "All my fixed bugs for any product"; query.FolderID = folder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForFixedBugsQuery(String.Empty, true, connectionRow.UserName)); } #endregion //Update Tree with the default structure _instance.Folders.AcceptChanges(); _instance.Queries.AcceptChanges(); _instance.ParametersValues.AcceptChanges(); }