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;
/****************************************************************************************************************************
* 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();
    DataSet ds_Checkuser = new DataSet();
    CultureInfo ci;
    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 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;
    DateTime dtmIn = new DateTime();
    DateTime dtmOut = new DateTime();
    #endregion
    #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"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        Hidden2.Value = Convert.ToString(Session["ITimeFormat"]);
        hiddenTime.Value = "HH:mm";
        TimeFormat = Convert.ToString(Session["ITimeFormat"]);
        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"]);
        lbl_EntryDate.Text = DateTime.Now.ToString(Convert.ToString(Session["MDateFormat"]) + " HH:mm:ss tt");
        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();
            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>");
                }
            }
        }
        if (Convert.ToString(Session["Demo"]) == "Express")
        {
            rbtGroup.Visible = false;
        }
        this.Page.RegisterStartupScript("EmployeeName", "<script> EmpName('ManualTimeEntry')</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);
        }
        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);
        }
        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();
    }
    /// <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);
    }
    /// <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)
    {
        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;
                    }
                }
            }
        }
        DateTime dtmCurrentDateTime = DateTime.Parse(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
        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
}
