Esempio n. 1
0
        /// <summary>Archives a PartyType 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="partyTypeCode">The value for the PartyTypeCode 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 partyTypeCode)
        {
            // Accessor for the PartyType Table.
            ServerMarketData.PartyTypeDataTable partyTypeTable = ServerMarketData.PartyType;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.PartyTypeRow partyTypeRow = partyTypeTable.FindByPartyTypeCode(partyTypeCode);
            if ((partyTypeRow == null))
            {
                throw new Exception(string.Format("The PartyType table does not have an element identified by {0}", partyTypeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((partyTypeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < partyTypeRow.GetBlotterRows().Length); index = (index + 1))
            {
                ServerMarketData.BlotterRow childBlotterRow = partyTypeRow.GetBlotterRows()[index];
                Blotter.ArchiveChildren(adoTransaction, sqlTransaction, childBlotterRow.RowVersion, childBlotterRow.BlotterId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            partyTypeRow[partyTypeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(partyTypeRow);
            partyTypeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"PartyType\" set \"IsArchived\" = 1 where \"PartyTypeCode\"=@partyTypeCode");

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