using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources; 
public partial class Transactions_AjaxManualTimeEntry : Base.BasePage
{
    EntranceEventData objEntrance = new EntranceEventData();
    PunchTypesEventdata objPunchTypes = new PunchTypesEventdata();
    ResourceManager rm;
    CultureInfo ci;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);
        //get the culture info to set the language
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (!IsPostBack)
        {
            DataSet ds_EntranceDetails = new DataSet();
            int intEntranceId = 0;
            if (Request.QueryString["EntranceId"] != "") 
            {
                if (Request.QueryString["EntranceId"] != "-Select-")
                {
                    intEntranceId = Convert.ToInt32(Request.QueryString["EntranceId"]);
                }
            }
            string strType = Request.QueryString["strType"].ToString();
            string strTerminalType = Request.QueryString["TerminalType"].ToString();
            if (strType == "PunchTypes")
            {
                if (strTerminalType == "I")
                {
                    DataSet dsInPunchTypes = new DataSet();
                    dsInPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(intEntranceId, "I");
                    foreach (DataRow drRow in dsInPunchTypes.Tables[0].Rows)
                    {
                        switch (drRow["PunchType"].ToString())
                        {
                            case "In":
                                drRow["PunchType"] = rm.GetString("PunchType_In", ci);
                                break;
                            case "Out":
                                drRow["PunchType"] = rm.GetString("PunchType_Out", ci);
                                break;
                            case "Shift In":
                                drRow["PunchType"] = rm.GetString("PunchType_ShiftIn", ci);
                                break;
                            case "Shift Out":
                                drRow["PunchType"] = rm.GetString("PunchType_ShiftOut", ci);
                                break;
                            case "Break In":
                                drRow["PunchType"] = rm.GetString("PunchType_BreakIn", ci);
                                break;
                            case "Break Out":
                                drRow["PunchType"] = rm.GetString("PunchType_BreakOut", ci);
                                break;
                            case "Lunch In":
                                drRow["PunchType"] = rm.GetString("PunchType_LunchIn", ci);
                                break;
                            case "Lunch Out":
                                drRow["PunchType"] = rm.GetString("PunchType_LunchOut", ci);
                                break;
                            case "In Duty":
                                drRow["PunchType"] = rm.GetString("PunchType_InDuty", ci);
                                break;
                            case "Out Duty":
                                drRow["PunchType"] = rm.GetString("PunchType_OutDuty", ci);
                                break;
                            case "Official In":
                                drRow["PunchType"] = rm.GetString("PunchType_OfficialIn", ci);
                                break;
                            case "Official Out":
                                drRow["PunchType"] = rm.GetString("PunchType_OfficialOut", ci);
                                break;
                        }
                    }
                    dsInPunchTypes.Tables[0].TableName = "InPunchTypes";
                    if (dsInPunchTypes.Tables["InPunchTypes"].Rows.Count > 0)
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write(dsInPunchTypes.GetXml());
                        dsInPunchTypes.Dispose();
                        Response.End();
                    }
                    else
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write("Fail");
                        Response.End();
                    }
                }
                else if (strTerminalType == "O")
                {
                    DataSet dsOutPunchTypes = new DataSet();
                    dsOutPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(intEntranceId, "O");
                    foreach (DataRow drRow in dsOutPunchTypes.Tables[0].Rows)
                    {
                        switch (drRow["PunchType"].ToString())
                        {
                            case "In":
                                drRow["PunchType"] = rm.GetString("PunchType_In", ci);
                                break;
                            case "Out":
                                drRow["PunchType"] = rm.GetString("PunchType_Out", ci);
                                break;
                            case "Shift In":
                                drRow["PunchType"] = rm.GetString("PunchType_ShiftIn", ci);
                                break;
                            case "Shift Out":
                                drRow["PunchType"] = rm.GetString("PunchType_ShiftOut", ci);
                                break;
                            case "Break In":
                                drRow["PunchType"] = rm.GetString("PunchType_BreakIn", ci);
                                break;
                            case "Break Out":
                                drRow["PunchType"] = rm.GetString("PunchType_BreakOut", ci);
                                break;
                            case "Lunch In":
                                drRow["PunchType"] = rm.GetString("PunchType_LunchIn", ci);
                                break;
                            case "Lunch Out":
                                drRow["PunchType"] = rm.GetString("PunchType_LunchOut", ci);
                                break;
                            case "In Duty":
                                drRow["PunchType"] = rm.GetString("PunchType_InDuty", ci);
                                break;
                            case "Out Duty":
                                drRow["PunchType"] = rm.GetString("PunchType_OutDuty", ci);
                                break;
                            case "Official In":
                                drRow["PunchType"] = rm.GetString("PunchType_OfficialIn", ci);
                                break;
                            case "Official Out":
                                drRow["PunchType"] = rm.GetString("PunchType_OfficialOut", ci);
                                break;
                        }
                    }
                    dsOutPunchTypes.Tables[0].TableName = "OutPunchTypes";
                    if (dsOutPunchTypes.Tables["OutPunchTypes"].Rows.Count > 0)
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write(dsOutPunchTypes.GetXml());
                        dsOutPunchTypes.Dispose();
                        Response.End();
                    }
                    else
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write("Fail");
                        Response.End();
                    }
                }
            }
            if (strType == "Terminals")
            {
                if (strTerminalType == "I")
                {
                    ds_EntranceDetails = objEntrance.SelectEntranceINOUTDetailsByIDview(intEntranceId, "In");
                    ds_EntranceDetails.Tables[0].TableName = "InTerminals";
                    if (ds_EntranceDetails.Tables["InTerminals"].Rows.Count > 0)
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write(ds_EntranceDetails.GetXml());
                        ds_EntranceDetails.Dispose();
                        Response.End();
                    }
                    else
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write("Fail");
                        Response.End();
                    }
                }
                else if (strTerminalType == "O")
                {
                    ds_EntranceDetails = objEntrance.SelectEntranceINOUTDetailsByIDview(intEntranceId, "Out");
                    ds_EntranceDetails.Tables[0].TableName = "OutTerminals";
                    if (ds_EntranceDetails.Tables[0].Rows.Count > 0)
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write(ds_EntranceDetails.GetXml());
                        ds_EntranceDetails.Dispose();
                        Response.End();
                    }
                    else
                    {
                        Response.Clear();
                        Response.ContentType = "text/xml";
                        Response.Write("Fail");
                        Response.End();
                    }
                }
            }
        }
    }
}
