//------------------------------------------------------------------------------
// <autogenerated>
//     This code was generated by CodeSmith.
//     Version: 2.5.18.0
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;

namespace CSharpCodeGeneratorSample
{
	#region Customer
	/// <summary>
	/// This object represents the properties and methods of a Customer.
	/// </summary>
	public class Customer
	{
		protected string _id;
		protected string _companyName = String.Empty;
		protected string _contactName = String.Empty;
		protected string _contactTitle = String.Empty;
		protected string _address = String.Empty;
		protected string _city = String.Empty;
		protected string _region = String.Empty;
		protected string _postalCode = String.Empty;
		protected string _country = String.Empty;
		protected string _phone = String.Empty;
		protected string _fax = String.Empty;
		
		public Customer()
		{
		}
		
		public Customer(string id)
		{
			SqlService sql = new SqlService();
			sql.AddParameter("@CustomerID", SqlDbType.NChar, id);
			SqlDataReader reader = sql.ExecuteSqlReader("SELECT * FROM Customers WHERE CustomerID = '" + id.ToString() + "'");
			
			if (reader.Read()) 
			{
				this.LoadFromReader(reader);
				reader.Close();
			}
			else
			{
				if (!reader.IsClosed) reader.Close();
				throw new ApplicationException("Customer does not exist.");
			}
		}
		
		public Customer(SqlDataReader reader)
		{
			this.LoadFromReader(reader);
		}
		
		protected void LoadFromReader(SqlDataReader reader)
		{
			if (reader != null && !reader.IsClosed)
			{
				_id = reader.GetString(0);
				if (!reader.IsDBNull(1)) _companyName = reader.GetString(1);
				if (!reader.IsDBNull(2)) _contactName = reader.GetString(2);
				if (!reader.IsDBNull(3)) _contactTitle = reader.GetString(3);
				if (!reader.IsDBNull(4)) _address = reader.GetString(4);
				if (!reader.IsDBNull(5)) _city = reader.GetString(5);
				if (!reader.IsDBNull(6)) _region = reader.GetString(6);
				if (!reader.IsDBNull(7)) _postalCode = reader.GetString(7);
				if (!reader.IsDBNull(8)) _country = reader.GetString(8);
				if (!reader.IsDBNull(9)) _phone = reader.GetString(9);
				if (!reader.IsDBNull(10)) _fax = reader.GetString(10);
			}
		}
		
		#region Public Properties
		public string Id
		{
			get {return _id;}
		}
		
		public string CompanyName
		{
			get {return _companyName;}
			set {_companyName = value;}
		}

		public string ContactName
		{
			get {return _contactName;}
			set {_contactName = value;}
		}

		public string ContactTitle
		{
			get {return _contactTitle;}
			set {_contactTitle = value;}
		}

		public string Address
		{
			get {return _address;}
			set {_address = value;}
		}

		public string City
		{
			get {return _city;}
			set {_city = value;}
		}

		public string Region
		{
			get {return _region;}
			set {_region = value;}
		}

		public string PostalCode
		{
			get {return _postalCode;}
			set {_postalCode = value;}
		}

		public string Country
		{
			get {return _country;}
			set {_country = value;}
		}

		public string Phone
		{
			get {return _phone;}
			set {_phone = value;}
		}

		public string Fax
		{
			get {return _fax;}
			set {_fax = value;}
		}
		#endregion
		
		public static Customer GetCustomer(string id)
		{
			return new Customer(id);
		}
	}
	#endregion
	
	#region Order
	/// <summary>
	/// This object represents the properties and methods of a Order.
	/// </summary>
	public class Order
	{
		protected int _id;
		protected string _customerID = String.Empty;
		protected int _employeeID;
		protected DateTime _orderDate;
		protected DateTime _requiredDate;
		protected DateTime _shippedDate;
		protected int _shipVia;
		protected decimal _freight;
		protected string _shipName = String.Empty;
		protected string _shipAddress = String.Empty;
		protected string _shipCity = String.Empty;
		protected string _shipRegion = String.Empty;
		protected string _shipPostalCode = String.Empty;
		protected string _shipCountry = String.Empty;
		
		public Order()
		{
		}
		
		public Order(int id)
		{
			SqlService sql = new SqlService();
			sql.AddParameter("@OrderID", SqlDbType.Int, id);
			SqlDataReader reader = sql.ExecuteSqlReader("SELECT * FROM Orders WHERE OrderID = '" + id.ToString() + "'");
			
			if (reader.Read()) 
			{
				this.LoadFromReader(reader);
				reader.Close();
			}
			else
			{
				if (!reader.IsClosed) reader.Close();
				throw new ApplicationException("Order does not exist.");
			}
		}
		
		public Order(SqlDataReader reader)
		{
			this.LoadFromReader(reader);
		}
		
		protected void LoadFromReader(SqlDataReader reader)
		{
			if (reader != null && !reader.IsClosed)
			{
				_id = reader.GetInt32(0);
				if (!reader.IsDBNull(1)) _customerID = reader.GetString(1);
				if (!reader.IsDBNull(2)) _employeeID = reader.GetInt32(2);
				if (!reader.IsDBNull(3)) _orderDate = reader.GetDateTime(3);
				if (!reader.IsDBNull(4)) _requiredDate = reader.GetDateTime(4);
				if (!reader.IsDBNull(5)) _shippedDate = reader.GetDateTime(5);
				if (!reader.IsDBNull(6)) _shipVia = reader.GetInt32(6);
				if (!reader.IsDBNull(7)) _freight = reader.GetDecimal(7);
				if (!reader.IsDBNull(8)) _shipName = reader.GetString(8);
				if (!reader.IsDBNull(9)) _shipAddress = reader.GetString(9);
				if (!reader.IsDBNull(10)) _shipCity = reader.GetString(10);
				if (!reader.IsDBNull(11)) _shipRegion = reader.GetString(11);
				if (!reader.IsDBNull(12)) _shipPostalCode = reader.GetString(12);
				if (!reader.IsDBNull(13)) _shipCountry = reader.GetString(13);
			}
		}
		
		#region Public Properties
		public int Id
		{
			get {return _id;}
		}
		
		public string CustomerID
		{
			get {return _customerID;}
			set {_customerID = value;}
		}

		public int EmployeeID
		{
			get {return _employeeID;}
			set {_employeeID = value;}
		}

		public DateTime OrderDate
		{
			get {return _orderDate;}
			set {_orderDate = value;}
		}

		public DateTime RequiredDate
		{
			get {return _requiredDate;}
			set {_requiredDate = value;}
		}

		public DateTime ShippedDate
		{
			get {return _shippedDate;}
			set {_shippedDate = value;}
		}

		public int ShipVia
		{
			get {return _shipVia;}
			set {_shipVia = value;}
		}

		public decimal Freight
		{
			get {return _freight;}
			set {_freight = value;}
		}

		public string ShipName
		{
			get {return _shipName;}
			set {_shipName = value;}
		}

		public string ShipAddress
		{
			get {return _shipAddress;}
			set {_shipAddress = value;}
		}

		public string ShipCity
		{
			get {return _shipCity;}
			set {_shipCity = value;}
		}

		public string ShipRegion
		{
			get {return _shipRegion;}
			set {_shipRegion = value;}
		}

		public string ShipPostalCode
		{
			get {return _shipPostalCode;}
			set {_shipPostalCode = value;}
		}

		public string ShipCountry
		{
			get {return _shipCountry;}
			set {_shipCountry = value;}
		}
		#endregion
		
		public static Order GetOrder(int id)
		{
			return new Order(id);
		}
	}
	#endregion
	
	#region Product
	/// <summary>
	/// This object represents the properties and methods of a Product.
	/// </summary>
	public class Product
	{
		protected int _id;
		protected string _productName = String.Empty;
		protected int _supplierID;
		protected int _categoryID;
		protected string _quantityPerUnit = String.Empty;
		protected decimal _unitPrice;
		protected short _unitsInStock;
		protected short _unitsOnOrder;
		protected short _reorderLevel;
		protected bool _discontinued;
		
		public Product()
		{
		}
		
		public Product(int id)
		{
			SqlService sql = new SqlService();
			sql.AddParameter("@ProductID", SqlDbType.Int, id);
			SqlDataReader reader = sql.ExecuteSqlReader("SELECT * FROM Products WHERE ProductID = '" + id.ToString() + "'");
			
			if (reader.Read()) 
			{
				this.LoadFromReader(reader);
				reader.Close();
			}
			else
			{
				if (!reader.IsClosed) reader.Close();
				throw new ApplicationException("Product does not exist.");
			}
		}
		
		public Product(SqlDataReader reader)
		{
			this.LoadFromReader(reader);
		}
		
		protected void LoadFromReader(SqlDataReader reader)
		{
			if (reader != null && !reader.IsClosed)
			{
				_id = reader.GetInt32(0);
				if (!reader.IsDBNull(1)) _productName = reader.GetString(1);
				if (!reader.IsDBNull(2)) _supplierID = reader.GetInt32(2);
				if (!reader.IsDBNull(3)) _categoryID = reader.GetInt32(3);
				if (!reader.IsDBNull(4)) _quantityPerUnit = reader.GetString(4);
				if (!reader.IsDBNull(5)) _unitPrice = reader.GetDecimal(5);
				if (!reader.IsDBNull(6)) _unitsInStock = reader.GetInt16(6);
				if (!reader.IsDBNull(7)) _unitsOnOrder = reader.GetInt16(7);
				if (!reader.IsDBNull(8)) _reorderLevel = reader.GetInt16(8);
				if (!reader.IsDBNull(9)) _discontinued = reader.GetBoolean(9);
			}
		}
		
		#region Public Properties
		public int Id
		{
			get {return _id;}
		}
		
		public string ProductName
		{
			get {return _productName;}
			set {_productName = value;}
		}

		public int SupplierID
		{
			get {return _supplierID;}
			set {_supplierID = value;}
		}

		public int CategoryID
		{
			get {return _categoryID;}
			set {_categoryID = value;}
		}

		public string QuantityPerUnit
		{
			get {return _quantityPerUnit;}
			set {_quantityPerUnit = value;}
		}

		public decimal UnitPrice
		{
			get {return _unitPrice;}
			set {_unitPrice = value;}
		}

		public short UnitsInStock
		{
			get {return _unitsInStock;}
			set {_unitsInStock = value;}
		}

		public short UnitsOnOrder
		{
			get {return _unitsOnOrder;}
			set {_unitsOnOrder = value;}
		}

		public short ReorderLevel
		{
			get {return _reorderLevel;}
			set {_reorderLevel = value;}
		}

		public bool Discontinued
		{
			get {return _discontinued;}
			set {_discontinued = value;}
		}
		#endregion
		
		public static Product GetProduct(int id)
		{
			return new Product(id);
		}
	}
	#endregion
	
	#region Shipper
	/// <summary>
	/// This object represents the properties and methods of a Shipper.
	/// </summary>
	public class Shipper
	{
		protected int _id;
		protected string _companyName = String.Empty;
		protected string _phone = String.Empty;
		
		public Shipper()
		{
		}
		
		public Shipper(int id)
		{
			SqlService sql = new SqlService();
			sql.AddParameter("@ShipperID", SqlDbType.Int, id);
			SqlDataReader reader = sql.ExecuteSqlReader("SELECT * FROM Shippers WHERE ShipperID = '" + id.ToString() + "'");
			
			if (reader.Read()) 
			{
				this.LoadFromReader(reader);
				reader.Close();
			}
			else
			{
				if (!reader.IsClosed) reader.Close();
				throw new ApplicationException("Shipper does not exist.");
			}
		}
		
		public Shipper(SqlDataReader reader)
		{
			this.LoadFromReader(reader);
		}
		
		protected void LoadFromReader(SqlDataReader reader)
		{
			if (reader != null && !reader.IsClosed)
			{
				_id = reader.GetInt32(0);
				if (!reader.IsDBNull(1)) _companyName = reader.GetString(1);
				if (!reader.IsDBNull(2)) _phone = reader.GetString(2);
			}
		}
		
		#region Public Properties
		public int Id
		{
			get {return _id;}
		}
		
		public string CompanyName
		{
			get {return _companyName;}
			set {_companyName = value;}
		}

		public string Phone
		{
			get {return _phone;}
			set {_phone = value;}
		}
		#endregion
		
		public static Shipper GetShipper(int id)
		{
			return new Shipper(id);
		}
	}
	#endregion
}
