/// <summary>Inserts a Holiday record using Metadata Parameters.</summary> /// <param name="parameters">Contains the metadata parameters.</param> public static void Delete(ParameterList parameters) { // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; long rowVersion = parameters["rowVersion"]; int holidayId = parameters["holidayId"]; // Call the internal method to complete the operation. Holiday.Delete(adoTransaction, sqlTransaction, rowVersion, holidayId); }
/// <summary>Deletes a Country 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="countryId">The value for the CountryId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> public static void Delete(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int countryId) { // Accessor for the Country Table. ServerMarketData.CountryDataTable countryTable = ServerMarketData.Country; // Rule #1: Make sure the record exists before updating it. ServerMarketData.CountryRow countryRow = countryTable.FindByCountryId(countryId); if ((countryRow == null)) { throw new Exception(string.Format("The Country table does not have an element identified by {0}", countryId)); } // Rule #2: Optimistic Concurrency Check if ((countryRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Delete the child records. for (int index = 0; (index < countryRow.GetAccountBaseRows().Length); index = (index + 1)) { ServerMarketData.AccountBaseRow childAccountBaseRow = countryRow.GetAccountBaseRows()[index]; AccountBase.DeleteChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId); } for (int index = 0; (index < countryRow.GetHolidayRows().Length); index = (index + 1)) { ServerMarketData.HolidayRow childHolidayRow = countryRow.GetHolidayRows()[index]; Holiday.Delete(adoTransaction, sqlTransaction, childHolidayRow.RowVersion, childHolidayRow.HolidayId); } for (int index = 0; (index < countryRow.GetProvinceRows().Length); index = (index + 1)) { ServerMarketData.ProvinceRow childProvinceRow = countryRow.GetProvinceRows()[index]; Province.Delete(adoTransaction, sqlTransaction, childProvinceRow.RowVersion, childProvinceRow.ProvinceId); } for (int index = 0; (index < countryRow.GetSecurityRows().Length); index = (index + 1)) { ServerMarketData.SecurityRow childSecurityRow = countryRow.GetSecurityRows()[index]; Security.DeleteChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. countryRow[countryTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(countryRow); countryRow.Delete(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Country\" set \"IsDeleted\" = 1 where \"CountryId\"=@countryId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@countryId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, countryId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Deletes 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 Delete(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."); } // Delete the child records. for (int index = 0; (index < holidayTypeRow.GetHolidayRows().Length); index = (index + 1)) { ServerMarketData.HolidayRow childHolidayRow = holidayTypeRow.GetHolidayRows()[index]; Holiday.Delete(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(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"HolidayType\" set \"IsDeleted\" = 1 where \"HolidayTypeCode\"=@holidayTypeCode" + ""); 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(); }