protected void TxtCategoryName_TextChanged(object sender, EventArgs e)
        {
            try
            {
                DataTable DtCategory = new DataTable();
                string    Comp_Code  = Session["COMP_CODE"].ToString();

                DtCategory = STOCKCategory_MASLogicLayer.GetAllSTOCKCategory_MASDetailWiseCompany(Comp_Code);
                if (TxtCategoryName.Text != string.Empty)
                {
                    DataView Dv = new DataView(DtCategory);
                    Dv.RowFilter = "CAT_NAME='" + TxtCategoryName.Text.Trim() + "'";
                    DataTable DtView = Dv.ToTable();
                    if (DtView.Rows.Count > 0)
                    {
                        HfCATCODE.Value = DtView.Rows[0]["CAT_CODE"].ToString();
                        Cat_Code        = Convert.ToInt32(DtView.Rows[0]["CAT_CODE"].ToString());
                    }
                    else
                    {
                        HfCATCODE.Value = string.Empty;
                        Cat_Code        = 0;
                    }
                }
                else
                {
                    HfCATCODE.Value = string.Empty;
                    Cat_Code        = 0;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                #region  DELETE

                if (HfStockCatCode.Value != string.Empty)
                {
                    string str = STOCKCategory_MASLogicLayer.DeleteSTOCKCategory_MASDetailsByID(HfStockCatCode.Value);
                    if (str.Contains("successfully"))
                    {
                        lblmsg.Text      = "Record Deleted Successfully";
                        lblmsg.ForeColor = Color.Green;
                    }
                    else if (str.Contains("Cannot"))
                    {
                        lblmsg.Text      = "Cannot Delete This Record It Used by Other Data";
                        lblmsg.ForeColor = Color.Red;
                    }
                    else
                    {
                        lblmsg.Text      = "Error:Stock Category Not Deleted";
                        lblmsg.ForeColor = Color.Red;
                    }
                    clear();
                    FillGrid(Session["COMP_CODE"].ToString());
                    UserRights();
                }
                #endregion
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void FillGrid(string CompCode)
        {
            try
            {
                DataTable Dt = new DataTable();

                Dt = STOCKCategory_MASLogicLayer.GetAllSTOCKCategory_MASDetails(Convert.ToInt32(Session["USERCODE"].ToString()), Convert.ToInt32(Session["COMP_CODE"].ToString()));
                DataView Dv = new DataView(Dt);
                if (CompCode != string.Empty)
                {
                    Dv.RowFilter = "COMP_CODE=" + Session["COMP_CODE"].ToString();
                }
                GvStockCatMaster.DataSource = Dv.ToTable();
                GvStockCatMaster.DataBind();
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void BtncallUpd_Click(object sender, EventArgs e)
        {
            try
            {
                if (BtncallUpd.Text == "UPDATE")
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ShowModel1", "ShowModel1()", true);
                }
                else
                {
                    STOCKCategory_MASLogicLayer insert = new STOCKCategory_MASLogicLayer();
                    insert.CAT_CODE     = HfStockCatCode.Value.Trim();
                    insert.CAT_NAME     = TxtStoctCatName.Text.Trim().ToUpper();
                    insert.ACTIVE       = "";
                    insert.PRODUCT_NO   = "";
                    insert.PRODUCT_DESC = "";

                    if (TxtStockOrder.Text == string.Empty)
                    {
                        insert.ORD_NO = "0";
                    }
                    else
                    {
                        insert.ORD_NO = TxtStockOrder.Text.Trim();
                    }
                    insert.REF_CAT_CODE = "0";
                    insert.CAT_TYPE     = "";
                    insert.RW_TYPE      = "";
                    insert.COMP_CODE    = Session["COMP_CODE"].ToString();
                    insert.CAT_CETHNO   = TxtTarrifNo.Text.Trim().ToUpper();
                    insert.INS_USERID   = Session["USERNAME"].ToString();
                    insert.INS_TERMINAL = Session["PC"].ToString();
                    insert.INS_DATE     = "";
                    insert.UPD_USERID   = Session["USERNAME"].ToString();
                    insert.UPD_TERMINAL = Session["PC"].ToString();
                    insert.UPD_DATE     = "";


                    if (BtncallUpd.Text.Trim().ToUpper() == "SAVE")
                    {
                        string str = STOCKCategory_MASLogicLayer.InsertSTOCKCategory_MASDetail(insert);
                        if (str.Contains("successfully"))
                        {
                            lblmsg.Text      = "STOCK CATEGORY DETAIL ADD SUCCESSFULLY.";
                            lblmsg.ForeColor = Color.Green;
                            clear();
                            FillGrid(Session["COMP_CODE"].ToString());
                            UserRights();
                        }
                        else if (str.Contains("Already") || str.Contains("PRIMARY KEY"))
                        {
                            lblmsg.Text      = "STOCK CATEGORY MASTER ALREADY EXIST.";
                            lblmsg.ForeColor = Color.Red;
                        }
                        else
                        {
                            lblmsg.Text      = "ERROR : STOCK CATEGORY DETAIL NOT SAVED";
                            lblmsg.ForeColor = Color.Red;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void GvStockCatMaster_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Deletea")
                {
                    #region DELETE
                    clear();
                    //    string COMP_CODE = HfCompCode.Value;
                    DataTable dt = STOCKCategory_MASLogicLayer.GetAllIDWiseSTOCKCategory_MASDetail(e.CommandArgument.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        DivEntry.Visible = true;
                        DivView.Visible  = false;

                        HfStockCatCode.Value = dt.Rows[0]["CAT_CODE"].ToString();
                        HfCompCode.Value     = dt.Rows[0]["COMP_CODE"].ToString();
                        TxtStoctCatName.Text = dt.Rows[0]["CAT_NAME"].ToString();
                        TxtTarrifNo.Text     = dt.Rows[0]["CAT_CETHNO"].ToString();
                        TxtStockOrder.Text   = dt.Rows[0]["ORD_NO"].ToString();
                    }
                    btnSave.Visible    = false;
                    btnDelete.Visible  = true;
                    Btncalldel.Visible = true;
                    BtncallUpd.Visible = false;
                    ControllerDisable();

                    #endregion
                }

                if (e.CommandName == "Edita")
                {
                    #region EDIT
                    clear();
                    //    string COMP_CODE = HfCompCode.Value;
                    DataTable dt = STOCKCategory_MASLogicLayer.GetAllIDWiseSTOCKCategory_MASDetail(e.CommandArgument.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        DivEntry.Visible = true;
                        DivView.Visible  = false;

                        HfStockCatCode.Value = dt.Rows[0]["CAT_CODE"].ToString();
                        HfCompCode.Value     = dt.Rows[0]["COMP_CODE"].ToString();
                        TxtStoctCatName.Text = dt.Rows[0]["CAT_NAME"].ToString();
                        TxtTarrifNo.Text     = dt.Rows[0]["CAT_CETHNO"].ToString();
                        TxtStockOrder.Text   = dt.Rows[0]["ORD_NO"].ToString();

                        BtncallUpd.Text = "UPDATE";

                        #endregion
                    }
                    #region CHECK UPDATE RIGHTS
                    if (Session["UPDATE"] != null)
                    {
                        if (Session["UPDATE"].ToString() == "Y")
                        {
                            ControllerEnable();
                        }
                        else
                        {
                            ControllerDisable();
                        }
                    }
                    #endregion
                    Btncalldel.Visible = false;
                    BtncallUpd.Visible = true;
                    btnSave.Visible    = true;
                    UserRights();
                }

                if (e.CommandName == "Viewa")
                {
                    #region SET TEXT ON VIEW
                    clear();

                    DataTable dt = STOCKCategory_MASLogicLayer.GetAllIDWiseSTOCKCategory_MASDetail(e.CommandArgument.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        DivEntry.Visible = true;
                        DivView.Visible  = false;

                        HfStockCatCode.Value = dt.Rows[0]["CAT_CODE"].ToString();
                        HfCompCode.Value     = dt.Rows[0]["COMP_CODE"].ToString();
                        TxtStoctCatName.Text = dt.Rows[0]["CAT_NAME"].ToString();
                        TxtTarrifNo.Text     = dt.Rows[0]["CAT_CETHNO"].ToString();
                        TxtStockOrder.Text   = dt.Rows[0]["ORD_NO"].ToString();

                        #endregion
                    }
                    ControllerDisable();
                    btnSave.Visible    = false;
                    Btncalldel.Visible = false;
                    BtncallUpd.Visible = false;
                    UserRights();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                #region INSERT _ UPDATE VALUE
                STOCKCategory_MASLogicLayer insert = new STOCKCategory_MASLogicLayer();
                insert.CAT_CODE     = HfStockCatCode.Value.Trim();
                insert.CAT_NAME     = TxtStoctCatName.Text.Trim().ToUpper();
                insert.ACTIVE       = "";
                insert.PRODUCT_NO   = "";
                insert.PRODUCT_DESC = "";

                if (TxtStoctCatName.Text == string.Empty)
                {
                    insert.ORD_NO = "0";
                }
                else
                {
                    insert.ORD_NO = TxtStockOrder.Text.Trim();
                }
                insert.REF_CAT_CODE = "0";
                insert.CAT_TYPE     = "";
                insert.RW_TYPE      = "";
                insert.COMP_CODE    = HfCompCode.Value.Trim();
                insert.CAT_CETHNO   = TxtTarrifNo.Text.Trim().ToUpper();
                insert.INS_USERID   = Session["USERNAME"].ToString();
                insert.INS_TERMINAL = Session["PC"].ToString();
                //  insert.INS_DATE = "";
                insert.UPD_USERID   = Session["USERNAME"].ToString();
                insert.UPD_TERMINAL = Session["PC"].ToString();
                //    insert.UPD_DATE = "";

                #endregion


                if (btnSave.Text.Trim().ToUpper() == "SAVE")
                {
                    string str = STOCKCategory_MASLogicLayer.InsertSTOCKCategory_MASDetail(insert);
                    if (str.Contains("successfully"))
                    {
                        lblmsg.Text      = "STOCK CATEGORY DETAIL ADD SUCCESSFULLY.";
                        lblmsg.ForeColor = Color.Green;
                        clear();
                        FillGrid(Session["COMP_CODE"].ToString());
                        UserRights();
                    }
                    else if (str.Contains("Already") || str.Contains("PRIMARY KEY"))
                    {
                        lblmsg.Text      = "STOCK CATEGORY MASTER ALREADY EXIST.";
                        lblmsg.ForeColor = Color.Red;
                    }
                    else
                    {
                        lblmsg.Text      = "ERROR : STOCK CATEGORY DETAIL NOT SAVED";
                        lblmsg.ForeColor = Color.Red;
                    }
                }
                else
                {
                    string str = STOCKCategory_MASLogicLayer.UpdateSTOCKCategory_MASDetail(insert);
                    if (str.Contains("successfully"))
                    {
                        lblmsg.Text      = "STOCK CATEGORY DETAIL UPDATE SUCCESSFULLY.";
                        lblmsg.ForeColor = Color.Green;
                        clear();
                        FillGrid(Session["COMP_CODE"].ToString());
                        UserRights();
                    }
                    else if (str.Contains("Already") || str.Contains("PRIMARY KEY"))
                    {
                        lblmsg.Text      = "STOCK CATEGORY MASTER ALREADY EXIST.";
                        lblmsg.ForeColor = Color.Red;
                    }
                    else
                    {
                        lblmsg.Text      = "ERROR : STOCK CATEGORY DETAIL NOT SAVED";
                        lblmsg.ForeColor = Color.Red;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }