Exemplo n.º 1
0
        /// <summary>
        /// Return a list of changes between this object and an old version
        /// For suppliers we really aren't that interested  in changes to these details just adding
        /// and deletion of suppliers
        /// </summary>
        /// <param name="oldObject"></param>
        /// <returns></returns>
        public List <AuditTrailEntry> AuditChanges(Supplier oldObject)
        {
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            // Construct the return list
            List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>();

            // Is this a new item or an update to an existing one
            if (SupplierID == 0)
            {
                AuditTrailEntry ate = new AuditTrailEntry();
                ate.Date      = DateTime.Now;
                ate.Class     = AuditTrailEntry.CLASS.supplier;
                ate.Type      = AuditTrailEntry.TYPE.added;
                ate.Key       = _name;
                ate.AssetID   = 0;
                ate.AssetName = "";
                ate.Username  = System.Environment.UserName;
                listChanges.Add(ate);
            }

            // Add all of these changes to the Audit Trail
            foreach (AuditTrailEntry entry in listChanges)
            {
                lwDataAccess.AuditTrailAdd(entry);
            }

            // Return the constructed list
            return(listChanges);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a new asset to the database (or possibly update an existing item)
        /// </summary>
        /// <returns></returns>
        public int Add()
        {
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            if (AssetID == 0)
            {
                // Add the asset to the database
                _assetID = lwDataAccess.AssetAdd(this);

                // ...and log this event in the audit trail
                AuditTrailEntry ate = new AuditTrailEntry();
                ate.Date      = DateTime.Now;
                ate.Class     = AuditTrailEntry.CLASS.asset;
                ate.Type      = AuditTrailEntry.TYPE.added;
                ate.Key       = _name;
                ate.AssetID   = _assetID;
                ate.AssetName = _name;
                ate.Username  = System.Environment.UserName;
                lwDataAccess.AuditTrailAdd(ate);
            }
            else
            {
                lwDataAccess.AssetUpdate(this);
            }
            return(0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Delete the current license from the database
        /// </summary>
        public void Delete()
        {
            // Delete from the database
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            lwDataAccess.ActionDelete(this);

            // ...and audit the deletion
            AuditTrailEntry ate = BuildATE();

            ate.Type = AuditTrailEntry.TYPE.deleted;
            lwDataAccess.AuditTrailAdd(ate);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Delete the current license from the database
        /// </summary>
        public void Delete()
        {
            // Delete from the database
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            lwDataAccess.SupplierDelete(this);

            // ...and audit the deletion
            AuditTrailEntry ate = new AuditTrailEntry();

            ate.Date      = DateTime.Now;
            ate.Class     = AuditTrailEntry.CLASS.supplier;
            ate.Type      = AuditTrailEntry.TYPE.deleted;
            ate.Key       = _name;
            ate.AssetID   = 0;
            ate.AssetName = "";
            ate.Username  = System.Environment.UserName;
            lwDataAccess.AuditTrailAdd(ate);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Delete this asset from the database
        /// </summary>
        /// <returns></returns>
        public int Delete()
        {
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            // ...and audit the deletion
            AuditTrailEntry ate = new AuditTrailEntry();

            ate.Date      = DateTime.Now;
            ate.Class     = AuditTrailEntry.CLASS.asset;
            ate.Type      = AuditTrailEntry.TYPE.deleted;
            ate.Key       = _name;
            ate.AssetID   = 0;
            ate.AssetName = "";
            ate.Username  = System.Environment.UserName;
            lwDataAccess.AuditTrailAdd(ate);

            // Delete the asset
            lwDataAccess.AssetDelete(this);
            return(0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Delete the current location from the database
        /// </summary>
        public bool Delete()
        {
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            // As locations are hierarchical we cannot just delete a location without first deleting ALL
            // children and we cannot do that if any of our descendants are still being referenced
            // Get a list of all of our children
            AssetGroupList children = new AssetGroupList(lwDataAccess.GetGroups(this), GroupType);

            // Loop through each child and try and delete them first before we delete ourselves - this actually
            // causes recursion through this deletion function as children may have children and so on...
            foreach (AssetGroup childGroup in children)
            {
                if (!childGroup.Delete())
                {
                    return(false);
                }
            }

            // Only now can we delete ourselves as all of our children have been handled.
            if (lwDataAccess.GroupDelete(this) != 0)
            {
                return(false);
            }

            // ...and audit the deletion
            AuditTrailEntry ate = new AuditTrailEntry();

            ate.Date      = DateTime.Now;
            ate.Class     = AuditTrailEntry.CLASS.location;
            ate.Type      = AuditTrailEntry.TYPE.deleted;
            ate.Key       = _name;
            ate.AssetID   = 0;
            ate.AssetName = "";
            ate.Username  = System.Environment.UserName;
            lwDataAccess.AuditTrailAdd(ate);
            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Return a list of changes between this object and an old version
        /// </summary>
        /// <param name="oldObject"></param>
        /// <returns></returns>
        public void AuditChanges(Asset oldObject)
        {
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            // Construct the return list
            List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>();

            // The following fields are auditable for an Asset
            //
            //	Stock Status
            //	Category
            //  Type
            //	Make
            //	Model
            //	Serial
            //	Supplier
            //
            // Build a blank AuditTrailEntry
            AuditTrailEntry ate = BuildATE();

            // We only audit changes made for existing assets so ignore if we weren't passed an original
            if (oldObject != null)
            {
                // Stock Status
                if (_stockStatus != oldObject._stockStatus)
                {
                    AddChange(listChanges, ate, "Stock Status", Asset.GetStockStatusText(oldObject._stockStatus), Asset.GetStockStatusText(_stockStatus));
                }

                // Asset Category / Tuype is the same thing
                if (_assetTypeID != oldObject._assetTypeID)
                {
                    AddChange(listChanges, ate, "Asset Type", oldObject.TypeAsString, this.TypeAsString);
                }

                // Make
                if (_make != oldObject._make)
                {
                    AddChange(listChanges, ate, "Make", oldObject._make, this._make);
                }

                // Model
                if (_model != oldObject._model)
                {
                    AddChange(listChanges, ate, "Model", oldObject._model, this._model);
                }

                // Serial
                if (_serial != oldObject._serial)
                {
                    AddChange(listChanges, ate, "Serial Number", oldObject._serial, this._serial);
                }


                // Add all of these changes to the Audit Trail
                foreach (AuditTrailEntry entry in listChanges)
                {
                    lwDataAccess.AuditTrailAdd(entry);
                }
            }

            // Return the constructed list
            return;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add a new Asset to the database
        /// </summary>
        /// <param name="theAsset"></param>
        /// <returns></returns>
        public int AuditTrailAdd(AuditTrailEntry ate)
        {
            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 AUDITTRAIL (_ASSETID ,_USERNAME ,_DATE ,_CLASS ,_TYPE ,_KEY ,_VALUE1 ,_VALUE2) " +
                            " VALUES (@nAssetID, @cUsername, @cSqlDate, @nClass, @nType, @cKey, @cOldValue, @cNewValue)";

                        SqlCeParameter[] spParams = new SqlCeParameter[8];
                        spParams[0] = new SqlCeParameter("@nAssetID", ate.AssetID);
                        spParams[1] = new SqlCeParameter("@cUsername", ate.Username);
                        spParams[2] = new SqlCeParameter("@cSqlDate", ate.Date);
                        spParams[3] = new SqlCeParameter("@nClass", ate.Class);
                        spParams[4] = new SqlCeParameter("@nType", ate.Type);
                        spParams[5] = new SqlCeParameter("@cKey", ate.Key);
                        spParams[6] = new SqlCeParameter("@cOldValue", ate.OldValue);
                        spParams[7] = new SqlCeParameter("@cNewValue", ate.NewValue);

                        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.AuditTrailAdd(ate);
            }

            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out with id : " + lItemID);
            }
            return(lItemID);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Return a list of changes between this object and an old version
        /// </summary>
        /// <param name="oldObject"></param>
        /// <returns></returns>
        public List <AuditTrailEntry> AuditChanges(Action oldObject)
        {
            AuditWizardDataAccess lwDataAccess = new AuditWizardDataAccess();

            // Construct the return list
            List <AuditTrailEntry> listChanges = new List <AuditTrailEntry>();

            // The following fields may change for an Action
            //
            //	Associated Computers
            //	Notes
            //  Status
            //
            // Build a blank AuditTrailEntry
            AuditTrailEntry ate = BuildATE();

            // Is this a new item or a change to an existing item
            if (ActionID == 0)
            {
                ate.Type = AuditTrailEntry.TYPE.added;
                AddChange(listChanges, ate, "", ActionTypeText, "");
            }

            else if (oldObject != null)
            {
                // Associated Computers
                if (this._associatedAssets != oldObject.AssociatedAssets)
                {
                    ate = AddChange(listChanges, ate, "Associated Computers", oldObject.AssociatedAssets, AssociatedAssets);
                }

                // Notes
                if (Notes != oldObject.Notes)
                {
                    ate = AddChange(listChanges
                                    , ate
                                    , "Notes"
                                    , oldObject.Notes
                                    , Notes);
                }

                // Status
                if (Status != oldObject.Status)
                {
                    ate = AddChange(listChanges
                                    , ate
                                    , "Status"
                                    , oldObject.StatusText
                                    , StatusText);
                }
            }

            // Add all of these changes to the Audit Trail
            foreach (AuditTrailEntry entry in listChanges)
            {
                lwDataAccess.AuditTrailAdd(entry);
            }


            // Return the constructed list
            return(listChanges);
        }