/// <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); }
/// <summary> /// Return a list of changes between this object and an old version /// We really aren't that interested in changes to these details just adding and deletion /// </summary> /// <param name="oldObject"></param> /// <returns></returns> public List <AuditTrailEntry> AuditChanges(AssetGroup oldObject) { AuditTrailDAO lwDataAccess = new AuditTrailDAO(); // Construct the return list List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>(); // Is this a new item or an update to an existing one if (GroupID == 0) { AuditTrailEntry ate = new AuditTrailEntry(); ate.Date = DateTime.Now; ate.Class = AuditTrailEntry.CLASS.location; ate.Type = AuditTrailEntry.TYPE.added; ate.Key = _name; ate.AssetID = 0; ate.AssetName = ""; ate.Username = System.Environment.UserName; listChanges.Add(ate); } // Add all of these changes to the Audit Trail foreach (AuditTrailEntry entry in listChanges) { lwDataAccess.AuditTrailAdd(entry); } // Return the constructed list return(listChanges); }
/// <summary> /// Wrapper around adding an Audit Trail Entry to the list and re-creating the base ATE object /// </summary> /// <param name="listChanges"></param> /// <param name="ate"></param> /// <param name="key"></param> /// <param name="oldValue"></param> /// <param name="newValue"></param> /// <returns></returns> protected AuditTrailEntry AddChange(List <AuditTrailEntry> listChanges, AuditTrailEntry ate, String key, String oldValue, String newValue) { ate.Key = ate.Key + "|" + key; ate.OldValue = oldValue; ate.NewValue = newValue; listChanges.Add(ate); ate = BuildATE(); return(ate); }
public DataTable GetAuditTrailByDate(string aStartDate, string aEndDate) { DataTable auditTrailDataTable = GetAssetAuditHistoryForReport(); DataTable resultsDataTable = new DataTable(); DataColumn dataColumn; dataColumn = new DataColumn(); dataColumn.DataType = Type.GetType("System.String"); dataColumn.ColumnName = "Location"; resultsDataTable.Columns.Add(dataColumn); dataColumn = new DataColumn(); dataColumn.DataType = Type.GetType("System.String"); dataColumn.ColumnName = "Asset Name"; resultsDataTable.Columns.Add(dataColumn); dataColumn = new DataColumn(); dataColumn.DataType = Type.GetType("System.String"); dataColumn.ColumnName = "Date / Time"; resultsDataTable.Columns.Add(dataColumn); dataColumn = new DataColumn(); dataColumn.DataType = Type.GetType("System.String"); dataColumn.ColumnName = "Category"; resultsDataTable.Columns.Add(dataColumn); dataColumn = new DataColumn(); dataColumn.DataType = Type.GetType("System.String"); dataColumn.ColumnName = "Operation"; resultsDataTable.Columns.Add(dataColumn); foreach (DataRow row in auditTrailDataTable.Rows) { AuditTrailEntry record = new AuditTrailEntry(row); if (CheckDate(record.Date, aStartDate, aEndDate)) { resultsDataTable.Rows.Add( new object[] { record.Location, record.AssetName, //record.Date.ToShortDateString() + " " + record.Date.ToShortTimeString(), record.Date.ToString("yyyy-MM-dd HH:mm"), record.ClassString, record.GetTypeDescription() }); } } return(resultsDataTable); }
/// <summary> /// Return a list of changes between this object and an old version /// </summary> /// <param name="oldObject"></param> /// <returns></returns> public List <AuditTrailEntry> AuditChanges(User oldObject) { AuditTrailDAO lwDataAccess = new AuditTrailDAO(); // Construct the return list List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>(); // The following fields may change for an Action // // Associated Computers // Notes // Status // // Build a blank AuditTrailEntry AuditTrailEntry ate = BuildATE(); // If the ld of the old object was 0 then this is a NEW item and not a change to an existing item if (UserID == 0) { ate.Type = AuditTrailEntry.TYPE.added; AddChange(listChanges, ate, "", "", ""); } else if (oldObject != null) { // First / Last Name if (this._firstName != oldObject._firstName) { ate = AddChange(listChanges, ate, "First Name", oldObject._firstName, _firstName); } if (this._lastName != oldObject._lastName) { ate = AddChange(listChanges, ate, "Last Name", oldObject._lastName, _lastName); } // Access Level if (_accessLevel != oldObject._accessLevel) { ate = AddChange(listChanges, ate, "Access Level", oldObject.AccessLevelAsString, AccessLevelAsString); } } // Add all of these changes to the Audit Trail foreach (AuditTrailEntry entry in listChanges) { lwDataAccess.AuditTrailAdd(entry); } // Return the constructed list return(listChanges); }
/// <summary> /// Delete the current license from the database /// </summary> public void Delete() { // Delete from the database LicensesDAO lwDataAccess = new LicensesDAO(); lwDataAccess.LicenseDelete(this); // ...and audit the deletion AuditTrailEntry ate = BuildATE(); ate.Type = AuditTrailEntry.TYPE.deleted; new AuditTrailDAO().AuditTrailAdd(ate); }
/// <summary> /// Construct a raw Audit Trail Entry and initialize it /// </summary> /// <returns></returns> protected AuditTrailEntry BuildATE() { AuditTrailEntry ate = new AuditTrailEntry(); ate.Date = DateTime.Now; ate.Class = AuditTrailEntry.CLASS.user; ate.Type = AuditTrailEntry.TYPE.changed; ate.Key = _logon; ate.AssetID = 0; ate.AssetName = ""; ate.Username = System.Environment.UserName; return(ate); }
/// <summary> /// Construct a raw Audit Trail Entry and initialize it /// </summary> /// <returns></returns> protected AuditTrailEntry BuildATE() { AuditTrailEntry ate = new AuditTrailEntry(); ate.Date = DateTime.Now; ate.Class = AuditTrailEntry.CLASS.application_changes; ate.Type = AuditTrailEntry.TYPE.changed; ate.AssetID = InstalledOnComputerID; ate.AssetName = this.InstalledOnComputer; ate.Username = System.Environment.UserName; return(ate); }
/// <summary> /// Delete the specified Audit TRail Entry from the database /// </summary> /// <param name="ate">The audit trail entry to remove</param> /// <returns></returns> public int AuditTrailDelete(AuditTrailEntry ate) { if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in"); } if (compactDatabaseType) { if (ate.AuditTrailID != 0) { try { using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection()) { string commandText = "DELETE FROM AUDITTRAIL WHERE _AUDITTRAILID = @nAuditTrailID"; using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddWithValue("@nAuditTrailID", ate.AuditTrailID); command.ExecuteNonQuery(); } } } 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); } } } else { AuditWizardDataAccess lAuditWizardDataAccess = new AuditWizardDataAccess(); lAuditWizardDataAccess.AuditTrailDelete(ate); } if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out"); } return(0); }
/// <summary> /// Construct a raw Audit Trail Entry and initialize it /// </summary> /// <returns></returns> protected AuditTrailEntry BuildATE() { AuditTrailEntry ate = new AuditTrailEntry(); ate.Date = DateTime.Now; ate.Class = AuditTrailEntry.CLASS.license; ate.Type = AuditTrailEntry.TYPE.changed; ate.Key = ApplicationName + "|" + _licenseTypeName; ate.AssetID = 0; ate.AssetName = ""; ate.Username = System.Environment.UserName; return(ate); }
/// <summary> /// Delete the current license from the database /// </summary> public void Delete() { // Delete from the database ActionsDAO lwDataAccess = new ActionsDAO(); lwDataAccess.ActionDelete(this); // ...and audit the deletion AuditTrailEntry ate = BuildATE(); ate.Type = AuditTrailEntry.TYPE.deleted; AuditTrailDAO lAuditTrailDAO = new AuditTrailDAO(); lAuditTrailDAO.AuditTrailAdd(ate); }
/// <summary> /// Delete the current license from the database /// </summary> public void Delete() { // Delete from the database SuppliersDAO lwDataAccess = new SuppliersDAO(); lwDataAccess.SupplierDelete(this); // ...and audit the deletion AuditTrailEntry ate = new AuditTrailEntry(); ate.Date = DateTime.Now; ate.Class = AuditTrailEntry.CLASS.supplier; ate.Type = AuditTrailEntry.TYPE.deleted; ate.Key = _name; ate.AssetID = 0; ate.AssetName = ""; ate.Username = System.Environment.UserName; new AuditTrailDAO().AuditTrailAdd(ate); }
/// <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); }
/// <summary> /// Delete the current location from the database /// </summary> public bool Delete() { LocationsDAO lwDataAccess = new LocationsDAO(); // As locations are hierarchical we cannot just delete a location without first deleting ALL // children and we cannot do that if any of our descendants are still being referenced // Get a list of all of our children AssetGroupList children = new AssetGroupList(lwDataAccess.GetGroups(this), GroupType); // Loop through each child and try and delete them first before we delete ourselves - this actually // causes recursion through this deletion function as children may have children and so on... foreach (AssetGroup childGroup in children) { if (!childGroup.Delete()) { return(false); } } // Only now can we delete ourselves as all of our children have been handled. if (lwDataAccess.GroupDelete(this) != 0) { return(false); } // ...and audit the deletion AuditTrailEntry ate = new AuditTrailEntry(); ate.Date = DateTime.Now; ate.Class = AuditTrailEntry.CLASS.location; ate.Type = AuditTrailEntry.TYPE.deleted; ate.Key = _name; ate.AssetID = 0; ate.AssetName = ""; ate.Username = System.Environment.UserName; new AuditTrailDAO().AuditTrailAdd(ate); return(true); }
/// <summary> /// Return a list of changes between this object and an old version /// </summary> /// <param name="oldObject"></param> /// <returns></returns> public List <AuditTrailEntry> ListChanges(ApplicationInstance oldObject) { // Construct the return list List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>(); // The Publisher, Application Name, Version and Installed Asset must not change // as these are basic properties of the application instance. // Build a blank AuditTrailEntry AuditTrailEntry ate = BuildATE(); if (this.Serial.ProductId != oldObject.Serial.ProductId) { ate = AddChange(listChanges, ate, "Serial Number", oldObject.Serial.ProductId, Serial.ProductId); } // CD Key if (this.Serial.CdKey != oldObject.Serial.CdKey) { ate = AddChange(listChanges, ate, "CD Key", oldObject.Serial.CdKey, Serial.CdKey); } // Return the constructed list return(listChanges); }
/// <summary> /// Add a new Asset to the database /// </summary> /// <param name="theAsset"></param> /// <returns></returns> public int AuditTrailAdd(AuditTrailEntry ate) { if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in"); } int lItemID = 0; if (compactDatabaseType) { try { using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection()) { string commandText = "INSERT INTO AUDITTRAIL (_ASSETID ,_USERNAME ,_DATE ,_CLASS ,_TYPE ,_KEY ,_VALUE1 ,_VALUE2) " + " VALUES (@nAssetID, @cUsername, @cSqlDate, @nClass, @nType, @cKey, @cOldValue, @cNewValue)"; SqlCeParameter[] spParams = new SqlCeParameter[8]; spParams[0] = new SqlCeParameter("@nAssetID", ate.AssetID); spParams[1] = new SqlCeParameter("@cUsername", ate.Username); spParams[2] = new SqlCeParameter("@cSqlDate", ate.Date); spParams[3] = new SqlCeParameter("@nClass", ate.Class); spParams[4] = new SqlCeParameter("@nType", ate.Type); spParams[5] = new SqlCeParameter("@cKey", ate.Key); spParams[6] = new SqlCeParameter("@cOldValue", ate.OldValue); spParams[7] = new SqlCeParameter("@cNewValue", ate.NewValue); using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddRange(spParams); command.ExecuteNonQuery(); } using (SqlCeCommand command = new SqlCeCommand("SELECT @@IDENTITY", conn)) { lItemID = Convert.ToInt32(command.ExecuteScalar()); } } } 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); } } else { AuditWizardDataAccess lAuditWizardDataAccess = new AuditWizardDataAccess(); lItemID = lAuditWizardDataAccess.AuditTrailAdd(ate); } if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out with id : " + lItemID); } return(lItemID); }
/// <summary> /// Return a list of changes between this object and an old version /// </summary> /// <param name="oldObject"></param> /// <returns></returns> public List <AuditTrailEntry> AuditChanges(ApplicationLicense oldObject) { AuditTrailDAO lwDataAccess = new AuditTrailDAO(); // Construct the return list List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>(); // License ID and ApplicationID must not change as these are basic properties of // the application license - Build a blank AuditTrailEntry AuditTrailEntry ate = BuildATE(); // Is this a new license rather than one we are modifying? if (LicenseID == 0) { ate.Type = AuditTrailEntry.TYPE.added; AddChange(listChanges, ate, "", "", ""); } else if (oldObject != null) { // License Type ID - note that if we change this we ignore related changes such as to the // usage counted or count fields as these will change if the type is changed if (this.LicenseTypeID != oldObject.LicenseTypeID) { ate = AddChange(listChanges, ate, "License Type", oldObject.LicenseTypeName, LicenseTypeName); } else { // Usage Counted if (this.UsageCounted != oldObject.UsageCounted) { ate = AddChange(listChanges , ate , "Usage Counted" , (oldObject.UsageCounted) ? "Yes" : "No" , (UsageCounted) ? "Yes" : "No"); } // Usage Count if (this.Count != oldObject.Count) { ate = AddChange(listChanges , ate , "Usage Count" , oldObject.Count.ToString() , Count.ToString()); } } // Supported Status if (Supported != oldObject.Supported) { ate = AddChange(listChanges , ate , "Support Status" , (oldObject.Supported) ? "Yes" : "No" , (Supported) ? "Yes" : "No"); } // If we are supported then we need to log other support fields also if (Supported) { // Support Expiry Date if (SupportExpiryDate != oldObject.SupportExpiryDate) { ate = AddChange(listChanges, ate, "Support Expiry Date", oldObject.SupportExpiryDate.ToString(), SupportExpiryDate.ToString()); } // Support Alert Days if (SupportAlertDays != oldObject.SupportAlertDays) { ate = AddChange(listChanges, ate, "Support Expiry Alert Days", oldObject.SupportAlertDays.ToString(), SupportAlertDays.ToString()); } // Support Alert by Email Status if (SupportAlertEmail != oldObject.SupportAlertEmail) { ate = AddChange(listChanges , ate , "Support Alert by Email" , (oldObject.SupportAlertEmail) ? "Yes" : "No" , (SupportAlertEmail) ? "Yes" : "No"); } // Support Alert Email Recipients if (this.SupportAlertRecipients != oldObject.SupportAlertRecipients) { ate = AddChange(listChanges, ate, "Support Alert Email Recipients", oldObject.SupportAlertRecipients.ToString(), SupportAlertRecipients); } } // Supplier if (SupplierID != oldObject.SupplierID) { ate = AddChange(listChanges , ate , "Supplier" , oldObject.SupplierName , SupplierName); } } // Add all of these changes to the Audit Trail foreach (AuditTrailEntry entry in listChanges) { lwDataAccess.AuditTrailAdd(entry); } // Return the constructed list return(listChanges); }
/// <summary> /// Return a list of changes between this object and an old version /// </summary> /// <param name="oldObject"></param> /// <returns></returns> public void AuditChanges(Asset oldObject) { AuditTrailDAO lwDataAccess = new AuditTrailDAO(); // Construct the return list List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>(); // The following fields are auditable for an Asset // // Stock Status // Category // Type // Make // Model // Serial // Supplier // // Build a blank AuditTrailEntry AuditTrailEntry ate = BuildATE(); // We only audit changes made for existing assets so ignore if we weren't passed an original if (oldObject != null) { // Stock Status if (_stockStatus != oldObject._stockStatus) { AddChange(listChanges, ate, "Stock Status", Asset.GetStockStatusText(oldObject._stockStatus), Asset.GetStockStatusText(_stockStatus)); } // Asset Category / Tuype is the same thing if (_assetTypeID != oldObject._assetTypeID) { AddChange(listChanges, ate, "Asset Type", oldObject.TypeAsString, this.TypeAsString); } // Make if (_make != oldObject._make) { AddChange(listChanges, ate, "Make", oldObject._make, this._make); } // Model if (_model != oldObject._model) { AddChange(listChanges, ate, "Model", oldObject._model, this._model); } // Serial if (_serial != oldObject._serial) { AddChange(listChanges, ate, "Serial Number", oldObject._serial, this._serial); } // Add all of these changes to the Audit Trail foreach (AuditTrailEntry entry in listChanges) { lwDataAccess.AuditTrailAdd(entry); } } // Return the constructed list return; }
/// <summary> /// Return a list of changes between this object and an old version /// </summary> /// <param name="oldObject"></param> /// <returns></returns> public List <AuditTrailEntry> AuditChanges(Action oldObject) { AuditTrailDAO lwDataAccess = new AuditTrailDAO(); // Construct the return list List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>(); // The following fields may change for an Action // // Associated Computers // Notes // Status // // Build a blank AuditTrailEntry AuditTrailEntry ate = BuildATE(); // Is this a new item or a change to an existing item if (ActionID == 0) { ate.Type = AuditTrailEntry.TYPE.added; AddChange(listChanges, ate, "", ActionTypeText, ""); } else if (oldObject != null) { // Associated Computers if (this._associatedAssets != oldObject.AssociatedAssets) { ate = AddChange(listChanges, ate, "Associated Computers", oldObject.AssociatedAssets, AssociatedAssets); } // Notes if (Notes != oldObject.Notes) { ate = AddChange(listChanges , ate , "Notes" , oldObject.Notes , Notes); } // Status if (Status != oldObject.Status) { ate = AddChange(listChanges , ate , "Status" , oldObject.StatusText , StatusText); } } // Add all of these changes to the Audit Trail foreach (AuditTrailEntry entry in listChanges) { lwDataAccess.AuditTrailAdd(entry); } // Return the constructed list return(listChanges); }