using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using System.Web.UI;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using System.Xml;
using System.Web.Configuration;

public partial class GetMyCalendarData : Base.BasePage
{
    #region Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    ReportDocument rptDoc = new ReportDocument();
    GetReports rptEmp = new GetReports();
    HeaderInformation hdrTable = new HeaderInformation();
    Rpt_Common rptcommon = new Rpt_Common();
    EmailConfiguration objEmailConfiguration = new EmailConfiguration();
    string strShiftDate = "";
    Dashboard objDash = new Dashboard();
    string strMycalendar = "";
    #endregion
    protected override void Page_Load(object sender, EventArgs e)
    {
        string source_Language;
        GC.Collect();
        base.Page_Load(sender, e);
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (Request.QueryString["ShiftDate"] != null)
        {
            strShiftDate = Convert.ToString(Request.QueryString["ShiftDate"]);
            GetMycalendar();
        }
        else if (Request.QueryString["individualUser"] != null)
        {
            IndividualUser();
        }
        else if (Request.QueryString["Team"] != null)
        {
            TeamCalendar();
        }

        Response.Write(strMycalendar);
        Response.End();
    }
    private void GetMycalendar()
    {
        try
        {
            DataSet ds = new DataSet();
            ds = objDash.GetMyCalendarDataforIndividual(strShiftDate, Convert.ToString(Session["EmpAutoID"]));
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow DR in ds.Tables[0].Rows)
                    {
                        strMycalendar = strMycalendar + Convert.ToString(DR["Date"]) + "," + Convert.ToString(DR["ShiftName"]) + "," + Convert.ToString(DR["hrsWork"]) + "," + Convert.ToString(DR["InTime"]) + "," + Convert.ToString(DR["OutTime"]) + "," + Convert.ToString(DR["LateIn"]) + "," + Convert.ToString(DR["EarlyOut"]) + "," + Convert.ToString(DR["LunchHrs"]) + "," + Convert.ToString(DR["AttendanceData"]) + "," + Convert.ToString(DR["Shift_TotalWorkingHours"]) + "," + Convert.ToString(DR["BrackHrs"]) + ",";
                    }
                    strMycalendar = strMycalendar.Substring(0, strMycalendar.Length - 1);
                    strMycalendar = strMycalendar + "#";
                    foreach (DataRow DR in ds.Tables[1].Rows)
                    {
                        strMycalendar = strMycalendar + Convert.ToString(DR["Present"]) + "," + Convert.ToString(DR["Absent"]) + "," + Convert.ToString(DR["Leave"]) + "," + Convert.ToString(DR["Holiday"]) + "," + Convert.ToString(DR["WeeklyOff"]) + "," + Convert.ToString(Convert.ToDecimal(DR["Present"]) + Convert.ToDecimal(DR["Absent"]) + Convert.ToDecimal(DR["Leave"]) + Convert.ToDecimal(DR["Holiday"]) + Convert.ToDecimal(DR["WeeklyOff"])) + "," + Convert.ToString(DR["MonthName"]) + ",";
                    }
                    strMycalendar = strMycalendar.Substring(0, strMycalendar.Length - 1);
                }
                else
                {
                    strMycalendar = "";
                }
            }
            else
            {
                strMycalendar = "";
            }
        }
        catch (Exception ex)
        {

        }
    }
    private void IndividualUser()
    {
        DataSet dstMyCalendar = new DataSet();
        dstMyCalendar = objDash.GetMyCalendarData(Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["EmpAutoID"]));
        if (dstMyCalendar.Tables.Count > 0)
        {
            if (dstMyCalendar.Tables[0].Rows.Count > 0)
                strMycalendar = Convert.ToString(dstMyCalendar.Tables[0].Rows[0]["MyCalendarOutput"]);
        }
    }
    private void TeamCalendar()
    {
        DataSet dstMyCalendarTeam = new DataSet();
        dstMyCalendarTeam = objDash.GetMyCalendarDataTeam(Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["EmpAutoID"]));
        if (dstMyCalendarTeam.Tables.Count > 0)
        {
            if (dstMyCalendarTeam.Tables[0].Rows.Count > 0)
                strMycalendar = Convert.ToString(dstMyCalendarTeam.Tables[0].Rows[0]["MyCalendarOutput"]);
        }
    }
}