frmBeltInstrument1.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using com.hnshituo.core.webapp.vo;
  2. using Common;
  3. using Common.vo.pb;
  4. using Infragistics.Win.UltraWinGrid;
  5. using JC_MeasuringSystem;
  6. using MeterModuleLibrary;
  7. using MeterPlugInLibrary;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Linq;
  12. using System.Net;
  13. using System.Threading;
  14. using System.Windows.Forms;
  15. namespace BeltScaleSystem
  16. {
  17. public partial class frmBeltInstrument1 : Form
  18. {
  19. public frmBeltInstrument1()
  20. {
  21. InitializeComponent();
  22. }
  23. private Log lg = Log.GetInstance();
  24. private BaseDbCls bd = new BaseDbCls();
  25. private string strIpAddress = "";
  26. private MeterBaseScalePointService monitorService = new MeterBaseScalePointService();
  27. private void frmMonitor_Load(object sender, EventArgs e)
  28. {
  29. PbCacheMonitor.frmMsgClosingTime = DateTime.Now;
  30. #region 载入计量点的信息
  31. bd.setBaseDbScalePoint();
  32. setGridData();
  33. strIpAddress = GetIP();
  34. #endregion 载入计量点的信息
  35. //thVoice.Start();
  36. }
  37. /// <summary>
  38. /// 计量点信息
  39. /// </summary>
  40. public void setGridData()
  41. {
  42. DataTable dt = dtJGPointInfo.Clone();
  43. if (PbCacheMonitor.sportInfoList!=null&& PbCacheMonitor.sportInfoList.Count>0&& PbCacheMonitor.ltMeterBaseScalePoint != null && PbCacheMonitor.ltMeterBaseScalePoint.Count > 0)
  44. {
  45. foreach (MeterBaseScalePoint mwm in PbCacheMonitor.ltMeterBaseScalePoint)
  46. {
  47. DataRow dr = dt.NewRow();
  48. dr["scalePointNo"] = mwm.scalePointNo;
  49. dr["baseSpotNo"] = mwm.baseSpotNo;
  50. dr["baseSpotName"] = mwm.baseSpotName;
  51. dr["monitorUserNo"] = mwm.monitorUserNo;
  52. dr["collectionCodeA"] = mwm.collectionCode;
  53. dr["collectionCodeB"] = mwm.collectionCodeB;
  54. dt.Rows.Add(dr);
  55. }
  56. }
  57. ClsControlPack.CopyDataToDatatable(ref dt, ref this.dtJGPointInfo, true);
  58. }
  59. private void ultraGridPW_CellChange(object sender, CellEventArgs e)
  60. {
  61. ultraGridPW.UpdateData();
  62. UltraGridRow ugr = ultraGridPW.ActiveRow;
  63. if (ugr != null)
  64. {
  65. if (ugr.Cells["UNCK"].Value.ToString().ToLower() == "false")
  66. {
  67. ucBeltInstrumentInfo_Real u = (ucBeltInstrumentInfo_Real)flPanel.Controls["uc" + ugr.Cells["baseSpotNo"].Text];
  68. flPanel.Controls.RemoveByKey("uc" + ugr.Cells["baseSpotNo"].Text);
  69. u.Close();
  70. }
  71. else {
  72. ucBeltInstrumentInfo_Real uc = new ucBeltInstrumentInfo_Real();
  73. uc.Name = "uc" + ugr.Cells["baseSpotNo"].Text;
  74. uc.collectionCodeA = ugr.Cells["collectionCodeA"].Text.Trim();
  75. uc.collectionCodeB = ugr.Cells["collectionCodeB"].Text.Trim();
  76. uc.sIpAddress = strIpAddress;
  77. uc.sPointNo = ugr.Cells["baseSpotNo"].Text;
  78. uc.sPointName = ugr.Cells["baseSpotName"].Text;
  79. uc.BorderStyle = BorderStyle.FixedSingle;
  80. flPanel.Controls.Add(uc);
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// 界面关闭
  86. /// </summary>
  87. /// <param name="sender"></param>
  88. /// <param name="e"></param>
  89. private void frmMonitor_FormClosing(object sender, FormClosingEventArgs e)
  90. {
  91. try
  92. {
  93. List<UltraGridRow> uGrid = GridHelper.UltraGridGetChooseRows(ultraGridPW, "UNCK");
  94. if (uGrid.Count == 0)
  95. {
  96. return;
  97. }
  98. foreach (UltraGridRow ugr in uGrid)
  99. {
  100. if (ugr.Cells["UNCK"].Value.ToString().ToUpper() == "TRUE")
  101. {
  102. ucBeltInstrumentInfo_Real u = (ucBeltInstrumentInfo_Real)flPanel.Controls["uc" + ugr.Cells["baseSpotNo"].Text];
  103. flPanel.Controls.RemoveByKey("uc" + ugr.Cells["baseSpotNo"].Text);
  104. u.Close();
  105. ugr.Cells["UNCK"].Value = false;
  106. }
  107. }
  108. }
  109. catch (Exception ex)
  110. {
  111. lg.WriteLog(4, "关闭皮带秤计量异常:" + ex.Message);
  112. }
  113. finally
  114. {
  115. }
  116. }
  117. /// <summary>
  118. /// 获取IP地址
  119. /// </summary>
  120. /// <returns></returns>
  121. public string GetIP()
  122. {
  123. try
  124. {
  125. IPHostEntry ipHost = Dns.Resolve(Dns.GetHostName());
  126. IPAddress ipAddr = ipHost.AddressList[0];
  127. return ipAddr.ToString();
  128. }
  129. catch (Exception ex)
  130. {
  131. Random rd = new Random();
  132. MessageBox.Show("GetIP方法异常,请关闭界面并稍后打开,或联系管理员!\r\n异常原因:\r\n!" + ex);
  133. lg.WriteLog(13, "GetIP方法异常:" + ex.Message);
  134. return rd.Next(99999, 999999) + "";
  135. }
  136. }
  137. }
  138. }