i want to use multiple forms in my addon but it give menu already exist, creates menus to SAP business one side bar but didn't open the forms.
here i posting my code
MENU file:
using System;
using System.Collections.Generic;
using System.Text;
using SAPbouiCOM.Framework;
namespace ER_B1_HR_AdOn
{
class Menu
{
public void AddMenuItems(SAPbouiCOM.Application Application)
{
SAPbouiCOM.Menus oMenus = null;
SAPbouiCOM.MenuItem oMenuItem = null;
oMenus = Application.Menus;
SAPbouiCOM.MenuCreationParams oCreationPackage = null;
oCreationPackage = ((SAPbouiCOM.MenuCreationParams)(Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)));
oMenuItem = Application.Menus.Item("43520"); // moudles'
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_POPUP;
oCreationPackage.UniqueID = "ER_B1_HR_AdOn";
oCreationPackage.String = "ER_B1_HR_AdOn";
oCreationPackage.Enabled = true;
oCreationPackage.Position = -1;
oMenus = oMenuItem.SubMenus;
try
{
// If the manu already exists this code will fail
oMenus.AddEx(oCreationPackage);
}
catch (Exception e)
{
}
try
{
// Get the menu collection of the newly added pop-up item
oMenuItem = Application.Menus.Item("ER_B1_HR_AdOn");
oMenus = oMenuItem.SubMenus;
// Create s sub menu
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
//Please replace following 2 "Form1" with real form class in current project
oCreationPackage.UniqueID = "ER_B1_HR_AdOn.displaypayrollinfo_b1f";
oCreationPackage.String = "displaypayrollinfo_b1f";
oMenus.AddEx(oCreationPackage);
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
oCreationPackage.UniqueID = "ER_B1_HR_AdOn.displaybasicinfo_b1f";
oCreationPackage.String = "displaybasicinfo_b1f";
oMenus.AddEx(oCreationPackage);
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
oCreationPackage.UniqueID = "ER_B1_HR_AdOn.createbankdetails_b1f";
oCreationPackage.String = "createbankdetails_b1f";
oMenus.AddEx(oCreationPackage);
Application.MenuEvent += new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler(SBO_Application_MenuEvent);
}
catch (Exception er)
{ // Menu already exists
Application.SetStatusBarMessage("Menu Already Exists", SAPbouiCOM.BoMessageTime.bmt_Short, true);
}
}
public void SBO_Application_MenuEvent(ref SAPbouiCOM.MenuEvent pVal, out bool BubbleEvent)
{
BubbleEvent = true;
try
{
//Please replace following 3 "Form1" with real form class in current project
if (pVal.BeforeAction && pVal.MenuUID == "ER_B1_HR_AdOn.displaypayrollinfo_b1f")
{
displaypayrollinfo_b1f activeForm1 = new displaypayrollinfo_b1f();
activeForm1.Show();
}
else if (pVal.BeforeAction && pVal.MenuUID == "ER_B1_HR_AdOn.displaybasicinfo_b1f")
{
displaybasicinfo_b1f activeForm2 = new displaybasicinfo_b1f();
activeForm2.Show();
}
else if (pVal.BeforeAction && pVal.MenuUID == "ER_B1_HR_AdOn.createbankdetails_b1f")
{
createbankdetails_b1f activeForm3 = new createbankdetails_b1f();
}
}
catch (Exception ex)
{
Application.SBO_Application.MessageBox(ex.ToString(), 1, "Ok", "", "");
}
}
}
}
PROGRAM file:
using System;
using System.Collections.Generic;
using SAPbouiCOM.Framework;
using Microsoft.VisualBasic;
namespace ER_B1_HR_AdOn
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
SAPbouiCOM.Application SBO_Application;
SAPbouiCOM.SboGuiApi SboGuiApi = null;
String sconnectionstring = null;
SboGuiApi = new SAPbouiCOM.SboGuiApi();
sconnectionstring = Interaction.Command();
SboGuiApi.Connect(sconnectionstring);
Menu mymenu = new Menu();
SBO_Application = SboGuiApi.GetApplication(-1);
mymenu.AddMenuItems(SBO_Application);
// Program SBOSysform = new Program();
System.Windows.Forms.Application.Run();
//Application oApp = null;
//if (args.Length < 1)
//{
// oApp = new Application();
//}
//else
//{
// oApp = new Application(args[1]);
//}
//Menu MyMenu = new Menu();
//MyMenu.AddMenuItems();
//oApp.RegisterMenuEventHandler(MyMenu.SBO_Application_MenuEvent);
//oApp.Run();
}
}
}