using System;
using System.Data;
public partial class Masters_ShiftPatternRemote : 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();
        //int iShift1ID = 0;
        //int iShift2ID = 0;
        //if (Request.QueryString["Shift1ID"] != null)
        //{
        //    iShift1ID = Convert.ToInt32(Request.QueryString["Shift1ID"]);            
        //}
        //if (Request.QueryString["Shift2ID"] != null)
        //{
        //    iShift2ID = Convert.ToInt32(Request.QueryString["Shift2ID"]);
        //}
        //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("Failure for Shift Overlapping for " + strShift1 + " And " + strShift2);
        //            Response.End();
        //        }
        //        else
        //        {
        //            Response.Clear();
        //            Response.Write("Success");
        //            Response.End();
        //        }
        //    }
        //}
        string shiftValue = "";
        if (Request.QueryString["shiftValue"] != null)
        {
            shiftValue = Convert.ToString(Request.QueryString["shiftValue"]);
        }
        char[] star = { '*' };
        string[] strShiftVal = shiftValue.Split(star);
        string strShift1 = "";
        string strShift2 = "";
        int iShift1ID = 0;
        int iShift2ID = 0;
        for (int i = 0; i < strShiftVal.Length; i++)
        {
            if (i == (strShiftVal.Length - 1))
            {
                if (strShiftVal[0] != "" && strShiftVal[0] != "-Select")
                {
                    iShift2ID = Convert.ToInt32(strShiftVal[0]);
                }
            }
            else
            {
                if (strShiftVal[i + 1] != "" && strShiftVal[i + 1] != "-Select")
                {
                    iShift2ID = Convert.ToInt32(strShiftVal[i + 1]);
                }
            }
            if (strShiftVal[i] != "" && strShiftVal[i] != "-Select")
            {
                iShift1ID = Convert.ToInt32(strShiftVal[i]);
            }
            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 " + strShift1 + " And " + strShift2);
                        Response.End();
                        return;
                    }
                    //else
                    //{
                    //    Response.Clear();
                    //    Response.Write("Success");
                    //    Response.End();
                    //}
                }
            }
        }
        Response.Clear();
        Response.Write("Success");
        Response.End();
    }
}
