using System;
using System.Data;
public partial class Masters_ShiftRosterRemote : Base.BasePage
{
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);
        ShiftPatternEventData objClass = new ShiftPatternEventData();
        string shiftPatternValue = "";
        if (Request.QueryString["shiftPatternValue"] != null)
        {
            shiftPatternValue = Convert.ToString(Request.QueryString["shiftPatternValue"]);
        }
        string rost = "";
        if (Request.QueryString["rost"] != null)
        {
            rost = Convert.ToString(Request.QueryString["rost"]);
        }
        char[] star = { '*' };
        string[] strRost = rost.Split(star);
        string[] strShiftVal = shiftPatternValue.Split(star);
        string strShift1 = "";
        string strShift2 = "";
        int iShift1ID = 0;
        int iShift2ID = 0;
        int iShiftPattern1ID = 0;
        int iShiftPattern2ID = 0;
        string strRost1 = "";
        string strRost2 = "";
        for (int i = 0; i < strShiftVal.Length; i++)
        {
            strRost1 = strRost[i];
            if (i == (strShiftVal.Length - 1))
            {
                if (strShiftVal[0] != "" && strShiftVal[0] != "-Select")
                {
                    iShiftPattern2ID = Convert.ToInt32(strShiftVal[0]);
                }
                strRost2 = strRost[0];
                strRost1 = strRost[i - 1];
            }
            else
            {
                if (strShiftVal[i + 1] != "" && strShiftVal[i + 1] != "-Select")
                {
                    iShiftPattern2ID = Convert.ToInt32(strShiftVal[i + 1]);
                }
                strRost2 = strRost[i + 1];
            }
            if (strShiftVal[i] != "" && strShiftVal[i] != "-Select")
            {
                iShiftPattern1ID = Convert.ToInt32(strShiftVal[i]);
            }
            //Get shift from the pattern
            ShiftAllocationEvendata objShift = new ShiftAllocationEvendata();
            DataSet ds_Shift1 = new DataSet();
            ds_Shift1 = objShift.SelectShiftPattern_ShiftAllocDetails(iShiftPattern1ID);
            if (ds_Shift1 != null && ds_Shift1.Tables.Count > 0 && ds_Shift1.Tables[0].Rows.Count > 0)
            {
                int iDays = ds_Shift1.Tables[0].Rows.Count;
                iShift1ID = Convert.ToInt32(ds_Shift1.Tables[0].Rows[iDays - 1]["id"]);
            }
            DataSet ds_Shift2 = new DataSet();
            ds_Shift2 = objShift.SelectShiftPattern_ShiftAllocDetails(iShiftPattern2ID);
            if (ds_Shift2 != null && ds_Shift2.Tables.Count > 0 && ds_Shift2.Tables[0].Rows.Count > 0)
            {
                iShift2ID = Convert.ToInt32(ds_Shift2.Tables[0].Rows[0]["id"]);
            }
            //End of get shift from pattern
            DataSet ds = new DataSet();
            ds = objClass.CheckShiftOverLapping(iShift1ID, iShift2ID);
            //string strShift1 = "";
            //string strShift2 = "";
            if (ds != null & ds.Tables.Count > 0 & ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ShiftOverLapping"] != DBNull.Value)
                {
                    if (Convert.ToInt32(ds.Tables[0].Rows[0]["ShiftOverLapping"]) != 0)
                    {
                        if (ds.Tables[0].Rows[0]["Shift1"] != DBNull.Value && Convert.ToString(ds.Tables[0].Rows[0]["Shift1"]) != "")
                        {
                            strShift1 = Convert.ToString(ds.Tables[0].Rows[0]["Shift1"]);
                        }
                        if (ds.Tables[0].Rows[0]["Shift2"] != DBNull.Value && Convert.ToString(ds.Tables[0].Rows[0]["Shift2"]) != "")
                        {
                            strShift2 = Convert.ToString(ds.Tables[0].Rows[0]["Shift2"]);
                        }
                        Response.Clear();
                        Response.Write("Shift Overlapping for " + strRost1 + " And " + strRost2);
                        Response.End();
                        return;
                    }
                    //else
                    //{
                    //    Response.Clear();
                    //    Response.Write("Success");
                    //    Response.End();
                    //}
                }
            }
        }
        Response.Clear();
        Response.Write("Success");
        Response.End();
    }
}
