using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                         Started Date  : 12-Aug-2007
* Module          : Shift Master                                      Last Modified : 19-Aug-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_ShiftModify : Base.BasePage
{
    #region Eastman
    EmployeeEventData objEmployee = new EmployeeEventData();
    #endregion
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    ShiftEvenData obj_Shift = new ShiftEvenData();
    int ShiftId, Emp_ID;
    ShiftEvenData objShift = new ShiftEvenData();
    cls_Common objCommon = new cls_Common();
    DateTime dt_ShitBin1, dt_ShiftBout1, dt_ShiftBin2, dt_ShiftBout2, dt_ShiftBin3, dt_ShiftBout3, ShiftIn, ShiftOut;
    int count, CheckBrk;
    string strshiftIn, strShiftout, strbrkIn1, strbrkOut1, strbrkIn2, strbrkOut2, strbrkIn3, strbrkOut3, maxot, minot;
    string gstrUserGroupName = string.Empty;
    int payrollConfig = 0;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        Emp_ID = Convert.ToInt32(Session["EmpAutoID"]);
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        //Set UserRights
        UserRights();
        ShiftId = Convert.ToInt16(Request.QueryString["SID"]);
        if (!Page.IsPostBack)
        {
            Hidden1.Value = Convert.ToString(Session["ITimeFormat"]);
            ddlCompany.Focus();
            CompanyBinding();
            BindingEmployeeCategory();
            GetShiftDetails();

            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "ChMaxLengthh('" + rm.GetString("Alert_Maximumlengthis250", ci) + "');";
            strSetAlert = strSetAlert + "InvalidFun('" + rm.GetString("Alert_InvalidBreaTime", ci) + "');";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_Select_Company") + "','" + rm.GetString("Alert_EnterShiftName") + "','" + rm.GetString("Alert_EnterShiftShortName") + "','" + rm.GetString("Alert_EnterShiftIntime") + "','" + rm.GetString("Alert_EnterShiftOuttime") + "','" + rm.GetString("Alert_Selectfirsthalfstarttime") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_Selectfirsthalfendtime") + "','" + rm.GetString("Alert_Selectsecondhalfstarttime") + "','" + rm.GetString("Alert_Selectsecondhalfendtime") + "','" + rm.GetString("Alert_SelectBreakEndTime1") + "','" + rm.GetString("Alert_SelectBreakStartTime1") + "','" + rm.GetString("Alert_SelectBreakEndTime2") + "',";
            strSetAlert = strSetAlert + "'" + rm.GetString("Alert_SelectBreakStartTime2") + "','" + rm.GetString("Alert_SelectBreakEndTime3") + "','" + rm.GetString("Alert_SelectBreakStartTime3") + "','" + rm.GetString("Alert_ClickCalculateHours") + "','" + rm.GetString("Alert_ConfirmSave") + "','" + rm.GetString("Alert_InValidTimeFormats") + "','" + rm.GetString("GraceShiftIn") + "','" + rm.GetString("GraceShiftOut") + "','" + rm.GetString("EnterminOT") + "','" + rm.GetString("EntermaxOT") + "','" + rm.GetString("Alert_EntervalidGraceShiftIn") + "','" + rm.GetString("Alert_EntervalidGraceShiftOut") + "','" + rm.GetString("Alert_EntervalidMinimumExtraTimeForOT") + "','" + rm.GetString("Alert_EnterMaximumExtraTimeForOT") + "','" + rm.GetString("Alert_MaximumExtraTimeForOTMinimum") + "','" + rm.GetString("Alert_EnterOverTimeOnWorkingDays") + "','" + rm.GetString("Alert_EntervaliddatainOverTimeOnWorkingDays") + "','" + rm.GetString("Alert_EnterMinimumExtraTimeForOT") + "','" + rm.GetString("Alert_MaximumExtraTimeForOT") + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
            objCommon.menu("ShiftMaster", "19");
        }
        //if the shift is used in shift allocation or shift pattern,our application will allow to modify only grace min & break hours
        DisableControls();
        payrollConfig = objCommon.CheckPageExistsInLicense(185);
        /*Below parameter is used for Angler*/
        if (payrollConfig == 1)
        {
            lblshiftType.Style.Add("display", "none");
            lblshiftType1.Style.Add("display", "none");
        }
        divEastmanShifts.Style.Add("display", "none");
        divspOT1.Style.Add("display", "none");
        divspOT2.Style.Add("display", "none");
        #region packageIDCalling
        if (Convert.ToString(Session["packageID"]) != "")
        {
            switch (Convert.ToString(Session["packageID"]))
            {
                case "155":
                    //Eastman
                    divEastmanShifts.Style.Add("display", "");
                    break;
                case "156":
                    //iffco
                    divspOT1.Style.Add("display", "");
                    divspOT2.Style.Add("display", "");
                    break;
                default:
                    break;
            }
        }

        if (Convert.ToString(Session["packageID"]) != "")
        {
            if (Convert.ToInt32(Session["packageID"]) < 159)//vaigai and future clients
            {
                lbl_MaxShiftWorkHours.Style.Add("display", "none");
                txtMaxShiftWorkHours.Style.Add("display", "none");
            }
        }

        #endregion
    }
    #endregion
    #region UserDefinedFunctions
    private void CompanyBinding()
    {
        DataSet dsCompany = new DataSet();
        dsCompany = objShift.SelectCompany(gstrUserGroupName, Convert.ToString(Session["LevelRights"]), 0);
        if (dsCompany != null)
        {
            if (dsCompany.Tables[0].Rows.Count > 0)
            {
                ddlCompany.DataSource = dsCompany;
                ddlCompany.DataTextField = "CompanyName";
                ddlCompany.DataValueField = "CompanyId";
                ddlCompany.DataBind();
            }
        }
        foreach (ListItem item in ddlCompany.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void DisableControls()
    {
        if (gstrUserGroupName != "SuperAdmin")
        {
            int count = obj_Shift.CheckShift_Delete(ShiftId);
            if (count > 0)
            {
                ddlCompany.Enabled = false;
                txt_FirstHalfEndTime.Enabled = false;
                txt_FirstHalfEndTime.Enabled = false;
                txt_MaxOTtime.Enabled = false;
                txt_SecondHalfEndTime.Enabled = false;
                txt_SecondHalfStartTime.Enabled = false;
                txt_ShiftDescription.Enabled = false;
                txt_ShiftInTime.Enabled = false;
                if (txt_ShiftName.Text == "No Shift")
                {
                    txt_ShiftName.Enabled = false;
                }
                txt_ShiftOuttime.Enabled = false;
                //txt_TotalWorkingHourrs.Enabled = false;
                if (txtShiftShortName.Text == "NOS")
                {
                    txtShiftShortName.Enabled = false;
                }
                txt_MinOTtmie.Enabled = false;
                txt_OverTimeWorkingDays.Enabled = false;
                txt_FirstHalfStartTime.Enabled = false;
                rbFreeScan.Enabled = false;
                rbFunctionKey.Enabled = false;
                rbtnYes.Enabled = false;
                rbtnNo.Enabled = false;
            }
        }
    }
    #region BindingEmployeeCategory
    private void BindingEmployeeCategory()
    {
        #region Eastman
        if (Convert.ToString(Session["packageID"]) != "")
            if (Convert.ToString(Session["packageID"]) == "155")
            {
                // employee category binding
                DataSet dsCategory = new DataSet();
                dsCategory = objEmployee.SelectCategoryDetailsEmployee("");
                if (dsCategory != null)
                {
                    if (dsCategory.Tables[0].Rows.Count > 0)
                    {
                        ddlEmpCatagory.DataSource = dsCategory;
                        ddlEmpCatagory.DataTextField = "CategoryName";
                        ddlEmpCatagory.DataValueField = "CategoryId";
                        ddlEmpCatagory.DataBind();
                    }
                    dsCategory.Dispose();
                    foreach (ListItem item in ddlEmpCatagory.Items)
                    {
                        item.Attributes.Add("title", item.Text);
                    }
                }
            }
        #endregion
    }
    #endregion
    private void GetShiftDetails()
    {
        try
        {
            DataSet ds_Shift = obj_Shift.SelectShiftById(ShiftId);
            if (ds_Shift.Tables[0].Rows.Count > 0)
            {
                #region Eastman
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["empCategory"]) != null)
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["empCategory"]) != "")
                        ddlEmpCatagory.SelectedValue = Convert.ToString(ds_Shift.Tables[0].Rows[0]["empCategory"]);
                #endregion
                ddlCompany.SelectedValue = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Level_Id"]);
                txt_ShiftName.Text = Server.HtmlDecode(Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_Name"]));
                txtShiftShortName.Text = Server.HtmlDecode(Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_ShortName"]));
                txt_ShiftDescription.Text = Server.HtmlDecode(Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_Description"]));
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["DefaultShift"]) == "False")
                {
                    rbtnNo.Checked = true;
                }
                else
                {
                    rbtnYes.Checked = true;
                }
                DateTime time1 = new DateTime();
                DateTime time2 = new DateTime();
                DateTime time3 = new DateTime();
                DateTime time4 = new DateTime();
                DateTime time5 = new DateTime();
                DateTime time6 = new DateTime();
                DateTime time7 = new DateTime();
                DateTime time8 = new DateTime();
                DateTime time9 = new DateTime();
                DateTime time10 = new DateTime();
                DateTime time11 = new DateTime();
                DateTime time12 = new DateTime();
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_StartTime"]) != "")
                {
                    time1 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_StartTime"]);
                    txt_ShiftInTime.Text = time1.ToString(Convert.ToString(Session["MTimeFormat"]));
                }
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_EndTime"]) != "")
                {
                    time2 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_EndTime"]);
                    txt_ShiftOuttime.Text = time2.ToString(Convert.ToString(Session["MTimeFormat"]));
                }

                txt_GraceShiftIn.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_GraceInTime"]);
                txt_GraceShiftOut.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_GraceOutTime"]);

                if (ds_Shift.Tables[0].Rows[0]["isStraightShift"].ToString() == "True")
                {
                    ckbStaightShift.Checked = true;
                    txt_MinimumHrs.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["straightPresentTime"]);
                    txtboxBreak.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["BreakHours"]);
                    Alert_ShowMinimumWorked();
                }
                else
                {
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_StartTime"]) != "")
                    {
                        time9 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_StartTime"]);
                        txt_FirstHalfStartTime.Text = time9.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_EndTime"]) != "")
                    {
                        time10 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_EndTime"]);
                        txt_FirstHalfEndTime.Text = time10.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_StartTime"]) != "")
                    {
                        time11 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_StartTime"]);
                        txt_SecondHalfStartTime.Text = time11.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_EndTime"]) != "")
                    {
                        time12 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_EndTime"]);
                        txt_SecondHalfEndTime.Text = time12.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime1"]) != "")
                    {
                        time3 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime1"]);
                        txt_BreakStratTime1.Text = time3.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime1"]) != "")
                    {
                        time4 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime1"]);
                        txt_BreakEndTime1.Text = time4.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime2"]) != "")
                    {
                        time5 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime2"]);
                        txt_BreakStartTime2.Text = time5.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime2"]) != "")
                    {
                        time6 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime2"]);
                        txt_BreakEndTime2.Text = time6.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime3"]) != "")
                    {
                        time7 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime3"]);
                        txt_BreakStartTime3.Text = time7.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime3"]) != "")
                    {
                        time8 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime3"]);
                        txt_BreakEndTime3.Text = time8.ToString(Convert.ToString(Session["MTimeFormat"]));
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalfWorkingHours"]) != "")
                    {
                        txtFirstHalfWorkHrs.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalfWorkingHours"]);
                    }
                    if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalfWorkingHours"]) != "")
                    {
                        txtSecondHalfWorkHrs.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalfWorkingHours"]);
                    }
                    ckbStaightShift.Checked = false;
                    txt_MinimumHrs.Text = "";
                    txtboxBreak.Text = "";
                    Alert_ShowMinimumWorked();
                }
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["ShiftType"]) != null)
                {
                    if (Convert.ToBoolean(ds_Shift.Tables[0].Rows[0]["ShiftType"]) == true)
                    {
                        rbFreeScan.Checked = true;
                        rbFunctionKey.Checked = false;
                    }
                    else
                    {
                        rbFunctionKey.Checked = true;
                        rbFreeScan.Checked = false;
                    }
                }
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["24HrsShift"]) != null)
                {
                    if (Convert.ToBoolean(ds_Shift.Tables[0].Rows[0]["24HrsShift"]) == true)
                    {
                        rb24HrsShiftYes.Checked = true;
                        rb24HrsShiftNo.Checked = false;
                    }
                    else
                    {
                        rb24HrsShiftYes.Checked = false;
                        rb24HrsShiftNo.Checked = true;
                    }

                }
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MinTimeOT"]) != "" && Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MinTimeOT"]) != "00:00")
                    txt_MinOTtmie.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MinTimeOT"]);
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MaxTimeOT"]) != "" && Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MaxTimeOT"]) != "00:00")
                    txt_MaxOTtime.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MaxTimeOT"]);
                txt_OverTimeWorkingDays.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_WorkingDay_OverTime"]);
                txt_TotalWorkingHourrs.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_TotalWorkingHours"]);

                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start1"]) != "" && Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start1"]) != "00:00")
                    txtspecialOTstart1.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start1"]);
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start2"]) != "" && Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start2"]) != "00:00")
                    txtspecialOTstart2.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start2"]);

                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["MaxShiftWorkHours"]) != "")
                    if (txtMaxShiftWorkHours != null)
                    {
                        txtMaxShiftWorkHours.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["MaxShiftWorkHours"]);
                    }

            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }

    private void Alert_ShowMinimumWorked()
    {
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "ShowMinimumWorked();";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
    }

    private int FindTotalBreakTime()
    {
        try
        {
            //Checking BreakTimes against ShiftIn and ShiftOut (For Three BreakTime)
            if (txt_BreakStratTime1.Text != "" && txt_BreakEndTime1.Text != "" && txt_BreakStartTime2.Text != "" && txt_BreakEndTime2.Text != "" && txt_BreakStartTime3.Text != "" && txt_BreakEndTime3.Text != "")
            {
                if (txt_BreakStratTime1.Text == txt_BreakEndTime1.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime2.Text == txt_BreakEndTime2.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime3.Text == txt_BreakEndTime3.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime1.Text == txt_BreakStartTime2.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstBreakTimeNotEqualToSecondBreakTime", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime2.Text == txt_BreakStartTime3.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SecondBreakTimeNotEqualToThirdBreakTime", ci) + "');", true);
                    return 0;
                }
                ShiftIn = Convert.ToDateTime(txt_ShiftInTime.Text);
                ShiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text);
                dt_ShitBin1 = Convert.ToDateTime(txt_BreakStratTime1.Text);
                dt_ShiftBout1 = Convert.ToDateTime(txt_BreakEndTime1.Text);
                dt_ShiftBin2 = Convert.ToDateTime(txt_BreakStartTime2.Text);
                dt_ShiftBout2 = Convert.ToDateTime(txt_BreakEndTime2.Text);
                dt_ShiftBin3 = Convert.ToDateTime(txt_BreakStartTime3.Text);
                dt_ShiftBout3 = Convert.ToDateTime(txt_BreakEndTime3.Text);
                strshiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
                strShiftout = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
                strbrkIn1 = Convert.ToDateTime(txt_BreakStratTime1.Text).ToString("hh:mm tt");
                strbrkOut1 = Convert.ToDateTime(txt_BreakEndTime1.Text).ToString("hh:mm tt");
                strbrkIn2 = Convert.ToDateTime(txt_BreakStartTime2.Text).ToString("hh:mm tt");
                strbrkOut2 = Convert.ToDateTime(txt_BreakEndTime2.Text).ToString("hh:mm tt");
                strbrkIn3 = Convert.ToDateTime(txt_BreakStartTime3.Text).ToString("hh:mm tt");
                strbrkOut3 = Convert.ToDateTime(txt_BreakEndTime3.Text).ToString("hh:mm tt");
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                    //If shiftIn and Out time falls between PM and AM add one day in Shiftout time
                    ShiftOut = ShiftOut.AddDays(1);
                else
                {
                    //Check whether ShiftIn time is greater than shiftIn time 
                    //If its greater than then display error message
                    if (ShiftIn > ShiftOut)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci) + "');", true);
                        return 0;
                    }
                }
                //Checks Whether Break In and Ou time falls between Shift In and  Shift out time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    //Case1
                    if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(6) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShitBin1 = dt_ShitBin1.AddDays(1);
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    //Case2
                    if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "PM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "PM" && strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    //Case3
                    if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "PM" && strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "PM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "PM" && strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "PM" && strbrkIn3.Substring(6) == "PM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    ///Checking BreakIn time1 and Break outTime 1
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time2 and Break outTime 2
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time3 and Break outTime 3
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end1 time is greater than Break Start time1
                if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM")
                {
                    dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end time2 is greater than Break Start time2
                if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM")
                {
                    dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Breakend time3 is greater than Break Start time3
                if (strbrkIn3.Substring(6) == "PM" && strbrkOut3.Substring(6) == "AM")
                {
                    dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether BreakEnd time is greater than previous Break start Time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(7) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(7) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(7) == "PM" && strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(7) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "PM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin2 < dt_ShiftBout1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                        return 0;
                    }
                    else if (dt_ShiftBin3 < dt_ShiftBout2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                        return 0;
                    }
                }
            }
            //Checking BreakTimes against ShiftIn and ShiftOut (For First and Second BreakTime)
            else if (txt_BreakStratTime1.Text != "" && txt_BreakEndTime1.Text != "" && txt_BreakStartTime2.Text != "" && txt_BreakEndTime2.Text != "")
            {
                if (txt_BreakStratTime1.Text == txt_BreakEndTime1.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime2.Text == txt_BreakEndTime2.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime1.Text == txt_BreakStartTime2.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstBreakTimeNotEqualToSecondBreakTime", ci) + "');", true);
                    return 0;
                }
                ShiftIn = Convert.ToDateTime(txt_ShiftInTime.Text);
                ShiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text);
                dt_ShitBin1 = Convert.ToDateTime(txt_BreakStratTime1.Text);
                dt_ShiftBout1 = Convert.ToDateTime(txt_BreakEndTime1.Text);
                dt_ShiftBin2 = Convert.ToDateTime(txt_BreakStartTime2.Text);
                dt_ShiftBout2 = Convert.ToDateTime(txt_BreakEndTime2.Text);
                strshiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
                strShiftout = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
                strbrkIn1 = Convert.ToDateTime(txt_BreakStratTime1.Text).ToString("hh:mm tt");
                strbrkOut1 = Convert.ToDateTime(txt_BreakEndTime1.Text).ToString("hh:mm tt");
                strbrkIn2 = Convert.ToDateTime(txt_BreakStartTime2.Text).ToString("hh:mm tt");
                strbrkOut2 = Convert.ToDateTime(txt_BreakEndTime2.Text).ToString("hh:mm tt");
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                    //If shiftIn and Out time falls between PM and AM add one day in Shiftout time
                    ShiftOut = ShiftOut.AddDays(1);
                else
                {
                    //Check whether ShiftIn time is greater than shiftIn time 
                    //If its greater than then display error message
                    if (ShiftIn > ShiftOut)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end1 time is greater than Break Start time1
                if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM")
                {
                    dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end time2 is greater than Break Start time2
                if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM")
                {
                    dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                //Checks Whether Break In and Ou time falls between Shift In and  Shift out time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    //Case1
                    if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(6) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM")
                    {
                        dt_ShitBin1 = dt_ShitBin1.AddDays(1);
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM")
                    {
                        //Modified by Prbakaran.P
                        if (dt_ShiftBout1.Date == dt_ShitBin1.Date)
                        {
                            dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        }
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    //Case2
                    if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "PM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM")
                    {
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    ///Checking BreakIn time1 and Break outTime 1
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time2 and Break outTime 2
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether BreakEnd time is greater than previous Break start Time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(7) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM")
                    {
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(7) == "AM" && strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM")
                    {
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin2 < dt_ShiftBout1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                        return 0;
                    }
                }
            }
            //Checking BreakTimes against ShiftIn and ShiftOut (For First and Third BreakTime) Added by Prabakaran.P
            else if (txt_BreakStratTime1.Text != "" && txt_BreakEndTime1.Text != "" && txt_BreakStartTime3.Text != "" && txt_BreakEndTime3.Text != "")
            {
                if (txt_BreakStratTime1.Text == txt_BreakEndTime1.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime3.Text == txt_BreakEndTime3.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime1.Text == txt_BreakStartTime3.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstBreakTimeNotEqualToThirdBreakTime", ci) + "');", true);
                    return 0;
                }
                ShiftIn = Convert.ToDateTime(txt_ShiftInTime.Text);
                ShiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text);
                dt_ShitBin1 = Convert.ToDateTime(txt_BreakStratTime1.Text);
                dt_ShiftBout1 = Convert.ToDateTime(txt_BreakEndTime1.Text);
                dt_ShiftBin3 = Convert.ToDateTime(txt_BreakStartTime3.Text);
                dt_ShiftBout3 = Convert.ToDateTime(txt_BreakEndTime3.Text);
                strshiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
                strShiftout = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
                strbrkIn1 = Convert.ToDateTime(txt_BreakStratTime1.Text).ToString("hh:mm tt");
                strbrkOut1 = Convert.ToDateTime(txt_BreakEndTime1.Text).ToString("hh:mm tt");
                strbrkIn3 = Convert.ToDateTime(txt_BreakStartTime3.Text).ToString("hh:mm tt");
                strbrkOut3 = Convert.ToDateTime(txt_BreakEndTime3.Text).ToString("hh:mm tt");
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                    //If shiftIn and Out time falls between PM and AM add one day in Shiftout time
                    ShiftOut = ShiftOut.AddDays(1);
                else
                {
                    //Check whether ShiftIn time is greater than shiftIn time 
                    //If its greater than then display error message
                    if (ShiftIn > ShiftOut)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end1 time is greater than Break Start time1
                if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM")
                {
                    dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end time3 is greater than Break Start time3
                if (strbrkIn3.Substring(6) == "PM" && strbrkOut3.Substring(6) == "AM")
                {
                    dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                //Checks Whether Break In and Out time falls between Shift In and  Shift out time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    //Case1
                    if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShitBin1 = dt_ShitBin1.AddDays(1);
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        //Modified by Prbakaran.P
                        if (dt_ShiftBout1.Date == dt_ShitBin1.Date)
                        {
                            dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        }
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    //Case2
                    if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "PM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    ///Checking BreakIn time1 and Break outTime 1
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time2 and Break outTime 2
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether BreakEnd time is greater than previous Break start Time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(7) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        if (dt_ShiftBin3 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(7) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        if (dt_ShiftBin3 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (dt_ShiftBin3 < dt_ShiftBout1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin3 < dt_ShiftBout1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                        return 0;
                    }
                }
            }
            //Checking BreakTimes against ShiftIn and ShiftOut (For First and Third BreakTime) End Here
            //Checking BreakTimes against ShiftIn and ShiftOut (For Second and Third BreakTime) Added By Prabakaran.P
            else if (txt_BreakStartTime2.Text != "" && txt_BreakEndTime2.Text != "" && txt_BreakStartTime3.Text != "" && txt_BreakEndTime3.Text != "")
            {
                if (txt_BreakStartTime2.Text == txt_BreakEndTime2.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime3.Text == txt_BreakEndTime3.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime2.Text == txt_BreakStartTime3.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SecondBreakTimeNotEqualToThirdBreakTime", ci) + "');", true);
                    return 0;
                }
                ShiftIn = Convert.ToDateTime(txt_ShiftInTime.Text);
                ShiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text);
                dt_ShiftBin2 = Convert.ToDateTime(txt_BreakStartTime2.Text);
                dt_ShiftBout2 = Convert.ToDateTime(txt_BreakEndTime2.Text);
                dt_ShiftBin3 = Convert.ToDateTime(txt_BreakStartTime3.Text);
                dt_ShiftBout3 = Convert.ToDateTime(txt_BreakEndTime3.Text);
                strshiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
                strShiftout = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
                strbrkIn2 = Convert.ToDateTime(txt_BreakStartTime2.Text).ToString("hh:mm tt");
                strbrkOut2 = Convert.ToDateTime(txt_BreakEndTime2.Text).ToString("hh:mm tt");
                strbrkIn3 = Convert.ToDateTime(txt_BreakStartTime3.Text).ToString("hh:mm tt");
                strbrkOut3 = Convert.ToDateTime(txt_BreakEndTime3.Text).ToString("hh:mm tt");
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                    //If shiftIn and Out time falls between PM and AM add one day in Shiftout time
                    ShiftOut = ShiftOut.AddDays(1);
                else
                {
                    //Check whether ShiftIn time is greater than shiftIn time 
                    //If its greater than then display error message
                    if (ShiftIn > ShiftOut)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end2 time is greater than Break Start time2
                if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM")
                {
                    dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end time3 is greater than Break Start time3
                if (strbrkIn3.Substring(6) == "PM" && strbrkOut3.Substring(6) == "AM")
                {
                    dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                //Checks Whether Break In and Ou time falls between Shift In and  Shift out time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    //Case1
                    if (strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        //Modified by Prbakaran.P
                        if (dt_ShiftBout2.Date == dt_ShiftBin2.Date)
                        {
                            dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        }
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    //Case2
                    if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "PM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    ///Checking BreakIn time1 and Break outTime 1
                    if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time2 and Break outTime 2
                    if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut) && (dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether BreakEnd time is greater than previous Break start Time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    if (strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(7) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(7) == "AM" && strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin3 < dt_ShiftBout2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                        return 0;
                    }
                }
            }
            //Checking BreakTimes against ShiftIn and ShiftOut (For Second and Third BreakTime)End Here
            //Checking BreakTimes against ShiftIn and ShiftOut (For the First Break Time)
            else if (txt_BreakStratTime1.Text != "" && txt_BreakEndTime1.Text != "")
            {
                if (txt_BreakStratTime1.Text == txt_BreakEndTime1.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                ShiftIn = Convert.ToDateTime(txt_ShiftInTime.Text);
                ShiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text);
                dt_ShitBin1 = Convert.ToDateTime(txt_BreakStratTime1.Text);
                dt_ShiftBout1 = Convert.ToDateTime(txt_BreakEndTime1.Text);
                strshiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
                strShiftout = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
                strbrkIn1 = Convert.ToDateTime(txt_BreakStratTime1.Text).ToString("hh:mm tt");
                strbrkOut1 = Convert.ToDateTime(txt_BreakEndTime1.Text).ToString("hh:mm tt");
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                    //If shiftIn and Out time falls between PM and AM add one day in Shiftout time
                    ShiftOut = ShiftOut.AddDays(1);
                else
                {
                    //Check whether ShiftIn time is greater than shiftIn time 
                    //If its greater than then display error message
                    if (ShiftIn > ShiftOut)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci) + "');", true);
                        return 0;
                    }
                }
                //Checks Whether Break In and Out time falls between Shift In and  Shift out time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    //Case1
                    if (strbrkIn1.Substring(6) == "AM" && strbrkOut1.Substring(6) == "AM")
                    {
                        dt_ShitBin1 = dt_ShitBin1.AddDays(1);
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM")
                    {
                        dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    ///Checking BreakIn time1 and Break outTime 1
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time2 and Break outTime 2
                    if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut) && (dt_ShiftBout1 > ShiftIn) && (dt_ShiftBout1 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end1 time is greater than Break Start time1
                if (strbrkIn1.Substring(6) == "PM" && strbrkOut1.Substring(6) == "AM")
                {
                    dt_ShiftBout1 = dt_ShiftBout1.AddDays(1);
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
            }
            //add here
            //Checking BreakTimes against ShiftIn and ShiftOut (For Second Break Time)
            else if (txt_BreakStartTime2.Text != "" && txt_BreakStartTime2.Text != "")
            {
                if (txt_BreakStartTime2.Text == txt_BreakEndTime2.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                ShiftIn = Convert.ToDateTime(txt_ShiftInTime.Text);
                ShiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text);
                dt_ShiftBin2 = Convert.ToDateTime(txt_BreakStartTime2.Text);
                dt_ShiftBout2 = Convert.ToDateTime(txt_BreakEndTime2.Text);
                strshiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
                strShiftout = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
                strbrkIn2 = Convert.ToDateTime(txt_BreakStartTime2.Text).ToString("hh:mm tt");
                strbrkOut2 = Convert.ToDateTime(txt_BreakEndTime2.Text).ToString("hh:mm tt");
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                    //If shiftIn and Out time falls between PM and AM add one day in Shiftout time
                    ShiftOut = ShiftOut.AddDays(1);
                else
                {
                    //Check whether ShiftIn time is greater than shiftIn time 
                    //If its greater than then display error message
                    if (ShiftIn > ShiftOut)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci) + "');", true);
                        return 0;
                    }
                }
                //Checks Whether Break In and Out time falls between Shift In and  Shift out time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    //Case1
                    if (strbrkIn2.Substring(6) == "AM" && strbrkOut2.Substring(6) == "AM")
                    {
                        dt_ShiftBin2 = dt_ShiftBin2.AddDays(1);
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM")
                    {
                        dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    ///Checking BreakIn time1 and Break outTime 1
                    if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time2 and Break outTime 2
                    if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut) && (dt_ShiftBout2 > ShiftIn) && (dt_ShiftBout2 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end1 time is greater than Break Start time1
                if (strbrkIn2.Substring(6) == "PM" && strbrkOut2.Substring(6) == "AM")
                {
                    dt_ShiftBout2 = dt_ShiftBout2.AddDays(1);
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
            }
            //Checking BreakTimes against ShiftIn and ShiftOut (For Third Break Time)
            else if (txt_BreakStartTime3.Text != "" && txt_BreakStartTime3.Text != "")
            {
                if (txt_BreakStartTime3.Text == txt_BreakEndTime3.Text)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                ShiftIn = Convert.ToDateTime(txt_ShiftInTime.Text);
                ShiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text);
                dt_ShiftBin3 = Convert.ToDateTime(txt_BreakStartTime3.Text);
                dt_ShiftBout3 = Convert.ToDateTime(txt_BreakEndTime3.Text);
                strshiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
                strShiftout = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
                strbrkIn3 = Convert.ToDateTime(txt_BreakStartTime3.Text).ToString("hh:mm tt");
                strbrkOut3 = Convert.ToDateTime(txt_BreakEndTime3.Text).ToString("hh:mm tt");
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                    //If shiftIn and Out time falls between PM and AM add one day in Shiftout time
                    ShiftOut = ShiftOut.AddDays(1);
                else
                {
                    //Check whether ShiftIn time is greater than shiftIn time 
                    //If its greater than then display error message
                    if (ShiftIn > ShiftOut)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci) + "');", true);
                        return 0;
                    }
                }
                //Checks Whether Break In and Out time falls between Shift In and  Shift out time
                if (strshiftIn.Substring(6) == "PM" && strShiftout.Substring(6) == "AM")
                {
                    //Case1
                    if (strbrkIn3.Substring(6) == "AM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBin3 = dt_ShiftBin3.AddDays(1);
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else if (strbrkIn3.Substring(6) == "PM" && strbrkOut3.Substring(6) == "AM")
                    {
                        dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                        if (!((dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut)))
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    ///Checking BreakIn time1 and Break outTime 1
                    if (!((dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                    ///Checking BreakIn time2 and Break outTime 2
                    if (!((dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut) && (dt_ShiftBout3 > ShiftIn) && (dt_ShiftBout3 < ShiftOut)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                        return 0;
                    }
                }
                //Checking Whether Break end1 time is greater than Break Start time1
                if (strbrkIn3.Substring(6) == "PM" && strbrkOut3.Substring(6) == "AM")
                {
                    dt_ShiftBout3 = dt_ShiftBout3.AddDays(1);
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
            }
        }
        catch
        {
            //
        }
        return 1;
    }
    private int ValidateShiftHalfTimes()
    {
        //Checking shift half times against ShiftIn and ShiftOut
        string shiftIn = Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt");
        string shiftOut = Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt");
        string strFirstHalfStartTime = Convert.ToDateTime(txt_FirstHalfStartTime.Text).ToString("hh:mm tt");
        string strFirstHalfEndTime = Convert.ToDateTime(txt_FirstHalfEndTime.Text).ToString("hh:mm tt");
        string strSecondHalfStartTime = Convert.ToDateTime(txt_SecondHalfStartTime.Text).ToString("hh:mm tt");
        string strSecondHalfEndTime = Convert.ToDateTime(txt_SecondHalfEndTime.Text).ToString("hh:mm tt");
        DateTime dtFHEndTime = DateTime.Parse(Convert.ToDateTime(txt_FirstHalfEndTime.Text).ToString("hh:mm tt"));
        DateTime dtSHStartTime = DateTime.Parse(Convert.ToDateTime(txt_SecondHalfStartTime.Text).ToString("hh:mm tt"));
        bool flag = false;
        if (strFirstHalfStartTime == strFirstHalfEndTime)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstHalfEndTimeandShiftInTimeshouldnotbeequal", ci) + "');", true);
            return 0;
        }
        if (strSecondHalfStartTime == strSecondHalfEndTime)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SecondHalfStartTimeandShiftOutTimeshouldnotbeequal", ci) + "');", true);
            return 0;
        }
        DateTime dtFirstHalfShiftIn = new DateTime();
        DateTime dtFirstHalfShiftOut = new DateTime();
        DateTime dtSecondHalfShiftIn = new DateTime();
        DateTime dtSecondHalfShiftOut = new DateTime();
        if (shiftIn.Substring(6) == "PM" && shiftOut.Substring(6) == "AM")
        {
            if (strFirstHalfStartTime.Substring(6) == "PM")
            {
                dtFirstHalfShiftIn = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + txt_FirstHalfStartTime.Text);
            }
            if (strFirstHalfEndTime.Substring(6) == "PM")
            {
                dtFirstHalfShiftOut = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + txt_FirstHalfEndTime.Text);
            }
            else
            {
                dtFirstHalfShiftOut = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " " + txt_FirstHalfEndTime.Text);
            }
            if (strSecondHalfStartTime.Substring(6) == "PM")
            {
                dtSecondHalfShiftIn = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + txt_SecondHalfStartTime.Text);
            }
            else
            {
                dtSecondHalfShiftIn = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " " + txt_SecondHalfStartTime.Text);
            }
            if (strSecondHalfEndTime.Substring(6) == "AM")
            {
                dtSecondHalfShiftOut = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " " + txt_SecondHalfEndTime.Text);
            }
        }
        else
        {
            dtFirstHalfShiftIn = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + txt_FirstHalfStartTime.Text);
            dtFirstHalfShiftOut = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + txt_FirstHalfEndTime.Text);
            dtSecondHalfShiftIn = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + txt_SecondHalfStartTime.Text);
            dtSecondHalfShiftOut = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + txt_SecondHalfEndTime.Text);
        }
        if (shiftIn == strFirstHalfStartTime && shiftOut == strSecondHalfEndTime)
        {
            if (dtFirstHalfShiftIn > dtFirstHalfShiftOut)
            {
                if (rb24HrsShiftYes.Checked == false)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstHalfStartTimeShouldbelessthanFirstHalfEndTime", ci) + "');", true);
                    return 0;
                }
            }
            if (dtSecondHalfShiftIn < dtFirstHalfShiftOut)
            {
                if (rb24HrsShiftYes.Checked == false)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SecondHalfStartTimeGreaterthanOrEqualToFirstHalfEndTime", ci) + "');", true);
                    return 0;
                }
            }
            if (dtSecondHalfShiftIn > dtSecondHalfShiftOut)
            {
                if (rb24HrsShiftYes.Checked == false)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SecondHalfStartTimeShouldbelessthanSecondHalfEndTime", ci) + "');", true);
                    return 0;
                }
            }
            if (dtFHEndTime == dtSHStartTime)
            {
                // contunue   
                flag = true;
            }
            else
            {
                if (txt_BreakStratTime1.Text != "" && txt_BreakEndTime1.Text != "")
                {
                    DateTime dtBrkIn1 = DateTime.Parse(Convert.ToDateTime(txt_BreakStratTime1.Text).ToString("hh:mm tt"));
                    DateTime dtBrkOut1 = DateTime.Parse(Convert.ToDateTime(txt_BreakEndTime1.Text).ToString("hh:mm tt"));
                    if (dtFHEndTime == dtBrkIn1 && dtSHStartTime == dtBrkOut1)
                    {
                        flag = true;
                    }
                }
                if (txt_BreakStartTime2.Text != "" && txt_BreakEndTime2.Text != "")
                {
                    DateTime dtBrkIn2 = DateTime.Parse(Convert.ToDateTime(txt_BreakStartTime2.Text).ToString("hh:mm tt"));
                    DateTime dtBrkOut2 = DateTime.Parse(Convert.ToDateTime(txt_BreakEndTime2.Text).ToString("hh:mm tt"));
                    if (dtFHEndTime == dtBrkIn2 && dtSHStartTime == dtBrkOut2)
                    {
                        flag = true;
                    }
                }
                if (txt_BreakStartTime3.Text != "" && txt_BreakEndTime3.Text != "")
                {
                    DateTime dtBrkIn3 = DateTime.Parse(Convert.ToDateTime(txt_BreakStartTime3.Text).ToString("hh:mm tt"));
                    DateTime dtBrkOut3 = DateTime.Parse(Convert.ToDateTime(txt_BreakEndTime3.Text).ToString("hh:mm tt"));
                    if (dtFHEndTime == dtBrkIn3 && dtSHStartTime == dtBrkOut3)
                    {
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_GiveABreakTime", ci) + "');", true);
                return 0;
            }
            if (txt_BreakStratTime1.Text != "")
            {
                strbrkIn1 = Convert.ToDateTime(txt_BreakStratTime1.Text).ToString("hh:mm tt");
                if (strFirstHalfStartTime == strbrkIn1)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime1shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfStartTime == strbrkIn1)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime1shouldnotbeequaltoSecondHalfStartTime", ci) + "');", true);
                    return 0;
                }
            }
            if (txt_BreakEndTime1.Text != "")
            {
                strbrkOut1 = Convert.ToDateTime(txt_BreakEndTime1.Text).ToString("hh:mm tt");
                if (strFirstHalfEndTime == strbrkOut1)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime1shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfEndTime == strbrkOut1)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime1shouldnotbeequaltoSecondHalfStartTime", ci) + "');", true);
                    return 0;
                }
            }
            if (txt_BreakStartTime2.Text != "")
            {
                strbrkIn2 = Convert.ToDateTime(txt_BreakStartTime2.Text).ToString("hh:mm tt");
                if (strFirstHalfStartTime == strbrkIn2)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfStartTime == strbrkIn2)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldnotbeequaltoSecondHalfStartTime", ci) + "');", true);
                    return 0;
                }
            }
            if (txt_BreakEndTime2.Text != "")
            {
                strbrkOut2 = Convert.ToDateTime(txt_BreakEndTime2.Text).ToString("hh:mm tt");
                if (strFirstHalfEndTime == strbrkOut2)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime2shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfEndTime == strbrkOut2)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime2shouldnotbeequaltoSecondHalfStartTime", ci) + "');", true);
                    return 0;
                }
            }
            if (txt_BreakStartTime3.Text != "")
            {
                strbrkIn3 = Convert.ToDateTime(txt_BreakStartTime3.Text).ToString("hh:mm tt");
                if (strFirstHalfStartTime == strbrkIn3)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfStartTime == strbrkIn3)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldnotbeequaltoSecondHalfStartTime", ci) + "');", true);
                    return 0;
                }
            }
            if (txt_BreakEndTime3.Text != "")
            {
                strbrkOut3 = Convert.ToDateTime(txt_BreakEndTime3.Text).ToString("hh:mm tt");
                if (strFirstHalfEndTime == strbrkOut3)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime3shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfEndTime == strbrkOut3)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime3shouldnotbeequaltoSecondHalfStartTime", ci) + "');", true);
                    return 0;
                }
            }
            // overlap checking
            return 1;
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidShiftandShiftHalfTimes", ci) + "');", true);
            return 0;
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_BreakTimings.Text = rm.GetString("ShiftTiming_BreakTimings", ci);
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        lbl_EndTime1.Text = rm.GetString("OnDuty_OutTime", ci);
        lbl_EndTime2.Text = rm.GetString("OnDuty_OutTime", ci);
        lbl_EndTime3.Text = rm.GetString("OnDuty_OutTime", ci);
        lbl_GraceShiftIn.Text = rm.GetString("ShiftTiming_GraceShiftIn", ci);
        lbl_GraceShiftOut.Text = rm.GetString("ShiftTiming_GraceShiftOut", ci);
        lbl_MaximumExtraTimeforOT.Text = rm.GetString("ShiftTiming_MaximumExtraTimeForOT", ci);
        lbl_MinimumExtraTimeforOT.Text = rm.GetString("ShiftTiming_MinimumExtraTimeForOT", ci);
        lbl_OvertimeOnWorkingDays.Text = rm.GetString("ShiftTiming_OverTimeOnWorkingDays", ci);
        lbl_ShiftDescription.Text = rm.GetString("ShiftTiming_ShiftDescription", ci);
        lbl_ShiftIn.Text = rm.GetString("ShiftTiming_ShiftIn", ci);
        lbl_ShiftName.Text = rm.GetString("ShiftTiming_ShiftName", ci);
        lbl_ShiftOut.Text = rm.GetString("ShiftTiming_ShiftOut", ci);
        lbl_ShiftShortName.Text = rm.GetString("ShiftTiming_ShiftShortName", ci);
        lbl_FirstHalfStartTime.Text = rm.GetString("ShiftTiming_FirstHalfStartTime", ci);
        lbl_FirstHalfEndTime.Text = rm.GetString("ShiftTiming_FirstHalfEndTime", ci);
        lbl_SecondHalfStartTime.Text = rm.GetString("ShiftTiming_SecondHalfStartTime", ci);
        lbl_SecondHalfEndTime.Text = rm.GetString("ShiftTiming_SecondHalfEndTime", ci);
        lbl_StartTime1.Text = rm.GetString("OnDuty_InTime", ci);
        lbl_StartTime2.Text = rm.GetString("Lunch_StartTime", ci);
        lbl_StartTime3.Text = rm.GetString("OnDuty_InTime", ci);
        lbl_TotalWorkingHours.Text = rm.GetString("ShiftTiming_TotalWorkingHours", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_ShiftTiming.Text = rm.GetString("Masters_Shift_ShiftTiming", ci);
        lblDefaultShift.Text = rm.GetString("Masters_Shift_DefaultShift", ci);
        rbtnYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnNo.Text = rm.GetString("ShiftSetting_No", ci);
        lblService.Text = rm.GetString("ShiftType", ci);
        rbFreeScan.Text = rm.GetString("FreeScan", ci);
        rbFunctionKey.Text = rm.GetString("FunctionKey", ci);
        Label1.Text = rm.GetString("ShiftHrs", ci);
        Label2.Text = rm.GetString("ShiftHrs", ci);
        lblFirstHalfWorkHrs.Text = rm.GetString("Masters_Shift_FirstHalfWorkHours", ci);
        lblSecondHalfWorkHrs.Text = rm.GetString("Masters_Shift_SecondHalfWorkHours", ci);
        lbl_hrs3.Text = rm.GetString("ShiftHrs", ci);
        btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btnCalculateHrs.Text = "&nbsp;&nbsp;" + rm.GetString("Calculate_Hours", ci);
        //btnCalculateHrs.Text = "";
        ddlCompany.Items[0].Text = rm.GetString("Select", ci);
        lblBreakHours.Text = rm.GetString("Field_BreakHours", ci);
        lblStraightShift.Text = rm.GetString("Field_StraightShift", ci);
        ckbStaightShift.Text = rm.GetString("ShiftSetting_Yes", ci);
        lbl_AttendancePresentMinHrs.Text = rm.GetString("Field_MinimumHrs", ci);
        lbl_General.Text = rm.GetString("Shift_General", ci);
        lbl24HrsShift.Text = rm.GetString("Shift_24Hrs", ci);
        lbl_ShiftTimings.Text = rm.GetString("ShiftTiming_ShiftTimings", ci);
        lbl_OverTime.Text = rm.GetString("Menu_Reports_OverTime", ci);
        rb24HrsShiftYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rb24HrsShiftNo.Text = rm.GetString("ShiftSetting_No", ci);
        #region Eastman
        lblEmpCategory.Text = rm.GetString("lblEmpCategory", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        #endregion
        #region Vaighai
        lbl_MaxShiftWorkHours.Text = rm.GetString("ShiftAdd_MaxShiftWorkHours", ci);
        #endregion
        lblImportNote.Text = rm.GetString("Field_ImportantNote", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(19, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
            Response.Redirect("MasterLandingPage.aspx");
    }
    #endregion
    #region ButtonEvents
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        string[] TotalWorkHours = txt_TotalWorkingHourrs.Text.Split(':');
        if (TotalWorkHours.Length < 2)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_ClickCalculateHours", ci) + "');ShowMinimumWorked();", true);
            return;
        }
        int TotalHours = Convert.ToInt32(TotalWorkHours[0]);
        int TotalMinutes = Convert.ToInt32(TotalWorkHours[1]);
        int intCompanyId = 0;
        if (ddlCompany.SelectedValue != "0")
        {
            intCompanyId = Convert.ToInt32(ddlCompany.SelectedValue);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Select_Company", ci) + "');ShowMinimumWorked();", true);
            return;
        }
        if (TotalHours < 0 || TotalMinutes < 0)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Totalhoursshouldnotbeinnegative", ci) + "');ShowMinimumWorked();", true);
            return;
        }
        if (TotalHours >= 24)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Totalworkhoursshouldlessthan23Hrs", ci) + "');ShowMinimumWorked();", true);
            return;
        }
        int valid = 0;
        switch (rb24HrsShiftYes.Checked)
        {
            case true:
                valid = 1;
                break;
            case false:
                if (ckbStaightShift.Checked == false)
                    valid = ValidateShiftHalfTimes();
                else
                    valid = 1;
                break;
        }
        if (valid == 1)
        {
            #region Eastman
            int intempCategory = 0;
            if (ddlEmpCatagory.SelectedValue != "0")
                intempCategory = Convert.ToInt32(ddlEmpCatagory.SelectedValue);
            #endregion

            #region Vaighai
            string MaxShiftWorkHours = "00:00";
            if (txtMaxShiftWorkHours.Text != "")
            {
                MaxShiftWorkHours = Convert.ToString(txtMaxShiftWorkHours.Text);
            }
            #endregion

            switch (rb24HrsShiftYes.Checked)
            {
                case true:
                    CheckBrk = 1;
                    break;
                case false:
                    CheckBrk = FindTotalBreakTime();
                    break;
            }
            if (CheckBrk == 1)
            {
                count = objShift.CheckShiftNameUpdate(intCompanyId, ShiftId, txt_ShiftName.Text.Trim().Replace("'", "''"));
                string OverTimeWorkingDays = "";
                if (count == 0)
                {
                    count = objShift.CheckShiftShortNameUpdate(intCompanyId, ShiftId, txtShiftShortName.Text.Trim().Replace("'", "''"));
                    if (count == 0)
                    {
                        maxot = (txt_MaxOTtime.Text == "") ? "00:00" : txt_MaxOTtime.Text;
                        minot = (txt_MinOTtmie.Text == "") ? "00:00" : txt_MinOTtmie.Text;
                        OverTimeWorkingDays = (txt_OverTimeWorkingDays.Text == "") ? "0" : txt_OverTimeWorkingDays.Text.Trim();
                        strbrkIn1 = (txt_BreakStratTime1.Text != "") ? Convert.ToDateTime(txt_BreakStratTime1.Text).ToString("hh:mm tt") : "";
                        strbrkIn2 = (txt_BreakStartTime2.Text != "") ? Convert.ToDateTime(txt_BreakStartTime2.Text).ToString("hh:mm tt") : "";
                        strbrkIn3 = (txt_BreakStartTime3.Text != "") ? Convert.ToDateTime(txt_BreakStartTime3.Text).ToString("hh:mm tt") : "";
                        strbrkOut1 = (txt_BreakEndTime1.Text != "") ? Convert.ToDateTime(txt_BreakEndTime1.Text).ToString("hh:mm tt") : "";
                        strbrkOut2 = (txt_BreakEndTime2.Text != "") ? Convert.ToDateTime(txt_BreakEndTime2.Text).ToString("hh:mm tt") : "";
                        strbrkOut3 = (txt_BreakEndTime3.Text != "") ? Convert.ToDateTime(txt_BreakEndTime3.Text).ToString("hh:mm tt") : "";
                        int intDefaultShift = 0;
                        switch (rbtnYes.Checked)
                        {
                            case true:
                                intDefaultShift = 1;
                                int dsShiftCount = 0;
                                dsShiftCount = objShift.SelectDefaultShiftcountForUpdate(intCompanyId, ShiftId);
                                if (dsShiftCount > 0)
                                {
                                    if (DefaultShiftCount.Value == string.Empty)
                                    {
                                        UpdateDefaultShift();
                                        return;
                                    }
                                }
                                if (DefaultShiftCount.Value == "cancel")
                                {
                                    intDefaultShift = 0;
                                }
                                break;
                            case false:
                                intDefaultShift = 0;
                                break;
                        }
                        if (ckbStaightShift.Checked == true)
                        {
                            objShift.InsertShift(intCompanyId, ShiftId, txt_ShiftName.Text.Trim().Replace("'", "''"), txtShiftShortName.Text.Trim().ToString().Replace("'", "''"), txt_ShiftDescription.Text.Replace("'", "''"), Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt"),
                                                Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt"), txt_GraceShiftIn.Text,
                                                 txt_GraceShiftOut.Text, strbrkIn1, strbrkOut1, strbrkIn2, strbrkOut2,
                                                 strbrkIn3, strbrkOut3, minot, maxot, Convert.ToSingle(OverTimeWorkingDays),
                                                 txt_TotalWorkingHourrs.Text, txtFirstHalfWorkHrs.Text, txtSecondHalfWorkHrs.Text, Emp_ID.ToString(), intDefaultShift, (rbFreeScan.Checked == true) ? 1 : 0, (rb24HrsShiftYes.Checked == true) ? 1 : 0, (ckbStaightShift.Checked == true) ? 1 : 0, Convert.ToString(txt_MinimumHrs.Text), Convert.ToString(txtboxBreak.Text), intempCategory, Convert.ToString(txtspecialOTstart1.Text), Convert.ToString(txtspecialOTstart2.Text), MaxShiftWorkHours);
                        }
                        else
                        {
                            objShift.InsertShift(intCompanyId, ShiftId, txt_ShiftName.Text.Trim().Replace("'", "''"), txtShiftShortName.Text.Trim().ToString().Replace("'", "''"), 
                                txt_ShiftDescription.Text.Replace("'", "''"), Convert.ToDateTime(txt_ShiftInTime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_ShiftOuttime.Text).ToString("hh:mm tt"),
                                                Convert.ToDateTime(txt_FirstHalfStartTime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_FirstHalfEndTime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_SecondHalfStartTime.Text).ToString("hh:mm tt"), Convert.ToDateTime(txt_SecondHalfEndTime.Text).ToString("hh:mm tt"), txt_GraceShiftIn.Text,
                                                 txt_GraceShiftOut.Text, strbrkIn1, strbrkOut1, strbrkIn2, strbrkOut2,
                                                 strbrkIn3, strbrkOut3, minot, maxot, Convert.ToSingle(OverTimeWorkingDays),
                                                 txt_TotalWorkingHourrs.Text, txtFirstHalfWorkHrs.Text, txtSecondHalfWorkHrs.Text, Emp_ID.ToString(), intDefaultShift, (rbFreeScan.Checked == true) ? 1 : 0, (rb24HrsShiftYes.Checked == true) ? 1 : 0, (ckbStaightShift.Checked == true) ? 1 : 0, Convert.ToString(txt_MinimumHrs.Text), Convert.ToString(txtboxBreak.Text), intempCategory, Convert.ToString(txtspecialOTstart1.Text), Convert.ToString(txtspecialOTstart2.Text), MaxShiftWorkHours);
                        }
                        string str = "alert('" + rm.GetString("Alert_Shiftsavedsuccessfully", ci) + "');location.replace('TA_UI_Master_ShiftDetails.aspx');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", str, true);
                    }
                    else
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Shiftshortnamealreadyexists", ci) + "');ShowMinimumWorked();", true);
                }
                else
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Shiftnamealreadyexists", ci) + "');ShowMinimumWorked();", true);
            }
        }
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_ShiftDetails.aspx");
    }
    private void UpdateDefaultShift()
    {
        string script = @"<script language='javascript' type='text/javascript'>
        window.onload=function()
        {
            objHiddenField = document.getElementById('" + DefaultShiftCount.ClientID + @"');
            objSubmit = document.getElementById('" + btn_Save.ClientID + @"');            
            if(confirm('Default Shift Already Defined For This Company,Do You want to replace?') == true)            
            {
                objHiddenField.value = 'true';
                objSubmit.click();                
            }
            else
            {                
                objHiddenField.value = 'cancel';
                objSubmit.click();                
            }
        }
        </script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "Confirm", script);
    }
    #endregion
}
