using System;
//using SystemFramework;

namespace MesServerFunctions
{

    /// <summary>
    /// 此类用于向WEB发送各种类型消息
    /// </summary>
    partial class FunctionMES
    {
       
        /// <summary>
        /// 批量发送WEB消息（Value为BOOL值）
        /// </summary>
        /// <param name="MessageNumm">消息编号组合</param>
        /// <param name="Value">消息值组合</param>
        /// <param name="OpName">工位号</param>
       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的消息
        /// </summary>
        /// <param name="Num">消息类型</param>
        /// <param name="OpName">消息工位</param>
       string Sendmessage(char Num,string Value, string OpName)
       {
           string SendMessage;
           string result = "";
           switch (Num)
           { 
               case '1':
                   //1（直接在界面通过选择机型确认工序内容）
                   SendMessage = "MES|ProcessList|" + OpName + "|" + Value;
                    result = AsyncSendMessage(SendMessage);
                   break;
               case '2':
                   //2显示物料
                   SendMessage = "MES|MaterialList|" + OpName + "|" + Value;
                    result = AsyncSendMessage(SendMessage);
                   break;
               case '3':
                   //3显示操作指导图片
                   SendMessage = "MES|PicShow|" + OpName + "|" + Value;
                    result = AsyncSendMessage(SendMessage);
                   break;
               case '4':
                   //4订单完工模块刷新完成数量
                   SendMessage = "MES|OrderFormList|" + OpName + "|" + Value;
                    AsyncSendMessage(SendMessage);
                    break;
               case '5':
                    SendMessage = "MES|ShowMoby|" + OpName + "|" + Value;
                    result = AsyncSendMessage(SendMessage);
                    break;
               case '6':
                    SendMessage = "MES|MaterialCheckPosition|" + OpName + "|" +Value;
                    result = AsyncSendMessage(SendMessage);
                   break;
               case '7':
                   SendMessage = "MES|WorkStart|" + OpName + "|" + Value;
                    result = AsyncSendMessage(SendMessage);
                   break;
               case '8'://清除MES生成编号
                  
                   break;
               case '9':
                   SendMessage = "MES|ConfirmOkGo|" + OpName + "|" + Value;
                    result = AsyncSendMessage(SendMessage);
                   break;
               case 'a':
                   SendMessage = "MES|FixAllow|" + OpName + "|" + Value;
                    result = AsyncSendMessage(SendMessage);
                   break;
           }
            return result;
       }
        /// <summary>
        /// 向WEB发送信息（value为字符串）
        /// </summary>
        /// <param name="Command">消息种类</param>
        /// <param name="Value">消息内容</param>
        /// <param name="OpName">工位号</param>
        string SendInfomation(string Command, string Value, string OpName)
        {
            string SendMessage = "MES|" + Command + "|" + OpName + "|" + Value;
            return 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;//在线节拍
                   //基本数据_工作日历_班次产量查询_New
                   // BaseDataSystemMES.OpNameCount_New(OpName, out opNameCount, out opNameCountTime);
                   string SendMessage;
                   SendMessage = "MES|ActuallyCount|" + OpName + "|" + opNameCount.ToString() + "&" + opNameCountTime.ToString();
                   AsyncSendMessage(SendMessage);
               }
               catch (Exception err)
               {
                   ////ApplicationLog.WriteLog(err, "Function02:SendActuallyCount");
               }
           }
       }


    }
}
