Exemple #1
0
        /// <summary>Inserts a OrderTree 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>
        /// <param name="isDeleted">The value for the IsDeleted column.</param>
        public static void Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int parentId, int childId, object isDeleted)
        {
            // Accessor for the OrderTree Table.
            ServerDataModel.OrderTreeDataTable orderTreeTable = ServerDataModel.OrderTree;
            // Apply Defaults
            if ((isDeleted == null))
            {
                isDeleted = false;
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerDataModel.OrderTreeRow orderTreeRow = orderTreeTable.NewOrderTreeRow();
            orderTreeRow[orderTreeTable.RowVersionColumn] = rowVersion;
            orderTreeRow[orderTreeTable.ParentIdColumn]   = parentId;
            orderTreeRow[orderTreeTable.ChildIdColumn]    = childId;
            orderTreeRow[orderTreeTable.IsDeletedColumn]  = isDeleted;
            orderTreeTable.AddOrderTreeRow(orderTreeRow);
            adoTransaction.DataRows.Add(orderTreeRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"OrderTree\" (\"rowVersion\",\"ParentId\",\"ChildId\",\"IsDeleted\") values (@rowVe" +
                                                   "rsion,@parentId,@childId,@isDeleted)");

            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.Parameters.Add(new SqlParameter("@isDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isDeleted));
            sqlCommand.ExecuteNonQuery();
        }
Exemple #2
0
        /// <summary>Archives a OrderTree 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 OrderTree Table.
            ServerDataModel.OrderTreeDataTable orderTreeTable = ServerDataModel.OrderTree;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.OrderTreeRow orderTreeRow = orderTreeTable.FindByParentIdChildId(parentId, childId);
            if ((orderTreeRow == null))
            {
                throw new Exception(string.Format("The OrderTree table does not have an element identified by {0}{0}", parentId, childId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((orderTreeRow.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.
            orderTreeRow[orderTreeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(orderTreeRow);
            orderTreeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"OrderTree\" set \"IsArchived\" = 1 where \"ParentId\"=@parentId and \"ChildId\"=" +
                                                   "@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>Deletes a Order 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="orderId">The value for the OrderId 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 orderId)
        {
            // Accessor for the Order Table.
            ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId);
            if ((orderRow == null))
            {
                throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((orderRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Delete the child records.
            for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId().Length); index = (index + 1))
            {
                ServerDataModel.OrderTreeRow childOrderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId()[index];
                OrderTree.Delete(adoTransaction, sqlTransaction, childOrderTreeRow.RowVersion, childOrderTreeRow.ParentId, childOrderTreeRow.ChildId);
            }
            for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId().Length); index = (index + 1))
            {
                ServerDataModel.OrderTreeRow childOrderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId()[index];
                OrderTree.Delete(adoTransaction, sqlTransaction, childOrderTreeRow.RowVersion, childOrderTreeRow.ParentId, childOrderTreeRow.ChildId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            orderRow[orderTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(orderRow);
            orderRow.Delete();
            // Delete the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Order\" set \"IsDeleted\" = 1 where \"OrderId\"=@orderId");

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