Esempio n. 1
0
        /// <summary>Archives a Violation record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="RowVersion">The version number of this row.</param>
        /// <param name="violationId">The value for the ViolationId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int violationId)
        {
            // Accessor for the Violation Table.
            ServerDataModel.ViolationDataTable violationTable = ServerDataModel.Violation;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ViolationRow violationRow = violationTable.FindByViolationId(violationId);
            if ((violationRow == null))
            {
                throw new Exception(string.Format("The Violation table does not have an element identified by {0}", violationId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((violationRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            violationRow[violationTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(violationRow);
            violationRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Violation\" set \"IsArchived\" = 1 where \"ViolationId\"=@violationId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@violationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, violationId));
            sqlCommand.ExecuteNonQuery();
        }
Esempio n. 2
0
        /// <summary>Inserts a Violation record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="restrictionId">The value for the RestrictionId column.</param>
        /// <param name="accountId">The value for the AccountId column.</param>
        /// <param name="securityId">The value for the SecurityId column.</param>
        /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param>
        /// <param name="description">The value for the Description column.</param>
        public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int restrictionId, int accountId, int securityId, int positionTypeCode, string description)
        {
            // Accessor for the Violation Table.
            ServerDataModel.ViolationDataTable violationTable = ServerDataModel.Violation;
            // Apply Defaults
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerDataModel.ViolationRow violationRow = violationTable.NewViolationRow();
            violationRow[violationTable.RowVersionColumn]       = rowVersion;
            violationRow[violationTable.RestrictionIdColumn]    = restrictionId;
            violationRow[violationTable.AccountIdColumn]        = accountId;
            violationRow[violationTable.SecurityIdColumn]       = securityId;
            violationRow[violationTable.PositionTypeCodeColumn] = positionTypeCode;
            violationRow[violationTable.DescriptionColumn]      = description;
            violationTable.AddViolationRow(violationRow);
            adoTransaction.DataRows.Add(violationRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"Violation\" (\"rowVersion\",\"ViolationId\",\"RestrictionId\",\"AccountId\",\"Secur" +
                                                   "ityId\",\"PositionTypeCode\",\"Description\") values (@rowVersion,@violationId,@restr" +
                                                   "ictionId,@accountId,@securityId,@positionTypeCode,@description)");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@violationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, violationRow[violationTable.ViolationIdColumn]));
            sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionId));
            sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId));
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(violationRow.ViolationId);
        }
Esempio n. 3
0
        /// <summary>Updates a Violation record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">The version number of the row</param>
        /// <param name="violationId">The value for the ViolationId column.</param>
        /// <param name="restrictionId">The value for the RestrictionId column.</param>
        /// <param name="accountId">The value for the AccountId column.</param>
        /// <param name="securityId">The value for the SecurityId column.</param>
        /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param>
        /// <param name="description">The value for the Description column.</param>
        public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int violationId, object restrictionId, object accountId, object securityId, object positionTypeCode, object description)
        {
            // Accessor for the Violation Table.
            ServerDataModel.ViolationDataTable violationTable = ServerDataModel.Violation;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ViolationRow violationRow = violationTable.FindByViolationId(violationId);
            if ((violationRow == null))
            {
                throw new Exception(string.Format("The Violation table does not have an element identified by {0}", violationId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((violationRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((restrictionId == null))
            {
                restrictionId = violationRow[violationTable.RestrictionIdColumn];
            }
            if ((accountId == null))
            {
                accountId = violationRow[violationTable.AccountIdColumn];
            }
            if ((securityId == null))
            {
                securityId = violationRow[violationTable.SecurityIdColumn];
            }
            if ((positionTypeCode == null))
            {
                positionTypeCode = violationRow[violationTable.PositionTypeCodeColumn];
            }
            if ((description == null))
            {
                description = violationRow[violationTable.DescriptionColumn];
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Update the record in the ADO database.
            violationRow[violationTable.RowVersionColumn]       = rowVersion;
            violationRow[violationTable.RestrictionIdColumn]    = restrictionId;
            violationRow[violationTable.AccountIdColumn]        = accountId;
            violationRow[violationTable.SecurityIdColumn]       = securityId;
            violationRow[violationTable.PositionTypeCodeColumn] = positionTypeCode;
            violationRow[violationTable.DescriptionColumn]      = description;
            adoTransaction.DataRows.Add(violationRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Violation\" set \"RowVersion\"=@rowVersion,\"RestrictionId\"=@restrictionId,\"A" +
                                                   "ccountId\"=@accountId,\"SecurityId\"=@securityId,\"PositionTypeCode\"=@positionTypeCo" +
                                                   "de,\"Description\"=@description where \"ViolationId\"=@violationId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@violationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, violationId));
            sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionId));
            sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId));
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }