public MachineConfig() { FilePath = ConfigurationSettings.AppSettings["INIFilePath"]; inihelper = new INIClass(FilePath); InitializeComponent(); }
private void 择opcsvcini文件路径ToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; dialog.Title = "请选择opcsvc.ini文件"; dialog.Filter = "配置文件(.ini)|*.ini"; if (dialog.ShowDialog() == DialogResult.OK) { FilePath = dialog.FileName; //MessageBox.Show(FilePath); inihelper = new INIClass(FilePath); toolStripStatusLabel1.Text = "opcsvc.ini文件路径:" + inihelper.FileName; GetAllAddressFormINI(); } }
private void Menu_Connect_Click(object sender, EventArgs e) { server = new MyServer(this); try { server.Start(); connect = true; toolStripStatusLabel1.Text = "连接状态:" + connect; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; browser = new MyBrowser(server); try { this.root = browser.GetRoot(); //login sessions.Clear(); foreach (string item in root) { try { int id = browser.LogInToOpcUser(item); MessageBox.Show(item.ToString() + " Log in to OPC Ok,连接成功!"); sessions.Add(new User(id, item)); } catch (Exception exc) { MessageBox.Show("Log in to OPC failed", exc.Message); } } //ComboBox byte[] result; INIClass inihelper = new INIClass(ConfigurationSettings.AppSettings["INIFilePath"]); if (inihelper.ExistINIFile()) { result = inihelper.IniReadValues("DefaultHosts", null); string value = Encoding.Default.GetString(result); string[] list = value.Split('\0'); foreach (string _item in list) { if (_item != "") { string _value = inihelper.IniReadValue("DefaultHosts", _item); comboBox1.Items.Add(_item + ":" + _value); //Items.Add(_item + ":" + _value); } } comboBox1.Enabled = true; comboBox1.SelectedIndex = 0; } } catch (Exception exc) { MessageBox.Show("Browser: parsing error.", exc.Message); } } catch (Exception exc) { MessageBox.Show("连接远程服务器出现错误:" + exc.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }