/// <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); }
public void DeleteAsset() { _assetDAO.AssetDelete(_asset); }
/// <summary> /// Purge unaudited assets given a date before which items should be discarded /// </summary> /// <param name="purgeBeforeDate"></param> /// <returns></returns> public int DatabasePurgeAssets(DateTime purgeBeforeDate) { if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in"); } AssetDAO lAssetDAO = new AssetDAO(); int lAssetsPurged = 0; try { if (compactDatabaseType) { using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection()) { string commandText = "SELECT _ASSETID FROM ASSETS " + "WHERE ( (_LASTAUDIT IS NOT NULL) AND (_LASTAUDIT < @dtPurgeDate) ) OR (_LASTAUDIT IS NULL)"; SqlCeParameter[] spParams = new SqlCeParameter[1]; spParams[0] = new SqlCeParameter("@dtPurgeDate", purgeBeforeDate); using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddRange(spParams); using (SqlCeDataReader reader = command.ExecuteReader()) { while (reader.Read()) { lAssetDAO.AssetDelete(reader.GetInt32(0)); lAssetsPurged++; } } } } } else { using (SqlConnection conn = DatabaseConnection.CreateOpenStandardConnection()) { string commandText = "SELECT _ASSETID FROM ASSETS " + "WHERE ( (_LASTAUDIT IS NOT NULL) AND (_LASTAUDIT < @dtPurgeDate) ) OR (_LASTAUDIT IS NULL)"; SqlParameter[] spParams = new SqlParameter[1]; spParams[0] = new SqlParameter("@dtPurgeDate", purgeBeforeDate); using (SqlCommand command = new SqlCommand(commandText, conn)) { command.Parameters.AddRange(spParams); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { lAssetDAO.AssetDelete(reader.GetInt32(0)); lAssetsPurged++; } } } } } } 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 with assets purged : " + lAssetsPurged); } return(lAssetsPurged); }