222
schangxiang@126.com
2024-12-14 3eabfd8dfa2574efbe8ce8d4a64862c16ad04823
CC/iWareCC_ASRS/ThreadService/02_BZ39¹¤Î»£¨²¹°åºó¹¤Î»£©/DataProcess_RobotBuffer_ModeChange.cs
@@ -1,109 +1,109 @@
using Admin.NET.Application;
using iWareCC.Common.Helper;
using iWareCC.StationService;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DataAccess;
using iWareSql.DBModel;
using iWareSql.WmsDBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Configuration;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WZ.Useful.Commons;
using XiGang.Core.Model;
//using Admin.NET.Application;
//using iWareCC.Common.Helper;
//using iWareCC.StationService;
//using iWareCommon.Common.Globle;
//using iWareCommon.Utils;
//using iWareModel;
//using iWareSql.DataAccess;
//using iWareSql.DBModel;
//using iWareSql.WmsDBModel;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.ServiceModel.Configuration;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using WZ.Useful.Commons;
//using XiGang.Core.Model;
namespace iWareCC.ThreadService
{
    /// <summary>
    /// æœºå™¨äººç¼“存岛 æ¨¡å¼åˆ‡æ¢ å¤„理
    /// </summary>
    public static class DataProcess_RobotBuffer_ModeChange
    {
        public static async void Handler()
        {
            var alertMsg = "";
            LogType logType = LogType.DataProcess_RobotBuffer_ModeChange;
            while (true)
            {
                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = string.Empty;
                try
                {//SystemValue.isAllowRuning_DataProcess_RobotBuffer_ModeChange &&
                    if ( SystemValue.isStartedModel)
                    {
                        var rgvLocation = StationLocationEnum.BZ39.ToString();
                        if (FormCC.IsAllowRunOutMode)
                        {
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var rbRunMode = wmsDB.wms_rbline_runmode.FirstOrDefault();
//namespace iWareCC.ThreadService
//{
//    /// <summary>
//    /// æœºå™¨äººç¼“存岛 æ¨¡å¼åˆ‡æ¢ å¤„理
//    /// </summary>
//    public static class DataProcess_RobotBuffer_ModeChange
//    {
//        public static async void Handler()
//        {
//            var alertMsg = "";
//            LogType logType = LogType.DataProcess_RobotBuffer_ModeChange;
//            while (true)
//            {
//                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
//                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = string.Empty;
//                try
//                {//SystemValue.isAllowRuning_DataProcess_RobotBuffer_ModeChange &&
//                    if ( SystemValue.isStartedModel)
//                    {
//                        var rgvLocation = StationLocationEnum.BZ39.ToString();
//                        if (FormCC.IsAllowRunOutMode)
//                        {
//                            using (WmsDBModel wmsDB = new WmsDBModel())
//                            {
//                                var rbRunMode = wmsDB.wms_rbline_runmode.FirstOrDefault();
                                if (TaskHandler.ValidateNoFinishOutTaskForRobotBuffer(wmsDB))
                                {//不存在
                                    rbRunMode.LineRunMode = (int)RbRunModeEnum.入库模式;
                                    rbRunMode.LineRunModeName = RbRunModeEnum.入库模式.ToString();
                                    rbRunMode.UpdateTime = DateTime.Now;
//                                if (TaskHandler.ValidateNoFinishOutTaskForRobotBuffer(wmsDB))
//                                {//不存在
//                                    rbRunMode.LineRunMode = (int)RbRunModeEnum.入库模式;
//                                    rbRunMode.LineRunModeName = RbRunModeEnum.入库模式.ToString();
//                                    rbRunMode.UpdateTime = DateTime.Now;
                                    //推送给PLC切换模式
                                    using (StationServiceClient client = new StationServiceClient())
                                    {
                                        var res = await client.ChangeModeAsync((int)EDevice.Station, (int)RbRunModeEnum.入库模式, rgvLocation);
                                        if (!res.result)
                                        {
                                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = $"{rgvLocation.ToString()}-推送给PLC切换模式 å¤±è´¥,ChangeModeAsync è¿”回:{res.resMsg}";
                                            continue;
                                        }
                                        else
                                        {
                                            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC切换模式 æˆåŠŸ,ChangeModeAsync,参数: ç«™ç‚¹{rgvLocation}");
                                        }
                                    }
                                    FormCC.IsAllowRunOutMode = false;
                                }
                                else
                                {//存在
                                    if (rbRunMode.LineRunMode == (int)RbRunModeEnum.出库模式)
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = $"已经是出库模式了,此次循环结束";
                                        continue;
                                    }
                                    rbRunMode.LineRunMode = (int)RbRunModeEnum.出库模式;
                                    rbRunMode.LineRunModeName = RbRunModeEnum.出库模式.ToString();
                                    rbRunMode.UpdateTime = DateTime.Now;
//                                    //推送给PLC切换模式
//                                    using (StationServiceClient client = new StationServiceClient())
//                                    {
//                                        var res = await client.ChangeModeAsync((int)EDevice.Station, (int)RbRunModeEnum.入库模式, rgvLocation);
//                                        if (!res.result)
//                                        {
//                                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = $"{rgvLocation.ToString()}-推送给PLC切换模式 å¤±è´¥,ChangeModeAsync è¿”回:{res.resMsg}";
//                                            continue;
//                                        }
//                                        else
//                                        {
//                                            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC切换模式 æˆåŠŸ,ChangeModeAsync,参数: ç«™ç‚¹{rgvLocation}");
//                                        }
//                                    }
//                                    FormCC.IsAllowRunOutMode = false;
//                                }
//                                else
//                                {//存在
//                                    if (rbRunMode.LineRunMode == (int)RbRunModeEnum.出库模式)
//                                    {
//                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = $"已经是出库模式了,此次循环结束";
//                                        continue;
//                                    }
//                                    rbRunMode.LineRunMode = (int)RbRunModeEnum.出库模式;
//                                    rbRunMode.LineRunModeName = RbRunModeEnum.出库模式.ToString();
//                                    rbRunMode.UpdateTime = DateTime.Now;
                                    //推送给PLC切换模式
                                    using (StationServiceClient client = new StationServiceClient())
                                    {
                                        var res = await client.ChangeModeAsync((int)EDevice.Station, (int)RbRunModeEnum.出库模式, rgvLocation);
                                        if (!res.result)
                                        {
                                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = $"{rgvLocation.ToString()}-推送给PLC切换模式 å¤±è´¥,ChangeModeAsync è¿”回:{res.resMsg}";
                                            continue;
                                        }
                                        else
                                        {
                                            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC切换模式 æˆåŠŸ,ChangeModeAsync,参数: ç«™ç‚¹{rgvLocation}");
                                        }
                                    }
                                }
//                                    //推送给PLC切换模式
//                                    using (StationServiceClient client = new StationServiceClient())
//                                    {
//                                        var res = await client.ChangeModeAsync((int)EDevice.Station, (int)RbRunModeEnum.出库模式, rgvLocation);
//                                        if (!res.result)
//                                        {
//                                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange = $"{rgvLocation.ToString()}-推送给PLC切换模式 å¤±è´¥,ChangeModeAsync è¿”回:{res.resMsg}";
//                                            continue;
//                                        }
//                                        else
//                                        {
//                                            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC切换模式 æˆåŠŸ,ChangeModeAsync,参数: ç«™ç‚¹{rgvLocation}");
//                                        }
//                                    }
//                                }
                                wmsDB.SaveChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange += " å‡ºçް异叏:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(logType, " å‡ºçŽ°å¼‚å¸¸ï¼š" + ex.Message, ex);
                }
            }
        }
//                                wmsDB.SaveChanges();
//                            }
//                        }
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ModeChange += " å‡ºçް异叏:" + ex.Message + SysGloble.SPLIT_STR;
//                    Log4NetHelper.WriteErrorLog(logType, " å‡ºçŽ°å¼‚å¸¸ï¼š" + ex.Message, ex);
//                }
//            }
//        }
    }
}
//    }
//}