private static void SetApplication() { SboGuiApi sboGuiApi = (SboGuiApi) new SboGuiApiClass(); sboGuiApi.Connect(GetConnectionString()); application = sboGuiApi.GetApplication(-1); }
/// <summary> /// Create SAP application context /// </summary> /// <returns>SAP application context</returns> public static Application GetApplication() { SboGuiApi guiApi = new SboGuiApi(); guiApi.Connect(Convert.ToString(Environment.GetCommandLineArgs().GetValue(1))); return(guiApi.GetApplication(-1)); }
public static void Init() { SboGuiApi sboGuiApi = new SboGuiApi(); sboGuiApi.Connect(Config.ConnectionStringSAP); var app = sboGuiApi.GetApplication(); var company = app.Company.GetDICompany() as SAPbobsCOM.Company; Data.SAPConnection.Init(company, app); }
/// <summary> Connects UI. </summary> /// <remarks> Ranaya, 04/05/2017. </remarks> protected void ConnectToUI() { //Create new SBO Application instance SBOApplication = new SboGuiApi(); //Get connection string from command line ConnectionString = System.Convert.ToString(Environment.GetCommandLineArgs().GetValue(1)); //Connect using connection string SBOApplication.Connect(ConnectionString); //Get UI Application Application = this.SBOApplication.GetApplication(ApplicationId); }
public SAPbobsCOM.Company connect(string connString) { try{ sboGui = new SboGuiApi(); CONNSTR = connString; sboGui.Connect(CONNSTR); oApp = sboGui.GetApplication(); oCompany = (SAPbobsCOM.Company)oApp.Company.GetDICompany(); oApp.StatusBar.SetText("Conectado", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success); //logger.log("Conectado", Log.Logger.LogType.INFO); } catch (Exception e) { SB1ControlException.SB1ControlException.Save(e); } return(oCompany); }
/// <summary> /// Connects this instance. /// </summary> /// <exception cref="ConnectionException"> /// Thrown when an error connecting to Business One occurs. /// </exception> public void Connect() { try { if (Connected) { return; } var gui = new SboGuiApi(); gui.Connect(connectionString); Application = gui.GetApplication(); } catch (COMException e) { throw ConnectionException.CreateFrom(e); } Connected = true; }
private void ConnectUi() { try { Logger.Info("Initializing UI API for SAP Business One Addon - {0}", Name); if (Environment.GetCommandLineArgs() == null || Environment.GetCommandLineArgs().Length < 2) { throw new ArgumentException("No connectionstring passed to executable"); } var link = new SboGuiApi(); link.Connect(Environment.GetCommandLineArgs().ElementAt(1)); Application = link.GetApplication(); Logger.Info("Addon {0} initialized and connected to SAP Business One UI API", Name); } catch (Exception e) { throw new Exception("Error connecting to UI API", e); } }
public static void ConnectViaUI() { try { SboGuiApi uiApi = new SboGuiApi(); // 1. Get the Connection String String connectionString = Convert.ToString(Environment.GetCommandLineArgs().GetValue(1)); // 2. Connect to UI API Object uiApi.Connect(connectionString); // License for your Add On (your IP) // Add-On Identifier // 3. Get the B1 Application Object oApplication = uiApi.GetApplication(); // 4. (To-Do) Delegate other sub component (e.g. AppEvent, etc.) GenericEventHandler.RegisterEventHandler(); // 5. (To-Do) Setup Event filters } catch (Exception ex) { MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } }
private int getProcessID() { var gui = new SboGuiApi(); try { gui.Connect("0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"); } catch (Exception) { return(-1); } var appId = gui.GetApplication().AppId; var processes = Process.GetProcessesByName(@"SAP Business One").Where(x => x.SessionId == Process.GetCurrentProcess().SessionId); foreach (var process in processes) { try { var processAppId = gui.GetAppIdFromProcessId(process.Id); if (appId == processAppId) { return(process.Id); } } catch (COMException) { // GetAppIdFromProcessId will throw when the current process is not the one we are connected to continue; } } return(-1); }
public B1Application(string connectionString, bool autoMigrate = false) { Check.IsNotNullOrEmpty("connectionString", connectionString); _systemForms = new ServiceLocator(); _userForms = new ServiceLocator(); _forms = new Dictionary <string, IB1Form>(); _errorHandler = new DefaultExceptionPolicy(); _modalForms = new List <string>(); _sboGuiApi = new SboGuiApi(); _sboGuiApi.Connect(connectionString); _sboApplication = _sboGuiApi.GetApplication(); _sboCompany = _sboApplication.Company.GetDICompany() as SAPbobsCOM.Company; _sboApplication.AppEvent += new _IApplicationEvents_AppEventEventHandler(OnApplicationEvent); _sboApplication.ItemEvent += new _IApplicationEvents_ItemEventEventHandler(OnAppItemEvent); _sboApplication.MenuEvent += new _IApplicationEvents_MenuEventEventHandler(OnAppMenuEvent); _sboApplication.FormDataEvent += new _IApplicationEvents_FormDataEventEventHandler(OnAppFormDataEvent); _sboApplication.RightClickEvent += new _IApplicationEvents_RightClickEventEventHandler(OnAppRightClick); _menus = new B1AppMenu(this); _businessObjects = new B1BusinessObjects(this); _permissionManager = new B1PermissionManager(this); _autoMigrate = autoMigrate; _currentApplication = this; }
public UDClass(string connectString) { string errmsg = ""; try { SboGuiApi sboApi = new SboGuiApi(); if (connectString == "") { MessageBox.Show("Add-on must be run from SAP Business One."); } sboApi.Connect(connectString); oApplication = sboApi.GetApplication(); oCompany = new SAPbobsCOM.Company(); string sCookies = oCompany.GetContextCookie(); string conStr = oApplication.Company.GetConnectionContext(sCookies); int ret = oCompany.SetSboLoginContext(conStr); int ret2 = 0;//; oCompany.Connect(); oCompany = oApplication.Company.GetDICompany(); if (ret2 == 0) { oApplication.StatusBar.SetText("Addon Connected Successfully.!", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success); oApplication.MenuEvent += new _IApplicationEvents_MenuEventEventHandler(oApplication_MenuEvent); oApplication.AppEvent += new _IApplicationEvents_AppEventEventHandler(oApplication_appEvent); oApplication.ItemEvent += new _IApplicationEvents_ItemEventEventHandler(oApplication_ItemEvent); string lang = oApplication.Language.ToString(); Program.sboLanguage = lang; try { int langnum = Convert.ToInt16(oApplication.Language.ToString()); lang = "_" + lang; } catch { } if (lang.Contains("English")) { lang = "ln_English"; } Program.sboLanguage = lang; loadMenu(lang); Program.sboLanguage = lang; // execTimer(); } else { MessageBox.Show(oCompany.GetLastErrorDescription()); MessageBox.Show("UI Not connected"); Environment.Exit(0); } } catch (Exception ex) { MessageBox.Show("Unable to connect company!" + ex.Message); Environment.Exit(0); } }