using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Northwind
{
	/// <summary>
	/// Summary description for frmProducts.
	/// </summary>
	public class frmProducts : frmBaseForm
	{
		private System.Windows.Forms.DataGrid dgProducts;
		private System.Windows.Forms.Button btnLoadProducts;
		private System.Windows.Forms.Button btnSaveChanges;
		private System.Windows.Forms.Button btnClose;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmProducts()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmProducts));
			this.dgProducts = new System.Windows.Forms.DataGrid();
			this.btnLoadProducts = new System.Windows.Forms.Button();
			this.btnSaveChanges = new System.Windows.Forms.Button();
			this.btnClose = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dgProducts)).BeginInit();
			this.SuspendLayout();
			// 
			// miFOpen
			// 
			this.miFOpen.Text = "&Load";
			// 
			// miFNew
			// 
			this.miFNew.Visible = false;
			// 
			// ilImages
			// 
			this.ilImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilImages.ImageStream")));
			// 
			// tbToolBar
			// 
			this.tbToolBar.Name = "tbToolBar";
			this.tbToolBar.Size = new System.Drawing.Size(350, 28);
			this.tbToolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbToolBar_ButtonClick);
			// 
			// tbbOpen
			// 
			this.tbbOpen.ToolTipText = "Load";
			// 
			// tbbNew
			// 
			this.tbbNew.Visible = false;
			// 
			// dgProducts
			// 
			this.dgProducts.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.dgProducts.DataMember = "";
			this.dgProducts.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgProducts.Location = new System.Drawing.Point(0, 37);
			this.dgProducts.Name = "dgProducts";
			this.dgProducts.Size = new System.Drawing.Size(350, 221);
			this.dgProducts.TabIndex = 0;
			// 
			// btnLoadProducts
			// 
			this.btnLoadProducts.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnLoadProducts.Location = new System.Drawing.Point(10, 262);
			this.btnLoadProducts.Name = "btnLoadProducts";
			this.btnLoadProducts.Size = new System.Drawing.Size(105, 26);
			this.btnLoadProducts.TabIndex = 1;
			this.btnLoadProducts.Text = "Load Products";
			this.btnLoadProducts.Click += new System.EventHandler(this.btnLoadProducts_Click);
			// 
			// btnSaveChanges
			// 
			this.btnSaveChanges.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.btnSaveChanges.Location = new System.Drawing.Point(130, 262);
			this.btnSaveChanges.Name = "btnSaveChanges";
			this.btnSaveChanges.Size = new System.Drawing.Size(105, 26);
			this.btnSaveChanges.TabIndex = 2;
			this.btnSaveChanges.Text = "Save Changes";
			this.btnSaveChanges.Click += new System.EventHandler(this.btnSaveChanges_Click);
			// 
			// btnClose
			// 
			this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnClose.Location = new System.Drawing.Point(250, 262);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(90, 26);
			this.btnClose.TabIndex = 3;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// frmProducts
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
			this.ClientSize = new System.Drawing.Size(350, 314);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnSaveChanges);
			this.Controls.Add(this.btnLoadProducts);
			this.Controls.Add(this.dgProducts);
			this.Name = "frmProducts";
			this.Text = "Products";
			this.Controls.SetChildIndex(this.dgProducts, 0);
			this.Controls.SetChildIndex(this.btnLoadProducts, 0);
			this.Controls.SetChildIndex(this.btnSaveChanges, 0);
			this.Controls.SetChildIndex(this.btnClose, 0);
			this.Controls.SetChildIndex(this.tbToolBar, 0);
			((System.ComponentModel.ISupportInitialize)(this.dgProducts)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void btnLoadProducts_Click(object sender, System.EventArgs e)
		{

			NorthwindDataAccess nwDA = new NorthwindDataAccess();
			dgProducts.DataSource = nwDA.RetrieveProducts();

		}

		private void btnSaveChanges_Click(object sender, System.EventArgs e)
		{
			NorthwindDataAccess nwDA = new NorthwindDataAccess();
			nwDA.UpdateProducts((dsProducts.ProductsDataTable)
				dgProducts.DataSource);
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{

			this.Close();

		}

		private void tbToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button.Equals(tbbOpen))
				btnLoadProducts_Click(sender, e);
		}
	}
}
