/// <summary> /// Delete the specified AssetType from the database /// </summary> /// <param name="licenseID"></param> /// <returns></returns> public int AssetTypeDelete(AssetType aAssetType) { if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in"); } int references = 0; if (compactDatabaseType) { // The delete code will perform a sanity check to ensure that we do not // delete user defined categories/fields which are still referenced so we simply delete it now int lParentID = -1; int lReferences = -1; try { using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection()) { string commandText = "SELECT _PARENTID FROM ASSET_TYPES WHERE _ASSETTYPEID = @nAssetTypeID"; using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddWithValue("@nAssetTypeID", aAssetType.AssetTypeID); object result = command.ExecuteScalar(); if ((result != null) && (result.GetType() != typeof(DBNull))) { lParentID = (int)result; } } if (lParentID == -1) { commandText = "SELECT min(_ASSETTYPEID) FROM ASSET_TYPES WHERE _PARENTID = @nAssetTypeID"; using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddWithValue("@nAssetTypeID", aAssetType.AssetTypeID); object result = command.ExecuteScalar(); if ((result != null) && (result.GetType() != typeof(DBNull))) { lReferences = (int)result; } } } else { commandText = "SELECT min(_ASSETID) FROM ASSETS WHERE _ASSETTYPEID = @nAssetTypeID"; using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddWithValue("@nAssetTypeID", aAssetType.AssetTypeID); object result = command.ExecuteScalar(); if ((result != null) && (result.GetType() != typeof(DBNull))) { lReferences = (int)result; } } } if (lReferences != -1) { references = -1; } else { commandText = "DELETE FROM ASSET_TYPES WHERE _ASSETTYPEID = @nAssetTypeID"; using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddWithValue("@nAssetTypeID", aAssetType.AssetTypeID); 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.AssetTypeDelete(aAssetType); } if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out"); } return(references); }