Click here to Skip to main content
15,896,606 members
Articles / Web Development / ASP.NET

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

Rate me:
Please Sign up or sign in to vote.
4.96/5 (134 votes)
16 Aug 200540 min read 1.2M   3.9K   462  
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using SmartInstitute.Automation.Commands.Framework;
using SmartInstitute.Client.Automation.Commands.Security;
using SmartInstitute.Client.Automation;
using System.Reflection;

#endregion

namespace SmartInstitute.Client.Forms
{
	partial class LoginScreen : Form
	{
		private Color DarkBlue = Color.FromArgb(255, 0, 48, 156);
		private Color LightBlue = Color.FromArgb(255, 90, 126, 220);

		public LoginScreen()
		{
			InitializeComponent();

			this.ResizePanels();

			this.lblServer.Text = _Application.Settings.WebServiceUrl;

			Version version = Assembly.GetExecutingAssembly().GetName().Version;

			this.lblServer.Text += " " + version.ToString();
		}

		private void pnlCenter_Paint(object sender, PaintEventArgs e)
		{
			Color gradientEnd = Color.FromArgb(95, Color.White);
			Color gradientStart = Color.FromArgb(10, Color.White);

			// Draw the vertical separator at the middle

			// First half of the separator
			Rectangle rect = new Rectangle((this.pnlCenter.ClientRectangle.Width / 2) - 2, 10, 1, (this.pnlCenter.ClientRectangle.Height / 2) - 10);
			using (LinearGradientBrush brush = new LinearGradientBrush(rect, gradientStart, gradientEnd, 90))
			{
				e.Graphics.FillRectangle(brush, rect);
			}

			// Second half of the separator
			rect.Offset(0, (this.pnlCenter.ClientRectangle.Height / 2) - 10);
			using (LinearGradientBrush brush = new LinearGradientBrush(rect, gradientEnd, gradientStart, 90))
			{
				e.Graphics.FillRectangle(brush, rect);
			}

			// Draw the top and bottom gradient bars

			// left half
			Rectangle rectHorizontal = new Rectangle(0, 0, this.pnlCenter.ClientRectangle.Width / 2, 2);

			// right half
			Rectangle rectHorizontal2 = rectHorizontal;
			rectHorizontal2.Offset(this.pnlCenter.ClientRectangle.Width / 2, 0);

			// draw left half on top and bottom
			using (LinearGradientBrush brush = new LinearGradientBrush(rectHorizontal, gradientStart, gradientEnd, 0f))
			{
				e.Graphics.FillRectangle(brush, rectHorizontal);

				rectHorizontal.Offset(0, this.pnlCenter.ClientRectangle.Height - 2);
				e.Graphics.FillRectangle(brush, rectHorizontal);
			}

			// draw right half on top and bottom
			using (LinearGradientBrush brush = new LinearGradientBrush(rectHorizontal, gradientEnd, gradientStart, 0f))
			{
				e.Graphics.FillRectangle(brush, rectHorizontal2);

				rectHorizontal2.Offset(0, this.pnlCenter.ClientRectangle.Height - 2);
				e.Graphics.FillRectangle(brush, rectHorizontal2);
			}

		}

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

		private void pnlCenter_Resize(object sender, EventArgs e)
		{
			this.ResizePanels();
		}

		private void ResizePanels()
		{
			this.Invalidate();

			int centerX = (this.pnlCenter.ClientRectangle.Width / 2);

			// the logo is left to the center
			this.pnlLogo.Left = centerX - this.pnlLogo.Width - 10;

			// the login box is righ to the center
			this.pnlLogin.SetBounds(centerX + 10, this.pnlLogin.Top, this.pnlCenter.ClientRectangle.Width - centerX - 10, this.pnlLogin.Height);
		}

		/// <summary>
		/// Start login process
		/// </summary>
		private void Login()
		{
			string[] credential = new string[] { txtUserName.Text, txtPassword.Text };

			lblProgress.Visible = true;
			lblProgress.Refresh();

			loginProgress.Visible = true;
			loginProgress.Value = loginProgress.Minimum;

			worker.RunWorkerAsync(credential);
		}

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

		/// <summary>
		/// Call web service and validate credentials
		/// </summary>
		/// <param name="userName"></param>
		/// <param name="password"></param>
		/// <returns></returns>
		private void Authenticate(string userName, string password)
		{
			AuthenticateCommand command = new AuthenticateCommand(userName, password);
			((ICommand)command).Execute();

			worker.ReportProgress(1, "Loading...");
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);

			e.Graphics.DrawImage(SmartInstitute.App.Properties.Resources.RightArrow, 0, 0);

			if (base.Focused)
			{
				e.Graphics.DrawRectangle(Pens.Yellow, e.ClipRectangle);
			}
		}

		private void worker_DoWork(object sender, DoWorkEventArgs e)
		{
			// This method will run on a thread other than the UI thread.
			// Be sure not to manipulate any Windows Forms controls created
			// on the UI thread from this method.

			string[] credential = (string[])e.Argument;
			string userName = credential[0];
			string password = credential[1];

			this.Authenticate(userName, password);
	}

		private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
		{
			lblProgress.Text = (string)e.UserState;
			lblProgress.Refresh();
		}

		private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			if (null != e.Error)
			{
				MessageBox.Show(this, e.Error.Message, "Login Problem", 
					MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
			else
			{
				this.DialogResult = DialogResult.OK;
				this.Close();
			}

			lblProgress.Visible = loginProgress.Visible = false;
		}

		private void LoginScreen_Load(object sender, EventArgs e)
		{
			txtUserName.Focus();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions