using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Web.Services;
using Microsoft.Web.Services.Dime;

namespace InfoProviderClient
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox lastNameTextBox;
		private System.Windows.Forms.Button fetchButton;
		private System.Windows.Forms.Label fullNameLabel;
		private System.Windows.Forms.Label recordLabel;
		private System.Windows.Forms.PictureBox personPictureBox;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.lastNameTextBox = new System.Windows.Forms.TextBox();
			this.fetchButton = new System.Windows.Forms.Button();
			this.fullNameLabel = new System.Windows.Forms.Label();
			this.recordLabel = new System.Windows.Forms.Label();
			this.personPictureBox = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(32, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Last Name";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(32, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "Full Name";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(32, 96);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(72, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "Record";
			// 
			// lastNameTextBox
			// 
			this.lastNameTextBox.Location = new System.Drawing.Point(112, 16);
			this.lastNameTextBox.Name = "lastNameTextBox";
			this.lastNameTextBox.Size = new System.Drawing.Size(144, 20);
			this.lastNameTextBox.TabIndex = 3;
			this.lastNameTextBox.Text = "";
			// 
			// fetchButton
			// 
			this.fetchButton.Location = new System.Drawing.Point(264, 16);
			this.fetchButton.Name = "fetchButton";
			this.fetchButton.TabIndex = 4;
			this.fetchButton.Text = "Fetch";
			this.fetchButton.Click += new System.EventHandler(this.fetchButton_Click);
			// 
			// fullNameLabel
			// 
			this.fullNameLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.fullNameLabel.Location = new System.Drawing.Point(112, 56);
			this.fullNameLabel.Name = "fullNameLabel";
			this.fullNameLabel.Size = new System.Drawing.Size(144, 16);
			this.fullNameLabel.TabIndex = 5;
			// 
			// recordLabel
			// 
			this.recordLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.recordLabel.Location = new System.Drawing.Point(112, 96);
			this.recordLabel.Name = "recordLabel";
			this.recordLabel.Size = new System.Drawing.Size(232, 16);
			this.recordLabel.TabIndex = 6;
			// 
			// personPictureBox
			// 
			this.personPictureBox.Location = new System.Drawing.Point(24, 128);
			this.personPictureBox.Name = "personPictureBox";
			this.personPictureBox.Size = new System.Drawing.Size(304, 272);
			this.personPictureBox.TabIndex = 7;
			this.personPictureBox.TabStop = false;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(352, 413);
			this.Controls.Add(this.personPictureBox);
			this.Controls.Add(this.recordLabel);
			this.Controls.Add(this.fullNameLabel);
			this.Controls.Add(this.fetchButton);
			this.Controls.Add(this.lastNameTextBox);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void fetchButton_Click(object sender, System.EventArgs e)
		{
			using(new AutoWaitCursor())
			{
				try
				{
					string lastName = lastNameTextBox.Text;
					if (lastName != null && lastName.Trim() != "")
					{
						personPictureBox.Image = null;

						//We are using the WSE specific proxy generated after we enabled 
						// this project for WSE Enhancement using the WSE Settings tool.

						InfoWithAttachment.InformationProviderWse service = 
							new InfoWithAttachment.InformationProviderWse();

						fullNameLabel.Text = 
							service.getFullName(lastName);
				
						recordLabel.Text = 
							service.getRecord(lastName);

						String result = service.getPicture(lastName);

						if (service.ResponseSoapContext.Attachments.Count > 0)
						{
							DimeAttachment attachment = service.ResponseSoapContext.Attachments[0];
						
							Bitmap theBitmap = new Bitmap(attachment.Stream);
							personPictureBox.Image = (Image) theBitmap;	
						}
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
		}
	}
}
