Example #1
0
        public int Add()
        {
            // Add from the database
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            _alertID = lwDataAccess.AlertAdd(this);
            return(_alertID);
        }
Example #2
0
        /// <summary>
        /// Add a new Alert to the database
        /// </summary>
        /// <param name="theAlert"></param>
        /// <returns></returns>
        public int AlertAdd(Alert aAlert)
        {
            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 ALERTS " +
                            "(_TYPE, _CATEGORY ,_MESSAGE ,_FIELD1 ,_FIELD2 ,_STATUS ,_ALERTDATE ,_ASSETNAME ,_ALERTNAME) " +
                            "VALUES " +
                            "(@nType, @nCategory, @cMessage, @cField1, @cField2 ,0 ,@dtmDate ,@cAssetName ,@cAlertName)";

                        SqlCeParameter[] spParams = new SqlCeParameter[8];
                        spParams[0] = new SqlCeParameter("@nType", (int)aAlert.Type);
                        spParams[1] = new SqlCeParameter("@nCategory", (int)aAlert.Category);
                        spParams[2] = new SqlCeParameter("@cMessage", aAlert.Message);
                        spParams[3] = new SqlCeParameter("@cField1", aAlert.Field1);
                        spParams[4] = new SqlCeParameter("@cField2", aAlert.Field2);
                        spParams[5] = new SqlCeParameter("@dtmDate", DateTime.Now);
                        spParams[6] = new SqlCeParameter("@cAssetName", aAlert.AssetName);
                        spParams[7] = new SqlCeParameter("@cAlertName", aAlert.AlertName);

                        using (SqlCeCommand command = new SqlCeCommand(commandText, conn))
                        {
                            command.Parameters.AddRange(spParams);
                            command.ExecuteNonQuery();
                        }

                        using (SqlCeCommand commandReturnValue = new SqlCeCommand("SELECT @@IDENTITY", conn))
                        {
                            lItemID = Convert.ToInt32(commandReturnValue.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.AlertAdd(aAlert);
            }

            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out");
            }
            return(lItemID);
        }