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_ShiftAdd : Base.BasePage
{
    #region Eastman
    EmployeeEventData objEmployee = new EmployeeEventData();
    #endregion
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objCommon = new cls_Common();
    DataSet ds_Checkuser = new DataSet();
    ShiftEvenData objShift = new ShiftEvenData();
    int count, Emp_ID;
    float WorkindayOver;
    DateTime dt_ShitBin1, dt_ShiftBout1, dt_ShiftBin2, dt_ShiftBout2, dt_ShiftBin3, dt_ShiftBout3, ShiftIn, ShiftOut;
    int CheckBrk;
    string strshiftIn, strShiftout, strbrkIn1, strbrkOut1, strbrkIn2, strbrkOut2, strbrkIn3, strbrkOut3, maxot, minot;
    string gstrUserGroupName = string.Empty;
    int payrollConfig = 0;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking159

        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();
        if (!Page.IsPostBack)
        {
            Hidden1.Value = Convert.ToString(Session["ITimeFormat"]);
            ddlCompany.Focus();
            CompanyBinding();
            objCommon.menu("ShiftMaster", "19");
            BindingEmployeeCategory();
        }
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "chkPermission('" + rm.GetString("Alert_Enterinhhmmformat", ci) + "');";
        strSetAlert = strSetAlert + "InvalidFun('" + rm.GetString("Alert_InvalidBreaTime", ci) + "');";
        strSetAlert = strSetAlert + "ChMaxLengthh('" + rm.GetString("Alert_Maximumlengthis250", 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_Invalidtimeformat1", ci) + "','" + 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") + "','" + rm.GetString("Alert_MinimumHrstomarkPresentforStraightShift") + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        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
    }

    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 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)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime2.Text == txt_BreakEndTime2.Text)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime3.Text == txt_BreakEndTime3.Text)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime1.Text == txt_BreakStartTime2.Text)
                {
                    //lbl_Error.Text = "First Break End Time and Second Break Start Time should not be equal";
                    //base.Message(rm.GetString("Alert_FirstBreakTimeNotEqualToSecondBreakTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstBreakTimeNotEqualToSecondBreakTime", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime2.Text == txt_BreakStartTime3.Text)
                {
                    //lbl_Error.Text = "Second Break End Time and Third Break Start Time should not be equal";
                    //base.Message(rm.GetString("Alert_SecondBreakTimeNotEqualToThirdBreakTime", ci));
                    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)
                    {
                        //lbl_Error.Text = "ShiftIn Time Should be less than Shift Out Time";
                        //base.Message(rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci));
                        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" && 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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        // base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time2 should be less than Breakend Time2";
                        //base.Message(rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        //lbl_Error.Text = "Breakstart Time2 should be less than Breakend Time2";
                        //base.Message(rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        //base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        // base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        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)
                        {
                            //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                            //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                            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)
                        {
                            //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                            //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                            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)
                        {
                            //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                            //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                            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)
                        {
                            //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                        else if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                            //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin2 < dt_ShiftBout1)
                    {
                        //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                        // base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                        return 0;
                    }
                    else if (dt_ShiftBin3 < dt_ShiftBout2)
                    {
                        //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                        //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                        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)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime2.Text == txt_BreakEndTime2.Text)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime1.Text == txt_BreakStartTime2.Text)
                {
                    //lbl_Error.Text = "First Break End Time and Second Break Start Time should not be equal";
                    //base.Message(rm.GetString("Alert_FirstBreakTimeNotEqualToSecondBreakTime", ci));
                    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)
                    {
                        //lbl_Error.Text = "ShiftIn Time Should be less than Shift Out Time";
                        //base.Message(rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time2 should be less than Breakend Time2";
                        //base.Message(rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        // lbl_Error.Text = "Breakstart Time2 should be less than Breakend Time2";
                        //base.Message(rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci));
                        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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)
                        {
                            //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                            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)
                        {
                            //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (dt_ShiftBin2 < dt_ShiftBout1)
                        {
                            //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin2 < dt_ShiftBout1)
                    {
                        //lbl_Error.Text = "BreakStart Time2 should be greater than BreakEnd Time1";
                        //base.Message(rm.GetString("Alert_BreakStartTime2shouldbegreaterthanBreakEndTime1", ci));
                        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)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime3.Text == txt_BreakEndTime3.Text)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime1.Text == txt_BreakStartTime3.Text)
                {
                    //lbl_Error.Text = "First Break End Time and Third Break Start Time should not be equal";
                    //base.Message(rm.GetString("Alert_FirstBreakTimeNotEqualToThirdBreakTime", ci));
                    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)
                    {
                        //lbl_Error.Text = "ShiftIn Time Should be less than Shift Out Time";
                        //base.Message(rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        // base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        //base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        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 (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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", 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)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (dt_ShiftBin3 < dt_ShiftBout1)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time1";
                            //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin3 < dt_ShiftBout1)
                    {
                        //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time1";
                        //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime1", ci));
                        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)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakStartTime3.Text == txt_BreakEndTime3.Text)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    // base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci) + "');", true);
                    return 0;
                }
                if (txt_BreakEndTime2.Text == txt_BreakStartTime3.Text)
                {
                    //lbl_Error.Text = "Second Break End Time and Third Break Start Time should not be equal";
                    //base.Message(rm.GetString("Alert_SecondBreakTimeNotEqualToThirdBreakTime", ci));
                    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)
                    {
                        //lbl_Error.Text = "ShiftIn Time Should be less than Shift Out Time";
                        // base.Message(rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time2 should be less than Breakend Time2";
                        //base.Message(rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        //lbl_Error.Text = "Breakstart Time2 should be less than Breakend Time2";
                        //base.Message(rm.GetString("Alert_BreakstartTime2shouldbelessthanBreakendTime2", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        // base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        // base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                            // base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                            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)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                            // base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (dt_ShiftBin3 < dt_ShiftBout2)
                        {
                            //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                            //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci) + "');", true);
                            return 0;
                        }
                    }
                }
                else
                {
                    if (dt_ShiftBin3 < dt_ShiftBout2)
                    {
                        //lbl_Error.Text = "BreakStart Time3 should be greater than BreakEnd Time2";
                        //base.Message(rm.GetString("Alert_BreakStartTime3shouldbegreaterthanBreakEndTime2", ci));
                        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)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    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)
                    {
                        //lbl_Error.Text = "ShiftIn Time Should be less than Shift Out Time";
                        //base.Message(rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci));
                        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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShitBin1 > ShiftIn) && (dt_ShitBin1 < ShiftOut)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout1 < dt_ShitBin1)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        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)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    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)
                    {
                        //lbl_Error.Text = "ShiftIn Time Should be less than Shift Out Time";
                        // base.Message(rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci));
                        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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShiftBin2 > ShiftIn) && (dt_ShiftBin2 < ShiftOut)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout2 < dt_ShiftBin2)
                    {
                        //lbl_Error.Text = "Breakstart Time1 should be less than Breakend Time1";
                        //base.Message(rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime1shouldbelessthanBreakendTime1", 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)
                {
                    //lbl_Error.Text = "Break Start and End Time should not be equal";
                    //base.Message(rm.GetString("Alert_BreakStartandEndTimeshouldnotbeequal", ci));
                    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)
                    {
                        //lbl_Error.Text = "ShiftIn Time Should be less than Shift Out Time";
                        // base.Message(rm.GetString("Alert_ShiftInTimeShouldbelessthanShiftOutTime", ci));
                        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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidBreakTimings", ci) + "');", true);
                            return 0;
                        }
                    }
                    else
                    {
                        if (!((dt_ShiftBin3 > ShiftIn) && (dt_ShiftBin3 < ShiftOut)))
                        {
                            //lbl_Error.Text = "Invalid Break Timings";
                            // base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                            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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)))
                    {
                        //lbl_Error.Text = "Invalid Break Timings";
                        //base.Message(rm.GetString("Alert_InvalidBreakTimings", ci));
                        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)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        //base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
                else
                {
                    if (dt_ShiftBout3 < dt_ShiftBin3)
                    {
                        //lbl_Error.Text = "Breakstart Time3 should be less than Breakend Time3";
                        // base.Message(rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakstartTime3shouldbelessthanBreakendTime3", ci) + "');", true);
                        return 0;
                    }
                }
            }
        }
        catch
        {
            //
        }
        return 1;
    }
    //Insert Shift Details
    protected void btn_Add_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;
        }
        try
        {
            #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
            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)
            {
                switch (rb24HrsShiftYes.Checked)
                {
                    case true:
                        CheckBrk = 1;
                        break;
                    case false:
                        CheckBrk = FindTotalBreakTime();
                        break;
                }
                if (CheckBrk == 1)
                {
                    count = objShift.CheckShiftName(intCompanyId, txt_ShiftName.Text.Trim().Replace("'", "''"));
                    if (count == 0)
                    {
                        //Shift Short Name exists checking
                        count = objShift.CheckShiftShortName(intCompanyId, 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;
                            WorkindayOver = (txt_OverTimeWorkingDays.Text == "") ? 0 : Convert.ToSingle(txt_OverTimeWorkingDays.Text);
                            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.SelectDefaultShiftcount(intCompanyId);
                                    if (dsShiftCount > 0)
                                        if (DefaultShiftCount.Value == string.Empty)
                                        {
                                            UpdateDefaultShift();
                                            return;
                                        }
                                    if (DefaultShiftCount.Value == "cancel")
                                        intDefaultShift = 0;
                                    break;
                                case false:
                                    intDefaultShift = 0;
                                    break;
                            }
                           
                            switch (ckbStaightShift.Checked)
                            {
                                case true:
                                    objShift.InsertShift(intCompanyId, 0, 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, WorkindayOver,
                                                 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);
                                    break;
                                case false:
                                    objShift.InsertShift(intCompanyId, 0, 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, WorkindayOver,
                                                 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);
                                    break;
                            }
                            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);
                }
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    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)
        {
            //lbl_Error.Text = "First Half End Time and Shift In Time should not be equal";
            // base.Message(rm.GetString("Alert_FirstHalfEndTimeandShiftInTimeshouldnotbeequal", ci));
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstHalfEndTimeandShiftInTimeshouldnotbeequal", ci) + "');", true);
            return 0;
        }
        if (strSecondHalfStartTime == strSecondHalfEndTime)
        {
            //lbl_Error.Text = "Second Half Start Time and Shift Out Time should not be equal";
            // base.Message(rm.GetString("Alert_SecondHalfStartTimeandShiftOutTimeshouldnotbeequal", ci));
            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)
                {
                    //lbl_Error.Text = "First Half Start Time Should be less than First Half End Time";
                    // base.Message(rm.GetString("Alert_FirstHalfStartTimeShouldbelessthanFirstHalfEndTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_FirstHalfStartTimeShouldbelessthanFirstHalfEndTime", ci) + "');", true);
                    return 0;
                }
            }
            if (dtSecondHalfShiftIn < dtFirstHalfShiftOut)
            {
                if (rb24HrsShiftYes.Checked == false)
                {
                    //lbl_Error.Text = "Second Half Start Time Should be greater than or equal to First Half End Time";
                    //base.Message(rm.GetString("Alert_SecondHalfStartTimeGreaterthanOrEqualToFirstHalfEndTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SecondHalfStartTimeGreaterthanOrEqualToFirstHalfEndTime", ci) + "');", true);
                    return 0;
                }
            }
            if (dtSecondHalfShiftIn > dtSecondHalfShiftOut)
            {
                if (rb24HrsShiftYes.Checked == false)
                {
                    //lbl_Error.Text = "Second Half Start Time Should be less than Second Half End Time";
                    //base.Message(rm.GetString("Alert_SecondHalfStartTimeShouldbelessthanSecondHalfEndTime", ci));
                    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)
            {
                //lbl_Error.Text = "Give a break time as like first half end time and second half start time";
                //base.Message(rm.GetString("Alert_GiveABreakTime", ci));
                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)
                {
                    //lbl_Error.Text = "Break Start Time1 should not be equal to First Half Start Time";
                    //base.Message(rm.GetString("Alert_BreakStartTime1shouldnotbeequaltoFirstHalfStartTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime1shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfStartTime == strbrkIn1)
                {
                    //lbl_Error.Text = "Break Start Time1 should not be equal to Second Half Start Time";
                    // base.Message(rm.GetString("Alert_BreakStartTime1shouldnotbeequaltoSecondHalfStartTime", ci));
                    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)
                {
                    //lbl_Error.Text = "Break End Time1 should not be equal to First Half End Time";
                    //base.Message(rm.GetString("Alert_BreakEndTime1shouldnotbeequaltoFirstHalfStartTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime1shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfEndTime == strbrkOut1)
                {
                    //lbl_Error.Text = "Break End Time1 should not be equal to Second Half End Time";
                    //base.Message(rm.GetString("Alert_BreakEndTime1shouldnotbeequaltoSecondHalfStartTime", ci));
                    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)
                {
                    ///lbl_Error.Text = "Break Start Time2 should not be equal to First Half Start Time";
                    //base.Message(rm.GetString("Alert_BreakStartTime2shouldnotbeequaltoFirstHalfStartTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime2shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfStartTime == strbrkIn2)
                {
                    //lbl_Error.Text = "Break Start Time2 should not be equal to Second Half Start Time";
                    //base.Message(rm.GetString("Alert_BreakStartTime2shouldnotbeequaltoSecondHalfStartTime", ci));
                    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)
                {
                    //lbl_Error.Text = "Break End Time2 should not be equal to First Half End Time";
                    //base.Message(rm.GetString("Alert_BreakEndTime2shouldnotbeequaltoFirstHalfStartTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime2shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfEndTime == strbrkOut2)
                {
                    //lbl_Error.Text = "Break End Time2 should not be equal to Second Half End Time";
                    //base.Message(rm.GetString("Alert_BreakEndTime2shouldnotbeequaltoSecondHalfStartTime", ci));
                    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)
                {
                    //lbl_Error.Text = "Break Start Time3 should not be equal to First Half Start Time";
                    //base.Message(rm.GetString("Alert_BreakStartTime3shouldnotbeequaltoFirstHalfStartTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakStartTime3shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfStartTime == strbrkIn3)
                {
                    //lbl_Error.Text = "Break Start Time3 should not be equal to Second Half Start Time";
                    //base.Message(rm.GetString("Alert_BreakStartTime3shouldnotbeequaltoSecondHalfStartTime", ci));
                    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)
                {
                    //lbl_Error.Text = "Break End Time3 should not be equal to First Half End Time";
                    // base.Message(rm.GetString("Alert_BreakEndTime3shouldnotbeequaltoFirstHalfStartTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime3shouldnotbeequaltoFirstHalfStartTime", ci) + "');", true);
                    return 0;
                }
                if (strSecondHalfEndTime == strbrkOut3)
                {
                    //lbl_Error.Text = "Break End Time3 should not be equal to Second Half End Time";
                    //base.Message(rm.GetString("Alert_BreakEndTime3shouldnotbeequaltoSecondHalfStartTime", ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_BreakEndTime3shouldnotbeequaltoSecondHalfStartTime", ci) + "');", true);
                    return 0;
                }
            }
            return 1;
        }
        else
        {
            //lbl_Error.Text = "Invalid Shift and Shift Half Times";
            //base.Message(rm.GetString("Alert_InvalidShiftandShiftHalfTimes", ci));
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidShiftandShiftHalfTimes", ci) + "');", true);
            return 0;
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_ShiftDetails.aspx");
    }
    //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_Add.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);
        lbl_StraightShiftReq.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 Vaighai  
        lbl_MaxShiftWorkHours.Text = rm.GetString("ShiftAdd_MaxShiftWorkHours", ci);
        #endregion
        #region Eastman
        lblEmpCategory.Text = rm.GetString("lblEmpCategory", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        #endregion
        lblImportNote.Text = rm.GetString("Field_ImportantNote", ci);
    }
    #region BindingEmployeeCategory
    private void BindingEmployeeCategory()
    {
        #region Eastman
        if (Convert.ToString(Session["packageID"]) != "")
            if (Convert.ToString(Session["packageID"]) == "155")
            {
                //packageID - 155 Eastman
                // 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 UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(19, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
            Response.Redirect("MasterLandingPage.aspx");
    }
    private void UpdateDefaultShift()
    {
        string script = @"<script language='javascript' type='text/javascript'>
        window.onload=function()
        {
            objHiddenField = document.getElementById('" + DefaultShiftCount.ClientID + @"');
            objSubmit = document.getElementById('" + btn_Add.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);
    }
}
