SettingForm.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.ServicePort = txtServicePort.Text;
  48. config.Server = txtServer.Text;
  49. //config.UploadInterval = int.Parse(nudUploadInterval.Value.ToString());
  50. config.PLCIP = txtPLCIP.Text;
  51. config.PLCPort = txtPLCPort.Text;
  52. config.PLCType = Enum.Parse<CpuType>(cboPLCType.Text);
  53. config.PLCReceiveInterval = int.Parse(nudInterval.Value.ToString());
  54. config.CameraIP = txtCameraIP.Text;
  55. config.CameraPort = txtCameraPort.Text;
  56. config.CameraUserName = txtUserName.Text;
  57. config.CameraPassword = txtPassword.Text;
  58. ConfigHelper.SaveConfig(config);
  59. this.DialogResult = DialogResult.OK;
  60. }
  61. catch (Exception ex)
  62. {
  63. MessageBox.Show(ex.Message + ex.StackTrace);
  64. }
  65. }
  66. private void btnCancel_Click(object sender, EventArgs e)
  67. {
  68. this.DialogResult = DialogResult.Cancel;
  69. }
  70. }
  71. }