1
wtt
2025-10-30 e9f9e11ae069c709e1aba50dc0744d5a2d0a4331
WarM/ÌõÂë´òÓ¡/Gy_BarCodeBill_automaticallyByPLC_New_Change.cs
@@ -17,6 +17,8 @@
using System.Printing;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
using WebAPI;
using Newtonsoft.Json;
namespace WarM
{
@@ -429,7 +431,11 @@
            }
            this.Sub_SaveBill();
            LogService.Write("==============================================================================================");
            LogService.Write("获取打印列表【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】");
            Display();
            LogService.Write("获取打印列表结束【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】");
            LogService.Write("==============================================================================================");
            if (radioButton_IsPrint_Yes.Checked == true)
            {
@@ -851,6 +857,7 @@
                        HWhID = ClsPub.isLong(grdSub.Rows[i].Cells[HWhID2Col].Value);
                        HSPID = ClsPub.isLong(grdSub.Rows[i].Cells[HSPID2Col].Value);
                        HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value);
                        HRemark = "PLC自动生成";
                        HMaterName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterName2Col].Value);
                        HMaterModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterModel2Col].Value);
                        HPinfan = ClsPub.isStrNull(grdSub.Rows[i].Cells[HPinfan2Col].Value);
@@ -957,14 +964,14 @@
                string LIU = "";
                int LEN = 4;
                DataSet ds;
                string sql = "select * from h_v_IF_BarCodeBillList Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),条码日期, 23) = '" + HDate + "' order by æ‰¹å· desc";
                string sql = "select * from h_v_IF_BarCodeBillList Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),条码日期, 23) = '" + HDate + "' and å¤‡æ³¨ = 'PLC自动生成' order by æ‰¹å· desc";
                ds = oCn.RunProcReturn(sql, "h_v_IF_BarCodeBillList");
                if (ds != null)
                {
                    long count = 0;
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        count = ClsPub.isLong(ds.Tables[0].Rows[0]["批号"].ToString().Replace(sYear + sPeriod + sDay, ""));
                        count = ClsPub.isLong(ds.Tables[0].Rows[0]["批号"].ToString().Replace(sYear + sPeriod + sDay + " ", ""));
                    }
                    LIU += count + 1;
                    while (LIU.Length < LEN)  //如果流水号小于6位数前面补0
@@ -978,7 +985,7 @@
                }
                //拼接批号
                HBatchNo = sYear + sPeriod + sDay + LIU;
                HBatchNo = sYear + sPeriod + sDay + " " + LIU;
            }
@@ -1165,7 +1172,11 @@
                this.Sub_SaveBill();
                //获取需要打印的数据
                LogService.Write("==============================================================================================");
                LogService.Write("获取打印列表【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】");
                Display();
                LogService.Write("获取打印列表结束【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】");
                LogService.Write("==============================================================================================");
                if (radioButton_IsPrint_Yes.Checked == true)
                {
@@ -1196,6 +1207,8 @@
        //获取需要打印的数据并存放在子表grdList
        private void Display()
        {
            LogService.Write("打印列表搜索语句:【select * from h_v_IF_BarCodeBillList Where HinterID=" + HInterID.ToString() + " order by HItemID】");
            //设置档案列表选项卡表格数据
            DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList Where HinterID=" + HInterID.ToString() + " order by HItemID", "h_v_IF_BarCodeBillList", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
@@ -1212,6 +1225,8 @@
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol);
            //画线
            //GraphLine();
            LogService.Write("打印列表数据:【" + JsonConvert.SerializeObject(DSet.Tables[0]) + "】");
        }
        //获取工单当天物料生成的条码记录
@@ -1356,16 +1371,49 @@
        }
        #endregion
        //#region MQTT接收到信息后的回调方法
        //public void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        //{
        //    try
        //    {
        //        string message = Encoding.UTF8.GetString(e.Message);
        //        List<MQTT_MainEntity_New> mQTT_MainEntity = getObjectByJson_Xs_OutDoorBillMain_New(message);
        //        for (int i = 0; i < mQTT_MainEntity[0].data.Count; i++)
        //        {
        //            if (mQTT_MainEntity[0].data[i].id == textBox_WorkPositionParams.Text && mQTT_MainEntity[0].data[i].value == 1)
        //            {
        //                produceQty += 1;
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //        string msg = "";
        //        if (disConnect(ref msg) == true)
        //        {
        //            MessageBox.Show(msg);
        //        }
        //        else
        //        {
        //            MessageBox.Show(msg);
        //        }
        //    }
        //}
        //#endregion
        #region MQTT接收到信息后的回调方法
        public void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            try
            {
                string message = Encoding.UTF8.GetString(e.Message);
                List<MQTT_MainEntity> mQTT_MainEntity = getObjectByJson_Xs_OutDoorBillMain(message);
                List<MQTT_MainEntity_New> mQTT_MainEntity = getObjectByJson_Xs_OutDoorBillMain_New(message);
                for(int i = 0; i < mQTT_MainEntity[0].data.Count; i++)
                {
                    if (mQTT_MainEntity[0].data[i].id == textBox_WorkPositionParams.Text && mQTT_MainEntity[0].data[i].value == true)
                    if (mQTT_MainEntity[0].data[i].id == textBox_WorkPositionParams.Text && mQTT_MainEntity[0].data[i].value == 1)
                    {
                        produceQty += 1;
                    }
@@ -2323,6 +2371,7 @@
                {
                    sMoney = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) / ClsPub.isDoule(grdMain.Rows[sRow].Cells[HMinQtyCol].Value);
                }
                sMoney = Math.Round(sMoney, 10);    // ä¿ç•™10位小数进行四舍五入
                sMoney = Math.Ceiling(sMoney);
                grdMain.Rows[sRow].Cells[HBQtyCol].Value = sMoney;
            }
@@ -2627,6 +2676,15 @@
            return list;
        }
        #endregion
        #region json转为对象
        public List<MQTT_MainEntity_New> getObjectByJson_Xs_OutDoorBillMain_New(string jsonString)
        {
            jsonString = "[" + jsonString.ToString() + "]";
            List<MQTT_MainEntity_New> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MQTT_MainEntity_New>>(jsonString);
            return list;
        }
        #endregion
        #endregion
    }
@@ -2635,13 +2693,30 @@
    public class MQTT_MainEntity
    {
        public string timestamp;
        public List<MQTT_SubEntity> data;
        public List<MQTT_SubEntity> values;
    }
    public class MQTT_SubEntity
    {   
        public string id;                           //工位
        public bool value;                          //结果
        public bool v;                              //结果
        public long t;                              //时间戳
    }
    #endregion
    #region MQTT发送数据模型1
    public class MQTT_MainEntity_New
    {
        public string id;
        public string name;
        public List<MQTT_SubEntity_New> data;
    }
    public class MQTT_SubEntity_New
    {
        public string id;                                   //工位
        public string name;                                 //结果
        public string updatetime;
        public string address;
        public long value;                              //时间戳
    }
    #endregion
}