using bizFacade;
using MesServerWork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MesServerFunctions
{
    /// <summary>
    /// 命令
    ///显示托盘信息√            case "ShowMoby":
    ///显示操作指南√            case "ProcessList":
    ///显示物料√                case "MaterialList":
    ///显示操作图片√            case "PicShow":
    ///显示拧紧位置√            case "ShaftPosition":
    ///实时显示质量数据√        case "ShowTimelyQuality":
    ///手动拧紧实时显示质量数据√case "ShowTimelyQuality_Tight":
    ///√                        case "OrderFormList":
    ///弹窗消息√                case "Notice":
    ///LED消息提醒√             case "ScrollNotice":
    ///物料检测初始化√          case "MaterialCheckPosition":
    ///返修质量数据显示√        case "RepairQuality"
    ///
    /// </summary>
    public class SendMessageFun
    {
        /// <summary>
        /// 批量发送WEB消息（Value为BOOL值）
        /// 1:显示工序内容
        /// 2：显示物料
        /// 3：显示操作指导图片
        /// 5：显示机型、工件流水号、订单信息
        /// c:显示质量数据
        /// </summary>
        /// <param name="MessageNumm">消息编号组合</param>
        /// <param name="Value">消息值组合</param>
        /// <param name="OpName">工位号</param>
        static public void SendMessage(string MessageNumm, string Value, string OpName)
        {
            for (int i = 0; i < MessageNumm.Length; i++)
            {
                SendMessage(MessageNumm[i], Value[i].ToString(), OpName);

            }
        }
        /// <summary>
        /// 向WEB发送信息（value为字符串）
        /// </summary>
        /// <param name="Command">消息种类</param>
        /// <param name="Value">消息内容</param>
        /// <param name="OpName">工位号</param>
        static public void SendInfomation(string Command, string Value, string OpName)
        {

            string SendMessage = "MES|" + Command + "|" + OpName + "|" + Value;
            AsyncSendMessage(SendMessage);
        }

        static public void AsyncSendMessage_Notice(string opname, string notice)
        {
            //通知Web界面
            BaseDataSystemMES.Web_Notice_Insert(opname, notice);
            string SendMessage = "MES|Notice|" + opname + "|" + "1";
            MIS_BASE.asyncSendMessage(SendMessage);
        }
        /// <summary>
        /// 选择发送给WEB的消息
        /// 1:显示工序内容
        /// 2：显示物料
        /// 3：显示操作指导图片
        /// 5：显示机型、工件流水号、订单信息
        /// c:显示质量数据
        /// </summary>
        /// <param name="Num">消息类型</param>
        /// <param name="OpName">消息工位</param>
        static void SendMessage(char Num, string Value, string OpName)
        {
            string SendMessage;
            switch (Num)
            {
                case '1':
                    //1（直接在界面通过选择机型确认工序内容）
                    SendMessage = "MES|ProcessList|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;

                case '2':
                    //2显示物料
                    SendMessage = "MES|MaterialList|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;

                case '3':

                    //3显示操作指导图片
                    SendMessage = "MES|PicShow|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case '4':
                    //3显示操作指导图片
                    SendMessage = "MES|OrderFormList|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;

                case '5':
                    SendMessage = "MES|ShowMoby|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case '6':
                    SendMessage = "MES|MaterialCheckPosition|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case '7':
                    SendMessage = "MES|WorkStart|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case '8':
                    SendMessage = "MES|OrderFormList|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case '9':
                    SendMessage = "MES|ConfirmOkGo|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case 'a':
                    SendMessage = "MES|FixAllow|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case 'b':
                    SendMessage = "MES|ShaftPosition|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
                case 'c':
                    //SendMessage = "MES|ShowQuality|" + OpName + "|" + Value;
                    SendMessage = "MES|ShowTimelyQuality|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
            }
        }

        /// <summary>
        /// 向WEB发送信息（value为字符串）
        /// </summary>
        /// <param name="Command">消息种类</param>
        /// <param name="Value">消息内容</param>
        /// <param name="OpName">工位号</param>
        //void SendInfomation(string Command, string Value, string OpName)
        //{

        //    string SendMessage = "MES|" + Command + "|" + OpName + "|" + Value;
        //    AsyncSendMessage(SendMessage);
        //}


        /// <summary>
        /// 发送在线产量、在线节拍
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private void SendActuallyCount(string OpName, int tagValue)
        {
            //当工件离开时，更新在线产量、在线节拍
            if (tagValue == 0)
            {
                try
                {
                    int opNameCount = 0;//在线产量
                    int opNameCountTime = 0;//在线节拍

                    BaseDataSystemMES.OpNameCount_New(OpName, out opNameCount, out opNameCountTime); //基本数据_工作日历_班次产量查询_New

                    SendInfomation("ActuallyCount", opNameCount.ToString() + "&" + opNameCountTime.ToString(), OpName);

                }
                catch (Exception err)
                {
                    ////ApplicationLog.WriteLog(err, "Function01:SendActuallyCount");
                }
            }
        }

        /// <summary>
        /// 发送信息到MES通讯服务器或者其他的
        /// </summary>
        /// <param name="Message"></param>
        static public void AsyncSendMessage(string Message)
        {
            MIS_BASE.asyncSendMessage(Message);
        }

        ///// <summary>
        ///// 发送提示消息
        ///// </summary>
        ///// <param name="Message"></param>
        //static public void AsyncSendMessage_Notice(string opname, string notice)
        //{
        //    //通知Web界面
        //    BaseDataSystemMES.Web_Notice_Insert(opname, notice);
        //    string SendMessage = "MES|Notice|" + opname + "|" + "1";
        //    MIS_BASE.asyncSendMessage(SendMessage);
        //}

        /// <summary>
        /// 发送信息到打印机
        /// </summary>
        /// <param name="Message"></param>
        private void asyncSendMessageToMark(string Message)
        {
            string messageSend = (string)Message;
            //UDPClientSend.Send_ALL(ApplicationConfig.MES_MarkPortNum, messageSend);
        }

        /// <summary>
        /// 发送信息到LED
        /// </summary>
        /// <param name="Message"></param>
        private void asyncSendMessageLED(string OpName)
        {

            //发送到大屏幕显示  41104
            string strMessage = "MIS|" + OpName + "|" + "0" + "|" + "1";
            //UDPClientSend.Send_ALL(ApplicationConfig.Port_ShowLED_ProductCount, strMessage);

        }


    }
}

