Esempio n. 1
0
        /// <summary>Deletes a ProposedOrder 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="proposedOrderId">The value for the ProposedOrderId 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 proposedOrderId)
        {
            // Accessor for the ProposedOrder Table.
            ServerDataModel.ProposedOrderDataTable proposedOrderTable = ServerDataModel.ProposedOrder;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ProposedOrderRow proposedOrderRow = proposedOrderTable.FindByProposedOrderId(proposedOrderId);
            if ((proposedOrderRow == null))
            {
                throw new Exception(string.Format("The ProposedOrder table does not have an element identified by {0}", proposedOrderId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((proposedOrderRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Delete the child records.
            for (int index = 0; (index < proposedOrderRow.GetProposedOrderTreeRowsByFKProposedOrderProposedOrderTreeChildId().Length); index = (index + 1))
            {
                ServerDataModel.ProposedOrderTreeRow childProposedOrderTreeRow = proposedOrderRow.GetProposedOrderTreeRowsByFKProposedOrderProposedOrderTreeChildId()[index];
                ProposedOrderTree.Delete(adoTransaction, sqlTransaction, childProposedOrderTreeRow.RowVersion, childProposedOrderTreeRow.ParentId, childProposedOrderTreeRow.ChildId);
            }
            for (int index = 0; (index < proposedOrderRow.GetProposedOrderTreeRowsByFKProposedOrderProposedOrderTreeParentId().Length); index = (index + 1))
            {
                ServerDataModel.ProposedOrderTreeRow childProposedOrderTreeRow = proposedOrderRow.GetProposedOrderTreeRowsByFKProposedOrderProposedOrderTreeParentId()[index];
                ProposedOrderTree.Delete(adoTransaction, sqlTransaction, childProposedOrderTreeRow.RowVersion, childProposedOrderTreeRow.ParentId, childProposedOrderTreeRow.ChildId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            proposedOrderRow[proposedOrderTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(proposedOrderRow);
            proposedOrderRow.Delete();
            // Delete the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"ProposedOrder\" set \"IsDeleted\" = 1 where \"ProposedOrderId\"=@proposedOrder" +
                                                   "Id");

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