222
schangxiang@126.com
2024-12-14 7c63794aa85ab939308d10a9ad5c1a57c46bbf6f
CC/iWareCC_ASRS/FormCC.cs
@@ -20,6 +20,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Core.Metadata.Edm;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
@@ -29,12 +30,18 @@
using System.Windows.Forms;
using XiGang.Core.Model;
using XiGang.Core.Model.ViewModels;
using static WZ.Useful.Commons.NativeMethods;
namespace iWareCC
{
    public partial class FormCC : Form
    {
        /// <summary>
        /// 全局-配置报警信息列表
        /// </summary>
        public static DeviceWarningOutput configDeviceWarningList = DeviceWarningHandler.GetConfigWarningList();
        /// <summary>
        /// 全局—是否可以运行执行出库模式
@@ -172,31 +179,12 @@
            startModelTipsThread.Start();
            #region 获取设备数据
            ParameterizedThreadStart parStart1 = new ParameterizedThreadStart(GetSrmInfo);
            Thread thread1 = new Thread(parStart1);
            object o1 = (int)EDevice.一号堆垛机;
            thread1.Start(o1);
            ParameterizedThreadStart parStart2 = new ParameterizedThreadStart(GetSrmInfo);
            Thread thread2 = new Thread(parStart2);
            object o2 = (int)EDevice.二号堆垛机;
            thread2.Start(o2);
            ParameterizedThreadStart parStart3 = new ParameterizedThreadStart(GetSrmInfo);
            Thread thread3 = new Thread(parStart3);
            object o3 = (int)EDevice.三号堆垛机;
            thread3.Start(o3);
            ParameterizedThreadStart parStart4 = new ParameterizedThreadStart(GetSrmInfo);
            Thread thread4 = new Thread(parStart4);
            object o4 = (int)EDevice.四号堆垛机;
            thread4.Start(o4);
            var tskGetStationInfo = new Thread(GetStationInfo);
            tskGetStationInfo.Start();
            var _GetStationWarningInfo = new Thread(GetStationWarningInfo);
            _GetStationWarningInfo.Start();
            tskSetSrmLable = new Thread(SrmRead_Label);
@@ -391,84 +379,6 @@
        /// <summary>
        /// 获取堆垛机的实时信息
        /// </summary>
        private void GetSrmInfo(object int_device)
        {
            while (true)
            {
                EDevice device = (EDevice)Enum.Parse(typeof(EDevice), int_device.ToString());
                Thread.Sleep(cycleDelay_Device);
                try
                {
                    using (var opcClinet = new SrmService.SrmServiceClient())
                    {
                        srmViewDict[(int)device] = opcClinet.GetSrmInfo((int)device);
                        CastToDevice_SrmRealTime(srmViewDict[(int)device]);
                        List<String> warningAddressList = new List<string>();
                        if (srmViewDict[(int)device].R_WarningDBList != null && srmViewDict[(int)device].R_WarningDBList.Length > 0)
                        {
                            var waringList = srmViewDict[(int)device].R_WarningDBList.ToList();
                            if (waringList != null && waringList.Count > 0)
                            {
                                for (int i = 0; i < waringList.Count; i++)
                                {
                                    DeviceWarningHandler.SaveWarning(device, iWareCommon.Utils.LogType.DataProcess_BZ39_IssueInboundTask,
                                        waringList[i].Code, waringList[i].Address, waringList[i].Context);//新增报警
                                    warningAddressList.Add(waringList[i].Address);
                                }
                            }
                        }
                        DeviceWarningHandler.AutoCloseWarning(device, iWareCommon.Utils.LogType.DataProcess_BZ39_IssueInboundTask, warningAddressList);//自动关闭报警
                    }
                }
                catch (Exception ex)
                {
                    Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.DataProcess_BZ39_IssueInboundTask, "获取" + device.ToString() + "的实时信息异常:" + ex.Message, ex);
                    continue;
                }
            };
        }
        /// <summary>
        /// 转换为SRM的实时状态
        /// </summary>
        /// <param name="view"></param>
        private void CastToDevice_SrmRealTime(SrmView view)
        {
            List<Device_SrmRealTime> realTimeList = new List<Device_SrmRealTime>();
            Device_SrmRealTime obj = new Device_SrmRealTime();
            EDevice device = (EDevice)Enum.Parse(typeof(EDevice), view.R_SrmNo.ToString());
            obj = new Device_SrmRealTime()
            {
                SrmCode = view.R_SrmNo.ToString(),
                SrmName = device.ToString(),
                Mode = view.R_Mode.ToString(),
                ModeName = view.ModeName,
                State = view.R_State.ToString(),
                StateName = view.StateName,
                TaskID = view.R_TaskNo.ToString(),
                LiftFull = view.R_LiftFull == 1,
                PosX = view.R_PosX,
                PosY = view.R_PosY,
                PosZ = view.R_PosZ,
                PosZName = EnumberHelper.GetEnumName<ESrmForkPosition>(view.R_PosZ).ToString(),
                // XCoordinate=view.r_xc
                SrmToPlace = view.SrmToPlace,
                SrmSourcePlace = view.SrmSourcePlace,
                ZCoordinate = view.R_PosZmm.ToString(),
                XCoordinate = view.R_PosXmm.ToString(),
                YCoordinate = view.R_PosYmm.ToString()
            };
            realTimeList.Add(obj);
            DeviceSrmRealTimeHandler.Update(realTimeList, iWareCommon.Utils.LogType.DataProcess_BZ39_IssueInboundTask);
        }
@@ -603,19 +513,19 @@
                    this.lbl_Mode_FJ.Text = "设备模式:" + PlcHelper.GetModeName(stationView.R_Mode_FJ);
                    this.lbl_XinTiao_FJ.Text = "心跳:" + stationView.R_HandShake_FJ;
                    this.lbl_Warning_FJ.Text = "心跳:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_FJ);
                    this.lbl_Warning_FJ.Text = "报警类型:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_FJ);
                    this.lbl_Mode_MB.Text = "设备模式:" + PlcHelper.GetModeName(stationView.R_Mode_MB);
                    this.lbl_XinTiao_MB.Text = "心跳:" + stationView.R_HandShake_MB;
                    this.lbl_Warning_MB.Text = "心跳:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_MB);
                    this.lbl_Warning_MB.Text = "报警类型:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_MB);
                    this.lbl_Mode_HB.Text = "设备模式:" + PlcHelper.GetModeName(stationView.R_Mode_HB);
                    this.lbl_XinTiao_HB.Text = "心跳:" + stationView.R_HandShake_HB;
                    this.lbl_Warning_HB.Text = "心跳:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_HB);
                    this.lbl_Warning_HB.Text = "报警类型:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_HB);
                    this.lbl_Mode_FX.Text = "设备模式:" + PlcHelper.GetModeName(stationView.R_Mode_FX);
                    this.lbl_XinTiao_FX.Text = "心跳:" + stationView.R_HandShake_FX;
                    this.lbl_Warning_FX.Text = "心跳:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_FX);
                    this.lbl_Warning_FX.Text = "报警类型:" + PlcHelper.GetWarningTypeName(stationView.R_Warning_FX);
                    ////显示RGV任务完成和完成确认信号
                    //this.lbl_R_RGV_Finish.Text = "RGV任务完成:" + rgvView.R_RGV_Finish;
@@ -683,6 +593,55 @@
                        tb_Rgv_Alter.Text = "";
                    }
                    DeviceWarningHandler.AutoCloseWarning(EDevice.RGV, iWareCommon.Utils.LogType.RgvThreadService, warningAddressList);//自动关闭报警
                    //*/
                }
                catch (Exception ex)
                {
                    rgvView = null;
                    Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.StationThreadService, "获取站点信息出现异常:" + ex.Message, ex);
                    continue;
                }
            }
        }
        /// <summary>
        /// 获取Station 报警信息
        /// </summary>
        /// <param name="obj"></param>
        private async void GetStationWarningInfo(object obj)
        {
            while (true)
            {
                Thread.Sleep(2000);//1秒钟读取一次
                try
                {
                    if (stationServiceClient == null)
                    {
                        continue;
                    }
                    /*
                    iWareCC.StationService.DeviceWarningInfo[] waringList = await stationServiceClient.GetWaringInfoListAsync((int)EDevice.Station, configDeviceWarningList.wmsConfigDeviceWarnings.ToArray());
                    //显示报警信息
                    List<String> warningCodeList = new List<string>();
                    if (waringList != null && waringList.Length > 0)
                    {
                        for (int i = 0; i < waringList.Length; i++)
                        {
                            var findObj = configDeviceWarningList.wms_config_device_warning_list.Where(x => x.WarningCode == waringList[i].Codek__BackingField).FirstOrDefault();
                            DeviceWarningHandler.SaveWarning(EDevice.Station, iWareCommon.Utils.LogType.StationThreadService,
                                findObj.WarningCode, findObj.DeviceAreaCode, findObj.WarningContent, findObj.DeviceWarningType);//新增报警
                            warningCodeList.Add(findObj.WarningCode);
                        }
                    }
                    else
                    {
                    }
                    DeviceWarningHandler.AutoCloseWarning(EDevice.Station, iWareCommon.Utils.LogType.StationThreadService, warningCodeList);//自动关闭报警
                    //*/
                }
@@ -1520,6 +1479,145 @@
                    item.UpiStatus = (int)UpiStatusEnum.初始;
                }
                //清空队列数据
                var list = db.mes_upi_linequeue.ToList();
                db.mes_upi_linequeue.RemoveRange(list);
                db.SaveChanges();
            }
            if (!string.IsNullOrEmpty(alertMsg))
            {
                MessageBox.Show("错误:" + alertMsg);
            }
            else
            {
                MessageBox.Show("已处理");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var alertMsg = "";
            using (WmsDBModel db = new WmsDBModel())
            {
                //查询立体库中的upi列表
                var quanList = db.wms_stock_quan.ToList().Select(x => x.Upi).ToList();
                var upiList = db.mes_batchOrderUPI_new.Where(x => !quanList.Contains(x.UPI)).ToList();
                foreach (var item in upiList)
                {
                    item.AreaCode = (int)AreaCodeEnum.无区域;
                    item.UpiStatus = (int)UpiStatusEnum.初始;
                }
                var packageCodeList = upiList.Select(x => x.PackageCode).ToList();
                var pList = db.mes_package_gather.Where(x => packageCodeList.Contains(x.PackageCode)).ToList();
                foreach (var item in pList)
                {
                    item.AreaCode = (int)AreaCodeEnum.无区域;
                    item.UpiStatus = (int)UpiStatusEnum.初始;
                }
                //清空队列数据
                var list = db.mes_upi_linequeue.ToList();
                db.mes_upi_linequeue.RemoveRange(list);
                db.SaveChanges();
            }
            if (!string.IsNullOrEmpty(alertMsg))
            {
                MessageBox.Show("错误:" + alertMsg);
            }
            else
            {
                MessageBox.Show("已处理");
            }
        }
        private void btn1_Click(object sender, EventArgs e)
        {
            var taskNo = this.tb_taskNo.Text.Trim();
            var alertMsg = "";
            using (WmsDBModel wmsDB = new WmsDBModel())
            {
                var task = wmsDB.wms_rbline_task.Where(x => x.TaskNo == taskNo && x.RbTaskType == (int)RbTaskTypeEnum.入库任务 && x.TaskStatus == (int)TaskStatusEnum.已下发).FirstOrDefault();
                if (task == null)
                {
                    MessageBox.Show("没找到任务");
                    return;
                }
                var upiCode = task.Upi;
                var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
                if (upiObj == null)
                {
                    MessageBox.Show($"根据UPI:{upiCode}没有找到对象 ");
                    return;
                }
                //增加库存
                wms_stock_quan qun = new wms_stock_quan()
                {
                    Id = Yitter.IdGenerator.YitIdHelper.NextId(),
                    Shelf = upiObj.Shelf,
                    Upi = upiCode,
                    PlanNo = task.PlanNo,
                    DetailName = upiObj.DetailName,
                    OrderId = task.OrderId,
                    CreateTime = DateTime.Now,
                    CreateUserName = SysGloble.WCSSystem,
                    InTime = DateTime.Now,
                    OperReason = "入库",
                    PackageCode = task.PackageCode,
                    Length = task.Length,
                    Width = task.Width,
                    Thk = task.Thk,
                    PlaceCode = task.PlaceCode,
                    StockStatus = (int)StockStatusEnum.在库,
                    StockStatusName = StockStatusEnum.在库.ToString(),
                };
                wmsDB.wms_stock_quan.Add(qun);
                task.TaskStatus = (int)TaskStatusEnum.已完成;
                task.FinishedTime = DateTime.Now;
                var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
                place.PlaceStatus = (int)PlaceStatusEnum.正常;
                WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, "缓存入库完成:" + task.PlaceCode);
                wmsDB.SaveChanges();
            }
            if (!string.IsNullOrEmpty(alertMsg))
            {
                MessageBox.Show("错误:" + alertMsg);
            }
            else
            {
                MessageBox.Show("已处理");
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //更新库存表中的次序字段
            var alertMsg = "";
            using (WmsDBModel db = new WmsDBModel())
            {
                //查询立体库中的upi列表
                var quanList = db.wms_stock_quan.ToList();
                var query_quanList = quanList.Select(x => x.Upi).ToList();
                var upiList = db.mes_batchOrderUPI_new.Where(x => query_quanList.Contains(x.UPI)).ToList();
                foreach (var item in quanList)
                {
                    var _shelf = upiList.Find(x => x.UPI == item.Upi);
                    item.Shelf = _shelf.Shelf;
                }
                db.SaveChanges();
            }
            if (!string.IsNullOrEmpty(alertMsg))