using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Threading;
using System.Resources;
using System.IO;
using System.Web.UI.HtmlControls;
using DevExpress.Web;
using System.Web.Services;
using System.Collections.Generic;
using System.Web;
/****************************************************************************************************************************
* Project Name    : TimeCheck                  Started Date  : 18-July-2007
* Module          : Manual Time Entry          Last Modified : 05-May-2011
* Programmer      : Kumuthini.L
* Modified by     : Sashma
*****************************************************************************************************************************/
public partial class Transactions_TA_UI_Transactions_ManualTimeEntryAdd : Base.BasePage
{
    #region Variable Declaration
    ResourceManager rm;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DateTime dtmCurrentDateTime;
    Rpt_Common rptcommon = new Rpt_Common();
    DateTime combinedDateTime;
    DataSet ds_Checkuser = new DataSet();
    CultureInfo ci;
    ShiftAllocationEvendata obj = new ShiftAllocationEvendata();
    ManualEntryEventData objManualEntry = new ManualEntryEventData();
    PunchTypesEventdata objPunchTypes = new PunchTypesEventdata();
    EntranceEventData objEntrance = new EntranceEventData();
    ShiftAllocationEvendata objShiftAllocation = new ShiftAllocationEvendata();
    EmployeeEventData objEmployee = new EmployeeEventData();
    cls_Master_Transportation objRoute = new cls_Master_Transportation();
    ShiftExchangeEventData objShiftExchange = new ShiftExchangeEventData();
    cls_Common objCommon = new cls_Common();
    ShiftEvenData objShift = new ShiftEvenData();
    DiscrepancyEventData objDis = new DiscrepancyEventData();
    LeaveApplicationEventData objLeave = new LeaveApplicationEventData();
    DataSet ds = new DataSet();
    int LevelID, loginEmployeeId;
    bool checkRecordExists;
    int count, gintUserId, gintInsertCount = 0, manualEntryExists = 0, approvalSettingsPageExists = 0;
    string gstrDateFormat, gstrEmployeeIds = string.Empty, gstrUserGroupName = string.Empty;
    string gstrDOJValidation = string.Empty, gstrPermissionValidation = string.Empty, gstrShiftValidation = string.Empty;
    string strEmployeeIds = string.Empty, onDuty = string.Empty, strIn = string.Empty, strOut = string.Empty, TimeFormat = string.Empty;
    String IN = string.Empty, BreaKIN = string.Empty, Out = string.Empty, BreakOut = string.Empty;
    DateTime dtmIn = new DateTime();
    DateTime dtmOut = new DateTime();
    String ShiftIN = string.Empty;
    String ShiftOut = string.Empty;
    #endregion

    DataSet ds_Year = new DataSet();
    #region Page Load Events
    /// <summary>
    /// On page load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        grv_EmpDetailss.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lblEmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        Hidden2.Value = Convert.ToString(Session["ITimeFormat"]);
        lbl_Times.Text = "Select Time(hh:mm:ss tt)"; 
        lbl_Dates.Text = "Select Date";
        hiddenTime.Value = "HH:mm";
        TimeFormat = Convert.ToString(Session["ITimeFormat"]);
        ds_Year = objCommon.GetYearsetting();
        Session["parentLevelId"] = "0";
        ViewState["YearSettings_Id"] = ds_Year.Tables[0].Rows[0]["YearSettings_Id"].ToString();
        if (TimeFormat == "HH:mm")
        {
            hiddenTime.Value = "HH:mm";
            lbl_InTime.Text = rm.GetString("ManualEntry_InTime", ci);
            lbl_OutTime.Text = rm.GetString("ManualEntry_OutTime", ci);
        }
        else
        {
            hiddenTime.Value = "LT";
            lbl_InTime.Text = rm.GetString("ManualEntry_InTime1", ci);
            lbl_OutTime.Text = rm.GetString("ManualEntry_OutTime1", ci);
        }
        gintUserId = Int32.Parse(Convert.ToString(Session["EmpAutoID"]));
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        int fl = Convert.ToInt32(Request.QueryString["fl"]);

        if (!IsPostBack)
        {
            if (Convert.ToString(TimeFormat) == "HH:mm")
            {
                lbl_EntryDate.Text = DateTime.Now.ToString(Convert.ToString(Session["MDateFormat"]) + " HH:mm");

            }
            else
            {
                lbl_EntryDate.Text = DateTime.Now.ToString(Convert.ToString(Session["MDateFormat"]) + " hh:mm tt");
            }
            //lbl_EntryDate.Text = DateTime.Now.ToString(Convert.ToString(Session["MDateFormat"]) + " " + Convert.ToString(TimeFormat));
        }
        else
        {
            if (ViewState["Employees"] !=null)
            {
                DataSet ds = (DataSet)ViewState["Employees"];
                grv_EmpDetailss.DataSource = ds;
                grv_EmpDetailss.DataBind();
            }
         
        }


        manualEntryExists = objCommon.CheckPageExistsInLicense(98);
        //Checking grade module is available or not and changed the id value from 110 to 228
        approvalSettingsPageExists = objCommon.CheckPageExistsInLicense(228);
        if (!IsPostBack)
        {
            // Set UserRights
            UserRights();
            LoadStrings(ci);
            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "','" + rm.GetString("Select", ci) + "');";
            strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
            strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_InValidTime", ci) + "','" + rm.GetString("Alert_InValidTimeFormat", ci) + "','" + rm.GetString("Alert_InvalidTimeMoreThan24", ci) + "','" + rm.GetString("Alert_InvalidTimeMoreThan59", ci) + "','" + rm.GetString("Alert_SelectInTerminal", ci) + "','" + rm.GetString("Alert_SelectPunchType", ci) + "','" + rm.GetString("Alert_FillInDate", ci) + "','" + rm.GetString("Alert_FillInTime", ci) + "','" + rm.GetString("Alert_SelectOutTerminal", ci) + "','" + rm.GetString("Alert_RouteName", ci) + "','" + rm.GetString("Alert_InTimeCorrectFormat", ci) + "','" + rm.GetString("Alert_InTimeCorrectFormat", ci) + "','" + rm.GetString("Alert_Are_you_sure_to_Save", ci) + "','" + rm.GetString("Alert_OutDate", ci) + "','" + rm.GetString("Alert_OutTime", ci) + "','" + rm.GetString("Alert_SelectInDate", ci) + "','" + rm.GetString("Alert_SelecttheRouteName", ci) + "','" + rm.GetString("Alert_Norecordsfound", ci) + "','" + rm.GetString("Alert_Errorinretrivingdetails", ci) + "','" + rm.GetString("Alert_SelectEntranceID", ci) + "','" + rm.GetString("Alert_SelectOutPunchType", ci) + "','" + rm.GetString("Alert_EntertheEmployeeID", ci) + "','" + rm.GetString("Validator_ManualTimeEntry_EntranceName", ci) + "','" + rm.GetString("Validator_ManualTimeEntry_Reason", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
            objCommon.menu("ManualTransaction", "26");
            FillEntranceDropDown();
            GetRouteDetails();

            #region
            //    if (fl == 1)
            //    {
            //        rbtGroup.Checked = true;
            //        rbtOnDuty.Checked = true;
            //        this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //        if (Session["CheckRecordsAddInPopUP"] != null)
            //        {
            //            Session["CheckRecordsAddInPopUP"] = null;
            //        }
            //        else
            //        {
            //            objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
            //            Session["EmpDetails"] = null;
            //        }
            //        fillEmployee();
            //        GroupManualEmployees();
            //    }
            //    else
            //    {
            //        rbtSingle.Checked = true;
            //        this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //        objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
            //        Session["EmpDetails"] = null;
            //        txt_EmployeeId.Focus();
            //    }
            //}
            //if (fl == 1)
            //{
            //    if (rbtGroup.Checked && rbtOnDuty.Checked)
            //    {
            //        rbtBusLate.Checked = false;
            //        rbtSingle.Checked = false;
            //        this.Page.RegisterStartupScript("Show", "<script> showGroupEntry();</script>");
            //    }
            //    if (rbtGroup.Checked && rbtBusLate.Checked)
            //    {
            //        rbtOnDuty.Checked = false;
            //        rbtSingle.Checked = false;
            //        this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //    }
            //    if (rbtSingle.Checked)
            //    {
            //        rbtGroup.Checked = false;
            //        rbtOnDuty.Checked = false;
            //        rbtBusLate.Checked = false;
            //        this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //        txt_EmployeeId.Focus();
            //    }
            //}
            //else
            //{
            //    if (rbtSingle.Checked)
            //    {
            //        rbtGroup.Checked = false;
            //        rbtOnDuty.Checked = false;
            //        rbtBusLate.Checked = false;
            //        this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //        txt_EmployeeId.Focus();
            //    }
            //    if (fl == 1)
            //    {
            //        if (rbtGroup.Checked && rbtOnDuty.Checked)
            //        {
            //            rbtSingle.Checked = false;
            //            rbtBusLate.Checked = false;
            //            this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //            if (Session["CheckRecordsAddInPopUP"] != null)
            //            {
            //                Session["CheckRecordsAddInPopUP"] = null;
            //            }
            //            fillEmployee();
            //        }
            //        if (rbtGroup.Checked && rbtBusLate.Checked)
            //        {
            //            rbtSingle.Checked = false;
            //            rbtOnDuty.Checked = false;
            //            this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //        }
            //    }
            //    else
            //    {
            //        if (rbtGroup.Checked && rbtBusLate.Checked)
            //        {
            //            rbtSingle.Checked = false;
            //            rbtOnDuty.Checked = false;
            //            this.Page.RegisterStartupScript("Show", "<script> showGroupEntry()</script>");
            //        }
            //    }
            #endregion
        }
        if (Convert.ToString(Session["Demo"]) == "Express")
        {
            rbtGroup.Visible = false;
        }
        this.Page.RegisterStartupScript("EmployeeName", "<script> EmpName('ManualTimeEntry')</script>");

        if (rbtMultipleEntry.Checked == true)
        {
            this.Page.RegisterStartupScript("Show", "<script> rbtBox()</script>");
        }

    }
    #endregion
    #region User Defined Function
    public void GroupManualEmployees()
    {
        DataSet dsGroup = new DataSet();
        if (Session["GroupEmployees"] != null)
        {
            dsGroup = (DataSet)Session["GroupEmployees"];
            grv_EmployeesGroup.DataSource = dsGroup;
            grv_EmployeesGroup.DataBind();
        }
        else
        {
            grv_EmployeesGroup.DataSource = null;
            grv_EmployeesGroup.DataBind();
        }
        if (Session["GroupEntryDate"] != null)
        {
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            string strInDate = Convert.ToDateTime(Session["GroupEntryDate"]).ToString(gstrDateFormat);
            txt_InDate.Text = strInDate;
            txt_InDate.Enabled = false;
            txt_OutDate.Text = strInDate;
        }
    }
    private void fillEmployee()
    {
        ds = objShiftAllocation.SelectEmployeeDetails(gintUserId);
        if (ds != null && ds.Tables[0].Rows.Count > 0)
        {
            grvEmployees.DataSource = ds;
            grvEmployees.DataBind();
        }
        else
        {
            grvEmployees.DataSource = ds;
            grvEmployees.DataBind();
        }
    }
    /// <summary>
    /// Fills Route dropdown
    /// </summary>
    private void GetRouteDetails()
    {
        DataSet ds_RouteName = new DataSet();
        string usergroupname = string.Empty;
        ds_RouteName = objRoute.SelectTransportationRouteDetails(usergroupname);
        if (ds_RouteName != null)
        {
            if (ds_RouteName.Tables[0].Rows.Count > 0)
            {
                ddlRouteName.DataSource = ds_RouteName;
                ddlRouteName.DataTextField = "Route_Name";
                ddlRouteName.DataValueField = "Id";
                ddlRouteName.DataBind();
            }
            ds_RouteName.Dispose();
            foreach (ListItem item in ddlRouteName.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    /// <summary>
    /// The FillEntranceDropDown Method is used to fill the Entrance Names in the Entrance Name DropDown List
    /// </summary>
    public void FillEntranceDropDown()
    {
        DataSet ds_Entrance = new DataSet();
        ds_Entrance = objEntrance.SelectEntranceDetailsForManualTimeEntry();
        string strEntranceId = string.Empty;
        if (ds_Entrance.Tables[0].Rows.Count > 0)
        {
            strEntranceId = ds_Entrance.Tables[0].Rows[0]["Entrance_Id"].ToString();
            ddlEntranceName.DataSource = ds_Entrance;
            ddlEntranceName.DataTextField = "Entrance_Name";
            ddlEntranceName.DataValueField = "Entrance_Id";
            ddlEntranceName.DataBind();
            ddlEntranceName.SelectedValue = strEntranceId;
            FillTerminals(strEntranceId);
        }
        ds_Entrance.Dispose();
    }
    public void FillTerminals(string strEntranceId)
    {
        DataSet dsInTerminals = new DataSet();
        dsInTerminals = objEntrance.SelectEntranceINOUTDetailsByIDview(Convert.ToInt32(strEntranceId), "In");
        dsInTerminals.Tables[0].TableName = "InTerminals";
        string strInTerminalId = string.Empty;
        if (dsInTerminals.Tables["InTerminals"].Rows.Count > 0)
        {
            strInTerminalId = Convert.ToString(dsInTerminals.Tables["InTerminals"].Rows[0]["Reader_Id"]);
            ddlInTerminals.DataSource = dsInTerminals;
            ddlInTerminals.DataTextField = "Terminal_Name";
            ddlInTerminals.DataValueField = "Reader_Id";
            ddlInTerminals.DataBind();
            FillInPunchTypes(strInTerminalId);
            FillMultipleInPunchTypes(strInTerminalId);
        }
        hdn_InTerminal.Value = ddlInTerminals.SelectedItem.Value;
        dsInTerminals.Dispose();

        DataSet dsOutTerminals = new DataSet();
        dsOutTerminals = objEntrance.SelectEntranceINOUTDetailsByIDview(Convert.ToInt32(strEntranceId), "Out");
        dsOutTerminals.Tables[0].TableName = "OutTerminals";
        string strOutTerminalId = string.Empty;
        if (dsOutTerminals.Tables[0].Rows.Count > 0)
        {
            strOutTerminalId = Convert.ToString(dsOutTerminals.Tables["OutTerminals"].Rows[0]["Reader_Id"]);
            ddlOutTerminals.DataSource = dsOutTerminals;
            ddlOutTerminals.DataTextField = "Terminal_Name";
            ddlOutTerminals.DataValueField = "Reader_Id";
            ddlOutTerminals.DataBind();
            FillOutPunchTypes(strOutTerminalId);
            FillMultipleOutPunchTypes(strOutTerminalId);
        }
        hdn_OutTerminal.Value = ddlOutTerminals.SelectedItem.Value;
        dsOutTerminals.Dispose();
    }
    public void FillInPunchTypes(string strEntranceId)
    {
        DataSet dsInPunchTypes = new DataSet();
        dsInPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(Convert.ToInt32(strEntranceId), "I"); 
        if (dsInPunchTypes.Tables.Count > 0)
        {
            if (dsInPunchTypes.Tables[0].Rows.Count > 0)
            {
                ddlInPunchTypes.DataSource = dsInPunchTypes;
                ddlInPunchTypes.DataTextField = "PunchType";
                ddlInPunchTypes.DataValueField = "PunchType_Value";
                ddlInPunchTypes.DataBind();
            }
            dsInPunchTypes.Dispose();
        }
    }
    public void FillOutPunchTypes(string strEntranceId)
    {
        DataSet dsOutPunchTypes = new DataSet();
        dsOutPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(Convert.ToInt32(strEntranceId), "O");
        if (dsOutPunchTypes.Tables.Count > 0)
        {
            if (dsOutPunchTypes.Tables[0].Rows.Count > 0)
            {
                ddlOutPunchTypes.DataSource = dsOutPunchTypes;
                ddlOutPunchTypes.DataTextField = "PunchType";
                ddlOutPunchTypes.DataValueField = "PunchType_Value";
                ddlOutPunchTypes.DataBind();
            }
        }
        ddlOutPunchTypes.Dispose();
    }
    public void FillMultipleInPunchTypes(string strEntranceId)
    {
        DataSet dsInPunchTypes = new DataSet();
        dsInPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(Convert.ToInt32(strEntranceId), "I");
        if (dsInPunchTypes.Tables.Count > 0)
        {
            if (dsInPunchTypes.Tables[0].Rows.Count > 0)
            {
                ddlINpunch.DataSource = dsInPunchTypes;
                ddlINpunch.DataTextField = "PunchType";
                ddlINpunch.DataValueField = "PunchType_Value";
                ddlINpunch.DataBind();
            }
            dsInPunchTypes.Dispose();
        }
    }
    public void FillMultipleOutPunchTypes(string strEntranceId)
    {
        DataSet dsOutPunchTypes = new DataSet();
        dsOutPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(Convert.ToInt32(strEntranceId), "O");
        if (dsOutPunchTypes.Tables.Count > 0)
        {
            if (dsOutPunchTypes.Tables[0].Rows.Count > 0)
            {
                ddlOutpunch.DataSource = dsOutPunchTypes;
                ddlOutpunch.DataTextField = "PunchType";
                ddlOutpunch.DataValueField = "PunchType_Value";
                ddlOutpunch.DataBind();
            }
        }
        ddlOutPunchTypes.Dispose();
    }
    /// <summary>
    /// To add manual entry for a single employee
    /// </summary>
    /// <param name="EmployeeId"></param>
    /// <param name="Type"></param>
    /// <param name="EmployeeAutoId"></param>
    public void AddManualEntryDetails(string EmployeeId, string Type, int EmployeeAutoId)
    {
        DataSet ds_EntranceDetails = new DataSet();
        int intEntranceId, intInReaderId = 0, intOutReaderId = 0, intRouteId = 0, intShiftId = 0;
        string strInDate = string.Empty, strOutDate = string.Empty, strManualTimeEntryStatus = string.Empty;
        string strIsINPunchPresent = "N";
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strInDate = objCommon.DateConvertion(gstrDateFormat, txt_InDate.Text);
        strOutDate = objCommon.DateConvertion(gstrDateFormat, txt_OutDate.Text);
        string strDateOfJoining = string.Empty, strFlag = "Y";
        DataSet dsEmployeeDOJ = new DataSet();
        dsEmployeeDOJ = objEmployee.GetEmployeeDateOfJoining(txt_EmployeeId.Text, "", "", "S");
        if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
        {
            if (dsEmployeeDOJ.Tables[0].Rows[0]["DateOfJoining"] != DBNull.Value)
            {
                strDateOfJoining = Convert.ToString(dsEmployeeDOJ.Tables[0].Rows[0]["DateOfJoining"]);
            }
        }
        if (strDateOfJoining != string.Empty)
        {
            DateTime dtmDateOfJoining = DateTime.Parse(strDateOfJoining);
            if (strInDate != string.Empty)
            {
                strIsINPunchPresent = "Y";
                DateTime dtmInDate = DateTime.Parse(strInDate);
                if (dtmInDate < dtmDateOfJoining)
                {
                    strFlag = "N";
                    if (Type == "S")
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_IndateGreaterThanEmpDOJ", ci) + "');", true);
                        string scrt = "<script>ManualTimeEntry()</script>";
                        this.Page.RegisterStartupScript("a", scrt);
                        hdn_InPunchType.Value = "";
                        hdn_OutPunchType.Value = "";
                        ddlInPunchTypes.SelectedIndex = 0;
                        ddlOutPunchTypes.SelectedIndex = 0;
                        hdn_InTerminal.Value = "";
                        hdn_OutTerminal.Value = "";
                        txt_InDate.Focus();
                        return;
                    }
                    if (Type == " ")
                    {
                        gstrDOJValidation = gstrDOJValidation + " " + EmployeeId;
                    }
                }
                intShiftId = objShiftExchange.SelectShiftId(EmployeeId, dtmInDate.Year.ToString(), dtmInDate.Month.ToString(), dtmInDate.Day.ToString());
                if (intShiftId == 0)
                {
                    strFlag = "N";
                    if (Type == "S")
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ManualTimeEntry", ci) + "');", true);
                        string scrt = "<script>ManualTimeEntry()</script>";
                        this.Page.RegisterStartupScript("a", scrt);
                        hdn_InPunchType.Value = "";
                        hdn_OutPunchType.Value = "";
                        ddlInPunchTypes.SelectedIndex = 0;
                        ddlOutPunchTypes.SelectedIndex = 0;
                        txt_InDate.Focus();
                        return;
                    }
                    if (Type == " ")
                    {
                        gstrShiftValidation = gstrShiftValidation + " " + EmployeeId;
                    }
                }
            }
            if (strOutDate != string.Empty)
            {
                DateTime dtmOutDate = DateTime.Parse(strOutDate);
                if (dtmOutDate < dtmDateOfJoining)
                {
                    strFlag = "N";
                    if (Type == "S")
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_OutdategreaterthanEmpDOJ", ci) + "');", true);
                        string scrt = "<script>ManualTimeEntry()</script>";
                        this.Page.RegisterStartupScript("a", scrt);
                        hdn_InPunchType.Value = "";
                        hdn_OutPunchType.Value = "";
                        ddlInPunchTypes.SelectedIndex = 0;
                        ddlOutPunchTypes.SelectedIndex = 0;
                        hdn_InTerminal.Value = "";
                        hdn_OutTerminal.Value = "";
                        txt_OutDate.Focus();
                        return;
                    }
                    if (Type == " ")
                    {
                        gstrDOJValidation = gstrDOJValidation + " " + EmployeeId;
                    }
                }
                if (strIsINPunchPresent == "N")
                {
                    intShiftId = objShiftExchange.SelectShiftId(EmployeeId, dtmOutDate.Year.ToString(), dtmOutDate.Month.ToString(), dtmOutDate.Day.ToString());
                    if (intShiftId == 0)
                    {
                        strFlag = "N";
                        if (Type == "S")
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ManualTimeEntry", ci) + "');", true);
                            string scrt = "<script>ManualTimeEntry()</script>";
                            this.Page.RegisterStartupScript("a", scrt);
                            hdn_InPunchType.Value = "";
                            hdn_OutPunchType.Value = "";
                            ddlInPunchTypes.SelectedIndex = 0;
                            ddlOutPunchTypes.SelectedIndex = 0;
                            txt_OutDate.Focus();
                            return;
                        }
                        if (Type == " ")
                        {
                            gstrShiftValidation = gstrShiftValidation + " " + EmployeeId;
                        }
                    }
                }
            }
        }
        count = objManualEntry.CheckManualEntry(EmployeeId, strInDate, txt_ShiftIn.Text, strOutDate, txt_ShiftOut.Text);
        if (count == 0)
        {
            if (strFlag == "Y")
            {
                intEntranceId = int.Parse(ddlEntranceName.SelectedValue);
                if (Type == "GB")
                {
                    intRouteId = int.Parse(ddlRouteName.SelectedValue);
                }
                string strInPunchType = hdn_InPunchType.Value;
                string strOutPunchType = hdn_OutPunchType.Value;
                if (hdn_InTerminal.Value != "")
                {
                    intInReaderId = Convert.ToInt32(hdn_InTerminal.Value);
                }
                else
                {
                    intInReaderId = 0;
                }
                if (hdn_OutTerminal.Value != "")
                {
                    intOutReaderId = Convert.ToInt32(hdn_OutTerminal.Value);
                }
                else
                {
                    intOutReaderId = 0;
                }
                string strEntryDate = objCommon.DateConvertion(gstrDateFormat, lbl_EntryDate.Text);
                strManualTimeEntryStatus = GetManualTimeEntryStatus(EmployeeId);
                if (txt_ShiftIn.Text != string.Empty)
                {
                    txt_ShiftIn.Text = Convert.ToDateTime(txt_ShiftIn.Text).ToString("hh:mm:ss tt");
                }
                if (txt_ShiftOut.Text != string.Empty)
                {
                    txt_ShiftOut.Text = Convert.ToDateTime(txt_ShiftOut.Text).ToString("hh:mm:ss tt");
                }
                if (manualEntryExists == 1)
                {
                    if (approvalSettingsPageExists == 1)
                    {
                        int intCompanyId = base.GetCompanyId(EmployeeAutoId);
                        DataSet dsApprovalSettings = new DataSet();
                        ShiftEvenData objShift = new ShiftEvenData();
                        dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
                        if (dsApprovalSettings != null)
                        {
                            if (dsApprovalSettings.Tables.Count > 0)
                            {
                                if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                                {
                                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ManualEntry"]) == false)
                                    {
                                        strManualTimeEntryStatus = "Approved";
                                    }
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ApprovalSettings", ci) + "');", true);
                                    return;
                                }
                            }
                        }
                    }
                }
                else
                {
                    strManualTimeEntryStatus = "Approved";
                }



                objManualEntry.InsertManualEntry(EmployeeId, DateTime.Parse(strEntryDate), strInDate, txt_ShiftIn.Text,
                    strInPunchType, strOutDate, txt_ShiftOut.Text, strOutPunchType, intInReaderId, intOutReaderId,
                    txt_Reason.Text.Trim().Replace("'", "''"), intRouteId, strManualTimeEntryStatus,
                    DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), 0, 0);
                objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
                Session["EmpDetails"] = null;
            }
            else
            {
                if (gstrEmployeeIds == "")
                {
                    gstrEmployeeIds = EmployeeId;
                }
                else
                {
                    gstrEmployeeIds = gstrEmployeeIds + "," + EmployeeId;
                }
            }
            if (Type == "S")
            {
                string strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Msg_ManualTimeEntrySuccessfull", ci) + "');";
                strScript = strScript + "location.replace('TA_UI_Transactions_ManualTimeEntry.aspx');";
                strScript = strScript + "</script>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            }
        }
        else
        {
            if (Type == "S")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ManualEntryAddedAlready", ci) + "');", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
                hdn_InPunchType.Value = "";
                hdn_OutPunchType.Value = "";
                ddlInPunchTypes.SelectedIndex = 0;
                ddlOutPunchTypes.SelectedIndex = 0;
            }
        }
    }
    /// <summary>
    /// To add manual entry for group of employees.
    /// </summary>
    /// <param name="dtEmpDetails"></param>
    public void AddManualEntryDetails_Group(DataTable dtEmpDetails, string Type)
    {
        DataSet ds_EntranceDetails = new DataSet();
        int intEntranceId, intInReaderId = 0, intOutReaderId = 0, intRouteId = 0;
        if (Type == "GB")
        {
            intRouteId = int.Parse(ddlRouteName.SelectedValue);
        }
        string strInDate = string.Empty, strOutDate = string.Empty, strManualTimeEntryStatus = string.Empty;
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strInDate = objCommon.DateConvertion(gstrDateFormat, txt_InDate.Text);
        strOutDate = objCommon.DateConvertion(gstrDateFormat, txt_OutDate.Text);
        DateTime dtmInDate = new DateTime();
        DateTime dtmOutDate = new DateTime();
        if (strInDate != string.Empty)
        {
            dtmInDate = DateTime.Parse(strInDate);
        }
        if (strOutDate != string.Empty)
        {
            dtmOutDate = DateTime.Parse(strOutDate);
        }
        StringWriter strWriter = new StringWriter();
        dtEmpDetails.WriteXml(strWriter);
        DataSet dsEmployeeDOJ = new DataSet();
        if (strInDate != string.Empty)
        {
            dsEmployeeDOJ = objEmployee.GetEmployeeDateOfJoining("", strWriter.ToString(), strInDate, "G");
        }
        if (strOutDate != string.Empty)
        {
            if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
            {
                dsEmployeeDOJ.Merge(objEmployee.GetEmployeeDateOfJoining("", strWriter.ToString(), strOutDate, "G"));
            }
            else
            {
                dsEmployeeDOJ = objEmployee.GetEmployeeDateOfJoining("", strWriter.ToString(), strOutDate, "G");
            }
        }
        DataSet dsEmployeeShiftID = new DataSet();
        if (strInDate != string.Empty)
        {
            dsEmployeeShiftID = objShiftExchange.SelectShiftId_Group(dtmInDate.Year.ToString(), dtmInDate.Month.ToString(), dtmInDate.Day.ToString(), strWriter.ToString());
        }
        if (strOutDate != string.Empty)
        {
            if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
            {
                dsEmployeeShiftID.Merge(objShiftExchange.SelectShiftId_Group(dtmOutDate.Year.ToString(), dtmOutDate.Month.ToString(), dtmOutDate.Day.ToString(), strWriter.ToString()));
            }
            else
            {
                dsEmployeeShiftID = objShiftExchange.SelectShiftId_Group(dtmOutDate.Year.ToString(), dtmOutDate.Month.ToString(), dtmOutDate.Day.ToString(), strWriter.ToString());
            }
        }
        DataSet dsEmployeeWithPermission = new DataSet();
        dsEmployeeWithPermission = objManualEntry.CheckPermissionForManualEntry_Group(strInDate, txt_ShiftIn.Text, strOutDate, txt_ShiftOut.Text, strWriter.ToString());
        DataSet dsEmployeeWithManualEntry = new DataSet();
        dsEmployeeWithManualEntry = objManualEntry.CheckManualEntry_Group(strInDate, txt_ShiftIn.Text, strOutDate, txt_ShiftOut.Text, strWriter.ToString());
        DataTable dtEmployeeToBeDeleted = new DataTable();
        dtEmployeeToBeDeleted.TableName = "Table";
        dtEmployeeToBeDeleted.Columns.Add("EmployeeAutoId", typeof(Int64));
        if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeDOJ.Tables[0]);
        }
        if (dsEmployeeShiftID.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeShiftID.Tables[0]);
        }
        if (dsEmployeeWithPermission.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeWithPermission.Tables[0]);
        }
        if (dsEmployeeWithManualEntry.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeWithManualEntry.Tables[0]);
        }
        DataSet dsEmpDetailsAfterDelete = new DataSet();
        if (dtEmployeeToBeDeleted.Rows.Count > 0)
        {
            StringWriter strEmployeeToBeDeleted = new StringWriter();
            dtEmployeeToBeDeleted.WriteXml(strEmployeeToBeDeleted);
            strEmployeeIds = objShiftAllocation.GetCommaSeparatedValues(strEmployeeToBeDeleted.ToString());
            dsEmpDetailsAfterDelete = objShiftAllocation.DeleteEmpFromTempTable(strEmployeeToBeDeleted.ToString(), gintUserId);
        }
        else
        {
            dsEmpDetailsAfterDelete.Tables.Add(dtEmpDetails.Copy());
        }
        intEntranceId = int.Parse(ddlEntranceName.SelectedValue);
        string strInPunchType = hdn_InPunchType.Value;
        string strOutPunchType = hdn_OutPunchType.Value;
        if (hdn_InTerminal.Value != "")
        {
            intInReaderId = Convert.ToInt32(hdn_InTerminal.Value);
        }
        else
        {
            intInReaderId = 0;
        }
        if (hdn_OutTerminal.Value != "")
        {
            intOutReaderId = Convert.ToInt32(hdn_OutTerminal.Value);
        }
        else
        {
            intOutReaderId = 0;
        }
        string strEntryDate = objCommon.DateConvertion(gstrDateFormat, lbl_EntryDate.Text);
        if (txt_ShiftIn.Text != string.Empty)
        {
            txt_ShiftIn.Text = Convert.ToDateTime(txt_ShiftIn.Text).ToString("hh:mm:ss tt");
        }
        if (txt_ShiftOut.Text != string.Empty)
        {
            txt_ShiftOut.Text = Convert.ToDateTime(txt_ShiftOut.Text).ToString("hh:mm:ss tt");
        }
        if (dsEmpDetailsAfterDelete.Tables[0].Rows.Count > 0)
        {
            dsEmpDetailsAfterDelete.Tables[0].Columns.Add("Status", typeof(string));
            int intCompanyId = base.GetCompanyId(Convert.ToInt32(dsEmpDetailsAfterDelete.Tables[0].Rows[0]["EmpId"]));
            DataSet dsApprovalSettings = new DataSet();
            ShiftEvenData objShift = new ShiftEvenData();
            dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
            foreach (DataRow drRow in dsEmpDetailsAfterDelete.Tables[0].Rows)
            {
                strManualTimeEntryStatus = GetManualTimeEntryStatus(drRow["EmployeeId"].ToString());
                if (manualEntryExists == 1)
                {
                    if (approvalSettingsPageExists == 1)
                    {
                        if (dsApprovalSettings != null)
                        {
                            if (dsApprovalSettings.Tables.Count > 0)
                            {
                                if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                                {
                                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ManualEntry"]) == false)
                                    {
                                        strManualTimeEntryStatus = "Approved";
                                    }
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ApprovalSettings", ci) + "');", true);
                                    return;
                                }
                            }
                        }
                    }
                }
                else
                {
                    strManualTimeEntryStatus = "Approved";
                }
                drRow["Status"] = strManualTimeEntryStatus;
            }
        }
        if (dsEmpDetailsAfterDelete.Tables[0].Rows.Count > 0)
        {
            StringWriter strEmployeesToInsert = new StringWriter();
            dsEmpDetailsAfterDelete.WriteXml(strEmployeesToInsert);
            objManualEntry.InsertManualEntry_Group(DateTime.Parse(strEntryDate), strInDate, txt_ShiftIn.Text, strInPunchType, strOutDate, txt_ShiftOut.Text, strOutPunchType, intInReaderId, intOutReaderId, txt_Reason.Text.Trim().Replace("'", "''"), intRouteId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), strEmployeesToInsert.ToString());
        }
        Session["EmpDetails"] = null;
    }
    /// <summary>
    /// To get the status of the manual entry based on the reporting to sanctioning persons
    /// </summary>
    /// <param name="inEmployeeCodeId"></param>
    /// <returns></returns>
    public string GetManualTimeEntryStatus(string inEmployeeCodeId)
    {
        DataSet dsReportingPersons = new DataSet();
        DataTable dtReportingPersons = new DataTable();
        string strManualTimeEntryStatus = string.Empty;
        Int64 intReportTo = 0, intLeave_Sanc_Authority = 0;
        dsReportingPersons = objEmployee.GetReportingToSanctionAuthorityByCodeID(inEmployeeCodeId);
        dtReportingPersons = dsReportingPersons.Tables[0];
        if (dtReportingPersons.Rows.Count > 0)
        {
            if (dtReportingPersons.Rows[0]["Reporting_To"] != DBNull.Value && dtReportingPersons.Rows[0]["Reporting_To"].ToString() != string.Empty)
                intReportTo = Int64.Parse(dtReportingPersons.Rows[0]["Reporting_To"].ToString());
            if (dtReportingPersons.Rows[0]["Leave_Sanc_Authority"] != DBNull.Value && dtReportingPersons.Rows[0]["Leave_Sanc_Authority"].ToString() != string.Empty)
                intLeave_Sanc_Authority = Int64.Parse(dtReportingPersons.Rows[0]["Leave_Sanc_Authority"].ToString());
        }
        if (intReportTo != 0 && intLeave_Sanc_Authority != 0 && intReportTo != intLeave_Sanc_Authority)
            strManualTimeEntryStatus = "Pending";
        else
            strManualTimeEntryStatus = "Forwarded";
        return (strManualTimeEntryStatus);
    }
    /// <summary>
    /// To display alert messages.
    /// </summary>
    /// <param name="Message"></param>
    private void DisplayMessage(string Message)
    {
        string strScript = "<script language='javascript' type='text/javascript'>";
        strScript += "alert('" + Message + "');location.replace('TA_UI_Transactions_ManualTimeEntry.aspx');";
        strScript += " </script>";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
    }
    private void DisplayShiftTimingMessage(string Message)
    {
        string strScript = "<script language='javascript' type='text/javascript'>";
        strScript += "alert('" + Message + "');";
        strScript += " </script>";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
    }
    /// <summary>
    /// Compare Current Date with In Date
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CheckInDate(object s, ServerValidateEventArgs e)
    {
        if (rbtOnDuty.Checked == false)
        {
            string strInDate = "";
            if (txt_InDate.Text != "")
            {
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                strInDate = objCommon.DateConvertion(gstrDateFormat, txt_InDate.Text);
                DateTime dtCurrent = DateTime.Now;
                DateTime dtInDate = DateTime.Parse(strInDate);
                int Days = dtCurrent.CompareTo(dtInDate);
                if (Days > 0)
                {
                    e.IsValid = true;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Validator_ManualTimeEntry_InDate", ci) + "');", true);
                    txt_InDate.Focus();
                    e.IsValid = false;
                }
            }
            else
            {
                e.IsValid = true;
            }
        }
    }
    /// <summary>
    /// Compare Current Date with Out Date
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CheckOutDate(object s, ServerValidateEventArgs e)
    {
        if (rbtOnDuty.Checked == false)
        {
            string strOutDate = "";
            if (txt_OutDate.Text != "")
            {
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                strOutDate = objCommon.DateConvertion(gstrDateFormat, txt_OutDate.Text);
                DateTime dtCurrent = DateTime.Now;
                DateTime dtOutDate = DateTime.Parse(strOutDate);
                int Days = dtCurrent.CompareTo(dtOutDate);
                if (Days > 0)
                {
                    e.IsValid = true;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Validator_ManualTimeEntry_OutDate", ci) + "');", true);
                    txt_OutDate.Focus();
                    e.IsValid = false;
                }
            }
            else
            {
                e.IsValid = true;
            }
        }
    }
    /// <summary>
    /// Compare InTime and OutTime
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CheckTime(object s, ServerValidateEventArgs e)
    {
        if ((txt_ShiftIn.Text != "") && (txt_ShiftOut.Text != ""))
        {
            DateTime dtmInTime = DateTime.Parse(txt_ShiftIn.Text);
            DateTime dtmOutTime = DateTime.Parse(txt_ShiftOut.Text);
            int day = dtmOutTime.CompareTo(dtmInTime);
            if (day > 0)
                e.IsValid = true;
            else
                e.IsValid = false;
        }
    }
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_ManualTimeEntry", ci);
        lbl_GroupEntryType.Text = rm.GetString("ManualTimeEntry_GroupEntryType", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EntranceName.Text = rm.GetString("EntranceMaster_Entrance_Name", ci);
        lbl_InDate.Text = rm.GetString("ManualTimeEntry_InDate", ci);
        lbl_InTerminal.Text = rm.GetString("Label_InTerminals", ci);
        lbl_InPunchType.Text = rm.GetString("ManualTimeEntry_InPunchType", ci);
        lbl_ManualTimeEntryDate.Text = rm.GetString("ManualTimeEntry_ManualTimeEntryDate", ci);
        lbl_OutDate.Text = rm.GetString("ManualTimeEntry_OutDate", ci);
        lbl_OutTerminal.Text = rm.GetString("Label_OutTerminals", ci);
        lbl_OutPunchType.Text = rm.GetString("ManualTimeEntry_OutPunchType", ci);
        lbl_Reason.Text = rm.GetString("email_Reason", ci);
        lbl_RouteName.Text = rm.GetString("Transportation_Route_RouteName", ci);
        lbl_TypeOfManualEntry.Text = rm.GetString("ManualTimeEntry_TypeOfManualEntry", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        CustomValidator1.ErrorMessage = rm.GetString("Validator_ManualTimeEntry_InDate", ci);
        CustomValidator3.ErrorMessage = rm.GetString("Validator_ManualTimeEntry_OutDate", ci);
        rbtSingle.Text = rm.GetString("rbtn_EmployeeMaster_Single", ci);
        rbtGroup.Text = rm.GetString("rbtn_ManualTimeEntry_Group", ci);
        rbtBusLate.Text = rm.GetString("rbtn_ManualTimeEntry_BusLate", ci);
        rbtOnDuty.Text = rm.GetString("Dash_OnDuty", ci);
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_View.Text = rm.GetString("btn_View", ci);
        //btn_Search.Text =  rm.GetString("btn_Search", ci);
        lbl_Employees.Text = rm.GetString("ManualTimeEntry_EmployeesAdd", ci);
        btn_ViewEmployees.Text = rm.GetString("btn_Add", ci);
        ddlRouteName.Items[0].Text = rm.GetString("Select", ci);
        ddlEntranceName.Items[0].Text = rm.GetString("Select", ci);
        grvEmployees.Columns[2].HeaderText = rm.GetString("email_EmployeeId", ci);
        grvEmployees.Columns[3].HeaderText = rm.GetString("email_EmployeeName", ci);
        lblLoading.Text = rm.GetString("ProgressBarText", ci);
        rbExcludingWeeklyOff.Text = rm.GetString("ShiftSetting_No", ci);
        btnGroupEmployees.Text = rm.GetString("btn_Add", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
        lblSelectEmployee.Text = rm.GetString("lblSelectEmployee", ci);
        lnkbtnBreakIn.Text = rm.GetString("PunchType_BreakIn", ci);
        lnkbtnBreakOut.Text = rm.GetString("PunchType_BreakOut", ci);
        lnkbtnClockIn.Text = rm.GetString("WebClockInOut_ClockIn", ci);
        lnkbtnClockOut.Text = rm.GetString("WebClockInOut_ClockOut", ci);
    }
    /// <summary>
    /// To check rights of the logged in user.
    /// </summary>
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(26, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    public void AddManualEntryDetails_GroupEntry(DataTable dtEmpDetails)
    {
        DataSet ds_EntranceDetails = new DataSet();
        int intEntranceId, intInReaderId = 0, intOutReaderId = 0, intRouteId = 0;
        string strInDate = string.Empty, strOutDate = string.Empty, strManualTimeEntryStatus = string.Empty;
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strInDate = objCommon.DateConvertion(gstrDateFormat, txt_InDate.Text);
        strOutDate = objCommon.DateConvertion(gstrDateFormat, txt_OutDate.Text);
        DateTime dtmInDate = new DateTime();
        DateTime dtmOutDate = new DateTime();
        if (strInDate != string.Empty)
        {
            dtmInDate = DateTime.Parse(strInDate);
        }
        if (strOutDate != string.Empty)
        {
            dtmOutDate = DateTime.Parse(strOutDate);
        }
        StringWriter strWriter = new StringWriter();
        dtEmpDetails.WriteXml(strWriter);
        DataSet dsEmployeeDOJ = new DataSet();
        if (strInDate != string.Empty)
        {
            dsEmployeeDOJ = objEmployee.GetEmployeeDateOfJoining("", strWriter.ToString(), strInDate, "G");
        }
        if (strOutDate != string.Empty)
        {
            if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
            {
                dsEmployeeDOJ.Merge(objEmployee.GetEmployeeDateOfJoining("", strWriter.ToString(), strOutDate, "G"));
            }
            else
            {
                dsEmployeeDOJ = objEmployee.GetEmployeeDateOfJoining("", strWriter.ToString(), strOutDate, "G");
            }
        }
        DataSet dsEmployeeShiftID = new DataSet();
        if (strInDate != string.Empty)
        {
            dsEmployeeShiftID = objShiftExchange.SelectShiftId_Group(dtmInDate.Year.ToString(), dtmInDate.Month.ToString(), dtmInDate.Day.ToString(), strWriter.ToString());
        }
        if (strOutDate != string.Empty)
        {
            if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
            {
                dsEmployeeShiftID.Merge(objShiftExchange.SelectShiftId_Group(dtmOutDate.Year.ToString(), dtmOutDate.Month.ToString(), dtmOutDate.Day.ToString(), strWriter.ToString()));
            }
            else
            {
                dsEmployeeShiftID = objShiftExchange.SelectShiftId_Group(dtmOutDate.Year.ToString(), dtmOutDate.Month.ToString(), dtmOutDate.Day.ToString(), strWriter.ToString());
            }
        }
        DataSet dsEmployeeWithPermission = new DataSet();
        dsEmployeeWithPermission = objManualEntry.CheckPermissionForManualEntry_Group(strInDate, txt_ShiftIn.Text, strOutDate, txt_ShiftOut.Text, strWriter.ToString());
        DataSet dsEmployeeWithManualEntry = new DataSet();
        dsEmployeeWithManualEntry = objManualEntry.CheckManualEntry_Group(strInDate, txt_ShiftIn.Text, strOutDate, txt_ShiftOut.Text, strWriter.ToString());
        DataTable dtEmployeeToBeDeleted = new DataTable();
        dtEmployeeToBeDeleted.TableName = "Table";
        dtEmployeeToBeDeleted.Columns.Add("EmployeeAutoId", typeof(Int64));
        if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeDOJ.Tables[0]);
        }
        if (dsEmployeeShiftID.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeShiftID.Tables[0]);
        }
        if (dsEmployeeWithPermission.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeWithPermission.Tables[0]);
        }
        if (dsEmployeeWithManualEntry.Tables[0].Rows.Count > 0)
        {
            dtEmployeeToBeDeleted.Merge(dsEmployeeWithManualEntry.Tables[0]);
        }
        DataSet dsEmpDetailsAfterDelete = new DataSet();
        if (dtEmployeeToBeDeleted.Rows.Count > 0)
        {
            StringWriter strEmployeeToBeDeleted = new StringWriter();
            dtEmployeeToBeDeleted.WriteXml(strEmployeeToBeDeleted);
            strEmployeeIds = objShiftAllocation.GetCommaSeparatedValues(strEmployeeToBeDeleted.ToString());
            dsEmpDetailsAfterDelete = objShiftAllocation.DeleteEmpFromTempTable(strEmployeeToBeDeleted.ToString(), gintUserId);
        }
        else
        {
            dsEmpDetailsAfterDelete.Tables.Add(dtEmpDetails.Copy());
        }
        intEntranceId = int.Parse(ddlEntranceName.SelectedValue);
        string strInPunchType = hdn_InPunchType.Value;
        string strOutPunchType = hdn_OutPunchType.Value;
        if (hdn_InTerminal.Value != "")
        {
            intInReaderId = Convert.ToInt32(hdn_InTerminal.Value);
        }
        else
        {
            intInReaderId = 0;
        }
        if (hdn_OutTerminal.Value != "")
        {
            intOutReaderId = Convert.ToInt32(hdn_OutTerminal.Value);
        }
        else
        {
            intOutReaderId = 0;
        }
        string strEntryDate = objCommon.DateConvertion(gstrDateFormat, lbl_EntryDate.Text);
        if (txt_ShiftIn.Text != string.Empty)
        {
            txt_ShiftIn.Text = Convert.ToDateTime(txt_ShiftIn.Text).ToString("hh:mm:ss tt");
        }
        if (txt_ShiftOut.Text != string.Empty)
        {
            txt_ShiftOut.Text = Convert.ToDateTime(txt_ShiftOut.Text).ToString("hh:mm:ss tt");
        }
        //Check Approval Settings for EnterPrise Edition and Demo Version
        // Demo Edition - 0
        //Standard Edition -  1
        //Profession Edition - 2
        //Enterprise Edition - 3
        if (dsEmpDetailsAfterDelete.Tables[0].Rows.Count > 0)
        {
            dsEmpDetailsAfterDelete.Tables[0].Columns.Add("Status", typeof(string));
            int intCompanyId = base.GetCompanyId(Convert.ToInt32(dsEmpDetailsAfterDelete.Tables[0].Rows[0]["EmpId"]));
            DataSet dsApprovalSettings = new DataSet();
            ShiftEvenData objShift = new ShiftEvenData();
            dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
            foreach (DataRow drRow in dsEmpDetailsAfterDelete.Tables[0].Rows)
            {
                strManualTimeEntryStatus = GetManualTimeEntryStatus(drRow["EmployeeId"].ToString());
                if (manualEntryExists == 1)
                {
                    if (approvalSettingsPageExists == 1)
                    {
                        if (dsApprovalSettings != null)
                        {
                            if (dsApprovalSettings.Tables.Count > 0)
                            {
                                if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                                {
                                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ManualEntry"]) == false)
                                    {
                                        strManualTimeEntryStatus = "Approved";
                                    }
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ApprovalSettings", ci) + "');", true);
                                    return;
                                }
                            }
                        }
                    }
                }
                else
                {
                    strManualTimeEntryStatus = "Approved";
                }
                drRow["Status"] = strManualTimeEntryStatus;
            }
        }
        if (dsEmpDetailsAfterDelete.Tables[0].Rows.Count > 0)
        {
            StringWriter strEmployeesToInsert = new StringWriter();
            dsEmpDetailsAfterDelete.WriteXml(strEmployeesToInsert);
            objManualEntry.InsertManualEntry_Group(DateTime.Parse(strEntryDate), strInDate, txt_ShiftIn.Text, strInPunchType, strOutDate, txt_ShiftOut.Text, strOutPunchType, intInReaderId, intOutReaderId, txt_Reason.Text.Trim().Replace("'", "''"), intRouteId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), strEmployeesToInsert.ToString());
        }
        Session["EmpDetails"] = null;
    }
    #endregion
    #region Button Events
    /// <summary>
    /// Add Button - Click Event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        rbtSingle.Checked = true;
        lbl_Error.Text = string.Empty;
        if (rbtOnDuty.Checked == false)
        {
            if ((txt_InDate.Text == "") && (txt_ShiftIn.Text == "") && (txt_OutDate.Text == "") && (txt_ShiftOut.Text == ""))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_EitherInDateTime", ci) + "');", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
                hdn_InPunchType.Value = "";
                hdn_OutPunchType.Value = "";
                ddlInPunchTypes.SelectedIndex = 0;
                ddlOutPunchTypes.SelectedIndex = 0;
                txt_InDate.Focus();
                return;
            }
        }
        if ((txt_InDate.Text != "") && (txt_ShiftIn.Text == ""))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_IntimeEmpty", ci) + "');", true);
            string scrt = "<script>ManualTimeEntry()</script>";
            this.Page.RegisterStartupScript("a", scrt);
            hdn_InPunchType.Value = "";
            hdn_OutPunchType.Value = "";
            ddlInPunchTypes.SelectedIndex = 0;
            ddlOutPunchTypes.SelectedIndex = 0;
            txt_ShiftIn.Focus();
            return;
        }
        if ((txt_InDate.Text == string.Empty) && (txt_ShiftIn.Text != string.Empty))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_InDate", ci) + "');", true);
            string scrt = "<script>ManualTimeEntry()</script>";
            this.Page.RegisterStartupScript("a", scrt);
            hdn_InPunchType.Value = "";
            hdn_OutPunchType.Value = "";
            ddlInPunchTypes.SelectedIndex = 0;
            ddlOutPunchTypes.SelectedIndex = 0;
            txt_InDate.Focus();
            return;
        }
        if ((txt_InDate.Text != "") && (txt_ShiftIn.Text != "") && (hdn_InPunchType.Value == "-Select-" || hdn_InPunchType.Value == ""))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SelectPunchType", ci) + "');", true);
            string scrt = "<script>ManualTimeEntry()</script>";
            this.Page.RegisterStartupScript("a", scrt);
            hdn_InPunchType.Value = "";
            hdn_OutPunchType.Value = "";
            ddlInPunchTypes.SelectedIndex = 0;
            ddlOutPunchTypes.SelectedIndex = 0;
            ddlInPunchTypes.Focus();
            return;
        }
        if ((txt_OutDate.Text != "") && (txt_ShiftOut.Text == ""))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_OutTimeEmpty", ci) + "');", true);
            string scrt = "<script>ManualTimeEntry()</script>";
            this.Page.RegisterStartupScript("a", scrt);
            hdn_InPunchType.Value = "";
            hdn_OutPunchType.Value = "";
            ddlInPunchTypes.SelectedIndex = 0;
            ddlOutPunchTypes.SelectedIndex = 0;
            txt_ShiftOut.Focus();
            return;
        }
        if ((txt_OutDate.Text == "") && (txt_ShiftOut.Text != ""))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_OutDateEmpty", ci) + "');", true);
            string scrt = "<script>ManualTimeEntry()</script>";
            this.Page.RegisterStartupScript("a", scrt);
            hdn_InPunchType.Value = "";
            hdn_OutPunchType.Value = "";
            ddlInPunchTypes.SelectedIndex = 0;
            ddlOutPunchTypes.SelectedIndex = 0;
            txt_OutDate.Focus();
            return;
        }
        if ((txt_OutDate.Text != "") && (txt_ShiftOut.Text != "") && (hdn_OutPunchType.Value == "-Select-" || hdn_OutPunchType.Value == ""))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SelectOutPunchType", ci) + "');", true);
            string scrt = "<script>ManualTimeEntry()</script>";
            this.Page.RegisterStartupScript("a", scrt);
            hdn_InPunchType.Value = "";
            hdn_OutPunchType.Value = "";
            ddlInPunchTypes.SelectedIndex = 0;
            ddlOutPunchTypes.SelectedIndex = 0;
            ddlOutPunchTypes.Focus();
            return;
        }
        if (rbtOnDuty.Checked == true)
        {
            if ((txt_InDate.Text == "") || (txt_ShiftIn.Text == "") || (txt_OutDate.Text == "") || (txt_ShiftOut.Text == ""))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_EnterInDateInTimeOutDateandOutTime", ci) + "')", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
                hdn_InPunchType.Value = "";
                hdn_OutPunchType.Value = "";
                ddlInPunchTypes.SelectedIndex = 0;
                ddlOutPunchTypes.SelectedIndex = 0;
                txt_InDate.Focus();
                return;
            }
        }
        string strInDate = "", strOutDate = "";
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strInDate = objCommon.DateConvertion(gstrDateFormat, txt_InDate.Text);
        strOutDate = objCommon.DateConvertion(gstrDateFormat, txt_OutDate.Text);
        DateTime dtmFromDate = new DateTime();
        DateTime dtmToDate = new DateTime();
        DataSet ds_Year = new DataSet();
        ds_Year = objCommon.GetYearsetting();
        if (ds_Year != null)
        {
            if (ds_Year.Tables[0].Rows.Count > 0)
            {
                if (ds_Year.Tables[0].Rows[0]["FromDate"] != DBNull.Value)
                {
                    dtmFromDate = DateTime.Parse(ds_Year.Tables[0].Rows[0]["FromDate"].ToString());
                }
                if (ds_Year.Tables[0].Rows[0]["ToDate"] != DBNull.Value)
                {
                    dtmToDate = DateTime.Parse(ds_Year.Tables[0].Rows[0]["ToDate"].ToString());
                }
                ViewState["YearSettings_Id"] = ds_Year.Tables[0].Rows[0]["YearSettings_Id"].ToString();
            }
        }
        string strMaxPayrollClosureDate = objManualEntry.SelectMaxPayrollClosureDate();
        if (txt_InDate.Text != string.Empty)
        {
            DateTime dtmInDate = DateTime.Parse(strInDate);
            if ((dtmFromDate <= dtmInDate) && (dtmInDate <= dtmToDate))
            {
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ActiveYear", ci) + "');", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
                hdn_InPunchType.Value = "";
                hdn_OutPunchType.Value = "";
                ddlInPunchTypes.SelectedIndex = 0;
                ddlOutPunchTypes.SelectedIndex = 0;
                txt_InDate.Focus();
                return;
            }
            if (Convert.ToString(Session["UserGroupName"]) != "SuperAdmin" && Convert.ToString(Session["HasSpecialRights"]) != "True")
            {
                if (strMaxPayrollClosureDate != "")
                {
                    DateTime dtmMaxPayrollClosureDate = DateTime.Parse(strMaxPayrollClosureDate);
                    if (dtmInDate <= dtmMaxPayrollClosureDate)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_InDateProcessed", ci) + "');", true);
                        string scrt = "<script>ManualTimeEntry()</script>";
                        this.Page.RegisterStartupScript("a", scrt);
                        hdn_InPunchType.Value = "";
                        hdn_OutPunchType.Value = "";
                        ddlInPunchTypes.SelectedIndex = 0;
                        ddlOutPunchTypes.SelectedIndex = 0;
                        txt_InDate.Focus();
                        return;
                    }
                }
            }
        }
        if (txt_OutDate.Text != "")
        {
            DateTime dtmOutDate = DateTime.Parse(strOutDate);
            if ((dtmFromDate <= dtmOutDate) && (dtmOutDate <= dtmToDate))
            {
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_OutdateSetting", ci) + "');", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
                hdn_InPunchType.Value = "";
                hdn_OutPunchType.Value = "";
                ddlInPunchTypes.SelectedIndex = 0;
                ddlOutPunchTypes.SelectedIndex = 0;
                txt_OutDate.Focus();
                return;
            }
            if (gstrUserGroupName != "SuperAdmin")
            {
                if (strMaxPayrollClosureDate != "")
                {
                    DateTime dtmMaxPayrollClosureDate = DateTime.Parse(strMaxPayrollClosureDate);
                    if (dtmOutDate <= dtmMaxPayrollClosureDate)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_InvalidPayroll", ci) + "');", true);
                        string scrt = "<script>ManualTimeEntry()</script>";
                        this.Page.RegisterStartupScript("a", scrt);
                        hdn_InPunchType.Value = "";
                        hdn_OutPunchType.Value = "";
                        ddlInPunchTypes.SelectedIndex = 0;
                        ddlOutPunchTypes.SelectedIndex = 0;
                        txt_OutDate.Focus();
                        return;
                    }
                }
            }
        }

        //if (Session["CurrentCountryDatetimes"] != null)
        //{

        String EmployeeID = Convert.ToString(txt_EmployeeId.Text);
        org_levelsEventData getUtcEmployeeCheck = new org_levelsEventData();
        DataSet ds_UTC = new DataSet();
        ds_UTC = getUtcEmployeeCheck.GetUTCTimeZoneEmployeeCheck(EmployeeID);
        int Counts = ds_UTC.Tables[0].Rows.Count;
        //String UTC = Convert.ToString(Session["TimezoneId"]);
        //TimeZoneName,TimeZoneDesc,HoursToBeAdded,MinToBeAdded TimezoneId
        if (Counts != 0)
        {
            Session["TimezoneId"] = ds_UTC.Tables[0].Rows[0]["TimezoneId"].ToString();
            Session["TimeZoneName"] = ds_UTC.Tables[0].Rows[0]["TimeZoneName"].ToString();
            Session["TimeZoneDesc"] = ds_UTC.Tables[0].Rows[0]["TimeZoneDesc"].ToString();
            Session["HoursToBeAdded"] = ds_UTC.Tables[0].Rows[0]["HoursToBeAdded"].ToString();
            Session["MinToBeAdded"] = ds_UTC.Tables[0].Rows[0]["MinToBeAdded"].ToString();

            //var dt = DateTime.UtcNow;
            //var tz = TimeZoneInfo.FindSystemTimeZoneById(Convert.ToString(Session["TimeZoneName"]) + " Standard Time");
            //var DateTimeForCountry = TimeZoneInfo.ConvertTimeFromUtc(dt, tz);

            DateTime ConvertUTCTime = new DateTime();
            int hours = Convert.ToInt32(ds_UTC.Tables[0].Rows[0]["HoursToBeAdded"]);
            int Minutes = Convert.ToInt32(ds_UTC.Tables[0].Rows[0]["MinToBeAdded"]);
            ConvertUTCTime = objCommon.TimezoneGetDateTime(hours, Minutes);


            Session["CurrentCountryDatetime"] = Convert.ToDateTime(ViewState["CountryGetDateTime"]).ToString("dd/MM/yyyy HH:mm:ss tt");

            string d = Session["CurrentCountryDatetime"].ToString();
            DateTime parsedDateTime;

            if (DateTime.TryParseExact(d, "dd/MM/yyyy HH:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDateTime))
            {
                string formattedDate = parsedDateTime.ToString(Convert.ToString(Session["MDateFormat"]));
                string formattedUtcTime = parsedDateTime.ToString("hh:mm tt", CultureInfo.InvariantCulture);
                //DateTime ddddd = DateTime.Parse(Convert.ToDateTime(formattedDate).ToShortTimeString());
                Session["CurrentCountryDatetimes"] = parsedDateTime;
                String A = Session["CurrentCountryDatetimes"].ToString();
                dtmCurrentDateTime = parsedDateTime;
            }
            else
            {
                dtmCurrentDateTime = DateTime.Parse(Session["CurrentCountryDatetime"].ToString());
            }


        }





        if ((txt_InDate.Text != "") && (txt_ShiftIn.Text != ""))
        {
            strIn = strInDate + " " + txt_ShiftIn.Text;
            dtmIn = DateTime.Parse(strIn);
            if (dtmIn > dtmCurrentDateTime)
            {
                if (rbtOnDuty.Checked == false)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_InDategreater", ci) + "');", true);
                    string scrt = "<script>ManualTimeEntry()</script>";
                    this.Page.RegisterStartupScript("a", scrt);
                    hdn_InPunchType.Value = "";
                    hdn_OutPunchType.Value = "";
                    ddlInPunchTypes.SelectedIndex = 0;
                    ddlOutPunchTypes.SelectedIndex = 0;
                    txt_ShiftIn.Focus();
                    return;
                }
            }
        }
        if ((txt_OutDate.Text != "") && (txt_ShiftOut.Text != ""))
        {
            strOut = strOutDate + " " + txt_ShiftOut.Text;
            dtmOut = DateTime.Parse(strOut);
            if (dtmOut > dtmCurrentDateTime)
            {
                if (rbtOnDuty.Checked == false)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_OutDategreater", ci) + "');", true);
                    string scrt = "<script>ManualTimeEntry()</script>";
                    this.Page.RegisterStartupScript("a", scrt);
                    hdn_InPunchType.Value = "";
                    hdn_OutPunchType.Value = "";
                    ddlInPunchTypes.SelectedIndex = 0;
                    ddlOutPunchTypes.SelectedIndex = 0;
                    txt_ShiftOut.Focus();
                    return;
                }
            }
        }
        /* If all InDate, InTime, OutDate and OutTime are not NULL, then check whether difference between In DateTime and Out DateTime  
           should not exceed 24 Hours and also check whether In DateTime cannot be greater than Out DateTime   
        */
        if ((txt_InDate.Text != "") && (txt_ShiftIn.Text != "") && (txt_OutDate.Text != "") && (txt_ShiftOut.Text != ""))
        {
            TimeSpan tsDiff = dtmOut.Subtract(dtmIn);
            double dTotalHrs = tsDiff.TotalHours;
            if (dTotalHrs > 24)
            {
            }
            else if (dTotalHrs < 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_InDatetimeGreater", ci) + "');", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
                hdn_InPunchType.Value = "";
                hdn_OutPunchType.Value = "";
                ddlInPunchTypes.SelectedIndex = 0;
                ddlOutPunchTypes.SelectedIndex = 0;
                txt_InDate.Focus();
                return;
            }
        }
        if (rbtSingle.Checked == true)
        {
            if (txt_EmployeeId.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_FillEmployee", ci) + "');", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
                hdn_InPunchType.Value = "";
                hdn_OutPunchType.Value = "";
                ddlInPunchTypes.SelectedIndex = 0;
                ddlOutPunchTypes.SelectedIndex = 0;
                txt_EmployeeId.Focus();
                return;
            }
            DataSet dsEmpAutoId = new DataSet();
            dsEmpAutoId = objCommon.getEmployeeAutoId(txt_EmployeeId.Text);
            if (dsEmpAutoId.Tables.Count > 0)
            {
                if (dsEmpAutoId.Tables[0].Rows.Count > 0)
                {
                    if (dsEmpAutoId.Tables[0].Rows[0]["Employee_Id"] != null)
                    {
                        int EmployeeAutoId = Convert.ToInt32(dsEmpAutoId.Tables[0].Rows[0]["Employee_Id"]);
                        AddManualEntryDetails(txt_EmployeeId.Text, "S", EmployeeAutoId);
                    }
                    else
                    {
                        Message("Employee Not Found");
                        return;
                    }
                }
                else
                {
                    Message("Employee Not Found");
                    return;
                }
            }
            else
            {
                Message("Employee Not Found");
                return;
            }
        }
        else if (rbtGroup.Checked == true)
        {
            DataTable dtEmpDetails = new DataTable();
            dtEmpDetails.Columns.Add("EmpID");
            dtEmpDetails.Columns.Add("EmployeeId");
            dtEmpDetails.Columns.Add("EmployeeName");
            dtEmpDetails.Columns.Add("LoginEmployeeId");
            dtEmpDetails.TableName = "Table";
            for (int i = 0; i < grv_EmployeesGroup.Rows.Count; i++)
            {
                DataRow dr = dtEmpDetails.NewRow();
                dr["EmpID"] = ((Label)(grv_EmployeesGroup.Rows[i].FindControl("lbl_EmpAutoId"))).Text;
                dr["EmployeeId"] = ((Label)(grv_EmployeesGroup.Rows[i].FindControl("lbl_EmpId"))).Text;
                dr["EmployeeName"] = ((Label)(grv_EmployeesGroup.Rows[i].FindControl("lbl_EmpName"))).Text;
                dr["LoginEmployeeId"] = ((Label)(grv_EmployeesGroup.Rows[i].FindControl("lbl_LoginEmployeeId"))).Text;
                dtEmpDetails.Rows.Add(dr);
            }
            if (dtEmpDetails != null && dtEmpDetails.Rows.Count > 0)
            {
                AddManualEntryDetails_GroupEntry(dtEmpDetails);
                Response.Redirect("../Transactions/TA_UI_Transactions_ManualTimeEntry.aspx");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("ManualTimeEntry_EmployeesAdd", ci) + "');", true);
                string scrt = "<script>ManualTimeEntry()</script>";
                this.Page.RegisterStartupScript("a", scrt);
            }
        }
    }
    /// <summary>
    ///  Cancel Button - Click Event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
        Session["EmpDetails"] = null;
        Response.Redirect("../Transactions/TA_UI_Transactions_ManualTimeEntry.aspx");
    }
    #endregion
    #region GridView Events
    protected void grv_Employees_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_EmployeesGroup.PageIndex = e.NewPageIndex;
        //GroupManualEmployees();
    }
    protected void grv_Employees_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblEmpAutoId = (Label)grv_EmployeesGroup.Rows[e.RowIndex].FindControl("lbl_EmpAutoId");
        Label lblLoginEmployeeId = (Label)grv_EmployeesGroup.Rows[e.RowIndex].FindControl("lbl_LoginEmployeeId");
        objShiftAllocation.DeleteEmpDetails(Convert.ToInt32(lblEmpAutoId.Text), Convert.ToInt32(lblLoginEmployeeId.Text));
        int index = Convert.ToInt32(e.RowIndex);
        DataSet ds = (DataSet)Session["GroupEmployees"];
        ds.Tables[0].Rows[index].Delete();
        Session["GroupEmployees"] = ds;
       // GroupManualEmployees();
    }
    /// <summary>
    /// On page index changing
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grvEmployees_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvEmployees.PageIndex = e.NewPageIndex;
        fillEmployee();
    }
    /// <summary>
    /// On row deleting
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grvEmployees_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblEmpAutoId = (Label)grvEmployees.Rows[e.RowIndex].FindControl("lbl_EmpAutoId");
        Label lblLoginEmployeeId = (Label)grvEmployees.Rows[e.RowIndex].FindControl("lbl_LoginEmployeeId");
        objShiftAllocation.DeleteEmpDetails(Convert.ToInt32(lblEmpAutoId.Text), Convert.ToInt32(lblLoginEmployeeId.Text));
        fillEmployee();
    }
    /// <summary>
    /// On gird row bound
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grvEmployees_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lbDelete = new LinkButton();
            lbDelete = (LinkButton)e.Row.Cells[0].Controls[0];
            if (lbDelete.Text == "Delete")
            {
                lbDelete.Text = rm.GetString("btn_Delete", ci);
            }
        }
    }
    #endregion
    #region MessageWithRedirect.
    /// <summary>
    /// Messages the with redirect.
    /// </summary>
    /// <param name="messageContent">Content of the message.</param>
    /// <param name="ToPage">To page.</param>
    private void MessageWithRedirect(string messageContent, string ToPage)
    {
        string strScript = "<script language='javascript' type='text/javascript'>";
        strScript += "alert('" + messageContent + "');";
        strScript += "location.href='" + ToPage + "';";
        strScript += " </script>";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
    }
    #endregion

    protected void btn_Save_Click(object sender, EventArgs e)
    {
        LinkButton lnbtn = (LinkButton)sender;
        string strInDate = string.Empty, strOutDate = string.Empty, strManualTimeEntryStatus = string.Empty;
        if (lnbtn != null)
        {
            if (txt_EmployeeId.Text == "")
            {
                Message("Employee ID should not empty");
                return;
            }

            String EmployeeId = txt_EmployeeId.Text;

            var intShiftId = objShiftExchange.SelectShiftId(EmployeeId, DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), DateTime.Now.Day.ToString());
            if (intShiftId == 0)
            {
                //DisableBtnControls();
                Message(rm.GetString("Msg_ManualTimeEntry", ci));
                return;
            }
            else
            {
                string punchType = "";
                switch (lnbtn.CommandName)
                {
                    case "Clock In":
                        punchType = "Clock In";
                        break;
                    case "Clock Out":
                        punchType = "Clock Out";
                        break;
                    case "Lunch Out":
                        punchType = "Lunch Out";
                        break;
                    case "Lunch In":
                        punchType = "Lunch In";
                        break;
                    case "Break Out":
                        punchType = "Break Out";
                        break;
                    case "Break In":
                        punchType = "Break In";
                        break;
                }
                if (Convert.ToString(txt_EmployeeId.Text) != "")
                {
                    int intCompanyId = base.GetCompanyId(Convert.ToInt32(Session["EmpAutoId"]));
                    if (Convert.ToInt32(Session["EmpAutoId"]) == 1)
                    {
                        intCompanyId = 1;
                    }
                    DataSet dsApprovalSettings = new DataSet();
                    ShiftEvenData objShift = new ShiftEvenData();
                    dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
                    if (dsApprovalSettings != null)
                    {
                        if (dsApprovalSettings.Tables.Count > 0)
                        {
                            if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                            {
                                if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["webClockInOut"]) == false)
                                    strManualTimeEntryStatus = "Approved";
                                else
                                    strManualTimeEntryStatus = GetManualTimeEntryStatus(Convert.ToString(txt_EmployeeId.Text));
                            }
                            else
                                strManualTimeEntryStatus = GetManualTimeEntryStatus(Convert.ToString(txt_EmployeeId.Text));
                        }
                    }
                    else
                        strManualTimeEntryStatus = "Approved";


                    if (punchType == "Clock In" || punchType == "Lunch In" || punchType == "Break In")
                    {
                        objManualEntry.InsertManualEntry
                        (
                            Convert.ToString(txt_EmployeeId.Text),
                            DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy")),
                            DateTime.Now.ToString("MM/dd/yyyy"),
                            DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"),
                            punchType,
                            "",
                            "",
                            "",
                            787,
                            0,
                            "Web " + punchType + " from" + "ManualPunch",
                            0,
                            strManualTimeEntryStatus,
                            DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"),
                            Convert.ToInt32(Session["EmpAutoID"]),
                           Convert.ToString(ViewState["YearSettings_Id"]), 0, 0
                           );

                        string strScript = "";
                        strScript = strScript + "<script language='javascript'>";

                        if (punchType == "Clock In")
                        {
                            strScript = strScript + "alert('" + rm.GetString("Msg_ManualClockInPunchSuccessfull", ci) + "');";
                        }
                        else if (punchType == "Break In")
                        {
                            strScript = strScript + "alert('" + rm.GetString("Msg_ManualBreakInPunchSuccessfull", ci) + "');";
                        }

                        strScript = strScript + "location.replace('TA_UI_Transactions_ManualTimeEntry.aspx');";
                        strScript = strScript + "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                    }
                    else
                    {
                        objManualEntry.InsertManualEntry
                         (
                             Convert.ToString(txt_EmployeeId.Text),
                             DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy")),
                             "",
                             "",
                             "",
                             DateTime.Now.ToString("MM/dd/yyyy"),
                             DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"),
                             punchType,
                             0,
                             788,
                             "Web " + punchType + " from" + "ManualPunch",
                             0,
                             strManualTimeEntryStatus,
                             DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"),
                             Convert.ToInt32(Session["EmpAutoID"]),
                             Convert.ToString(ViewState["YearSettings_Id"]), 0, 0
                            );

                        string strScript = "";
                        strScript = strScript + "<script language='javascript'>";


                        if (punchType == "Clock Out")
                        {
                            strScript = strScript + "alert('" + rm.GetString("Msg_ManualClockOutPunchSuccessfull", ci) + "');";
                        }
                        else if (punchType == "Break Out")
                        {
                            strScript = strScript + "alert('" + rm.GetString("Msg_ManualBreakOutPunchSuccessfull", ci) + "');";
                        }

                        strScript = strScript + "location.replace('TA_UI_Transactions_ManualTimeEntry.aspx');";
                        strScript = strScript + "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);

                    }
                }
            }
        }
    }


    /****************************************************************************************************************************
    * Project Name    : TimeCheck                  Started Date  : 04-Jan-2024
    * Module          : Manual Time Entry          Last Modified : 27-May-2011
    * Programmer      : Hariharan.J
    * Modified by     : Hariharan.J
    *****************************************************************************************************************************/

    protected void txt_EmployeeId_TextChanged(object sender, EventArgs e)
    {
        #region UTC Time Save
        //String EmployeeID = Convert.ToString(Session["EmpAutoID"]);
        String EmployeeID = Convert.ToString(txt_EmployeeId.Text);
        org_levelsEventData getUtcEmployeeCheck = new org_levelsEventData();
        DataSet ds_UTC = new DataSet();
        ds_UTC = getUtcEmployeeCheck.GetUTCTimeZoneEmployeeCheck(EmployeeID);
        int Counts = ds_UTC.Tables[0].Rows.Count;

        if (Counts != 0)
        {
            Session["TimezoneId"] = ds_UTC.Tables[0].Rows[0]["TimezoneId"].ToString();
            Session["TimeZoneName"] = ds_UTC.Tables[0].Rows[0]["TimeZoneName"].ToString();
            Session["TimeZoneDesc"] = ds_UTC.Tables[0].Rows[0]["TimeZoneValue"].ToString();
            Session["HoursToBeAdded"] = ds_UTC.Tables[0].Rows[0]["HoursToBeAdded"].ToString();
            Session["MinToBeAdded"] = ds_UTC.Tables[0].Rows[0]["MinToBeAdded"].ToString();

            DateTime ConvertUTCTime = new DateTime();
            int hours = Convert.ToInt32(ds_UTC.Tables[0].Rows[0]["HoursToBeAdded"]);
            int Minutes = Convert.ToInt32(ds_UTC.Tables[0].Rows[0]["MinToBeAdded"]);
            ConvertUTCTime = objCommon.TimezoneGetDateTime(hours, Minutes);

            ViewState["CountryGetDateTime"] = ConvertUTCTime;


            if (Convert.ToString(TimeFormat) == "HH:mm")
            {
                lbl_EntryDate.Text = ConvertUTCTime.ToString(Convert.ToString(Session["MDateFormat"]) + " HH:mm");

            }
            else
            {
                lbl_EntryDate.Text = ConvertUTCTime.ToString(Convert.ToString(Session["MDateFormat"]) + " hh:mm tt");
            }

            Session["CurrentCountryDatetime"] = ConvertUTCTime.ToString(Convert.ToString(Session["MDateFormat"]) + " HH:mm:ss tt");

            string d = Session["CurrentCountryDatetime"].ToString();
            DateTime parsedDateTime;

            if (DateTime.TryParseExact(d, "dd/MM/yyyy HH:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDateTime))
            {
                string formattedDate = parsedDateTime.ToString(Convert.ToString(Session["MDateFormat"]));
                string formattedUtcTime = parsedDateTime.ToString("hh:mm tt", CultureInfo.InvariantCulture);

                Session["CurrentCountryDatetimes"] = parsedDateTime;
                String A = Session["CurrentCountryDatetimes"].ToString();
            }


        }
        else
        {
            lbl_EntryDate.Text = DateTime.Now.ToString(Convert.ToString(Session["MDateFormat"]) + " HH:mm tt");
        }


        #endregion


    }

    protected void grv_Shift_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowIndex == 0)
        //{
        //    HtmlInputRadioButton rdbID = new HtmlInputRadioButton();
        //    rdbID = (HtmlInputRadioButton)e.Row.FindControl("rdbID");
        //    rdbID.Checked = true;
        //    hdnEmployeeCodeId.Value = rdbID.Value;
        //}
    }
    protected void grv_Shift_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Shift.EnableViewState = true;
        string ChkBoxIDs = "";
        CheckBox deleteChkBxItem = new CheckBox();
        foreach (GridViewRow i in grv_Shift.Rows)
        {
            deleteChkBxItem = (CheckBox)i.Cells[0].FindControl("deletethis");
            if (deleteChkBxItem.Checked)
            {
                if (ChkBoxIDs == "")
                {
                    ChkBoxIDs = ((Label)i.FindControl("lbl_EmpId")).Text.ToString();
                }
                else
                {
                    ChkBoxIDs = ChkBoxIDs + "," + ((Label)i.FindControl("lbl_EmpId")).Text.ToString();
                }
            }
        }
        if (Convert.ToString(Session["EmployeeIds"]) == "")
        {
            Session["EmployeeIds"] = ChkBoxIDs;
        }
        else
        {
            if (ChkBoxIDs != "")
            {
                Session["EmployeeIds"] = Session["EmployeeIds"] + "," + ChkBoxIDs;
            }
        }
        CheckBox chkSelect = new CheckBox();
        chkSelect = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
        Session["SelectAllStatus"] = chkSelect.Checked;
        grv_Shift.PageIndex = e.NewPageIndex;
        
        shiftDataBind();

        CheckEmployeeId_CheckBox();
        //shiftDataBind();
    }

    public void CheckEmployeeId_CheckBox()
    {
        string strEmpId = "";
        strEmpId = (string)Session["EmployeeIds"];
        int intEmployeeIdsLength = strEmpId.Length;
        char[] Delimit = { ',' };
        string[] Empid = strEmpId.Split(Delimit);
        CheckBox deleteChkBxItem = new CheckBox();
        foreach (GridViewRow gr in grv_Shift.Rows)
        {
            string empId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
            foreach (string str in Empid)
            {
                if (str == empId)
                {
                    deleteChkBxItem = (CheckBox)gr.Cells[0].FindControl("deletethis");
                    deleteChkBxItem.Checked = true;
                    int intLength = empId.Length;
                    if (intEmployeeIdsLength > intLength)
                    {
                        int intIndex = strEmpId.IndexOf("," + str + ",");
                        if (intIndex != -1)
                        {
                            strEmpId = strEmpId.Remove(intIndex, (intLength + 1));
                        }
                        else
                        {
                            if (strEmpId.IndexOf(str + ",") != -1 && strEmpId.IndexOf(str + ",") == 0)
                            {
                                strEmpId = strEmpId.Remove(0, (intLength + 1));
                            }
                            else if (strEmpId.IndexOf("," + str) != -1 && (strEmpId.IndexOf("," + str) + intLength + 1) == intEmployeeIdsLength)
                            {
                                strEmpId = strEmpId.Substring(0, (intEmployeeIdsLength - (intLength + 1)));
                            }
                        }
                    }
                    else
                    {
                        strEmpId = strEmpId.Replace(empId, "");
                    }
                    intEmployeeIdsLength = strEmpId.Length;
                    Session["EmployeeIds"] = strEmpId;
                    goto D;
                }
            }
            D:;
        }
    }
    protected void lnkbtnGrid_Click(object sender, EventArgs e)
    {
        
        
        shiftDataBind();
       
    }

    protected string GetEmployeeIdsInOtherPagesOfGrid()
    {
        LevelID = Convert.ToInt32(Session["currentSession"]);
        Rpt_Common rptcommon = new Rpt_Common();
        string Level = "";
        if (LevelID != 0)
            Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
        string strEmpCodeID = "";
        //strEmpCodeID = Convert.ToString(txtEmpCodeID.Text).Replace("'", "''");
        string strPopShiftEmployeeId = null;
        if (Session["PopShiftEmpId"] != null)
        {
            strPopShiftEmployeeId = Session["PopShiftEmpId"].ToString();
        }
        if (ViewState["Employees"] != null)
        {
            ds = (DataSet)ViewState["Employees"];
        }
        else
        {
            ds = obj.SelectEmployeeForShiftAlloc(Convert.ToInt32(Session["EmpAutoId"]), Level, Convert.ToString(Session["UserGroupName"]), 
                Convert.ToString(Session["GradeLevel"]), strPopShiftEmployeeId, LevelID, txtEmployeeName.Text, 
                Convert.ToInt32(Session["EmpCategoryShift"]), Convert.ToInt32(Session["EmpTypeShift"]),
                Convert.ToInt32(0));
        }
        string strEmpId = string.Empty;
        string ChkBoxIDs = string.Empty;
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            foreach (GridViewRow gr in grv_Shift.Rows)
            {
                strEmpId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
                if (strEmpId == dr["Employee_Code_Id"].ToString())
                {
                    goto A;
                }
            }
            if (ChkBoxIDs == "")
            {
                ChkBoxIDs = dr["Employee_Code_Id"].ToString();
            }
            else
            {
                ChkBoxIDs = ChkBoxIDs + "," + dr["Employee_Code_Id"].ToString();
            }
            A:;
        }
        return ChkBoxIDs;
    }
    protected void grv_CheckAll_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkSelect = new CheckBox();
        chkSelect = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
        string ChkBoxIDs = string.Empty;
        if (chkSelect.Checked)
        {
            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
            if (Session["EmployeeIds"].ToString() == "")
            {
                Session["EmployeeIds"] = ChkBoxIDs;
            }
            else
            {
                if (ChkBoxIDs != "")
                {
                    Session["EmployeeIds"] = Session["EmployeeIds"] + "," + ChkBoxIDs;
                }
            }
        }
        else
        {
            Session["EmployeeIds"] = string.Empty;
        }
        foreach (GridViewRow gr in grv_Shift.Rows)
        {
            chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
            chkSelect.Checked = ((CheckBox)sender).Checked;
        }
    }
    protected void grv_Check_CheckedChanged(object sender, EventArgs e)
    {
        string ChkBoxIDs = string.Empty;
        int intCount = 0;
        int intGridPageSize = grv_Shift.PageSize;
        int intGridTotalPages = grv_Shift.PageCount;
        bool boolAllChecked = false;
        CheckBox chkSelect = new CheckBox();
        CheckBox chkSelectAll = new CheckBox();
        chkSelectAll = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
        if (((CheckBox)sender).Checked == false)
        {
            chkSelectAll.Checked = false;
        }
        else
        {
            foreach (GridViewRow gr in grv_Shift.Rows)
            {
                chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
                if (chkSelect.Checked)
                    intCount = intCount + 1;
            }
            if (Convert.ToInt32(Session["TotalEmployees"].ToString()) == intCount)
            {
                chkSelectAll.Checked = true;
            }
            else if (intCount > 0 && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intCount && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intGridPageSize)
            {
                if (intCount == intGridPageSize)
                {
                    if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                    {
                        ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                        char[] Delimit = { ',' };
                        string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                        string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                        Array.Sort(SessionEmployeeIds);
                        Array.Sort(ChedkedEmployeeIds);
                        if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                        {
                            for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                            {
                                if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                {
                                    boolAllChecked = false;
                                    break;
                                }
                            }
                            boolAllChecked = true;
                        }
                        if (boolAllChecked == true)
                        {
                            chkSelectAll.Checked = true;
                        }
                    }
                }
                else if (grv_Shift.PageIndex == intGridTotalPages - 1)
                {
                    int intLastPageCount = Convert.ToInt32(Session["TotalEmployees"].ToString()) - (intGridPageSize * (intGridTotalPages - 1));
                    if (intCount == intLastPageCount)
                    {
                        if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                        {
                            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                            char[] Delimit = { ',' };
                            string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                            string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                            Array.Sort(SessionEmployeeIds);
                            Array.Sort(ChedkedEmployeeIds);
                            if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                            {
                                for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                                {
                                    if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                    {
                                        boolAllChecked = false;
                                        break;
                                    }
                                }
                                boolAllChecked = true;
                            }
                            if (boolAllChecked == true)
                            {
                                chkSelectAll.Checked = true;
                            }
                        }
                    }
                }
            }
        }
    }

    protected void grv_EmpDetailss_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == GridViewRowType.Data)
        {
            //source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            //rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            Label DeletedRecord = (Label)grv_EmpDetailss.FindRowCellTemplateControl(e.VisibleIndex, null, "lblIsDeleted");
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True" || DeletedRecord.Text == rm.GetString("Grid_True", ci))
                {
                    DeletedRecord.ForeColor = System.Drawing.Color.Red;
                }
            }
            HtmlInputCheckBox deleteChkBxItem = (HtmlInputCheckBox)grv_EmpDetailss.FindRowCellTemplateControl(e.VisibleIndex, null, "chkSelect");
            // LinkButton LnkbtnDelete = (LinkButton)grv_EmpDetails.FindRowCellTemplateControl(e.VisibleIndex, null, "btnDelete");
            if (deleteChkBxItem != null)
            {
                int Employee = Convert.ToInt32(e.GetValue("Employee_Id"));
                //int Count = objEmployee.CountEmployee(Employee);
                //if (Count > 0)
                //{
                //    deleteChkBxItem.Disabled = true;
                //    // LnkbtnDelete.Enabled = false;
                //}
                //else
                //{
                //    deleteChkBxItem.Disabled = false;
                //    //LnkbtnDelete.Enabled = true;
                //}
            }
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True")
                {
                    DeletedRecord.Text = rm.GetString("Grid_True", ci);
                    //if (hdnDeletedData.Value == string.Empty)
                    //{
                    //    hdnDeletedData.Value = Convert.ToString(e.GetValue("Employee_Id"));
                    //}
                    //else
                    //{
                    //    //if (hdnDeletedData.Value.Contains(Convert.ToString(e.GetValue("Employee_Id"))) == false)
                    //    //{
                    //    //    hdnDeletedData.Value = hdnDeletedData.Value + "," + Convert.ToString(e.GetValue("Employee_Id"));
                    //    //}
                    //}
                }
                else if (DeletedRecord.Text == "False")
                {
                    DeletedRecord.Text = rm.GetString("Grid_False", ci);
                }
            }
        }
    }



    public void shiftDataBind()
    {
        LevelID = Convert.ToInt32(Session["parentLevelIdManual"]); 
        string strEmpCodeID = "";
        //strEmpCodeID = Convert.ToString(txtEmpCodeID.Text).Replace("'", "''");
        Rpt_Common rptcommon = new Rpt_Common();
        string Level = "";
        if (LevelID != 0)
        {
            Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
            //lblError.Text = "";
        }
        else
        {
            grv_Shift.DataBind();
           // Div1.Visible = false;
            //btn_done1.Visible = false;
            string strMsg;
            strMsg = "<script language='javascript'>";
            strMsg = strMsg + "alert('" + rm.GetString("Alert_Selectallorganizationlevels", ci) + "');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("Display Message", strMsg);
            //checkLevel = true;
            checkRecordExists = false;
            return;
        }
        string strPopShiftEmployeeId = null;
        if (Session["PopShiftEmpId"] != null)
        {
            strPopShiftEmployeeId = Convert.ToString(Session["PopShiftEmpId"]);
        }
        ds = obj.SelectEmployeeForShiftAlloc(Convert.ToInt32(Session["EmpAutoId"]), Level, Convert.ToString(Session["UserGroupName"]), 
            Convert.ToString(Session["GradeLevel"]), strPopShiftEmployeeId, LevelID, txtEmployeeName.Text, Convert.ToInt32(Session["EmpCategoryShift"]), 
            Convert.ToInt32(Session["EmpTypeShift"]), 
            Convert.ToInt32(0));
        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                grv_Shift.DataSource = ds.Tables[0];
                grv_Shift.DataBind();
                Session["TotalEmployees"] = ds.Tables[0].Rows.Count;
                ViewState["Employees"] = ds;
                grv_EmpDetailss.DataSource = ds;
                grv_EmpDetailss.DataBind();
                divShift.Visible = true;
                //btn_done1.Visible = true;
            }
            else
            {
                
                //btn_done1.Visible = false;
                checkRecordExists = false;
            }
        }
        else
        {
            checkRecordExists = false;
        }
        if (checkRecordExists == true)
        {
            CheckBox chkSelect = new CheckBox();
            chkSelect = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
            chkSelect.Checked = Convert.ToBoolean(Session["SelectAllStatus"]);
        }
       
    }
    [WebMethod]
    public static void GetSelectedRowsData(List<Dictionary<string, string>> selectedRowsData)
    {

        DataSet dataSet = new DataSet();
        DataTable dataTable = new DataTable();

        // Add columns to the DataTable
        dataTable.Columns.Add("EmployeeId", typeof(string));
        dataTable.Columns.Add("EmployeeCodeId", typeof(string));
        // Process selectedRowsData
        foreach (var row in selectedRowsData)
        {
            string employeeId = row["EmployeeId"];
            string employeeCodeId = row["EmployeeCodeId"];
            DataRow newRow = dataTable.NewRow();
            newRow["EmployeeId"] = employeeId;
            newRow["EmployeeCodeId"] = employeeCodeId;
            dataTable.Rows.Add(newRow);

            // Do whatever you want with the data
        }
        dataSet.Tables.Add(dataTable);

        HttpContext.Current.Session["Employees"] = dataSet;

    }
    private void InsertMultipleEmployeeManualEntry()
    {
        int intEmployeeId = 0;
        int intLoopCounter = 0;
        string strEmployeeCode = string.Empty;
        string strEmployeeName = string.Empty;
        LevelID = Convert.ToInt32(Session["currentSession"]);
        Rpt_Common rptcommon = new Rpt_Common();
        string Level = "";
        if (LevelID != 0)
            Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
        int Countss = 0;

        


        if (ViewState["Employees"] != null)
        {
            ds = (DataSet)ViewState["Employees"];
            int intCount = ds.Tables[0].Rows.Count;
            string hdnSelectRowValue = hdnSelectRow.Value.ToString();
            string[] values = hdnSelectRowValue.Split(',');
            if (hdnSelectRowValue != "")
            {
                foreach (string hdnEm in values)
                {

                    for (int i = 0; i < intCount; i++)
                    {
                        if (hdnEm == ds.Tables[0].Rows[i]["Employee_Id"].ToString())
                        {
                            intEmployeeId = Convert.ToInt32(ds.Tables[0].Rows[i]["Employee_Id"].ToString());
                            strEmployeeCode = Convert.ToString(ds.Tables[0].Rows[i]["Employee_Code_Id"].ToString());
                            strEmployeeName = Convert.ToString(ds.Tables[0].Rows[i]["Employee Name"].ToString());
                            Session["strEmployeeCode"] = strEmployeeCode;
                            AddMultipleManualEntryDetails(strEmployeeCode, "S", intEmployeeId);
                            Countss = Countss + 1;
                        }
                    }


                }
            }
            else
            {
                string strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + " Select the Listed Employee " + "');";
                strScript = strScript + "</script>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);


            }
            
           
            if (Countss > 0)
            {
                String ShiftINs = Convert.ToString(Session["ShiftIN"]);
                String ShiftOuts = Convert.ToString(Session["ShiftOut"]);
                String FinalCon = String.Empty;
                if (ShiftINs != String.Empty || ShiftINs != "")
                {
                    FinalCon = ShiftINs + " Attendance saved successfully";
                }
                else
                {
                    FinalCon = ShiftOuts + " Attendance saved successfully";
                }

                string strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + FinalCon + "');";
                strScript = strScript + "location.replace('TA_UI_Transactions_ManualTimeEntry.aspx');";
                strScript = strScript + "</script>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            }
           
        }
        else
        {
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + " Select the Listed Employee " +"');";
            strScript = strScript + "</script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
        }
    }


    public void AddMultipleManualEntryDetails(string EmployeeId, string Type, int EmployeeAutoId)
    {
        DataSet ds_EntranceDetails = new DataSet();
        int intEntranceId, intInReaderId = 0, intOutReaderId = 0, intRouteId = 0, intShiftId = 0;
        string strInDate = string.Empty, strOutDate = string.Empty, strInTime = string.Empty, strOutTime = string.Empty, strManualTimeEntryStatus = string.Empty;
        string strIsINPunchPresent = "N";
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);


        strInDate = objCommon.DateConvertion(gstrDateFormat, txt_Dates.Text);
        strInTime = txt_Times.Text;
        strOutDate = objCommon.DateConvertion(gstrDateFormat, txt_Dates.Text);
        strOutTime = txt_Times.Text;

        //strInDate = DateTime.Now.Date.ToString();
        //strInTime = DateTime.Now.TimeOfDay.ToString();
        //strOutDate =  DateTime.Now.ToString();
        //strOutTime = DateTime.Now.TimeOfDay.ToString();


        string strDateOfJoining = string.Empty, strFlag = "Y";
        DataSet dsEmployeeDOJ = new DataSet();
        String Emp = Convert.ToString( Session["strEmployeeCode"]);
        dsEmployeeDOJ = objEmployee.GetEmployeeDateOfJoining(Convert.ToString(Session["strEmployeeCode"]), "", "", "S");
        if (dsEmployeeDOJ.Tables[0].Rows.Count > 0)
        {
            if (dsEmployeeDOJ.Tables[0].Rows[0]["DateOfJoining"] != DBNull.Value)
            {
                strDateOfJoining = Convert.ToString(dsEmployeeDOJ.Tables[0].Rows[0]["DateOfJoining"]);
            }
        }
        if (strDateOfJoining != string.Empty) 
       {
            DateTime dtmDateOfJoining = DateTime.Parse(strDateOfJoining);
             ShiftIN = Convert.ToString(Session["ShiftIN"]);
             ShiftOut = Convert.ToString(Session["ShiftOut"]);

            #region  ShiftIN
            if (ShiftIN == "ShiftIN" || ShiftIN == "Break IN")
            {
                if (strInDate != string.Empty)
                {
                    strIsINPunchPresent = "Y";
                    DateTime dtmInDate = DateTime.Parse(strInDate);
                    if (dtmInDate < dtmDateOfJoining)
                    {
                        strFlag = "N";
                        if (Type == "S")
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_IndateGreaterThanEmpDOJ", ci) + "');", true);
                            string scrt = "<script>ManualTimeEntry()</script>";
                            this.Page.RegisterStartupScript("a", scrt);
                            hdn_InPunchType.Value = "";
                            hdn_OutPunchType.Value = "";
                            ddlInPunchTypes.SelectedIndex = 0;
                            ddlOutPunchTypes.SelectedIndex = 0;
                            hdn_InTerminal.Value = "";
                            hdn_OutTerminal.Value = "";
                            txt_InDate.Focus();
                            return;
                        }
                        if (Type == " ")
                        {
                            gstrDOJValidation = gstrDOJValidation + " " + EmployeeId;
                        }
                    }
                    intShiftId = objShiftExchange.SelectShiftId(EmployeeId, dtmInDate.Year.ToString(), dtmInDate.Month.ToString(), dtmInDate.Day.ToString());
                    if (intShiftId == 0)
                    {
                        strFlag = "N";
                        if (Type == "S")
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ManualTimeEntry", ci) +". Employee ID:" + EmployeeId + "');", true);
                            string scrt = "<script>ManualTimeEntry()</script>";
                            this.Page.RegisterStartupScript("a", scrt);
                            hdn_InPunchType.Value = "";
                            hdn_OutPunchType.Value = "";
                            ddlInPunchTypes.SelectedIndex = 0;
                            ddlOutPunchTypes.SelectedIndex = 0;
                            txt_InDate.Focus();
                            return;
                        }
                        if (Type == " ")
                        {
                            gstrShiftValidation = gstrShiftValidation + " " + EmployeeId;
                        }
                    }


                }
            }

            #endregion

            #region ShiftOut
            if (ShiftOut== "ShiftOut" || ShiftOut == "Break Out")
            {
                if (strOutDate != string.Empty)
                {
                    DateTime dtmOutDate = DateTime.Parse(strOutDate);
                    if (dtmOutDate < dtmDateOfJoining)
                    {
                        strFlag = "N";
                        if (Type == "S")
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_OutdategreaterthanEmpDOJ", ci) + "');", true);
                            string scrt = "<script>ManualTimeEntry()</script>";
                            this.Page.RegisterStartupScript("a", scrt);
                            hdn_InPunchType.Value = "";
                            hdn_OutPunchType.Value = "";
                            ddlInPunchTypes.SelectedIndex = 0;
                            ddlOutPunchTypes.SelectedIndex = 0;
                            hdn_InTerminal.Value = "";
                            hdn_OutTerminal.Value = "";
                            txt_OutDate.Focus();
                            return;
                        }
                        if (Type == " ")
                        {
                            gstrDOJValidation = gstrDOJValidation + " " + EmployeeId;
                        }
                    }
                    if (strIsINPunchPresent == "N")
                    {
                        intShiftId = objShiftExchange.SelectShiftId(EmployeeId, dtmOutDate.Year.ToString(), dtmOutDate.Month.ToString(), dtmOutDate.Day.ToString());
                        if (intShiftId == 0)
                        {
                            strFlag = "N";
                            if (Type == "S")
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ManualTimeEntry", ci) + "');", true);
                                string scrt = "<script>ManualTimeEntry()</script>";
                                this.Page.RegisterStartupScript("a", scrt);
                                hdn_InPunchType.Value = "";
                                hdn_OutPunchType.Value = "";
                                ddlInPunchTypes.SelectedIndex = 0;
                                ddlOutPunchTypes.SelectedIndex = 0;
                                txt_OutDate.Focus();
                                return;
                            }
                            if (Type == " ")
                            {
                                gstrShiftValidation = gstrShiftValidation + " " + EmployeeId;
                            }
                        }
                    }
                }
            }

                
            #endregion
            
        }




        if (ShiftIN == "ShiftIN" || ShiftIN == "Break IN")
        {
            //count = objManualEntry.CheckManualEntry(EmployeeId, strInDate, strInTime, strOutDate, strOutTime);
            count = objManualEntry.CheckManualEntry(EmployeeId, Convert.ToString( Convert.ToDateTime( strInDate).ToString("yyyy/MM/dd")),
                Convert.ToString(Convert.ToDateTime( strInTime).ToString("hh:mm:ss tt")), "", "");
        }
        else
        {
            count = objManualEntry.CheckManualEntry(EmployeeId,"","", Convert.ToString(Convert.ToDateTime(strOutDate).ToString("yyyy/MM/dd")),
                Convert.ToString(Convert.ToDateTime(strOutTime).ToString("hh:mm:ss tt")));
            //count = objManualEntry.CheckManualEntry(EmployeeId, "", "", strOutDate, strOutTime);
        }

        if (count == 0)
        {
            if (strFlag == "Y")
            {
                intEntranceId = int.Parse(ddlEntranceName.SelectedValue);
                if (Type == "GB")
                {
                    intRouteId = int.Parse(ddlRouteName.SelectedValue);
                }
                string strInPunchType = hdn_InPunchType.Value;
                string strOutPunchType = hdn_OutPunchType.Value;
                if (hdn_InTerminal.Value != "")
                {
                    intInReaderId = Convert.ToInt32(hdn_InTerminal.Value);
                }
                else
                {
                    intInReaderId = 0;
                }
                if (hdn_OutTerminal.Value != "")
                {
                    intOutReaderId = Convert.ToInt32(hdn_OutTerminal.Value);
                }
                else
                {
                    intOutReaderId = 0;
                }
                string strEntryDate = Convert.ToString( DateTime.Now.Date.ToString("MM/dd/yyyy"));
                strManualTimeEntryStatus = GetManualTimeEntryStatus(EmployeeId);
                if (strInTime != string.Empty)
                {
                    strInTime = Convert.ToDateTime(strInTime).ToString("hh:mm:ss tt");
                }
                if (strOutTime != string.Empty)
                {
                    strOutTime = Convert.ToDateTime(strOutTime).ToString("hh:mm:ss tt");
                }
                if (manualEntryExists == 1)
                {
                    if (approvalSettingsPageExists == 1)
                    {
                        int intCompanyId = base.GetCompanyId(EmployeeAutoId);
                        DataSet dsApprovalSettings = new DataSet();
                        ShiftEvenData objShift = new ShiftEvenData();
                        dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
                        if (dsApprovalSettings != null)
                        {
                            if (dsApprovalSettings.Tables.Count > 0)
                            {
                                if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                                {
                                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ManualEntry"]) == false)
                                    {
                                        strManualTimeEntryStatus = "Approved";
                                    }
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ApprovalSettings", ci) + "');", true);
                                    return;
                                }
                            }
                        }
                    }
                }
                else
                {
                    strManualTimeEntryStatus = "Approved";
                }

                String Savedby =Convert.ToString(Session["EmployeeId"]).ToUpper();
                String SavebyName  = Convert.ToString(Session["user"]);
                String CreatedNameAndID = "Rasied by- " + SavebyName + "," + Savedby;

                if (ShiftIN == "ShiftIN" || ShiftIN == "Break IN")
                {
                    DataSet dsInTerminals = new DataSet(); 
                    dsInTerminals = objEntrance.SelectEntranceINOUTDetailsByIDview(Convert.ToInt32(1), "In");
                    String Readerr = Convert.ToString(dsInTerminals.Tables["Table"].Rows[0]["Reader_Id"]);
                    DataSet dsInPunchTypes = new DataSet();
                    dsInPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(Convert.ToInt32(Readerr), "I");

                    if(dsInPunchTypes.Tables[0].Rows.Count>0)
                    {
                        intInReaderId = Convert.ToInt32(dsInPunchTypes.Tables["Table"].Rows[0]["PunchType_Id"]);
                    }
                    if (ShiftIN == "ShiftIN")
                    {
                        IN = "IN";

                        objManualEntry.InsertManualEntry(EmployeeId, DateTime.Parse(strEntryDate), strInDate, strInTime,
                   IN, "", "", "", intInReaderId, 0,
                   CreatedNameAndID, 0, strManualTimeEntryStatus,
                   DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), 0, 0);

                    }
                    else if (ShiftIN == "Break IN")
                    {
                        BreaKIN = "Break In";
                        objManualEntry.InsertManualEntry(EmployeeId, DateTime.Parse(strEntryDate), strInDate, strInTime,
                   BreaKIN, "", "", "", intInReaderId, 0,
                   CreatedNameAndID, 0, strManualTimeEntryStatus,
                   DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), 0, 0);
                    }

                }
                else
                {

                    DataSet dsInTerminals = new DataSet();
                    dsInTerminals = objEntrance.SelectEntranceINOUTDetailsByIDview(Convert.ToInt32(1), "Out");
                    String Readerr = Convert.ToString(dsInTerminals.Tables["Table"].Rows[0]["Reader_Id"]);

                    DataSet dsOutPunchTypes = new DataSet();
                    dsOutPunchTypes = objPunchTypes.Select_PunchTypeDetailsByTerminalId(Convert.ToInt32(Readerr), "O");

                    if (dsOutPunchTypes.Tables[0].Rows.Count > 0)
                    {
                        
                        for (int i = 0; i < dsOutPunchTypes.Tables[0].Rows.Count;i++)
                        {
                            if (Convert.ToString(dsOutPunchTypes.Tables["Table"].Rows[i]["PunchType_Value"]) == "Break Out")
                            {
                                intOutReaderId = Convert.ToInt32(dsOutPunchTypes.Tables["Table"].Rows[i]["PunchType_Id"]);
                            }
                            else if(Convert.ToString(dsOutPunchTypes.Tables["Table"].Rows[i]["PunchType_Value"]) == "Out")
                            {
                                intOutReaderId = Convert.ToInt32(dsOutPunchTypes.Tables["Table"].Rows[i]["PunchType_Id"]);
                            }
                        }
                    }

                    //objManualEntry.InsertManualEntry(EmployeeId, DateTime.Parse(strEntryDate), strInDate, txt_ShiftIn.Text,
                    //strInPunchType, strOutDate, txt_ShiftOut.Text, strOutPunchType, intInReaderId, intOutReaderId,
                    //txt_Reason.Text.Trim().Replace("'", "''"), intRouteId, strManualTimeEntryStatus,
                    //DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), 0, 0);


                    if (ShiftOut == "ShiftOut")
                    {
                        Out = "Out";
                        objManualEntry.InsertManualEntry(EmployeeId, DateTime.Parse(strEntryDate), "", "",
                  "", strOutDate, strOutTime, Out, 0, intOutReaderId,
                 CreatedNameAndID, 0, strManualTimeEntryStatus,
                  DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), 0, 0);
                    }
                    else if (ShiftOut == "Break Out")
                    {
                        BreakOut = "Break Out";
                        objManualEntry.InsertManualEntry(EmployeeId, DateTime.Parse(strEntryDate), "", "",
                  "", strOutDate, strOutTime, BreakOut, 0, intOutReaderId,
                 CreatedNameAndID, 0, strManualTimeEntryStatus,
                  DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), gintUserId, ViewState["YearSettings_Id"].ToString(), 0, 0);

                    }

                   

                }
                ShiftIN = "";
                ShiftOut = "";


                objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
                Session["EmpDetails"] = null;
            }
            else
            {
                if (gstrEmployeeIds == "")
                {
                    gstrEmployeeIds = EmployeeId;
                }
                else
                {
                    gstrEmployeeIds = gstrEmployeeIds + "," + EmployeeId;
                }
            }
            if (Type == "S")
            {
                //string strScript = "";
                //strScript = strScript + "<script language='javascript'>";
                //strScript = strScript + "alert('" + rm.GetString("Msg_ManualTimeEntrySuccessfull", ci) + "');";
                //strScript = strScript + "location.replace('TA_UI_Transactions_ManualTimeEntry.aspx');";
                //strScript = strScript + "</script>";
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            }
        }
        else
        {
            if (Type == "S")
            {
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ManualEntryAddedAlready", ci) + "');", true);
                //string scrt = "<script>ManualTimeEntry()</script>";
                //this.Page.RegisterStartupScript("a", scrt);
                //hdn_InPunchType.Value = "";
                //hdn_OutPunchType.Value = "";
                //ddlInPunchTypes.SelectedIndex = 0;
                //ddlOutPunchTypes.SelectedIndex = 0;
            }
        }
    }


    protected void btn_ShiftIN_Click(object sender, EventArgs e)
    {
        Session["ShiftOut"] = "";
        Session["ShiftIN"] = "ShiftIN";
        DataSet DS = (DataSet)Session["Employees"];
        if (txt_Dates.Text==String.Empty || txt_Dates.Text == "" || txt_Times.Text== String.Empty || txt_Times.Text=="")
        {
            this.Page.RegisterStartupScript("Show", "<script> rbtBox()</script>");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "ShowOffical('" + "Enter Either InDate and InTime (or) OutDate and OutTime (or) Both" +"');", true);
          
        }
        else
        {
            InsertMultipleEmployeeManualEntry();
        }

    }

    protected void btn_BreakOut_Click(object sender, EventArgs e)
    {
        Session["ShiftIN"] = "";
        Session["ShiftOut"] = "Break Out";
        if (txt_Dates.Text == String.Empty || txt_Dates.Text == "" || txt_Times.Text == String.Empty || txt_Times.Text == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + "Enter Either InDate and InTime (or) OutDate and OutTime (or) Both" + "');", true);
           
        }
        else
        {
            InsertMultipleEmployeeManualEntry();
        }
    }

    protected void btn_BreakIN_Click(object sender, EventArgs e)
    {
        Session["ShiftOut"] = "";
        Session["ShiftIN"] = "Break IN";
        if (txt_Dates.Text == String.Empty || txt_Dates.Text == "" || txt_Times.Text == String.Empty || txt_Times.Text == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + "Enter Either InDate and InTime (or) OutDate and OutTime (or) Both" + "');", true);
           
        }
        else
        {
            InsertMultipleEmployeeManualEntry();
        }
    }

    protected void btn_ShiftOut_Click(object sender, EventArgs e)
    {
        Session["ShiftIN"] = "";
        Session["ShiftOut"] = "ShiftOut";
        if (txt_Dates.Text == String.Empty || txt_Dates.Text == "" || txt_Times.Text == String.Empty || txt_Times.Text == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + "Enter Either InDate and InTime (or) OutDate and OutTime (or) Both" + "');", true);
          
        }
        else
        {
            InsertMultipleEmployeeManualEntry();
        }
    }


    #region  Old test only
    //CheckBox chkSelect = new CheckBox();
    //CheckBox chkSelectAll = new CheckBox();
    //chkSelectAll = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
    //if (chkSelectAll.Checked)
    //{
    //foreach (DataRow dr in ds.Tables[0].Rows)
    //{
    //    intEmployeeId = Convert.ToInt32(dr["Employee_Id"]);
    //    strEmployeeCode = Convert.ToString(dr["Employee_Code_Id"]);
    //    strEmployeeName = Convert.ToString(dr["Employee Name"]);
    //    Session["strEmployeeCode"] = strEmployeeCode;
    //    AddMultipleManualEntryDetails(strEmployeeCode, "S", intEmployeeId);
    //}
    //}
    //else
    //{
    //    foreach (GridViewRow gr in grv_Shift.Rows)
    //    {
    //        chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
    //        if (chkSelect.Checked)
    //        {
    //            string strEmpCodeId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
    //            for (intLoopCounter = 0; intLoopCounter < intCount; intLoopCounter++)
    //            {
    //                if (ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString() == strEmpCodeId)
    //                {
    //                    intEmployeeId = Convert.ToInt32(ds.Tables[0].Rows[intLoopCounter]["Employee_Id"].ToString());
    //                    strEmployeeCode = ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString();
    //                    strEmployeeName = ds.Tables[0].Rows[intLoopCounter]["Employee Name"].ToString();
    //                    Session["strEmployeeCode"] = strEmployeeCode;
    //                    AddMultipleManualEntryDetails(strEmployeeCode, "S", intEmployeeId);

    //                     Countss = Countss + 1;
    //                }
    //            }
    //        }


    //    }
    //    if(Countss>0)
    //    {
    //        string strScript = "";
    //        strScript = strScript + "<script language='javascript'>";
    //        strScript = strScript + "alert('" + rm.GetString("Msg_ManualTimeEntrySuccessfull", ci) + ". Employee Counts:" + Countss + "');";
    //        strScript = strScript + "location.replace('TA_UI_Transactions_ManualTimeEntry.aspx');";
    //        strScript = strScript + "</script>";
    //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
    //    }

    //}

    //protected void InsertEmployeeDetails()
    //{
    //    int intEmployeeId = 0;
    //    int intLoopCounter = 0;
    //    string strEmployeeCode = string.Empty;
    //    string strEmployeeName = string.Empty;
    //    string strEmployeeIds = Convert.ToString(Session["EmployeeIds"]);
    //    char[] Delimit = { ',' };
    //    string[] EmployeeIds = strEmployeeIds.Split(Delimit);
    //    LevelID = Convert.ToInt32(Session["currentSession"]);
    //    //Rpt_Common rptcommon = new Rpt_Common();
    //    string Level = "";
    //    if (LevelID != 0)
    //        Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
    //    string strEmpCodeID = "";
    //    strEmpCodeID = Convert.ToString(txtEmployeeName.Text).Replace("'", "''");
    //    string strPopShiftEmployeeId = null;
    //    if (Session["PopShiftEmpId"] != null)
    //    {
    //        strPopShiftEmployeeId = Convert.ToString(Session["PopShiftEmpId"]);
    //    }
    //    if (ViewState["Employees"] != null)
    //    {
    //        ds = (DataSet)ViewState["Employees"];
    //    }
    //    else
    //    {
    //        ds = obj.SelectEmployeeForShiftAlloc(Convert.ToInt32(Session["EmpAutoID"]), Level, Convert.ToString(Session["UserGroupName"]), 
    //            Convert.ToString(Session["GradeLevel"]), strPopShiftEmployeeId, LevelID, txtEmployeeName.Text, Convert.ToInt16(Session["EmpCategoryShift"]),
    //            Convert.ToInt16(Session["EmpTypeShift"]), 1);
    //    }
    //    int intCount = ds.Tables[0].Rows.Count;
    //    System.Web.UI.HtmlControls.HtmlInputRadioButton chkSelect = new System.Web.UI.HtmlControls.HtmlInputRadioButton();

    //    foreach (GridViewRow gr in grv_Shift.Rows)
    //    {
    //        chkSelect = (System.Web.UI.HtmlControls.HtmlInputRadioButton)gr.Cells[0].FindControl("rdbId");
    //        if (chkSelect.Checked)
    //        {
    //            string strEmpCodeId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
    //            for (intLoopCounter = 0; intLoopCounter < intCount; intLoopCounter++)
    //            {
    //                if (ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString() == strEmpCodeId)
    //                {
    //                    intEmployeeId = Convert.ToInt32(ds.Tables[0].Rows[intLoopCounter]["Employee_Id"].ToString());
    //                    strEmployeeCode = ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString();
    //                    strEmployeeName = ds.Tables[0].Rows[intLoopCounter]["Employee Name"].ToString();
    //                    obj.DeleteEmpShiftDetails(Convert.ToInt32(Session["EmpAutoID"]));
    //                    obj.InsertEmpDetails(intEmployeeId, strEmployeeCode, strEmployeeName.Replace("'", "''"), loginEmployeeId);
    //                }
    //            }
    //        }
    //    }

    //}



    //public void shiftDataBind()
    //{

    //   // LevelID = (int)Session["currentSession"];
    //   //String  ch= rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
    //    LevelID = Convert.ToInt32(Session["GETOrgParentID"]);
    //    string US = Convert.ToString(Session["UserGroupName"]);
    //    String LR = Convert.ToString(Session["LevelRights"]);
    //    //Session["parentLevelId"] = null;
    //    if (LevelID == 0)
    //    {
    //        //ds = obj.SelectEmployee(LevelID);
    //        //grv_Shift.DataSource = ds.Tables[0];
    //        //grv_Shift.DataBind();
    //        //grv_Shift.Visible = true;
    //        //gcheckParentLevelExist = false;
    //        grv_Shift.DataSourceID = "";
    //        grv_Shift.DataBind();
    //        //lbl_Error.Text = "Select Organization Level";
    //        string strMsg;
    //        strMsg = "<script language='javascript'>";
    //        strMsg = strMsg + "alert('" + rm.GetString("Alert_Selectallorganizationlevels", ci) + "');";
    //        strMsg = strMsg + "</script>";
    //        Page.RegisterStartupScript("Display Message", strMsg);
    //        //checkLevel = true;
    //        btn_ShiftIN.Visible = false;
    //        btn_BreakIN.Visible = false;
    //        btn_BreakOut.Visible = false;
    //        btn_ShiftOut.Visible = false;
    //        return;
    //    }
    //    else
    //    {
    //        //Rpt_Common rptcommon = new Rpt_Common();
    //        string Level = "";
    //        Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
    //        ds = obj.SelectEmployeeforpopup(Convert.ToInt32(Session["EmpAutoId"]), Level, Convert.ToString(Session["UserGroupName"]), 
    //            Convert.ToString(Session["GradeLevel"]), Convert.ToInt32(Session["currentSession"]), txt_EmployeeId.Text, txtEmployeeName.Text,
    //            Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), "");
    //        if (ds.Tables[0].Rows.Count > 0)
    //        {
    //            grv_Shift.DataSource = ds.Tables[0];
    //            grv_Shift.DataBind();
    //            divShift.Visible = true;
    //            //gcheckParentLevelExist = true;
    //            btn_ShiftIN.Visible = true;
    //            btn_BreakIN.Visible = true;
    //            btn_BreakOut.Visible = true;
    //            btn_ShiftOut.Visible = true;

    //        }
    //        else
    //        {
    //            //gcheckParentLevelExist = false;
    //        }
    //        lbl_Error.Text = "";
    //    }
    //}
    #endregion

    //private void page_init()
    //{

    //}

}
