/// <summary>Archives a ProposedOrderTree 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="parentId">The value for the ParentId column.</param> /// <param name="childId">The value for the ChildId 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 parentId, int childId) { // Accessor for the ProposedOrderTree Table. ServerDataModel.ProposedOrderTreeDataTable proposedOrderTreeTable = ServerDataModel.ProposedOrderTree; // Rule #1: Make sure the record exists before updating it. ServerDataModel.ProposedOrderTreeRow proposedOrderTreeRow = proposedOrderTreeTable.FindByParentIdChildId(parentId, childId); if ((proposedOrderTreeRow == null)) { throw new Exception(string.Format("The ProposedOrderTree table does not have an element identified by {0}{0}", parentId, childId)); } // Rule #2: Optimistic Concurrency Check if ((proposedOrderTreeRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. proposedOrderTreeRow[proposedOrderTreeTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(proposedOrderTreeRow); proposedOrderTreeRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"ProposedOrderTree\" set \"IsArchived\" = 1 where \"ParentId\"=@parentId and \"C" + "hildId\"=@childId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@parentId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, parentId)); sqlCommand.Parameters.Add(new SqlParameter("@childId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, childId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Inserts a ProposedOrderTree record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="parentId">The value for the ParentId column.</param> /// <param name="childId">The value for the ChildId column.</param> public static void Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int parentId, int childId) { // Accessor for the ProposedOrderTree Table. ServerDataModel.ProposedOrderTreeDataTable proposedOrderTreeTable = ServerDataModel.ProposedOrderTree; // Apply Defaults // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Insert the record into the ADO database. ServerDataModel.ProposedOrderTreeRow proposedOrderTreeRow = proposedOrderTreeTable.NewProposedOrderTreeRow(); proposedOrderTreeRow[proposedOrderTreeTable.RowVersionColumn] = rowVersion; proposedOrderTreeRow[proposedOrderTreeTable.ParentIdColumn] = parentId; proposedOrderTreeRow[proposedOrderTreeTable.ChildIdColumn] = childId; proposedOrderTreeTable.AddProposedOrderTreeRow(proposedOrderTreeRow); adoTransaction.DataRows.Add(proposedOrderTreeRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand("insert \"ProposedOrderTree\" (\"rowVersion\",\"ParentId\",\"ChildId\") values (@rowVersio" + "n,@parentId,@childId)"); 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("@parentId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, parentId)); sqlCommand.Parameters.Add(new SqlParameter("@childId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, childId)); sqlCommand.ExecuteNonQuery(); }
/// <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(); }