using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLayer;
using DTO;
using Helper;

namespace NikaiDSR.Manager
{
    public partial class SummaryTeamReport : PageBase
    {

        #region declarartion
        CommonManager CM = new CommonManager();
        ReportManager RM = new ReportManager();
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PageTitle = "NIKAI - EXECUTIVE - REPORT A: SUMMARY BY TEAM";
                FillCountryComboBox();
                FillRegionComboBox();
                //FillLocationComboBox();

                Common.SetDatePickerUICulture(dpFrom);
                Common.SetDatePickerUICulture(dpTo);
            }
        }

        void FillCountryComboBox()
        {
            IList<CountryDTO> CountryList = CM.GetCountry(null, null);
            Helper.Validation.FillTelerikDropdown(cmbCountry, CountryList, "Country_Name", "Country_Id", "Select Country", "0");
        }

        void FillRegionComboBox()
        {
            IList<RegionDTO> RegionList = CM.GetRegion(null, null, null);
            Helper.Validation.FillTelerikDropdown(cmbRegion, RegionList, "Region_Name", "Region_Id", "Select Region", "0");
        }

        void FillLocationComboBox()
        {
            IList<LocationDTO> LocationList = CM.GetLocation(null, null, null);
            Helper.Validation.FillTelerikDropdown(cmbLocation, LocationList, "Location_Name", "Location_Id", "Select Location", "0");
        }


        protected void Grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            var a = RM.GetManagerReport(dpFrom.SelectedDate, dpTo.SelectedDate, Convert.ToInt32(cmbCountry.SelectedValue),
                                                  Convert.ToInt32(cmbRegion.SelectedValue), 0,//Convert.ToInt32(cmbLocation.SelectedValue),
                                                  rblAccounts.SelectedValue, UserID, null, null).Take(2);
            try
            {
                //Helper.Validation.FillTelerikDropdown(cmbLocation, a, "Date", "Executive_Count", "Select Location", "0");
                cmbLocation.DataSource = a;
                cmbLocation.DataTextField = "Executive_Count";
                cmbLocation.DataValueField = "Executive_Count";
                cmbLocation.DataBind();
                //cmbLocation.Items.Add(new RadComboBoxItem("asdad", "asd"));
                //cmbLocation.Items.Add(new RadComboBoxItem("asdad1", "asd1"));
                Grid.DataSource = a;
            }
            catch (Exception ex)
            { }
        }

        protected void Grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {

        }
        protected void btnGo_Click(object sender, EventArgs e)
        {
            string Error = "";
            if (!Validate(ref Error))
                ShowErrorMessage(Error, errMsg, Common.ERROR_MESSAGE_TYPE.ERROR);
            else
            {
                Grid.Rebind();
                //ShowErrorMessage("Updated Successfully.", errMsg, Common.ERROR_MESSAGE_TYPE.SUCCESS);
            }
        }
        bool Validate(ref string Error)
        {
            bool validateFlag = false;

            if (!(Helper.Validation.DatePickerValidate(dpFrom))
                && Validation.DatePickerValidate(dpTo))
            //&& Validation.ComboBoxValidate(cbCountry)
            //&& Validation.ComboBoxValidate(cbRegion)
            //&& Validation.ComboBoxValidate(cbLocation))
            {
                Error = "Fill all mandatory fields.";
            }
            else if (dpFrom.SelectedDate > dpTo.SelectedDate)
            {
                Error = (string)GetGlobalResourceObject("Res", "OutTime_Intime");
            }
            else
            {
                validateFlag = true;
            }

            return validateFlag;
        }

    }
}