using com.hnshituo.core.webapp.vo; using Common; using Common.vo.pb; using Infragistics.Win.UltraWinGrid; using JC_MeasuringSystem; using MeterModuleLibrary; using MeterPlugInLibrary; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Net; using System.Threading; using System.Windows.Forms; namespace BeltScaleSystem { public partial class frmBeltScale_Res : Form { private BeltScaleDataCollectionControl collection = new BeltScaleDataCollectionControl(); //实时表数据采集 public frmBeltScale_Res() { InitializeComponent(); } private Log lg = Log.GetInstance(); private BaseDbCls bd = new BaseDbCls(); private string userId = "", userName = ""; private string[] strPntNoCollect = null; private List strPntNoList = new List(); private CoreAppUser userinfo = null; private string strIpAddress = ""; private DbHelper db = new DbHelper(); private MeterBaseScalePointService monitorService = new MeterBaseScalePointService(); private void frmMonitor_Load(object sender, EventArgs e) { PbCacheMonitor.frmMsgClosingTime = DateTime.Now; // timer2.Start(); userId = ((ST_MainForm)(this.MdiParent)).UserID; userName = ((ST_MainForm)(this.MdiParent)).UserName; userinfo = ((ST_MainForm)(this.MdiParent)).AppUser; #region 载入计量点的信息 bd.setBaseDbScalePoint(); // bd.getDbBaseScale(1); setGridData(); strIpAddress = GetIP(); foreach (UltraGridRow ugr in ultraGridPW.Rows) { strPntNoList.Add(ugr.Cells["collectionCodeA"].Text.Trim());//添加所有的计量点 strPntNoList.Add(ugr.Cells["collectionCodeB"].Text.Trim());//添加所有的计量点 if (ugr.Cells["monitorUserNo"].Text.Trim() != "" && ugr.Cells["monitorUserNo"].Text.Trim() == userName) { ugr.Cells["UNCK"].Value = true; BeltScaleMeterControl uc = new BeltScaleMeterControl(); //uc.strCollectNo = ugr.Cells["collectionCode"].Text.Trim(); uc.Name = "uc" + ugr.Cells["baseSpotNo"].Text; uc.sUserId = userId; uc.sUserName = userName; uc.sIpAddress = strIpAddress; uc.sPointNo = ugr.Cells["baseSpotNo"].Text; uc.sPointName = ugr.Cells["baseSpotName"].Text; //uc.ucMonitoringEvent += new EventHandler(ucEvent); //uc.evoice += new EventVoice(setsVoice); //****************************************注意下面这个********************** // uc.moxaip = dtPointInfo.Rows[k]["MOXAIP"].ToString().Trim(); //uc.openMsg += new EventOpenMsg(OpenMsg); //uc.rowPointInfo = null; uc.BorderStyle = BorderStyle.FixedSingle; // uc.db = db; flPanel.Controls.Add(uc); } else { ugr.Cells["UNCK"].Value = false; } } // strPntNoCollect = strPntNoList.ToArray();//加载所有的计量点,不管有没有接管 // collection.EventBeltScaleDataCollectionArgs += new EventBeltScaleDataCollection(weightCollect);//数据采集解析 // collection.Start(new string[5] { "CAR40", "CAR41", "CAR42", "CAR43", "CAR44" });//数据采集启动 // collection.Start(strPntNoCollect);//数据采集启动 // ClsControlPack.RefreshAndAutoSize(this.ultraGridPW); #endregion 载入计量点的信息 //thVoice.Start(); } /// /// 计量点信息 /// public void setGridData() { DataTable dt = dtJGPointInfo.Clone(); if (PbCacheMonitor.sportInfoList != null && PbCacheMonitor.sportInfoList.Count > 0 && PbCacheMonitor.ltMeterBaseScalePoint != null && PbCacheMonitor.ltMeterBaseScalePoint.Count > 0) { foreach (MeterBaseScalePoint mwm in PbCacheMonitor.ltMeterBaseScalePoint) { if (mwm.scalePointName.Contains("备用")) { DataRow dr = dt.NewRow(); dr["scalePointNo"] = mwm.scalePointNo; dr["baseSpotNo"] = mwm.baseSpotNo; dr["baseSpotName"] = mwm.baseSpotName; dr["monitorUserNo"] = mwm.monitorUserNo; dr["collectionCodeA"] = mwm.collectionCode; dr["collectionCodeB"] = mwm.collectionCodeB; dt.Rows.Add(dr); } } //for (int i=0; i s.baseSpotNo == um.sPointNo).FirstOrDefault(); if (monitor == null) { MessageBox.Show("获取当前计量点信息异常,请稍后再试"); return; } } /// /// 修改数据到接管表 /// private void UpdateCarijeg(MeterBaseScalePoint monitor) { RESTfulResult rms = monitorService.doUpdateWf(monitor); if (!rms.Succeed) { lg.WriteLog(4, "写入数据失败"); } } /// /// 重量采集 /// /// /// private void weightCollect(object o, List e) { try { if (e != null) { foreach (var item in e) { foreach (MeterBaseScalePoint mwm in PbCacheMonitor.ltMeterBaseScalePoint) { if (mwm.collectionCode.Equals(item.pointid)) { mwm.weight = item.weight; } if (mwm.collectionCodeB.Equals(item.pointid)) { mwm.weightB = item.weight; } } } } } catch (Exception) { throw; } } /// /// 重点!!! /// 从主界面向用户控件中插入信息 /// /// /// private void timer2_Tick(object sender, EventArgs e) { try { foreach (MeterBaseScalePoint mon in PbCacheMonitor.ltMeterBaseScalePoint) { foreach (Control cn in flPanel.Controls) { if (cn.Name.Contains("uc")) { BeltScaleMeterControl uc = cn as BeltScaleMeterControl; if (uc.sPointNo == mon.baseSpotNo) { // uc.rowPointInfo = mon; } } } } //if (bd.getDb()) //{ //} //else //{ // lg.WriteLog(4, "未找到实时监控数据"); //} //*/ } catch (Exception ex) { lg.WriteLog(4, "数据库连接异常"); } } private void ultraGridPW_CellChange(object sender, CellEventArgs e) { ultraGridPW.UpdateData(); UltraGridRow ugr = ultraGridPW.ActiveRow; if (ugr != null) { if (ugr.Cells["UNCK"].Value.ToString().ToLower() == "false") { BeltScaleMeterControl uc = (BeltScaleMeterControl)flPanel.Controls["uc" + ugr.Cells["baseSpotNo"].Text]; flPanel.Controls.RemoveByKey("uc" + ugr.Cells["baseSpotNo"].Text); uc.Close(); RESTfulResult rm = monitorService.doUpdateWf(new MeterBaseScalePoint { scalePointNo = ugr.Cells["scalePointNo"].Text.Trim(), monitorUserNo = "" }); if (!rm.Succeed) { lg.WriteLog(4, "写入取消接管信息失败"); } } else { bd.setBaseDbScalePoint(); MeterBaseScalePoint mwm = PbCacheMonitor.ltMeterBaseScalePoint.Where(s => s.scalePointNo == ugr.Cells["scalePointNo"].Text.Trim()).FirstOrDefault(); //先查一次是否接管了 if (mwm != null && !string.IsNullOrEmpty(mwm.monitorUserNo)) { ugr.Cells["UNCK"].Value = false; MessageBox.Show("当前计量点已被账号【" + mwm.monitorUserNo + "】接管"); return; } BeltScaleMeterControl uc = new BeltScaleMeterControl();//点击数据行进行接管 //uc.strCollectNo = ugr.Cells["collectionCode"].Text.Trim(); uc.Name = "uc" + ugr.Cells["baseSpotNo"].Text; uc.sUserId = userId; uc.sUserName = userName; uc.sIpAddress = strIpAddress; uc.sPointNo = ugr.Cells["baseSpotNo"].Text; uc.sPointName = ugr.Cells["baseSpotName"].Text; uc.userClass = userinfo.userClass; uc.userGroup = userinfo.userGroup; //uc.ucMonitoringEvent += new EventHandler(ucEvent); //uc.evoice += new EventVoice(setsVoice); //****************************************注意下面这个********************** // uc.moxaip = dtPointInfo.Rows[k]["MOXAIP"].ToString().Trim(); //uc.openMsg += new EventOpenMsg(OpenMsg); uc.BorderStyle = BorderStyle.FixedSingle; // uc.db = db; flPanel.Controls.Add(uc); RESTfulResult rm = monitorService.doUpdateWf(new MeterBaseScalePoint { scalePointNo = ugr.Cells["scalePointNo"].Text.Trim(), monitorUserNo = userName }); if (!rm.Succeed) { lg.WriteLog(4, "写入接管信息失败"); } } } } /// /// 界面关闭方法:还原接管状态 /// /// /// private void frmMonitor_FormClosing(object sender, FormClosingEventArgs e) { try { List uGrid = GridHelper.UltraGridGetChooseRows(ultraGridPW, "UNCK"); if (uGrid.Count == 0) { return; } foreach (UltraGridRow ugr in uGrid) { if (ugr.Cells["UNCK"].Value.ToString().ToUpper() == "TRUE") { UpdateCarijeg(new MeterBaseScalePoint { scalePointNo = ugr.Cells["scalePointNo"].Text.Trim(), monitorUserNo = "", monitorUserIP = "" }); BeltScaleMeterControl u = (BeltScaleMeterControl)flPanel.Controls["uc" + ugr.Cells["baseSpotNo"].Text]; flPanel.Controls.RemoveByKey("uc" + ugr.Cells["baseSpotNo"].Text); u.Close(); ugr.Cells["UNCK"].Value = false; } } } catch (Exception ex) { lg.WriteLog(4, "关闭皮带秤计量异常:" + ex.Message); } finally { } } /// /// 获取IP地址 /// /// public string GetIP() { try { IPHostEntry ipHost = Dns.Resolve(Dns.GetHostName()); IPAddress ipAddr = ipHost.AddressList[0]; return ipAddr.ToString(); } catch (Exception ex) { Random rd = new Random(); MessageBox.Show("GetIP方法异常,请关闭界面并稍后打开,或联系管理员!\r\n异常原因:\r\n!" + ex); lg.WriteLog(13, "GetIP方法异常:" + ex.Message); return rd.Next(99999, 999999) + ""; } } } }