using S7.Net; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace xicheji { public partial class SettingForm : Form { public SettingForm() { InitializeComponent(); } private void SettingForm_Load(object sender, EventArgs e) { try { var names = Enum.GetNames(); cboPLCType.Items.Clear(); cboPLCType.Items.AddRange(names); var config = ConfigHelper.GetConfig(); txtServer.Text = config.Server; txtPLCIP.Text = config.PLCIP; txtPLCPort.Text = config.PLCPort; cboPLCType.SelectedItem = Enum.GetName(config.PLCType); nudInterval.Value = config.PLCReceiveInterval; txtCameraIP.Text = config.CameraIP; txtCameraPort.Text = config.CameraPort; txtUserName.Text = config.CameraUserName; txtPassword.Text = config.CameraPassword; } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } } private void btnOK_Click(object sender, EventArgs e) { try { var config = ConfigHelper.GetConfig(); //config.ServicePort = txtServicePort.Text; config.Server = txtServer.Text; //config.UploadInterval = int.Parse(nudUploadInterval.Value.ToString()); config.PLCIP = txtPLCIP.Text; config.PLCPort = txtPLCPort.Text; config.PLCType = Enum.Parse(cboPLCType.Text); config.PLCReceiveInterval = int.Parse(nudInterval.Value.ToString()); config.CameraIP = txtCameraIP.Text; config.CameraPort = txtCameraPort.Text; config.CameraUserName = txtUserName.Text; config.CameraPassword = txtPassword.Text; ConfigHelper.SaveConfig(config); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } } }