private void tbtnOpcConfig_Click(object sender, EventArgs e) { var opcConfig = new OpcConfig(); opcConfig.ShowDialog(); Init(); }
/// <summary> /// 初始化 /// </summary> private void Init() { var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigInfo.OpcJson); //判断Opc-配置文件是否存在 if (File.Exists(filePath)) { this.rtxtRecord.Text = ""; this.rtxtRecordDb.Text = ""; // deserialize JSON directly from a file using (StreamReader file = File.OpenText(filePath)) { JsonSerializer serializer = new JsonSerializer(); mOpcJson = (OpcJson)serializer.Deserialize(file, typeof(OpcJson)); } txtHostIP.Text = mOpcJson.HostIP; txtHostName.Text = mOpcJson.HostName; txtServerName.Text = mOpcJson.ServerName; listboxAlias.Items.Clear(); foreach (var item in mOpcJson.AliasList) { listboxAlias.Items.Add(item); } if (ConnectServer()) { btnReadDb.Enabled = true; btnWriteDb.Enabled = true; btnWrite.Enabled = true; } } else { MessageBox.Show("Opc-配置不存在,请先配置!", "提示信息"); var opcConfig = new OpcConfig(); opcConfig.ShowDialog(); Init(); } }