using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MesWork
{
    public partial class QingYa_OP0010 { }
    public partial class MesWorkForm
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_Msg"></param>
        public void LoadClientInfo(object _Msg)
        {
            try
            {
                string recStr = (string)_Msg;
                string m_Source = recStr.Split('|')[0];
                string cmd = recStr.Split('|')[1];
                //string OpName = recStr.Split('|')[2];
                //string tagValue = recStr.Split('|')[3];

                switch (m_Source)
                {
                    case "DT":
                        switch (cmd)
                        {
                            case "B_C_DT_WebLoaded":
                                new TaskFactory().StartNew(delegate () {
                                    try
                                    {
                                        var tagList = DriverCache["Cache_Tag"];
                                        foreach (var item in tagList)
                                        {
                                            var tf = (OpcBasic.TagFormat)item.Value;
                                            var tagID = tf.TagID;
                                            var tagValue = tf.TagValue.ToString();
                                            var tagTypeID = Convert.ToInt32(tf.TagTypeID);
                                            var tagTypeCodeID = (int)tf.TagTypeCodeID;
                                            var opName = tf.OpName.ToString();
                                            if (tagTypeID == 11)
                                            {
                                                switch (tagValue.ToUpper())
                                                {
                                                    case "1":
                                                    case "TRUE":
                                                        tagValue = "1";
                                                        break;
                                                    default:
                                                        tagValue = "0";
                                                        break;
                                                }
                                            }
                                           
                                            S_C_B_TagIDTrigger(opName,tagID, tagValue);
                                        }
                                    }
                                    catch (Exception ew1) { }
                                    //try
                                    //{
                                    //    var from_to_loc = agvRead.ReadAgv();
                                    //    MesWorkForm.S_C_B_TagIDTrigger(agvRead.connectStr, agvRead.tagID, from_to_loc);
                                    //}
                                    //catch (Exception ew2) { }
                                });
                                break;
                        }
                        break;
                    case "MES":
                        switch (cmd)
                        {
                            case "B_C_DT_WebLoaded":
                                //string OpName = recStr.Split('|')[2];
                                //if (OpName == "AllOpName")
                                //{

                                //    foreach (var fanucBaseNC in fanucBaseNCArray)
                                //    {
                                //        fanucBaseNC.SendDataReLoad();
                                //    }

                                //    return;
                                //}
                                //if (fanucBaseNCArray.FirstOrDefault(o => o.OpName == OpName) != null) {
                                //    fanucBaseNCArray.FirstOrDefault(o => o.OpName == OpName).SendDataReLoad();
                                //}

                                // FanucBaseNC.SendStateDataFirst();



                                break;
                            default:
                                break;
                        }
                        break;
                }

            }
            catch (Exception err) { }
        }





    }
}
