Example #1
0
        /// <summary>
        /// Update the specified Asset Type
        /// </summary>
        /// <param name="theAsset"></param>
        /// <returns></returns>
        public int AssetTypeUpdate(AssetType aAssetType)
        {
            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in");
            }

            if (compactDatabaseType)
            {
                try
                {
                    using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection())
                    {
                        string commandText =
                            "UPDATE ASSET_TYPES " +
                            "SET " +
                            "_NAME = @cName, " +
                            "_PARENTID = @nParentID, " +
                            "_ICON = @cIcon " +
                            "WHERE _ASSETTYPEID = @nAssetTypeID";

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

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

                        spParams[3] = new SqlCeParameter("@cIcon", aAssetType.Icon);

                        using (SqlCeCommand command = new SqlCeCommand(commandText, conn))
                        {
                            command.Parameters.AddRange(spParams);
                            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.AssetTypeUpdate(aAssetType);
            }

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