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

namespace Northwind
{
	/// <summary>
	/// Summary description for frmAbout.
	/// </summary>
	public class frmAbout : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListView lvComponents;
		private System.Windows.Forms.ColumnHeader Component;
		private System.Windows.Forms.ColumnHeader Version;
		private System.Windows.Forms.Label lblProduct;
		private System.Windows.Forms.Label lblVersion;
		private System.Windows.Forms.Label lblCompany;
		private System.Windows.Forms.Label lblCopyright;
		private System.Windows.Forms.Label lblDescription;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.PictureBox pbLogo;
		private System.Windows.Forms.Label label1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmAbout()
		{
			//
			// 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(frmAbout));
			this.pbLogo = new System.Windows.Forms.PictureBox();
			this.lblProduct = new System.Windows.Forms.Label();
			this.lvComponents = new System.Windows.Forms.ListView();
			this.Component = new System.Windows.Forms.ColumnHeader();
			this.Version = new System.Windows.Forms.ColumnHeader();
			this.lblVersion = new System.Windows.Forms.Label();
			this.lblCompany = new System.Windows.Forms.Label();
			this.lblCopyright = new System.Windows.Forms.Label();
			this.lblDescription = new System.Windows.Forms.Label();
			this.btnOK = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// pbLogo
			// 
			this.pbLogo.Image = ((System.Drawing.Image)(resources.GetObject("pbLogo.Image")));
			this.pbLogo.Location = new System.Drawing.Point(7, 7);
			this.pbLogo.Name = "pbLogo";
			this.pbLogo.Size = new System.Drawing.Size(129, 130);
			this.pbLogo.TabIndex = 0;
			this.pbLogo.TabStop = false;
			// 
			// lblProduct
			// 
			this.lblProduct.Location = new System.Drawing.Point(147, 7);
			this.lblProduct.Name = "lblProduct";
			this.lblProduct.Size = new System.Drawing.Size(206, 20);
			this.lblProduct.TabIndex = 1;
			this.lblProduct.Text = "Product";
			// 
			// lvComponents
			// 
			this.lvComponents.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						   this.Component,
																						   this.Version});
			this.lvComponents.Location = new System.Drawing.Point(87, 201);
			this.lvComponents.Name = "lvComponents";
			this.lvComponents.Size = new System.Drawing.Size(260, 84);
			this.lvComponents.TabIndex = 2;
			this.lvComponents.View = System.Windows.Forms.View.Details;
			// 
			// Component
			// 
			this.Component.Text = "Component";
			this.Component.Width = 178;
			// 
			// Version
			// 
			this.Version.Text = "Version";
			this.Version.Width = 100;
			// 
			// lblVersion
			// 
			this.lblVersion.Location = new System.Drawing.Point(147, 28);
			this.lblVersion.Name = "lblVersion";
			this.lblVersion.Size = new System.Drawing.Size(206, 20);
			this.lblVersion.TabIndex = 3;
			this.lblVersion.Text = "Version";
			// 
			// lblCompany
			// 
			this.lblCompany.Location = new System.Drawing.Point(147, 49);
			this.lblCompany.Name = "lblCompany";
			this.lblCompany.Size = new System.Drawing.Size(206, 19);
			this.lblCompany.TabIndex = 4;
			this.lblCompany.Text = "Company";
			// 
			// lblCopyright
			// 
			this.lblCopyright.Location = new System.Drawing.Point(147, 69);
			this.lblCopyright.Name = "lblCopyright";
			this.lblCopyright.Size = new System.Drawing.Size(206, 27);
			this.lblCopyright.TabIndex = 5;
			this.lblCopyright.Text = "Copyright";
			// 
			// lblDescription
			// 
			this.lblDescription.Location = new System.Drawing.Point(147, 104);
			this.lblDescription.Name = "lblDescription";
			this.lblDescription.Size = new System.Drawing.Size(206, 76);
			this.lblDescription.TabIndex = 6;
			this.lblDescription.Text = "Description";
			// 
			// btnOK
			// 
			this.btnOK.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnOK.Location = new System.Drawing.Point(273, 298);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(63, 20);
			this.btnOK.TabIndex = 7;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(93, 180);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(207, 20);
			this.label1.TabIndex = 8;
			this.label1.Text = "Referenced Assemblies";
			// 
			// frmAbout
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnOK;
			this.ClientSize = new System.Drawing.Size(354, 330);
			this.ControlBox = false;
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.lblDescription);
			this.Controls.Add(this.lblCopyright);
			this.Controls.Add(this.lblCompany);
			this.Controls.Add(this.lblVersion);
			this.Controls.Add(this.lvComponents);
			this.Controls.Add(this.lblProduct);
			this.Controls.Add(this.pbLogo);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmAbout";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "About";
			this.Load += new System.EventHandler(this.frmAbout_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

			Assembly asbly = Assembly.GetExecutingAssembly();
			object[] attrs = asbly.GetCustomAttributes(true);

			foreach(Attribute att in attrs)
			{
				if(att is AssemblyCompanyAttribute)
				{
					lblCompany.Text =
						((AssemblyCompanyAttribute)att).Company;
				}
				else if(att is AssemblyCopyrightAttribute)
				{
					lblCopyright.Text =
						((AssemblyCopyrightAttribute)att).Copyright;
				}
				else if(att is AssemblyDescriptionAttribute)
				{
					lblDescription.Text =		
						((AssemblyDescriptionAttribute)att).Description;
				}
				else if(att is AssemblyProductAttribute)
				{
					lblProduct.Text =
						((AssemblyProductAttribute)att).Product;
				}
				else if(att is AssemblyTitleAttribute)
				{
					this.Text = "About " + 
						((AssemblyTitleAttribute)att).Title;
				}
				else
				{
					Trace.WriteLine(typeof(Attribute).Name);
				}
			}

			lblVersion.Text = "Version " +
				asbly.GetName().Version.ToString();

			LoadComponentVersions();

		}

		private void LoadComponentVersions()
		{
			foreach(AssemblyName an in Assembly.GetEntryAssembly().
				GetReferencedAssemblies())
			{
				lvComponents.Items.Add(new ListViewItem(
					new string[]{an.Name, an.Version.ToString()}));
			}
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

	}
}
