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

namespace SUNWEB
{
    public partial class NewGroupCondiment : 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;
        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();
        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();
        MySqlCommand Cmdv = new MySqlCommand();
        MYSQLCLOUD ObjCloudMain = new MYSQLCLOUD();
   

        // 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_CondimentGroup = string.Empty;
        string Branchidval = string.Empty;
        string BranchFullName = string.Empty;
        string Curr_BranchFullName = string.Empty;
        string Cmb_BranchName = string.Empty;
        string BranchAlias = string.Empty;

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

        Int32 iAddCondimentGroup;
        Int32 iAddCondiment;
        Int32 iAddCondimentGroupDetail;
        Int32 iUpdateCondimentGroup;
        Int32 iUpdateCondiment;
        Int32 iDeleteCondiment;
        Int32 iDeleteCondimentGroupID;
        string Vw_Chk = string.Empty;
        string FileID = string.Empty;

        //Condiment Flag
        DataTable DTPrinterList = new DataTable();
        DataTable DTCondiment = new DataTable();
        string RActive_Stauts = string.Empty;
        string RFlag2_Printer = string.Empty;
        string PrinterName1, PrinterName2, PrinterName3, PrinterName4, PrinterName5, PrinterName6, PrinterName7,
              PrinterName8, PrinterName9, PrinterName10, PrinterName11, PrinterName12, PrinterName13, PrinterName14, PrinterName15, PrinterName16, PrinterName17, PrinterName18, PrinterName19;
        string RPrintno1, RPrintno2, RPrintno3, RPrintno4, RPrintno5, RPrintno6, RPrintno7, RPrintno8, RPrintno9, RPrintno10, RPrintno11, RPrintno12, RPrintno13, RPrintno14, RPrintno15, RPrintno16, RPrintno17, RPrintno18, RPrintno19;
        Int32 iUpdateCondimentFlag;
        string RBranchid = string.Empty;
        string Branchid = string.Empty;

        string ReadHQ = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {

            btnAddNew.CssClass = "btn btn-success";
            btnApplySearchCndimentGroup.CssClass = "btn btn-primary";
           

            PID = "29";    // This is for NewGroupcondiment Page : Inherited from Condiment Rights 
            if (!IsPostBack)
            {
               

            }

            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_CondimentGroup"].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);
                            }
                        }
                    }
                }
            }
         
            //if (!IsPostBack)
            //{

            //    BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
            //    Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            //    if (txtCondimentGroupID.Text != "")
            //    {
            //        CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text.Trim()));
            //        txtCondimentName.Enabled = true;
            //        txtCondimentDesc.Enabled = true;
            //        btnAddCondiment.Enabled = true;
            //    }
            //    else
            //    {
            //        txtCondimentName.Enabled = false;
            //        txtCondimentDesc.Enabled = false;
            //        btnAddCondiment.Enabled = false;
            //    }
            //    ShowCondimentGroups(Cmb_BranchName); //Show Condiment Group 
            //    lblclientname.Text = Session["CM_ID"].ToString();
            //    lblstorename.Text = Cmb_BranchName;
            //}
            //else
            //{
            //    if (txtCondimentGroupID.Text != "")
            //    {
            //        txtCondimentName.Enabled = true;
            //        txtCondimentDesc.Enabled = true;
            //        btnAddCondiment.Enabled = true;
            //    }
            //    else
            //    {
            //        txtCondimentName.Enabled = false;
            //        txtCondimentDesc.Enabled = false;
            //        btnAddCondiment.Enabled = false;
            //    }
            //}
        }


        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 ActiveCall()
        {
            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());
                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());
                }
            }


            ISHQ = ObjMain.ExecuteScalar("select BranchName from branches where Branchname='" + ActiveCallvalue + "' and branchID=1;");  //now 

            if (ISHQ != "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch(Session["Branch_HQ"].ToString());
                UPDATEBRANCH(ActiveCallvalue);
            }

            cd_BranchAlias = ActiveCallvalue;
            ReadHQ = ObjUserBL.GetBranchFullNameByBranchName(Session["Branch_HQ"].ToString(), cd_BranchAlias);
            //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);

            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);

            }

            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_CondimentGroup = DtLicense.Rows[0]["CONDIMENTGROUP"].ToString();
                Session["L_CondimentGroup"] = L_CondimentGroup;
            }


            if ((Session["L_CondimentGroup"] == null) || Session["L_CondimentGroup"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            {
                //Response.Redirect("DeniedPage.aspx");//Response.Redirect("DeniedPage.aspx");
                if (cmbBranches.SelectedItem.Text == "HQ")
                {
                    // btnExcel.Enabled = true;
                    // HQ Validation    02-12-21

                    #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

                    // Include the Loading Functions 
                    // Hided on 08-10-255 
                    //  LoadInventoryview();
                    // LoadPIInventoryview(BranchAlias);
                    UPDATEBRANCH(BranchAlias);



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

            }
            else if (Session["Write_Acess"].ToString() == "N")
            {
                Response.Redirect("DeniedPage.aspx");
            }
            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 = cmbBranches.SelectedItem.Text;
                // BindGridview(ActiveCallvalue, txtStartDt.Text, txtEndDt.Text);
                System.Threading.Thread.Sleep(2000);


                #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



                cmbBranches.CssClass = "form-select";
                if (!IsPostBack)
                {

                    BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                    Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
                    if (txtCondimentGroupID.Text != "")
                    {
                        CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text.Trim()));
                        txtCondimentName.Enabled = true;
                        txtCondimentDesc.Enabled = true;
                        btnAddCondiment.Enabled = true;
                    }
                    else
                    {
                        txtCondimentName.Enabled = false;
                        txtCondimentDesc.Enabled = false;
                        btnAddCondiment.Enabled = false;
                    }
                    lblclientname.Text = Session["CM_ID"].ToString();
                    lblstorename.Text = BranchAlias;
                }
                else
                {
                    if (txtCondimentGroupID.Text != "")
                    {
                        txtCondimentName.Enabled = true;
                        txtCondimentDesc.Enabled = true;
                        btnAddCondiment.Enabled = true;
                    }
                    else
                    {
                        txtCondimentName.Enabled = false;
                        txtCondimentDesc.Enabled = false;
                        btnAddCondiment.Enabled = false;
                    }
                }

             

            }
            ShowCondimentGroups(BranchAlias); //Show Condiment Group 

            lblclientname.Text = Session["CM_ID"].ToString();
            lblstorename.Text = BranchAlias;

            UPDATEBRANCH(BranchAlias);

        }

        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 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");

            }

        }

        protected void btnGetReports_Click(object sender, EventArgs e)
        {

        }

        protected void  cmbBranches_SelectedIndexChanged(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(1000);
            if (cmbBranches.SelectedIndex == 1)
            {

                BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
                UPDATEBRANCH(Cmb_BranchName);
                Session["BranchFullName"] = BranchFullName;
                //  this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Javascript", "javascript:GetActiveSession5();", true);
                //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "MyFun1", "GetActiveSession5();", true);
            }
            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



                Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + BranchAlias + "';");
                RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
                DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);
                Session["BranchFullName"] = BranchFullName;
                // this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Javascript", "javascript:GetActiveSession5();", true);

            }

            if (cmbBranches.SelectedIndex == 0)
            {
                Response.Write("NewGroupCondiment.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 (DtLicense.Rows.Count > 0)
                {

                    L_CondimentGroup = DtLicense.Rows[0]["CONDIMENTGROUP"].ToString();
                    Session["L_CondimentGroup"] = L_CondimentGroup;
                }

                if ((Session["L_CondimentGroup"] == null) || Session["L_CondimentGroup"].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

                        //ClearForms();
                        // Disable Temporarily On 27-03-24 : Paging need to do 
                        // Karthik Hided on 08-10-25
                        // LoadInventoryview();
                        // LoadPIInventoryview(BranchAlias); 
                        UPDATEBRANCH(Cmb_BranchName);

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

                }

                else
                {
                    if (Session["Write_Acess"].ToString() == "N")
                    {

                        //If No .. Disable the Button 

                    }
                    else if (Session["Write_Acess"].ToString() == "Y")
                    {
                        //If Yes .. Enable the Button 
                    }
                    #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
                    //ClearForms();
                    // Disable temporarily on 27-03-24 
                    // Karthik Hided on 08-10-25
                    // LoadInventoryview();
                    // LoadPIInventoryview(BranchAlias);                      
                }
                UPDATEBRANCH(Cmb_BranchName);
                Response.Redirect(Request.RawUrl);
            }

            /*if (cmbBranches.SelectedIndex == 1)
            {
                Response.Write("Inventory.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 = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                    Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
                    UPDATEBRANCH(Cmb_BranchName);
                }
                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 )
                    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_CondimentAdd = DtLicense.Rows[0]["CONDIMENT"].ToString();
                    Session["L_CondimentAdd"] = L_CondimentAdd;
                }

                if ((Session["L_CondimentAdd"] == null) || Session["L_CondimentAdd"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
                {
                    if (cmbBranches.SelectedIndex == 1)
                    {
                        // btnExcel.Enabled = true;
                        #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);
                        ShowCondimentGroups(Cmb_BranchName);
                        cmbBranches.CssClass = "form-select";


                        lblclientname.Text = Session["CM_ID"].ToString();
                        lblstorename.Text = BranchAlias;

                        // Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);                       
                    }
                    else
                    {
                        Response.Redirect("DeniedPage.aspx");
                    }
                }
                else if (Session["Write_Acess"].ToString() == "N")
                {
                    Response.Redirect("DeniedPage.aspx");
                }
                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
                    cmbBranches.CssClass = "form-select";
                    UPDATEBRANCH(BranchAlias);
                    ShowCondimentGroups(Cmb_BranchName);


                    lblclientname.Text = Session["CM_ID"].ToString();
                    lblstorename.Text = BranchAlias;


                    //  Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
                }
            }*/

        }

        private void AddCondimentGroup(string sDB, string CondimentGroup, string CondimentGroupDefaultQTY,int optional) //John added CondimentGroupDefaultQTY on 27-Jan-2022 
        {
            // SQL Injection Prevention 
            // XSS Prevention 
            string sCmd = string.Empty;
            int iCondimentGroupID = int.Parse(ObjSel.GenerateCondimentGroupID(sDB));
            sCmd = "Insert into {0}.condimentgroup(condimentgroupid,condimentgroupname,condimentgroupdefaultqty,condimentgroupoptional)values(@condimentgroupid,@condimentgroupname,@condimentgroupdefaultqty,condimentgroupoptional)";
            string Commmad = string.Format(sCmd, sDB);

            MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@condimentgroupid",iCondimentGroupID),
                     new MySqlParameter("@condimentgroupname",CondimentGroup),
                     new MySqlParameter("@condimentgroupdefaultqty",CondimentGroupDefaultQTY),
                     new MySqlParameter("@condimentgroupoptional",optional),
                    };
            iAddCondimentGroup = ObjMain.ExecuteQuery(Commmad, parameters);
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Group Successfully Added ')", true);
            txtCondimentGroupID.Text = iCondimentGroupID.ToString();
            if (txtCondimentGroupID.Text != "")
            {
                txtCondimentName.Enabled = true;
                txtCondimentDesc.Enabled = true;
                txtCondimentGroupDefaultQTY.Enabled = true;
                btnAddCondiment.Enabled = true;
            }
            else
            {
                txtCondimentName.Enabled = false;
                txtCondimentDesc.Enabled = false;
                txtCondimentGroupDefaultQTY.Enabled = false;
                btnAddCondiment.Enabled = false;
            }
            //txtCondimentGroup.Text = "";
            //ShowCondimentGroups(sDB);
        }

        private void UpdateCondimentGroup(string sDB, int CondimentGroupID, string CondimentGroup, string CondimentGroupDefaultQTY,int optional)
        {
            string sCmd = string.Empty;
            sCmd = "Update {0}.CondimentGroup set CondimentGroupName=@CondimentGroupName,CondimentGroupDefaultQTY=@CondimentGroupDefaultQTY,condimentgroupoptional=@condimentgroupoptional  where CondimentGroupID =@CondimentGroupID ;";
            string Commmad = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@CondimentGroupName",CondimentGroup),
                new MySqlParameter("@CondimentGroupID",CondimentGroupID),
                new MySqlParameter("@CondimentGroupDefaultQTY",CondimentGroupDefaultQTY),
                new MySqlParameter("@condimentgroupoptional",optional),
            };

            iUpdateCondimentGroup = ObjMain.ExecuteQuery(Commmad, parameters);
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Group Update Successfully')", true);
        }

        private void AddCondiment(string sDB, string CondimentName, string CondimentDesc,int iCondimentDefaultQTY)
        {
            string sCmd = string.Empty;
            int iCondimentid = int.Parse(ObjSel.GenerateCondimentID(sDB));
            sCmd = "Insert into {0}.Condiment(condimentid,condimentname,condimentdesc,condimentdefaultQty)values(@condimentid,@condimentname,@condimentdesc,@condimentdefaultqty);";
            string command = string.Format(sCmd, sDB);

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@condimentid",iCondimentid),
                new MySqlParameter("@condimentname",CondimentName),
                new MySqlParameter("@condimentdesc",CondimentDesc),
                new MySqlParameter("@condimentdefaultqty",iCondimentDefaultQTY),          

            };
            iAddCondiment = ObjMain.ExecuteQuery(command, parameters);
            AddCondimentGroupDetails(sDB, int.Parse(txtCondimentGroupID.Text.Trim()), iCondimentid);
            SaveImagedetailstoS3(sDB, "Condiment", iCondimentid);
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Successfully Added ')", true);
        }

        private void AddCondimentGroupDetails(string sDB, int iCondimentGroupID, int iCondimentID)
        {
            // Prevention SQL Injection 
            // Prevention XSS


            string sCmd = "Insert Into {0}.CondimentGroupDetails(CondimentGroupID,CondimentID)values(@CondimentGroupID,@CondimentID)";
            string command = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
                {
                     new MySqlParameter("@CondimentGroupID",iCondimentGroupID),
                     new MySqlParameter("@CondimentID",iCondimentID),

                    };

            iAddCondimentGroupDetail = ObjMain.ExecuteQuery(command, parameters);

        }

        private void CondimentListbyCondimentGroup(string sDB, int iCondimentGroupID)
        {

            grdCondimentList.DataSource = null;

            //MySqlCommand cmd = new MySqlCommand("Select condimentid,condimentname,condimentdesc from " + sDB + ".condiment;", Cn);
            string cmd = "Select A.condimentid,A.condimentname,condimentdesc,condimentdefaultqty,C.CondimentGroupID,CondimentGroupName,if(singleselection=0,'false','true') as SingleSelection,if(Available=0,'true','false') as Available,if(SpecialCondiment=0,'false','true') as SpecialCondiment,nosubcondiment, ImagePath from {0}.condiment A " +
                                                 " join {0}.CondimentGroupDetails B on A.CondimentID = B.CondimentID " +
                                                 " join {0}.CondimentGroup C on B.CondimentGroupID = C.CondimentGroupID Where C.Condimentgroupid=@Condimentgroupid ";


            string command = string.Format(cmd, sDB);
            MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@Condimentgroupid",iCondimentGroupID),
                  };


            DataTable Dt = new DataTable();
            Dt = ObjMain.NewGetData_DT(command, parameters);
            grdCondimentList.DataSource = Dt;
            grdCondimentList.DataBind();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
            Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            string _CondimentGroup = txtCondimentGroup.Text.Trim();
            string _CondimentGroupDefaultQTY = txtCondimentGroupDefaultQTY.Text.Trim(); // John added on 27-Jan-2022
            int _CondimentOptional = 0;
            if(chkoptional.Checked)
            {
                _CondimentOptional = 1;
            }
           
            if (txtCondimentGroupID.Text == "")
            {
                AddCondimentGroup(Cmb_BranchName.Trim(), _CondimentGroup, _CondimentGroupDefaultQTY,_CondimentOptional);
            }
            else
            {
                UpdateCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text), txtCondimentGroup.Text, _CondimentGroupDefaultQTY, _CondimentOptional);
                ShowCondimentGroups(Cmb_BranchName);
                CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text));
            }
        }

        //protected void btnEdit_Click(object sender, EventArgs e)
        //{
        //    BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
        //    Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
        //    //string _CondimentGroupID = txtCondimentGroupID
        //    UpdateCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text), txtCondimentGroup.Text);
        //    ShowCondimentGroups(Cmb_BranchName);
        //}

        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            txtCondimentGroupID.Text = "";
            txtCondimentGroup.Text = "";
            txtCondimentID.Text = "";
            txtCondimentName.Text = "";
            txtCondimentDesc.Text = "";
            txtCondimentDefaultQTY.Text = "0";
            Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
        }

        protected void btnAddCondiment_Click(object sender, EventArgs e)
        {
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            string _CondimentID = txtCondimentID.Text.Trim();
            string _CondimentName = txtCondimentName.Text.Trim();
            string _CondimentDesc = txtCondimentDesc.Text.Trim();
            string _CondimentDefaultQTY = txtCondimentDefaultQTY.Text.Trim();
            
            if (txtCondimentID.Text == "")
            {
                AddCondiment(Cmb_BranchName.Trim(), _CondimentName, _CondimentDesc, int.Parse(_CondimentDefaultQTY));
                CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text.Trim()));
                txtCondimentID.Text = "";
                txtCondimentName.Text = "";
                txtCondimentDesc.Text = "";
                txtCondimentDefaultQTY.Text = "0";
                //divCondimentImage.Attributes.Add("style", "");
            }
            else
            {
                UpdateCondiment(Cmb_BranchName, _CondimentID, _CondimentName, _CondimentDesc,int.Parse(_CondimentDefaultQTY));
                CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text.Trim()));
                txtCondimentID.Text = "";
                txtCondimentName.Text = "";
                txtCondimentDesc.Text = "";
                txtCondimentDefaultQTY.Text = "0";
                //divCondimentImage.Attributes.Add("style", "");
            }

        }

        private void ShowCondimentGroups(string sDB)
        {

            grdCondimentGroupList.DataSource = null;

            string cmd = "Select CondimentGroupID,condimentGroupName,condimentgroupdefaultqty from {0}.CondimentGroup ; ";
            string command = string.Format(cmd, sDB);
            DataTable Dt = new DataTable();
            Dt = ObjMain.GetData_DT(command);

            grdCondimentGroupList.DataSource = Dt;
            grdCondimentGroupList.DataBind();
        }

        protected void OnSelectedIndexChangedGroup(object sender, EventArgs e)
        {

            //Accessing TemplateField Column controls.
            BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
            Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);

            string sCondimentGroupID = (grdCondimentGroupList.SelectedRow.FindControl("lblGCondimentID") as Label).Text;
            string sCondimentGroupName = (grdCondimentGroupList.SelectedRow.FindControl("lblGCondimentName") as Label).Text;
            string sCondimetGroupDefaultQTY = (grdCondimentGroupList.SelectedRow.FindControl("lblGCondimentDefaultQTY") as Label).Text;

            txtCondimentGroupID.Text = sCondimentGroupID.ToString().Trim();
            txtCondimentGroup.Text = sCondimentGroupName.ToString().Trim();
            txtCondimentGroupDefaultQTY.Text = sCondimetGroupDefaultQTY.ToString().Trim();
            CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(sCondimentGroupID));

            if (sCondimentGroupID != "")
            {
                txtCondimentName.Enabled = true;
                txtCondimentDesc.Enabled = true;
                txtCondimentGroupDefaultQTY.Enabled = true;
                btnAddCondiment.Enabled = true;
                //btnSave.Enabled = false;

            }
            else
            {
                txtCondimentName.Enabled = false;
                txtCondimentDesc.Enabled = false;
                txtCondimentGroupDefaultQTY.Enabled = false;
                btnAddCondiment.Enabled = false;
                // btnSave.Enabled = true;

            }

            txtCondimentID.Text = "";
            txtCondimentName.Text = "";
            txtCondimentDesc.Text = "";
            txtCondimentDefaultQTY.Text = "0";
            //divCondimentImage.Attributes.Add("style", "");
        }

        protected void grdCondimentList_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditRow")
            {
                //Determine the RowIndex of the Row whose LinkButton was clicked.
                int rowIndex = Convert.ToInt32(e.CommandArgument);

                //Reference the GridView Row.
                GridViewRow row = grdCondimentList.Rows[rowIndex];

                //Fetch value of Name.
                string CondimentID = (row.FindControl("lblCondimentID") as Label).Text;
                string CondimentName = (row.FindControl("lblCondimentName") as Label).Text;
                string CondimentDesc = (row.FindControl("lblDescription") as Label).Text;
                string CondimentDefaultQTY = (row.FindControl("lblDefaultQTY") as Label).Text;
                string CondimentImagePath = (row.FindControl("lblImagePath") as Label).Text;
                
                Control divImagePath = FindControl("divCondimentImage");

                //HtmlControl divImagePath = (HtmlControl)Page.FindControl("divCondimentImage");

                txtCondimentID.Text = CondimentID;
                txtCondimentName.Text = CondimentName;
                txtCondimentDesc.Text = CondimentDesc;
                txtCondimentDefaultQTY.Text = CondimentDefaultQTY;

                //divCondimentImage.Attributes.Add("style", "background: url('" + CondimentImagePath + "');margin-left: 0px; width: 100px; height: 165px; background-size: cover; background-position: center; background-repeat: no-repeat;");


                //Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
                //Fetch value of Country
                //string country = row.Cells[1].Text;       

                System.Web.UI.ScriptManager.RegisterStartupScript(updatepanel1, updatepanel1.GetType(), "loadImage", "loadImage()", true);
            }
            else if (e.CommandName == "DeleteRow")
            {
                int rowIndex = Convert.ToInt32(e.CommandArgument);

                //Reference the GridView Row.
                GridViewRow row = grdCondimentList.Rows[rowIndex];

                //Fetch value of Name.
                string CondimentID = (row.FindControl("lblCondimentID") as Label).Text;
                BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
                DeleteCondimentGroupDetails(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text.Trim()), int.Parse(CondimentID));
                DeleteCondiment(Cmb_BranchName, int.Parse(CondimentID.ToString()));
                CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text.Trim()));
            }
            else if(e.CommandName == "ViewRow")
            {
                int rowIndex = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = grdCondimentList.Rows[rowIndex];

                string CondimentID = (row.FindControl("lblCondimentID") as Label).Text;
                string CondimentName = (row.FindControl("lblCondimentName") as Label).Text;
               
                BranchFullName = cmbBranches.SelectedItem.Text;
                Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
                modallblCondmentID.Text = CondimentID;
                modallblCondimentName.Text = CondimentName;
                LoadCondimentPrinterFlag(Cmb_BranchName,CondimentID);
            }
        }

        private void UpdateCondiment(string sDB, string iCondimentID, string sCondimentName, string sCondimentDesc, int iCondimentDefaultQTY)
        {
            string sCmd = string.Empty;
            sCmd = "Update {0}.Condiment set condimentname=@condimentname,condimentdesc=@condimentdesc,condimentdefaultqty=@condimentdefaultqty where CondimentID=@CondimentID ";
            string command = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
                    {
                     new MySqlParameter("@condimentname",sCondimentName.Trim()),
                     new MySqlParameter("@condimentdesc",sCondimentDesc.Trim()),
                     new MySqlParameter("@CondimentID",iCondimentID.Trim()),
                     new MySqlParameter("@condiment",iCondimentDefaultQTY),
                     new MySqlParameter("@condimentdefaultqty",iCondimentDefaultQTY),                     
                    };


            iUpdateCondiment = ObjMain.ExecuteQuery(command, parameters);
            SaveImagedetailstoS3(sDB, "Condiment", int.Parse(iCondimentID));
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Successfully Update ')", true);
        }

        private void DeleteCondiment(string sDB, int CondimentID)
        {
            string sCmd = "Delete from  {0}.Condiment where CondimentID=@CondimentID ";
            string command = string.Format(sCmd, sDB);

            MySqlParameter[] parameters =
                   {
                     new MySqlParameter("@CondimentID",CondimentID),
                   };
            iDeleteCondiment = ObjMain.ExecuteQuery(command, parameters);
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Successfully Deleted ')", true);
        }

        public void DeleteCondimentGroupDetails(string sDB, int iCondimentGroupID, int iCondimentID)
        {
            string sCmd = "Delete from  {0}.CondimentGroupDetails where CondimentGroupID=@CondimentGroupID and CondimentID =@CondimentID ";
            string command = string.Format(sCmd, sDB);

            MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@CondimentGroupID",iCondimentGroupID),
                     new MySqlParameter("@CondimentID",iCondimentID),
                   };
            iDeleteCondimentGroupID = ObjMain.ExecuteQuery(command, parameters);
        }

        //txtCondimentName_OnTextChanged
        protected void txtCondimentName_OnTextChanged(object sender, EventArgs e)
        {

            txtCondimentDesc.Text = txtCondimentName.Text;

        }

        protected void btnApplySearchCndimentGroup_Click(object sender, EventArgs e)
        {
            btnAddNew.CssClass = "btn btn-success";


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

        private void ShowCondimentGroupsPopup(string sDB)
        {
            string sCondition = string.Empty;

            if (txtInputCondimentGroup.Text != "")
            {
                sCondition = " Where CondimentGroupName like CONCAT('%',@SearchTxt,'%') ";
            }

            grdCondimentGroupList.DataSource = null;
            string cmd = "Select CondimentGroupID,condimentGroupName,CondimentGroupDefaultQTY from {0}.CondimentGroup " + sCondition + " ";
            string command = string.Format(cmd, sDB);

            MySqlParameter[] parameters =
                    {
                     new MySqlParameter("@SearchTxt",txtInputCondimentGroup.Text.Trim()),

                    };
            DataTable Dt = new DataTable();
            Dt = ObjMain.NewGetData_DT(command, parameters);
            grdCondimentGroupList.DataSource = Dt;
            grdCondimentGroupList.DataBind();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroupList();", true);
        }

        protected void chkAvailable_Changed(object sender, EventArgs e)
        {
            string sDB = string.Empty;
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            sDB = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);

            string sCmd = string.Empty;
            int AvailableVal;
            foreach (GridViewRow row in grdCondimentList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    Label lblCondimentID = (row.Cells[0].FindControl("lblCondimentID") as Label);
                    CheckBox chkRow = (row.Cells[0].FindControl("chkAvailable") as CheckBox);
                    if (chkRow.Checked == true)
                    {
                        AvailableVal = 0;
                    }
                    else
                    {
                        AvailableVal = 1;
                    }

                    sCmd = "Update {0}.Condiment Set Available = " + AvailableVal + " where CondimentID = @CondimentID";
                    string command = string.Format(sCmd, sDB);
                    MySqlParameter[] parameters =
                    {
                        new MySqlParameter("@CondimentID",lblCondimentID.Text)
                    };
                    iUpdateCondiment = ObjMain.ExecuteQuery(command, parameters);

                }
            }

            if (iUpdateCondiment > 0)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Availability Succesfully Updated. ')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Availability Error on Updating. ')", true);
            }

        }

        //chkSingleSelection_Changed
        protected void chkSingleSelection_Changed(object sender, EventArgs e)
        {
            string sDB = string.Empty;
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            sDB = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);

            string sCmd = string.Empty;
            int SingleSelectionVal;
            foreach (GridViewRow row in grdCondimentList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    Label lblCondimentID = (row.Cells[0].FindControl("lblCondimentID") as Label);
                    CheckBox chkRow = (row.Cells[0].FindControl("chkSingleSelection") as CheckBox);
                    if (chkRow.Checked == true)
                    {
                        SingleSelectionVal = 1;
                    }
                    else
                    {
                        SingleSelectionVal = 0;
                    }

                    sCmd = "Update {0}.Condiment Set singleselection = " + SingleSelectionVal + " where CondimentID = @CondimentID";
                    string command = string.Format(sCmd, sDB);
                    MySqlParameter[] parameters =
                    {
                        new MySqlParameter("@CondimentID",lblCondimentID.Text)
                    };
                    iUpdateCondiment = ObjMain.ExecuteQuery(command, parameters);

                }
            }

            if (iUpdateCondiment > 0)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Single Selection Succesfully Updated. ')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Single Selection Error on Updating. ')", true);
            }

        }




        protected void chknosubcondiment_Changed(object sender, EventArgs e)
        {

            string sDB = string.Empty;
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
            sDB = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            string sCmd = string.Empty;
            int ChkNosuncondimentVal;
            foreach (GridViewRow row in grdCondimentList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    Label lblCondimentID = (row.Cells[0].FindControl("lblCondimentID") as Label);
                    CheckBox chkRow = (row.Cells[0].FindControl("chknosubcondiment") as CheckBox);
                    if (chkRow.Checked == true)
                    {
                        ChkNosuncondimentVal = 1;
                    }
                    else
                    {
                        ChkNosuncondimentVal = 0;
                    }

                    sCmd = "Update {0}.Condiment Set nosubcondiment = " + ChkNosuncondimentVal + " where CondimentID = @CondimentID";
                    string command = string.Format(sCmd, sDB);
                    MySqlParameter[] parameters =
                    {
                        new MySqlParameter("@CondimentID",lblCondimentID.Text)
                    };
                    iUpdateCondiment = ObjMain.ExecuteQuery(command, parameters);

                }

                if (iUpdateCondiment > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert('No Suncondiment Selection Succesfully Updated. ')", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert('No Suncondiment Single Selection Error on Updating. ')", true);
                }

            }
        }
        protected void chkCondimentStatus_Changed(object sender,EventArgs e)
        {
            string sDB = string.Empty;
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
            sDB = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            string sCmd = string.Empty;
            int SpecialCondimentVal;
            foreach (GridViewRow row in grdCondimentList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    Label lblCondimentID = (row.Cells[0].FindControl("lblCondimentID") as Label);
                    CheckBox chkRow = (row.Cells[0].FindControl("chkSpecialCondiment") as CheckBox);
                    if (chkRow.Checked == true)
                    {
                        SpecialCondimentVal = 1;
                    }
                    else
                    {
                        SpecialCondimentVal = 0;
                    }

                    sCmd = "Update {0}.Condiment Set SpecialCondiment = " + SpecialCondimentVal + " where CondimentID = @CondimentID";
                    string command = string.Format(sCmd, sDB);
                    MySqlParameter[] parameters =
                    {
                        new MySqlParameter("@CondimentID",lblCondimentID.Text)
                    };
                    iUpdateCondiment = ObjMain.ExecuteQuery(command, parameters);

                }
            }

            if (iUpdateCondiment > 0)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Status  Succesfully Updated. ')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Status  Error on Updating. ')", true);
            }
        }

        protected void btnClearCondiment_Click(object sender, EventArgs e)
        {
            txtCondimentID.Text = "";
            txtCondimentName.Text = "";
            txtCondimentDesc.Text = "";
            txtCondimentDefaultQTY.Text = "0";
           // divCondimentImage.Attributes.Add("style", "");
        }

        //protected void grdCondimentList_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //Accessing TemplateField Column controls.
        //    BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
        //    Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);

        //    string sCondimentID = (grdCondimentList.SelectedRow.FindControl("lblCondimentID") as Label).Text;
        //    string sCondimentName = (grdCondimentList.SelectedRow.FindControl("lblCondimentName") as Label).Text;
        //    string sCondimentDesc = (grdCondimentList.SelectedRow.FindControl("lblDescription") as Label).Text;

        //    txtCondimentID.Text = sCondimentID.ToString().Trim();
        //    txtCondimentName.Text = sCondimentName.ToString().Trim();
        //    txtCondimentDesc.Text = sCondimentDesc.ToString().Trim();
        //    CondimentListbyCondimentGroup(Cmb_BranchName, int.Parse(txtCondimentGroupID.Text));

        //    //if (sCondimentGroupID != "")
        //    //{
        //    //    txtCondimentName.Enabled = true;
        //    //    txtCondimentDesc.Enabled = true;
        //    //    btnAddCondiment.Enabled = true;
        //    //}
        //    //else
        //    //{
        //    //    txtCondimentName.Enabled = false;
        //    //    txtCondimentDesc.Enabled = false;
        //    //    btnAddCondiment.Enabled = false;
        //    //}
        //}
        //protected void grdCondimentList_ItemCommand(object sender, GridViewCommandEventArgs e)
        //{
        //    if (e.CommandName == "Edit")
        //    {
        //         Label textBox = e.Item.FindControl("lblQtydt") as Label;
        //         Label lblHidenval = e.Item.FindControl("lblHidenPrice") as Label;
        //    }

        //    if (e.CommandName == "Delete")
        //    {

        //    }
        //}

        public void SaveImagedetailstoS3(string branchalias, string module, int CondimentID) //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 Extention = S3_Extention.ToString().Trim();
                int S3 = 0;
                int S3_LandingUPT = 0;

                V = S3_http + "//" + S3_S3link + "/" + S3_Companyname + "/" + S3_Brachname + "/" + S3_Extention + "/" + S3_FileName+ "/" + CondimentID + "." + S3_FileName;
                string Url = V.ToString().Trim();
                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}' and InventoryID = '{2}' ";
                string command = string.Format(ChkIsExistQuery, branchalias, module, CondimentID);
                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),
                    };

                    hdnfileid.Value = FileID;

                    //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 UpdateCondiment = "Update {0}.Condiment set ImagePath = @ImagePath where CondimentID = @CondimentID";
                    string commandC = string.Format(UpdateCondiment, branchalias);

                    MySqlParameter[] parametersC =
                     {
                        new MySqlParameter("@ImagePath",Url),
                        new MySqlParameter("@CondimentID",CondimentID),
                    };
                    S3_LandingUPT = ObjMain.ExecuteQuery(commandC, parametersC);
                    //LoadLandingImage(branchalias);
                    //LoadCompanyLogo(branchalias); //john added on 30-Sept-2021
                    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
                    {
                        //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,InventoryID,Module)" +
                        "values(@fileName,@BucketName,@CompanyName ,@StoreName,@Url,@Extention,@InventoryID,@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("@InventoryID",CondimentID),
                     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 UpdateCondiment = "Update {0}.Condiment set ImagePath = @ImagePath where CondimentID = @CondimentID";
                    string commandF = string.Format(UpdateCondiment, branchalias);

                    MySqlParameter[] parametersF =
                    {
                        new MySqlParameter("@ImagePath",Url),
                        new MySqlParameter("@CondimentID",CondimentID),
                     };

                    S3_LandingUPT = ObjMain.ExecuteQuery(commandF, parametersF);

                    //LoadLandingImage(branchalias);
                    //LoadCompanyLogo(branchalias); //john added on 30-Sept-2021


                    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
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Something Went Wrong !'); ", true);
                    }
                }
            }
        }
        
        public class Root
        {
            public string dbPath { get; set; }
        }

        public void Flag2Value()
        {
            string[] Printer = new string[20];

            if (chkRP19.Checked == true || chkRP18.Checked == true || chkRP17.Checked == true || chkRP16.Checked == true || chkRP15.Checked == true || chkRP14.Checked == true || chkRP13.Checked == true || chkRP12.Checked == true || chkRP11.Checked == true || chkRP10.Checked == true || chkRP9.Checked == true || chkRP8.Checked == true || chkRP7.Checked == true || chkRP6.Checked == true || chkRP5.Checked == true || chkRP4.Checked == true || chkRP3.Checked == true || chkRP2.Checked == true || chkRP1.Checked == true)
            {
                Printer[0] = "1";
            }
            else
            {
                Printer[0] = "0";
            }

            if (chkRP19.Checked == true)
            {
                Printer[1] = "1";
            }
            else
            {
                Printer[1] = "0";
            }

            if (chkRP18.Checked == true)
            {
                Printer[2] = "1";

            }
            else
            {
                Printer[2] = "0";
            }

            if (chkRP17.Checked == true)
            {
                Printer[3] = "1";
            }
            else
            {
                Printer[3] = "0";
            }

            if (chkRP16.Checked == true)
            {
                Printer[4] = "1";
            }
            else
            {
                Printer[4] = "0";
            }

            if (chkRP15.Checked == true)
            {
                Printer[5] = "1";
            }
            else
            {
                Printer[5] = "0";
            }

            if (chkRP14.Checked == true)
            {
                Printer[6] = "1";
            }
            else
            {
                Printer[6] = "0";
            }

            if (chkRP13.Checked == true)
            {
                Printer[7] = "1";

            }
            else
            {
                Printer[7] = "0";
            }

            if (chkRP12.Checked == true)
            {
                Printer[8] = "1";
            }
            else
            {
                Printer[8] = "0";
            }

            if (chkRP11.Checked == true)
            {
                Printer[9] = "1";
            }
            else
            {
                Printer[9] = "0";
            }

            if (chkRP10.Checked == true)
            {
                Printer[10] = "1";
            }
            else
            {
                Printer[10] = "0";
            }

            if (chkRP9.Checked == true)
            {
                Printer[11] = "1";
            }
            else
            {
                Printer[11] = "0";
            }

            if (chkRP8.Checked == true)
            {
                Printer[12] = "1";
            }
            else
            {
                Printer[12] = "0";
            }

            if (chkRP7.Checked == true)
            {
                Printer[13] = "1";

            }
            else
            {
                Printer[13] = "0";
            }

            if (chkRP6.Checked == true)
            {
                Printer[14] = "1";
            }
            else
            {
                Printer[14] = "0";
            }

            if (chkRP5.Checked == true)
            {
                Printer[15] = "1";

            }
            else
            {
                Printer[15] = "0";
            }

            if (chkRP4.Checked == true)
            {
                Printer[16] = "1";

            }
            else
            {
                Printer[16] = "0";
            }

            if (chkRP3.Checked == true)
            {
                Printer[17] = "1";

            }
            else
            {
                Printer[17] = "0";
            }

            if (chkRP2.Checked == true)
            {
                Printer[18] = "1";
            }
            else
            {
                Printer[18] = "0";
            }

            if (chkRP1.Checked == true)
            {
                Printer[19] = "1";

            }
            else
            {
                Printer[19] = "0";
            }

            StringBuilder BuildValue = new StringBuilder();
            foreach (string value in Printer)
            {
                BuildValue.Append(value);
            }

            //if (txtCategoryName.Text == "")
            //{
            //    btnSaveCategory.Visible = true;
            //    btnSaveCategory.CssClass = "btn btn-primary";

            //    btnUpdate.Visible = false;
            //    btnUpdate.CssClass = "btn btn-primary";

            //}
            //else
            //{
            //    btnUpdate.Visible = true;
            //    btnUpdate.CssClass = "btn btn-primary";

            //}

            HideCatPrinter.Value = BuildValue.ToString();
            lblmsgCate_Printer.Text = BuildValue.ToString();
            if(UpdateCondimentFlag(HideCatPrinter.Value) == "true")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Condiment Kitchenflag Successfully Updated')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error_msg", "alert(' Condiment Kithenflag failed to Update')", true);
            }
        }

        public void ResetCheckboxCP()
        {
            chkPrinterInven.Checked = false;
            chkRP19.Checked = false;
            chkRP18.Checked = false;
            chkRP17.Checked = false;
            chkRP16.Checked = false;
            chkRP15.Checked = false;
            chkRP14.Checked = false;
            chkRP13.Checked = false;
            chkRP12.Checked = false;
            chkRP11.Checked = false;
            chkRP10.Checked = false;
            chkRP9.Checked = false;
            chkRP8.Checked = false;
            chkRP7.Checked = false;
            chkRP6.Checked = false;
            chkRP5.Checked = false;
            chkRP4.Checked = false;
            chkRP3.Checked = false;
            chkRP2.Checked = false;
            chkRP1.Checked = false;
        }

        public string UpdateCondimentFlag(string KitchenFlag)
        {
            string sDB = string.Empty;
            string sCmd = string.Empty;
            string CondimentID = string.Empty;
            CondimentID = modallblCondmentID.Text;
            KitchenFlag = KitchenFlag.Substring(1);
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
            sDB = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);

            sCmd = "Update {0}.Condiment set kitchenFlag = '" + KitchenFlag + "' where CondimentID = @CondimentID";
            string command = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@CondimentID",CondimentID)
            };
            iUpdateCondimentFlag = ObjMain.ExecuteQuery(command, parameters);
            if (iUpdateCondimentFlag > 0)
            {
                return "true";
            }
            else
            {
                return "false";
            }            
        }

        public void LoadCondimentPrinterFlag(string Cmb_BranchName,string CondimentID)
        {
            //Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            //if (cmbBranches.Visible == false)
            //{

            //    BranchAlias = Session["Branch_HQ"].ToString();

            //}
            //else
            //{
            //    if (cmbBranches.SelectedItem.Text == "HQ")
            //    {
            //        // btnExcel.Enabled = true;
            //        // HQ Validation    02-12-21
            //        BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
            //        Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            //        UPDATEBRANCH(Cmb_BranchName);
            //        BranchAlias = Cmb_BranchName;
            //    }

            //    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;

            //    }
            //}


            DTCondiment = ObjSel.ReadCondiment(Cmb_BranchName, CondimentID);   
            RFlag2_Printer = "0" + DTCondiment.Rows[0]["kitchenflag"].ToString();
            //RFlag2_Printer = RFlag2_Printer

            char[] Flag2_Val = RFlag2_Printer.ToCharArray();

            string P0 = RFlag2_Printer[0].ToString();           //1: Inventory Flag ; 0:Category Flag  
            string P1 = RFlag2_Printer[1].ToString();           // Print on Remote Printer 19                               
            string P2 = RFlag2_Printer[2].ToString();           // Print on Remote Printer 18  
            string P3 = RFlag2_Printer[3].ToString();           //  Print on Remote Printer 17  
            string P4 = RFlag2_Printer[4].ToString();           //  Print on Remote Printer 16  
            string P5 = RFlag2_Printer[5].ToString();          //   Print on Remote Printer 15  
            string P6 = RFlag2_Printer[6].ToString();          //   Print on Remote Printer 14   
            string P7 = RFlag2_Printer[7].ToString();          //  Print on Remote Printer 13  
            string P8 = RFlag2_Printer[8].ToString();          //  Print on Remote Printer 12 
            string P9 = RFlag2_Printer[9].ToString();          //  Print on Remote Printer 11 
            string P10 = RFlag2_Printer[10].ToString();       //   Print on Remote Printer 10
            string P11 = RFlag2_Printer[11].ToString();       //   Print on Remote Printer 9
            string P12 = RFlag2_Printer[12].ToString();       //   Print on Remote Printer 8
            string P13 = RFlag2_Printer[13].ToString();       //   Print on Remote Printer 7
            string P14 = RFlag2_Printer[14].ToString();       //   Print on Remote Printer 6
            string P15 = RFlag2_Printer[15].ToString();       //   Print on Remote Printer 5
            string P16 = RFlag2_Printer[16].ToString();       //   Print on Remote Printer 4
            string P17 = RFlag2_Printer[17].ToString();       //   Print on Remote Printer 3
            string P18 = RFlag2_Printer[18].ToString();       //   Print on Remote Printer 2 
            string P19 = RFlag2_Printer[19].ToString();       //   Print on Remote Printer 1

            // Get the Printer Value and Its Lable 


            string Printer_Query = "select id,PrinterNo,PrinterName,Visible  from  " + Cmb_BranchName + ".PrinterLable;";
            DTPrinterList = ObjCloudMain.GetData_DT(Printer_Query);

            if (DTPrinterList.Rows.Count > 0)
            {
                // Load 19th 

                RPrintno19 = DTPrinterList.Rows[0]["Visible"].ToString();
                PrinterName19 = DTPrinterList.Rows[0]["PrinterName"].ToString();
                lblLPrinter19.Text = PrinterName19;  // Assign to  Lable

                if (RPrintno19.Equals("0"))
                {
                    chkRP19.Visible = false;
                    lblLPrinter19.Visible = false;
                }
                else
                {
                    chkRP19.Visible = true;
                    lblLPrinter19.Visible = true;
                }


                // Load 18th
                RPrintno18 = DTPrinterList.Rows[1]["Visible"].ToString();
                PrinterName18 = DTPrinterList.Rows[1]["PrinterName"].ToString();
                lblLPrinter18.Text = PrinterName18;  // Assign to  Lable

                if (RPrintno18.Equals("0"))
                {
                    chkRP18.Visible = false;
                    lblLPrinter18.Visible = false;
                }
                else
                {
                    chkRP18.Visible = true;
                    lblLPrinter18.Visible = true;

                }


                // Load 17th 
                RPrintno17 = DTPrinterList.Rows[2]["Visible"].ToString();
                PrinterName17 = DTPrinterList.Rows[2]["PrinterName"].ToString();
                lblLPrinter17.Text = PrinterName17;  // Assign to  Lable

                if (RPrintno17.Equals("0"))
                {
                    chkRP17.Visible = false;
                    lblLPrinter17.Visible = false;
                }
                else
                {
                    chkRP17.Visible = true;
                    lblLPrinter17.Visible = true;
                }



                // Load 16th 
                RPrintno16 = DTPrinterList.Rows[3]["Visible"].ToString();
                PrinterName16 = DTPrinterList.Rows[3]["PrinterName"].ToString();
                lblLPrinter16.Text = PrinterName16;  // Assign to  Lable
                if (RPrintno16.Equals("0"))
                {
                    chkRP16.Visible = false;
                    lblLPrinter16.Visible = false;

                }
                else
                {
                    chkRP16.Visible = true;
                    lblLPrinter16.Visible = true;

                }
                // Load 15th 
                RPrintno15 = DTPrinterList.Rows[4]["Visible"].ToString();
                PrinterName15 = DTPrinterList.Rows[4]["PrinterName"].ToString();
                lblLPrinter15.Text = PrinterName15;  // Assign to  Lable
                if (RPrintno15.Equals("0"))
                {
                    chkRP15.Visible = false;
                    lblLPrinter15.Visible = false;

                }
                else
                {
                    chkRP15.Visible = true;
                    lblLPrinter15.Visible = true;
                }
                // Load 14th
                RPrintno14 = DTPrinterList.Rows[5]["Visible"].ToString();
                PrinterName14 = DTPrinterList.Rows[5]["PrinterName"].ToString();
                lblLPrinter14.Text = PrinterName14;  // Assign to  Lable
                if (RPrintno14.Equals("0"))
                {
                    chkRP14.Visible = false;
                    lblLPrinter14.Visible = false;
                }
                else
                {
                    chkRP14.Visible = true;
                    lblLPrinter14.Visible = true;
                }
                // Load 13th
                RPrintno13 = DTPrinterList.Rows[6]["Visible"].ToString();
                PrinterName13 = DTPrinterList.Rows[6]["PrinterName"].ToString();
                lblLPrinter13.Text = PrinterName13;  // Assign to  Lable
                if (RPrintno13.Equals("0"))
                {
                    chkRP13.Visible = false;
                    lblLPrinter13.Visible = false;
                }
                else
                {
                    chkRP13.Visible = false;
                    lblLPrinter13.Visible = false;
                }

                // Load 12th
                RPrintno12 = DTPrinterList.Rows[7]["Visible"].ToString();
                PrinterName12 = DTPrinterList.Rows[7]["PrinterName"].ToString();
                lblLPrinter12.Text = PrinterName12;  // Assign to  Lable
                if (RPrintno12.Equals("0"))
                {
                    chkRP12.Visible = false;
                    lblLPrinter12.Visible = false;
                }
                else
                {
                    chkRP12.Visible = true;
                    lblLPrinter12.Visible = true;
                }



                // Load 11th
                RPrintno11 = DTPrinterList.Rows[8]["Visible"].ToString();
                PrinterName11 = DTPrinterList.Rows[8]["PrinterName"].ToString();
                lblLPrinter11.Text = PrinterName11;  // Assign to  Lable
                if (RPrintno11.Equals("0"))
                {
                    chkRP11.Visible = false;
                    lblLPrinter11.Visible = false;
                }
                else
                {
                    chkRP11.Visible = true;
                    lblLPrinter11.Visible = true;
                }


                // Load 10th 
                RPrintno10 = DTPrinterList.Rows[9]["Visible"].ToString();
                PrinterName10 = DTPrinterList.Rows[9]["PrinterName"].ToString();
                lblLPrinter10.Text = PrinterName10;  // Assign to  Lable
                if (RPrintno10.Equals("0"))
                {
                    chkRP10.Visible = false;
                    lblLPrinter10.Visible = false;
                }
                else
                {
                    chkRP10.Visible = true;
                    lblLPrinter10.Visible = true;
                }

                // Load 9th 
                RPrintno9 = DTPrinterList.Rows[10]["Visible"].ToString();
                PrinterName9 = DTPrinterList.Rows[10]["PrinterName"].ToString();
                lblLPrinter9.Text = PrinterName9;  // Assign to  Lable
                if (RPrintno9.Equals("0"))
                {
                    chkRP9.Visible = false;
                    lblLPrinter9.Visible = false;
                }
                else
                {
                    chkRP9.Visible = true;
                    lblLPrinter9.Visible = true;
                }

                // Load 8th 
                RPrintno8 = DTPrinterList.Rows[11]["Visible"].ToString();
                PrinterName8 = DTPrinterList.Rows[11]["PrinterName"].ToString();
                lblLPrinter8.Text = PrinterName8;  // Assign to  Lable
                if (RPrintno8.Equals("0"))
                {
                    chkRP8.Visible = false;
                    lblLPrinter8.Visible = false;
                }
                else
                {
                    chkRP8.Visible = false;
                    lblLPrinter8.Visible = false;
                }

                // Load 7th 
                RPrintno7 = DTPrinterList.Rows[12]["Visible"].ToString();
                PrinterName7 = DTPrinterList.Rows[12]["PrinterName"].ToString();
                lblLPrinter7.Text = PrinterName7;  // Assign to  Lable
                if (RPrintno7.Equals("0"))
                {
                    chkRP7.Visible = false;
                    lblLPrinter7.Visible = false;
                }
                else
                {
                    chkRP7.Visible = true;
                    lblLPrinter7.Visible = true;

                }


                // Load 6th 
                RPrintno6 = DTPrinterList.Rows[13]["Visible"].ToString();
                PrinterName6 = DTPrinterList.Rows[13]["PrinterName"].ToString();
                lblLPrinter6.Text = PrinterName6;  // Assign to  Lable
                if (RPrintno6.Equals("0"))
                {
                    chkRP6.Visible = false;
                    lblLPrinter6.Visible = false;
                }
                else
                {
                    chkRP6.Visible = true;
                    lblLPrinter6.Visible = true;

                }

                // Load 5th 
                RPrintno5 = DTPrinterList.Rows[14]["Visible"].ToString();
                PrinterName5 = DTPrinterList.Rows[14]["PrinterName"].ToString();
                lblLPrinter5.Text = PrinterName5;  // Assign to  Lable
                if (RPrintno5.Equals("0"))
                {
                    chkRP5.Visible = false;
                    lblLPrinter5.Visible = false;
                }
                else
                {

                    chkRP5.Visible = true;
                    lblLPrinter5.Visible = true;
                }
                // Load 4th 
                RPrintno4 = DTPrinterList.Rows[15]["Visible"].ToString();
                PrinterName4 = DTPrinterList.Rows[15]["PrinterName"].ToString();
                lblLPrinter4.Text = PrinterName4;  // Assign to  Lable
                if (RPrintno4.Equals("0"))
                {
                    chkRP4.Visible = false;
                    lblLPrinter4.Visible = false;

                }
                else
                {
                    chkRP4.Visible = true;
                    lblLPrinter4.Visible = true;

                }

                // Load 3rd 
                RPrintno3 = DTPrinterList.Rows[16]["Visible"].ToString();
                PrinterName3 = DTPrinterList.Rows[16]["PrinterName"].ToString();
                lblLPrinter3.Text = PrinterName3;  // Assign to  Lable
                if (RPrintno3.Equals("0"))
                {
                    chkRP3.Visible = false;
                    lblLPrinter3.Visible = false;

                }
                else
                {
                    chkRP3.Visible = true;
                    lblLPrinter3.Visible = true;
                }

                // Load 2nd 
                RPrintno2 = DTPrinterList.Rows[17]["Visible"].ToString();
                PrinterName2 = DTPrinterList.Rows[17]["PrinterName"].ToString();
                lblLPrinter2.Text = PrinterName2;  // Assign to  Lable

                if (RPrintno2.Equals("0"))
                {
                    chkRP2.Visible = false;
                    lblLPrinter2.Visible = false;
                }
                else
                {
                    chkRP2.Visible = true;
                    lblLPrinter2.Visible = true;

                }

                // Load 1st
                RPrintno1 = DTPrinterList.Rows[18]["Visible"].ToString();
                PrinterName1 = DTPrinterList.Rows[18]["PrinterName"].ToString();
                lblLPrinter1.Text = PrinterName1;  // Assign to  Lable

                if (RPrintno1.Equals("0"))
                {
                    chkRP1.Visible = false;
                    lblLPrinter1.Visible = false;

                }
                else
                {
                    chkRP1.Visible = true;
                    lblLPrinter1.Visible = true;

                }


            }

            if (RActive_Stauts == "-1")
            {
                //chkActiveStatus.Checked = true;
            }
            else
            {
                //chkActiveStatus.Checked = false;
            }

            // Assign Values to Checkbox : 

            if (P0.Equals("1"))
            {
                chkPrinterInven.Checked = true;

            }
            else
            {
                chkPrinterInven.Checked = false;
            }

            //Check the Visible value For Printer 19
            if (RPrintno19.Equals("1"))
            {
                if (P1.Equals("1"))
                {
                    chkRP19.Checked = true;
                    chkRP19.Visible = true;
                    lblLPrinter19.Visible = true;
                }
                else
                {
                    chkRP19.Checked = false;
                    chkRP19.Visible = true;
                    lblLPrinter19.Visible = true;
                }
            }
            else
            {
                chkRP19.Visible = false;
                lblLPrinter19.Visible = false;
            }
            // Check the Visible value For Printer 18

            if (RPrintno18.Equals("1"))
            {
                if (P2.Equals("1"))
                {
                    chkRP18.Checked = true;

                    chkRP18.Visible = true;
                    lblLPrinter18.Visible = true;
                }
                else
                {
                    chkRP18.Checked = false;

                    chkRP18.Visible = true;
                    lblLPrinter18.Visible = true;
                }



            }
            else
            {
                chkRP18.Visible = false;
                lblLPrinter18.Visible = false;

            }

            // Check the Visible value For Printer 17
            if (RPrintno17.Equals("1"))
            {
                if (P3.Equals("1"))
                {
                    chkRP17.Checked = true;
                    chkRP17.Visible = true;
                    lblLPrinter18.Visible = true;

                }
                else
                {
                    chkRP17.Checked = false;
                    chkRP17.Visible = true;
                    lblLPrinter17.Visible = true;

                }

            }
            else
            {
                chkRP17.Visible = false;
                lblLPrinter17.Visible = false;

            }

            // Check the Visible value For Printer 16
            if (RPrintno16.Equals("1"))
            {
                if (P4.Equals("1"))
                {
                    chkRP16.Checked = true;
                    chkRP16.Visible = true;
                    lblLPrinter16.Visible = true;
                }
                else
                {
                    chkRP16.Checked = false;
                    chkRP16.Visible = true;
                    lblLPrinter16.Visible = true;
                }

            }
            else
            {
                chkRP16.Visible = false;
                lblLPrinter16.Visible = false;

            }

            // Check the Visible value For Printer 15
            if (RPrintno15.Equals("1"))
            {
                if (P5.Equals("1"))
                {
                    chkRP15.Checked = true;

                }
                else
                {
                    chkRP15.Checked = false;
                    chkRP15.Visible = true;
                    lblLPrinter15.Visible = true;
                }

            }
            else
            {
                chkRP15.Visible = false;
                lblLPrinter15.Visible = false;

            }

            // Check the Visible value For Printer 14 : 

            if (RPrintno14.Equals("1"))
            {
                if (P6.Equals("1"))
                {
                    chkRP14.Checked = true;
                    chkRP14.Visible = true;
                    lblLPrinter14.Visible = true;
                }
                else
                {
                    chkRP14.Checked = false;
                    chkRP14.Visible = true;
                    lblLPrinter14.Visible = true;
                }

            }
            else
            {
                chkRP14.Visible = false;
                lblLPrinter14.Visible = false;
            }

            // Check the Visible value For Printer 13
            if (RPrintno13.Equals("1"))
            {
                if (P7.Equals("1"))
                {
                    chkRP13.Checked = true;
                    chkRP13.Visible = true;
                    lblLPrinter13.Visible = true;
                }
                else
                {
                    chkRP13.Checked = false;
                    chkRP13.Visible = true;
                    lblLPrinter13.Visible = true;


                }

            }
            else
            {
                chkRP13.Visible = false;
                lblLPrinter13.Visible = false;

            }

            // Check the Visible value For Printer 12
            if (RPrintno12.Equals("1"))
            {
                if (P8.Equals("1"))
                {
                    chkRP12.Checked = true;
                    chkRP12.Visible = true;
                    lblLPrinter12.Visible = true;
                }
                else
                {
                    chkRP12.Checked = false;
                    chkRP12.Visible = true;
                    lblLPrinter12.Visible = true;
                }


            }
            else
            {
                chkRP12.Visible = false;
                lblLPrinter12.Visible = false;
            }

            // Check the Visible value For Printer 11
            if (RPrintno11.Equals("1"))
            {
                if (P9.Equals("1"))
                {
                    chkRP11.Checked = true;
                    chkRP11.Visible = true;
                    lblLPrinter11.Visible = true;
                }
                else
                {
                    chkRP11.Checked = false;
                    chkRP11.Visible = true;
                    lblLPrinter11.Visible = true;
                }

            }
            else
            {
                chkRP11.Visible = false;
                lblLPrinter11.Visible = false;
            }

            // Check the Visible value For Printer 10
            if (RPrintno10.Equals("1"))
            {
                if (P10.Equals("1"))
                {
                    chkRP10.Checked = true;
                    chkRP10.Visible = true;
                    lblLPrinter10.Visible = true;
                }
                else
                {
                    chkRP10.Checked = false;
                    chkRP10.Visible = true;
                    lblLPrinter10.Visible = true;
                }


            }
            else
            {
                chkRP10.Visible = false;
                lblLPrinter10.Visible = false;
            }
            // Check the Visible value For Printer 9

            if (RPrintno9.Equals("1"))
            {
                if (P11.Equals("1"))
                {
                    chkRP9.Checked = true;
                    chkRP9.Visible = true;
                    lblLPrinter9.Visible = true;
                }
                else
                {
                    chkRP9.Checked = false;
                    chkRP9.Visible = true;
                    lblLPrinter9.Visible = true;
                }
            }
            else
            {
                chkRP9.Visible = false;
                lblLPrinter9.Visible = false;
            }
            // Check the Visible value For Printer 8

            if (RPrintno8.Equals("1"))
            {
                if (P12.Equals("1"))
                {
                    chkRP8.Checked = true;
                    chkRP8.Visible = true;
                    lblLPrinter8.Visible = true;
                }
                else
                {
                    chkRP8.Checked = false;
                    chkRP8.Visible = true;
                    lblLPrinter8.Visible = true;
                }

            }
            else
            {
                chkRP8.Visible = false;
                lblLPrinter8.Visible = false;
            }

            // Check the Visible value For Printer 7
            if (RPrintno7.Equals("1"))
            {
                if (P13.Equals("1"))
                {
                    chkRP7.Checked = true;
                    chkRP7.Visible = true;
                    lblLPrinter7.Visible = true;
                }
                else
                {
                    chkRP7.Checked = false;
                    chkRP7.Visible = true;
                    lblLPrinter7.Visible = true;

                }

            }
            else
            {
                chkRP7.Visible = false;
                lblLPrinter7.Visible = false;

            }
            // Check the Visible value For Printer 6

            if (RPrintno6.Equals("1"))
            {
                if (P14.Equals("1"))
                {
                    chkRP6.Checked = true;
                    chkRP6.Visible = true;
                    lblLPrinter6.Visible = true;
                }
                else
                {
                    chkRP6.Checked = false;
                    chkRP6.Visible = true;
                    lblLPrinter6.Visible = true;
                }

            }
            else
            {
                chkRP6.Visible = false;
                lblLPrinter6.Visible = false;
            }

            // Check the Visible value For Printer 5

            if (RPrintno5.Equals("1"))
            {
                if (P15.Equals("1"))
                {
                    chkRP5.Checked = true;
                    chkRP5.Visible = true;
                    lblLPrinter5.Visible = true;
                }
                else
                {
                    chkRP5.Checked = false;
                    chkRP5.Visible = true;
                    lblLPrinter5.Visible = true;
                }
            }
            else
            {
                chkRP5.Visible = false;
                lblLPrinter5.Visible = false;
            }

            // Check the Visible value For Printer 4
            if (RPrintno4.Equals("1"))
            {
                if (P16.Equals("1"))
                {
                    chkRP4.Checked = true;
                    chkRP4.Visible = true;
                    lblLPrinter4.Visible = true;
                }
                else
                {
                    chkRP4.Checked = false;
                    chkRP4.Visible = true;
                    lblLPrinter4.Visible = true;
                }

            }
            else
            {
                chkRP4.Visible = false;
                lblLPrinter4.Visible = false;

            }


            // Check the Visible value For Printer 3
            if (RPrintno3.Equals("1"))
            {
                if (P17.Equals("1"))
                {
                    chkRP3.Checked = true;
                    chkRP3.Visible = true;
                    lblLPrinter3.Visible = true;
                }
                else
                {
                    chkRP3.Checked = false;
                    chkRP3.Visible = true;
                    lblLPrinter3.Visible = true;
                }
            }
            else
            {
                chkRP3.Visible = false;
                lblLPrinter3.Visible = false;
            }
            // Check the Visible value For Printer 2

            if (RPrintno2.Equals("1"))
            {
                if (P18.Equals("1"))
                {
                    chkRP2.Checked = true;
                    chkRP2.Visible = true;
                    lblLPrinter2.Visible = true;
                }
                else
                {
                    chkRP2.Checked = false;
                    chkRP2.Visible = true;
                    lblLPrinter2.Visible = true;
                }


            }
            else
            {
                chkRP2.Visible = false;
                lblLPrinter2.Visible = false;
            }

            // Check the Visible value For Printer 1
            if (RPrintno1.Equals("1"))
            {
                if (P19.Equals("1"))
                {
                    chkRP1.Checked = true;
                    chkRP1.Visible = true;
                    lblLPrinter1.Visible = true;
                }
                else
                {
                    chkRP1.Checked = false;
                    chkRP1.Visible = true;
                    lblLPrinter1.Visible = true;
                }

            }
            else
            {
                chkRP1.Visible = false;
                lblLPrinter1.Visible = false;
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ModalView", "<script> var modal = document.getElementById('KitchenFlagModal');modal.style.display = 'block';</script>", false);
        }

        protected void btnSavePrinter_Click(object sender, EventArgs e)
        {
            Flag2Value();
            ResetCheckboxCP();
        }
     
    }
}