SettingForm.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using S7.Net;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace xicheji
  12. {
  13. public partial class SettingForm : Form
  14. {
  15. public SettingForm()
  16. {
  17. InitializeComponent();
  18. }
  19. private void SettingForm_Load(object sender, EventArgs e)
  20. {
  21. try
  22. {
  23. var names = Enum.GetNames<CpuType>();
  24. cboPLCType.Items.Clear();
  25. cboPLCType.Items.AddRange(names);
  26. var config = ConfigHelper.GetConfig();
  27. txtServer.Text = config.Server;
  28. txtPLCIP.Text = config.PLCIP;
  29. txtPLCPort.Text = config.PLCPort;
  30. cboPLCType.SelectedItem = Enum.GetName<CpuType>(config.PLCType);
  31. nudInterval.Value = config.PLCReceiveInterval;
  32. txtCameraIP.Text = config.CameraIP;
  33. txtCameraPort.Text = config.CameraPort;
  34. txtUserName.Text = config.CameraUserName;
  35. txtPassword.Text = config.CameraPassword;
  36. }
  37. catch (Exception ex)
  38. {
  39. MessageBox.Show(ex.Message + ex.StackTrace);
  40. }
  41. }
  42. private void btnOK_Click(object sender, EventArgs e)
  43. {
  44. try
  45. {
  46. var config = ConfigHelper.GetConfig();
  47. config.Server = txtServer.Text;
  48. config.PLCIP = txtPLCIP.Text;
  49. config.PLCPort = txtPLCPort.Text;
  50. config.PLCType = Enum.Parse<CpuType>(cboPLCType.Text);
  51. config.PLCReceiveInterval = int.Parse(nudInterval.Value.ToString());
  52. config.CameraIP = txtCameraIP.Text;
  53. config.CameraPort = txtCameraPort.Text;
  54. config.CameraUserName = txtUserName.Text;
  55. config.CameraPassword = txtPassword.Text;
  56. ConfigHelper.SaveConfig(config);
  57. this.DialogResult = DialogResult.OK;
  58. }
  59. catch (Exception ex)
  60. {
  61. MessageBox.Show(ex.Message + ex.StackTrace);
  62. }
  63. }
  64. private void btnCancel_Click(object sender, EventArgs e)
  65. {
  66. this.DialogResult = DialogResult.Cancel;
  67. }
  68. }
  69. }