| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- 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 frmLocalTruckScaleActuals : FrmBase
- {
- public frmLocalTruckScaleActuals(OpeBase _ob)
- {
- InitializeComponent();
- new CodeFile.FormMove(this, panel1);
- ob = _ob;
- }
- bool start = true;
- private static object sync = new object();
- private static frmLocalTruckScaleActuals instance;
- public static frmLocalTruckScaleActuals GetSingleton(OpeBase _ob)
- {
- lock (sync)
- {
- ;
- if (instance == null || instance.IsDisposed)
- instance = new frmLocalTruckScaleActuals(_ob);
- }
- return instance;
- }
- private CommunicationEntity communicationnow;
- private frmMessage _frmMessage;
- private CmmPoundBaseEntity cmmPoundBase;
- private CmmActualWeightEntity cmmactual = new CmmActualWeightEntity();
- private CmmActualWeightEntity cmmactualbefore = new CmmActualWeightEntity();
- private List<CmmPoundBaseEntity> poundInfos;
- private List<CmmBaseSpotInfoEntity> 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);
- }
- /// <summary>
- /// 启动采集
- /// </summary>
- /// <param name="communication"></param>
- 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<CmmBaseProtocolCEntity> protocols = EntityHelper.GetData<CmmBaseProtocolCEntity>(
- "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)
- {
- txtMessage.Text = "";
- labRealWgt.Text = "";
- txtTaer_wt.Text = "";
- txtNet_wet.Text = "";
- txtCross_wt.Text = "";
- poundInfos = EntityHelper.GetData<CmmPoundBaseEntity>(
- "com.steering.Mcms.PoundBaseServer.getPoudInfo",
- new object[] { ValidDataPurviewIds },
- ob);
- CmmBaseSpotInfo = EntityHelper.GetData<CmmBaseSpotInfoEntity>(
- "com.steering.Mcms.CmmBaseSpotInfoServer.doQuery",
- new object[] { },
- ob);
- this.WindowState = FormWindowState.Normal;
- }
- 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)
- {
- try
- {
- double wt;
- if (double.TryParse(txtWeight.Text.Replace("t", ""), out wt))
- {
- if ((wt == 0 || wt < 0)&&txtMessage.Text != " ")
- {
- start = false;
- txtMessage.SafeRefreshControl(() => txtMessage.Text = " ");
- }
- else
- {
- start = true;
- }
- if (communicationnow == null)
- return;
- if (wt < 0.5 && boolbefor == false)
- {
- textCar_no.SafeRefreshControl(() => textCar_no.Text = "");
- labRealWgt.SafeRefreshControl(() => labRealWgt.Text = "");
- txtTaer_wt.SafeRefreshControl(() => txtTaer_wt.Text = "");
- txtCross_wt.SafeRefreshControl(() => txtCross_wt.Text = "");
- txtNet_wet.SafeRefreshControl(() => txtNet_wet.Text = "");
- boolbefor = true;
- var CmmA = EntityHelper.GetData<CmmActualWeightEntity>(
- "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<CmmActualWeightEntity>(
- "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<string, object>();
- dic.Add("recordNo", cmmactual.RecordNo);
- // dic.Add("validflag", new List<string> { "2" });
- CmmWeightRecordEntity cmmrecord = EntityHelper.GetData<CmmWeightRecordEntity>(
- "com.steering.Mcms.RecordServer.doQueryRecord",
- new object[] { dic },
- ob).First();
- textCar_no.SafeRefreshControl(() => textCar_no.Text = cmmrecord.CarNo);
- labRealWgt.SafeRefreshControl(() => labRealWgt.Text = cmmrecord.RecordWeight.ToString() + "t");
- if (cmmrecord.Validflag == "2")
- {
- var dic1 = new Dictionary<string, object>();
- string strtime = DateTime.Now.ToString("yyyy-MM-dd 00: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);
- // dic.Add("shippersName", cmmrecord.ShippersName);
- // dic.Add("receiveName", cmmrecord.ReceiveName);
- dic1.Add("validflag", new List<string> { "1" });
- List<CmmWeightResultEntity> list = EntityHelper.GetData<CmmWeightResultEntity>(
- "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 btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- this.WindowState = FormWindowState.Maximized;
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- labDate.Text = DateTime.Now.ToString();
- }
- }
- }
|