/// <summary> /// Add this Action to the database /// </summary> /// <returns></returns> public int Add() { int status = -1; // If this supplier already exists then call the update instead if (_actionID != 0) { return(Update(null)); } // Add the ACTION to the database AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess(); int id = lwDataAccess.ActionAdd(this); if (id != 0) { AuditChanges(null); _actionID = id; status = 0; } return(status); }
/// <summary> /// Add a new Action to the database /// </summary> /// <param name="theAlert"></param> /// <returns></returns> public int ActionAdd(Action aAction) { 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 ACTIONS (_APPLICATIONID ,_TYPE, _STATUS ,_ASSETS, _NOTES) " + "VALUES (@nApplicationID ,@nType, @nStatus, @cAssets, @cNotes)"; SqlCeParameter[] spParams = new SqlCeParameter[5]; spParams[0] = new SqlCeParameter("@nType", (int)aAction.ActionType); spParams[1] = new SqlCeParameter("@nApplicationID", (int)aAction.ApplicationID); spParams[2] = new SqlCeParameter("@nStatus", (int)aAction.Status); spParams[3] = new SqlCeParameter("@cAssets", aAction.AssociatedAssets); spParams[4] = new SqlCeParameter("@cNotes", aAction.Notes); using (SqlCeCommand command = new SqlCeCommand(commandText, conn)) { command.Parameters.AddRange(spParams); command.ExecuteNonQuery(); } // then get id of newly inserted record 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.ActionAdd(aAction); } if (isDebugEnabled) { logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out"); } return(lItemID); }