Пример #1
0
        /// <summary>
        /// Connect only DI Api
        /// </summary>
        /// <param name="serverName">SQL Server Name</param>
        /// <param name="serverType">Server type</param>
        /// <param name="companyDb"></param>
        /// <param name="dbUsername"></param>
        /// <param name="dbPassword"></param>
        /// <param name="username">SBO Username</param>
        /// <param name="password">SBO Password</param>
        /// <param name="licenceServer">Licence Server</param>
        public static void DiConnect(string serverName, SAPbobsCOM.BoDataServerTypes serverType, string companyDb,
                                     string dbUsername = null, string dbPassword = null, string username = null, string password = null, string licenceServer = null)
        {
            _diCompany = new SAPbobsCOM.Company
            {
                Server       = serverName,
                DbServerType = serverType,
                CompanyDB    = companyDb
            };

            if (licenceServer != null)
            {
                _diCompany.LicenseServer = licenceServer;
            }

            if (string.IsNullOrEmpty(username))
            {
                _diCompany.UseTrusted = true;
            }
            else
            {
                _diCompany.UseTrusted = false;
                _diCompany.UserName   = username;
                _diCompany.Password   = password;
                _diCompany.DbUserName = dbUsername;
                _diCompany.DbPassword = dbPassword;
            }

            var connectResponse = _diCompany.Connect();

            if (connectResponse != 0)
            {
                int    errCode;
                string errMsg;
                _diCompany.GetLastError(out errCode, out errMsg);

                Logger.Debug($"Servername={serverName}, CompanyDb={companyDb}, ServerType={serverType}, " +
                             $"DbUsername={dbUsername}, DbPassword={dbPassword}, " +
                             $"SboUsername={username}, SboPassword={password}, " +
                             $"UseTrusted={_diCompany.UseTrusted}, " +
                             $"LicenceServer={licenceServer}");

                throw new Exception($"DI Connect Error: {errCode} {errMsg}");
            }

            if (serverType == BoDataServerTypes.dst_HANADB)
            {
                HanaHandlers.Register();
            }
        }
Пример #2
0
        private static void InitializeServerVariables(out SAPbobsCOM.BoDataServerTypes dbType, out String DatabaseName, out String Server, out String LicenseServer, out String User, out String Password
                                                      , out String sUseTrusted, out String dbUserName, out String dbPassword)
        {
            TWM_Licence.TWM_SAP oEncrypter = new TWM_Licence.TWM_SAP(new Byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 10, 73, 1, 5, 75, 1, 8 });
            //Initialize all the environment variable for config file.
            //If nonspecified strings, write the default to config file.

            //Get the dbServerType
            if (frmSetting.GetConfigLine(sConfig_File, "dbServerType") != null)
            {
                dbType = (SAPbobsCOM.BoDataServerTypes) int.Parse(frmSetting.GetConfigLine(sConfig_File, "dbServerType"));
            }
            else
            {
                dbType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
                frmSetting.WriteConfigFile(sConfig_File, "dbServerType", ((int)dbType).ToString(), frmSetting.WriteType.Append);
            }


            //Get the DatabaseName
            if (frmSetting.GetConfigLine(sConfig_File, "DatabaseName") != null)
            {
                DatabaseName = frmSetting.GetConfigLine(sConfig_File, "DatabaseName");
            }
            else
            {
                DatabaseName = "UNZA";
                frmSetting.WriteConfigFile(sConfig_File, "DatabaseName", DatabaseName, frmSetting.WriteType.Append);
            }


            //Get the Server
            if (frmSetting.GetConfigLine(sConfig_File, "ServerName") != null)
            {
                Server = frmSetting.GetConfigLine(sConfig_File, "ServerName");
            }
            else
            {
                Server = "sapserver";
                frmSetting.WriteConfigFile(sConfig_File, "ServerName", Server, frmSetting.WriteType.Append);
            }


            //Get the License Server
            if (frmSetting.GetConfigLine(sConfig_File, "LicenseServer") != null)
            {
                LicenseServer = frmSetting.GetConfigLine(sConfig_File, "LicenseServer");
            }
            else
            {
                LicenseServer = "sapserver:30000";
                frmSetting.WriteConfigFile(sConfig_File, "LicenseServer", LicenseServer, frmSetting.WriteType.Append);
            }


            //Get the User
            if (frmSetting.GetConfigLine(sConfig_File, "User") != null)
            {
                User = frmSetting.GetConfigLine(sConfig_File, "User");
            }
            else
            {
                User = "******";
                frmSetting.WriteConfigFile(sConfig_File, "User", User, frmSetting.WriteType.Append);
            }

            //Get the Password
            if (frmSetting.GetConfigLine(sConfig_File, "Password") != null)
            {
                Password = frmSetting.GetConfigLine(sConfig_File, "Password");
                Password = oEncrypter.Decrypt(Password);
            }
            else
            {
                Password = "******";
                String EncryptedPass = oEncrypter.Encrypt(Password);
                frmSetting.WriteConfigFile(sConfig_File, "Password", EncryptedPass, frmSetting.WriteType.Append);
            }


            //Get the UseTrusted
            if (frmSetting.GetConfigLine(sConfig_File, "UseTrusted") != null)
            {
                sUseTrusted = frmSetting.GetConfigLine(sConfig_File, "UseTrusted");
            }
            else
            {
                sUseTrusted = "0";
                frmSetting.WriteConfigFile(sConfig_File, "UseTrusted", sUseTrusted, frmSetting.WriteType.Append);
            }


            //if Not UseTrusted, Get The DBUserName And DBPassword
            if (sUseTrusted != "1")
            {
                //Get the User
                if (frmSetting.GetConfigLine(sConfig_File, "DBUserName") != null)
                {
                    dbUserName = frmSetting.GetConfigLine(sConfig_File, "DBUserName");
                }
                else
                {
                    dbUserName = "******";
                    frmSetting.WriteConfigFile(sConfig_File, "DBUserName", dbUserName, frmSetting.WriteType.Append);
                }


                //Get the Password
                if (frmSetting.GetConfigLine(sConfig_File, "DBPassword") != null)
                {
                    dbPassword = frmSetting.GetConfigLine(sConfig_File, "DBPassword");
                    dbPassword = oEncrypter.Decrypt(dbPassword);
                }
                else
                {
                    dbPassword = "******";
                    String EncryptedPass = oEncrypter.Encrypt(dbPassword);
                    frmSetting.WriteConfigFile(sConfig_File, "DBPassword", EncryptedPass, frmSetting.WriteType.Append);
                }
            }
            else
            {
                dbUserName = "";
                dbPassword = "";
            }
        }
Пример #3
0
        static void Main(String[] Args)
        {
            //Create an Event Log
            if (Args.Length == 0)
            {
                SAPbouiCOM.SboGuiApi oGUI = new SAPbouiCOM.SboGuiApi();
                oGUI.Connect(eCommon.SBOConnectionString);
                try
                {
                    eCommon.SetApplication(oGUI.GetApplication(-1), gcAddOnName, true);
                    //SBOAddon_DB addOnDb = new SBOAddon_DB();

                    SBOAddon oAddOn = new SBOAddon();
                    if (oAddOn.Connected)
                    {
                        System.Windows.Forms.Application.Run();
                    }
                }
                catch (Exception Ex)
                {
                    System.Windows.Forms.MessageBox.Show("ERROR - Connection failed: " + Ex.Message);;
                }
            }
            else
            {
                switch (Args[0].ToUpper())
                {
                case "READNUPDATE":
                    eCommon.CreateLogFileNoUI();
                    try
                    {
                        SAPbobsCOM.BoDataServerTypes ServerType = BoDataServerTypes.dst_MSSQL2012;
                        String Server     = null;
                        String LicServer  = null;
                        String CompDB     = null;
                        String UserName   = null;
                        String Password   = null;
                        String UseTrusted = "0";
                        String DBUserName = null;
                        String DBPassword = null;
                        InitializeServerVariables(out ServerType, out CompDB, out Server, out LicServer, out UserName, out Password, out UseTrusted, out DBUserName, out DBPassword);
                        eCommon.InitCompany(ServerType, Server, LicServer, CompDB, UserName, Password);
                    }
                    catch (Exception Ex)
                    {
                        eCommon.WriteEventLog("Could not connect to company. " + Ex.Message);
                    }

                    if (eCommon.oCompany.Connected)
                    {
                        ReadAndUpdateDB _rnu = new ReadAndUpdateDB();
                    }

                    break;

                case "SETTING":
                    frmSetting frm = new frmSetting();
                    frm.ShowDialog();
                    break;
                }
            }
        }