Example #1
0
        /// <summary>Archives a PriceType 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="priceTypeCode">The value for the PriceTypeCode 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 priceTypeCode)
        {
            // Accessor for the PriceType Table.
            ServerMarketData.PriceTypeDataTable priceTypeTable = ServerMarketData.PriceType;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.PriceTypeRow priceTypeRow = priceTypeTable.FindByPriceTypeCode(priceTypeCode);
            if ((priceTypeRow == null))
            {
                throw new Exception(string.Format("The PriceType table does not have an element identified by {0}", priceTypeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((priceTypeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < priceTypeRow.GetDestinationOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.DestinationOrderRow childDestinationOrderRow = priceTypeRow.GetDestinationOrderRows()[index];
                DestinationOrder.Archive(adoTransaction, sqlTransaction, childDestinationOrderRow.RowVersion, childDestinationOrderRow.DestinationOrderId);
            }
            for (int index = 0; (index < priceTypeRow.GetSourceOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = priceTypeRow.GetSourceOrderRows()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < priceTypeRow.GetWorkingOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = priceTypeRow.GetWorkingOrderRows()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            priceTypeRow[priceTypeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(priceTypeRow);
            priceTypeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"PriceType\" set \"IsArchived\" = 1 where \"PriceTypeCode\"=@priceTypeCode");

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