//using DataLinkMesWork;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
//using SystemFramework;

namespace MesServerWork
{
    public class InitTagValueListData
    {
        public InitTagValueListData()
        {
            DataTable dt = ReadMesServerData();

            InitMesReadTagKey();
            initAllItemValue(dt);
        }

        DataTable ReadMesServerData()
        {
            return null;// MesWork.PlcLinkForm.dt_BasicData.Select($"是否启用 = 1 and 监控属性代码 = '{1}'").CopyToDataTable<DataRow>();
        }

        void InitMesReadTagKey()
        {
            DataTable dt = null;// MesWork.PlcLinkForm.dt_BasicData.Select($"是否启用 = 1 and 变量类型代码=19 and 监控属性代码 = '{1}'").CopyToDataTable<DataRow>(); ;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (MesReadTagKey_Hash.ContainsKey(dt.Rows[i]["工位号"].ToString()))
                {
                    MesReadTagKey_Hash[dt.Rows[i]["工位号"].ToString()] = dt.Rows[i]["TagID"].ToString();
                }
                else
                {
                    MesReadTagKey_Hash.Add(dt.Rows[i]["工位号"].ToString(), dt.Rows[i]["TagID"].ToString());
                }

            }

        }
        void initAllItemValue(DataTable dt)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (ItemValue_Hash.ContainsKey(dt.Rows[i]["TagID"]))
                {
                    if (Convert.ToInt32(dt.Rows[i]["列位置"]) != 0)
                    {
                        ItemValue_Hash[dt.Rows[i]["TagID"]] = dt.Rows[i]["测量项目"].ToString() + "(" + dt.Rows[i]["列位置"].ToString() + ")";
                    }
                    else
                    {
                        ItemValue_Hash[dt.Rows[i]["TagID"]] = dt.Rows[i]["测量项目"].ToString();
                    }

                }
                else
                {
                    if (Convert.ToInt32(dt.Rows[i]["列位置"]) != 0)
                    {
                        ItemValue_Hash[dt.Rows[i]["TagID"]] = dt.Rows[i]["测量项目"].ToString() + "(" + dt.Rows[i]["列位置"].ToString() + ")";
                    }
                    else
                    {
                        ItemValue_Hash[dt.Rows[i]["TagID"]] = dt.Rows[i]["测量项目"].ToString();
                    }
                }

            }


        }



        public static Hashtable MesReadTagKey_Hash = new Hashtable();
        public static Hashtable ItemValue_Hash = new Hashtable();

    }
}
