using CLS_BL;
using CLS_DL;
using CLS_PL;
using iTextSharp.text;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using MySql.Data;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using static SUNWEB.InteractiveDashboard;

namespace SUNWEB
{
    public partial class Layoutsetting : System.Web.UI.Page
    {

        BL_SELECT ObjSel = new BL_SELECT();
        BLCompany ObjBL = new BLCompany();
        PLCOMMON ObjPL = new PLCOMMON();
        BL_USER ObjUserBL = new BL_USER(); //This Object for All User and Page Related fuctions included 
        PLCUSTOMER ObjCustPL = new PLCUSTOMER();
        Int32 K = 0;
        Int32 L = 0;
        Int32 S = 0;
        Int32 Q = 0;
        Int32 iUpdateSetting = 0; //Product
        Int32 iUpdateIndexSetting = 0; //Index
        Int32 iUpdateViewCart = 0; // ViewCart
        Int32 iUpdateTakeaway = 0; // Takeawaycharge
        Int32 iUpdateCharge = 0;    //Charge
        Int32 iUpdateEmail = 0;  //Email
        Int32 ifomo = 0;  //Email
        Int32 iIcrmUpdate = 0; // IcrmUpdate
        Int32 iWebUpdate = 0; // IwebUpdate
        string ConStr = ConfigurationManager.ConnectionStrings["ConMysql"].ConnectionString;
        string ConStr_Rds = ConfigurationManager.ConnectionStrings["ConRDS"].ConnectionString;
        string Curr_Date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        string Curr_DateOnly = System.DateTime.Now.ToString("yyyy-MM-dd");
        DateTime MonthstartDt;
        DataSet ds = new DataSet();
        MYSQLDB ObjMain = new MYSQLDB();
        MYSQLCLOUD ObjCloudMain = new MYSQLCLOUD();
        DataTable DT = new DataTable();
        DataTable Dt2 = new DataTable();
        DataTable DtLicense = new DataTable();
        DataTable DtSuperAdmin = new DataTable();
        DataTable DtMultiBranch = new DataTable();
        DataTable DtNormalUser = new DataTable();
        DataTable DTProductSale = new DataTable();
        DataTable DTImageResult = new DataTable();
        DataTable DTLogo = new DataTable();

        MySqlCommand Cmdv = new MySqlCommand();
        // User Variables 
        string UserId = string.Empty;
        string UserName = string.Empty;
        string PortalTypeId = string.Empty;
        string cd_Id = string.Empty;
        string Datapath = string.Empty;
        string cd_BranchAlias = string.Empty;
        string IsMultiBranch = string.Empty;
        string IsSuperAdmin = string.Empty;
        string ActiveCallvalue = string.Empty;
        // License Variables ..
        string PID = string.Empty;
        string Page_Acess = string.Empty;
        string Read_Acess = string.Empty;
        string Write_Acess = string.Empty;
        string Isdowld_Acess = string.Empty;
        string Rcd_id = string.Empty;
        string RPortalid = string.Empty;
        string Useridvalue = string.Empty;
        string QueryCurr_Select = string.Empty;
        string L_MaxUserCnt = string.Empty;

        string L_LayoutSetting = string.Empty;
        string Branchidval = string.Empty;
        string BranchFullName = string.Empty;
        string Curr_BranchFullName = string.Empty;
        string Cmb_BranchName = string.Empty;

        string HQ = string.Empty;
        string Cm_id = string.Empty;
        string ISHQ = string.Empty;
        DataSet DS = new DataSet();
        string BranchAlias = string.Empty;
        string FileID = string.Empty;
        string Vw_Chk = string.Empty;

        // For Menu Creation 
        string RCategoryID = string.Empty;
        string RCategoryName = string.Empty;
        string RDescription = string.Empty;
        string URL = string.Empty;
        string SeqNO = string.Empty;
        DataTable ChkTable = new DataTable();

        DataTable DtPriceFlag = new DataTable();
        DataTable DtinventoryCnt = new DataTable();
        DataTable DtRead = new DataTable();
        string ReadHQ = string.Empty;

        string RBranchid = string.Empty;
        string Branchid = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {

            PID = "39";    // This is for Layout Setting Page 
            #region Default
            if (!IsPostBack)
            {
                txtStartDt.Text = Curr_DateOnly;
                txtEndDt.Text = Curr_DateOnly;
                txtntaxflag.Text = "0";
                txtnvalue.Text = "0.000";


            }
            MonthstartDt = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, 1);
            if (Session["UserName"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == "") && ((Convert.ToBoolean(Session["IsMultiBranch"])) == true))
            {
                if (!IsPostBack)
                {
                    LoadBranchesOnID();   

                    string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
                    ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
                    if (ActiveCallvalue != " " || ActiveCallvalue != "Select Branch")
                    {
                        ActiveCall();
                    }
                }
            }
            else if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchesOnID();   
                }
                cd_BranchAlias = cmbBranches.SelectedItem.Text;
                //LoadInventoryListGrid(cd_BranchAlias, txtStartDt.Text, txtEndDt.Text);
            }
            else if (((Convert.ToBoolean(Session["IsMultiBranch"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchesOnID();
                    ActiveCall();
                }
            }
            else if (((Session["PortalTypeId"].ToString() != "") || (Convert.ToBoolean(Session["IsSuperAdmin"])) == false) && ((Convert.ToBoolean(Session["IsMultiBranch"])) == false))
            {
                cmbBranches.Enabled = false;
                cmbBranches.Visible = false;

                Cm_id = ObjSel.GETcmid(Session["Cd_Id"].ToString());  // Get cm_id
                HQ = ObjSel.Get_HQ(Cm_id);     // Get the HQ Value
                Curr_BranchFullName = ObjSel.GetBranchFullName(HQ, Session["Branch_HQ"].ToString());
                lblBranchAliasName.ForeColor = System.Drawing.Color.DodgerBlue;
                lblBranchAliasName.Text = "Branch Name" + "&nbsp;" + "-" + "&nbsp;" + Curr_BranchFullName + "&nbsp; ";

                cd_BranchAlias = Session["Branch_HQ"].ToString();
                Datapath = Session["DataPath"].ToString();
                PortalTypeId = Session["PortalTypeId"].ToString();

                DT = ObjUserBL.GetPageRightsDetailsPid(Session["UserId"].ToString(), PID);
                if (DT.Rows.Count > 0)
                {
                    Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                    Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                    Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                    Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                    Session["Page_Acess"] = Page_Acess;
                    Session["Read_Acess"] = Read_Acess;
                    Session["Write_Acess"] = Write_Acess;
                    Session["Isdowld_Acess"] = Isdowld_Acess;
                }
                if ((Session["L_LayoutSetting"].ToString() == "N") || (Session["Page_Acess"].ToString() == "N"))
                {
                    Response.Redirect("DeniedPage.aspx");
                }
                else
                {
                    // lblMsgTotalSelection.Text = "Item Sale  Between" + "&nbsp;&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  and  &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                    if (!IsPostBack)
                    {
                        if (Session["Isdowld_Acess"].ToString() == "N")
                        {
                            // btnExcel.Enabled = false;
                            Response.Write(@"<script language='javascript'>alert('No Access To download.')</script>");
                        }
                        else
                        {
                            btnGetReports.Visible = true;

                            if (cmbBranches.Visible == false)
                            {
                                //  BindGridview(Session["Branch_HQ"].ToString(), txtStartDt.Text, txtEndDt.Text);
                            }
                        }
                    }
                }
            }
            else
            {

            }
            #endregion


        }


        #region Default Setting

        public void ActiveCall()
        {
            string _default_branch = ObjMain.ExecuteScalar("select DefaultBranch from portaldb.companymaster where cm_id = " + Session["CM_ID"] + ";");

            string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
            ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
            if (ActiveCallvalue == "")
            {
                #region  Default Branch Validation:Either HQ or First Branch Based On IsHQ Ini in PMS 
                string _hq_query = "select IsHQ from  portaldb.companymaster where cm_id=" + Session["CM_ID"] + " ;";
                string _Is_HQ_Enabled = Convert.ToString(ObjMain.ExecuteScalar(_hq_query));
                if (_Is_HQ_Enabled == "1")
                {
                    ActiveCallvalue = ObjSel.GetHQ(Session["Branch_HQ"].ToString());

                }
                else if (_Is_HQ_Enabled == "0")
                {
                    ActiveCallvalue = ObjSel.GETBrachAlias8(Session["CM_ID"].ToString(), Session["Branch_HQ"].ToString(), Session["UserId"].ToString());
                }

                #endregion




            }


            #region  HQ Validation in ActiveCall Function : Starts 
            cd_BranchAlias = ActiveCallvalue;
            // HQ Validation For Loading Branch Name : Dropdown  Added Karthik  On 02-12-21 

            ReadHQ = ObjUserBL.GetBranchFullNameByBranchName(Session["Branch_HQ"].ToString(), cd_BranchAlias);

            if (ReadHQ == "HQ")
            {
                cmbBranches.Items.FindByText(ReadHQ).Selected = true;
            }
            else
            {
                Curr_BranchFullName = ObjUserBL.GetBranchCurr_BranchVal(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), cd_BranchAlias);
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Curr_BranchFullName);  // This will Return BranchName( Actual Database Name )
                cmbBranches.Items.FindByText(Curr_BranchFullName).Selected = true;
                Branchidval = ObjUserBL.GetBranchIDbyName(ActiveCallvalue, ActiveCallvalue);

            }

            #endregion

            if (Branchidval != "")
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, Branchidval);
            }
            else
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, Session["Fistbranch"].ToString());

            }
            if (DT.Rows.Count > 0)
            {
                Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                Session["Page_Acess"] = Page_Acess;
                Session["Read_Acess"] = Read_Acess;
                Session["Write_Acess"] = Write_Acess;
                Session["Isdowld_Acess"] = Isdowld_Acess;
            }
            Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + ActiveCallvalue + "';");
            RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
            DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);
            if (DtLicense.Rows.Count > 0)
            {


                L_LayoutSetting = DtLicense.Rows[0]["LAYOUTSETTING"].ToString();
                Session["L_LayoutSetting"] = L_LayoutSetting;
            }
            if ((Session["L_LayoutSetting"] == null) || Session["L_LayoutSetting"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            {
                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion


                LoadProductIni(BranchAlias);
                LoadIndexIni(BranchAlias);
                LoadViewCart(BranchAlias);
                LoadVTakeawayCharge(BranchAlias);
                LoadVTakeawayChargeOnly(BranchAlias);
                LoadCharge(BranchAlias); //John added on 06-Sept-2021 Charge GridView
                LoadEmail(BranchAlias); //John added on 30-Sept-2021 Email Setting
                LoadLandingImage(BranchAlias);
                LoadCompanyLogo(BranchAlias); //John added on 30-Sept-2021 
                LoadAdvertisementImage(BranchAlias);  //john added on 31-July-2024
                LoadICRMCompanyLogo(BranchAlias);// Karthik added on Nov-2024
                LoadICRMCompanyBG(BranchAlias);
                LoadSms(BranchAlias);
                LoadFomo(BranchAlias);
                LoadPost(BranchAlias);
                LoadICRM(BranchAlias);
                LoadCRM(BranchAlias);
                LoadPortal(BranchAlias);
                LoadInventoryPriceFlagRows(BranchAlias);
                lblclientname.Text = Session["CM_ID"].ToString();
                lblstorename.Text = BranchAlias;


                #region  Check the Webordering Menu and Menu Creation  
                ChkTable = ObjMain.GetData_DT("Select  * from " + ActiveCallvalue + ".menu;");

                if (ChkTable.Rows.Count > 0)
                {
                    lblIsWeborderingMenuCreated.Text = "Webordering Menu Already Created! ";

                    lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    lblIsWeborderingMenuCreated.Text = "Webordering Menu is Empty ! ";
                    lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Red;
                }
                #endregion

            }
            else
            {

                //btnExcel.Enabled = true;
                //lblMsgTotalSelection.Text = "Total Sale Selection Between" + "&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                cd_BranchAlias = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                // BindGridview(ActiveCallvalue, txtStartDt.Text, txtEndDt.Text);
                System.Threading.Thread.Sleep(2000);
                LoadProductIni(ActiveCallvalue);
                LoadIndexIni(ActiveCallvalue);
                LoadViewCart(ActiveCallvalue);
                LoadVTakeawayCharge(ActiveCallvalue);
                LoadVTakeawayChargeOnly(ActiveCallvalue);
                LoadCharge(ActiveCallvalue); //John added on 06-Sept-2021 Charge GridView
                LoadEmail(ActiveCallvalue); //John added on 30-Sept-2021 Email Setting
                LoadLandingImage(ActiveCallvalue);
                LoadCompanyLogo(ActiveCallvalue); //John added on 30-Sept-2021 
                LoadAdvertisementImage(ActiveCallvalue);  //john added on 31-July-2024
                LoadICRMCompanyLogo(ActiveCallvalue);// Karthik added on Nov-2024
                LoadICRMCompanyBG(ActiveCallvalue);
                LoadSms(ActiveCallvalue);
                LoadFomo(ActiveCallvalue);
                LoadPost(ActiveCallvalue);
                LoadICRM(ActiveCallvalue);
                LoadCRM(ActiveCallvalue);
                LoadPortal(ActiveCallvalue);
                LoadInventoryPriceFlagRows(ActiveCallvalue);
                lblclientname.Text = Session["CM_ID"].ToString();
                lblstorename.Text = ActiveCallvalue;


                #region  Check the Webordering Menu and Menu Creation  
                ChkTable = ObjMain.GetData_DT("Select  * from " + ActiveCallvalue + ".menu;");

                if (ChkTable.Rows.Count > 0)
                {
                    lblIsWeborderingMenuCreated.Text = "Webordering Menu Already Created! ";

                    lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    lblIsWeborderingMenuCreated.Text = "Webordering Menu is Empty ! ";
                    lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Red;
                }
                #endregion

            }

        }

        public void LoadBranchName()
        {
            DtNormalUser = ObjUserBL.GetBranchOnLoginValues8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtNormalUser.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtNormalUser;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }
        }


        public void LoadBranchesOnID()
        {
            DT = ObjUserBL.GetBranchIDList(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            StringBuilder StrBObj = new StringBuilder();

            for (int i = 0; i < DT.Rows.Count; i++)
            {
                DataRow dr = DT.Rows[i];
                RBranchid = dr["Branchid"].ToString();
                if (StrBObj.Length != 0)
                {

                    RBranchid = "," + RBranchid;
                    StrBObj.Append("  " + RBranchid + "    ");
                }
                else
                {
                    string _get_HQ = ObjSel.GetHQ_Status(Session["CM_ID"].ToString());
                    if (_get_HQ == "0")
                    {

                        //UPDATEBRANCH(Cmb_BranchName);
                        //Response.Redirect(Request.RawUrl);
                        Branchid = RBranchid;
                        StrBObj.Append("SELECT  Branchid ,BranchName,branchfullname,datapath FROM " + Session["Branch_HQ"].ToString() + ".branches where branchid in ( " + Branchid + " ");


                    }
                    else if (_get_HQ == "1")
                    {
                        Branchid = RBranchid;
                        StrBObj.Append("SELECT  Branchid ,BranchName,branchfullname,datapath FROM " + Session["Branch_HQ"].ToString() + ".branches where branchid in (1 , " + Branchid + " ");


                    }


                }


            }
            StrBObj.Append(")");
            Dt2 = ObjCloudMain.GetData_DT(StrBObj.ToString());

            if (Dt2.Rows.Count > 0)
            {
                cmbBranches.DataSource = Dt2;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }

        }


        public void LoadBranchName4SuperAdmin()
        {
            DtSuperAdmin = ObjUserBL.GetBranchOnSuperAdmin8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtSuperAdmin.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtSuperAdmin;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }
        }

        public void UPDATEBRANCH(string ActiveCallvalue)
        {
            if (!string.IsNullOrEmpty(Session["UserId"] as string))
            {
                Useridvalue = Session["UserId"].ToString();
                QueryCurr_Select = "Update portaldb.usermaster set ActiveValue='" + ActiveCallvalue + "' where Userid=" + Useridvalue + "";
                S = ObjMain.ExecuteNonQuery(QueryCurr_Select);
            }
            else
            {
                Response.Redirect("Login.aspx");

            }

        }
        #endregion

        protected void btnGetReports_Click(object sender, EventArgs e)
        {

        }

        protected void btnMenucreation_Click(object sender, EventArgs e)
        {
            string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
            ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
            if (ActiveCallvalue == "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch(Session["Branch_HQ"].ToString());
            }
            ISHQ = ObjMain.ExecuteScalar("select BranchName from " + ActiveCallvalue + ".branches where Branchname='" + ActiveCallvalue + "' and branchID=1;");  //now 
            if (ISHQ != "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch(Session["Branch_HQ"].ToString());
                UPDATEBRANCH(ActiveCallvalue);
            }



            ChkTable = ObjMain.GetData_DT("Select  * from " + ActiveCallvalue + ".menu;");

            if (ChkTable.Rows.Count == 0)
            {
                DT = ObjMain.GetData_DT("Select  Categoryid,CategoryName,Description from " + ActiveCallvalue + ".inventorycategories Where CategoryName<>'Round' and Categoryid<>0 order by categoryid");
                if (DT.Rows.Count > 0)
                {
                    for (int i = 0; i < DT.Rows.Count; i++)
                    {
                        DataRow dr = DT.Rows[i];
                        SeqNO = ObjSel.GetMax_SeqNo(ActiveCallvalue);
                        RCategoryID = dr["Categoryid"].ToString();
                        RCategoryName = dr["CategoryName"].ToString();
                        RDescription = dr["Description"].ToString();
                        URL = "~/ProductDetails.aspx?Categoryid=" + RCategoryID + "";
                        K = ObjMain.ExecuteNonQuery("Insert into " + ActiveCallvalue + ".Menu(ParentMenuId,Title,Description,Url,CategoryId,SeqNo)values(0,'" + RCategoryName + "','" + RDescription + "','" + URL + "'," + RCategoryID + "," + SeqNO + " )");
                    }

                }
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Webordering menu Created Successfully');location.href='LayoutSetting.aspx'", true);

            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Already menu Created');location.href='LayoutSetting.aspx'", true);
            }


        }

        protected void cmbBranches_SelectedIndexChanged(object sender, EventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;      // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion


            UPDATEBRANCH(BranchAlias);

            ActiveCall();


            //if (cmbBranches.SelectedIndex == 0)
            //{
            //    Response.Write("LayoutSetting.aspx");
            //}
            //else
            //{
            //    DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, cmbBranches.SelectedItem.Value);
            //    if (DT.Rows.Count > 0)
            //    {
            //        Page_Acess = DT.Rows[0]["Acess_status"].ToString();
            //        Read_Acess = DT.Rows[0]["Read_Access"].ToString();
            //        Write_Acess = DT.Rows[0]["Write_Access"].ToString();
            //        Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();
            //        Session["Page_Acess"] = Page_Acess;
            //        Session["Read_Acess"] = Read_Acess;
            //        Session["Write_Acess"] = Write_Acess;
            //        Session["Isdowld_Acess"] = Isdowld_Acess;
            //    }


            //    if (cmbBranches.SelectedIndex == 1)
            //    {

            //        BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            //        Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            //        UPDATEBRANCH(Cmb_BranchName);

            //    }
            //    else
            //    {
            //        BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            //        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            //        Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + Cmb_BranchName + "';");
            //        RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
            //        DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);

            //    }


            //    if (DtLicense.Rows.Count > 0)
            //    {


            //        L_LayoutSetting = DtLicense.Rows[0]["LAYOUTSETTING"].ToString();
            //        Session["L_LayoutSetting"] = L_LayoutSetting;
            //    }




            //    if ((Session["L_LayoutSetting"] == null) || Session["L_LayoutSetting"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            //    {

            //        if (cmbBranches.SelectedItem.Text == "HQ")
            //        {

            //            #region  Validation Between HQ Branch and Normal Branch 
            //            BranchFullName = cmbBranches.SelectedItem.Text;      // This will Return Branch FullName 
            //            if (BranchFullName == "HQ")
            //            {
            //                BranchAlias = Session["Branch_HQ"].ToString();
            //            }
            //            else
            //            {
            //                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
            //                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            //                BranchAlias = Cmb_BranchName;

            //            }
            //            #endregion



            //            // Assign s3 realted Parameter values 
            //            // clientname.Value = Session["CM_ID"].ToString();
            //            lblclientname.Text = Session["CM_ID"].ToString();
            //            lblstorename.Text = BranchAlias;
            //            LoadFomo(BranchAlias);
            //            LoadSms(BranchAlias);
            //            LoadProductIni(BranchAlias);
            //            LoadIndexIni(BranchAlias);
            //            LoadViewCart(BranchAlias);
            //            LoadVTakeawayCharge(BranchAlias);
            //            LoadVTakeawayChargeOnly(BranchAlias);
            //            LoadLandingImage(BranchAlias);
            //            LoadCompanyLogo(BranchAlias);
            //            LoadICRMCompanyBG(BranchAlias);  // Karthik added on 20-Nov-2025
            //            LoadAdvertisementImage(BranchAlias);  //john added on 31-July-2024
            //            LoadICRMCompanyLogo(BranchAlias);
            //            LoadPost(BranchAlias);
            //            LoadICRM(BranchAlias);
            //            LoadCRM(BranchAlias);
            //            LoadPortal(BranchAlias);
            //            LoadInventoryPriceFlagRows(BranchAlias);
            //            #region  Check the Webordering Menu and Menu Creation  
            //            ChkTable = ObjMain.GetData_DT("Select  * from " + BranchAlias + ".menu;");

            //            if (ChkTable.Rows.Count > 0)
            //            {
            //                lblIsWeborderingMenuCreated.Text = "Webordering Menu Already Created! ";

            //                lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Green;
            //            }
            //            else
            //            {
            //                lblIsWeborderingMenuCreated.Text = "Webordering Menu is Empty ! ";
            //                lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Red;
            //            }
            //            #endregion

            //        }
            //        else
            //        {
            //            Response.Redirect("DeniedPage.aspx");
            //        }

            //    }
            //    else
            //    {

            //        // Assign s3 realted Parameter values 
            //        // clientname.Value = Session["CM_ID"].ToString();
            //        lblclientname.Text = Session["CM_ID"].ToString();
            //        lblstorename.Text = Cmb_BranchName;
            //        LoadFomo(Cmb_BranchName);
            //        LoadSms(Cmb_BranchName);
            //        LoadProductIni(Cmb_BranchName);
            //        LoadIndexIni(Cmb_BranchName);
            //        LoadViewCart(Cmb_BranchName);
            //        LoadVTakeawayCharge(Cmb_BranchName);
            //        LoadVTakeawayChargeOnly(Cmb_BranchName);
            //        LoadLandingImage(Cmb_BranchName);
            //        LoadCompanyLogo(Cmb_BranchName);
            //        LoadICRMCompanyBG(ActiveCallvalue);  // Karthik added on 20-Nov-2025
            //        LoadAdvertisementImage(Cmb_BranchName);  //john added on 31-July-2024
            //        LoadICRMCompanyLogo(Cmb_BranchName);
            //        LoadPost(Cmb_BranchName);
            //        LoadICRM(Cmb_BranchName);
            //        LoadCRM(Cmb_BranchName);
            //        LoadPortal(Cmb_BranchName);
            //        LoadInventoryPriceFlagRows(Cmb_BranchName);
            //        #region  Check the Webordering Menu and Menu Creation  
            //        ChkTable = ObjMain.GetData_DT("Select  * from " + Cmb_BranchName + ".menu;");

            //        if (ChkTable.Rows.Count > 0)
            //        {
            //            lblIsWeborderingMenuCreated.Text = "Webordering Menu Already Created! ";

            //            lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Green;
            //        }
            //        else
            //        {
            //            lblIsWeborderingMenuCreated.Text = "Webordering Menu is Empty ! ";
            //            lblIsWeborderingMenuCreated.ForeColor = System.Drawing.Color.Red;
            //        }
            //        #endregion



            //    }



            //}
            //UPDATEBRANCH(Cmb_BranchName);



        }

        private void LoadIndexIni(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from {0}.WebOrderingIniSetting where Page = 'Index' and id<>2 and id<>71;";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdIniIndex.DataSource = DT;
            grdIniIndex.DataBind();

            //Dt2 = ObjMain.GetData_DT(query);
            //grdCategoryCustom.DataSource = Dt2;
            //grdCategoryCustom.DataBind();
        }

        private void LoadProductIni(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from {0}.WebOrderingIniSetting where Page = 'Product' and id<>'66'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdIniSettings.DataSource = DT;
            grdIniSettings.DataBind();

            //Dt2 = ObjMain.GetData_DT(query);
            //grdCategoryCustom.DataSource = Dt2;
            //grdCategoryCustom.DataBind();
        }

        private void LoadViewCart(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from {0}.WebOrderingIniSetting where Page = 'ViewCart'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdViewCart.DataSource = DT;
            grdViewCart.DataBind();

            //Dt2 = ObjMain.GetData_DT(query);
            //grdCategoryCustom.DataSource = Dt2;
            //grdCategoryCustom.DataBind();
        }

        private void LoadPost(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from {0}.WebOrderingIniSetting where Page = 'Post'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdPost.DataSource = DT;
            grdPost.DataBind();

            //Dt2 = ObjMain.GetData_DT(query);
            //grdCategoryCustom.DataSource = Dt2;
            //grdCategoryCustom.DataBind();
        }

        private void LoadICRM(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from {0}.WebOrderingIniSetting where Page = 'ICRM'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdICRM.DataSource = DT;
            grdICRM.DataBind();

            //Dt2 = ObjMain.GetData_DT(query);
            //grdCategoryCustom.DataSource = Dt2;
            //grdCategoryCustom.DataBind();
        }

        private void LoadCRM(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from {0}.WebOrderingIniSetting where Page = 'CRM'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdCRM.DataSource = DT;
            grdCRM.DataBind();

            //Dt2 = ObjMain.GetData_DT(query);
            //grdCategoryCustom.DataSource = Dt2;
            //grdCategoryCustom.DataBind();
        }

        private void LoadVTakeawayCharge(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select *  from {0}.webtakeawaycharge ;";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdTakeAwaysetting.DataSource = DT;
            grdTakeAwaysetting.DataBind();
        }

        private void LoadVTakeawayChargeOnly(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select *  from {0}.webtakeawaychargeOnly ;";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdTakeAwaysettingonly.DataSource = DT;
            grdTakeAwaysettingonly.DataBind();
        }

        private void LoadCharge(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from {0}.WebOrderingIniSetting where Page = 'Charge'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdCharge.DataSource = DT;
            grdCharge.DataBind();
        }

        private void LoadEmail(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from  {0}.WebOrderingIniSetting where Page = 'Email' and id<>13";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdEmailSetting.DataSource = DT;
            grdEmailSetting.DataBind();
        }

        private void LoadSms(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from  {0}.WebOrderingIniSetting where Page = 'SMS'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdSMSSetting.DataSource = DT;
            grdSMSSetting.DataBind();
        }

        private void LoadFomo(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from  {0}.WebOrderingIniSetting where Page = 'FOMO'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdFomoSetting.DataSource = DT;
            grdFomoSetting.DataBind();
        }

        private void LoadPortal(string sDB)
        {
            DataTable DT = new DataTable();
            string sCmd = "Select ID,IniName,IniValue from  {0}.WebOrderingIniSetting where Page = 'Portal'";
            string command = string.Format(sCmd, sDB);
            DT = ObjMain.GetData_DT(command);
            grdweb.DataSource = DT;
            grdweb.DataBind();
        }
        public void LoadInventoryPriceFlagRows(string sDB)
        {
            string _inventoryrows = string.Empty;
            string _priceflagrows = string.Empty;
            string Inven_sCmd = "Select count(*) as InventoryRows from {0}.Inventory; ";
            string Invent_command = string.Format(Inven_sCmd, sDB);
            _inventoryrows = ObjMain.ExecuteScalar(Invent_command);
            //Assign value to lable
            lblInventoryrows.Text = _inventoryrows;

            string priceflag_sCmd = "Select count(*) as PriceflagRows from {0}.priceflag; ";
            string priceflag_command = string.Format(priceflag_sCmd, sDB);
            _priceflagrows = ObjMain.ExecuteScalar(priceflag_command);
            //Assign value to lable
            lblPriceflagrows.Text = _priceflagrows;

        }
        protected void grdIniSettings_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // Prevention SQL Injection   : 12-10-21
            // Prevention XSS 
            // Parameterized Approach 
            if (e.CommandName == "UpdateProduct")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdIniSettings.Rows[index];
                string sIniID = (row.FindControl("ID") as Label).Text;
                string sIniValue = (row.FindControl("txtProductIniValue") as TextBox).Text;
                //string color = (row.FindControl("colorpicker") as Label).Text;
                DropDownList ddlOption = (row.FindControl("cmbShow") as DropDownList);

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )

                    if (sIniID.ToString() == "1" || sIniID.ToString() == "4" || sIniID.ToString() == "23" || sIniID.ToString() == "37" || sIniID.ToString() == "41" || sIniID.ToString() == "44"
                        || sIniID.ToString() == "43" || sIniID.ToString() == "65" || sIniID.ToString() == "67" || sIniID.ToString() == "69" || sIniID.ToString() == "74" || sIniID.ToString() == "75"
                        || sIniID.ToString() == "81" || sIniID.ToString() == "83")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id =@id ;";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",ddlOption.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateSetting = ObjMain.ExecuteQuery(command, parameters);
                        if (iUpdateSetting > 0)
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Product Page Layout Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                        }


                    }
                    else if (sIniID.ToString() == "76" || sIniID.ToString() == "77" || sIniID.ToString() == "78" || sIniID.ToString() == "79")
                    {


                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id =@id ;";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateSetting = ObjMain.ExecuteQuery(command, parameters);
                        if (iUpdateSetting > 0)
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Product Page Layout Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                        }


                    }
                    else if (sIniID.ToString() == "80")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id =@id ;";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateSetting = ObjMain.ExecuteQuery(command, parameters);
                        if (iUpdateSetting > 0)
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Product Page Layout Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                        }
                    }




                }
            }

        }

        protected void grdIniIndex_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // Prevention SQL Injection   : 12-10-21
            // Prevention XSS 
            // Parameterized Approach 
            if (e.CommandName == "UpdateIndex")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdIniIndex.Rows[index];
                string sIniID = (row.FindControl("IDIndex") as Label).Text;
                // DropDownList ddlOption = (row.FindControl("cmbShow") as DropDownList);
                //Label sIniID = (row.FindControl("IDIndex") as Label);
                DropDownList cmbindexval = (row.FindControl("cmbindexini") as DropDownList);
                string sIniValue = (row.FindControl("txtIniValue") as TextBox).Text;

                if (cmbBranches.SelectedIndex != 0)
                {
                    if (sIniID.ToString() == "2" || sIniID.ToString() == "66")
                    {
                        BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@IniValue",sIniValue),
                            new MySqlParameter("@id",sIniID),
                         };

                        iUpdateIndexSetting = ObjMain.ExecuteQuery(command, parameters);

                    }
                    else if (sIniID.ToString() == "17") //john added on 03-Dec-2021 to Enable/Disable Promo Item Based on Top Sale
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@Inivalue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@IniValue", sIniValue),
                            new MySqlParameter("@id", sIniID),
                        };
                        iUpdateIndexSetting = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "52") //Karthik added on 03-Dec-2021 to Enable/Disable Menugroup : Menu Item Based on Top Sale
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@Inivalue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@IniValue", cmbindexval.SelectedIndex),
                            new MySqlParameter("@id", sIniID),
                        };
                        iUpdateIndexSetting = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "63") // Karthik added on 04-May-2024  0 - Operative Hours &&  1 - ShiftSchedule 
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@Inivalue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@IniValue", cmbindexval.SelectedIndex),
                            new MySqlParameter("@id", sIniID),
                        };
                        iUpdateIndexSetting = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "64") // Karthik added on 04-May-2024  0 - ShiftHours On same Day &&  1 - ShiftHours On Different Day(Falls on next Day)
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@Inivalue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@IniValue", cmbindexval.SelectedIndex),
                            new MySqlParameter("@id", sIniID),
                        };
                        iUpdateIndexSetting = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "71") // Karthik added on 22-Nov-2024  for ICRM CompanyLogo 
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@Inivalue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@IniValue", cmbindexval.SelectedIndex),
                            new MySqlParameter("@id", sIniID),
                        };
                        iUpdateIndexSetting = ObjMain.ExecuteQuery(command, parameters);
                    }





                    if (iUpdateIndexSetting > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Index Page Layout Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong on index !'); ", true);
                    }
                }
            }

        }

        protected void grdViewCart_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UpdateViewCartPromoCount")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdViewCart.Rows[index];
                string sIniID = (row.FindControl("lblViewCartPromoID") as Label).Text;
                DropDownList cmbViewCart = (row.FindControl("cmbViewCart") as DropDownList);
                //Label sIniID = (row.FindControl("IDIndex") as Label);
                string sIniValue = (row.FindControl("txtViewCartShowCount") as TextBox).Text;

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    if (sIniID.ToString() == "3") //ViewCart Promo Show Item Count
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "5") //ViewCart Enable Special Notes
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue = @IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);

                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "6") //Enable Promotion
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);

                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "7") //Promo Order By
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "8") //Promo Caption 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }


                    else if (sIniID.ToString() == "18") // Update the WebOrderId's Reset  Value in iniSetting Table 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }



                    else if (sIniID.ToString() == "38") // Update 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }


                    else if (sIniID.ToString() == "39") // Update 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "40") // Update 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "42") // Update 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "45") // Update 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "46") // Update 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "47") // Update 
                    {

                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "70") //Enable OnetimePromocode
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id";
                        string command = string.Format(sCmd, Cmb_BranchName);

                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbViewCart.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iUpdateViewCart = ObjMain.ExecuteQuery(command, parameters);
                    }

                    if (iUpdateViewCart > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' ViewCart Page Layout Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }
                }
            }
        }

        protected void grdTakeAwaysetting_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "UpdateTakaAway")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdTakeAwaysetting.Rows[index];
                string sIniID = (row.FindControl("lblTakwayID") as Label).Text;
                DropDownList cmbTakeAway = (row.FindControl("cmbTakeAway") as DropDownList);
                //Label sIniID = (row.FindControl("IDIndex") as Label);
                string sTakeawaycaption = (row.FindControl("TxtTakeAwayCaption") as TextBox).Text;
                string sTxtValue = (row.FindControl("txtValue") as TextBox).Text;
                string sTaxflag = (row.FindControl("TxtTaxFlag") as TextBox).Text;


                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    if (sIniID.ToString() == "1") // WebTakeAwayCharge
                    {
                        string sCmd = "Update {0}.webtakeawaycharge set TakeAwayCaption=@TakeAwayCaption,Value=@Value,TaxFlag=@TaxFlag,IsEnable=@IsEnable  where ID=@ID; ";
                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@ID",sIniID),
                         new MySqlParameter("@TakeAwayCaption",sTakeawaycaption),
                         new MySqlParameter("@Value",sTxtValue),
                         new MySqlParameter("@TaxFlag",sTaxflag),
                         new MySqlParameter("@IsEnable",cmbTakeAway.SelectedIndex),

                        };

                        iUpdateTakeaway = ObjMain.ExecuteQuery(command, parameters);
                    }

                    if (iUpdateTakeaway > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Takeaway charge Setting Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }


                }

            }

        }

        protected void grdTakeAwaysettingonly_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "UpdateTakaAway")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdTakeAwaysettingonly.Rows[index];
                string sIniID = (row.FindControl("lblTakwayID") as Label).Text;
                DropDownList cmbTakeAway = (row.FindControl("cmbTakeAway") as DropDownList);
                //Label sIniID = (row.FindControl("IDIndex") as Label);
                string sTakeawaycaption = (row.FindControl("TxtTakeAwayCaption") as TextBox).Text;
                string sTxtValue = (row.FindControl("txtValue") as TextBox).Text;
                string sTaxflag = (row.FindControl("TxtTaxFlag") as TextBox).Text;


                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )

                    string sCmd = "Update {0}.webtakeawaychargeonly set TakeAwayCaption=@TakeAwayCaption,Value=@Value,TaxFlag=@TaxFlag,IsEnable=@IsEnable  where ID=@ID; ";
                    string command = string.Format(sCmd, Cmb_BranchName);

                    if (sIniID == "1")
                    {
                        MySqlParameter[] parameters =
                           {
                         new MySqlParameter("@ID",sIniID),
                         new MySqlParameter("@TakeAwayCaption",sTakeawaycaption),
                         new MySqlParameter("@Value","0.000"),
                         new MySqlParameter("@TaxFlag","0"),
                         new MySqlParameter("@IsEnable",cmbTakeAway.SelectedIndex),

                        };

                        iUpdateTakeaway = ObjMain.ExecuteQuery(command, parameters);

                    }
                    else
                    {
                        MySqlParameter[] parameters =
                               {
                         new MySqlParameter("@ID",sIniID),
                         new MySqlParameter("@TakeAwayCaption",sTakeawaycaption),
                         new MySqlParameter("@Value",sTxtValue),
                         new MySqlParameter("@TaxFlag",sTaxflag),
                         new MySqlParameter("@IsEnable",cmbTakeAway.SelectedIndex),

                        };

                        iUpdateTakeaway = ObjMain.ExecuteQuery(command, parameters);

                    }








                    if (iUpdateTakeaway > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Takeaway charge Setting Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }


                }

            }



        }

        protected void Insert(object sender, EventArgs e)
        {

            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )

            string sCmd = "Insert into {0}.webtakeawaychargeonly(TakeAwayCaption,Value,TaxFlag,IsEnable)values(@TakeAwayCaption,@Value,@TaxFlag,@IsEnable);";
            string command = string.Format(sCmd, Cmb_BranchName);
            int z = 0;

            MySqlParameter[] parameters =
            {

                new MySqlParameter("@TakeAwayCaption",txtnTakeawaycaption.Text),
                new MySqlParameter("@Value",txtnvalue.Text),
                new MySqlParameter("@TaxFlag",txtntaxflag.Text),
                new MySqlParameter("@IsEnable","0"),
            };

            z = ObjMain.ExecuteQuery(command, parameters);


            if (z > 0)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Takeaway charge Item added  Successfully');location.href='LayoutSetting.aspx'", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
            }



        }

        protected void grdCharge_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion





            if (e.CommandName == "UpdateChargeIniValue")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdCharge.Rows[index];
                string lblID = (row.FindControl("lblChargeID") as Label).Text;
                DropDownList cmbCharge = (row.FindControl("cmbCharge") as DropDownList);
                string lblValue = (row.FindControl("txtChargeIniValue") as TextBox).Text;
                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);

                    if (lblID.ToString().Trim() == "9" || lblID.ToString().Trim() == "12" || lblID.ToString().Trim() == "22")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",lblValue),
                         new MySqlParameter("@id",lblID.ToString().Trim()),
                        };

                        iUpdateCharge = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (lblID.ToString().Trim() == "10" || lblID.ToString().Trim() == "11")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue = @IniValue where id = @id ";
                        string command = string.Format(sCmd, BranchAlias);


                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbCharge.SelectedIndex),
                         new MySqlParameter("@id",lblID.ToString().Trim()),
                        };


                        iUpdateCharge = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (lblID.ToString().Trim() == "16")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue = @Inivalue where id = @id";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@IniValue",cmbCharge.SelectedIndex),
                            new MySqlParameter("@id",lblID.ToString().Trim()),
                        };
                        iUpdateCharge = ObjMain.ExecuteQuery(command, parameters);

                    }
                }

                if (iUpdateCharge > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Charge Page Layout Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong!'); ", true);
                }

            }
        }

        protected void grdEmailSetting_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // Prevention SQL Injection : 12-10-21
            // Prevention XSS 
            // Parameterized Appraoch 



            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion


            if (e.CommandName == "UpdateEmailSettingIniValue")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdEmailSetting.Rows[index];
                string lblID = (row.FindControl("lblEmailSettingID") as Label).Text;
                string txtValue = (row.FindControl("lblEmailSettingValue") as TextBox).Text;
                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                    if (lblID.ToString() == "14")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue = @IniValue where id =14";

                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",txtValue.ToString()),

                        };
                        iUpdateEmail = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (lblID.ToString() == "15")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id = 15";

                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",txtValue.ToString()),

                        };
                        iUpdateEmail = ObjMain.ExecuteQuery(command, parameters);
                    }
                }

                if (iUpdateEmail > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Email Setting Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                }
            }
        }

        protected void grdSMSSetting_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion

            if (e.CommandName == "UpdateSMSSettingIniValue")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdSMSSetting.Rows[index];
                string lblID = (row.FindControl("lblSMSSettingID") as Label).Text;
                string txtValue = (row.FindControl("lblSMSSettingValue") as TextBox).Text;
                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);

                    // CallerId Value 
                    if (lblID.ToString() == "30")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue = @IniValue where id =30";
                        string command = string.Format(sCmd, BranchAlias);
                        try
                        {

                            MySqlParameter[] parameters =
                            {
                         new MySqlParameter("@IniValue",txtValue.ToString()),

                        };
                            iUpdateEmail = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;

                        }

                    }
                    // UserName 
                    else if (lblID.ToString() == "31")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id = 31";
                        string command = string.Format(sCmd, BranchAlias);

                        try
                        {

                            MySqlParameter[] parameters =
                            {
                            new MySqlParameter("@IniValue",txtValue.ToString()),
                            };
                            iUpdateEmail = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;

                        }


                    }
                    // Password 
                    else if (lblID.ToString() == "32")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id = 32";
                        string command = string.Format(sCmd, BranchAlias);

                        try
                        {
                            MySqlParameter[] parameters =
                           {
                           new MySqlParameter("@IniValue",txtValue.ToString()),
                           };
                            iUpdateEmail = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;

                        }

                    }
                    // Message Contend 
                    else if (lblID.ToString() == "33")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id = 33";
                        string command = string.Format(sCmd, BranchAlias);

                        try
                        {
                            MySqlParameter[] parameters =
                            {
                            new MySqlParameter("@IniValue",txtValue.ToString()),
                           };
                            iUpdateEmail = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;
                        }


                    }




                }

                if (iUpdateEmail > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Sms Setting Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                }
            }



        }

        protected void grdFomoSetting_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion


            if (e.CommandName == "UpdateFomoSettingIniValue")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdFomoSetting.Rows[index];
                string lblID = (row.FindControl("lblFomoSettingID") as Label).Text;
                string txtValue = (row.FindControl("lblFomoSettingValue") as TextBox).Text;
                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);

                    // Company Name Value 
                    if (lblID.ToString() == "34")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue = @IniValue where id =34";
                        string command = string.Format(sCmd, BranchAlias);
                        try
                        {

                            MySqlParameter[] parameters =
                            {
                            new MySqlParameter("@IniValue",txtValue.ToString()),

                            };
                            ifomo = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;

                        }

                    }
                    // Fomo - MID Value
                    else if (lblID.ToString() == "35")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id = 35";
                        string command = string.Format(sCmd, BranchAlias);

                        try
                        {

                            MySqlParameter[] parameters =
                            {
                            new MySqlParameter("@IniValue",txtValue.ToString()),
                            };
                            ifomo = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;

                        }


                    }
                    // Fomo - PSK 
                    else if (lblID.ToString() == "36")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id = 36";
                        string command = string.Format(sCmd, BranchAlias);

                        try
                        {
                            MySqlParameter[] parameters =
                           {
                           new MySqlParameter("@IniValue",txtValue.ToString()),
                           };
                            ifomo = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;

                        }

                    }


                    else if (lblID.ToString() == "51")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue =@IniValue where id = 51";
                        string command = string.Format(sCmd, BranchAlias);

                        try
                        {
                            MySqlParameter[] parameters =
                           {
                           new MySqlParameter("@IniValue",txtValue.ToString()),
                           };
                            ifomo = ObjMain.ExecuteQuery(command, parameters);

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            sCmd = string.Empty;
                            command = string.Empty;

                        }

                    }


                }

                if (ifomo > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Fomo Setting Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                }
            }




        }


        //protected void grdCharge_RowCommand(object sender, GridViewC)
        //{
        //}

        protected void grdIniSettings_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("ID") as Label);
                Label lblFunctionName = (e.Row.FindControl("lblFunctionName") as Label);
                DropDownList ddlOption = (e.Row.FindControl("cmbShow") as DropDownList);
                TextBox sIniValue = (e.Row.FindControl("txtProductIniValue") as TextBox);
                //Label colorpicker = (e.Row.FindControl("colorpicker") as Label);
                //string color = (e.Row.FindControl("colorpicker") as Label);
                if (sIniID.Text == "1") //Product Show
                {

                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Name and Desc");
                    ddlOption.Items.Add("Name");
                    ddlOption.Items.Add("Description");
                    ddlOption.DataBind();
                }
                else if (sIniID.Text == "4") // Product Show Special Remarks
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                    ddlOption.DataBind();
                }
                else if (sIniID.Text == "23")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "37")
                {
                    sIniValue.Visible = false;
                    //ddlOption.Items.Add("Disable");
                    //ddlOption.Items.Add("Enable");                
                    ddlOption.Items.Add("Name");
                    ddlOption.Items.Add("Description");
                    ddlOption.Items.Add("Name and Desc");
                    ddlOption.DataBind();
                }
                else if (sIniID.Text == "41")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Enable");
                    ddlOption.Items.Add("Disable");
                }
                else if (sIniID.Text == "44")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Enable");
                    ddlOption.Items.Add("Disable");

                }

                else if (sIniID.Text == "43")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "65")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "67")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "69")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "74")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "75")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "76")
                {

                    ddlOption.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "77")
                {

                    ddlOption.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "78")
                {

                    ddlOption.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "79")
                {

                    ddlOption.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "80")
                {

                    ddlOption.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "81")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }
                else if (sIniID.Text == "83")
                {
                    sIniValue.Visible = false;
                    ddlOption.Items.Add("Disable");
                    ddlOption.Items.Add("Enable");
                }


                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion




                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    RetVal = ObjSel.GetIniSettingValue(Cmb_BranchName, sIniID.Text);
                    //ddlOption.Items.FindByValue(RetVal).Selected = true;



                    if (sIniID.Text == "76" || sIniID.Text == "77" || sIniID.Text == "78" || sIniID.Text == "79" || sIniID.Text == "80")
                    {
                        //txtValue.Visible = false;
                        ddlOption.Visible = false;
                        sIniValue.Enabled = true;
                        if (sIniID.Text == "76" || sIniID.Text == "77" || sIniID.Text == "78" || sIniID.Text == "79")
                        {
                            //colorpicker.Visible = true;
                        }

                    }
                    else if (sIniID.Text == "1" || sIniID.Text == "4" || sIniID.Text == "23" || sIniID.Text == "41" || sIniID.Text == "44" || sIniID.Text == "43" || sIniID.Text == "65" || sIniID.Text == "67" || sIniID.Text == "69" || sIniID.Text == "74" || sIniID.Text == "75" || sIniID.Text == "81" || sIniID.Text == "83")
                    {
                        sIniValue.Visible = false;
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text.Trim());
                        ddlOption.SelectedIndex = int.Parse(RetVal);

                    }
                    else if (sIniID.Text == "37")
                    {
                        sIniValue.Visible = false;
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text.Trim());
                        ddlOption.SelectedIndex = int.Parse(RetVal);

                    }



                }

            }


        }

        protected void grdIniIndex_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion

            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("IDIndex") as Label);
                //DropDownList ddlOption = (e.Row.FindControl("cmbShow") as DropDownList);
                TextBox sIniValue = (e.Row.FindControl("txtIniValue") as TextBox);

                Label lblIndexini = (e.Row.FindControl("lblIniName") as Label);
                DropDownList cmbindexs = (e.Row.FindControl("cmbindexini") as DropDownList);



                if (sIniID.Text == "52" || sIniID.Text == "63" || sIniID.Text == "64") // Menugroup : Menu 
                {
                    cmbindexs.Items.Add("Disable");
                    cmbindexs.Items.Add("Enable");
                    cmbindexs.DataBind();
                    sIniValue.Visible = false;
                }



                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )


                    if (sIniID.Text == "2" || sIniID.Text == "17" || sIniID.Text == "71")
                    {

                        sIniValue.Enabled = true;
                        cmbindexs.Visible = false;


                    }

                    if (sIniID.Text == "52")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        //sIniValue.Text = RetVal;
                        cmbindexs.SelectedIndex = int.Parse(RetVal);
                    }
                    else if (sIniID.Text == "63")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        //sIniValue.Text = RetVal;
                        cmbindexs.SelectedIndex = int.Parse(RetVal);
                    }
                    else if (sIniID.Text == "64")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        //sIniValue.Text = RetVal;
                        cmbindexs.SelectedIndex = int.Parse(RetVal);
                    }



                }
            }
        }

        protected void grdViewCart_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("lblViewCartPromoID") as Label);
                //DropDownList ddlOption = (e.Row.FindControl("cmbShow") as DropDownList);
                TextBox sIniValue = (e.Row.FindControl("txtViewCartShowCount") as TextBox);
                CheckBox chkAll = (e.Row.FindControl("chkAll") as CheckBox);
                Label lblViewCartName = (e.Row.FindControl("lblViewCartName") as Label);
                DropDownList cmbViewCart = (e.Row.FindControl("cmbViewCart") as DropDownList);

                if (sIniID.Text == "3") //Promo Show Item Count
                {
                    cmbViewCart.Visible = false;
                }

                if (sIniID.Text == "5") //ViewCart Enable Special Notes
                {
                    cmbViewCart.Items.Add("Disable");
                    cmbViewCart.Items.Add("Enable");
                    cmbViewCart.DataBind();

                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }

                if (sIniID.Text == "6") //Enable Promo
                {
                    cmbViewCart.Items.Add("Disable");
                    cmbViewCart.Items.Add("Enable");
                    cmbViewCart.DataBind();
                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }

                if (sIniID.Text == "7") //Promo Order by
                {
                    cmbViewCart.Items.Add("Top Selling");
                    cmbViewCart.Items.Add("Main and Sub Postion");
                    cmbViewCart.DataBind();
                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }

                if (sIniID.Text == "8") //Promo Order by
                {

                    sIniValue.Enabled = true;
                    cmbViewCart.Visible = false;
                    chkAll.Visible = false;

                }

                if (sIniID.Text == "18") //WebOrderId Reset Value : PayAt Counter 
                {

                    sIniValue.Enabled = true;
                    cmbViewCart.Visible = false;
                    chkAll.Visible = false;

                }

                if (sIniID.Text == "38") // Enable , Disable Discount 
                {
                    cmbViewCart.Items.Add("Disable");
                    cmbViewCart.Items.Add("Enable");
                    cmbViewCart.DataBind();

                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }

                if (sIniID.Text == "39") // Enable , Disable Tax in Webordering 
                {
                    cmbViewCart.Items.Add("Disable");
                    cmbViewCart.Items.Add("Enable");
                    cmbViewCart.DataBind();

                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }

                if (sIniID.Text == "40") // Enable , Disable Email Validation
                {
                    cmbViewCart.Items.Add("Disable");
                    cmbViewCart.Items.Add("Enable");
                    cmbViewCart.DataBind();

                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }
                if (sIniID.Text == "42") // Is TakeAway Only validation 
                {
                    cmbViewCart.Items.Add("Disable");
                    cmbViewCart.Items.Add("Enable");
                    cmbViewCart.DataBind();

                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }

                if (sIniID.Text == "70") // Enable OnetimePromocode
                {
                    cmbViewCart.Items.Add("Disable");
                    cmbViewCart.Items.Add("Enable");
                    cmbViewCart.DataBind();

                    sIniValue.Visible = false;
                    chkAll.Visible = false;
                }


                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion


                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )

                    if (sIniID.Text == "3" || sIniID.Text == "5" || sIniID.Text == "6" || sIniID.Text == "4" || sIniID.Text == "38" || sIniID.Text == "39" || sIniID.Text == "40" || sIniID.Text == "42" || sIniID.Text == "45" || sIniID.Text == "46" || sIniID.Text == "47" || sIniID.Text == "70")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        //sIniValue.Text = RetVal;
                        cmbViewCart.SelectedIndex = int.Parse(RetVal);
                    }
                    if (sIniValue.Text == "0")
                    {
                        chkAll.Checked = true;
                        sIniValue.Enabled = false;
                    }
                    else
                    {
                        chkAll.Checked = false;
                    }

                    if (sIniID.Text == "8")  //Promo Caption
                    {

                        sIniValue.Enabled = true;
                        cmbViewCart.Visible = false;
                        chkAll.Visible = false;

                    }



                }

                //CheckBox chkAll = (CheckBox)e.Row.FindControl("chkAll");
                //TextBox txtViewCartShowCount = (TextBox)e.Row.FindControl("txtViewCartShowCount");

                //if (chkAll.Checked == false)
                //{
                //    txtViewCartShowCount.Enabled = false;
                //   // txtTotime.Enabled = false;
                //}
            }
        }



        // Rowcommand For TakeAway Charge 
        protected void grdTakeAwaysetting_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("lblTakwayID") as Label);
                //DropDownList ddlOption = (e.Row.FindControl("cmbShow") as DropDownList);
                TextBox stakeawayText = (e.Row.FindControl("TxtTakeAwayCaption") as TextBox);
                TextBox sIniValue = (e.Row.FindControl("txtValue") as TextBox);
                TextBox sTaxflag = (e.Row.FindControl("TxtTaxFlag") as TextBox);
                TextBox sIsEnable = (e.Row.FindControl("txtIsEnable") as TextBox);
                DropDownList cmbTakeAway = (e.Row.FindControl("cmbTakeAway") as DropDownList);

                if (sIniID.Text == "1")
                {
                    cmbTakeAway.Items.Add("Disable");
                    cmbTakeAway.Items.Add("Enable");
                    cmbTakeAway.DataBind();
                    sIniValue.Visible = true;
                }

                if (cmbBranches.SelectedIndex != 0)
                {
                    cmbTakeAway.SelectedIndex = int.Parse(sIsEnable.Text);
                }



            }

        }

        protected void grdTakeAwaysettingonly_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("lblTakwayID") as Label);
                TextBox stakeawayText = (e.Row.FindControl("TxtTakeAwayCaption") as TextBox);
                TextBox sIniValue = (e.Row.FindControl("txtValue") as TextBox);
                TextBox sTaxflag = (e.Row.FindControl("TxtTaxFlag") as TextBox);
                TextBox sIsEnable = (e.Row.FindControl("txtIsEnable") as TextBox);
                DropDownList cmbTakeAway = (e.Row.FindControl("cmbTakeAway") as DropDownList);
                if (sIniID.Text == "1")
                {
                    cmbTakeAway.Items.Add("Disable");
                    cmbTakeAway.Items.Add("Enable");
                    cmbTakeAway.DataBind();
                    sIniValue.Visible = true;
                }
                if (cmbBranches.SelectedIndex != 0)
                {
                    cmbTakeAway.SelectedIndex = int.Parse(sIsEnable.Text);
                }

            }


        }


        protected void grdCharge_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion

            string sRetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblID = (e.Row.FindControl("lblChargeID") as Label);
                Label lblName = (e.Row.FindControl("lblChargeName") as Label);
                TextBox txtValue = (e.Row.FindControl("txtChargeIniValue") as TextBox);
                DropDownList cmbCharge = (e.Row.FindControl("cmbCharge") as DropDownList);

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                    if (lblID.Text == "9" || lblID.Text == "12" || lblID.Text == "22") //Queue Prefix
                    {
                        //txtValue.Visible = false;
                        cmbCharge.Visible = false;
                    }
                    else if (lblID.Text == "10" || lblID.Text == "11") //Queue Reset Everyday,Queue Enable
                    {
                        sRetVal = ObjSel.GetIniSettingValue(BranchAlias, lblID.Text.Trim());
                        cmbCharge.Items.Add("Disable");
                        cmbCharge.Items.Add("Enable");
                        cmbCharge.DataBind();
                        txtValue.Visible = false;
                        cmbCharge.SelectedIndex = int.Parse(sRetVal);
                    }
                    else if (lblID.Text == "16")
                    {
                        sRetVal = ObjSel.GetIniSettingValue(BranchAlias, lblID.Text.Trim());
                        cmbCharge.Items.Add("Queue No");
                        cmbCharge.Items.Add("Table No");
                        cmbCharge.DataBind();
                        txtValue.Visible = false;
                        cmbCharge.SelectedIndex = int.Parse(sRetVal);
                    }
                }
            }
        }

        protected void grdEmailSetting_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblID = (e.Row.FindControl("lblEmailSettingID") as Label);
                Label lblName = (e.Row.FindControl("lblEmailSettingName") as Label);
                TextBox txtValue = (e.Row.FindControl("lblEmailSettingValue") as TextBox);

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                    if (lblID.Text == "15")
                    {
                        string asteriskValue = new string('*', txtValue.Text.Length);
                        txtValue.Attributes["value"] = asteriskValue;
                        txtValue.TextMode = TextBoxMode.Password;
                    }
                }
            }
        }

        protected void grdSMSSetting_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblID = (e.Row.FindControl("lblSMSSettingID") as Label);
                Label lblName = (e.Row.FindControl("lblSMSSettingName") as Label);
                TextBox txtValue = (e.Row.FindControl("lblSMSSettingValue") as TextBox);

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                    if (lblID.Text == "32")
                    {
                        string asteriskValue = new string('*', txtValue.Text.Length);
                        txtValue.Attributes["value"] = asteriskValue;
                        txtValue.TextMode = TextBoxMode.Password;
                    }
                    if (lblID.Text == "30")
                    {
                        txtValue.MaxLength = 11;
                    }

                }
            }



        }

        protected void grdFomoSetting_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblID = (e.Row.FindControl("lblFomoSettingID") as Label);
                Label lblName = (e.Row.FindControl("lblFomoSettingName") as Label);
                TextBox txtValue = (e.Row.FindControl("lblFomoSettingValue") as TextBox);

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                    if (lblID.Text == "35")
                    {
                        string asteriskValue = new string('*', txtValue.Text.Length);
                        txtValue.Attributes["value"] = asteriskValue;
                        txtValue.TextMode = TextBoxMode.Password;
                    }

                    if (lblID.Text == "36")
                    {
                        string asteriskValue = new string('*', txtValue.Text.Length);
                        txtValue.Attributes["value"] = asteriskValue;
                        txtValue.TextMode = TextBoxMode.Password;
                    }

                    if (lblID.Text == "51")
                    {
                        string asteriskValue = new string('*', txtValue.Text.Length);
                        txtValue.Attributes["value"] = asteriskValue;
                        txtValue.TextMode = TextBoxMode.Password;
                    }
                }
            }




        }


        protected void chkAll_Changed(object sender, EventArgs e)
        {
            foreach (GridViewRow gvrow in grdViewCart.Rows)
            {
                Label lblID = (gvrow.Cells[0].FindControl("lblViewCartPromoID") as Label);
                TextBox txtViewCartShowCount = (gvrow.Cells[2].FindControl("txtViewCartShowCount") as TextBox);
                CheckBox chkRow = (gvrow.Cells[2].FindControl("chkAll") as CheckBox);

                if (lblID.Text == "3") //John added on 19-Aug-2021 ini ID 3 only is allowed.
                {
                    if (chkRow.Checked)
                    {
                        //if checked do something
                        txtViewCartShowCount.Text = "0";
                        txtViewCartShowCount.Enabled = false;

                    }
                    else
                    {
                        txtViewCartShowCount.Enabled = true;

                    }
                }
            }
        }


        protected void BtnSaveImage_Click(object sender, EventArgs e)
        {
            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion


            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )

            SaveImagedetailstoS3(BranchAlias, "LANDINGPAGE", 2, "Index");


        }

        protected void btnSaveImageLogo_Click(object sender, EventArgs e)
        {
            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion

            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            SaveImagedetailstoS3(BranchAlias, "COMPANYLOGO", 13, "Email");
        }

        protected void btnSaveImageAds_Click(object sender, EventArgs e)
        {
            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion

            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            SaveImagedetailstoS3(BranchAlias, "ADVERTISEMENTIMAGE", 66, "Product");
        }

        public void LoadLandingImage(string branchAlias)
        {
            

            string Qry_Image = "Select IniValue from {0}.WebOrderingIniSetting where Page = 'Index' and id=2; ";
            string command = string.Format(Qry_Image, BranchAlias);
            DTImageResult = ObjMain.GetData_DT(command);

            dtimg.DataSource = DTImageResult;
            dtimg.DataBind();


        }

        public void LoadCompanyLogo(string branchAlias)
        {
           

            string Qry_Image = "Select IniValue from {0}.WebOrderingIniSetting where Page = 'Email' and id=13;";
            string command = string.Format(Qry_Image, BranchAlias);
            DTLogo = ObjMain.GetData_DT(command);
            dtimglogo.DataSource = DTLogo;
            dtimglogo.DataBind();
        }

        public void LoadICRMCompanyLogo(string branchAlias)
        {

            string Qry_Image = "Select IniValue from {0}.WebOrderingIniSetting where Page = 'ICRM' and id=71;";
            string command = string.Format(Qry_Image, branchAlias);
            DTLogo = ObjMain.GetData_DT(command);
            dtICRmimglogo.DataSource = DTLogo;
            dtICRmimglogo.DataBind();
        }


        public void LoadICRMCompanyBG(string branchAlias)
        {

            string Qry_Image = "Select IniValue from {0}.WebOrderingIniSetting where Page = 'ICRM' and id=84;";
            string command = string.Format(Qry_Image, branchAlias);
            DTLogo = ObjMain.GetData_DT(command);
            dtICRmimgBg.DataSource = DTLogo;
            dtICRmimgBg.DataBind();
        }


        public void LoadAdvertisementImage(string branchAlias)  //john added on 31-July-2024
        {
            string query = "Select IniValue from {0}.WebOrderingIniSetting where Page = 'Product' and id=66;";
            string command = string.Format(query, branchAlias);
            DTLogo = ObjMain.GetData_DT(command);
            dtimgAdv.DataSource = DTLogo;
            dtimgAdv.DataBind();
        }


        public void SaveImagedetailstoS3(string branchalias, string module, int IniID, string PageValue) //John added module,ini and page ID parameter on 30-Sept-2021
        {

            // Get the Full S3Path 

            // var A = "https://suntoyo-aws-s3.s3.ap-southeast-1.amazonaws.com/49/da1/jpg/a01.jpg";


            if (hdnPath.Value != "")
            {

                var JsonResult = hdnPath.Value;
                Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(JsonResult);
                var V = myDeserializedClass.dbPath;
                hdnurl.Value = V;


                var Result = V.Split('/');

                string S3_http = Result[0];
                string S3_null = Result[1];
                string S3_S3link = Result[2];
                string S3_Companyname = Result[3];
                string S3_Brachname = Result[4];
                string S3_Extention = Result[5];
                string S3_FileName = Result[6];

                string FileName = S3_FileName.ToString().Trim();
                string BucketName = "suntoyo-aws-s3";
                string StoreName = S3_Brachname.ToString().Trim();
                string Url = V.ToString().Trim();
                string Extention = S3_Extention.ToString().Trim();
                int S3 = 0;
                int S3_LandingUPT = 0;

                string ChkIsExist = string.Empty;
                //string module = "LANDINGPAGE"; 'johh hide on 30-Sept-2021 

                // Prevention SQL Injection 
                string ChkIsExistQuery = " Select fileName from  {0}.filedetails where Module='{1}' ";
                string command = string.Format(ChkIsExistQuery, branchalias, module);
                ChkIsExist = ObjMain.ExecuteScalar(command);

                if (ChkIsExist != "")
                {
                    // Call Update 
                    string S3_Update = "UPDATE {0}.filedetails SET fileName=@fileName, BucketName=@BucketName,Url=@Url,Extention=@Extention ,ModifiedDate=@ModifiedDate where Module=@Module AND CompanyName=@CompanyName AND StoreName=@StoreName ; ";
                    string commandA = string.Format(S3_Update, branchalias);

                    MySqlParameter[] parametersA =
                     {
                     new MySqlParameter("@fileName",FileName),
                     new MySqlParameter("@BucketName",BucketName),
                     new MySqlParameter("@Url",Url),
                     new MySqlParameter("@Extention",Extention),
                     new MySqlParameter("@ModifiedDate",Curr_Date),
                     new MySqlParameter("@Module",module),
                     new MySqlParameter("@CompanyName",S3_Companyname),
                     new MySqlParameter("@StoreName",StoreName),
                     };
                    S3 = ObjMain.ExecuteQuery(commandA, parametersA);

                    // Getting FileId
                    string Query_Fileid = "select fileid from {0}.filedetails  where Module=@Module and companyname=@companyname and StoreName=@StoreName ;";
                    string commandB = string.Format(Query_Fileid, branchalias);
                    MySqlParameter[] parametersB =
                     {
                     new MySqlParameter("@Module",module),
                     new MySqlParameter("@CompanyName",S3_Companyname.ToString().Trim()),
                     new MySqlParameter("@StoreName",StoreName),
                    };


                    FileID = ObjMain.NewExecuteScalar(commandB, parametersB);

                    hdnfileid.Value = FileID;
                    //string UPT_LandingImage = "UPDATE " + branchalias + ".WebOrderingIniSetting SET iniValue='" + Url + "' where Page='Index' and id=2; ";
                    string UPT_LandingImage = "UPDATE {0}.WebOrderingIniSetting SET iniValue=@iniValue where Page=@Page and id=@id ;"; //john added on 30-Sept-2021 id pass by parameter
                    string commandC = string.Format(UPT_LandingImage, branchalias);

                    MySqlParameter[] parametersC =
                     {
                     new MySqlParameter("@iniValue",Url),
                     new MySqlParameter("@Page",PageValue),
                     new MySqlParameter("@id",IniID),
                    };
                    S3_LandingUPT = ObjMain.ExecuteQuery(commandC, parametersC);
                    LoadLandingImage(branchalias);
                    LoadCompanyLogo(branchalias); //john added on 30-Sept-2021
                    LoadAdvertisementImage(branchalias);    //john added on 31-July-2024
                    LoadICRMCompanyLogo(branchalias);  // Karthik added on 20-11-2024
                    LoadICRMCompanyBG(branchalias);  // Karthik added on 20-Nov-2025

                    if (S3_LandingUPT > 0)
                    {
                        //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' LandingPage Image  Updated Successfully '); ", true);
                        if (IniID == 2) //Landing Page
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' LandingPage Image  Updated Successfully '); ", true);
                        }
                        else if (IniID == 13) //Company Logo
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Company Logo  Updated Successfully ');window.location.href='" + Request.RawUrl + "';", true);
                        }
                        else if (IniID == 66) // advertisement image
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Advertisement Image  Updated Successfully ');window.location.href='" + Request.RawUrl + "';", true);
                        }

                        else if (IniID == 71)  //ICRM Company Logo
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('ICRM Company Logo  Added Successfully ');window.location.href='" + Request.RawUrl + "';", true);
                        }

                        else if (IniID == 84)  //ICRM Company Logo
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('ICRM Company Background Image  Added Successfully ');window.location.href='" + Request.RawUrl + "';", true);
                        }




                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }

                }
                else
                {
                    // Call Insert 

                    string S3_Insert = " INSERT INTO  {0}.filedetails(fileName,BucketName,CompanyName,StoreName, Url, Extention,Module)" +
                        "values(@fileName,@BucketName,@CompanyName ,@StoreName,@Url,@Extention,@Module)";
                    string commandD = string.Format(S3_Insert, branchalias);

                    MySqlParameter[] parametersD =
                    {
                     new MySqlParameter("@fileName",FileName),
                     new MySqlParameter("@BucketName",BucketName),
                     new MySqlParameter("@CompanyName",S3_Companyname),
                     new MySqlParameter("@StoreName",StoreName),
                     new MySqlParameter("@Url",Url),
                     new MySqlParameter("@Extention",Extention),
                     new MySqlParameter("@Module",module),
                     };

                    S3 = ObjMain.ExecuteQuery(commandD, parametersD);

                    string QueryE = "select fileid from {0}.filedetails  where Module=@Module and companyname=@companyname and StoreName=@StoreName ;";
                    string commandE = string.Format(QueryE, branchalias);

                    MySqlParameter[] parametersE =
                    {

                     new MySqlParameter("@Module",module),
                     new MySqlParameter("@CompanyName",S3_Companyname.ToString().Trim()),
                     new MySqlParameter("@StoreName",BucketName),
                     };
                    FileID = ObjMain.NewExecuteScalar(commandE, parametersE);
                    hdnfileid.Value = FileID;
                    //string UPT_LandingImage = "UPDATE " + branchalias + ".WebOrderingIniSetting SET iniValue='" + Url + "' where Page='Index' and id=2; ";
                    string UPT_LandingImage = "UPDATE {0}.WebOrderingIniSetting SET iniValue=@iniValue where Page=@Page and id=@id ;"; //john added on 30-Sept-2021 id pass by parameter
                    string commandF = string.Format(UPT_LandingImage, branchalias);


                    MySqlParameter[] parametersF =
                    {

                     new MySqlParameter("@iniValue",Url),
                     new MySqlParameter("@Page",PageValue),
                     new MySqlParameter("@id",IniID),
                     };

                    S3_LandingUPT = ObjMain.ExecuteQuery(commandF, parametersF);

                    LoadLandingImage(branchalias);
                    LoadCompanyLogo(branchalias); //john added on 30-Sept-2021
                    LoadAdvertisementImage(branchalias); //john added on 31-July-2024


                    if (S3_LandingUPT > 0)
                    {
                        if (IniID == 2) //Landing Page
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' LandingPage Image  Added Successfully '); ", true);
                        }
                        else if (IniID == 13)  //Company Logo
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Company Logo  Added Successfully ');window.location.href='" + Request.RawUrl + "';", true);
                        }

                        else if (IniID == 71)  //ICRM Company Logo
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('ICRM Company Logo  Added Successfully ');window.location.href='" + Request.RawUrl + "';", true);
                        }

                        else if (IniID == 84)  //ICRM Company Logo
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('ICRM Company Background Image  Added Successfully ');window.location.href='" + Request.RawUrl + "';", true);
                        }



                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }

                }


            }
            else
            {


            }




            //Response.Redirect("Layoutsetting.aspx"); //John added on 30-Sept-2021 refresh page


        }


        public class Root
        {
            public string dbPath { get; set; }
        }

        protected void grdPost_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "UpdatePost")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdPost.Rows[index];
                string sIniID = (row.FindControl("lblPostId") as Label).Text;
                DropDownList cmbpost = (row.FindControl("cmbPost") as DropDownList);

                string sIniValue = (row.FindControl("txtPostValue") as TextBox).Text;

                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;      // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion


                if (sIniID.ToString() == "48") // Update 
                {

                    string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ;";
                    string command = string.Format(sCmd, BranchAlias);
                    MySqlParameter[] parameters =
                    {
                         new MySqlParameter("@IniValue",cmbpost.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };
                    K = ObjMain.ExecuteQuery(command, parameters);

                    if (K > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Post Page Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }

                }



            }
        }

        protected void grdPost_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("lblPostId") as Label);
                TextBox sIniValue = (e.Row.FindControl("txtPostValue") as TextBox);
                Label lblViewCartName = (e.Row.FindControl("lblPostName") as Label);
                DropDownList cmbpost = (e.Row.FindControl("cmbPost") as DropDownList);


                if (sIniID.Text == "48") // IsUnderPostFunction
                {
                    cmbpost.Items.Add("Disable");
                    cmbpost.Items.Add("Enable");
                    cmbpost.DataBind();
                    sIniValue.Visible = false;

                }

                if (cmbBranches.SelectedIndex != 0)
                {
                    #region  Validation Between HQ Branch and Normal Branch 
                    BranchFullName = cmbBranches.SelectedItem.Text;      // This will Return Branch FullName 
                    if (BranchFullName == "HQ")
                    {
                        BranchAlias = Session["Branch_HQ"].ToString();
                    }
                    else
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                        BranchAlias = Cmb_BranchName;

                    }
                    #endregion
                    if (sIniID.Text == "48")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        cmbpost.SelectedIndex = int.Parse(RetVal);

                    }

                }

            }

        }

        protected void grdICRM_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("lblICRMId") as Label);
                TextBox sIniValue = (e.Row.FindControl("txtICRMValue") as TextBox);
                Label lblViewCartName = (e.Row.FindControl("lblICRMIniName") as Label);
                DropDownList icrmcmb = (e.Row.FindControl("cmbICRM") as DropDownList);


                if (sIniID.Text == "45")      // IsMembership
                {
                    icrmcmb.Items.Add("Disable");
                    icrmcmb.Items.Add("Enable");
                    icrmcmb.DataBind();
                    sIniValue.Visible = false;

                }
                else if (sIniID.Text == "46")  // IsCashBack
                {
                    icrmcmb.Items.Add("Disable");
                    icrmcmb.Items.Add("Enable");
                    icrmcmb.DataBind();
                    sIniValue.Visible = false;

                }
                else if (sIniID.Text == "47")  // IsPointRedemption
                {
                    icrmcmb.Items.Add("Disable");
                    icrmcmb.Items.Add("Enable");
                    icrmcmb.DataBind();
                    sIniValue.Visible = false;
                }
                else if (sIniID.Text == "49")  // IsPointRedemption
                {
                    DataTable Dt_Combo = new DataTable();
                    Dt_Combo = ObjSel.LoadIMembership(Session["Branch_HQ"].ToString());     // Load the IMembership List
                    icrmcmb.DataSource = Dt_Combo;
                    icrmcmb.DataTextField = "MembershipName";
                    icrmcmb.DataValueField = "Membershipid";
                    icrmcmb.DataBind();
                    sIniValue.Visible = false;

                }
                else if (sIniID.Text == "50")  // Points Rounding Settings
                {
                    icrmcmb.Items.Add("No Rounding");
                    icrmcmb.Items.Add("Round Up");
                    icrmcmb.Items.Add("Round Down");
                    icrmcmb.DataBind();
                    sIniValue.Visible = false;
                }

                else if (sIniID.Text == "55")  // Merchant Email Username
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "56")  // Merchant Email Password
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "57")  // Merchant  To Email Username
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }

                else if (sIniID.Text == "68")  // AES Key Value 
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }

                else if (sIniID.Text == "71")  // ICRM Company
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "72")  // Min Purchase
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "73")  // Max Redeem 
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }


                if (cmbBranches.SelectedIndex != 0)
                {
                    #region  Validation Between HQ Branch and Normal Branch 
                    BranchFullName = cmbBranches.SelectedItem.Text;      // This will Return Branch FullName 
                    if (BranchFullName == "HQ")
                    {
                        BranchAlias = Session["Branch_HQ"].ToString();
                    }
                    else
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                        BranchAlias = Cmb_BranchName;

                    }
                    #endregion
                    if (sIniID.Text == "45" || sIniID.Text == "46" || sIniID.Text == "47" || sIniID.Text == "50")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        icrmcmb.SelectedIndex = int.Parse(RetVal);

                    }
                    else if (sIniID.Text == "49")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        icrmcmb.SelectedValue = RetVal;

                    }


                }

            }



        }

        protected void grdICRM_RowCommand(object sender, GridViewCommandEventArgs e)
        {


            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion


            if (e.CommandName == "UpdateICRM")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdICRM.Rows[index];
                string sIniID = (row.FindControl("lblICRMId") as Label).Text;
                DropDownList cmbicrm = (row.FindControl("cmbICRM") as DropDownList);
                //Label sIniID = (row.FindControl("IDIndex") as Label);
                string sIniValue = (row.FindControl("txtICRMValue") as TextBox).Text;

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    if (sIniID.ToString() == "45")   // Icrm IsMembership
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbicrm.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "46")   // Icrm IsCashBack
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbicrm.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "47")   // Icrm IsPointRedemption
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbicrm.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "49")   // Icrm Select Default IMembership 
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbicrm.SelectedValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "50")   // Icrm Points Rounding Settings
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbicrm.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "55")   // Merchant Email-Username
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "56")   // Merchant Email-Password
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "57")   // icrm-Merchant To Email Username 
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }


                    else if (sIniID.ToString() == "68")   //   AES Value 
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "72")   //   Min Purchase
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "73")   //   Max Redeem
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }


                    Force_Update(BranchAlias);

                    if (iIcrmUpdate > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' ViewCart Page Layout Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }



                }
            }



        }

        /// <summary>
        /// This function used to do the force update when Cashback and Pointredemption validation at a time 
        /// </summary>
        /// <param name="db"></param>
        public void Force_Update(string db)
        {
            string scm1 = "select inivalue from {0}.weborderinginisetting where id=46;";
            string command1 = string.Format(scm1, db);
            string check1 = ObjMain.ExecuteScalar(command1);

            string scm2 = "select inivalue from {0}.weborderinginisetting where id=47;";
            string command2 = string.Format(scm2, db);
            string check2 = ObjMain.ExecuteScalar(command2);

            if (check1 == "1" && check2 == "1")
            {

                string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id =@id ;";
                string command = string.Format(sCmd, db);
                MySqlParameter[] parameters =
                {
                         new MySqlParameter("@IniValue","0"),
                         new MySqlParameter("@id","47"),
                        };
                K = ObjMain.ExecuteQuery(command, parameters);

                if (K > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Post Page Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                }

            }

        }

        #region Advacado Grid Funcations  Added Karthik 21-03-24

        protected void grdCRM_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion

            if (e.CommandName == "UpdateCRM")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdCRM.Rows[index];
                string sIniID = (row.FindControl("lblCRMId") as Label).Text;
                DropDownList cmbicrm = (row.FindControl("cmbCRM") as DropDownList);
                //Label sIniID = (row.FindControl("IDIndex") as Label);
                string sIniValue = (row.FindControl("txtCRMValue") as TextBox).Text;

                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    if (sIniID.ToString() == "19")   // OutletID
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "20")   // Min Purchase
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "21")   // Max Redeem
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "24")   // AdvocadoAPIKey
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "25")   // AdvocadoSecret
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "26")   // Advocado Membership CampaignID
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "27")   // AdvocadoTier1
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "28")   // icrm-Merchant To Email Username 
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "29")   // Advocado Outlet Name
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }
                    else if (sIniID.ToString() == "58")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbicrm.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "59")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbicrm.SelectedIndex),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    else if (sIniID.ToString() == "60")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue=@IniValue where id=@id ";
                        string command = string.Format(sCmd, BranchAlias);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",sIniValue),
                         new MySqlParameter("@id",sIniID),
                        };

                        iIcrmUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }







                    Force_Update(Cmb_BranchName);

                    if (iIcrmUpdate > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Advacado  setting Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }



                }
            }



        }

        protected void grdCRM_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("lblCRMId") as Label);
                TextBox sIniValue = (e.Row.FindControl("txtCRMValue") as TextBox);
                Label lblViewCartName = (e.Row.FindControl("lblCRMIniName") as Label);
                DropDownList icrmcmb = (e.Row.FindControl("cmbCRM") as DropDownList);



                if (sIniID.Text == "19")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }

                else if (sIniID.Text == "20")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "21")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "24")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "25")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "26")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "27")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "28")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "29")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }
                else if (sIniID.Text == "58")
                {
                    icrmcmb.Items.Add("Disable");
                    icrmcmb.Items.Add("Enable");
                    icrmcmb.DataBind();
                    sIniValue.Visible = false;
                }
                else if (sIniID.Text == "59")
                {
                    icrmcmb.Items.Add("Disable");
                    icrmcmb.Items.Add("Enable");
                    icrmcmb.DataBind();
                    sIniValue.Visible = false;
                }

                else if (sIniID.Text == "60")
                {
                    icrmcmb.Visible = false;
                    sIniValue.Visible = true;
                }



                if (cmbBranches.SelectedIndex != 0)
                {
                    #region  Validation Between HQ Branch and Normal Branch 
                    BranchFullName = cmbBranches.SelectedItem.Text;      // This will Return Branch FullName 
                    if (BranchFullName == "HQ")
                    {
                        BranchAlias = Session["Branch_HQ"].ToString();
                    }
                    else
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                        BranchAlias = Cmb_BranchName;

                    }
                    #endregion
                    if (sIniID.Text == "58" || sIniID.Text == "59")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        icrmcmb.SelectedIndex = int.Parse(RetVal);

                    }



                }

            }

        }

        #endregion

        protected void BtnICMSaveImageLogo_Click(object sender, EventArgs e)
        {
            if (cmbBranches.Visible == false)
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;          // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion

            }

            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            SaveImagedetailstoS3(BranchAlias, "ICRMCOMPANYLOGO", 71, "ICRM");
        }

        protected void grdweb_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            string RetVal = string.Empty;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the DropDownList in the Row
                Label sIniID = (e.Row.FindControl("lblWebId") as Label);
                Label lblFunctionName = (e.Row.FindControl("lblWebIniName") as Label);
                DropDownList ddlweb = (e.Row.FindControl("cmbWeb") as DropDownList);
                TextBox sIniValue = (e.Row.FindControl("txtWebValue") as TextBox);
                //Label colorpicker = (e.Row.FindControl("colorpicker") as Label);
                //string color = (e.Row.FindControl("colorpicker") as Label);
                
                if (sIniID.Text == "82")
                {
                    sIniValue.Visible = false;
                    ddlweb.Items.Add("Disable");
                    ddlweb.Items.Add("Enable");
                    ddlweb.DataBind();
                }




                if (cmbBranches.SelectedIndex != 0)
                {
                    #region  Validation Between HQ Branch and Normal Branch 
                    BranchFullName = cmbBranches.SelectedItem.Text;      // This will Return Branch FullName 
                    if (BranchFullName == "HQ")
                    {
                        BranchAlias = Session["Branch_HQ"].ToString();
                    }
                    else
                    {
                        BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                        Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                        BranchAlias = Cmb_BranchName;

                    }
                    #endregion
                    if (sIniID.Text == "82")
                    {
                        RetVal = ObjSel.GetIniSettingValue(BranchAlias, sIniID.Text);
                        ddlweb.SelectedIndex = int.Parse(RetVal);

                    }
                   


                }



            }










        }

        protected void grdweb_RowCommand(object sender, GridViewCommandEventArgs e)
        {


            if (e.CommandName == "UpdateWeb")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdweb.Rows[index];
                string lblID = (row.FindControl("lblWebId") as Label).Text;
                string txtValue = (row.FindControl("txtWebValue") as TextBox).Text;
                DropDownList cmbReadweb = (row.FindControl("cmbWeb") as DropDownList);
                if (cmbBranches.SelectedIndex != 0)
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);
                    if (lblID.ToString() == "82")
                    {
                        string sCmd = "Update {0}.weborderinginisetting set IniValue = @IniValue where id =82";

                        string command = string.Format(sCmd, Cmb_BranchName);
                        MySqlParameter[] parameters =
                        {
                         new MySqlParameter("@IniValue",cmbReadweb.SelectedIndex),

                        };
                        iWebUpdate = ObjMain.ExecuteQuery(command, parameters);
                    }

                    string safeValue = Server.HtmlEncode(Cmb_BranchName);
                    string script = $"localStorage.setItem('Initialbranch', '{safeValue}');"; 
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "SetLocalStorage", script, true);




                }

                if (iWebUpdate > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('WebPortal Successfully Updated ');location.href='LayoutSetting.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                }
            }


        }

        protected void btnPriceflagcreate_Click(object sender, EventArgs e)
        {
            if (cmbBranches.Visible == false)
            {
              BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;          // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion

            }

            // Call Priceflag Function
            Truncate_priceflag();
            INS_PriceFlage(BranchAlias);
           

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Priceflag created Successfully Updated ');location.href='LayoutSetting.aspx'", true);

        }

        protected void btnPriceflagFix_Click(object sender, EventArgs e)
        {
            if (cmbBranches.Visible == false)
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;          // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion

            }

           
            INS_PriceFlage_Fix(BranchAlias);

        }

        /// <summary>
        ///  Insert the Priceflag from new Inventory . 
        /// </summary>
        /// <param name="sdb"></param>
        public void INS_PriceFlage(string sdb)
        {

            // Local Variable 

            string Inventoryid = string.Empty;
            string Barcode = string.Empty;

            //#1 Check the PriceFlage table Record  count 

            string PriceFlagQuery = "select * from {0}.PriceFlag;";
            string Price_command = string.Format(PriceFlagQuery, sdb);
            DtPriceFlag = ObjMain.GetData_DT(Price_command);

            //#2 Get Inventory Table Record Count 

            string InventoryRowCountQuery = "select * from {0}.Inventory; ";
            string Inventory_command = string.Format(InventoryRowCountQuery, sdb);
            DtinventoryCnt = ObjMain.GetData_DT(Inventory_command);

            //#3. If PriceFlag  is NULL 
            if (DtPriceFlag.Rows.Count == 0)
            {
                // Call Insert Function

                string ReadInventoryids = "select Inventoryid,Barcode from {0}.inventory order by Inventoryid; ";
                string commandReads = string.Format(ReadInventoryids, sdb);
                DtRead = ObjMain.GetData_DT(commandReads);

                for (int i = 0; i < DtRead.Rows.Count; i++)
                {
                    DataRow dr = DtRead.Rows[i];

                    Inventoryid = dr["Inventoryid"].ToString();
                    Barcode = dr["BarCode"].ToString();

                    // #1.2 IF Not Exist   
                    // Call Insert  Function : PriceFlag
                    #region   Insert Portion
                    string Ins_PriceFlag = " insert into {0}.PriceFlag (Inventoryid,Barcode,Price_Flag,Price2_Flag,Price3_Flag,Price4_Flag)" +
                                           " values " +
                                           " (@Inventoryid,@Barcode,@Price_Flag,@Price2_Flag,@Price3_Flag,@Price4_Flag);";
                    string Ins_command = string.Format(Ins_PriceFlag, sdb);
                    MySqlParameter[] parameters =
                        {
                             new MySqlParameter("@Inventoryid",Inventoryid),
                             new MySqlParameter("@Barcode",Barcode),
                             new MySqlParameter("@Price_Flag","0"),
                             new MySqlParameter("@Price2_Flag","0"),
                             new MySqlParameter("@Price3_Flag","0"),
                             new MySqlParameter("@Price4_Flag","0"),
                        };
                    Q = ObjMain.ExecuteQuery(Ins_command, parameters);




                    #endregion
                }


            }
            //#4. If PriceFlag  < Inventory 
            else if (DtPriceFlag.Rows.Count < DtinventoryCnt.Rows.Count)
            {

                string CheckA = string.Empty;

                //#1.1 IF Inventoryid is exist  in  PriceFlag Table Ignore to Insert 

                string ReadInventoryids = "select Inventoryid,Barcode from {0}.inventory order by Inventoryid; ";
                string commandReads = string.Format(ReadInventoryids, sdb);
                DtRead = ObjMain.GetData_DT(commandReads);

                for (int i = 0; i < DtRead.Rows.Count; i++)
                {
                    DataRow dr = DtRead.Rows[i];

                    Inventoryid = dr["Inventoryid"].ToString();
                    Barcode = dr["BarCode"].ToString();

                    // #1.2 IF Inventoryid is  Exist  in PriceFlag  Ignore to Insert  
                    // Check the Inventoryid in 'PriceFlag'

                    string ReadInventoryidOnPriceFlag = "select Inventoryid from {0}.PriceFlag where  Inventoryid=@Inventoryid ; ";
                    string command_ReadPriceflag = string.Format(ReadInventoryidOnPriceFlag, sdb);
                    MySqlParameter[] parameters =
                    {
                     new MySqlParameter("@Inventoryid",Inventoryid),
                    };
                    CheckA = ObjMain.NewExecuteScalar(command_ReadPriceflag, parameters);

                    if (CheckA != "")
                    {
                        // Record Already Exist In PriceFlag : Ignore for insert 
                    }
                    else
                    {
                        // Call Insert  Function : PriceFlag  
                        #region   Insert Portion
                        string Ins_PriceFlag = " insert into {0}.PriceFlag (Inventoryid,Barcode,Price_Flag,Price2_Flag,Price3_Flag,Price4_Flag)" +
                                               " values " +
                                               " (@Inventoryid,@Barcode,@Price_Flag,@Price2_Flag,@Price3_Flag,@Price4_Flag);";
                        string Ins_command = string.Format(Ins_PriceFlag, sdb);
                        MySqlParameter[] parametersM =
                            {
                             new MySqlParameter("@Inventoryid",Inventoryid),
                             new MySqlParameter("@Barcode",Barcode),
                             new MySqlParameter("@Price_Flag","0"),
                             new MySqlParameter("@Price2_Flag","0"),
                             new MySqlParameter("@Price3_Flag","0"),
                             new MySqlParameter("@Price4_Flag","0"),
                        };
                        Q = ObjMain.ExecuteQuery(Ins_command, parametersM);

                        #endregion

                    }


                }



            }
            else
            {
                // Nothing To :  Run 
            }




        }

        /// <summary> 
        ///  This function uses to truncate the Priceflag table 
        /// </summary>
        public void Truncate_priceflag()
        {

            if (cmbBranches.Visible == false)
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                #region  Validation Between HQ Branch and Normal Branch 
                BranchFullName = cmbBranches.SelectedItem.Text;          // This will Return Branch FullName 
                if (BranchFullName == "HQ")
                {
                    BranchAlias = Session["Branch_HQ"].ToString();
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    BranchAlias = Cmb_BranchName;

                }
                #endregion

            }
            #region   Insert Portion
            string truncate_PriceFlag = "truncate table  {0}.PriceFlag;";
                                
            string truncate_command = string.Format(truncate_PriceFlag, BranchAlias);
            
           Q = ObjMain.ExecuteNonQuery(truncate_command);

            #endregion
        }

        public void INS_PriceFlage_Fix(string sdb)
        {

            // Local Variable 

            string Inventoryid = string.Empty;
            string Barcode = string.Empty;

            //#1 Check the PriceFlage table Record  count 

            string PriceFlagQuery = "select * from {0}.PriceFlag;";
            string Price_command = string.Format(PriceFlagQuery, sdb);
            DtPriceFlag = ObjMain.GetData_DT(Price_command);

            //#2 Get Inventory Table Record Count 

            string InventoryRowCountQuery = "select * from {0}.Inventory; ";
            string Inventory_command = string.Format(InventoryRowCountQuery, sdb);
            DtinventoryCnt = ObjMain.GetData_DT(Inventory_command);

            //#3. If PriceFlag  is NULL 
            if (DtPriceFlag.Rows.Count == 0)
            {
                // Call Insert Function

                string ReadInventoryids = "select Inventoryid,Barcode from {0}.inventory order by Inventoryid; ";
                string commandReads = string.Format(ReadInventoryids, sdb);
                DtRead = ObjMain.GetData_DT(commandReads);

                for (int i = 0; i < DtRead.Rows.Count; i++)
                {
                    DataRow dr = DtRead.Rows[i];

                    Inventoryid = dr["Inventoryid"].ToString();
                    Barcode = dr["BarCode"].ToString();

                    // #1.2 IF Not Exist   
                    // Call Insert  Function : PriceFlag
                    #region   Insert Portion
                    string Ins_PriceFlag = " insert into {0}.PriceFlag (Inventoryid,Barcode,Price_Flag,Price2_Flag,Price3_Flag,Price4_Flag)" +
                                           " values " +
                                           " (@Inventoryid,@Barcode,@Price_Flag,@Price2_Flag,@Price3_Flag,@Price4_Flag);";
                    string Ins_command = string.Format(Ins_PriceFlag, sdb);
                    MySqlParameter[] parameters =
                        {
                             new MySqlParameter("@Inventoryid",Inventoryid),
                             new MySqlParameter("@Barcode",Barcode),
                             new MySqlParameter("@Price_Flag","0"),
                             new MySqlParameter("@Price2_Flag","0"),
                             new MySqlParameter("@Price3_Flag","0"),
                             new MySqlParameter("@Price4_Flag","0"),
                        };
                    Q = ObjMain.ExecuteQuery(Ins_command, parameters);
                    #endregion
                }


            }
            //#4. If PriceFlag  < Inventory 
            else if (DtPriceFlag.Rows.Count < DtinventoryCnt.Rows.Count)
            {

                string CheckA = string.Empty;

                //#1.1 IF Inventoryid is exist  in  PriceFlag Table Ignore to Insert 

                string ReadInventoryids = "select Inventoryid,Barcode from {0}.inventory order by Inventoryid; ";
                string commandReads = string.Format(ReadInventoryids, sdb);
                DtRead = ObjMain.GetData_DT(commandReads);

                for (int i = 0; i < DtRead.Rows.Count; i++)
                {
                    DataRow dr = DtRead.Rows[i];

                    Inventoryid = dr["Inventoryid"].ToString();
                    Barcode = dr["BarCode"].ToString();

                    // #1.2 IF Inventoryid is  Exist  in PriceFlag  Ignore to Insert  
                    // Check the Inventoryid in 'PriceFlag'

                    string ReadInventoryidOnPriceFlag = "select Inventoryid from {0}.PriceFlag where  Inventoryid=@Inventoryid ; ";
                    string command_ReadPriceflag = string.Format(ReadInventoryidOnPriceFlag, sdb);
                    MySqlParameter[] parameters =
                    {
                     new MySqlParameter("@Inventoryid",Inventoryid),
                    };
                    CheckA = ObjMain.NewExecuteScalar(command_ReadPriceflag, parameters);

                    if (CheckA != "")
                    {
                        // Record Already Exist In PriceFlag : Ignore for insert 
                        // Call Insert  Function : PriceFlag   added on 05-09-25  
                        #region   Update Portion
                        string UPT_PriceFlag = @"UPDATE {0}.PriceFlag SET Barcode=@Barcode Where Inventoryid=@Inventoryid ;";
                        string UPT_command = string.Format(UPT_PriceFlag, sdb);
                        MySqlParameter[] parametersM =
                            {
                             new MySqlParameter("@Inventoryid",Inventoryid),
                             new MySqlParameter("@Barcode",Barcode),
                            };
                        Q = ObjMain.ExecuteQuery(UPT_command, parametersM);
                        #endregion
                    }
                    else
                    {
                        // Call Insert  Function : PriceFlag  
                        #region   Insert Portion
                        string Ins_PriceFlag = " insert into {0}.PriceFlag (Inventoryid,Barcode,Price_Flag,Price2_Flag,Price3_Flag,Price4_Flag)" +
                                               " values " +
                                               " (@Inventoryid,@Barcode,@Price_Flag,@Price2_Flag,@Price3_Flag,@Price4_Flag);";
                        string Ins_command = string.Format(Ins_PriceFlag, sdb);
                        MySqlParameter[] parametersM =
                            {
                             new MySqlParameter("@Inventoryid",Inventoryid),
                             new MySqlParameter("@Barcode",Barcode),
                             new MySqlParameter("@Price_Flag","0"),
                             new MySqlParameter("@Price2_Flag","0"),
                             new MySqlParameter("@Price3_Flag","0"),
                             new MySqlParameter("@Price4_Flag","0"),
                        };
                        Q = ObjMain.ExecuteQuery(Ins_command, parametersM);

                        #endregion

                    }


                }



            }
            else if (DtPriceFlag.Rows.Count == DtinventoryCnt.Rows.Count)
            {
                string CheckA = string.Empty;

                //#1.1 IF Inventoryid is exist  in  PriceFlag Table Ignore to Insert 

                string ReadInventoryids = "select Inventoryid,Barcode from {0}.inventory order by Inventoryid; ";
                string commandReads = string.Format(ReadInventoryids, sdb);
                DtRead = ObjMain.GetData_DT(commandReads);

                for (int i = 0; i < DtRead.Rows.Count; i++)
                {
                    DataRow dr = DtRead.Rows[i];

                    Inventoryid = dr["Inventoryid"].ToString();
                    Barcode = dr["BarCode"].ToString();

                    // #1.2 IF Inventoryid is  Exist  in PriceFlag  Ignore to Insert  
                    // Check the Inventoryid in 'PriceFlag'

                    string ReadInventoryidOnPriceFlag = "select Inventoryid from {0}.PriceFlag where  Inventoryid=@Inventoryid ; ";
                    string command_ReadPriceflag = string.Format(ReadInventoryidOnPriceFlag, sdb);
                    MySqlParameter[] parameters =
                    {
                     new MySqlParameter("@Inventoryid",Inventoryid),
                    };
                    CheckA = ObjMain.NewExecuteScalar(command_ReadPriceflag, parameters);

                    if (CheckA != "")
                    {
                        // Record Already Exist In PriceFlag : Ignore for insert 
                        // Call Insert  Function : PriceFlag   added on 05-09-25  
                        #region   Update Portion
                        string UPT_PriceFlag = @"UPDATE {0}.PriceFlag SET Barcode=@Barcode Where Inventoryid=@Inventoryid ;";
                        string UPT_command = string.Format(UPT_PriceFlag, sdb);
                        MySqlParameter[] parametersM =
                            {
                             new MySqlParameter("@Inventoryid",Inventoryid),
                             new MySqlParameter("@Barcode",Barcode),
                            };
                        Q = ObjMain.ExecuteQuery(UPT_command, parametersM);
                        #endregion
                    }
                    else
                    {
                        

                       // This is insert Part 

                    }

                    
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Priceflag Fixes Successfully Updated ');location.href='LayoutSetting.aspx'", true);


                }


            }
            else
            {


            }



        }
        
        protected void BtnICMSaveImageBackground_Click(object sender, EventArgs e)
        {

            #region  Validation Between HQ Branch and Normal Branch 
            BranchFullName = cmbBranches.SelectedItem.Text;         // This will Return Branch FullName 
            if (BranchFullName == "HQ")
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;     // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                BranchAlias = Cmb_BranchName;

            }
            #endregion



            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            SaveImagedetailstoS3(BranchAlias, "ICRMCOMPANYBG", 84, "ICRM");


        }
    }
}