CommunicationDetailSetting.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Core.StlMes.Client.LgResMgt.Mcms.entity;
  10. using CoreFS.CA06;
  11. namespace Core.StlMes.Client.LgResMgt.Mcms
  12. {
  13. public partial class CommunicationDetailSetting : FrmBase
  14. {
  15. public CommunicationDetailSetting(iCommunication data)
  16. {
  17. InitializeComponent();
  18. if (data != null)
  19. {
  20. if (data is SerialPortEntity)
  21. {
  22. rbt1.Checked = true;
  23. cmbCom.Text = ((SerialPortEntity) data).PortName;
  24. baudRate.Text = ((SerialPortEntity)data).StrBaudRate;
  25. }
  26. else if (data is SocketClient)
  27. {
  28. rbt2.Checked = true;
  29. txtIp.Text = ((SocketClient)data).Ip;
  30. txtPort.Text = ((SocketClient)data).Port;
  31. }
  32. }
  33. }
  34. private iCommunication _entity;
  35. public iCommunication Entity
  36. {
  37. get { return _entity; }
  38. }
  39. private void utmMain_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  40. {
  41. switch (e.Tool.Key)
  42. {
  43. case "Save": // ButtonTool
  44. // Place code here
  45. if (rbt1.Checked)
  46. {
  47. if (cmbCom.SelectedIndex < 0)
  48. {
  49. MessageBox.Show("清选择串口号!");
  50. return;
  51. }
  52. if (baudRate.SelectedIndex < 0)
  53. {
  54. MessageBox.Show("清选择波特率!");
  55. return;
  56. }
  57. SerialPortEntity tempSerialPortEntity = new SerialPortEntity
  58. {
  59. PortName = cmbCom.Text,
  60. StrBaudRate = baudRate.Text,
  61. StrDataBits = "8",
  62. StrParity = "NONE",
  63. StrStopBits = "ONE"
  64. };
  65. _entity = tempSerialPortEntity;
  66. }
  67. else if (rbt2.Checked)
  68. {
  69. if (string.IsNullOrWhiteSpace(txtIp.Text))
  70. {
  71. MessageBox.Show("请输入远程服务的IP地址!");
  72. return;
  73. }
  74. else if (string.IsNullOrWhiteSpace(txtPort.Text))
  75. {
  76. MessageBox.Show("请输入远程服务的端口!");
  77. return;
  78. }
  79. SocketClient tempSocketClient = new SocketClient
  80. {
  81. Ip = txtIp.Text,
  82. Port = txtPort.Text
  83. };
  84. _entity = tempSocketClient;
  85. }
  86. else
  87. {
  88. MessageBox.Show("清选择通信类型!");
  89. return;
  90. }
  91. this.DialogResult = DialogResult.OK;
  92. break;
  93. case "Close": // ButtonTool
  94. this.DialogResult = DialogResult.Cancel;
  95. break;
  96. }
  97. }
  98. private void rbt1_CheckedChanged(object sender, EventArgs e)
  99. {
  100. panel4.Visible = rbt1.Checked;
  101. panel5.Visible = rbt2.Checked;
  102. }
  103. }
  104. }