Skip to Content
-2
J S
Feb 12, 2020 at 05:08 AM

Code not working

49 Views

Hi

I have below code but it is not going in oApp_menuEvent

public clsCommon()
        {
            try
            {
                SetApplication();
                oCompany = (SAPbobsCOM.Company)oApp.Company.GetDICompany();
                oApp.MessageBox("U r connected To : " + oCompany.CompanyName, 1, "Ok", "", "");
                AddMenuItems();
                bool tmpBool = true;
                oApp.MenuEvent += new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler(oApp_MenuEvent);
                oApp.AppEvent += new SAPbouiCOM._IApplicationEvents_AppEventEventHandler(oApp_AppEvent);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void AddMenuItems()
        {
            SAPbouiCOM.Menus oMenus = null;
            SAPbouiCOM.MenuItem oMenuItem = null;


            int i = 0; // to be used as counter
            int lAddAfter = 0;
            oMenus = oApp.Menus;
             SAPbouiCOM.MenuCreationParams oCreationPackage = null;
            oCreationPackage = ((SAPbouiCOM.MenuCreationParams)(oApp.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)));
            oMenuItem = oApp.Menus.Item("43520"); // moudles'

            string sPath = null;
            sPath = Application.StartupPath;
            sPath = sPath.Remove(sPath.Length - 9, 9);

            oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_POPUP;
            oCreationPackage.UniqueID = "MyMenu01";
            oCreationPackage.String = "Sample Menu";
            oCreationPackage.Enabled = true;
            oCreationPackage.Image = sPath + "UI.bmp";
            oCreationPackage.Position = 15;
            oMenus = oMenuItem.SubMenus;
            try
            {
                oMenus.AddEx(oCreationPackage);
                oMenuItem = oApp.Menus.Item("MyMenu01");
                oMenus = oMenuItem.SubMenus;


                oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
                oCreationPackage.UniqueID = "MySubMenu";
                oCreationPackage.String = "Sample Sub Menu";
                oMenus.AddEx(oCreationPackage);
            }
            catch (Exception er)
            {
            }
        }


        private void oApp_MenuEvent(ref SAPbouiCOM.MenuEvent pVal, out bool BubbleEvent)
        {
            BubbleEvent = false;
            if (pVal.BeforeAction == false)
            {
                switch (pVal.MenuUID)
                {
                    case "MySubMenu":
                        GatePass();
                        break;
                }
            }
        }

Thanks