Esempio n. 1
0
        private void OpenConfigFileBtn_Click(object sender, EventArgs e)
        {
            openConfigFileDialog.Title            = "Open a config file.";
            openConfigFileDialog.Filter           = "*.ini  | *.*";
            openConfigFileDialog.FilterIndex      = 1;
            openConfigFileDialog.RestoreDirectory = false;
            openConfigFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            openConfigFileDialog.Multiselect      = false;
            //

            if (openConfigFileDialog.ShowDialog() == DialogResult.OK)
            {
                // Go to XML handling part.

                // Test code here.
                // MessageBox.Show(openConfigFileDialog.FileName);
                ConfigFilePath.Text = openConfigFileDialog.FileName;
            }

            {
                if (File.Exists(ConfigFilePath.Text))
                {
                    // 读取ini
                    Ini ini = new Ini(ConfigFilePath.Text);
                    portsListCB.Text = ini.ReadValue("serial", "port");
                    buadRateCB.Text  = ini.ReadValue("serial", "buadrate");
                    checkbitsCB.Text = ini.ReadValue("serial", "checkbits");
                    databitsCB.Text  = ini.ReadValue("serial", "databits");
                    stopbitsCB.Text  = ini.ReadValue("serial", "stopbits");

                    dbServerAddressTB.Text = ini.ReadValue("database", "sever");
                    dbPortDB.Text          = ini.ReadValue("database", "port");
                    dbUsrNameTB.Text       = ini.ReadValue("database", "username");
                    dbPwdTB.Text           = ini.ReadValue("database", "password");
                    dbNameTB.Text          = ini.ReadValue("database", "databasename");
                }
            }
        }
Esempio n. 2
0
        private void saveConfigBtn_Click(object sender, EventArgs e)
        {
            // 保存配置信息

            {
                Ini ini = new Ini(ConfigFilePath.Text);
                // 写入ini
                ini.Writue("serial", "port", portsListCB.Text);
                ini.Writue("serial", "buadrate", buadRateCB.Text);
                ini.Writue("serial", "checkbits", checkbitsCB.Text);
                ini.Writue("serial", "databits", databitsCB.Text);
                ini.Writue("serial", "stopbits", stopbitsCB.Text);

                ini.Writue("database", "sever", dbServerAddressTB.Text);
                ini.Writue("database", "port", dbPortDB.Text);
                ini.Writue("database", "username", dbUsrNameTB.Text);
                ini.Writue("database", "password", dbPwdTB.Text);
                ini.Writue("database", "databasename", dbNameTB.Text);

                // label1.Text = "new ini file created!";
                MessageBox.Show("Your config had saved!");
            }
        }