Example #1
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 = "";
            }
        }
Example #2
0
        private void FillConfigLineToScreen()
        {
            String     sValue     = "";
            ConfigLine ConfigItem = new ConfigLine();

            for (int i = 0; i < ConfigLines.Count; i++)
            {
                sValue = "";
                sValue = GetConfigLine(SBOAddon.sConfig_File, ConfigLines[i].Key);

                ConfigItem.Group = ConfigLines[i].Group;
                ConfigItem.Key   = ConfigLines[i].Key;
                if (sValue != null)
                {
                    ConfigItem.Value = sValue;
                }
                else
                {
                    ConfigItem.Value = "";
                }

                ConfigLines[i] = ConfigItem;
                switch (ConfigItem.Key.ToUpper())
                {
                case "DBSERVERTYPE":
                    if (ConfigItem.Value == "")
                    {
                        ConfigItem.Value = "0";
                    }
                    cboDbType.SelectedIndex = int.Parse(ConfigItem.Value) - 1;
                    break;

                case "DATABASENAME":
                    if (sValue == null)
                    {
                        txtDBName.Text = "Default : " + DatabaseName;
                    }
                    else
                    {
                        txtDBName.Text = ConfigItem.Value;
                    }
                    break;

                case "SERVERNAME":
                    if (sValue == null)
                    {
                        txtSrvrName.Text = "Default : " + ServerName;
                    }
                    else
                    {
                        txtSrvrName.Text = ConfigItem.Value;
                    }
                    break;

                case "LICENSESERVER":
                    String[] License = ConfigItem.Value.Split(':');
                    if (sValue == null)
                    {
                        txtLcnsSrvr.Text = "Default : " + LicenseServer;
                        txtLcnsPort.Text = LicensePort;
                    }
                    else
                    {
                        if (License.Length > 1)
                        {
                            txtLcnsSrvr.Text = License[0];
                            txtLcnsPort.Text = License[1];
                        }
                        else if (License.Length == 1)
                        {
                            txtLcnsSrvr.Text = License[0];
                        }
                    }
                    break;

                case "USER":
                    if (sValue == null)
                    {
                        txtUserName.Text = "Default : " + User;
                    }
                    else
                    {
                        txtUserName.Text = ConfigItem.Value;
                    }

                    break;

                case "PASSWORD":
                    if (sValue == null)
                    {
                        txtPassword.Text = "Default : " + Password;
                    }
                    else
                    {
                        String DecryptedString = "";
                        try
                        {
                            DecryptedString  = encrypter.Decrypt(sValue);
                            txtPassword.Text = DecryptedString;
                        }
                        catch
                        {
                            MessageBox.Show("Password is not in expected format \n\r Please fill in correct password in 'Company tab'", "Password error", MessageBoxButtons.OK);
                            txtPassword.Text = "";
                        }
                    }
                    break;

                case "USETRUSTED":
                    if (sValue == null)
                    {
                        if (ConfigItem.Value == "1")
                        {
                            chbTrusted.Checked = true;
                        }
                        else
                        {
                            chbTrusted.Checked = false;
                        }
                    }
                    else
                    {
                        if (sValue.ToUpper() == "Y" || sValue == "1")
                        {
                            chbTrusted.Checked = true;
                        }
                        else
                        {
                            chbTrusted.Checked = false;
                        }
                    }

                    if (chbTrusted.Checked)
                    {
                        grpTrusted.Enabled = false;
                    }
                    else
                    {
                        grpTrusted.Enabled = true;
                    }

                    break;

                case "DBUSER":
                    if (sValue == null)
                    {
                        txtDBUser.Text = "Default : " + DBUser;
                    }
                    else
                    {
                        txtDBUser.Text = sValue;
                    }

                    break;

                case "DBPASSWORD":
                    if (sValue == null)
                    {
                        txtDBPassword.Text = "Default : " + DBPassword;
                    }
                    else
                    {
                        String DecryptedString = "";
                        try
                        {
                            DecryptedString    = encrypter.Decrypt(sValue);
                            txtDBPassword.Text = DecryptedString;
                        }
                        catch
                        {
                            MessageBox.Show("Password is not in expected format \r\nPlease fill in correct password.", "Password error", MessageBoxButtons.OK);
                            txtPassword.Text = "";
                        }
                    }
                    break;
                }
            }
        }