frmHotDeliveryWeightWarn.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. using com.hnshituo.core.webapp.vo;
  2. using Common;
  3. using Common.vo.pb;
  4. using Infragistics.Win.UltraWinEditors;
  5. using JC_MeasuringSystem;
  6. using MeterPlugInLibrary;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Drawing;
  10. using System.Media;
  11. using System.Windows.Forms;
  12. namespace StorageMeterSystem
  13. {
  14. public partial class frmHotDeliveryWeightWarn : Form
  15. {
  16. private HotDeliveryDataCollectionControl collection = new HotDeliveryDataCollectionControl(); //实时表数据采集
  17. private ComBaseInfoService comBaseInfoService = new ComBaseInfoService(); //基础数服务
  18. private MeterBaseScalePointService scalePointService = new MeterBaseScalePointService(); //计量点信息服务
  19. private Log l = Log.GetInstance(); //日志
  20. private string userId = "", userName = ""; //用户ID用户名
  21. private string strBaseCode = "";//基础数据主键
  22. private CoreAppUser appUser = null;//登陆信息
  23. private string[] strPntNoCollect = null; //所有的计量点
  24. private List<string> strPntNoList = new List<string>(); //
  25. private frmHotDeliveryBeltWarn fm = null;//预警界面
  26. public bool bMsgOpen = false; //是否打开了预警界面提醒
  27. public bool bWarnFlage = false; //是否继续打开预警界面
  28. private int iWarnWeight = 0; //预警重量,大于这个值预警
  29. private string rk_CurPath = Application.StartupPath; //System.Environment.CurrentDirectory;//获取到当前路径
  30. private SoundPlayer play_ls = null;//报警声音播放
  31. public frmHotDeliveryWeightWarn()
  32. {
  33. InitializeComponent();
  34. }
  35. private void frmHotDeliveryWeightWarn_Load(object sender, EventArgs e)
  36. {
  37. userId = ((ST_MainForm)(this.MdiParent)).UserID;
  38. userName = ((ST_MainForm)(this.MdiParent)).UserName;
  39. appUser = ((ST_MainForm)(this.MdiParent)).AppUser;
  40. #region 载入基础信息
  41. //计量点信息载入cmbPoint;cmbPointUp
  42. RESTfulResult<List<MeterBaseScalePoint>> rr = scalePointService.doQueryWf(new MeterBaseScalePoint { validFlag = "1", spotTypeNo = "001002004" });
  43. if (rr.Succeed && rr.Data != null && rr.Data.Count > 0)
  44. {
  45. ClsControlPack.SetUltraComboDataSource(cmbPoint, rr.Data.ListToDataTable<MeterBaseScalePoint>(), "collectionCode", "baseSpotName");
  46. }
  47. else
  48. {
  49. MessageBox.Show("计量点载入失败!");
  50. return;
  51. }
  52. #endregion 载入基础信息
  53. }
  54. #region 点击事件
  55. /// <summary>
  56. /// 选择计量点的事件
  57. /// </summary>
  58. /// <param name="sender"></param>
  59. /// <param name="e"></param>
  60. private void cmbPoint_ValueChanged(object sender, EventArgs e)
  61. {
  62. //查询预警值
  63. RESTfulResult<List<ComBaseInfo>> rrComMeterGroop = comBaseInfoService.doQueryBaseList(new ComBaseInfo { validFlag = "1", baseName = cmbPoint.Text });
  64. if (rrComMeterGroop.Succeed && rrComMeterGroop.Data != null && rrComMeterGroop.Data.Count > 0)
  65. {
  66. strBaseCode = rrComMeterGroop.Data[0].baseCode;
  67. if (!string.IsNullOrEmpty(rrComMeterGroop.Data[0].memo))
  68. {
  69. numLimit.Value = Convert.ToInt32(rrComMeterGroop.Data[0].memo);
  70. iWarnWeight = Convert.ToInt32(rrComMeterGroop.Data[0].memo);
  71. }
  72. }
  73. else
  74. {
  75. MessageBox.Show("热送磅重量预警值信息载入失败!" + rrComMeterGroop.Message);
  76. return;
  77. }
  78. }
  79. /// <summary>
  80. /// 开始监控
  81. /// </summary>
  82. /// <param name="sender"></param>
  83. /// <param name="e"></param>
  84. private void btStart_Click(object sender, EventArgs e)
  85. {
  86. if (string.IsNullOrEmpty(cmbPoint.Value + "") || string.IsNullOrEmpty(cmbPoint.Text) || string.IsNullOrEmpty(strBaseCode))
  87. {
  88. MessageBox.Show("请先选择一个计量点!");
  89. return;
  90. }
  91. if (btStart.Text.Equals("正在监控"))
  92. {
  93. MessageBox.Show("已经监控了一个计量点,若需要更换计量点,请重新打开界面后再进行监控!");
  94. return;
  95. }
  96. btStart.Text = "正在监控";
  97. strPntNoList.Add((cmbPoint.Value + "").ToUpper());
  98. strPntNoCollect = strPntNoList.ToArray();//加载所有的计量点,不管有没有接管
  99. collection.EventHotDeliveryDataCollectionArgs += new EventHotDeliveryDataCollection(weightCollect);//数据采集解析
  100. collection.Start(strPntNoCollect);//数据采集启动
  101. }
  102. /// <summary>
  103. /// 设置报警值
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void btSetLimit_Click(object sender, EventArgs e)
  108. {
  109. if (string.IsNullOrEmpty(strBaseCode))
  110. {
  111. MessageBox.Show("请先选择计量点的,再更新预警值!");
  112. return;
  113. }
  114. ComBaseInfo baseInfo = new ComBaseInfo();
  115. baseInfo.baseCode = strBaseCode;
  116. baseInfo.updateManNo = userId;
  117. baseInfo.updateManName = userName;
  118. if (!string.IsNullOrEmpty(numLimit.Text))
  119. {
  120. baseInfo.memo = numLimit.Text;
  121. iWarnWeight = Convert.ToInt32(numLimit.Value);
  122. }
  123. RESTfulResult<String> rms = comBaseInfoService.doUpdateWf(baseInfo);
  124. if (rms.Succeed)
  125. {
  126. MessageBox.Show("预警值更新成功!");
  127. }
  128. else
  129. {
  130. MessageBox.Show("操作失败:" + rms.Data);
  131. l.WriteLog(19, "操作失败:" + rms.Data + rms.Message);
  132. }
  133. }
  134. #endregion 点击事件
  135. #region 设置界面重量的值
  136. /// <summary>
  137. /// 时间控件监控
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void timer1_Tick(object sender, EventArgs e)
  142. {
  143. if (iWarnWeight > 0 && iWarnWeight < Convert.ToInt32(txtWeight.Text.Replace("kg", "").Trim()))
  144. {
  145. //报警一次
  146. if (!bWarnFlage)
  147. {
  148. lbState.Text = "重量报警";
  149. lbState.BackColor = Color.Red;
  150. setLable("重量报警");
  151. setLable("red");
  152. play_ls = new SoundPlayer(rk_CurPath + "\\Sound\\cc.wav");
  153. play_ls.PlayLooping();
  154. //OpenMsg("当前重量【 " + txtWeight.Text.Replace("kg", "").Trim() + " kg】超出预警值【 " + numLimit.Value + " kg】!");
  155. bWarnFlage = true;
  156. }
  157. }
  158. }
  159. /// <summary>
  160. /// 重量采集
  161. /// </summary>
  162. /// <param name="o"></param>
  163. /// <param name="e"></param>
  164. private void weightCollect(object o, List<CollectModel> e)
  165. {
  166. try
  167. {
  168. //采集的重量赋值
  169. if (e != null)
  170. {
  171. foreach (var item in e)
  172. {
  173. if (cmbPoint.Value.Equals(item.pointid))
  174. {
  175. setWeightCollect(item.weight + "");
  176. if (item.weight == 0 || item.weight < iWarnWeight)
  177. {
  178. //回零后,下一次继续报警!
  179. bWarnFlage = false;
  180. if (play_ls!=null)
  181. {
  182. play_ls.Stop();
  183. }
  184. setLable("重量正常");
  185. setLable("transparent");
  186. }
  187. }
  188. }
  189. }
  190. }
  191. catch (Exception)
  192. {
  193. //throw;
  194. }
  195. }
  196. /// <summary>
  197. /// 调用预警界面
  198. /// </summary>
  199. /// <param name="strWarnInfo"></param>
  200. private void OpenMsg(string strWarnInfo)
  201. {
  202. try
  203. {
  204. if (!bMsgOpen)
  205. {
  206. if (PbCacheMonitor.frmMsgClosingTime == null)
  207. {
  208. bMsgOpen = true;
  209. fm = frmHotDeliveryBeltWarn.CreateInstrance(this);
  210. fm.TopMost = true;
  211. fm.setLbTxt(strWarnInfo);
  212. fm.Show();
  213. }
  214. else
  215. {
  216. TimeSpan secondSpan = new TimeSpan(DateTime.Now.Ticks - PbCacheMonitor.frmMsgClosingTime.Value.Ticks);
  217. if (secondSpan.TotalSeconds > 5)
  218. {
  219. bMsgOpen = true;
  220. fm = frmHotDeliveryBeltWarn.CreateInstrance(this);
  221. fm.TopMost = true;
  222. fm.setLbTxt(strWarnInfo);
  223. fm.Show();
  224. }
  225. }
  226. }
  227. /*
  228. if (!string.IsNullOrEmpty(openPointNo) && fm != null)
  229. {
  230. fm.CloseFrm();
  231. }
  232. */
  233. }
  234. catch { }
  235. }
  236. /// <summary>
  237. /// 采集重量赋值
  238. /// </summary>
  239. /// <param name="bGreen"></param>
  240. public void setWeightCollect(string weight)
  241. {
  242. txtWeight.Invoke(new UpdateUIEventHander(UpdateUI_Method), txtWeight, new UpdateUIArgs(weight));
  243. }
  244. /// <summary>
  245. /// label状态赋值
  246. /// </summary>
  247. /// <param name="bGreen"></param>
  248. public void setLable(string value)
  249. {
  250. txtWeight.Invoke(new UpdateUIEventHander(UpdateUI_Method), lbState, new UpdateUIArgs(value));
  251. }
  252. #endregion 设置界面重量的值
  253. #region 线程中赋值的控件需使用委托
  254. private delegate void UpdateUIEventHander(object sender, UpdateUIArgs args); //自定义事件用来从线程中更新控件的值
  255. public class UpdateUIArgs : EventArgs
  256. {
  257. public string textValue { get; private set; }
  258. public UpdateUIArgs(string textValue)
  259. {
  260. this.textValue = textValue;
  261. }
  262. }
  263. /// <summary>
  264. /// 更新界面的UI
  265. /// </summary>
  266. /// <param name="sender"></param>
  267. /// <param name="args"></param>
  268. private void UpdateUI_Method(object sender, UpdateUIArgs args)
  269. {
  270. if (sender is UltraTextEditor)
  271. {
  272. if (args.textValue == "" || args.textValue == null)
  273. {
  274. ((UltraTextEditor)sender).Text = "0 kg";
  275. }
  276. else
  277. {
  278. ((UltraTextEditor)sender).Text = args.textValue + " kg";
  279. }
  280. }
  281. else if (sender is Button)
  282. {
  283. if (args.textValue == "red")
  284. {
  285. ((Button)sender).BackColor = Color.Red;
  286. ((Button)sender).ForeColor = Color.White;
  287. }
  288. else if (args.textValue == "green")
  289. {
  290. ((Button)sender).BackColor = Color.White;
  291. ((Button)sender).ForeColor = Color.Black;
  292. }
  293. else
  294. {
  295. ((Label)sender).Text = args.textValue;
  296. }
  297. }
  298. else if (sender is Label)
  299. {
  300. if (args.textValue == "red")
  301. {
  302. ((Label)sender).BackColor = Color.Red;
  303. }
  304. else if (args.textValue == "transparent")
  305. {
  306. ((Label)sender).BackColor = Color.Transparent;
  307. }
  308. else
  309. {
  310. ((Label)sender).Text = args.textValue;
  311. }
  312. }
  313. else if (sender is PictureBox)
  314. {
  315. if (args.textValue == "red")
  316. {
  317. ((PictureBox)sender).Load(PbCache.path + "\\image\\icon\\red.gif");
  318. }
  319. else
  320. {
  321. ((PictureBox)sender).Load(PbCache.path + "\\image\\icon\\green.gif");
  322. }
  323. }
  324. }
  325. #endregion 线程中赋值的控件需使用委托
  326. /// <summary>
  327. /// 关闭界面
  328. /// </summary>
  329. /// <param name="sender"></param>
  330. /// <param name="e"></param>
  331. private void frmHotDeliveryWeightWarn_FormClosing(object sender, FormClosingEventArgs e)
  332. {
  333. try
  334. {
  335. collection.Stop();
  336. timer1.Stop();
  337. }
  338. catch (Exception ex)
  339. {
  340. l.WriteLog(19, "关闭热送磅计量异常:" + ex.Message);
  341. }
  342. finally
  343. {
  344. }
  345. }
  346. }
  347. }