public bool DeleteHomePage(HomePageSetUpBE SetupBE)
        {


            SqlConnection con = connectionDAL.Connection();

            SqlCommand cmd = new SqlCommand("Sp_UM_HomePageSetupDelete", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add("@HomePageId", System.Data.SqlDbType.Int).Value = SetupBE.HomePageId;



            //con.Open();

            int row = cmd.ExecuteNonQuery();

            con.Close();

            if (row == 2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool ModifyHomePage(HomePageSetUpBE SetupBE)
        {

            SqlConnection con = connectionDAL.Connection();

            SqlCommand cmd = new SqlCommand("Sp_UM_HomePageSetupUpdate", con);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add("@HomePageId", System.Data.SqlDbType.Int).Value = SetupBE.HomePageId;
            cmd.Parameters.Add("@PageValidDateFrom", System.Data.SqlDbType.Date).Value = SetupBE.PageValidDateFrom;
            cmd.Parameters.Add("@PageValidDateTo", System.Data.SqlDbType.Date).Value = SetupBE.PageValidDateTo;
            cmd.Parameters.Add("@PageValidTimeFrom", System.Data.SqlDbType.Time).Value = SetupBE.PageValidTimeFrom;
            cmd.Parameters.Add("@PageValidTimeTo", System.Data.SqlDbType.Time).Value = SetupBE.PageValidTimeTo;
            cmd.Parameters.Add("@PageHtml", System.Data.SqlDbType.VarChar).Value = SetupBE.PageHtml;
            cmd.Parameters.Add("@LastModifiedBy", System.Data.SqlDbType.Int).Value = SetupBE.LastModifiedBy;

            //con.Open();
            int row = cmd.ExecuteNonQuery();
            con.Close();
            if (row == 2)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        protected void retreiveDATA()
        {
            HomePageSetUpBE HomePage = new HomePageSetUpBE();
            HomePageSetUpBAL HomePageBAL = new HomePageSetUpBAL();
            DataTable dt = new DataTable();

            HomePage.HomePageId = Convert.ToInt32(hdnHomePageId.Value);

            if (HomePageBAL.GetDetailsbyHomePageId(HomePage, ref dt))
            {
                string[] TimeFrom = new string[2];
                string[] TimeTo = new string[2];
                txtPageValidDateFrom.Text = Convert.ToDateTime(dt.Rows[0]["PageValidDateFrom"]).ToShortDateString();
                txtPageValidDateTo.Text = Convert.ToDateTime(dt.Rows[0]["PageValidDateTo"]).ToShortDateString();
                
                TimeFrom =dt.Rows[0]["PageValidTimeFrom"].ToString().Split(':');
                DdlFromHrs.Text = (TimeFrom[0]).ToString();
                DdlFromMns.Text = (TimeFrom[1]).ToString();

                TimeTo = dt.Rows[0]["PageValidTimeTo"].ToString().Split(':');
                DdlToHrs.Text = (TimeTo[0]).ToString();
                DdlToMns.Text = (TimeTo[1]).ToString();
                txtHtmlEditorExtender_HomePage.Text = HttpUtility.HtmlDecode(dt.Rows[0]["PageHtml"].ToString());
            
            }
            else
            {
            }
        }
        public bool AddHomePage(HomePageSetUpBE SetupBE)
        {

            SqlConnection con = connectionDAL.Connection();
            SqlCommand cmd = new SqlCommand("Sp_UM_HomePageSetupInsert", con);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("@PageValidDateFrom", System.Data.SqlDbType.Date).Value = SetupBE.PageValidDateFrom;
            cmd.Parameters.Add("@PageValidDateTo", System.Data.SqlDbType.Date).Value = SetupBE.PageValidDateTo;
            cmd.Parameters.Add("@PageValidTimeFrom", System.Data.SqlDbType.Time).Value = SetupBE.PageValidTimeFrom;
            cmd.Parameters.Add("@PageValidTimeTo", System.Data.SqlDbType.Time).Value = SetupBE.PageValidTimeTo;
            cmd.Parameters.Add("@PageHtml", System.Data.SqlDbType.VarChar).Value = SetupBE.PageHtml;
            cmd.Parameters.Add("@LastModifiedBy", System.Data.SqlDbType.Int).Value = SetupBE.LastModifiedBy;

            //con.Open();
            int row = cmd.ExecuteNonQuery();   //returns an integer value to check whether the data has been successfully inserted into the database table
            con.Close();
            if (row > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
 public bool AddHomePage(HomePageSetUpBE SetupBE)
 {
     HomePageSetUpDAL SetupDAL = new HomePageSetUpDAL();
     if (SetupDAL.AddHomePage(SetupBE))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 public bool GetHtml(HomePageSetUpBE setupBE, ref DataTable dt)
 {
     HomePageSetUpDAL SetupDAL = new HomePageSetUpDAL();
     if (SetupDAL.GetHtml(setupBE, ref dt))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
        protected void btnDeleteYes_Click(object sender, EventArgs e)
        {
            HomePageSetUpBE HomePage = new HomePageSetUpBE();
            HomePageSetUpBAL HomePageBAL = new HomePageSetUpBAL();

            HomePage.HomePageId = Convert.ToInt32(hdnHomePageListId.Value);

            if (HomePageBAL.DeleteHomePage(HomePage))
            {
                LvHomePageItems.EditIndex = -1;
                BindHomePageList();
                LoggedIn master = (LoggedIn)this.Master;
                master.ShowMessage("Record successfully deleted.", true);
                BindHomePageList();
                recalcNoOfPages();
            }
            else
            {
                LoggedIn master = (LoggedIn)this.Master;
                master.ShowMessage("UnSuccessful", false);
            
            }
            
        }
 protected void GetHtmlPage(HomePageSetUpBE HomePage)
 {
     DataTable dt = new DataTable();
     HomePageSetUpBAL HomePageBAL = new HomePageSetUpBAL();
     if (HomePageBAL.GetHtml(HomePage, ref dt))
     {
         divOutput.InnerHtml = HttpUtility.HtmlDecode(dt.Rows[0]["PageHtml"].ToString());
     }
     else
     {
     }
    
 }
        protected void LvHomePageItems_OnItemCommand(object sender, ListViewCommandEventArgs e)
        {
            HtmlTableRow SelectedRow;
            LoggedIn master = (LoggedIn)this.Master;

            if (e.Item.DisplayIndex % 2 == 0) //even
            {
                SelectedRow = e.Item.FindControl("trItemTemplate") as HtmlTableRow;
            }
            else //odd
            {
                SelectedRow = e.Item.FindControl("trAltItemTemplate") as HtmlTableRow;
            }

            SelectedRow.BgColor = "Red";

            if (String.Equals(e.CommandName, "Delete"))
            {
                if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "delete"))
                {
                    master.ShowMessage("You are not authorised to perform this function. Please contact system administrator.", false);
                    return;
                }
                HomePageSetUpBE HomePage = new HomePageSetUpBE();

                string[] arg = new string[3];
                arg = e.CommandArgument.ToString().Split(',');
                hdnHomePageListId.Value = arg[0].ToString();
                StartDateTimeText.Text = Convert.ToDateTime(arg[1]).ToShortDateString() + ' ' + arg[3].ToString();
                EndDateTimeText.Text = Convert.ToDateTime(arg[2].ToString()).ToShortDateString() + ' ' + arg[4].ToString();

                mpe_DeleteHomePageItem.Show();

            }

            if (String.Equals(e.CommandName, "View"))
            {
                if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "delete"))
                {
                    master.ShowMessage("You are not authorised to perform this function. Please contact system administrator.", false);
                    return;
                }
                HomePageSetUpBE HomePage = new HomePageSetUpBE();
           
                string HomePageId = e.CommandArgument.ToString();
                HomePage.HomePageId = Convert.ToInt32(HomePageId);

                GetHtmlPage(HomePage);

                mpe_ViewHomePageSetup.Show();

            }
        }
        public bool GetDetailsbyHomePageId(HomePageSetUpBE setupBE , ref DataTable dt)
        {
            SqlConnection con = connectionDAL.Connection();
            SqlDataAdapter da = new SqlDataAdapter("Sp_UM_GetAllDetailsofHomePagebyHomePageId", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter HomePageId = new SqlParameter("@HomePageId", SqlDbType.Int);
            HomePageId.Value = setupBE.HomePageId;
            da.SelectCommand.Parameters.Add(HomePageId);
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        public bool VerifyOverlapHomePage(HomePageSetUpBE setupBE, ref DataTable dt)
        {
            SqlConnection con = connectionDAL.Connection();
            SqlDataAdapter da = new SqlDataAdapter("Sp_UM_HomePageSetupVerifyTimeOverlap", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter PageValidDateFrom = new SqlParameter("@PageValidDateFrom", SqlDbType.Date);
            SqlParameter PageValidDateTo = new SqlParameter("@PageValidDateTo", SqlDbType.Date);
            SqlParameter PageValidTimeFrom = new SqlParameter("@PageValidTimeFrom", SqlDbType.Time);
            SqlParameter PageValidTimeTo = new SqlParameter("@PageValidTimeTo", SqlDbType.Time);
            //SqlParameter PageHtml = new SqlParameter("@PageHtml", SqlDbType.VarChar);

            PageValidDateFrom.Value = setupBE.PageValidDateFrom;
            PageValidDateTo.Value = setupBE.PageValidDateTo;
            PageValidTimeFrom.Value = setupBE.PageValidTimeFrom;
            PageValidTimeTo.Value = setupBE.PageValidTimeTo;
            //PageHtml.Value = setupBE.PageHtml;

            da.SelectCommand.Parameters.Add(PageValidDateFrom);
            da.SelectCommand.Parameters.Add(PageValidDateTo);
            da.SelectCommand.Parameters.Add(PageValidTimeFrom);
            da.SelectCommand.Parameters.Add(PageValidTimeTo);
            //da.SelectCommand.Parameters.Add(PageHtml);

            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool GetHtml(HomePageSetUpBE SetupBE, ref DataTable dt)
        {
               SqlConnection con = connectionDAL.Connection();
               SqlDataAdapter da = new SqlDataAdapter("Sp_UM_GetHomePageHtmlbyHomePageId", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter HomePageId = new SqlParameter("@HomePageId", SqlDbType.VarChar);

            HomePageId.Value = SetupBE.HomePageId;
            da.SelectCommand.Parameters.Add(HomePageId);

            da.Fill(dt);
            if (loadHtmlProfile(ref dt))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool SearchHomePage(HomePageSetUpBE setupBE, ref DataTable dt)
        {
            HomePageSetUpDAL SetupDAL = new HomePageSetUpDAL();

            if (SetupDAL.SearchHomePage(setupBE, ref dt))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool VerifyOverlapHomePage(HomePageSetUpBE setupBE, ref DataTable dt)
        {
            HomePageSetUpDAL SetupDAL = new HomePageSetUpDAL();

            if (SetupDAL.VerifyOverlapHomePage(setupBE, ref dt))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();

            HomePageSetUpBE setupBE = new HomePageSetUpBE();
            HomePageSetUpBAL setupBAL = new HomePageSetUpBAL();

            setupBE.HomePageId = Convert.ToInt32(hdnHomePageId.Value);
            setupBE.PageValidDateFrom = Convert.ToDateTime(txtPageValidDateFrom.Text);
            setupBE.PageValidDateTo = Convert.ToDateTime(txtPageValidDateTo.Text);
            setupBE.PageValidTimeFrom = DdlFromHrs.SelectedValue + ":" + DdlFromMns.SelectedValue;
            setupBE.PageValidTimeTo = DdlToHrs.SelectedValue + ":" + DdlToMns.SelectedValue;
            setupBE.PageHtml = HttpUtility.HtmlDecode(txtHtmlEditorExtender_HomePage.Text);
            setupBE.LastModifiedBy = LoggedInUser.UserId;
            

            if (setupBAL.VerifyOverlapHomePage(setupBE, ref dt))
            {
                LoggedIn MasterPage = (LoggedIn)Page.Master;
                MasterPage.ShowMessage("Sorry You Cannot Update Event To Already Existing Dates", false);
                txtHtmlEditorExtender_HomePage.Text = HttpUtility.HtmlDecode(txtHtmlEditorExtender_HomePage.Text);
               
               
            }

            else
            {
                LoggedIn MasterPage = (LoggedIn)Page.Master;
                MasterPage.ShowMessage("No Other events On the Same Date Proceed.", false);
                txtHtmlEditorExtender_HomePage.Text = HttpUtility.HtmlDecode(txtHtmlEditorExtender_HomePage.Text);
              
                if (setupBAL.ModifyHomePage(setupBE))
                {

                    txtHtmlEditorExtender_HomePage.Text = HttpUtility.HtmlDecode(txtHtmlEditorExtender_HomePage.Text);
                    
                    MasterPage.ShowMessage("Record Successfully Updated", true);
                   
                }
                else
                {
                    MasterPage.ShowMessage("UnSuccessful", true);
                    
                   
                }
            }

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            HomePageSetUpBE SetupBE = new HomePageSetUpBE();
            HomePageSetUpBAL SetupBAL = new HomePageSetUpBAL();
            DataTable dt = new DataTable();


            SetupBE.PageValidDateFrom = Convert.ToDateTime(txtPageValidDateFrom.Text);
            SetupBE.PageValidDateTo = Convert.ToDateTime(txtPageValidDateTo.Text);
            SetupBE.PageValidTimeFrom = DdlFromHrs.SelectedValue + ":" + DdlFromMns.SelectedValue;
            SetupBE.PageValidTimeTo = DdlToHrs.SelectedValue + ":" + DdlToMns.SelectedValue;
            SetupBE.PageHtml = HttpUtility.HtmlDecode(txtHtmlEditorExtender_HomePage.Text);
            SetupBE.LastModifiedBy = LoggedInUser.UserId;

            txtHtmlEditorExtender_HomePage.Text = HttpUtility.HtmlDecode(HtmlEditorText);

            if (SetupBAL.VerifyOverlapHomePage(SetupBE, ref dt))
            {
               
                txtHtmlEditorExtender_HomePage.Text = HttpUtility.HtmlDecode(HtmlEditorText);
                LoggedIn MasterPage = (LoggedIn)Page.Master;
                MasterPage.ShowMessage("Sorry You Cannot Add Event On The Same Dates", false);
            }

            else
            {

                LoggedIn MasterPage = (LoggedIn)Page.Master;
                  MasterPage.ShowMessage("No Other events On the Same Date Proceed....", false);
              

                if (SetupBAL.AddHomePage(SetupBE))
                {
                  //  LoggedIn MasterPage = (LoggedIn)Page.Master;
                      MasterPage.ShowMessage("Record Succesfully Added", true);
                    
                    txtPageValidDateFrom.Text = "";
                    txtPageValidDateTo.Text = "";
                    DdlFromHrs.SelectedIndex = 0;
                    DdlFromMns.SelectedIndex = 0;
                    DdlToHrs.SelectedIndex = 0;
                    DdlToMns.SelectedIndex = 0;
                    txtHtmlEditorExtender_HomePage.Text = "";
                }
                else
                {
                     MasterPage.ShowMessage("Unsuccessful", false);
                    
                }
            }




        }