
using DataLinkMesWork1;
using System.Data;
using System.Data.SqlClient;

namespace MisDataFunDll
{
    public partial class MisDataFun
    {
        public static DataTable BaseData_tagTable_TagName()
        {
            DataTable dt = null;
            string sql;
            sql = "SELECT distinct[TagName],[变量类型代码] FROM[MES_基本变量_原始数据] ";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        public static DataTable GetMesServerCodeFromMIS()
        {
            DataTable dt;
            string sql;
            sql = "exec MES_计划BOM_工位与名称_查询应用程序";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        public static DataTable dt_Signal()
        {
            DataTable dt;
            string sql;
            sql = "SELECT *  FROM [MES_基本变量_原始数据]";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        public static DataTable dt_Device()
        {
            DataTable dt;
            string sql;
            sql = "SELECT  * FROM [MES_基本变量设备类型对应表]";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        public static DataTable dt_TagTypeDataType()
        {
            DataTable dt;
            string sql;
            sql = "SELECT TOP (1000) [序号],[变量类型],[TagTypeDataType],[TagName],[变量类型代码],[TagTypeChange],[MesTagTypeChange],[WebTagTypeChange],[信号点名称][变量类型名称] FROM [MES_基本变量变量类型代码]";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        public static DataTable GetCheckOpName()
        {
            DataTable dt = new DataTable();
            string produceName = "MES_计划BOM_工位与名称_查询";
            SqlParameter[] thisParms = null;


            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);

            return dt;
        }

        /// <summary>
        /// 查询工步属性
        /// </summary>
        /// <returns></returns>
        public static DataTable GetworkStepPropertyFromMIS()
        {
            DataTable dt;
            string sql;
            sql = "SELECT distinct 工位号,工步属性 FROM [MES_计划BOM_工位与名称] where 是否监控=1";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        /// <summary>
        /// 查询返修工位号
        /// </summary>
        /// <returns></returns>
        public static DataTable GetOpNameRepairFromMIS()
        {
            DataTable dt;
            string sql;
            sql = "SELECT distinct 工位号,返修工位号 FROM [MES_计划BOM_工位与名称] where 是否监控=1";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }



        /// <summary>
        /// 测量工位号和工位名称
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_QualityData_OpName_Name()
        {
            DataTable dt;
            string sql = "SELECT distinct [工位号],[工位名称]  FROM [MES_计划BOM_工位与名称]  "
                + " where (监控属性代码 = '" + 1 + "')"
                + " ORDER BY 工位号 ";
            //来源于SQL Server
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        /// <summary>
        /// MES_计划BOM_工位与名称
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_OpName()
        {
            //DataTable dt;
            //string sql = "SELECT *  FROM [MES_计划BOM_工位与名称]  "
            //    + " where (监控属性代码 = '" + ApplicationConfig.MES_Code.ToString() + "')"
            //    + " ORDER BY 工位号 ";
            //DataAccess.ExecuteDataTable(sql, out dt);
            //return dt;

            //2022.07.27.LLX 处理了一下子
            DataTable dt;
            string sql = "SELECT *  FROM [MES_计划BOM_工位与名称]  "
                + " where (监控属性代码 = '" + 1 + "') and [是否通过监控系统保存数据] is not null"
                + " ORDER BY 工位号 ";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        /// <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;
        }

        /// <summary>
        /// 发动机类型转换表
        /// SELECT  ID,发动机机型代码  FROM MES_计划BOM_发动机型号代码
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_QualityData_EngineTypeID()
        {
            DataTable dt;
            string sql;
            sql = "SELECT  ID,发动机机型代码  FROM MES_计划BOM_发动机型号代码 ";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }


        /// <summary>
        /// 测量合格标志
        /// 全部测量数据的测量工位
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_QualityData_GoodBad_MIS_OpName_B5A()
        {
            DataTable dt;
            string sql;
            sql = "SELECT  distinct 工位号 "
                    + " FROM MES_基本变量_原始数据 "
                    + " where 变量特点 = 8 and 是否启用 = 1 "
                    + " and (监控属性代码 = '" + 1 + "')";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        /// <summary>
        /// 测量合格标志
        /// 全部测量数据的测量工位的数据来源
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_QualityData_GoodBad_MIS_OpName(string opName)
        {
            DataTable dt;
            string sql;
            sql = "SELECT  TagID,工位号,数据来源 "
                    + " FROM MES_基本变量_原始数据 "
                    + " where OpcServer_OPNAME = '1'  and 是否启用 = 1 "
                    + " and 工位号='" + opName + "'"
                    + " and (监控属性代码 = '" + 1 + "')";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        /// <summary>
        /// 测量合格标志
        /// 全部测量数据的测量工位的数据来源的测量变量
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_QualityData_GoodBad_MIS_OpName(string opName, string opNameFrom)
        {
            DataTable dt;
            string sql;
            sql = "SELECT  TagID "
                    + " FROM MES_基本变量_原始数据 "
                    + " where OpcServer_OPNAME = '2'  and 是否启用 = 1 "
                    + " and 工位号='" + opName + "'"
                    + " and 数据来源='" + opNameFrom + "'"
                    + " and (监控属性代码 = '" + 1 + "')";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        /// <summary>
        /// MES_基本变量_机型代码_查询
        /// </summary>
        /// <param name="dt"></param>
        static public void EngineType_Select(out DataTable dt)
        {
            dt = null;
            string sql = "exec MES_基本变量_机型代码_查询";
            DataAccess.ExecuteDataTable(sql, out dt);
        }









    }
}
