using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Drawing;
using System.IO;
using BusinessLayer;
using DTO;

namespace NikaiDSR
{
    public partial class LandingPageAdmin : PageBase
    {
        #region declaration
        CommonManager CM = new CommonManager();
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PageTitle = "NIKAI- HOME";
                FillExecutiveComboBox();
                dtSearch.SelectedDate = DateTime.Now;
            }
        }

        void FillExecutiveComboBox()
        {
            IList<ManagerExecutivesDTO> LinkedExecutives = CM.GetLinkedExecutives(UserID);
            Helper.Validation.FillTelerikDropdown(cmbExecutive, LinkedExecutives, "Site_User_Name", "Site_User_Id", "Select", "0");
        }

        protected void Grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            Grid.DataSource = null;

            if (cmbExecutive.SelectedValue != "0")
                Grid.DataSource = CM.GetAttandanceAndDSR(null, dtSearch.SelectedDate, UserID, Convert.ToInt32(cmbExecutive.SelectedValue));
            else
                Grid.DataSource = CM.GetAttandanceAndDSR(null, dtSearch.SelectedDate, UserID, null);
        }

        protected void Grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                LinkButton lbtnChange = (LinkButton)item.FindControl("btnChangeAttendance");

                if (item["Attendance"].Text == "Present" && item["DSR"].Text == "Yes")
                {
                    ((LinkButton)item.FindControl("btnViewDSR")).Visible = true;
                    ((LinkButton)item.FindControl("btnViewDSR")).PostBackUrl = "~/Executive/DSREntry.aspx?Dt=" + item["Date"].Text +
                                                                               "&UID=" + item["UserId"].Text;
                                                                               //"&DSR=" + item["DSR_Id"].Text + "&DSRH=" + item["DSR_Head_Id"].Text;
                }
                else
                {
                    lbtnChange.Visible = true;
                }

                if (lbtnChange.Visible == true)
                {
                    string UserId = item["UserId"].Text;
                    lbtnChange.PostBackUrl = "~/Executive/ChangeAttendance.aspx?Dt=" + item["Date"].Text + "&UID=" + UserId;
                }
            }
        }

        protected void btnGo_Click(object sender, EventArgs e)
        {
            Grid.Rebind();
        }
    }
}