// clsValidation.cs
// Copyright (C) 2008 Karel Jordaan karel_jordaan@yahoo.com.au
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System.Windows.Forms;

namespace GUIControlLogic
{
    /// <summary>
    /// Functions to validate GUI input 
    /// set a errorprovider if validation fails
    /// </summary>
    /// <remarks>None</remarks>
    public class clsValidation
    {
        #region Variable declaration

        /// <summary>
        /// Reference to a new error provider class
        /// </summary>
        /// <remarks>None</remarks>
        private readonly ErrorProvider ep = new ErrorProvider();

        #endregion

        #region Structures

        #endregion

        #region Enumerations

        /// <summary>
        /// type of validation to perform
        /// </summary>
        /// <remarks>None</remarks>
        public enum TypeValidation
        {
            Required = 0,
            unallocated = 1
        }

        #endregion

        #region Functions

        /// <summary>
        /// main function for validation
        /// </summary>
        /// <param name="frm">a referece to the calling form, to set the errorprovider to</param>
        /// <param name="txt">the string to validate</param>
        /// <param name="ctrl">the control to set the errorprovider to</param>
        /// <param name="tv">the type of validation to perform</param>
        /// <returns>boolean to indicate success</returns>
        /// <remarks>None</remarks>
        public bool DoValidation(Form frm, string txt, Control ctrl, TypeValidation tv)
        {
            ep.ContainerControl = frm;
            bool ValidationResult = new bool();

            switch (tv)
            {
                case TypeValidation.Required:

                    ValidationResult = ValidateRequired(txt);

                    break;
            }

            if (!ValidationResult)
            {
                ep.SetError(ctrl, "Please enter an alias.");
                return true;
            }
            ep.SetError(ctrl, "");
            return false;
        }

        /// <summary>
        /// function to check for empty string
        /// </summary>
        /// <param name="str">String to check</param>
        /// <returns>Bool</returns>
        /// <remarks>None</remarks>
        public bool ValidateRequired(string str)
        {
            if (str != "")
                return true;
            return false;
        }

//		public bool ValidateIligal(string strInput)
//		{
//
//
//
//		}

        #endregion

        #region Menu handlers

        #endregion

        #region Custom Windows Form Designer generated code

        #endregion

        #region Events

        #endregion
    }
}