private string HandlePatchesData(string applicationFilter) { string newIds = String.Empty; string category; string name; DataTable resultsDataTable = new DataTable(); AuditedItemsDAO lAuditedItemsDAO = new AuditedItemsDAO(); string af = applicationFilter; category = af.Substring(13, af.IndexOf("and _name") - 15); name = af.Substring(af.IndexOf("and _name") + 13, af.IndexOf("and _value") - (af.IndexOf("and _name = '") + 15)); resultsDataTable = lAuditedItemsDAO.GetCompliantAssetsIdsForPatch(category + "|" + name); foreach (DataRow compliantRow in resultsDataTable.Rows) { if (!newIds.Contains(compliantRow.ItemArray[0].ToString())) { newIds += compliantRow.ItemArray[0].ToString() + ","; } } return(newIds.TrimEnd(',')); }
/// <summary> /// Gets all available data values for the specifed HARDWARE field. In this case we need to know /// for each asset the value for the specified hardware or system field. /// </summary> /// <param name="reportColumn"></param> protected void GetHardwareFieldValues(AssetList cachedAssetList, AuditDataReportColumn reportColumn) { AuditedItemsDAO lwDataAccess = new AuditedItemsDAO(); // The field name held in the report column combines the field catagory and name with the name last // We need to split these for the purpose of passing to the database function int index = reportColumn.FieldName.LastIndexOf('|'); string category = reportColumn.FieldName.Substring(0, index); string name = reportColumn.FieldName.Substring(index + 1); // We need to get a list of values specified for this hardware field noting that we return ALL audited values // as we cannot filter by asset at this time. The data is therefore returned is the form AssetID / Value DataTable table = lwDataAccess.GetAuditedItemValues(null, category, name); // Move this data into a Dictionary to make it easier to access Dictionary <int, string> listFieldValues = new Dictionary <int, string>(); foreach (DataRow row in table.Rows) { int assetID = (int)row["_ASSETID"]; string value = (string)row["_VALUE"]; // Just in case we get duplicate values filter them out here if (!listFieldValues.ContainsKey(assetID)) { listFieldValues.Add(assetID, value); } } // Now loop through the Assets and determine which does have the application and which does not // We store the value 'Installed' or 'Not Installed' for the value for each asset foreach (Asset asset in cachedAssetList) { string value; // Do we have a value for this asset? If not store "<no value>" if (listFieldValues.ContainsKey(asset.AssetID)) { value = listFieldValues[asset.AssetID]; } else { value = AWMiscStrings.NoValueFound; } // Add the column to the result set reportColumn.Values.Add(new AuditDataReportColumnValue(value, asset.Name, asset.AssetID, asset.Location)); } }
/// <summary> /// Populate the Hardware node of the tree /// </summary> /// <param name="parentNode"></param> protected void PopulateSystemPatches(UltraTreeNode parentNode) { DataTable categoryTable = new AuditedItemsDAO().GetAuditedItemCategories(parentNode.Key); UltraTreeNode[] categoryNodes = new UltraTreeNode[categoryTable.Rows.Count]; UltraTreeNode categoryNode; for (int i = 0; i < categoryTable.Rows.Count; i++) { string category = (string)categoryTable.Rows[i]["_CATEGORY"]; categoryNode = new UltraTreeNode(category, category.Substring(category.LastIndexOf("|") + 1)); categoryNode.Tag = parentNode.Tag; categoryNodes[i] = categoryNode; } parentNode.Nodes.AddRange(categoryNodes); }
/// <summary> /// Expand the Children for a Hardware based field /// </summary> /// <param name="field"></param> /// <param name="returnDictionary"></param> protected void ExpandHardwareFieldChildren(string field) { AuditedItemsDAO lwDataAccess = new AuditedItemsDAO(); // Get the child CATEGORIES of this field (if any) DataTable categoryTable = lwDataAccess.GetAuditedItemCategories(field); // OK there were child CATEGORIES - recurse as we are only actually interested in VALUES beneath // the categories, not the categories themselves foreach (DataRow row in categoryTable.Rows) { string category = (string)row["_CATEGORY"]; ExpandHardwareFieldChildren(category); } // Now check for any NAMES within this category DataTable namesTable = lwDataAccess.GetAuditedItemCategoryNames(field); // Add any NAMES into the report foreach (DataRow row in namesTable.Rows) { string category = (string)row["_CATEGORY"]; string name = (string)row["_NAME"]; string icon = (string)row["_ICON"]; string fieldName = category + "|" + name; this.Add(new AuditDataReportColumn(AuditDataReportColumn.eFieldType.hardware , fieldName , GetLabelForField(fieldName))); } // If there were NO SUB-CATEGORIES and NO NAMES then simply add the field itself as it be a NAME // If we have no return data then just add the item itself to the dictionary if ((categoryTable.Rows.Count == 0) && (namesTable.Rows.Count == 0)) { this.Add(new AuditDataReportColumn(AuditDataReportColumn.eFieldType.hardware, field, GetLabelForField(field))); return; } }
//protected void PopulateSystemPatches(UltraTreeNode parentNode) //{ // AuditedItemsDAO lwDataAccess = new AuditedItemsDAO(); // DataTable categoryTable = lwDataAccess.GetAuditedItemCategories(parentNode.Key); // //UltraTreeNode[] categoryNodes = new UltraTreeNode[categoryTable.Rows.Count]; // // Iterate through the returned rows and add the text and icon to the tree // // All the returned items are categories // foreach (DataRow row in categoryTable.Rows) // { // string category = (string)row["_CATEGORY"]; // string icon = (string)row["_ICON"]; // UltraTreeNode categoryNode; // int index; // string nodeText = String.Empty; // // We display just the last portion of the category name as the node text // index = category.LastIndexOf("|"); // nodeText = category.Substring(index + 1); // // Add the category itself // categoryNode = new UltraTreeNode(category, nodeText); // categoryNode.Tag = parentNode.Tag; // categoryNode.LeftImages.Add(IconMapping.LoadIcon(icon, IconMapping.ICONSIZE.small)); // Trace.Write("Adding node " + category + " to tree node " + parentNode.Key + "\n"); // try // { // parentNode.Nodes.Add(categoryNode); // } // catch (Exception) // { // } // } //} /// <summary> /// Populate the Hardware node of the tree /// </summary> /// <param name="parentNode"></param> //protected void PopulateHardware(UltraTreeNode parentNode) //{ // AuditedItemsDAO lwDataAccess = new AuditedItemsDAO(); // DataTable categoryTable = lwDataAccess.GetAuditedItemCategories(parentNode.Key); // DataRow catRow; // UltraTreeNode categoryNode, nameNode; // int index; // string icon, nodeText, category, name, nameKey; // UltraTreeNode[] nodes = new UltraTreeNode[categoryTable.Rows.Count]; // parentNode.Nodes.Clear(); // // Iterate through the returned rows and add the text and icon to the tree // // All the returned items are categories // for (int i = 0; i < categoryTable.Rows.Count; i++) // { // catRow = categoryTable.Rows[i]; // category = (string)catRow["_CATEGORY"]; // //icon = (string)catRow["_ICON"]; // if (category.StartsWith("System|Patches|")) // { // string reducedCategory = category.Substring(0, category.LastIndexOf('|')); // index = reducedCategory.LastIndexOf("|"); // nodeText = reducedCategory.Substring(index + 1); // categoryNode = new UltraTreeNode(reducedCategory, nodeText); // categoryNode.Tag = parentNode.Tag; // //categoryNode.LeftImages.Add(IconMapping.LoadIcon(icon, IconMapping.ICONSIZE.small)); // try // { // parentNode.Nodes.Add(categoryNode); // // Recurse to check for child categories of the category we have just added // PopulateSystemPatches(categoryNode); // } // catch (Exception ex) // { // } // } // else // { // // We display just the last portion of the category name as the node text // index = category.LastIndexOf("|"); // nodeText = category.Substring(index + 1); // // Add the category itself // categoryNode = new UltraTreeNode(category, nodeText); // categoryNode.Tag = parentNode.Tag; // //categoryNode.LeftImages.Add(IconMapping.LoadIcon(icon, IconMapping.ICONSIZE.small)); // categoryNode.Override.ShowExpansionIndicator = ShowExpansionIndicator.CheckOnExpand; // nodes[i] = categoryNode; // } // } // parentNode.Nodes.AddRange(nodes); // // Now check for any NAMES within this category // DataTable namesTable = lwDataAccess.GetAuditedItemCategoryNames(parentNode.Key); // UltraTreeNode[] namesNodes = new UltraTreeNode[namesTable.Rows.Count]; // // Add any NAMES after the Categories // for (int j = 0; j < namesTable.Rows.Count; j++) // { // DataRow row = namesTable.Rows[j]; // category = (string)row["_CATEGORY"]; // name = (string)row["_NAME"]; // //icon = (string)row["_ICON"]; // // Add the NAME node // nameKey = category + "|" + name; // nameNode = new UltraTreeNode(nameKey, name); // nameNode.Tag = parentNode.Tag; // //nameNode.LeftImages.Add(IconMapping.LoadIcon(icon, IconMapping.ICONSIZE.small)); // nameNode.Override.NodeStyle = _valueNodeStyle; // namesNodes[j] = nameNode; // } // parentNode.Nodes.AddRange(namesNodes); // // If no sub-categories or Names then set the expansion indicator to none // if ((categoryTable.Rows.Count == 0) && (namesTable.Rows.Count == 0)) // parentNode.Override.ShowExpansionIndicator = ShowExpansionIndicator.Never; //} protected void PopulateHardware(UltraTreeNode parentNode) { AuditedItemsDAO lwDataAccess = new AuditedItemsDAO(); DataTable categoryTable = lwDataAccess.GetAuditedItemCategories(parentNode.Key); DataRow catRow; UltraTreeNode categoryNode, nameNode; UltraTreeNode[] nodes; int index; string nodeText, category, name, nameKey; //parentNode.Nodes.Clear(); if (parentNode.Key == "System|Patches") { for (int i = 0; i < categoryTable.Rows.Count; i++) { catRow = categoryTable.Rows[i]; category = (string)catRow["_CATEGORY"]; string reducedCategory = category.Substring(0, category.LastIndexOf('|')); index = reducedCategory.LastIndexOf("|"); nodeText = reducedCategory.Substring(index + 1); categoryNode = new UltraTreeNode(reducedCategory, nodeText); categoryNode.Tag = parentNode.Tag; categoryNode.Override.ShowExpansionIndicator = ShowExpansionIndicator.CheckOnExpand; if (fieldsTree.GetNodeByKey(reducedCategory) == null) { parentNode.Nodes.Add(categoryNode); } } } else { nodes = new UltraTreeNode[categoryTable.Rows.Count]; // Iterate through the returned rows and add the text and icon to the tree // All the returned items are categories for (int i = 0; i < categoryTable.Rows.Count; i++) { catRow = categoryTable.Rows[i]; category = (string)catRow["_CATEGORY"]; // We display just the last portion of the category name as the node text index = category.LastIndexOf("|"); nodeText = category.Substring(index + 1); // Add the category itself categoryNode = new UltraTreeNode(category, nodeText); categoryNode.Tag = parentNode.Tag; categoryNode.Override.ShowExpansionIndicator = ShowExpansionIndicator.CheckOnExpand; nodes[i] = categoryNode; } parentNode.Nodes.AddRange(nodes); } // Now check for any NAMES within this category - only need to do this if there were no categories DataTable namesTable = new DataTable(); if (categoryTable.Rows.Count == 0) { namesTable = lwDataAccess.GetAuditedItemCategoryNames(parentNode.Key); UltraTreeNode[] namesNodes = new UltraTreeNode[namesTable.Rows.Count]; // Add any NAMES after the Categories for (int j = 0; j < namesTable.Rows.Count; j++) { DataRow row = namesTable.Rows[j]; category = (string)row["_CATEGORY"]; name = (string)row["_NAME"]; // Add the NAME node nameKey = category + "|" + name; nameNode = new UltraTreeNode(nameKey, name); nameNode.Tag = parentNode.Tag; nameNode.Override.NodeStyle = _valueNodeStyle; namesNodes[j] = nameNode; } parentNode.Nodes.AddRange(namesNodes); } // If no sub-categories or Names then set the expansion indicator to none if ((categoryTable.Rows.Count == 0) && (namesTable.Rows.Count == 0)) { parentNode.Override.ShowExpansionIndicator = ShowExpansionIndicator.Never; } }