/// <summary>Archives a Restriction 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="restrictionId">The value for the RestrictionId 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 restrictionId) { // Accessor for the Restriction Table. ServerDataModel.RestrictionDataTable restrictionTable = ServerDataModel.Restriction; // Rule #1: Make sure the record exists before updating it. ServerDataModel.RestrictionRow restrictionRow = restrictionTable.FindByRestrictionId(restrictionId); if ((restrictionRow == null)) { throw new Exception(string.Format("The Restriction table does not have an element identified by {0}", restrictionId)); } // Rule #2: Optimistic Concurrency Check if ((restrictionRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < restrictionRow.GetViolationRows().Length); index = (index + 1)) { ServerDataModel.ViolationRow childViolationRow = restrictionRow.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. restrictionRow[restrictionTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(restrictionRow); restrictionRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Restriction\" set \"IsArchived\" = 1 where \"RestrictionId\"=@restrictionId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Inserts a Violation record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="restrictionId">The value for the RestrictionId column.</param> /// <param name="accountId">The value for the AccountId column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="description">The value for the Description column.</param> public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int restrictionId, int accountId, int securityId, int positionTypeCode, string description) { // Accessor for the Violation Table. ServerDataModel.ViolationDataTable violationTable = ServerDataModel.Violation; // Apply Defaults // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Insert the record into the ADO database. ServerDataModel.ViolationRow violationRow = violationTable.NewViolationRow(); violationRow[violationTable.RowVersionColumn] = rowVersion; violationRow[violationTable.RestrictionIdColumn] = restrictionId; violationRow[violationTable.AccountIdColumn] = accountId; violationRow[violationTable.SecurityIdColumn] = securityId; violationRow[violationTable.PositionTypeCodeColumn] = positionTypeCode; violationRow[violationTable.DescriptionColumn] = description; violationTable.AddViolationRow(violationRow); adoTransaction.DataRows.Add(violationRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand("insert \"Violation\" (\"rowVersion\",\"ViolationId\",\"RestrictionId\",\"AccountId\",\"Secur" + "ityId\",\"PositionTypeCode\",\"Description\") values (@rowVersion,@violationId,@restr" + "ictionId,@accountId,@securityId,@positionTypeCode,@description)"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@violationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, violationRow[violationTable.ViolationIdColumn])); sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionId)); sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description)); sqlCommand.ExecuteNonQuery(); // Return Statements return(violationRow.ViolationId); }
/// <summary>Deletes a Violation 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="violationId">The value for the ViolationId 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 violationId) { // Accessor for the Violation Table. ServerDataModel.ViolationDataTable violationTable = ServerDataModel.Violation; // Rule #1: Make sure the record exists before updating it. ServerDataModel.ViolationRow violationRow = violationTable.FindByViolationId(violationId); if ((violationRow == null)) { throw new Exception(string.Format("The Violation table does not have an element identified by {0}", violationId)); } // Rule #2: Optimistic Concurrency Check if ((violationRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Delete the child records. // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. violationRow[violationTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(violationRow); violationRow.Delete(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Violation\" set \"IsDeleted\" = 1 where \"ViolationId\"=@violationId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@violationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, violationId)); sqlCommand.ExecuteNonQuery(); }
/// <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(); }
/// <summary>ArchiveChildrens a Security 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="securityId">The value for the SecurityId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int securityId) { // Accessor for the Security Table. ServerDataModel.SecurityDataTable securityTable = ServerDataModel.Security; // This record can be used to iterate through all the children. ServerDataModel.SecurityRow securityRow = securityTable.FindBySecurityId(securityId); // Archive the child records. for (int index = 0; (index < securityRow.GetAccountRows().Length); index = (index + 1)) { ServerDataModel.AccountRow childAccountRow = securityRow.GetAccountRows()[index]; Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId().Length); index = (index + 1)) { ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId()[index]; Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId().Length); index = (index + 1)) { ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId()[index]; Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId()[index]; BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId()[index]; BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } for (int index = 0; (index < securityRow.GetBlotterMapRows().Length); index = (index + 1)) { ServerDataModel.BlotterMapRow childBlotterMapRow = securityRow.GetBlotterMapRows()[index]; BlotterMap.Archive(adoTransaction, sqlTransaction, childBlotterMapRow.RowVersion, childBlotterMapRow.BlotterMapId); } for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtDebtId().Length); index = (index + 1)) { ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtDebtId()[index]; Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtSettlementId().Length); index = (index + 1)) { ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtSettlementId()[index]; Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetCurrencyRows().Length); index = (index + 1)) { ServerDataModel.CurrencyRow childCurrencyRow = securityRow.GetCurrencyRows()[index]; Currency.ArchiveChildren(adoTransaction, sqlTransaction, childCurrencyRow.RowVersion, childCurrencyRow.CurrencyId); } for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquityEquityId().Length); index = (index + 1)) { ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquityEquityId()[index]; Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquitySettlementId().Length); index = (index + 1)) { ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquitySettlementId()[index]; Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSecurityId()[index]; Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId); } for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSettlementId()[index]; Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId); } for (int index = 0; (index < securityRow.GetPositionRows().Length); index = (index + 1)) { ServerDataModel.PositionRow childPositionRow = securityRow.GetPositionRows()[index]; Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode); } for (int index = 0; (index < securityRow.GetPositionTargetRows().Length); index = (index + 1)) { ServerDataModel.PositionTargetRow childPositionTargetRow = securityRow.GetPositionTargetRows()[index]; PositionTarget.Archive(adoTransaction, sqlTransaction, childPositionTargetRow.RowVersion, childPositionTargetRow.ModelId, childPositionTargetRow.SecurityId, childPositionTargetRow.PositionTypeCode); } for (int index = 0; (index < securityRow.GetPriceRows().Length); index = (index + 1)) { ServerDataModel.PriceRow childPriceRow = securityRow.GetPriceRows()[index]; Price.Archive(adoTransaction, sqlTransaction, childPriceRow.RowVersion, childPriceRow.SecurityId, childPriceRow.CurrencyId); } for (int index = 0; (index < securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.ProposedOrderRow childProposedOrderRow = securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSecurityId()[index]; ProposedOrder.Archive(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId); } for (int index = 0; (index < securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.ProposedOrderRow childProposedOrderRow = securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId()[index]; ProposedOrder.Archive(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId); } for (int index = 0; (index < securityRow.GetTaxLotRows().Length); index = (index + 1)) { ServerDataModel.TaxLotRow childTaxLotRow = securityRow.GetTaxLotRows()[index]; TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId); } for (int index = 0; (index < securityRow.GetViolationRows().Length); index = (index + 1)) { ServerDataModel.ViolationRow childViolationRow = securityRow.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. securityRow[securityTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(securityRow); securityRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Security\" set \"IsArchived\" = 1 where \"SecurityId\"=@securityId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Updates a Violation record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="rowVersion">The version number of the row</param> /// <param name="violationId">The value for the ViolationId column.</param> /// <param name="restrictionId">The value for the RestrictionId column.</param> /// <param name="accountId">The value for the AccountId column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="description">The value for the Description column.</param> public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int violationId, object restrictionId, object accountId, object securityId, object positionTypeCode, object description) { // Accessor for the Violation Table. ServerDataModel.ViolationDataTable violationTable = ServerDataModel.Violation; // Rule #1: Make sure the record exists before updating it. ServerDataModel.ViolationRow violationRow = violationTable.FindByViolationId(violationId); if ((violationRow == null)) { throw new Exception(string.Format("The Violation table does not have an element identified by {0}", violationId)); } // Rule #2: Optimistic Concurrency Check if ((violationRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Apply Defaults if ((restrictionId == null)) { restrictionId = violationRow[violationTable.RestrictionIdColumn]; } if ((accountId == null)) { accountId = violationRow[violationTable.AccountIdColumn]; } if ((securityId == null)) { securityId = violationRow[violationTable.SecurityIdColumn]; } if ((positionTypeCode == null)) { positionTypeCode = violationRow[violationTable.PositionTypeCodeColumn]; } if ((description == null)) { description = violationRow[violationTable.DescriptionColumn]; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Update the record in the ADO database. violationRow[violationTable.RowVersionColumn] = rowVersion; violationRow[violationTable.RestrictionIdColumn] = restrictionId; violationRow[violationTable.AccountIdColumn] = accountId; violationRow[violationTable.SecurityIdColumn] = securityId; violationRow[violationTable.PositionTypeCodeColumn] = positionTypeCode; violationRow[violationTable.DescriptionColumn] = description; adoTransaction.DataRows.Add(violationRow); // Update the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Violation\" set \"RowVersion\"=@rowVersion,\"RestrictionId\"=@restrictionId,\"A" + "ccountId\"=@accountId,\"SecurityId\"=@securityId,\"PositionTypeCode\"=@positionTypeCo" + "de,\"Description\"=@description where \"ViolationId\"=@violationId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@violationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, violationId)); sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionId)); sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description)); // Update the record in the SQL database. sqlCommand.ExecuteNonQuery(); }