using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataLinkMesWork;

using SystemFramework;

namespace bizFacade
{
    public partial class BaseDataSystemMES
    {

        /// <summary>
        /// MES_基本变量_DB数据结构_根据工位代码_获得普通变量
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_OpcServerMES(int mesCode, string opName)
        {
            DataTable dt;
            string sql;
            sql = "SELECT TagID,0 as TagValue,TagName,工位号,数据来源,TagTypeID,TagLong,列位置,测量位置,变量类型代码,测量项目,TagAdr,TagAdrDemo,变量特点,变量排序   "
            + " FROM MES_基本变量_原始数据 "
            + " where 变量类型代码 = "+mesCode.ToString()+"  and 是否启用 = 1"
            + " and 工位号='" + opName + "'"
            + " and (监控属性代码 = '" + 1+ "')";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        /// <summary>
        /// MES_基本变量_DB数据结构_根据工位代码_获得普通变量
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_OpcServerMES(int mesCode)
        {
            DataTable dt;
            string sql;
            sql = "SELECT TagID,0 as TagValue,TagName,工位号,数据来源,TagTypeID,TagLong,列位置,测量位置,变量类型代码,测量项目,TagAdr,TagAdrDemo,变量特点,变量排序   "
            + " FROM MES_基本变量_原始数据 "
            + " where 变量类型代码 = " + mesCode.ToString() + "  and 是否启用 = 1"
            + " and (监控属性代码 = '" + 1 + "')";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        
        /// <summary>
        /// MES_基本变量_DB数据结构_获得激发变量
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_All()
        {
            //string errorMessage;
            DataTable dt = null;
            string sql;
            sql = "SELECT  TagID,0 as TagValue,TagName,工位号,数据来源,TagTypeID,TagLong,列位置,测量位置,变量类型代码,测量项目,TagAdr,TagAdrDemo,变量特点,变量排序   FROM [MES_基本变量_原始数据] "
                + " where ((变量类型代码 >= 19 and 变量类型代码 <= 27)  or (变量类型代码 = 101) or (变量类型代码 = 102) or (变量类型代码 = 105) or (变量类型代码 = 1000) or (变量类型代码 = 1001) or (变量类型代码 = 1002) or (变量类型代码 = 1003) or (变量类型代码 = 1004))  and (是否启用 = 1) "
                + " and (监控属性代码 = '" + 1 + "')"
                + " ORDER BY TagID ";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        /// <summary>
        /// MES_基本变量_DB数据结构_获得激发变量
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_All_B5A()
        {
            //string errorMessage;
            DataTable dt = null;
            string sql;
            sql = "SELECT  TagID,0 as TagValue,TagName,工位号,数据来源,TagTypeID,TagLong,列位置,测量位置,变量类型代码,测量项目,TagAdr,TagAdrDemo,变量特点,变量排序   FROM [MES_基本变量_原始数据] "
                + " where ((变量类型代码 = 101) or (变量类型代码 = 102) )  and (是否启用 = 1) "
                + " and (监控属性代码 = '" + 1 + "')"
                + " ORDER BY TagID ";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        
        /// <summary>
        /// 20170310 新加
        /// MES_基本变量_DB数据结构_获得所有普通变量（除101.102.103.104.105）
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_OpcServerMES_ALL_CF()
        {
            DataTable dt;
            string sql;
            sql = "SELECT TagID,0 as TagValue,TagName,工位号,数据来源,TagTypeID,TagLong,列位置,测量位置,变量类型代码,测量项目,TagAdr,TagAdrDemo,变量特点,变量排序   "
            + " FROM MES_基本变量_原始数据 "
            + " where 变量类型代码 <> 101 and 变量类型代码 <> 102 and 变量类型代码 <> 103 and 变量类型代码 <> 104  and 变量类型代码 <> 105 and 是否启用 = 1"
            + " and (监控属性代码 = '" + 1 + "')";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

    }
}
