using CommonLib.Config; using CommonLib.DAQ; using CommonLib.LOG; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DataCollectionSystem { public partial class DeviceSettingForm : DevComponents.DotNetBar.Metro.MetroForm { public DeviceSettingForm() { InitializeComponent(); } ConfigValue config = null; private void BtnOK_Click(object sender, EventArgs e) { try { GetValue(); config.SaveConfig(); MessageBox.Show("保存设置成功"); DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show("保存信息失败,错误提示:"+ex.Message,"错误",MessageBoxButtons.OK, MessageBoxIcon.Error); LogStorage.Logs.Add(LogLevel.Error, ex.Message + "\n" + ex.StackTrace); } } void GetValue () { TextBox[] HostName = { textBoxHostName1, textBoxHostName2, textBoxHostName3, textBoxHostName4, textBoxHostName5 }; CheckBox[] checkBoxIP = { checkBoxIP1 , checkBoxIP2 , checkBoxIP3, checkBoxIP4, checkBoxIP5}; for(int i=0; i< HostName.Length; i++) { config.cardInfos[i].HostName = HostName[i].Text; config.cardInfos[i].Enable = checkBoxIP[i].Checked; } } void SetValue() { TextBox[] HostName = { textBoxHostName1, textBoxHostName2, textBoxHostName3, textBoxHostName4 , textBoxHostName5}; CheckBox[] checkBoxIP = { checkBoxIP1, checkBoxIP2, checkBoxIP3, checkBoxIP4 , checkBoxIP5 }; for (int i = 0; i < HostName.Length; i++) { HostName[i].Text = config.cardInfos[i].HostName; checkBoxIP[i].Checked = config.cardInfos[i].Enable; } } private void DeviceSettingForm_Load(object sender, EventArgs e) { try { config = MainForm.configValue; SetValue(); cmbHostNames.Items.AddRange(DAQCard.HostNames); } catch (Exception ex) { LogStorage.Logs.Add(LogLevel.Error, ex.Message + "\n" + ex.StackTrace); } } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void label7_Click(object sender, EventArgs e) { } } }