using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Web.UI;

namespace Helper
{
    public class Validation
    {
        /// <summary>
        ///----------------------------------------------------------------
        /// void Method FillTelerikDropdown:
        /// Purpose: This method populates the telerik dropdown
        /// thisControl = Telerik dropdown control
        /// cboDataSource = Datasource used to bind with the control
        /// TextField = Dropdowncontrol text field 
        /// ValueField = Dropdowncontrol value field
        /// DefaultTextField = Default Text field if any to be pased for e.g. (Select Gender)
        /// DefaultValueField = Default Value field if any to be passed for e.g. 0
        /// Returns:
        ///   Nothing
        ///----------------------------------------------------------------
        /// </summary>
        public static void FillTelerikDropdown(
            RadComboBox thisControl,
            object cboDataSource,
            string TextField,
            string ValueField,
            string DefaultTextField,
            string DefaultValueField)
        {
            thisControl.Items.Clear();
            thisControl.ShowMoreResultsBox = false;
            thisControl.DataSource = cboDataSource;
            thisControl.DataTextField = TextField;
            thisControl.DataValueField = ValueField;
            thisControl.DataBind();
            if (thisControl.Items.Count > 0)
            {
                if (DefaultTextField.Trim().Length > 0)
                    thisControl.Items.Insert(0, new RadComboBoxItem(DefaultTextField, DefaultValueField));
            }
            else
                thisControl.Items.Insert(0, new RadComboBoxItem("No Data", DefaultValueField));

        }

        public static bool ComboBoxValidate(RadComboBox comboBox)
        {
            if (comboBox.SelectedValue == "0" || string.IsNullOrEmpty(comboBox.Text))
                return false;
            else
                return true;
        }

        public static bool TextBoxValidate(RadTextBox textBox)
        {
            if (string.IsNullOrEmpty(textBox.Text))
                return false;
            else
                return true;
        }

        public static bool TimePickerValidate(RadTimePicker timePicker)
        {
            if (timePicker.SelectedDate == null || string.IsNullOrEmpty(timePicker.SelectedDate.Value.ToShortTimeString().ToString()))
                return false;
            else
                return true;
        }


        public static bool DatePickerValidate(RadDatePicker datePicker)
        {
            if (datePicker.SelectedDate == null || string.IsNullOrEmpty(datePicker.SelectedDate.ToString()))
                return false;
            else
                return true;
        }

        public static bool NumericTextBoxValidate(RadNumericTextBox numericTextBox)
        {
            if (string.IsNullOrEmpty(numericTextBox.Text) || (Convert.ToInt32(numericTextBox.Text) <= 0))
                return false;
            else
                return true;
        }
    }
}
