Exemple #1
0
        /// <summary>
        /// Return a list of all of the audit trail entries which are audit history records for
        /// the specified asset
        /// </summary>
        /// <returns></returns>
        public DataTable GetAssetAuditHistory(Asset aAsset, DateTime aStartDate, DateTime aEndDate)
        {
            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in");
            }

            DataTable ateTable = new DataTable(TableNames.AUDITTRAIL);

            if (compactDatabaseType)
            {
                try
                {
                    using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection())
                    {
                        string commandText =
                            "SELECT AUDITTRAIL.* ,ASSETS._NAME AS ASSETNAME ,LOCATIONS._FULLNAME AS FULLLOCATIONNAME " +
                            "FROM AUDITTRAIL " +
                            "LEFT JOIN ASSETS ON (AUDITTRAIL._ASSETID = ASSETS._ASSETID) " +
                            "LEFT JOIN LOCATIONS ON (ASSETS._LOCATIONID = LOCATIONS._LOCATIONID) " +
                            "WHERE _CLASS <= 3 ";

                        if (aAsset.AssetID == 0)
                        {
                            commandText += "AND AUDITTRAIL._ASSETID <> 0 ";
                        }
                        else
                        {
                            commandText += "AND AUDITTRAIL._ASSETID = @nAssetID ";
                        }

                        if (aStartDate != DateTime.MinValue && aEndDate != DateTime.MinValue)
                        {
                            commandText +=
                                "AND CONVERT(datetime ,AUDITTRAIL._DATE ,120) " +
                                "BETWEEN @cStartDate AND @cEndDate ";
                        }

                        commandText += "ORDER BY _AUDITTRAILID";

                        using (SqlCeCommand command = new SqlCeCommand(commandText, conn))
                        {
                            if (aAsset.AssetID != 0)
                            {
                                command.Parameters.AddWithValue("@nAssetID", aAsset.AssetID);
                            }

                            if (aStartDate != DateTime.MinValue && aEndDate != DateTime.MinValue)
                            {
                                command.Parameters.AddWithValue("@cStartDate", aStartDate);
                                command.Parameters.AddWithValue("@cEndDate", aEndDate);
                            }

                            new SqlCeDataAdapter(command).Fill(ateTable);
                        }
                    }
                }
                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();
                ateTable = lAuditWizardDataAccess.GetAssetAuditHistory(aAsset, aStartDate, aEndDate);
            }

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