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;

namespace SUNWEB
{
    public partial class Modifier : 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_Modifier = string.Empty;
        string Branchidval = string.Empty;
        string BranchFullName = string.Empty;
        string Curr_BranchFullName = string.Empty;
        string Cmb_BranchName = string.Empty;

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

        string Vw_Chk = string.Empty;


        Int32 iAddModifier = 0;
        Int32 iUpdateModifier = 0;
        Int32 iDeleteModifier = 0;

        string RBranchid = string.Empty;
        string Branchid = string.Empty;
        string BranchAlias = string.Empty;
        string ReadHQ = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            PID = "31";    // This is for Modifier Page . 
            if (!IsPostBack)
            {
                //txtStartDt.Text = Curr_DateOnly;
                //txtEndDt.Text = Curr_DateOnly;
            }
            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)
                {
                    //LoadBranchName4SuperAdmin();
                    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)
                {
                    //LoadBranchName4SuperAdmin();
                    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)
                {
                    //LoadBranchName();
                    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_Modifier"].ToString() == "N") || (Session["Page_Acess"].ToString() == "N"))
                {
                    Response.Redirect("DeniedPage.aspx");
                }
                else
                {
                    // lblMsgTotalSelection.Text = "Item Sale  Between" + "&nbsp;&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  and  &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                    if (!IsPostBack)
                    {
                        if (Session["Isdowld_Acess"].ToString() == "N")
                        {
                            // btnExcel.Enabled = false;
                            Response.Write(@"<script language='javascript'>alert('No Access To download.')</script>");
                        }
                        else
                        {
                            btnGetReports.Visible = true;

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

                        }


                    }

                }

            }
            else
            {

            }

            if (!IsPostBack)
            {
                BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
                GrdLinkView.DataSource = null;
                GrdLinkView.DataBind();
                lblHeader.Text = "";
                ModifierList(Cmb_BranchName);
                ResetFields();
            }
        }

        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 = ObjMain.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_Modifier = DtLicense.Rows[0]["Modifier"].ToString();
                Session["L_Modifier"] = L_Modifier;
            }

            if ((Session["L_Modifier"] == null) || Session["L_Modifier"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            {
                //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 = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                // BindGridview(ActiveCallvalue, txtStartDt.Text, txtEndDt.Text);

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

                }
                #endregion

                // HQ Validation    02-12-21
                // Include the Load Functions
                // Hided on 08-10-255 
                //  LoadInventoryview();     
                //LoadPIInventoryview(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='{0}' where Userid={1};";
                string command = string.Format(QueryCurr_Select, ActiveCallvalue, Useridvalue);
                S = ObjMain.ExecuteNonQuery(command);
            }
            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);
            //BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            //Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            //if (cmbBranches.SelectedIndex != 0)
            //{
            //    GrdLinkView.DataSource = null;
            //    GrdLinkView.DataBind();
            //    lblHeader.Text = "";
            //    //Reset all fields
            //    ModifierList(Cmb_BranchName);
            //    ResetFields();
            //}
            //UPDATEBRANCH(Cmb_BranchName);
            //Response.Redirect(Request.RawUrl); //john added on 16-Nov-2021 reload page when changing branch
            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("Modifier.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_Modifier = DtLicense.Rows[0]["MODIFIER"].ToString();
                    Session["L_Modifier"] = L_Modifier;
                }

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

        private void ResetFields()
        {
            //Reset all fields
            lblModifierControlID.Text = "";

            cmbStep1.SelectedValue = "0";
            cmbLevel1.SelectedValue = "0";
            cmbLevel2.SelectedValue = "0";
            cmbLevel3.SelectedValue = "0";
            cmbLevel4.SelectedValue = "0";
            cmbLevel5.SelectedValue = "0";
            cmbLevel6.SelectedValue = "0";
            cmbLevel7.SelectedValue = "0";
            cmbLevel8.SelectedValue = "0";
            cmbLevel9.SelectedValue = "0";
            cmbLevel10.SelectedValue = "0";

            lblStep1Desc.Text = "";
            lblLevel1Desc.Text = "";
            lblLevel2Desc.Text = "";
            lblLevel3Desc.Text = "";
            lblLevel4Desc.Text = "";
            lblLevel5Desc.Text = "";
            lblLevel6Desc.Text = "";
            lblLevel7Desc.Text = "";
            lblLevel8Desc.Text = "";
            lblLevel9Desc.Text = "";
            lblLevel10Desc.Text = "";

            txtMin1.Text = "0";
            txtMin2.Text = "0";
            txtMin3.Text = "0";
            txtMin4.Text = "0";
            txtMin5.Text = "0";
            txtMin6.Text = "0";
            txtMin7.Text = "0";
            txtMin8.Text = "0";
            txtMin9.Text = "0";
            txtMin10.Text = "0";

            txtMax1.Text = "0";
            txtMax2.Text = "0";
            txtMax3.Text = "0";
            txtMax4.Text = "0";
            txtMax5.Text = "0";
            txtMax6.Text = "0";
            txtMax7.Text = "0";
            txtMax8.Text = "0";
            txtMax9.Text = "0";
            txtMax10.Text = "0";


        }

        protected void btnStep_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);
            if (cmbStep1.SelectedValue != "0") // Inventory
            {
                Step1ViewList(Cmb_BranchName, cmbStep1.SelectedValue);
                lblHeader.Text = "Step1 " + cmbStep1.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModal();", true);
            }

            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel1_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel1.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 1 " + cmbLevel1.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel2_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel2.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 2 " + cmbLevel2.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel3_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel3.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 3 " + cmbLevel3.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel4_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel4.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 4 " + cmbLevel4.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel5_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel5.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 5 " + cmbLevel5.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel6_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel6.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 6 " + cmbLevel6.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel7_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel7.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 7 " + cmbLevel7.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel8_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel8.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 8 " + cmbLevel7.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel9_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel9.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 9 " + cmbLevel9.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }

        }

        protected void btnLevel10_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);
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            if (cmbLevel10.SelectedValue == "8")
            {
                LevelsViewList(Cmb_BranchName);
                lblHeader.Text = "Level 10 " + cmbLevel10.SelectedItem.Text;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }
        }

        protected void btnSaveModifier_click(object sender, EventArgs e)
        {

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

            if (lblLevel1Desc.Text != "" && txtMax1.Text == "0") //John added on 18-June-2021 Validate if max is zero
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 1 max cannot be 0(zero).')", true);
                txtMax1.Attributes.Add("onfocus", "this.select();");
                txtMax1.Focus();
                return;
            }

            if (lblLevel2Desc.Text != "" && txtMax2.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 2 max cannot be 0(zero).')", true);
                txtMax2.Attributes.Add("onfocus", "this.select();");
                txtMax2.Focus();
                return;
            }

            if (lblLevel3Desc.Text != "" && txtMax3.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 3 max cannot be 0(zero).')", true);
                txtMax3.Attributes.Add("onfocus", "this.select();");
                txtMax3.Focus();
                return;
            }

            if (lblLevel4Desc.Text != "" && txtMax4.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 4 max cannot be 0(zero).')", true);
                txtMax4.Attributes.Add("onfocus", "this.select();");
                txtMax4.Focus();
                return;
            }

            if (lblLevel5Desc.Text != "" && txtMax5.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 5 max cannot be 0(zero).')", true);
                txtMax5.Attributes.Add("onfocus", "this.select();");
                txtMax5.Focus();
                return;
            }

            if (lblLevel6Desc.Text != "" && txtMax6.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 6 max cannot be 0(zero).')", true);
                txtMax6.Attributes.Add("onfocus", "this.select();");
                txtMax6.Focus();
                return;
            }

            if (lblLevel7Desc.Text != "" && txtMax7.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 7 max cannot be 0(zero).')", true);
                txtMax7.Attributes.Add("onfocus", "this.select();");
                txtMax7.Focus();
                return;
            }

            if (lblLevel8Desc.Text != "" && txtMax8.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 8 max cannot be 0(zero).')", true);
                txtMax8.Attributes.Add("onfocus", "this.select();");
                txtMax8.Focus();
                return;
            }

            if (lblLevel9Desc.Text != "" && txtMax9.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 9 max cannot be 0(zero).')", true);
                txtMax9.Attributes.Add("onfocus", "this.select();");
                txtMax9.Focus();
                return;
            }

            if (lblLevel10Desc.Text != "" && txtMax10.Text == "0")
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Level 10 max cannot be 0(zero).')", true);
                txtMax10.Attributes.Add("onfocus", "this.select();");
                txtMax10.Focus();
                return;
            }


            if (cmbStep1.SelectedValue != "0")
            {
                if (lblModifierControlID.Text == "")
                {
                    SaveModifier(Cmb_BranchName);
                    ModifierList(Cmb_BranchName);

                }
                else
                {
                    UpdateModifier(Cmb_BranchName, int.Parse(Microsoft.Security.Application.Encoder.HtmlEncode(lblModifierControlID.Text.Trim())));
                    ModifierList(Cmb_BranchName);
                }
                ResetFields();
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Invalid Salection for Type')", true);
            }
            //Response.Redirect(Request.Url.ToString());
        }

        protected void btnClear_click(object sender, EventArgs e)
        {
            ResetFields();
        }

        protected void btnSelect_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);

            foreach (GridViewRow row in GrdLinkView.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkRow = (row.Cells[0].FindControl("chkSelect") as CheckBox);
                    if (chkRow.Checked)
                    {
                        string sRow1 = (row.Cells[1].FindControl("lblID") as Label).Text;
                        string sRow2 = (row.Cells[1].FindControl("lblName") as Label).Text;

                        lblStep1Barcode.Text = sRow1;
                        lblStep1Desc.Text = sRow2;

                        if (int.Parse(cmbStep1.SelectedValue) > 2) //john added on 14-Jan-2025 for Group's
                        {
                            lblStep1Barcode.Text = sRow2.Trim();
                            lblStep1Desc.Text = sRow2.Trim();
                        }

                    }
                }
            }
        }

        protected void btnUpdate_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);

            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("ControlID"), new DataColumn("ControlType") });
            foreach (GridViewRow row in grdModList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkRow = (row.Cells[0].FindControl("chkSelectMod") as CheckBox);
                    if (chkRow.Checked)
                    {
                        string sRow1 = (row.Cells[1].FindControl("lblControlID") as Label).Text;
                        if (GetControlIDDetails(Cmb_BranchName, int.Parse(sRow1)) == "true")
                        {
                            chkRow.Checked = false;
                        }
                    }
                }
            }
            //foreach (GridViewRow row in GrdLinkView.Rows)
            //{
            //    if(row.RowType == DataControlRowType.DataRow)
            //    {
            //        CheckBox chkRow = (row.Cells[0].FindControl("chkSelect") as CheckBox);
            //        if (chkRow.Checked)
            //        {
            //            string sRow1 = (row.Cells[1].FindControl("lblID") as Label).Text;
            //            if (GetControlIDDetails(Cmb_BranchName, int.Parse(sRow1)) == "true")
            //            {
            //                chkRow.Checked = false;
            //            }
            //        }
            //    }
            //}
        }

        protected void btnDelete_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);

            if (lblModifierControlID.Text != "")
            {
                DeleteModifer(Cmb_BranchName, lblModifierControlID.Text.Trim());
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error_Msg", "alert('Please select modifier to delete.')", true);
            }


            //DataTable dt = new DataTable();
            //dt.Columns.AddRange(new DataColumn[2] { new DataColumn("ControlID"), new DataColumn("ControlType") });
            //foreach (GridViewRow row in grdModList.Rows)
            //{
            //    CheckBox chkRow = (row.Cells[0].FindControl("chkSelectMod") as CheckBox);
            //    if (chkRow.Checked)
            //    {
            //        string sRow1 = (row.Cells[1].FindControl("lblControlID") as Label).Text;
            //        DeleteModifer(Cmb_BranchName, sRow1);
            //    }
            //}

        }

        protected void cmbStep1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblStep1Barcode.Text = "";
            lblStep1Desc.Text = "";
        }

        protected void cmbLevel1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel1ID.Text = "";
            lblLevel1Desc.Text = "";
            txtMin1.Text = "0";
            txtMax1.Text = "0";
        }

        protected void cmbLevel2_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel2ID.Text = "";
            lblLevel2Desc.Text = "";
            txtMin2.Text = "0";
            txtMax2.Text = "0";
        }

        protected void cmbLevel3_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel3ID.Text = "";
            lblLevel3Desc.Text = "";
            txtMin3.Text = "0";
            txtMax3.Text = "0";
        }

        protected void cmbLevel4_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel4ID.Text = "";
            lblLevel4Desc.Text = "";
            txtMin4.Text = "0";
            txtMax4.Text = "0";
        }

        protected void cmbLevel5_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel5ID.Text = "";
            lblLevel5Desc.Text = "";
            txtMin5.Text = "0";
            txtMax5.Text = "0";
        }

        protected void cmbLevel6_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel6ID.Text = "";
            lblLevel6Desc.Text = "";
            txtMin6.Text = "0";
            txtMax6.Text = "0";
        }

        protected void cmbLevel7_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel7ID.Text = "";
            lblLevel7Desc.Text = "";
            txtMin7.Text = "0";
            txtMax7.Text = "0";
        }

        protected void cmbLevel8_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel8ID.Text = "";
            lblLevel8Desc.Text = "";
            txtMin8.Text = "0";
            txtMax8.Text = "0";
        }

        protected void cmbLevel9_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel9ID.Text = "";
            lblLevel9Desc.Text = "";
            txtMin9.Text = "0";
            txtMax9.Text = "0";
        }

        protected void cmbLevel10_SelectedIndexChanged(object sender, EventArgs e)
        {
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            lblHeader.Text = "";

            lblLevel10ID.Text = "";
            lblLevel10Desc.Text = "";
            txtMin10.Text = "0";
            txtMax10.Text = "0";
        }

        protected void chkSelect_CheckedChanged(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);

            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("row1"), new DataColumn("row2") });
            foreach (GridViewRow row in GrdLinkView.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkRow = (row.Cells[0].FindControl("chkSelect") as CheckBox);
                    if (chkRow.Checked)
                    {
                        string sRow1 = (row.Cells[1].FindControl("lblID") as Label).Text;
                        string sRow2 = (row.Cells[2].FindControl("lblName") as Label).Text;

                        //txtLGCondimentID.Text = sRow1;
                        //txtLGCondimentName.Text = sRow2;


                        if (lblHeader.Text == "Step1 Inventory")
                        {
                            if (ValidateItem(Cmb_BranchName, cmbStep1.SelectedValue, sRow1) == "false")
                            {
                                lblStep1Barcode.Text = sRow1;
                                lblStep1Desc.Text = sRow2;
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error_Msg", "alert('Item already linked ')", true);
                                chkRow.Checked = false;
                            }
                        }

                        if (lblHeader.Text == "Level 1 Condiment Group")
                        {
                            lblLevel1ID.Text = sRow1;
                            lblLevel1Desc.Text = sRow2;
                            txtMax1.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 2 Condiment Group")
                        {
                            lblLevel2ID.Text = sRow1;
                            lblLevel2Desc.Text = sRow2;
                            txtMax2.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }


                        if (lblHeader.Text == "Level 3 Condiment Group")
                        {
                            lblLevel3ID.Text = sRow1;
                            lblLevel3Desc.Text = sRow2;
                            txtMax3.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }


                        if (lblHeader.Text == "Level 4 Condiment Group")
                        {
                            lblLevel4ID.Text = sRow1;
                            lblLevel4Desc.Text = sRow2;
                            txtMax4.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }


                        if (lblHeader.Text == "Level 5 Condiment Group")
                        {
                            lblLevel5ID.Text = sRow1;
                            lblLevel5Desc.Text = sRow2;
                            txtMax5.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 6 Condiment Group")
                        {
                            lblLevel6ID.Text = sRow1;
                            lblLevel6Desc.Text = sRow2;
                            txtMax6.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 7 Condiment Group")
                        {
                            lblLevel7ID.Text = sRow1;
                            lblLevel7Desc.Text = sRow2;
                            txtMax7.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 8 Condiment Group")
                        {
                            lblLevel8ID.Text = sRow1;
                            lblLevel8Desc.Text = sRow2;
                            txtMax8.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 9 Condiment Group")
                        {
                            lblLevel9ID.Text = sRow1;
                            lblLevel9Desc.Text = sRow2;
                            txtMax9.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 10 Condiment Group")
                        {
                            lblLevel10ID.Text = sRow1;
                            lblLevel10Desc.Text = sRow2;
                            txtMax10.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }
                    }
                }
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModal();", true);
        }


        protected void chkSelectCondimentGroup_CheckedChanged(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);

            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("row1"), new DataColumn("row2") });
            foreach (GridViewRow row in GrdCondimentGroup.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkRow = (row.Cells[0].FindControl("chkSelectCondimentGroup") as CheckBox);
                    if (chkRow.Checked)
                    {
                        string sRow1 = (row.Cells[1].FindControl("lblID") as Label).Text;
                        string sRow2 = (row.Cells[2].FindControl("lblName") as Label).Text;

                        //txtLGCondimentID.Text = sRow1;
                        //txtLGCondimentName.Text = sRow2;

                        if (lblHeader.Text == "Level 1 Condiment Group")
                        {
                            lblLevel1ID.Text = sRow1;
                            lblLevel1Desc.Text = sRow2;
                            txtMax1.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 2 Condiment Group")
                        {
                            lblLevel2ID.Text = sRow1;
                            lblLevel2Desc.Text = sRow2;
                            txtMax2.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }


                        if (lblHeader.Text == "Level 3 Condiment Group")
                        {
                            lblLevel3ID.Text = sRow1;
                            lblLevel3Desc.Text = sRow2;
                            txtMax3.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }


                        if (lblHeader.Text == "Level 4 Condiment Group")
                        {
                            lblLevel4ID.Text = sRow1;
                            lblLevel4Desc.Text = sRow2;
                            txtMax4.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }


                        if (lblHeader.Text == "Level 5 Condiment Group")
                        {
                            lblLevel5ID.Text = sRow1;
                            lblLevel5Desc.Text = sRow2;
                            txtMax5.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 6 Condiment Group")
                        {
                            lblLevel6ID.Text = sRow1;
                            lblLevel6Desc.Text = sRow2;
                            txtMax6.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 7 Condiment Group")
                        {
                            lblLevel7ID.Text = sRow1;
                            lblLevel7Desc.Text = sRow2;
                            txtMax7.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 8 Condiment Group")
                        {
                            lblLevel8ID.Text = sRow1;
                            lblLevel8Desc.Text = sRow2;
                            txtMax8.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 9 Condiment Group")
                        {
                            lblLevel9ID.Text = sRow1;
                            lblLevel9Desc.Text = sRow2;
                            txtMax9.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }

                        if (lblHeader.Text == "Level 10 Condiment Group")
                        {
                            lblLevel10ID.Text = sRow1;
                            lblLevel10Desc.Text = sRow2;
                            txtMax10.Text = GetCondimentGroupMax(Cmb_BranchName, sRow1);
                        }
                    }
                }
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
        }

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

            //DataTable dt = new DataTable();
            //dt.Columns.AddRange(new DataColumn[2] { new DataColumn("ControlID"), new DataColumn("ControlType") });
            //foreach (GridViewRow row in GrdLinkView.Rows)
            //{

            //    if (row.RowType == DataControlRowType.DataRow)
            //    {
            //        CheckBox chkRow = (row.Cells[0].FindControl("chkSelect") as CheckBox);
            //        if (chkRow.Checked)
            //        {

            //            string sRow1 = (row.Cells[1].FindControl("ControlID") as Label).Text;
            //            if (GetControlIDDetails(Cmb_BranchName, int.Parse(sRow1)) == "true")
            //            {
            //            }
            //        }
            //    }
            //}
        }



        private string GetControlIDDetails(string sBD, int iControlID)
        {

            // Prevents SQL Injections 
            // Parameterized Approach 
            string sGetControlIDDetails = string.Empty;
            sGetControlIDDetails = "false";
            string upgrade1 = string.Empty;
            DataTable Dt = new DataTable();

            string sCmd = "Select  " +
                                 " ControlID, ControlType, ControlCode, ControlName,  " +
                                 " ProcessType1, ProcessCode1, ProcessName1, ProcessMin1, ProcessMax1, ProcessOption1, ProcessUpgrade1, " +
                                 " ProcessType2, ProcessCode2, ProcessName2, ProcessMin2, ProcessMax2, ProcessOption2, ProcessUpgrade2," +
                                 " ProcessType3, ProcessCode3, ProcessName3, ProcessMin3, ProcessMax3, ProcessOption3, ProcessUpgrade3," +
                                 " ProcessType4, ProcessCode4, ProcessName4, ProcessMin4, ProcessMax4, ProcessOption4, ProcessUpgrade4," +
                                 " ProcessType5, ProcessCode5, ProcessName5, ProcessMin5, ProcessMax5, ProcessOption5, ProcessUpgrade5," +
                                 " ProcessType6, ProcessCode6, ProcessName6, ProcessMin6, ProcessMax6, ProcessOption6, ProcessUpgrade6," +
                                 " ProcessType7, ProcessCode7, ProcessName7, ProcessMin7, ProcessMax7, ProcessOption7, ProcessUpgrade7," +
                                 " ProcessType8, ProcessCode8, ProcessName8, ProcessMin8, ProcessMax8, ProcessOption8, ProcessUpgrade8," +
                                 " ProcessType9, ProcessCode9, ProcessName9, ProcessMin9, ProcessMax9, ProcessOption9, ProcessUpgrade9," +
                                 " ProcessType10, ProcessCode10, ProcessName10, ProcessMin10, ProcessMax10, ProcessOption10, ProcessUpgrade10 " +
                                 " from {0}.modifiercontrol where ControlID = @ControlID;";

            string command = string.Format(sCmd, sBD);

            MySqlParameter[] parameters =
                   {
                     new MySqlParameter("@ControlID",iControlID),

                    };

            Dt = ObjMain.NewGetData_DT(command, parameters);

            if (Dt.Rows.Count > 0)
            {
                lblModifierControlID.Text = Dt.Rows[0]["ControlID"].ToString();

                cmbStep1.Text = Dt.Rows[0]["ControlType"].ToString();
                lblStep1Barcode.Text = Dt.Rows[0]["ControlCode"].ToString();
                lblStep1Desc.Text = Dt.Rows[0]["ControlName"].ToString();

                cmbLevel1.Text = Dt.Rows[0]["ProcessType1"].ToString();
                lblLevel1ID.Text = Dt.Rows[0]["ProcessCode1"].ToString();
                lblLevel1Desc.Text = Dt.Rows[0]["ProcessName1"].ToString();
                txtMin1.Text = Dt.Rows[0]["ProcessMin1"].ToString();
                txtMax1.Text = Dt.Rows[0]["ProcessMax1"].ToString();

                if (int.Parse(Dt.Rows[0]["ProcessUpgrade1"].ToString()) == 0)
                {
                    chkupgrade1.Checked = false;
                }
                else
                {
                    chkupgrade1.Checked = true;
                }

                cmbLevel2.Text = Dt.Rows[0]["ProcessType2"].ToString();
                lblLevel2ID.Text = Dt.Rows[0]["ProcessCode2"].ToString();
                lblLevel2Desc.Text = Dt.Rows[0]["ProcessName2"].ToString();
                txtMin2.Text = Dt.Rows[0]["ProcessMin2"].ToString();
                txtMax2.Text = Dt.Rows[0]["ProcessMax2"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade2"].ToString()) == 0)
                {
                    chkupgrade2.Checked = false;
                }
                else
                {
                    chkupgrade2.Checked = true;
                }

                cmbLevel3.Text = Dt.Rows[0]["ProcessType3"].ToString();
                lblLevel3ID.Text = Dt.Rows[0]["ProcessCode3"].ToString();
                lblLevel3Desc.Text = Dt.Rows[0]["ProcessName3"].ToString();
                txtMin3.Text = Dt.Rows[0]["ProcessMin3"].ToString();
                txtMax3.Text = Dt.Rows[0]["ProcessMax3"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade3"].ToString()) == 0)
                {
                    chkupgrade3.Checked = false;
                }
                else
                {
                    chkupgrade3.Checked = true;
                }

                cmbLevel4.Text = Dt.Rows[0]["ProcessType4"].ToString();
                lblLevel4ID.Text = Dt.Rows[0]["ProcessCode4"].ToString();
                lblLevel4Desc.Text = Dt.Rows[0]["ProcessName4"].ToString();
                txtMin4.Text = Dt.Rows[0]["ProcessMin4"].ToString();
                txtMax4.Text = Dt.Rows[0]["ProcessMax4"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade4"].ToString()) == 0)
                {
                    chkupgrade4.Checked = false;
                }
                else
                {
                    chkupgrade4.Checked = true;
                }

                cmbLevel5.Text = Dt.Rows[0]["ProcessType5"].ToString();
                lblLevel5ID.Text = Dt.Rows[0]["ProcessCode5"].ToString();
                lblLevel5Desc.Text = Dt.Rows[0]["ProcessName5"].ToString();
                txtMin5.Text = Dt.Rows[0]["ProcessMin5"].ToString();
                txtMax5.Text = Dt.Rows[0]["ProcessMax5"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade5"].ToString()) == 0)
                {
                    chkupgrade5.Checked = false;
                }
                else
                {
                    chkupgrade5.Checked = true;
                }

                cmbLevel6.Text = Dt.Rows[0]["ProcessType6"].ToString();
                lblLevel6ID.Text = Dt.Rows[0]["ProcessCode6"].ToString();
                lblLevel6Desc.Text = Dt.Rows[0]["ProcessName6"].ToString();
                txtMin6.Text = Dt.Rows[0]["ProcessMin6"].ToString();
                txtMax6.Text = Dt.Rows[0]["ProcessMax6"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade6"].ToString()) == 0)
                {
                    chkupgrade6.Checked = false;
                }
                else
                {
                    chkupgrade6.Checked = true;
                }

                cmbLevel7.Text = Dt.Rows[0]["ProcessType7"].ToString();
                lblLevel7ID.Text = Dt.Rows[0]["ProcessCode7"].ToString();
                lblLevel7Desc.Text = Dt.Rows[0]["ProcessName7"].ToString();
                txtMin7.Text = Dt.Rows[0]["ProcessMin7"].ToString();
                txtMax7.Text = Dt.Rows[0]["ProcessMax7"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade7"].ToString()) == 0)
                {
                    chkupgrade7.Checked = false;
                }
                else
                {
                    chkupgrade7.Checked = true;
                }

                cmbLevel8.Text = Dt.Rows[0]["ProcessType8"].ToString();
                lblLevel8ID.Text = Dt.Rows[0]["ProcessCode8"].ToString();
                lblLevel8Desc.Text = Dt.Rows[0]["ProcessName8"].ToString();
                txtMin8.Text = Dt.Rows[0]["ProcessMin8"].ToString();
                txtMax8.Text = Dt.Rows[0]["ProcessMax8"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade8"].ToString()) == 0)
                {
                    chkupgrade8.Checked = false;
                }
                else
                {
                    chkupgrade8.Checked = true;
                }

                cmbLevel9.Text = Dt.Rows[0]["ProcessType9"].ToString();
                lblLevel9ID.Text = Dt.Rows[0]["ProcessCode9"].ToString();
                lblLevel9Desc.Text = Dt.Rows[0]["ProcessName9"].ToString();
                txtMin9.Text = Dt.Rows[0]["ProcessMin9"].ToString();
                txtMax9.Text = Dt.Rows[0]["ProcessMax9"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade9"].ToString()) == 0)
                {
                    chkupgrade9.Checked = false;
                }
                else
                {
                    chkupgrade9.Checked = true;
                }

                cmbLevel10.Text = Dt.Rows[0]["ProcessType10"].ToString();
                lblLevel10ID.Text = Dt.Rows[0]["ProcessCode10"].ToString();
                lblLevel10Desc.Text = Dt.Rows[0]["ProcessName10"].ToString();
                txtMin10.Text = Dt.Rows[0]["ProcessMin10"].ToString();
                txtMax10.Text = Dt.Rows[0]["ProcessMax10"].ToString();
                if (int.Parse(Dt.Rows[0]["ProcessUpgrade10"].ToString()) == 0)
                {
                    chkupgrade10.Checked = false;
                }
                else
                {
                    chkupgrade10.Checked = true;
                }

                sGetControlIDDetails = "true";

            }
            else
            {
                sGetControlIDDetails = "false";

            }

            return sGetControlIDDetails;

        }

        private void Step1ViewList(string sDB, string ControlType)
        {

            // Prevents SQL Injections 
            // Parameterized Approach 
            string sCmd = string.Empty;
            GrdLinkView.DataSource = null;
            GrdLinkView.DataBind();
            switch (ControlType)
            {
                case "1":
                    sCmd = "Select Barcode as row1,Inventoryname as row2,Description as row3 from {0}.Inventory where barcode <> 'Round' and Active <> 0";
                    break;
                case "2":
                    sCmd = "Select Categorynumber as row1,CategoryName as row2,Description as row3 from {0}.inventorycategories where CategoryName <> 'Round' and Active <> 0";
                    break;
                case "3":
                    sCmd = "Select GroupID as row1,GroupName as row2,Description as row3 from {0}.Group1 where Active <> 0";
                    break;
                case "4":
                    sCmd = "Select GroupID as row1,GroupName as row2,Description as row3 from {0}.Group2 where Active <> 0";
                    break;
                case "5":
                    sCmd = "Select GroupID as row1,GroupName as row2,Description as row3 from {0}.Group3 where Active <> 0";
                    break;
                case "6":
                    sCmd = "Select GroupID as row1,GroupName as row2,Description as row3 from {0}.Group4 where Active <> 0";
                    break;
                case "7":
                    sCmd = "Select GroupID as row1,GroupName as row2,Description as row3 from {0}.Group5 where Active <> 0";
                    break;
                default:
                    break;
            }


            string command = string.Format(sCmd, sDB);
            DataTable Dt = new DataTable();
            Dt = ObjMain.GetData_DT(command);
            GrdLinkView.DataSource = Dt;
            GrdLinkView.DataBind();
            DisableRowItem();
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "ShowModal(); event.preventDefault();", true);
        }

        private void LevelsViewList(string sDB)
        {

            // Prevents SQL Injections 
            // Parameterized Approach 

            MySqlConnection Cn = new MySqlConnection(ConStr_Rds);
            //GrdLinkView.DataSource = null;
            //GrdLinkView.DataBind();
            //GrdCondimentGroup
            GrdCondimentGroup.DataSource = null;
            GrdCondimentGroup.DataBind();

            string sCmd = "Select CondimentGroupID as row1,CondimentGroupName as row2,'' as row3 from {0}.Condimentgroup";
            string command = string.Format(sCmd, sDB);
            DataTable Dt = new DataTable();
            Dt = ObjMain.GetData_DT(command);
            //GrdLinkView.DataSource = Dt;
            //GrdLinkView.DataBind();
            GrdCondimentGroup.DataSource = Dt;
            GrdCondimentGroup.DataBind();
        }

        private void ModifierList(string sDB)
        {

            grdModList.DataSource = null;
            grdModList.DataBind();

            string sCmd = "Select ControlID, ControlType, ControlCode, ControlName,  " +
                                " ProcessType1, ProcessCode1, ProcessName1, ProcessMin1, ProcessMax1, ProcessOption1, " +
                                " ProcessType2, ProcessCode2, ProcessName2, ProcessMin2, ProcessMax2, ProcessOption2, " +
                                " ProcessType3, ProcessCode3, ProcessName3, ProcessMin3, ProcessMax3, ProcessOption3, " +
                                " ProcessType4, ProcessCode4, ProcessName4, ProcessMin4, ProcessMax4, ProcessOption4, " +
                                " ProcessType5, ProcessCode5, ProcessName5, ProcessMin5, ProcessMax5, ProcessOption5, " +
                                " ProcessType6, ProcessCode6, ProcessName6, ProcessMin6, ProcessMax6, ProcessOption6, " +
                                " ProcessType7, ProcessCode7, ProcessName7, ProcessMin7, ProcessMax7, ProcessOption7, " +
                                " ProcessType8, ProcessCode8, ProcessName8, ProcessMin8, ProcessMax8, ProcessOption8, " +
                                " ProcessType9, ProcessCode9, ProcessName9, ProcessMin9, ProcessMax9, ProcessOption9, " +
                                " ProcessType10, ProcessCode10, ProcessName10, ProcessMin10, ProcessMax10, ProcessOption10 " +
                                " from {0}.modifiercontrol;";


            DataTable Dt = new DataTable();
            string command = string.Format(sCmd, sDB);
            Dt = ObjMain.GetData_DT(command);
            grdModList.DataSource = Dt;
            grdModList.DataBind();

        }

        private string ValidateItem(string sDB, string sControlType, string sControlCode)
        {
            string sValidateItem = string.Empty;
            string sCmd = "Select *from {0}.modifiercontrol where ControlType=@ControlType and ControlCode=@ControlCode;";
            string command = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
            {
                new MySqlParameter("ControlType",sControlType),
                new MySqlParameter("@ControlCode",sControlCode),
            };
            sValidateItem = ObjMain.NewExecuteScalar(command, parameters);
            // sValidateItem = ObjMain.ExecuteScalar(sCmd);    Exiting Code 

            if (sValidateItem == "")
            {
                sValidateItem = "false";
            }
            else
            {
                sValidateItem = "true";
            }
            return sValidateItem;
        }

        private void SaveModifier(string sDB)
        {
            // XSS Attack Prevention 

            // Prevents  SQL Injection
            // Parameterized approach 

            int iContorID = int.Parse(ObjSel.GenerateModifierID(sDB));
            string sCmd = "Insert Into {0}.ModifierControl(ControlID, ControlType, ControlCode, ControlName, " +
                        " ProcessType1, ProcessCode1, ProcessName1, ProcessMin1, ProcessMax1, ProcessOption1,ProcessUpgrade1, " +
                        " ProcessType2, ProcessCode2, ProcessName2, ProcessMin2, ProcessMax2, ProcessOption2,ProcessUpgrade2, " +
                        " ProcessType3, ProcessCode3, ProcessName3, ProcessMin3, ProcessMax3, ProcessOption3,ProcessUpgrade3, " +
                        " ProcessType4, ProcessCode4, ProcessName4, ProcessMin4, ProcessMax4, ProcessOption4,ProcessUpgrade4, " +
                        " ProcessType5, ProcessCode5, ProcessName5, ProcessMin5, ProcessMax5, ProcessOption5,ProcessUpgrade5, " +
                        " ProcessType6, ProcessCode6, ProcessName6, ProcessMin6, ProcessMax6, ProcessOption6,ProcessUpgrade6, " +
                        " ProcessType7, ProcessCode7, ProcessName7, ProcessMin7, ProcessMax7, ProcessOption7,ProcessUpgrade7, " +
                        " ProcessType8, ProcessCode8, ProcessName8, ProcessMin8, ProcessMax8, ProcessOption8,ProcessUpgrade8, " +
                        " ProcessType9, ProcessCode9, ProcessName9, ProcessMin9, ProcessMax9, ProcessOption9,ProcessUpgrade9, " +
                        " ProcessType10, ProcessCode10, ProcessName10, ProcessMin10, ProcessMax10, ProcessOption10,ProcessUpgrade10) " +
                        " values " +
                        "(@ControlID,@ControlType,@ControlCode,@ControlName," +
                        " @ProcessType1,@ProcessCode1,@ProcessName1,@ProcessMin1,@ProcessMax1,@ProcessOption1,@ProcessUpgrade1," +
                        " @ProcessType2,@ProcessCode2,@ProcessName2,@ProcessMin2,@ProcessMax2,@ProcessOption2,@ProcessUpgrade2," +
                        " @ProcessType3,@ProcessCode3,@ProcessName3,@ProcessMin3,@ProcessMax3,@ProcessOption3,@ProcessUpgrade3," +
                        " @ProcessType4,@ProcessCode4,@ProcessName4,@ProcessMin4,@ProcessMax4,@ProcessOption4,@ProcessUpgrade4," +
                        " @ProcessType5,@ProcessCode5,@ProcessName5,@ProcessMin5,@ProcessMax5,@ProcessOption5,@ProcessUpgrade5," +
                        " @ProcessType6,@ProcessCode6,@ProcessName6,@ProcessMin6,@ProcessMax5,@ProcessOption6,@ProcessUpgrade6," +
                        " @ProcessType7,@ProcessCode7,@ProcessName7,@ProcessMin7,@ProcessMax7,@ProcessOption7,@ProcessUpgrade7," +
                        " @ProcessType8,@ProcessCode8,@ProcessName8,@ProcessMin8,@ProcessMax8,@ProcessOption8,@ProcessUpgrade8," +
                        " @ProcessType9,@ProcessCode9,@ProcessName9,@ProcessMin9,@ProcessMax9,@ProcessOption9,@ProcessUpgrade9," +
                        " @ProcessType10,@ProcessCode10,@ProcessName10,@ProcessMin10,@ProcessMax10,@ProcessOption10,@ProcessUpgrade10" +
                        " ) ";


            string command = string.Format(sCmd, sDB);

            int upgrade1 = 0;
            int upgrade2 = 0;
            int upgrade3 = 0;
            int upgrade4 = 0;
            int upgrade5 = 0;
            int upgrade6 = 0;
            int upgrade7 = 0;
            int upgrade8 = 0;
            int upgrade9 = 0;
            int upgrade10 = 0;

            if (chkupgrade1.Checked)
            {
                upgrade1 = 1;
            }

            if (chkupgrade2.Checked)
            {
                upgrade2 = 1;
            }

            if (chkupgrade3.Checked)
            {
                upgrade3 = 1;
            }

            if (chkupgrade4.Checked)
            {
                upgrade4 = 1;
            }

            if (chkupgrade5.Checked)
            {
                upgrade5 = 1;
            }

            if (chkupgrade6.Checked)
            {
                upgrade6 = 1;
            }

            if (chkupgrade7.Checked)
            {
                upgrade7 = 1;
            }

            if (chkupgrade8.Checked)
            {
                upgrade8 = 1;
            }

            if (chkupgrade9.Checked)
            {
                upgrade9 = 1;
            }

            if (chkupgrade10.Checked)
            {
                upgrade10 = 1;
            }


            MySqlParameter[] parameters =
                   {
                     //new MySqlParameter("@ControlID",iContorID),
                     //new MySqlParameter("@ControlType",Microsoft.Security.Application.Encoder.HtmlEncode(cmbStep1.SelectedValue)),
                     //new MySqlParameter("@ControlCode",Microsoft.Security.Application.Encoder.HtmlEncode(lblStep1Barcode.Text.Trim())),
                     //new MySqlParameter("@ControlName",Microsoft.Security.Application.Encoder.HtmlEncode(lblStep1Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessType1",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel1.SelectedValue)),
                     //new MySqlParameter("@ProcessCode1",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel1ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName1",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel1Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin1",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin1.Text.Trim())),
                     //new MySqlParameter("@ProcessMax1",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax1.Text.Trim())),
                     //new MySqlParameter("@ProcessOption1",'0'),
                     //new MySqlParameter("@ProcessType2",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel2.SelectedValue)),
                     //new MySqlParameter("@ProcessCode2",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel2ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName2",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel2Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin2",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin2.Text.Trim())),
                     //new MySqlParameter("@ProcessMax2",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax2.Text.Trim())),
                     //new MySqlParameter("@ProcessOption2",'0'),
                     //new MySqlParameter("@ProcessType3",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel3.SelectedValue)),
                     //new MySqlParameter("@ProcessCode3",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel3ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName3",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel3Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin3",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin3.Text.Trim())),
                     //new MySqlParameter("@ProcessMax3",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax3.Text.Trim())),
                     //new MySqlParameter("@ProcessOption3",'0'),

                     //new MySqlParameter("@ProcessType4",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel4.SelectedValue)),
                     //new MySqlParameter("@ProcessCode4",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel4ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName4",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel4Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin4",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin4.Text.Trim())),
                     //new MySqlParameter("@ProcessMax4",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax4.Text.Trim())),
                     //new MySqlParameter("@ProcessOption4",'0'),

                     //new MySqlParameter("@ProcessType5",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel5.SelectedValue)),
                     //new MySqlParameter("@ProcessCode5",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel5ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName5",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel5Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin5",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin5.Text.Trim())),
                     //new MySqlParameter("@ProcessMax5",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax5.Text.Trim())),
                     //new MySqlParameter("@ProcessOption5",'0'),

                     //new MySqlParameter("@ProcessType6",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel6.SelectedValue)),
                     //new MySqlParameter("@ProcessCode6",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel6ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName6",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel6Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin6",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin6.Text.Trim())),
                     //new MySqlParameter("@ProcessMax6",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax6.Text.Trim())),
                     //new MySqlParameter("@ProcessOption6",'0'),


                     //new MySqlParameter("@ProcessType7",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel7.SelectedValue)),
                     //new MySqlParameter("@ProcessCode7",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel7ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName7",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel7Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin7",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin7.Text.Trim())),
                     //new MySqlParameter("@ProcessMax7",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax7.Text.Trim())),
                     //new MySqlParameter("@ProcessOption7",'0'),

                     //new MySqlParameter("@ProcessType8",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel8.SelectedValue)),
                     //new MySqlParameter("@ProcessCode8",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel8ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName8",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel8Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin8",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin8.Text.Trim())),
                     //new MySqlParameter("@ProcessMax8",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax8.Text.Trim())),
                     //new MySqlParameter("@ProcessOption8",'0'),

                     //new MySqlParameter("@ProcessType9",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel9.SelectedValue)),
                     //new MySqlParameter("@ProcessCode9",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel9ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName9",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel9Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin9",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin9.Text.Trim())),
                     //new MySqlParameter("@ProcessMax9",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax9.Text.Trim())),
                     //new MySqlParameter("@ProcessOption9",'0'),

                     //new MySqlParameter("@ProcessType10",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel10.SelectedValue)),
                     //new MySqlParameter("@ProcessCode10",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel10ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName10",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel10Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin10",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin10.Text.Trim())),
                     //new MySqlParameter("@ProcessMax10",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax10.Text.Trim())),
                     //new MySqlParameter("@ProcessOption10",'0'),

                new MySqlParameter("@ControlID",iContorID),
                     new MySqlParameter("@ControlType",cmbStep1.SelectedValue),
                     new MySqlParameter("@ControlCode",lblStep1Barcode.Text.Trim()),
                     new MySqlParameter("@ControlName",lblStep1Desc.Text.Trim()),
                     new MySqlParameter("@ProcessType1",cmbLevel1.SelectedValue),
                     new MySqlParameter("@ProcessCode1",lblLevel1ID.Text.Trim()),
                     new MySqlParameter("@ProcessName1",lblLevel1Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin1",txtMin1.Text.Trim()),
                     new MySqlParameter("@ProcessMax1",txtMax1.Text.Trim()),
                     new MySqlParameter("@ProcessOption1",'0'),
                     new MySqlParameter("@ProcessUpgrade1",upgrade1),

                     new MySqlParameter("@ProcessType2",cmbLevel2.SelectedValue),
                     new MySqlParameter("@ProcessCode2",lblLevel2ID.Text.Trim()),
                     new MySqlParameter("@ProcessName2",lblLevel2Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin2",txtMin2.Text.Trim()),
                     new MySqlParameter("@ProcessMax2",txtMax2.Text.Trim()),
                     new MySqlParameter("@ProcessOption2",'0'),
                     new MySqlParameter("@ProcessUpgrade2",upgrade2),

                     new MySqlParameter("@ProcessType3",cmbLevel3.SelectedValue),
                     new MySqlParameter("@ProcessCode3",lblLevel3ID.Text.Trim()),
                     new MySqlParameter("@ProcessName3",lblLevel3Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin3",txtMin3.Text.Trim()),
                     new MySqlParameter("@ProcessMax3",txtMax3.Text.Trim()),
                     new MySqlParameter("@ProcessOption3",'0'),
                     new MySqlParameter("@ProcessUpgrade3",upgrade3),

                     new MySqlParameter("@ProcessType4",cmbLevel4.SelectedValue),
                     new MySqlParameter("@ProcessCode4",lblLevel4ID.Text.Trim()),
                     new MySqlParameter("@ProcessName4",lblLevel4Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin4",txtMin4.Text.Trim()),
                     new MySqlParameter("@ProcessMax4",txtMax4.Text.Trim()),
                     new MySqlParameter("@ProcessOption4",'0'),
                     new MySqlParameter("@ProcessUpgrade4",upgrade4),

                     new MySqlParameter("@ProcessType5",cmbLevel5.SelectedValue),
                     new MySqlParameter("@ProcessCode5",lblLevel5ID.Text.Trim()),
                     new MySqlParameter("@ProcessName5",lblLevel5Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin5",txtMin5.Text.Trim()),
                     new MySqlParameter("@ProcessMax5",txtMax5.Text.Trim()),
                     new MySqlParameter("@ProcessOption5",'0'),
                     new MySqlParameter("@ProcessUpgrade5",upgrade5),

                     new MySqlParameter("@ProcessType6",cmbLevel6.SelectedValue),
                     new MySqlParameter("@ProcessCode6",lblLevel6ID.Text.Trim()),
                     new MySqlParameter("@ProcessName6",lblLevel6Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin6",txtMin6.Text.Trim()),
                     new MySqlParameter("@ProcessMax6",txtMax6.Text.Trim()),
                     new MySqlParameter("@ProcessOption6",'0'),
                     new MySqlParameter("@ProcessUpgrade6",upgrade6),

                     new MySqlParameter("@ProcessType7",cmbLevel7.SelectedValue),
                     new MySqlParameter("@ProcessCode7",lblLevel7ID.Text.Trim()),
                     new MySqlParameter("@ProcessName7",lblLevel7Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin7",txtMin7.Text.Trim()),
                     new MySqlParameter("@ProcessMax7",txtMax7.Text.Trim()),
                     new MySqlParameter("@ProcessOption7",'0'),
                     new MySqlParameter("@ProcessUpgrade7",upgrade7),

                     new MySqlParameter("@ProcessType8",cmbLevel8.SelectedValue),
                     new MySqlParameter("@ProcessCode8",lblLevel8ID.Text.Trim()),
                     new MySqlParameter("@ProcessName8",lblLevel8Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin8",txtMin8.Text.Trim()),
                     new MySqlParameter("@ProcessMax8",txtMax8.Text.Trim()),
                     new MySqlParameter("@ProcessOption8",'0'),
                     new MySqlParameter("@ProcessUpgrade8",upgrade8),

                     new MySqlParameter("@ProcessType9",cmbLevel9.SelectedValue),
                     new MySqlParameter("@ProcessCode9",lblLevel9ID.Text.Trim()),
                     new MySqlParameter("@ProcessName9",lblLevel9Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin9",txtMin9.Text.Trim()),
                     new MySqlParameter("@ProcessMax9",txtMax9.Text.Trim()),
                     new MySqlParameter("@ProcessOption9",'0'),
                     new MySqlParameter("@ProcessUpgrade9",upgrade9),

                     new MySqlParameter("@ProcessType10",cmbLevel10.SelectedValue),
                     new MySqlParameter("@ProcessCode10",lblLevel10ID.Text.Trim()),
                     new MySqlParameter("@ProcessName10",lblLevel10Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin10",txtMin10.Text.Trim()),
                     new MySqlParameter("@ProcessMax10",txtMax10.Text.Trim()),
                     new MySqlParameter("@ProcessOption10",'0'),
                     new MySqlParameter("@ProcessUpgrade10",upgrade10),

            };


            iAddModifier = ObjMain.ExecuteQuery(command, parameters);
            if (iAddModifier == 1)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Modifier Successfully Saved ');window.location.href=window.location.href;", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Error On Saving Modifier ')", true);
            }
        }

        private void UpdateModifier(string sDB, int lblModifierControlID)
        {

            // XSS Attack Prevention 
            string sCmd = "Update {0}.ModifierControl set" +
                        " ControlType = @ControlType,ControlCode = @ControlCode,ControlName = @ControlName , " +
                        " ProcessType1 =@ProcessType1,ProcessCode1 = @ProcessCode1,ProcessName1 = @ProcessName1,ProcessMin1 = @ProcessMin1,ProcessMax1= @ProcessMax1,ProcessUpgrade1=@ProcessUpgrade1, " +
                        " ProcessType2 =@ProcessType2,ProcessCode2 = @ProcessCode2,ProcessName2 = @ProcessName2,ProcessMin2 = @ProcessMin2,ProcessMax2= @ProcessMax2,ProcessUpgrade2=@ProcessUpgrade2, " +
                        " ProcessType3 =@ProcessType3,ProcessCode3 = @ProcessCode3,ProcessName3 = @ProcessName3,ProcessMin3 = @ProcessMin3,ProcessMax3 =@ProcessMax3,ProcessUpgrade3=@ProcessUpgrade3, " +
                        " ProcessType4 =@ProcessType4,ProcessCode4 = @ProcessCode4,ProcessName4 = @ProcessName4,ProcessMin4 = @ProcessMin4,ProcessMax4 =@ProcessMax4,ProcessUpgrade4=@ProcessUpgrade4, " +
                        " ProcessType5 =@ProcessType5,ProcessCode5 = @ProcessCode5,ProcessName5 = @ProcessName5,ProcessMin5 = @ProcessMin5,ProcessMax5 =@ProcessMax5,ProcessUpgrade5=@ProcessUpgrade5, " +
                        " ProcessType6 =@ProcessType6,ProcessCode6 = @ProcessCode6,ProcessName6 = @ProcessName6,ProcessMin6 = @ProcessMin6,ProcessMax6 =@ProcessMax6,ProcessUpgrade6=@ProcessUpgrade6, " +
                        " ProcessType7 =@ProcessType7,ProcessCode7 = @ProcessCode7,ProcessName7 = @ProcessName7,ProcessMin7 = @ProcessMin7,ProcessMax7 =@ProcessMax7,ProcessUpgrade7=@ProcessUpgrade7, " +
                        " ProcessType8 =@ProcessType8,ProcessCode8 =@ProcessCode8,ProcessName8 = @ProcessName8,ProcessMin8 = @ProcessMin8,ProcessMax8 =@ProcessMax8,ProcessUpgrade8=@ProcessUpgrade8, " +
                        " ProcessType9 =@ProcessType9,ProcessCode9 =@ProcessCode9,ProcessName9 = @ProcessName9,ProcessMin9 = @ProcessMin9,ProcessMax9 =@ProcessMax9,ProcessUpgrade9=@ProcessUpgrade9, " +
                        " ProcessType10 =@ProcessType10,ProcessCode10 =@ProcessCode10,ProcessName10 =@ProcessName10,ProcessMin10 =@ProcessMin10,ProcessMax10 =@ProcessMax10,ProcessUpgrade10=@ProcessUpgrade10 " +
                        " where ControlID = @ControlID";
            string command = string.Format(sCmd, sDB);

            int upgrade1 = 0;
            int upgrade2 = 0;
            int upgrade3 = 0;
            int upgrade4 = 0;
            int upgrade5 = 0;
            int upgrade6 = 0;
            int upgrade7 = 0;
            int upgrade8 = 0;
            int upgrade9 = 0;
            int upgrade10 = 0;

            if (chkupgrade1.Checked)
            {
                upgrade1 = 1;
            }

            if (chkupgrade2.Checked)
            {
                upgrade2 = 1;
            }

            if (chkupgrade3.Checked)
            {
                upgrade3 = 1;
            }

            if (chkupgrade4.Checked)
            {
                upgrade4 = 1;
            }

            if (chkupgrade5.Checked)
            {
                upgrade5 = 1;
            }

            if (chkupgrade6.Checked)
            {
                upgrade6 = 1;
            }

            if (chkupgrade7.Checked)
            {
                upgrade7 = 1;
            }

            if (chkupgrade8.Checked)
            {
                upgrade8 = 1;
            }

            if (chkupgrade9.Checked)
            {
                upgrade9 = 1;
            }

            if (chkupgrade10.Checked)
            {
                upgrade10 = 1;
            }


            MySqlParameter[] parameters =
                 {
                     //new MySqlParameter("@ControlID",lblModifierControlID),
                     //new MySqlParameter("@ControlType",Microsoft.Security.Application.Encoder.HtmlEncode(cmbStep1.SelectedValue)),
                     //new MySqlParameter("@ControlCode",Microsoft.Security.Application.Encoder.HtmlEncode(lblStep1Barcode.Text.Trim())),
                     //new MySqlParameter("@ControlName",Microsoft.Security.Application.Encoder.HtmlEncode(lblStep1Desc.Text.Trim())),

                     //new MySqlParameter("@ProcessType1",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel1.SelectedValue)),
                     //new MySqlParameter("@ProcessCode1",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel1ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName1",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel1Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin1",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin1.Text.Trim())),
                     //new MySqlParameter("@ProcessMax1",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax1.Text.Trim())),


                     //new MySqlParameter("@ProcessType2",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel2.SelectedValue)),
                     //new MySqlParameter("@ProcessCode2",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel2ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName2",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel2Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin2",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin2.Text.Trim())),
                     //new MySqlParameter("@ProcessMax2",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax2.Text.Trim())),


                     //new MySqlParameter("@ProcessType3",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel3.SelectedValue)),
                     //new MySqlParameter("@ProcessCode3",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel3ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName3",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel3Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin3",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin3.Text.Trim())),
                     //new MySqlParameter("@ProcessMax3",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax3.Text.Trim())),


                     //new MySqlParameter("@ProcessType4",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel4.SelectedValue)),
                     //new MySqlParameter("@ProcessCode4",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel4ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName4",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel4Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin4",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin4.Text.Trim())),
                     //new MySqlParameter("@ProcessMax4",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax4.Text.Trim())),


                     //new MySqlParameter("@ProcessType5",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel5.SelectedValue)),
                     //new MySqlParameter("@ProcessCode5",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel5ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName5",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel5Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin5",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin5.Text.Trim())),
                     //new MySqlParameter("@ProcessMax5",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax5.Text.Trim())),


                     //new MySqlParameter("@ProcessType6",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel6.SelectedValue)),
                     //new MySqlParameter("@ProcessCode6",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel6ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName6",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel6Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin6",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin6.Text.Trim())),
                     //new MySqlParameter("@ProcessMax6",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax6.Text.Trim())),



                     //new MySqlParameter("@ProcessType7",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel7.SelectedValue)),
                     //new MySqlParameter("@ProcessCode7",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel7ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName7",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel7Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin7",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin7.Text.Trim())),
                     //new MySqlParameter("@ProcessMax7",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax7.Text.Trim())),


                     //new MySqlParameter("@ProcessType8",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel8.SelectedValue)),
                     //new MySqlParameter("@ProcessCode8",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel8ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName8",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel8Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin8",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin8.Text.Trim())),
                     //new MySqlParameter("@ProcessMax8",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax8.Text.Trim())),


                     //new MySqlParameter("@ProcessType9",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel9.SelectedValue)),
                     //new MySqlParameter("@ProcessCode9",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel9ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName9",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel9Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin9",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin9.Text.Trim())),
                     //new MySqlParameter("@ProcessMax9",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax9.Text.Trim())),


                     //new MySqlParameter("@ProcessType10",Microsoft.Security.Application.Encoder.HtmlEncode(cmbLevel10.SelectedValue)),
                     //new MySqlParameter("@ProcessCode10",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel10ID.Text.Trim())),
                     //new MySqlParameter("@ProcessName10",Microsoft.Security.Application.Encoder.HtmlEncode(lblLevel10Desc.Text.Trim())),
                     //new MySqlParameter("@ProcessMin10",Microsoft.Security.Application.Encoder.HtmlEncode(txtMin10.Text.Trim())),
                     //new MySqlParameter("@ProcessMax10",Microsoft.Security.Application.Encoder.HtmlEncode(txtMax10.Text.Trim())),

                 new MySqlParameter("@ControlID",lblModifierControlID),
                     new MySqlParameter("@ControlType",cmbStep1.SelectedValue),
                     new MySqlParameter("@ControlCode",lblStep1Barcode.Text.Trim()),
                     new MySqlParameter("@ControlName",lblStep1Desc.Text.Trim()),

                     new MySqlParameter("@ProcessType1",cmbLevel1.SelectedValue),
                     new MySqlParameter("@ProcessCode1",lblLevel1ID.Text.Trim()),
                     new MySqlParameter("@ProcessName1",lblLevel1Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin1",txtMin1.Text.Trim()),
                     new MySqlParameter("@ProcessMax1",txtMax1.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade1",upgrade1),


                     new MySqlParameter("@ProcessType2",cmbLevel2.SelectedValue),
                     new MySqlParameter("@ProcessCode2",lblLevel2ID.Text.Trim()),
                     new MySqlParameter("@ProcessName2",lblLevel2Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin2",txtMin2.Text.Trim()),
                     new MySqlParameter("@ProcessMax2",txtMax2.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade2",upgrade2),


                     new MySqlParameter("@ProcessType3",cmbLevel3.SelectedValue),
                     new MySqlParameter("@ProcessCode3",lblLevel3ID.Text.Trim()),
                     new MySqlParameter("@ProcessName3",lblLevel3Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin3",txtMin3.Text.Trim()),
                     new MySqlParameter("@ProcessMax3",txtMax3.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade3",upgrade3),

                     new MySqlParameter("@ProcessType4",cmbLevel4.SelectedValue),
                     new MySqlParameter("@ProcessCode4",lblLevel4ID.Text.Trim()),
                     new MySqlParameter("@ProcessName4",lblLevel4Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin4",txtMin4.Text.Trim()),
                     new MySqlParameter("@ProcessMax4",txtMax4.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade4",upgrade4),

                     new MySqlParameter("@ProcessType5",cmbLevel5.SelectedValue),
                     new MySqlParameter("@ProcessCode5",lblLevel5ID.Text.Trim()),
                     new MySqlParameter("@ProcessName5",lblLevel5Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin5",txtMin5.Text.Trim()),
                     new MySqlParameter("@ProcessMax5",txtMax5.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade5",upgrade5),

                     new MySqlParameter("@ProcessType6",cmbLevel6.SelectedValue),
                     new MySqlParameter("@ProcessCode6",lblLevel6ID.Text.Trim()),
                     new MySqlParameter("@ProcessName6",lblLevel6Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin6",txtMin6.Text.Trim()),
                     new MySqlParameter("@ProcessMax6",txtMax6.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade6",upgrade6),

                     new MySqlParameter("@ProcessType7",cmbLevel7.SelectedValue),
                     new MySqlParameter("@ProcessCode7",lblLevel7ID.Text.Trim()),
                     new MySqlParameter("@ProcessName7",lblLevel7Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin7",txtMin7.Text.Trim()),
                     new MySqlParameter("@ProcessMax7",txtMax7.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade7",upgrade7),

                     new MySqlParameter("@ProcessType8",cmbLevel8.SelectedValue),
                     new MySqlParameter("@ProcessCode8",lblLevel8ID.Text.Trim()),
                     new MySqlParameter("@ProcessName8",lblLevel8Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin8",txtMin8.Text.Trim()),
                     new MySqlParameter("@ProcessMax8",txtMax8.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade8",upgrade8),

                     new MySqlParameter("@ProcessType9",cmbLevel9.SelectedValue),
                     new MySqlParameter("@ProcessCode9",lblLevel9ID.Text.Trim()),
                     new MySqlParameter("@ProcessName9",lblLevel9Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin9",txtMin9.Text.Trim()),
                     new MySqlParameter("@ProcessMax9",txtMax9.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade9",upgrade9),

                     new MySqlParameter("@ProcessType10",cmbLevel10.SelectedValue),
                     new MySqlParameter("@ProcessCode10",lblLevel10ID.Text.Trim()),
                     new MySqlParameter("@ProcessName10",lblLevel10Desc.Text.Trim()),
                     new MySqlParameter("@ProcessMin10",txtMin10.Text.Trim()),
                     new MySqlParameter("@ProcessMax10",txtMax10.Text.Trim()),
                     new MySqlParameter("@ProcessUpgrade10",upgrade10),

            };

            iUpdateModifier = ObjMain.ExecuteQuery(command, parameters);
            if (iUpdateModifier == 1)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Modifier Successfully Saved ');window.location.href=window.location.href;", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Error On Saving Modifier ')", true);
            }

            // iUpdateModifier = ObjCloudMain.ExecuteNonQuery(sCmd);  Existing Code 

            //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Modifier Successfully Updated ')", true);
            //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Modifier Successfully Updated ')", true);
            //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "if(!alert(' Modifier Successfully Updated!')){window.location.reload();}", true);
            //Response.Redirect(Request.RawUrl);  
            //ResetFields();


        }

        private void DeleteModifer(string sDB, string iControlID)
        {
            string sCmd = "Delete from {0}.ModifierControl where ControlID = @ControlID";
            string Command = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
                        {
                new MySqlParameter("@ControlID",iControlID)
            };

            iDeleteModifier = ObjMain.ExecuteQuery(Command, parameters);

            //Response.Redirect(Request.RawUrl);  
            //ModifierListPopup(Cmb_BranchName);
            ModifierList(Cmb_BranchName);
            ResetFields();
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "success_msg", "alert(' Modifier Successfully Deleted ');window.location.href=window.location.href;", true);

        }

        private string GetCondimentGroupMax(string sDB, string sCondimentGroupID)
        {

            // Prevents SQL Injection 
            // Parameterized Apporach 
            string sGetCondimentGroupMax = string.Empty;
            string sCmd = "Select count(*) from {0}.CondimentGroupDetails where condimentgroupid=@condimentgroupid ;";
            string command = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
                   {
                     new MySqlParameter("@condimentgroupid",sCondimentGroupID),

                    };

            sGetCondimentGroupMax = ObjMain.NewExecuteScalar(command, parameters);


            // N  sGetCondimentGroupMax = ObjMain.ExecuteScalar(sCmd);    Existing Code 
            if (sGetCondimentGroupMax == "")
            {
                sGetCondimentGroupMax = "0";
            }
            return sGetCondimentGroupMax;
        }

        protected void btnApplySearchModifier_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);
            ModifierListPopup(Cmb_BranchName);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalModifier();", true);
        }

        private void ModifierListPopup(string sDB)
        {
            // XSS Attack Prevention 
            // Prevents SQL Injection 
            // Parameterized Approach
            string sCondition = string.Empty;
            if (txtInputModifier.Text != "")
            {
                if (cmbSearchOption.SelectedIndex == 1)
                {
                    sCondition = " where ControlName like CONCAT('%',@ControlValue ,'%') ";
                }
                else if (cmbSearchOption.SelectedIndex == 2)
                {
                    sCondition = " where ControlCode like CONCAT('%',@ControlValue ,'%') ";
                }
            }

            grdModList.DataSource = null;
            grdModList.DataBind();
            DataTable Dt = new DataTable();
            string sCmd = " Select  " +
                                 " ControlID, ControlType, ControlCode, ControlName,  " +
                                 " ProcessType1, ProcessCode1, ProcessName1, ProcessMin1, ProcessMax1, ProcessOption1, " +
                                 " ProcessType2, ProcessCode2, ProcessName2, ProcessMin2, ProcessMax2, ProcessOption2, " +
                                 " ProcessType3, ProcessCode3, ProcessName3, ProcessMin3, ProcessMax3, ProcessOption3, " +
                                 " ProcessType4, ProcessCode4, ProcessName4, ProcessMin4, ProcessMax4, ProcessOption4, " +
                                 " ProcessType5, ProcessCode5, ProcessName5, ProcessMin5, ProcessMax5, ProcessOption5, " +
                                 " ProcessType6, ProcessCode6, ProcessName6, ProcessMin6, ProcessMax6, ProcessOption6, " +
                                 " ProcessType7, ProcessCode7, ProcessName7, ProcessMin7, ProcessMax7, ProcessOption7, " +
                                 " ProcessType8, ProcessCode8, ProcessName8, ProcessMin8, ProcessMax8, ProcessOption8, " +
                                 " ProcessType9, ProcessCode9, ProcessName9, ProcessMin9, ProcessMax9, ProcessOption9, " +
                                 " ProcessType10, ProcessCode10, ProcessName10, ProcessMin10, ProcessMax10, ProcessOption10 " +
                                 " from {0}.modifiercontrol " + sCondition + ";";



            string command = string.Format(sCmd, sDB);

            MySqlParameter[] parameters =
                    {
                     new MySqlParameter("@ControlValue", txtInputModifier.Text.Trim()),

                    };

            Dt = ObjMain.NewGetData_DT(command, parameters);
            grdModList.DataSource = Dt;
            grdModList.DataBind();

        }

        protected void btnApplySearch_Click(object sender, EventArgs e)
        {
            // XSS Attack Prevention 
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            Step1ViewListPopup(Microsoft.Security.Application.Encoder.HtmlEncode(Cmb_BranchName));
        }

        protected void btnApplySearchCondimentGroup_Click(object sender, EventArgs e)
        {
            // XSS Attack Prevention 
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            LevelsViewListPopup(Microsoft.Security.Application.Encoder.HtmlEncode(Cmb_BranchName));
        }

        private void Step1ViewListPopup(string sDB)
        {
            // Prevents SQL Injection 
            // Parameterized Approach

            DataTable Dt = new DataTable();
            string sCondition = string.Empty;
            if (txtInput.Text != "")
            {
                if (cmbSearch.SelectedValue == "Name")
                {

                    sCondition = " And InventoryName like  CONCAT('%', @Input, '%') ";
                }

                else if (cmbSearch.SelectedValue == "Desc")
                {

                    sCondition = " And Description like CONCAT('%', @Input, '%') ";

                }
                else if (cmbSearch.SelectedValue == "ID")
                {
                    sCondition = " And Barcode like CONCAT('%', @Input, '%') ";

                }


                MySqlConnection Cn = new MySqlConnection(ConStr_Rds);
                GrdLinkView.DataSource = null;
                GrdLinkView.DataBind();

                string sCmd = "Select Barcode as row1,Inventoryname as row2,Description as row3 from {0}.Inventory where barcode <> 'Round' and Active <> 0 " + sCondition + " ";
                string command = string.Format(sCmd, sDB);

                MySqlParameter[] parameters =
                        {
                     new MySqlParameter("@Input", Microsoft.Security.Application.Encoder.HtmlEncode(txtInput.Text.Trim())),

                    };

                Dt = ObjMain.NewGetData_DT(command, parameters);
                GrdLinkView.DataSource = Dt;
                GrdLinkView.DataBind();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModal();", true);
            }
        }


        private void LevelsViewListPopup(string sDB)
        {

            // XSS Attack Prevention 
            // Prevents SQL Injection 
            // Parameterized Approach
            string sCondition = string.Empty;
            DataTable Dt = new DataTable();
            if (txtCondimentGroupName.Text != "")
            {
                sCondition = " Where CondimentGroupName like  CONCAT('%',@CondimentGroupName,'%') ";
            }
            MySqlConnection Cn = new MySqlConnection(ConStr_Rds);
            GrdCondimentGroup.DataSource = null;
            GrdCondimentGroup.DataBind();

            string sCmd = "Select CondimentGroupID as row1,CondimentGroupName as row2,'' as row3 from {0}.Condimentgroup " + sCondition + " ";
            string command = string.Format(sCmd, sDB);
            MySqlParameter[] parameters =
                    {
                     new MySqlParameter("@CondimentGroupName", Microsoft.Security.Application.Encoder.HtmlEncode(txtCondimentGroupName.Text.Trim())),
                    };

            Dt = ObjMain.NewGetData_DT(command, parameters);
            GrdCondimentGroup.DataSource = Dt;
            GrdCondimentGroup.DataBind();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ShowModalCondimentGroup();", true);
        }

        private void DisableRowItem()
        {
            // XSS Attack Prevention 
            BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
            Cmb_BranchName = ObjSel.GetBranchDBNamebyFullName(Session["Branch_HQ"].ToString(), BranchFullName);
            //if (cmbStep1.SelectedValue == "1")
            //{
            //for (int i = 0; i < this.GrdLinkView.Rows.Count; i++)
            for (int i = 0; i < this.GrdLinkView.Rows.Count; i++)
            {
                CheckBox chkBox = (CheckBox)GrdLinkView.Rows[i].FindControl("chkSelect");
                Label lblBarcode = (Label)GrdLinkView.Rows[i].FindControl("lblID");
                //ValidateItem
                if (ValidateItem(Cmb_BranchName, cmbStep1.SelectedValue, Microsoft.Security.Application.Encoder.HtmlEncode(lblBarcode.Text.Trim())) == "true")
                {
                    GrdLinkView.Rows[i].Enabled = false;
                    GrdLinkView.Rows[i].ForeColor = System.Drawing.Color.FromArgb(211, 211, 211);
                }
            }
            //}
        }


    }
}