using Infragistics.Win.UltraWinListView; using Infragistics.Win.UltraWinTabControl; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Timers; using System.Windows.Forms; using System.Xml.Linq; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.LgResMgt.Mcms.entity; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.Misc; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using Infragistics.Win.UltraWinListView; using Infragistics.Win.UltraWinTabControl; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; using BorderStyle = NPOI.SS.UserModel.BorderStyle; using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment; using Timer = System.Timers.Timer; using System.Net.Sockets; using System.Threading; using System.Text; using System.Collections; using Core.Mes.Client.Comm.Format; namespace Core.StlMes.Client.LgResMgt.Mcms { public partial class frmLocalTruckScaleActual : FrmBase { public frmLocalTruckScaleActual() { InitializeComponent(); } private CommunicationEntity communicationnow; private frmMessage _frmMessage; private CmmPoundBaseEntity cmmPoundBase; private CmmActualWeightEntity cmmactual=new CmmActualWeightEntity(); private CmmActualWeightEntity cmmactualbefore =new CmmActualWeightEntity(); private List poundInfos; private List CmmBaseSpotInfo; private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { if (cboPoundList.Text.Trim() == "") return; if ((cboPoundList.Text.Trim() != null)&&(communicationnow!=null)) { communicationnow.Communication.Show = false; communicationnow.Communication.Stop(); communicationnow.Communication.ReceiveData -= defultClenttEntity_ReceiveData; } communicationnow = null; communicationnow = new CommunicationEntity(); var combase= CmmBaseSpotInfo.First(p => p.BaseSpotNo == cboPoundList.Text); communicationnow.Communication = new SocketClient { Ip = combase.WeightIp, Port = combase.WeightPort, Show = true }; communicationnow.PoundNo = cboPoundList.Text; communicationnow.Communication.Show = true; WeightLoad(communicationnow.Communication, communicationnow.PoundNo); } /// /// 启动采集 /// /// private void WeightLoad(iCommunication communication, string PNO) { communication.ReceiveData += defultClenttEntity_ReceiveData; CmmBaseProtocolEntity cmmBaseProtocol = null; cmmPoundBase = poundInfos.First(p => p.PoundNo == PNO); if (cmmPoundBase != null) { List protocols = EntityHelper.GetData( "com.steering.Mcms.ProcotolServer.getProcotolId", new object[] { cmmPoundBase.PoundProtocolId }, ob); if ((protocols != null) && protocols.Any()) cmmBaseProtocol = new CmmBaseProtocolEntity { ProtocolId = cmmPoundBase.PoundProtocolId, ListC = protocols }; // cboPoundList.Text = cmmPoundBase.PoundNo; } communication.ChangeProtocol(new TruckScaleProtocol(cmmBaseProtocol)); utbConnect_Click(null, null); } private void defultClenttEntity_ReceiveData(object sender, object data, string message, DataType datatype, byte[] bdata) { SocketClient client = sender as SocketClient; if (client.Show == true) { ShowMessage(data, message, datatype, sender); } } private void ShowMessage(object data, string message, DataType dataType, object sender) { SocketClient client = sender as SocketClient; if (dataType == DataType.ReceiveData) { double wt; if (double.TryParse(data.ToString2(), out wt)) txtWeight.SafeRefreshControl(() => { txtWeight.Text = (wt / 100d).ToString("0.00") + "t"; }); } else if (dataType == DataType.Open) { utbConnect.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Red); txtMessage.SafeRefreshControl( () => txtMessage.Text = client.Status ? "已打开" : "已关闭"); // cboNo.SafeRefreshControl(() => cboNo.Enabled = false); } else if (dataType == DataType.Close) { utbConnect.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Lime); txtMessage.SafeRefreshControl( () => txtMessage.Text = client.Status ? "已打开" : "已关闭"); } else if (dataType == DataType.Error) { MessageBox.Show(message); } else if (dataType == DataType.ClientReconnect) { txtMessage.SafeRefreshControl(() => txtMessage.Text = "网络异常,正在重连服务!"); } txtMessage.SafeRefreshControl(() => txtMessage.Text = client.ToString()); if ((_frmMessage != null) && !_frmMessage.IsDisposed) _frmMessage.SafeShowMsg(message, dataType); else _frmMessage = null; } private void frmLocalTruckScaleActual_Load(object sender, EventArgs e) { poundInfos = EntityHelper.GetData( "com.steering.Mcms.PoundBaseServer.getPoudInfo", new object[] { ValidDataPurviewIds }, ob); CmmBaseSpotInfo = EntityHelper.GetData( "com.steering.Mcms.CmmBaseSpotInfoServer.doQuery", new object[] { }, ob); } private void utbConnect_Click(object sender, EventArgs e) { if (communicationnow.Communication == null) return; if ((communicationnow.Communication != null) && communicationnow.Communication.Status) { communicationnow.Communication.Stop(); } else { communicationnow.Communication.Start(); } } private bool boolbefor = false; private void timer1_Tick(object sender, EventArgs e) { double wt; try { if (double.TryParse(txtWeight.Text.Replace("t", ""), out wt)) { if (communicationnow == null) return; if (wt < 0.5 && boolbefor == false) { boolbefor = true; var CmmA = EntityHelper.GetData( "com.steering.Mcms.CmmActualWeightServer.doQuery", new object[] { }, ob); cmmactualbefore = CmmA.First(p => p.BaseSpotNo == communicationnow.PoundNo); } if ((cmmactualbefore != null) && (cmmactualbefore.BaseSpotNo != cboPoundList.Text.Trim())) { boolbefor = false; } if (wt >= 0.5) { txtMessage.SafeRefreshControl(() => txtMessage.Text = "开始计量"); var CmmA = EntityHelper.GetData( "com.steering.Mcms.CmmActualWeightServer.doQuery", new object[] { }, ob); cmmactual = CmmA.First(p => p.BaseSpotNo == cboPoundList.Text); } if ((cmmactualbefore == null && cmmactual != null) || ((cmmactualbefore.RecordNo != cmmactual.RecordNo) && (!(string.IsNullOrEmpty(cmmactual.RecordNo))))) { boolbefor = false; var dic = new Dictionary(); dic.Add("recordNo", cmmactual.RecordNo); // dic.Add("validflag", new List { "2" }); CmmWeightRecordEntity cmmrecord = EntityHelper.GetData( "com.steering.Mcms.RecordServer.doQueryRecord", new object[] { dic }, ob).First(); textCar_no.SafeRefreshControl(() => textCar_no.Text = cmmrecord.CarNo); // txtMessage.SafeRefreshControl(() => txtMessage.Text = client.ToString()); txtShipper.SafeRefreshControl(() => txtShipper.Text = cmmrecord.ShippersName); txtRecive.SafeRefreshControl(() => txtRecive.Text = cmmrecord.ReceiveName); txtMat_name.SafeRefreshControl(() => txtMat_name.Text = cmmrecord.MatName); txtMat_type.SafeRefreshControl(() => txtMat_type.Text = cmmrecord.MatType); if (cmmrecord.Validflag == "2") { var dic1 = new Dictionary(); string strtime = DateTime.Now.ToString("yyyy-MM-dd 07:00:00"); string strtime1 = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"); dic1.Add("time", strtime); dic1.Add("time1", strtime1); dic1.Add("carNo", cmmrecord.CarNo); dic1.Add("shippersName", cmmrecord.ShippersName); dic1.Add("receiveName", cmmrecord.ReceiveName); dic1.Add("validflag", new List { "1" }); List list = EntityHelper.GetData( "com.steering.Mcms.ResultServer.doQuery", new object[] { dic1 }, ob); var p = list.First(); if (p != null) { txtTaer_wt.SafeRefreshControl(() => txtTaer_wt.Text = p.TareWt + "t"); txtCross_wt.SafeRefreshControl(() => txtCross_wt.Text = p.GrossWt + "t"); txtNet_wet.SafeRefreshControl(() => txtNet_wet.Text = p.NetWt + "t"); } } } } } catch { } } private void btnMaxShow_Click(object sender, EventArgs e) { Form form = frmLocalTruckScaleActuals.GetSingleton(ob); // 有参数 form.Show(); form.Activate(); } } }