예제 #1
0
        /// <summary>
        /// Add a new Asset Type to the database
        /// </summary>
        /// <param name="theAlert"></param>
        /// <returns></returns>
        public int AssetTypeAdd(AssetType aAssetType)
        {
            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 ASSET_TYPES " +
                            "(_NAME ,_PARENTID ,_AUDITABLE ,_ICON) " +
                            "VALUES " +
                            "(@cName, @nParentID, @bAuditable ,@cIcon)";

                        SqlCeParameter[] spParams = new SqlCeParameter[4];
                        spParams[0] = new SqlCeParameter("@cName", aAssetType.Name);

                        if (aAssetType.ParentID == 0)
                        {
                            spParams[1] = new SqlCeParameter("@nParentID", DBNull.Value);
                        }
                        else
                        {
                            spParams[1] = new SqlCeParameter("@nParentID", aAssetType.ParentID);
                        }

                        spParams[2] = new SqlCeParameter("@bAuditable", Convert.ToInt32(aAssetType.Auditable));
                        spParams[3] = new SqlCeParameter("@cIcon", aAssetType.Icon);

                        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.AssetTypeAdd(aAssetType);
            }

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