public DataTable CreateComplianceGrid(string complianceStatus, string _lastCompliantIds, List <string> _lastComplianceFilterConditions, string aAssetIds) { DataTable complianceDataTable = new DataTable(); string compliantIds = _lastCompliantIds; DataRow[] rows; AssetDAO lAssetDAO = new AssetDAO(); DataColumn myDataColumn; myDataColumn = new DataColumn(); myDataColumn.DataType = Type.GetType("System.String"); myDataColumn.ColumnName = "AssetName"; complianceDataTable.Columns.Add(myDataColumn); if (complianceStatus == "Non-Compliant") { // an empty lSelectedAssets means that all assets have been selected if (aAssetIds == "") { aAssetIds = new AssetDAO().GetAllAssetIdsAsString(); } StringBuilder sb = new StringBuilder(); DataTable nonCompliantIds = new AssetDAO().GetNonCompliantAssetIds(compliantIds, aAssetIds); foreach (DataRow compliantRow in nonCompliantIds.Rows) { sb.Append(compliantRow.ItemArray[0].ToString() + ","); } compliantIds = sb.ToString().TrimEnd(','); } if (compliantIds != "") { object[] lNewRowArray = new object[_lastComplianceFilterConditions.Count + 1]; string lCurrentReportCondition = ""; DataTable lUnionResultsDataTable = RunCustomUnionStatement(compliantIds, _lastComplianceFilterConditions); string t; int k = 1; foreach (string filterCondition in _lastComplianceFilterConditions) { t = filterCondition; myDataColumn = new DataColumn(); myDataColumn.DataType = Type.GetType("System.String"); myDataColumn.ColumnName = t.Substring(t.IndexOf("_name = ") + 9, t.IndexOf("and _value") - t.IndexOf("_name = ") - 11); while (complianceDataTable.Columns.Contains(myDataColumn.ColumnName)) { myDataColumn.ColumnName += "_" + k.ToString(); k++; } complianceDataTable.Columns.Add(myDataColumn); } DataTable lAssetNameDataTable = lAssetDAO.GetAssetNamesByIds(compliantIds); foreach (string lAssetId in compliantIds.Split(',')) { lNewRowArray[0] = lAssetNameDataTable.Select("_ASSETID = " + lAssetId)[0].ItemArray[1].ToString(); for (int i = 0; i < _lastComplianceFilterConditions.Count; i++) { lCurrentReportCondition = _lastComplianceFilterConditions[i]; lCurrentReportCondition = lCurrentReportCondition.Substring(lCurrentReportCondition.IndexOf("_category")); rows = lUnionResultsDataTable.Select(String.Format("ASSETID = {0} AND REFID = {1}", lAssetId, i)); // deal with applications differently if (lCurrentReportCondition.StartsWith("_category = 'Applications|")) { lNewRowArray[i + 1] = (rows.Length == 0) ? "Not Installed" : "Installed"; } else { lNewRowArray[i + 1] = (rows.Length == 0) ? "" : rows[0].ItemArray[1].ToString(); } } complianceDataTable.Rows.Add(lNewRowArray); } } return(complianceDataTable); }