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;
using System.Globalization;

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

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                PageTitle = "NIKAI- HOME";
            }
            //Response.Redirect("General/Home.aspx",false);
        }

        protected void Grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            Grid.DataSource = null;
            if (cmbPeriod.SelectedValue != "0")
            {
                Grid.DataSource = CM.GetAttandanceAndDSR(Convert.ToInt32(cmbPeriod.SelectedValue), null, UserID, null);
            }
        }

        protected void cmbPeriod_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            Grid.Rebind();
        }

        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");

                //item["Date"].Text = Convert.ToDateTime(item["Date"].Text).ToString("dddd MMM dd,yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                
                if (item["Attendance"].Text == "Present" && item["DSR"].Text == "Yes")
                {
                    ((LinkButton)item.FindControl("btnEditDSR")).Visible = true;
                    ((LinkButton)item.FindControl("btnEditDSR")).PostBackUrl = "~/Executive/DSREntry.aspx?Dt=" + item["Date"].Text +
                                                                               "&DSR=" + item["DSR_Id"].Text + "&DSRH=" + item["DSR_Head_Id"].Text;
                }
                else if (item["Attendance"].Text == "Present" && item["DSR"].Text == "No")
                {
                    ((LinkButton)item.FindControl("btnFillDSR")).Visible = true;
                    ((LinkButton)item.FindControl("btnFillDSR")).PostBackUrl = "~/Executive/DSREntry.aspx?Dt=" + item["Date"].Text +
                                                                               "&DSR=" + item["DSR_Id"].Text + "&DSRH=" + item["DSR_Head_Id"].Text;
                    ((LinkButton)item.FindControl("btnChangeAttendance")).Visible = true;
                }
                else if (item["Attendance"].Text == "Absent" && item["DSR"].Text == "No")
                {
                    lbtnChange.Visible = true;
                }

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

                item["Attendance"].Text = (item["Attendance"].Text == "Present") ? (string)GetGlobalResourceObject("Res", "Present") : (string)GetGlobalResourceObject("Res", "Absent");
                item["DSR"].Text = (item["DSR"].Text == "Yes") ? (string)GetGlobalResourceObject("Res", "Yes") : (string)GetGlobalResourceObject("Res", "No");
            }
        }
    }
}