예제 #1
0
        /// <summary>Archives a HolidayType 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="holidayTypeCode">The value for the HolidayTypeCode 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 holidayTypeCode)
        {
            // Accessor for the HolidayType Table.
            ServerMarketData.HolidayTypeDataTable holidayTypeTable = ServerMarketData.HolidayType;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.HolidayTypeRow holidayTypeRow = holidayTypeTable.FindByHolidayTypeCode(holidayTypeCode);
            if ((holidayTypeRow == null))
            {
                throw new Exception(string.Format("The HolidayType table does not have an element identified by {0}", holidayTypeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((holidayTypeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < holidayTypeRow.GetHolidayRows().Length); index = (index + 1))
            {
                ServerMarketData.HolidayRow childHolidayRow = holidayTypeRow.GetHolidayRows()[index];
                Holiday.Archive(adoTransaction, sqlTransaction, childHolidayRow.RowVersion, childHolidayRow.HolidayId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            holidayTypeRow[holidayTypeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(holidayTypeRow);
            holidayTypeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"HolidayType\" set \"IsArchived\" = 1 where \"HolidayTypeCode\"=@holidayTypeCod" +
                                                   "e");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@holidayTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, holidayTypeCode));
            sqlCommand.ExecuteNonQuery();
        }
예제 #2
0
 /// <summary>Collects the table lock request(s) for an Update operation</summary>
 /// <param name="adoTransaction">A list of locks required for this operation.</param>
 public static void Archive(AdoTransaction adoTransaction)
 {
     // These table lock(s) are required for the 'Archive' operation.
     adoTransaction.LockRequests.AddWriterLock(ServerMarketData.HolidayTypeLock);
     Holiday.Archive(adoTransaction);
 }