/***********************************************************************************************
* Activate.cs
*
* Developed by     : SafeNet, Inc
*
* Copyright (C) 2009 SafeNet, Inc. All rights reserved.
*
* Purpose          : Activate password input form. Source file for Activate passowrd form.

***********************************************************************************************/
//Include name space
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Sproeval
{
    /// <summary>
    /// Activate password input form.Source file for Activate passowrd form
    /// Here we get user input for Acticate passwords and perform some validation.
    /// </summary>
    public class ActivateForm : System.Windows.Forms.Form
    {
        // Duffrent resource control declaration here
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox AP1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox AP2;
        private System.Windows.Forms.Button OKBtn;
        private System.Windows.Forms.Button CancelBtn;
    
        private System.ComponentModel.Container components = null;

        public ActivateForm()
        {
            
            // Required for Windows Form Designer support
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        // Distroy Form resource at time of closing the form.
        /// </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(ActivateForm));
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.AP1 = new System.Windows.Forms.TextBox();
			this.CancelBtn = new System.Windows.Forms.Button();
			this.AP2 = new System.Windows.Forms.TextBox();
			this.OKBtn = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 30);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(120, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Activation Password1";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 64);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(120, 16);
			this.label2.TabIndex = 2;
			this.label2.Text = "Activation Password2";
			// 
			// AP1
			// 
			this.AP1.Location = new System.Drawing.Point(144, 24);
			this.AP1.MaxLength = 4;
			this.AP1.Name = "AP1";
			this.AP1.Size = new System.Drawing.Size(64, 20);
			this.AP1.TabIndex = 0;
			this.AP1.Text = "";
			// 
			// CancelBtn
			// 
			this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.CancelBtn.Location = new System.Drawing.Point(133, 96);
			this.CancelBtn.Name = "CancelBtn";
			this.CancelBtn.Size = new System.Drawing.Size(75, 25);
			this.CancelBtn.TabIndex = 3;
			this.CancelBtn.Text = "Cancel";
			this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
			// 
			// AP2
			// 
			this.AP2.Location = new System.Drawing.Point(144, 60);
			this.AP2.MaxLength = 4;
			this.AP2.Name = "AP2";
			this.AP2.Size = new System.Drawing.Size(64, 20);
			this.AP2.TabIndex = 1;
			this.AP2.Text = "";
			// 
			// OKBtn
			// 
			this.OKBtn.Location = new System.Drawing.Point(48, 96);
			this.OKBtn.Name = "OKBtn";
			this.OKBtn.Size = new System.Drawing.Size(75, 25);
			this.OKBtn.TabIndex = 2;
			this.OKBtn.Text = "OK";
			this.OKBtn.Click += new System.EventHandler(this.OKBtn_Click);
			// 
			// ActivateForm
			// 
			
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(218, 135);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.CancelBtn,
																		  this.OKBtn,
																		  this.AP2,
																		  this.label2,
																		  this.AP1,
																		  this.label1});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "ActivateForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Activate";
			this.ResumeLayout(false);

		}
        #endregion

        /***************************************************************************************
        * Procedure : OKBtn_Click
        *
        * Purpose   : Called on OK button click
        *
        * Descrip   : Gets user inputs for Activate passwords.validate values and if valid then 
        *             store in global variable
        '**************************************************************************************/        
        private void OKBtn_Click(object sender, System.EventArgs e)
        {
            string sActivatePwrd1="";
            string sActivatePwrd2="";
            int k_IsValid=-1,j_IsValid=-1;

            // Get ActivatePassword1 value entered by user as string
            sActivatePwrd1=AP1.Text;
            // Get ActivatePassword2 value entered by user as string
            sActivatePwrd2=AP2.Text;

            //Perform validation for Activatepassword1 string value and convert into integer.
            j_IsValid = MainForm.isValidData(sActivatePwrd1.Trim(), MainForm.VALIDDATA_LENGTH,ref MainForm.ActivatePwrd1);
            //Perform validation for Activatepassword2 string value and convert into integer.
            k_IsValid = MainForm.isValidData(sActivatePwrd2.Trim(), MainForm.VALIDDATA_LENGTH,ref MainForm.ActivatePwrd2);

            if((j_IsValid==1)||(k_IsValid==1))// If any one activate password are blank
            {
                MessageBox.Show("Specify Activate Passwords to proceed.","Activate",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            if((j_IsValid==2)||(k_IsValid==2))// if activate passwords are of invalid string
            {
                MessageBox.Show("Activate Passwords must be in hex with length not exceeding 4 digit.","Activate",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            if((j_IsValid==3)||(k_IsValid==3))//if activate passwords are of invalid string
            {
                MessageBox.Show("Activate Passwords must be in hex with length not exceeding 4 digit.","Activate",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
			Close(); //close form if password valid
		}

        /***************************************************************************************
        * Procedure : CancelBtn_Click
        *
        * Purpose   : Called on CANCEL button click
        *
        * Descrip   : close the form.
        ***************************************************************************************/        
        private void CancelBtn_Click(object sender, System.EventArgs e)
        {
            Close ();// close form
        }
    }
}
