using System;
using System.Data;
using Microsoft.SqlServer.Server;
using System.Data.SqlClient;
using System.Data.SqlTypes;


public class PubsTriggers
{
	// used for trigger when rows are deleted from
	// the jobs table. Deleted jobs are moved to
	// the obsoletejobs table

	// Change this to reflect the real attribute values
	//[SqlTrigger("name", "tablename", "FOR clause")]
	public static void AddToObsolete()
	{
		int rowsAffected = 0;
		// get the trigger context so you can tell what is
		// going on
		// this trigger is for deletes
		// Make a command
		// make a command the inserts the deleted row into
		// the obsoletejobs table
		// move the rows

		if (rowsAffected == 0)
		{
			// something bad happened, rollback
		}
	}
	// Used for trigger on authors table
	// prevents the authors contract from
	// being changed from 1 to 0 if any
	// author (of those being updated) 
	// has a book that pays a royality
	// greater than 30.
	// All publishers should have this
	// trigger in their databases

	// Change this to reflect the real attribute values
	//[SqlTrigger("name", "tablename", "FOR clause")]
	
	public static void AuthorCheckContract()
	{
			// get the trigger context for later
			// this is used on for updates
			{
				// check to see if the contract is being changed
				// from 1 to 0
				//
				SqlCommand cmd = null;

				try
				{
					if ((int)cmd.ExecuteScalar() > 0)
					{
						// if you get to here then at
						// least one of the authors in
						// those in the updated table
						// had a book with a royalty 
						// greater than 30
					}
				}
				catch (Exception e)
				{
					// do nothing, means contract was not part of the update statement
				}
			}
		}
	}
