Exemple #1
0
        /// <summary>
        /// Add a new asset to the database (or possibly update an existing item)
        /// </summary>
        /// <param name="updateAsset"></param>
        /// <returns></returns>
        public int Add()
        {
            AssetDAO lwDataAccess = new AssetDAO();

            if (AssetID == 0)
            {
                _assetID = lwDataAccess.AssetAdd(this);

                // only add audit trail if the assetID is not 0 (i.e. we added one)
                if (_assetID != 0)
                {
                    // ...and log this event in the audit trail
                    AuditTrailEntry ate = new AuditTrailEntry();
                    ate.Date      = DateTime.Now;
                    ate.Class     = AuditTrailEntry.CLASS.asset;
                    ate.Type      = AuditTrailEntry.TYPE.added;
                    ate.Key       = _name;
                    ate.AssetID   = _assetID;
                    ate.AssetName = _name;
                    ate.Username  = System.Environment.UserName;
                    new AuditTrailDAO().AuditTrailAdd(ate);

                    NewsFeed.AddNewsItem(NewsFeed.Priority.Information, "Added new asset to database (" + this.Name + ")");
                }
            }
            else
            {
                lwDataAccess.AssetUpdate(this);
            }
            return(0);
        }
Exemple #2
0
        /// <summary>
        /// Load all of the Child Assets for this asset
        /// </summary>
        /// <returns>Count of items added to the list</returns>
        public int PopulateChildAssets()
        {
            AssetDAO lwDataAccess = new AssetDAO();

            _childAssets = new AssetList(lwDataAccess.EnumerateChildAssets(AssetID), false);
            return(_childAssets.Count);
        }
Exemple #3
0
        public void Init()
        {
            _assetDAO = new AssetDAO();
            _asset    = new Asset();

            _asset.Name          = "test asset";
            _asset.AgentStatus   = Asset.AGENTSTATUS.deployed;
            _asset.AgentVersion  = "agent version 1";
            _asset.AlertsEnabled = false;
            _asset.AssetTag      = "asset tag";
            _asset.AssetTypeID   = 2;
            _asset.Auditable     = true;
            _asset.Domain        = "test";
            _asset.DomainID      = 1;
            _asset.FullLocation  = "full location";
            _asset.IPAddress     = "1.2.3.4";
            _asset.LastAudit     = DateTime.Now.AddDays(-1);
            _asset.Location      = "location";
            _asset.LocationID    = 1;
            _asset.MACAddress    = "00:11:22:33";
            _asset.Make          = "make";
            _asset.Model         = "model";
            _asset.OverwriteData = true;
            _asset.ParentAssetID = 1;
            _asset.RequestAudit  = false;
            _asset.SerialNumber  = "AB12345";
            _asset.StockStatus   = Asset.STOCKSTATUS.inuse;
            _asset.SupplierID    = 1;
            _asset.SupplierName  = "supplier";
            _asset.TypeAsString  = "Computer";
            _asset.UniqueID      = "ABCDE12345";
        }
Exemple #4
0
        /// <summary>
        /// Called to perform a 'Deploy Agent' Operation on the specified PC
        /// </summary>
        /// <param name="operationThread"></param>
        protected bool DeployAgent(OperationThreadData operationThread, Asset.AGENTSTATUS assetStatus)
        {
            // This is the status of the operation
            bool success = true;

            // This is the text which we shall display for the operation
            string message = "Success";

            // Get the operation to be performed
            Operation operation = operationThread.ActiveOperation;

            try
            {
                // Get the Agent Service Controller passing it the name of the computer
                AuditAgentServiceController agentServiceController = new AuditAgentServiceController(operation.AssetName);

                // Use it to get the current status of the asset

                // If already started, flag this
                if (assetStatus == Asset.AGENTSTATUS.Running)
                {
                    message = "The AuditWizard Agent Service is already running";
                }

                else
                {
                    // If the agent has not been deployed to this computer previously then do so now
                    if (assetStatus == Asset.AGENTSTATUS.notdeployed)
                    {
                        // Install the Agent Service (throws an exception on error)
                        agentServiceController.Install();
                        assetStatus = Asset.AGENTSTATUS.deployed;
                        AssetDAO lwDataAccess = new AssetDAO();
                        lwDataAccess.AssetUpdateAssetStatus(operation.AssetID, assetStatus);
                    }

                    // If the status is now deployed then we can start the Agent
                    if (assetStatus == Asset.AGENTSTATUS.deployed)
                    {
                        // Start the agent (throws an exception on error)
                        agentServiceController.Start();
                    }
                }
            }

            catch (Exception e)
            {
                success = false;
                message = "Error: An Exception occurred while Deploying the AuditAgent, the error text was " + e.Message;
            }

            // Update the Operation object with the overall status and completion message
            operation.Status    = (success) ? Operation.STATUS.complete_success : Operation.STATUS.complete_error;
            operation.ErrorText = message;

            // Return now
            return(success);
        }
        public void RecieveInvestment(Company investor, MySqlConnection connection)
        {
            Balance += investor.Investment;
            Asset a = new Asset(1, investor.Investment, DateTime.Now, Id);

            AssetDAO.InsertAssets(connection, new List <Asset> {
                a
            });
        }
        public void RecieveCredit(Company bank, MySqlConnection connection)
        {
            Balance += bank.Investment;
            Asset a = new Asset(1, bank.Investment, DateTime.Now, Id);

            AssetDAO.InsertAssets(connection, new List <Asset> {
                a
            });
        }
        //5 types of enterprise creation -
        //private assets, investment, bank credit, private assets+investment, private assets+bank credit
        public void CreateEnterpriseWithPrivateAssets(decimal personal, MySqlConnection connection)
        {
            Balance = personal;
            Asset a = new Asset(1, personal, DateTime.Now, Id);

            AssetDAO.InsertAssets(connection, new List <Asset> {
                a
            });
        }
        private void bnCreateSchedule_Click(object sender, EventArgs e)
        {
            DateTime    dt              = DateTime.Now;
            Appointment rootAppt        = new Appointment(dt, dt);
            string      lReportCategory = comboBoxReportCategory.Text;
            string      lReportName     = comboBoxReportName.Text;

            if (lReportCategory == "Custom" || lReportCategory == "Compliance" || lReportCategory == "User-Defined SQL")
            {
                rootAppt.Description = comboBoxReportName.SelectedValue.ToString();
            }

            rootAppt.Subject = String.Format("{0} Report | {1}", lReportCategory, lReportName);
            rootAppt.Subject = (cmbPublishers.Visible) ? rootAppt.Subject + " | " + cmbPublishers.Text : rootAppt.Subject;

            // an empty lSelectedAssets means that all assets have been selected
            if (_selectedAssetIds == "")
            {
                DataTable lAllAssetDataTable = new AssetDAO().GetAllAssetIds();
                foreach (DataRow assetRow in lAllAssetDataTable.Rows)
                {
                    _selectedAssetIds += assetRow[0].ToString() + ",";
                }

                _selectedAssetIds = _selectedAssetIds.TrimEnd(',');
            }

            rootAppt.Location   = _selectedAssetIds;
            rootAppt.Recurrence = DefineReportRecurrence(rootAppt);

            if (rootAppt.Recurrence != null)
            {
                if (rootAppt.Recurrence.OccurrenceStartTime < DateTime.Now)
                {
                    DateTime lDateTime = rootAppt.Recurrence.OccurrenceStartTime;

                    if (lDateTime.Minute == 59)
                    {
                        rootAppt.Recurrence.OccurrenceStartTime =
                            new DateTime(lDateTime.Year, lDateTime.Month, lDateTime.Day, lDateTime.Hour + 1, 0, 0);
                    }
                    else
                    {
                        rootAppt.Recurrence.OccurrenceStartTime =
                            new DateTime(lDateTime.Year, lDateTime.Month, lDateTime.Day, lDateTime.Hour, lDateTime.Minute + 1, 0);
                    }
                }

                new ReportSchedulesDAO().Insert(rootAppt.Save());
                PopulateGrid();
            }
        }
Exemple #9
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Do you want to delete the Support Contract?", "AuditWizard", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         AssetDAO objAsseDAO = new AssetDAO();
         objAsseDAO.DeleteSupportContract(_asset.AssetID);
         checkBoxSupportContract.Checked = false;
         ClearControlsSupportContract();
         FillSupportContractComboBox();
         FillSuppliersComboBox();
         MessageBox.Show("Support Contract Successfully Deleted", "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.panelSupportExpired.Visible = false;
     }
 }
Exemple #10
0
        private bool GetSupportContractDetails(string strAssetName)
        {
            int iAssetID = new AssetDAO().AssetIDByAssetName(strAssetName);

            if (iAssetID > 0)
            {
                m_objSupportContract.AssetID = iAssetID;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #11
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            AssetDAO objAsseDAO = new AssetDAO();
            SelectedNodesCollection objSelectednode = tree.SelectedNodes;

            if (buttonOK.Text == "Apply" && bApply == true)
            {
                int iCount = objSelectednode.Count;
                for (int i = 0; i < iCount; i++)
                {
                    string strTag = objSelectednode[i].Tag.ToString();
                    if (GetSupportContractDetails(strTag))
                    {
                        objAsseDAO.AddSupportContract(m_objSupportContract);
                    }
                }
                tree.SelectedNodes.Clear();
                ClearControlsSupportContract();
                FillControlsOnLoad();
                FillSupportContractComboBox();
                FillSuppliersComboBox();
                checkBoxSupportContract.Checked = false;
                InitialiseSupportContractTab();
                MessageBox.Show("Support Contract Successfully Added for the Selected Assets.", "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Information);
                buttonOK.Text = "OK";
                bApply        = false;
            }

            else if (MessageBox.Show("Do you wish to Deploy Support Contract to other Assets?\nTo deploy, highlight required assets in Network View using Ctrl key", "AuditWizard", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                buttonOK.Text = "Apply";
                bApply        = true;
                GetSupportContractDetails();
            }
            else
            {
                if (GetSupportContractDetails())
                {
                    objAsseDAO.AddSupportContract(m_objSupportContract);

                    ClearControlsSupportContract();
                    FillControlsOnLoad();
                    FillSupportContractComboBox();
                    FillSuppliersComboBox();
                    checkBoxSupportContract.Checked = false;
                    InitialiseSupportContractTab();
                }
                MessageBox.Show("Support Contract Successfully Added", "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Add a user defined data field and its value.
        ///
        /// First locate the specified asset (or create a new one if this does not exist)
        /// Locate the user defined data field (or create a new one if this does not exist)
        /// Set the value for the field given its ID and asset
        ///
        /// </summary>
        /// <param name="lvi"></param>
        private void AddUserDataField(UltraListViewItem lvi)
        {
            AssetDAO lwDataAccess = new AssetDAO();

            // Recover the data fields
            string assetName = lvi.Text;
            string category  = lvi.SubItems[2].Text;

            if (category == "Asset Data")
            {
                category = "General";
            }
            string fieldName  = lvi.SubItems[0].Text;
            string fieldValue = lvi.SubItems[1].Text;

            // Does the Asset exist?
            // Note that as we only have an asset name we can only possibly match on that
            int assetID = lwDataAccess.AssetFind(assetName);

            // If the asset exists then add the history record for it
            if (assetID != 0)
            {
                // Does the User Data Category exist?  If not create it also
                UserDataCategory parentCategory = _listCategories.FindCategory(category);
                if (parentCategory == null)
                {
                    parentCategory      = new UserDataCategory(UserDataCategory.SCOPE.Asset);
                    parentCategory.Name = category;
                    parentCategory.Add();
                    _listCategories.Add(parentCategory);
                }


                // Now look at the User Data Field and see if we have one already with this name
                UserDataField thisField = parentCategory.FindField(fieldName);
                if (thisField == null)
                {
                    // No existing field of this name in the General Category so add it
                    thisField          = new UserDataField();
                    thisField.ParentID = parentCategory.CategoryID;
                    thisField.Name     = fieldName;
                    thisField.Add();
                    parentCategory.Add(thisField);
                }

                // ...and set the value for the asset both here and in the database
                thisField.SetValueFor(assetID, fieldValue, true);
            }
        }
Exemple #13
0
        public int Update(Asset oldAsset)
        {
            AssetDAO lwDataAccess = new AssetDAO();

            if (this._assetID == 0)
            {
                return(Add());
            }
            else
            {
                lwDataAccess.AssetUpdate(this);
                AuditChanges(oldAsset);
            }
            return(0);
        }
Exemple #14
0
        /// <summary>
        /// This function is responsible for generating the actual data which will be displayed by the report
        /// </summary>
        protected void GenerateReportData()
        {
            // Create a string representation of the publisher filter list passed to us
            // We need to get the entire licensing information at this point
            FileSystemDAO lwDataAccess = new FileSystemDAO();
            DataTable     dataTable    = lwDataAccess.EnumerateFileSystemFiles(_filterFile);

            // Create a string representation of the publisher filter list passed to us
            // We need to get the entire licensing information at this point
            AssetGroup.GROUPTYPE displayType        = AssetGroup.GROUPTYPE.userlocation;
            DataTable            table              = new LocationsDAO().GetGroups(new AssetGroup(displayType));
            AssetGroup           _cachedAssetGroups = new AssetGroup(table.Rows[0], displayType);

            _cachedAssetGroups.Populate(true, _ignoreChildAssets, true);

            // Now apply the filter to these groups
            _cachedAssetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets);

            // Now that we have a definitive list of the assets (as objects) which we want to include in the
            // report we could really do with expanding this list so that ALL of the assets are in a single list
            // and not distributed among the publishers
            //AssetList _cachedAssetList = _cachedAssetGroups.GetAllAssets();
            //_selectedAssets = String.Empty;

            //foreach (Asset asset in _cachedAssetList)
            //{
            //    _selectedAssets += asset.Name + ";";
            //}

            //char[] charsToTrim = { ';' };
            //_selectedAssets.TrimEnd(charsToTrim);

            _selectedAssets = new AssetDAO().ConvertIdListToNames(new AssetDAO().GetSelectedAssets(), ',');

            ResetSelectedAssets();

            // ...then create InternetReportEntry objects for each returned and add to the view
            foreach (DataRow row in dataTable.Rows)
            {
                FileSystemFile file = new FileSystemFile(row);

                // Check for this being filtered by location/asset
                if (FilterRecord(file))
                {
                    AddRecord(file);
                }
            }
        }
Exemple #15
0
        public void UpdateStockStatus(STOCKSTATUS newStockStatus)
        {
            // Ignore if no change actually made
            if (newStockStatus == _stockStatus)
            {
                return;
            }

            AssetDAO lwDataAccess = new AssetDAO();

            // Audit the status change
            Asset oldAsset = new Asset(this);

            // Update the object and the database
            _stockStatus = newStockStatus;
            lwDataAccess.AssetUpdateStockStatus(_assetID, newStockStatus);

            // ...then audit the change
            AuditChanges(oldAsset);
        }
    void AssetTest(MySqlConnection connection)
    {
        List <Asset> assets = new List <Asset>();

        assets.Add(new Asset(2, 5, new DateTime(2014, 09, 25), 1));

        AssetDAO.InsertAssets(connection, assets);

        List <Asset> assets2 = AssetDAO.GetAssets(connection);

        assets2[1].Value = 888;

        AssetDAO.UpdateAssets(connection, assets2);

        assets2 = AssetDAO.GetAssets(connection);

        AssetDAO.DeleteAssets(connection, assets);

        assets2 = AssetDAO.GetAssets(connection);
    }
Exemple #17
0
        /// <summary>
        /// Called to return and update the current status of the specified (named) asset
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="assetStatus"></param>
        /// <param name="message"></param>
        protected int UpdateCurrentAgentStatus(string assetName, int assetID, out Asset.AGENTSTATUS assetStatus, out string message)
        {
            // Get the Agent Service Controller passing it the name of the computer
            AuditAgentServiceController agentServiceController = new AuditAgentServiceController(assetName);

            // Use it to get the current status of the asset
            LaytonServiceController.ServiceStatus serviceStatus = agentServiceController.CheckStatus();
            assetStatus = Asset.AGENTSTATUS.notdeployed;

            switch (serviceStatus)
            {
            case LaytonServiceController.ServiceStatus.Running:
                assetStatus = Asset.AGENTSTATUS.Running;
                break;

            case LaytonServiceController.ServiceStatus.Stopped:
                assetStatus = Asset.AGENTSTATUS.deployed;
                break;

            case LaytonServiceController.ServiceStatus.NotInstalled:
                assetStatus = Asset.AGENTSTATUS.notdeployed;
                break;

            case LaytonServiceController.ServiceStatus.UnableToConnect:
                message = "Error: Could not connect to remote computer, please check that it is turned on";
                return(-1);

            default:
                message = "Error: An Invalid or Unknown Status was returned";
                return(-1);
            }

            // Update the status of the computer in the database if we were successful
            message = Asset.TranslateDeploymentStatus(assetStatus);
            AssetDAO lwDataAccess = new AssetDAO();

            lwDataAccess.AssetUpdateAssetStatus(assetID, assetStatus);

            return(0);
        }
        private void Form_Load(object sender, EventArgs e)
        {
            // Don't populate the control in design mode
            if (DesignMode)
            {
                return;
            }

            // basic settings
            tbAlertMonitorName.Text = _alertDefinition.Name;
            tbAlertDescription.Text = _alertDefinition.Description;
            cbEmailAlert.Checked    = _alertDefinition.EmailAlert;

            // trigger settings
            selectedFields.AfterSelect += new AfterSelectEventHandler(selectedFields_AfterSelect);

            foreach (AlertTrigger trigger in _alertDefinition.Triggers)
            {
                AddTriggerToList(trigger);
            }

            // CMD 8.4.1
            // select computers settings - note that we opt to display root level assets but not lower level as these
            // shgould only be populated as and when required
            selectLocationsControl.Populate(true, false, true);

            // get the ID of the asset first - selectLocationsControl.RestoreSelections requires an ID
            List <string> monitoredComputers = new List <string>();
            AssetDAO      lAssetDao          = new AssetDAO();

            foreach (string monitoredComputer in _alertDefinition.MonitoredComputers)
            {
                monitoredComputers.Add(lAssetDao.ConvertNameListToIds(monitoredComputer));
            }

            if (_alertDefinition.MonitoredComputers.Count > 0)
            {
                selectLocationsControl.RestoreSelections("", Utility.ListToString(monitoredComputers, ','));
            }
        }
Exemple #19
0
        private void AddAsset()
        {
            AssetDAO lwDataAccess = new AssetDAO();

            _asset.Name = this.tbAssetName.Text;

            // Set the asset type
            AssetType assetType = cbAssetType.Value as AssetType;

            _asset.AssetTypeID = assetType.AssetTypeID;

            // Do we have a name for the asset and is it unique?
            if ((_asset.Name == "") || (lwDataAccess.AssetFind(_asset) != 0))
            {
                MessageBox.Show("You must specify a unique name for this asset", "Invalid Asset Name");
                this.DialogResult = DialogResult.None;
                return;
            }

            // OK - unique asset so create it
            _asset.AssetID = _asset.Add();
        }
Exemple #20
0
        /// <summary>
        /// Delete this asset from the database
        /// </summary>
        /// <returns></returns>
        public int Delete()
        {
            AuditTrailDAO lwDataAccess = new AuditTrailDAO();

            // ...and audit the deletion
            AuditTrailEntry ate = new AuditTrailEntry();

            ate.Date      = DateTime.Now;
            ate.Class     = AuditTrailEntry.CLASS.asset;
            ate.Type      = AuditTrailEntry.TYPE.deleted;
            ate.Key       = _name;
            ate.AssetID   = 0;
            ate.AssetName = "";
            ate.Username  = System.Environment.UserName;
            lwDataAccess.AuditTrailAdd(ate);

            // Delete the asset
            AssetDAO lAssetDAO = new AssetDAO();

            lAssetDAO.AssetDelete(this);
            return(0);
        }
Exemple #21
0
        private void backgroundWorker_ImportHistoryLine(string[] fields)
        {
            // Does the Asset exist?
            Asset newAsset = new Asset();

            newAsset.Name = fields[0];
            //
            AssetDAO lwDataAccess = new AssetDAO();

            newAsset.AssetID = lwDataAccess.AssetFind(newAsset);

            // If the asset exists then add the history record for it
            if (newAsset.AssetID != 0)
            {
                // Create an Audit Trail Entry record based on the data passed in to us.
                try
                {
                    AuditTrailDAO auditTrailDAO = new AuditTrailDAO();

                    AuditTrailEntry ate = new AuditTrailEntry();
                    //ate.Date = DateTime.ParseExact(fields[1], "yyyy-MM-dd HH:mm:ss", null);
                    ate.Date      = Convert.ToDateTime(fields[1]);
                    ate.Class     = AuditTrailEntry.CLASS.asset;
                    ate.AssetID   = newAsset.AssetID;
                    ate.AssetName = newAsset.Name;
                    ate.Type      = AuditTrailEntry.TranslateV7Type((AuditTrailEntry.V7_HIST_OPS)Convert.ToInt32(fields[2]));
                    ate.Key       = fields[3];
                    ate.OldValue  = fields[4];
                    ate.NewValue  = fields[5];
                    ate.Username  = fields[6];
                    auditTrailDAO.AuditTrailAdd(ate);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }
        }
Exemple #22
0
        /// <summary>
        /// Update the License Statistics
        /// </summary>
        private void UpdateLicenseStatistics()
        {
            // Recover the total license count from the product key
            Layton.Cab.Interface.LaytonProductKey key = WorkItem.RootWorkItem.Items[Layton.Cab.Interface.MiscStrings.ProductKey] as Layton.Cab.Interface.LaytonProductKey;
            int licenseCount = (key.IsTrial) ? 10 : key.AssetCount;

            UltraExplorerBarGroup licenses = overviewExplorerBar.Groups["licensing"];

            if (licenses == null)
            {
                return;
            }

            // Set this in the explorer bar
            licenses.Items["licensecount"].Text = StatisticTitles.LicensedFor + licenseCount.ToString();

            // Now we need a count of the 'licensable' assets within the database - this is the number of assets
            // which have been audited excluding child assets and any which have been flagged as 'disposed of'
            AssetDAO awDataAccess = new AssetDAO();
            int      licensesUsed = awDataAccess.LicensedAssetCount();

            licenses.Items["licensesused"].Text = StatisticTitles.LicensesUsed + licensesUsed.ToString();
        }
Exemple #23
0
        private void PopulateAssetApplicationMatches(string aSearchText, string aGroupIdList)
        {
            DataTable lDataTable = new AssetDAO().FindAssetByApplicationName(aSearchText, aGroupIdList);

            PopulateResultsListView(lDataTable, "Installed Applications");
        }
Exemple #24
0
        public DataTable GetAssetAuditHistoryForReport()
        {
            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in");
            }

            DataTable ateTable = new DataTable(TableNames.AUDITTRAIL);

            string commandText =
                "SELECT AUDITTRAIL.* ,ASSETS._NAME AS ASSETNAME ,LOCATIONS._FULLNAME AS FULLLOCATIONNAME " +
                "FROM AUDITTRAIL " +
                "LEFT JOIN ASSETS ON (AUDITTRAIL._ASSETID = ASSETS._ASSETID) " +
                "LEFT JOIN LOCATIONS ON (ASSETS._LOCATIONID = LOCATIONS._LOCATIONID) " +
                "WHERE _CLASS <= 3 " +
                "AND AUDITTRAIL._ASSETID <> 0 ";

            string lAssetIds = new AssetDAO().GetSelectedAssets();

            if (lAssetIds != "")
            {
                commandText += "AND ASSETS._ASSETID IN  (" + lAssetIds + ") ";
            }

            commandText += "ORDER BY _AUDITTRAILID";

            try
            {
                if (compactDatabaseType)
                {
                    using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection())
                    {
                        using (SqlCeCommand command = new SqlCeCommand(commandText, conn))
                        {
                            new SqlCeDataAdapter(command).Fill(ateTable);
                        }
                    }
                }
                else
                {
                    using (SqlConnection conn = DatabaseConnection.CreateOpenStandardConnection())
                    {
                        using (SqlCommand command = new SqlCommand(commandText, conn))
                        {
                            new SqlDataAdapter(command).Fill(ateTable);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                Utility.DisplayErrorMessage("A database error has occurred in AuditWizard." + Environment.NewLine + Environment.NewLine +
                                            "Please see the log file for further details.");
                logger.Error("Exception in " + System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
            }
            catch (SqlCeException ex)
            {
                Utility.DisplayErrorMessage("A database error has occurred in AuditWizard." + Environment.NewLine + Environment.NewLine +
                                            "Please see the log file for further details.");
                logger.Error("Exception in " + System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
            }
            catch (Exception ex)
            {
                Utility.DisplayErrorMessage("A database error has occurred in AuditWizard." + Environment.NewLine + Environment.NewLine +
                                            "Please see the log file for further details.");

                logger.Error("Exception in " + System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
            }

            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out");
            }
            return(ateTable);
        }
Exemple #25
0
        private string HandleAssetDetailsData(string assetFilter)
        {
            string        assetValue;
            string        assetCriteria;
            DataTable     resultsDataTable   = new DataTable();
            AssetDAO      lAssetDAO          = new AssetDAO();
            AssetTypesDAO lAssetTypesDAO     = new AssetTypesDAO();
            LocationsDAO  lLocationsDAO      = new LocationsDAO();
            string        newIds             = String.Empty;
            string        complianceCriteria = String.Empty;

            //foreach (string assetFilter in applicationFilters)
            //{
            assetCriteria = assetFilter.Substring(41, assetFilter.IndexOf("and _value") - 43);

            switch (assetCriteria)
            {
            case "Asset Name":
                complianceCriteria = "_name";
                break;

            case "Location":
                complianceCriteria = "_locationid";
                break;

            case "Date of last Audit":
                complianceCriteria = "_lastaudit";
                break;

            case "IP Address":
                complianceCriteria = "_ipaddress";
                break;

            case "MAC Address":
                complianceCriteria = "_macaddress";
                break;

            case "Make":
                complianceCriteria = "_make";
                break;

            case "Model":
                complianceCriteria = "_model";
                break;

            case "Serial Number":
                complianceCriteria = "_serial_number";
                break;

            case "Category":
                complianceCriteria = "_category";
                break;

            case "Type":
                complianceCriteria = "_type";
                break;

            case "Asset Tag":
                complianceCriteria = "_assettag";
                break;
            }

            if (complianceCriteria == "_category")
            {
                assetValue       = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                resultsDataTable = lAssetTypesDAO.GetCompliantAssetCategoriesValue(assetValue);
            }
            else if (complianceCriteria == "_type")
            {
                assetValue       = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                resultsDataTable = lAssetTypesDAO.GetCompliantAssetTypesValue(assetValue);
            }
            else if (complianceCriteria == "_locationid")
            {
                assetValue       = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                resultsDataTable = lLocationsDAO.GetCompliantLocationValues(assetValue);
            }
            else if (complianceCriteria == "_lastaudit")
            {
                if (assetFilter.IndexOf("and _value") != -1)
                {
                    resultsDataTable =
                        lAssetDAO.GetCompliantAssetValueForLastAudit(assetFilter.Substring(assetFilter.IndexOf("and _value") + 11));
                }
            }
            else
            {
                assetValue = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                //resultsDataTable = lAssetDAO.GetCompliantAssetValue(complianceCriteria, assetValue, compliantIds);
                resultsDataTable = lAssetDAO.GetCompliantAssetValue(complianceCriteria, assetValue);
            }

            foreach (DataRow compliantRow in resultsDataTable.Rows)
            {
                if (!newIds.Contains(compliantRow.ItemArray[0].ToString()))
                {
                    newIds += compliantRow.ItemArray[0].ToString() + ",";
                }
            }

            newIds = newIds.TrimEnd(',');
            return(newIds);
        }
Exemple #26
0
        private string GetCompliantAssetIds(List <string> aReportConditions, string aAssetIds)
        {
            DataTable resultsTable = new DataTable();
            string    lReturnedIds = "";

            try
            {
                // an empty lSelectedAssets means that all assets have been selected
                if (aAssetIds == "")
                {
                    aAssetIds = new AssetDAO().GetAllAssetIdsAsString();
                }

                string lBooleanCondition = "";
                string lFilterCondition  = "";
                string lSQLString        = "SELECT _ASSETID FROM ASSETS WHERE (";

                // the user could have picked any of the audited categories
                // parse each filter condition and find the data
                foreach (string filterCondition in aReportConditions)
                {
                    string otherCompliantIds = "";

                    if (!filterCondition.StartsWith("1ST"))
                    {
                        lBooleanCondition = filterCondition.Substring(0, filterCondition.IndexOf("_category"));
                        lSQLString       += (lBooleanCondition == "And") ? ") " + lBooleanCondition + " (" : lBooleanCondition + " ";
                    }

                    lFilterCondition = filterCondition.Substring(filterCondition.IndexOf("_category"));

                    // APPLICATIONS
                    if (lFilterCondition.StartsWith("_category = 'Applications|"))
                    {
                        otherCompliantIds = HandleApplications(lFilterCondition, aAssetIds);
                    }
                    // USER-DEFINED DATA
                    else if (lFilterCondition.StartsWith("_category = 'UserData|"))
                    {
                        otherCompliantIds = HandleUserData(lFilterCondition);
                    }
                    // ASSET DETAILS
                    else if (lFilterCondition.StartsWith("_category = 'Asset Details'"))
                    {
                        otherCompliantIds = HandleAssetDetailsData(lFilterCondition);
                    }
                    // OPERATING SYSTEMS
                    else if (lFilterCondition.StartsWith("_category = 'Operating Systems'"))
                    {
                        otherCompliantIds = HandleOSData(lFilterCondition);
                    }
                    // SYSTEM PATCHES
                    else if (lFilterCondition.StartsWith("_category = 'System|Patches|"))
                    {
                        otherCompliantIds = HandlePatchesData(lFilterCondition);
                    }
                    // AUDITEDITEMS
                    else
                    {
                        otherCompliantIds = HandleAuditedItemsData(lFilterCondition);
                    }

                    otherCompliantIds = (otherCompliantIds == "") ? "''" : otherCompliantIds;
                    lSQLString       += String.Format("_ASSETID IN ({0}) ", otherCompliantIds);
                }

                lSQLString = lSQLString.Trim();

                // if we have only included Or statements we'll need to add a trailing bracket here
                if (CountOccurencesOfChar(lSQLString, '(') > CountOccurencesOfChar(lSQLString, ')'))
                {
                    lSQLString += ")";
                }

                lSQLString += String.Format(" AND _ASSETID IN ({0})", aAssetIds);

                DataTable lDataTable = new StatisticsDAO().PerformQuery(lSQLString);


                foreach (DataRow compliantRow in lDataTable.Rows)
                {
                    if (!lReturnedIds.Contains(compliantRow.ItemArray[0].ToString()))
                    {
                        lReturnedIds += compliantRow.ItemArray[0].ToString() + ",";
                    }
                }

                lReturnedIds = lReturnedIds.TrimEnd(',');
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }

            return(lReturnedIds);
        }
Exemple #27
0
        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);
        }
Exemple #28
0
        private DataTable ReportDataDrilldown(string aRowLabel)
        {
            DataTable     reportDataSet  = new DataTable();
            StatisticsDAO lStatisticsDAO = new StatisticsDAO();

            string reportName = "";

            if (aRowLabel.StartsWith("Compliance : "))
            {
                reportName = aRowLabel.Substring(13);
            }
            else if (aRowLabel.StartsWith("Installations for : "))
            {
                reportName = aRowLabel.Substring(20);
            }
            else
            {
                reportName  = aRowLabel.Substring(0, aRowLabel.IndexOf(":"));
                reportName += ": ";
            }

            switch (reportName)
            {
            case StatisticTitles.ComputersDiscovered:
                reportDataSet = lStatisticsDAO.ComputersDiscovered();
                break;

            case StatisticTitles.ComputersAudited:
                reportDataSet = lStatisticsDAO.ComputersAudited();
                break;

            case StatisticTitles.ComputerLastAudit:
                reportDataSet = lStatisticsDAO.ComputerLastAudit();
                break;

            case StatisticTitles.AssetsInStock:
                reportDataSet = lStatisticsDAO.AssetsInStock();
                break;

            case StatisticTitles.AssetsInUse:
                reportDataSet = lStatisticsDAO.AssetsInUse();
                break;

            case StatisticTitles.AssetsPending:
                reportDataSet = lStatisticsDAO.AssetsPending();
                break;

            case StatisticTitles.AssetsDisposed:
                reportDataSet = lStatisticsDAO.AssetsDisposed();
                break;

            case StatisticTitles.AgentsDeployed:
                reportDataSet = lStatisticsDAO.AgentsDeployed();
                break;

            case StatisticTitles.UniqueApplications:
                reportDataSet = lStatisticsDAO.UniqueApplications();
                break;

            case StatisticTitles.TotalApplications:
                reportDataSet = lStatisticsDAO.TotalApplications();
                break;

            case StatisticTitles.AuditedToday:
                reportDataSet = lStatisticsDAO.AuditedToday();
                break;

            case StatisticTitles.NotAudited7:
                reportDataSet = lStatisticsDAO.NotAudited7();
                break;

            case StatisticTitles.NotAudited14:
                reportDataSet = lStatisticsDAO.NotAudited14();
                break;

            case StatisticTitles.NotAudited30:
                reportDataSet = lStatisticsDAO.NotAudited30();
                break;

            case StatisticTitles.NotAudited90:
                reportDataSet = lStatisticsDAO.NotAudited90();
                break;

            case StatisticTitles.NotAudited:
                reportDataSet = lStatisticsDAO.NotAudited();
                break;

            case StatisticTitles.LastAlert:
                reportDataSet = lStatisticsDAO.LastAlert();
                break;

            case StatisticTitles.OutstandingAlerts:
                reportDataSet = lStatisticsDAO.StatisticsAssetsStatusDrilldown(aRowLabel);
                break;

            case StatisticTitles.AlertsToday:
                reportDataSet = lStatisticsDAO.AlertsToday();
                break;

            case StatisticTitles.AlertsThisWeek:
                reportDataSet = lStatisticsDAO.AlertsThisWeek();
                break;

            case StatisticTitles.AlertsThisMonth:
                reportDataSet = lStatisticsDAO.AlertsThisMonth();
                break;

            case StatisticTitles.SupportExpired:
                reportDataSet = lStatisticsDAO.SupportExpired();
                break;

            case StatisticTitles.SupportExpireToday:
                reportDataSet = lStatisticsDAO.SupportExpireToday();
                break;

            case StatisticTitles.SupportExpireThisWeek:
                reportDataSet = lStatisticsDAO.SupportExpireThisWeek();
                break;

            case StatisticTitles.SupportExpireThisMonth:
                reportDataSet = lStatisticsDAO.SupportExpireThisMonth();
                break;

            case StatisticTitles.SupportExpiredAsset:
                reportDataSet = lStatisticsDAO.SupportExpiredAsset();
                break;

            case StatisticTitles.SupportExpireTodayAsset:
                reportDataSet = lStatisticsDAO.SupportExpireTodayAsset();
                break;

            case StatisticTitles.SupportExpireThisWeekAsset:
                reportDataSet = lStatisticsDAO.SupportExpireThisWeekAsset();
                break;

            case StatisticTitles.SupportExpireThisMonthAsset:
                reportDataSet = lStatisticsDAO.SupportExpireThisMonthAsset();
                break;

            case "Compliant":
            case "Non-Compliant":
            case "Ignored":
            case "Not Defined":
                reportDataSet = lStatisticsDAO.StatisticsComplianceDrilldown(reportName);
                break;

            default:
                AssetDAO lAssetDAO        = new AssetDAO();
                string   lVersion         = (reportName.EndsWith(")")) ? reportName.Substring(reportName.LastIndexOf('(') + 2).TrimEnd(')') : "";
                string   lApplicationName = (lVersion == "") ? reportName : reportName.Substring(0, reportName.LastIndexOf(" ("));
                //reportDataSet = lAssetDAO.FindAssetByApplicationNameAndVersion(lApplicationName, lVersion, lAssetDAO.GetAllAssetIdsAsString());

                // CMD 8.4.2.3 - Why pass in all asset IDS???  A null string is better from what I can see
                reportDataSet = lAssetDAO.FindAssetByApplicationNameAndVersion(lApplicationName, lVersion, "");
                break;
            }

            return(reportDataSet);
        }
Exemple #29
0
        /// <summary>
        /// Update the configuration for ALL deployed AuditAgents
        /// </summary>
        public void ScannerUpdate()
        {
            // Get the list of computers which currently have the AuditAgent deployed (running or not)
            AssetDAO  lwDataAccess = new AssetDAO();
            AssetList listAssets   = new AssetList(lwDataAccess.EnumerateDeployedAssets(), true);

            //if (listAssets.Count == 0)
            //{
            //    MessageBox.Show("Found no assets which already have an AuditAgent deployed.", "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}

            FormLoadScannerConfiguration form = new FormLoadScannerConfiguration(true, "Select a configuration file to update all assets.");

            if (form.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // Use the Deserialize method to restore the object's state.
                    //auditScannerDefinition = AuditWizardSerialization.DeserializeObject(form.FileName);

                    string agentIniFileName = Path.Combine(AuditAgentStrings.AuditAgentFilesPath, AuditAgentStrings.AuditAgentIni);
                    File.Copy(form.FileName, agentIniFileName, true);
                }
                catch (System.IO.FileNotFoundException)
                {
                    MessageBox.Show("An error has occurred whilst updating the AuditAgent, please see the log file for further information.",
                                    "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // JML TODO log this exception
                    return;
                }
                catch (System.IO.IOException)
                {
                    MessageBox.Show("An error has occurred whilst updating the AuditAgent, please see the log file for further information.",
                                    "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // JML TODO log this exception
                    return;
                }
                catch
                {
                    MessageBox.Show("An error has occurred whilst updating the AuditAgent, please see the log file for further information.",
                                    "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // JML TODO log this exception
                    return;
                }
            }
            else
            {
                return;
            }

            // Ensure that we at least have a data path
            //if (auditScannerDefinition.DeployPathData == "")
            //{
            //    MessageBox.Show("The audit scanner configuration has not been configured yet", "Audit Scanner Configuration Not Defined");
            //    return;
            //}

            // Write the Agent Ini File to the Agent folder as this will combine the scanner configuration
            // with data taken from the Application Definitions File (publisher mappings etc)
            //string agentIniFileName = Path.Combine(AuditAgentStrings.AuditAgentFilesPath, AuditAgentStrings.AuditAgentIni);
            //if (auditScannerDefinition.WriteTo(agentIniFileName) != 0)
            //{
            //    MessageBox.Show("Error : Failed to write the AuditAgent configuration file", "Deploy Error");
            //    return;
            //}

            // We will pend the operation by adding it to the Operations queue in the database
            // The AuditWizard service works on this queue
            foreach (Asset asset in listAssets)
            {
                Operation newOperation = new Operation(asset.AssetID, Operation.OPERATION.updateconfiguration);
                newOperation.Add();
            }

            MessageBox.Show("The AuditAgent Update Request has been queued for " + listAssets.Count.ToString() + " PC(s) and will be actioned by the AuditWizard Service\n\nYou can check its progress by viewing the Operations Log", "Operations Queued", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #30
0
        public DataTable CreateDataTableForCustomReport(List <string> aReportConditions, string aAssetIds)
        {
            DataTable lResultsDataTable = new DataTable();
            bool      bPatchesIncluded  = false;

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                bool lDisplayAsAssetRegister = false;

                // aReportConditions contains a list of all criteria and a list of required assets
                // loop through each asset and get the data for each column
                // need to build a DataTable with the required columns
                string lDisplayResultsAsAssetRegister = "";

                foreach (string lReportCondition in aReportConditions)
                {
                    if (lDisplayResultsAsAssetRegister == "")
                    {
                        if (lReportCondition.StartsWith("ASSET_REGISTER:"))
                        {
                            lDisplayResultsAsAssetRegister = lReportCondition;
                            break;
                        }
                    }
                }

                // an empty lSelectedAssets means that all assets have been selected
                if (aAssetIds == "")
                {
                    aAssetIds = new AssetDAO().GetAllAssetIdsAsString();
                }

                if (lDisplayResultsAsAssetRegister != "")
                {
                    lDisplayAsAssetRegister = Convert.ToBoolean(lDisplayResultsAsAssetRegister.Substring(15));
                }

                // if all children of a parent node are selected, we will only see the parent here
                // i.e. Hardware|CPU means we have selected all children of that root
                // we need to loop through each of the fields now to handle this case

                _updatedReportConditions.Clear();

                foreach (string lReportCondition in aReportConditions)
                {
                    List <string> listParts = Utility.ListFromString(lReportCondition, '|', true);

                    switch (listParts[0])
                    {
                    case AWMiscStrings.AssetDetails:
                        ExpandAssetDetailFieldChildren(lReportCondition);
                        break;

                    case AWMiscStrings.OSNode:
                        ExpandOSFieldChildren(lReportCondition);
                        break;

                    case AWMiscStrings.ApplicationsNode:
                        ExpandApplicationFieldChildren(lReportCondition);
                        break;

                    case AWMiscStrings.HardwareNode:
                        ExpandAuditedItemsChildren(lReportCondition);
                        break;

                    case AWMiscStrings.SystemNode:
                        ExpandAuditedItemsChildren(lReportCondition);
                        break;

                    case AWMiscStrings.UserDataNode:
                        ExpandUserDataChildren(lReportCondition);
                        break;

                    default:
                        break;
                    }
                }

                DataRow[] rows;
                string    lCurrentReportCondition;

                if (!lDisplayAsAssetRegister)
                {
                    lResultsDataTable = BuildResultsTableStandard(_updatedReportConditions);
                    object[] lNewRowArray = new object[_updatedReportConditions.Count];

                    DataTable lUnionResultsDataTable = RunCustomUnionStatement(aAssetIds);
                    //object[] lNewRowArray = new object[lUnionResultsDataTable.Rows.Count];

                    foreach (string lAssetId in aAssetIds.Split(','))
                    {
                        for (int i = 0; i < _updatedReportConditions.Count; i++)
                        {
                            lCurrentReportCondition = _updatedReportConditions[i];

                            rows = lUnionResultsDataTable.Select(String.Format("ASSETID = {0} AND REFID = {1}", lAssetId, i));

                            // deal with applications differently
                            if (lCurrentReportCondition.StartsWith("Applications|"))
                            {
                                lNewRowArray[i] = (rows.Length == 0) ? "Not Installed" : "Installed";
                            }
                            else
                            {
                                lNewRowArray[i] = (rows.Length == 0) ? "" : rows[0].ItemArray[1].ToString();
                            }
                            if (lCurrentReportCondition.StartsWith("System|Patches"))
                            {
                                bPatchesIncluded = true;
                            }
                        }

                        if (bPatchesIncluded)
                        {
                            string   strAssetName = lNewRowArray[0].ToString();
                            int      iColCount    = lResultsDataTable.Columns.Count;
                            object[] lRowArray    = new object[iColCount];
                            for (int j = 1; j < lNewRowArray.Length; j = j + 4)
                            {
                                for (int i = 0; i < iColCount - 2; i++)
                                {
                                    lRowArray[i + 2] = lNewRowArray[i + j].ToString();
                                }
                                lRowArray[0] = strAssetName;
                                string    strPatchItem      = _updatedReportConditions[j].ToString();
                                String [] lReportConditions = strPatchItem.Split('|');
                                strPatchItem = lReportConditions[lReportConditions.Length - 3] + "|" + lReportConditions[lReportConditions.Length - 2];
                                lRowArray[1] = strPatchItem;

                                //check before adding applies to this asset
                                bool bInsert = false;
                                for (int i = 2; i < iColCount; i++)
                                {
                                    if (lRowArray[i].ToString() != "")
                                    {
                                        bInsert = true;
                                        break;
                                    }
                                }
                                if (bInsert)
                                {
                                    lResultsDataTable.Rows.Add(lRowArray);
                                }
                            }
                        }
                        else
                        {
                            lResultsDataTable.Rows.Add(lNewRowArray);
                        }
                    }
                }
                else
                {
                    lResultsDataTable = new DataTable();
                    lResultsDataTable.Columns.Add("Asset Name", typeof(string));
                    lResultsDataTable.Columns.Add("Field Name", typeof(string));
                    lResultsDataTable.Columns.Add("Value", typeof(string));

                    DataTable lUnionResultsDataTable = RunCustomUnionStatement(aAssetIds);

                    foreach (string lAssetId in aAssetIds.Split(','))
                    {
                        string lAssetName = lAssetDAO.ConvertIdListToNames(lAssetId, ';');
                        bPatchesIncluded = false;
                        bool            bItemRowAdded    = false;
                        int             iCount           = 0;
                        List <object[]> listupdatedPatch = new List <object[]>();

                        for (int i = 0; i < _updatedReportConditions.Count; i++)
                        {
                            object[] lNewRowArray = new object[3];
                            lCurrentReportCondition = _updatedReportConditions[i];
                            rows = lUnionResultsDataTable.Select(String.Format("ASSETID = {0} AND REFID = {1}", lAssetId, i));

                            lNewRowArray[0] = lAssetName;
                            lNewRowArray[1] = lCurrentReportCondition.Split('|')[lCurrentReportCondition.Split('|').Length - 1];

                            // deal with applications differently
                            if (lCurrentReportCondition.StartsWith("Applications|"))
                            {
                                lNewRowArray[2] = (rows.Length == 0) ? "Not Installed" : "Installed";
                            }
                            else
                            {
                                lNewRowArray[2] = (rows.Length == 0) ? "" : rows[0].ItemArray[1].ToString();
                            }

                            if (lCurrentReportCondition.StartsWith("System|Patches"))
                            {
                                bPatchesIncluded = true;
                            }

                            if (bPatchesIncluded)
                            {
                                object[] NewRowArray = new object[3];
                                NewRowArray[0] = lAssetName;
                                NewRowArray[1] = "Item";
                                String[] lReportConditions = lCurrentReportCondition.Split('|');
                                string   strPatchItem      = lReportConditions[lReportConditions.Length - 3] + "|" + lReportConditions[lReportConditions.Length - 2];
                                NewRowArray[2] = strPatchItem;

                                if (!bItemRowAdded)
                                {
                                    //lResultsDataTable.Rows.Add(NewRowArray);
                                    listupdatedPatch.Add(NewRowArray);
                                    bItemRowAdded = true;
                                }
                                iCount++;
                                //lResultsDataTable.Rows.Add(lNewRowArray);
                                listupdatedPatch.Add(lNewRowArray);


                                if (iCount == 4)
                                {
                                    //We had the details for a patch check it is associated with the asset
                                    bItemRowAdded = false;
                                    iCount        = 0;
                                    bool bInsert = false;
                                    for (int k = 1; k < listupdatedPatch.Count - 1; k++)
                                    {
                                        if (listupdatedPatch[k][2].ToString() != "")
                                        {
                                            bInsert = true;
                                            break;
                                        }
                                    }
                                    if (bInsert)
                                    {
                                        foreach (object[] objItem in listupdatedPatch)
                                        {
                                            lResultsDataTable.Rows.Add(objItem);
                                        }
                                        listupdatedPatch.Clear();
                                    }
                                    else
                                    {
                                        listupdatedPatch.Clear();
                                    }
                                }
                            }
                            else
                            {
                                lResultsDataTable.Rows.Add(lNewRowArray);
                            }
                        }
                    }

                    lResultsDataTable.DefaultView.Sort = "Asset Name ASC";
                }
            }
            catch (OutOfMemoryException ex)
            {
                logger.Error(ex.Message);
                MessageBox.Show(
                    "An out of memory exception has occured.  You may have too many items in your Custom Report." + Environment.NewLine + Environment.NewLine +
                    "Please reduce the number of assets and/or report fields and re-run the query.",
                    "AuditWizard",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                if (ex.Number == 701 || ex.Number == 8623)
                {
                    MessageBox.Show(
                        "An SQL Exception has occured. You may have too many items in your Custom Report." + Environment.NewLine + Environment.NewLine +
                        "Please reduce the number of assets and/or report fields and re-run the query.",
                        "AuditWizard",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            return(lResultsDataTable);
        }