Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
        /// <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();
        }