private void btnEnter_Click(object sender, EventArgs e) { //OPC设置 OpcProtocol iOpcProtocol = (OpcProtocol)cmbOpcProtocol.SelectedItem; opcConfig.OpcProtocol = Convert.ToInt32(iOpcProtocol); opcConfig.OpcTypeName = txtTypeName.Text.ToString(); opcConfig.ReconnectInterval = Convert.ToInt32(cmbReconnectInterval.SelectedItem); opcConfig.ReconnectEnable = (Boolean)cmbReconnectEnable.SelectedItem; if (iOpcProtocol == OpcProtocol.DA) { var iIp = txtIP.Text; var iServerName = cmbServerName.Text; opcConfig.DaAddress.Ip = iIp.ToString(); opcConfig.DaAddress.ServerName = iServerName.ToString(); } else if (iOpcProtocol == OpcProtocol.UA) { var iUri = txtUri.Text; var iUserName = txtUserName.Text; var iPassword = txtPassword.Text; var iUseSecurity = cmbUseSecurity.SelectedItem; opcConfig.UaAddress.Uri = iUri.ToString(); opcConfig.UaAddress.UserName = iUserName.ToString(); opcConfig.UaAddress.Password = iPassword.ToString(); opcConfig.UaAddress.UseSecurity = (Boolean)iUseSecurity; } else { MessageBox.Show("请选择UA DA后重试!"); return; } //Tag设置 tagConfig.TagsQueueNum = Convert.ToInt32(cmbTagsQueueNum.SelectedItem); //保存设置 try { ConfigurationManagerExtend.SectionSave(opcConfig, "default", "Address"); ConfigurationManagerExtend.SectionSave(tagConfig, "default", "Tag"); this.DialogResult = DialogResult.OK; } catch (Exception ee) { MessageBox.Show(string.Format("保存失败!内容:{0}", ee.Message), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }