public FormServerConfig()
        {
            // set default security salt
            sqlOptionsDefault.securitySalt = optionsDefault.securitySalt;
            queOptionsDefault.securitySalt = optionsDefault.securitySalt;

            // user options gets default value first
            optionsUser       = optionsDefault;
            sqliteOptionsUser = sqliteOptionsDefault;
            sqlOptionsUser    = sqlOptionsDefault;
            queOptionsUser    = queOptionsDefault;

            InitializeComponent();

            // Database SQLite is default option
            rbSqlite.Checked         = true;
            chkSqlUseDefault.Enabled = false;
            // Set form initial values from user options
            tbSecuritySalt.Text = optionsDefault.securitySalt;
            tbSqliteDbPath.Text = sqliteOptionsDefault.dbFilePath;
            SetFormValuesFromSqlOptionsDefault();
            SetFormValuesFromQueOptionsDefault();

            startupcompleted = true;
        }
        private void OnApplyConfig(object sender, EventArgs e)
        {
            if (!ValidateTobasaModules())
            {
                return;
            }


            if (!ValidateSecuritySalt())
            {
                MessageBox.Show("Please check security salt input", "Security salt invalid");
                return;
            }

            if (!ValidateSqliteDb())
            {
                MessageBox.Show("Please check SQLite Database input", "SQLite Database invalid");
                return;
            }

            if (!ValidateSqlPasswordInput())
            {
                MessageBox.Show("Please check SQL Server password input", "Password does not match");
                return;
            }

            if (!ValidateQueuePasswordInput())
            {
                MessageBox.Show("Please check QueueServer password input", "Password does not match");
                return;
            }


            DialogResult dlgResult = MessageBox.Show("Apply configuration?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (dlgResult != DialogResult.Yes)
            {
                return;
            }

            if (rbSqlserver.Checked)
            {
                optionsUser.providerType = "OLEDB";
            }
            else
            {
                optionsUser.providerType = "SQLITE";
            }

            if (chkUseSecuritySaltDefault.Checked)
            {
                optionsUser.securitySalt = optionsDefault.securitySalt;
            }
            else
            {
                optionsUser.securitySalt = tbSecuritySalt.Text;
            }

            if (chkSqliteUseDefault.Checked)
            {
                sqliteOptionsUser = sqliteOptionsDefault;
            }
            else
            {
                sqliteOptionsUser.dbFilePath = tbSqliteDbPath.Text;
            }

            if (chkSqlUseDefault.Checked)
            {
                sqlOptionsUser = sqlOptionsDefault;
            }
            else
            {
                TransferFormValuesToSqlOptionsUser();
            }

            if (chkQueueUseDefault.Checked)
            {
                queOptionsUser = queOptionsDefault;
            }
            else
            {
                TransferFormValuesToQueOptionsUser();
            }


            foreach (KeyValuePair <string, ConfigFile> kv in configFileDict)
            {
                ConfigFile cfg = kv.Value;

                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(cfg.path);

                    XmlNode connStrNode = xmlDoc.DocumentElement.SelectSingleNode("/configuration/connectionStrings");
                    if (connStrNode != null)
                    {
                        var child = connStrNode.FirstChild;
                        if (child != null)
                        {
                            var attribut = child.Attributes.GetNamedItem("connectionString");
                            if (attribut != null)
                            {
                                if (rbSqlserver.Checked)
                                {
                                    attribut.Value = sqlOptionsUser.connString;
                                }
                                else
                                {
                                    attribut.Value = sqliteOptionsUser.connString;
                                }
                            }
                        }
                    }

                    XmlNode tobasaSettings = xmlDoc.DocumentElement.SelectSingleNode("/configuration/userSettings/Tobasa.Properties.Settings");
                    foreach (XmlNode node in tobasaSettings.ChildNodes)
                    {
                        var settingName = node.Attributes.GetNamedItem("name");

                        // Security salt
                        if (settingName != null && settingName.Value == "SecuritySalt")
                        {
                            var settingVal = node.FirstChild;
                            settingVal.InnerText = optionsUser.securitySalt;
                        }

                        // Queueserver connection info
                        if (settingName != null && settingName.Value == "QueueServerHost")
                        {
                            var settingVal = node.FirstChild;
                            settingVal.InnerText = queOptionsUser.hostAddr;
                        }
                        if (settingName != null && settingName.Value == "QueueServerPort")
                        {
                            var settingVal = node.FirstChild;
                            settingVal.InnerText = queOptionsUser.tcpPort;
                        }
                        if (settingName != null && settingName.Value == "QueueUserName")
                        {
                            var settingVal = node.FirstChild;
                            settingVal.InnerText = queOptionsUser.username;
                        }
                        if (settingName != null && settingName.Value == "QueuePassword")
                        {
                            var settingVal = node.FirstChild;
                            settingVal.InnerText = queOptionsUser.passwordEnc;
                        }

                        // SQL Server connection password and provider
                        if (settingName != null && settingName.Value == "ConnectionStringPassword")
                        {
                            var settingVal = node.FirstChild;

                            if (rbSqlserver.Checked)
                            {
                                settingVal.InnerText = sqlOptionsUser.passwordEnc;
                            }
                            else
                            {
                                settingVal.InnerText = "";
                            }
                        }
                        if (settingName != null && settingName.Value == "ProviderType")
                        {
                            var settingVal = node.FirstChild;

                            settingVal.InnerText = optionsUser.providerType;
                        }
                    }

                    xmlDoc.Save(cfg.path);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().Name);
                }
            }

            MessageBox.Show("Configurations applied", "Information");
        }