Ejemplo n.º 1
0
        /// <summary>Archives a PositionType 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="positionTypeCode">The value for the PositionTypeCode 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 positionTypeCode)
        {
            // Accessor for the PositionType Table.
            ServerDataModel.PositionTypeDataTable positionTypeTable = ServerDataModel.PositionType;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.PositionTypeRow positionTypeRow = positionTypeTable.FindByPositionTypeCode(positionTypeCode);
            if ((positionTypeRow == null))
            {
                throw new Exception(string.Format("The PositionType table does not have an element identified by {0}", positionTypeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((positionTypeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < positionTypeRow.GetPositionRows().Length); index = (index + 1))
            {
                ServerDataModel.PositionRow childPositionRow = positionTypeRow.GetPositionRows()[index];
                Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode);
            }
            for (int index = 0; (index < positionTypeRow.GetPositionTargetRows().Length); index = (index + 1))
            {
                ServerDataModel.PositionTargetRow childPositionTargetRow = positionTypeRow.GetPositionTargetRows()[index];
                PositionTarget.Archive(adoTransaction, sqlTransaction, childPositionTargetRow.RowVersion, childPositionTargetRow.ModelId, childPositionTargetRow.SecurityId, childPositionTargetRow.PositionTypeCode);
            }
            for (int index = 0; (index < positionTypeRow.GetTaxLotRows().Length); index = (index + 1))
            {
                ServerDataModel.TaxLotRow childTaxLotRow = positionTypeRow.GetTaxLotRows()[index];
                TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId);
            }
            for (int index = 0; (index < positionTypeRow.GetViolationRows().Length); index = (index + 1))
            {
                ServerDataModel.ViolationRow childViolationRow = positionTypeRow.GetViolationRows()[index];
                Violation.Archive(adoTransaction, sqlTransaction, childViolationRow.RowVersion, childViolationRow.ViolationId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            positionTypeRow[positionTypeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(positionTypeRow);
            positionTypeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"PositionType\" set \"IsArchived\" = 1 where \"PositionTypeCode\"=@positionType" +
                                                   "Code");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode));
            sqlCommand.ExecuteNonQuery();
        }