using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Medivators.Reporting
{
	public partial class dlgAdminPass : Form
	{
		private int _attempts = 0;

		public dlgAdminPass()
		{
			InitializeComponent();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;

			if (this.txtKey.Text != null && this.txtKey.Text.Length > 0)
				if (pwd.Verify(this.txtKey.Text) == pwd.VerifyResult.Valid)
					this.DialogResult = DialogResult.OK;
				else
					_attempts += 1;

			if (this.DialogResult != DialogResult.OK && _attempts < 3)
			{
				Console.Beep();
				this.txtKey.SelectAll();
			}
			else
				this.Hide();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.Hide();
		}

		private void dlgAdminPass_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (_attempts < 3 && this.DialogResult != DialogResult.OK)
				e.Cancel= true;
		}

	}
}