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

using SystemFramework;

namespace bizFacade
{
    partial class BaseDataSystemMES
    {
        /// <summary>
        /// 机床报警变量
        /// 103
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_Alarm()
        {
            //string errorMessage;
            DataTable dt;
            string sql;
            sql = "SELECT  TagID,0 as TagValue,TagName,工位号,数据来源,TagTypeID,TagLong,列位置,测量位置,变量类型代码,测量项目,TagAdr,TagAdrDemo   FROM [MES_基本变量_原始数据] where 变量类型代码 = 103 and 是否启用 = 1"
                + " and (监控属性代码 = '" + 1 + "')";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        /// <summary>
        /// 测量数据发动机在线状态_增加数据_自动工位
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="EngineID"></param>
        /// <param name="Pallet"></param>
        /// <param name="arrivedTime"></param>
        /// <param name="leavedTime"></param>
        /// <param name="TimeDiff"></param>
        /// <param name="Target"></param>
        /// <param name="lineType"></param>
        /// <param name="isPass"></param>
        /// <param name="OpNameUpDownType"></param>
        static public void WorkStartInsert_AutoWorkStation(string opName, string EngineID, int Pallet, DateTime arrivedTime, DateTime leavedTime, int TimeDiff, int Target, string lineType, string isPass, int OpNameUpDownType)
        {
            string procedureName;
            procedureName = "测量数据发动机在线状态_增加数据_自动工位";
            SqlParameter[] thisParms = new SqlParameter[10];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@托盘编号", Pallet);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@到达时间", arrivedTime);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@离开时间", leavedTime);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@在线时间", TimeDiff);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@目标时间", Target);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@线体类型", lineType);
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@是否合格", isPass);
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@工位上下线类型", OpNameUpDownType);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }
        static public void WorkStartInsert(string opName, int isOK, string dishNumber = null)
        {
            string procedureName;
            procedureName = "测量数据发动机在线状态_增加数据";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@是否合格", isOK.ToString());
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@托盘号", dishNumber);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }

        static public void Update_DataBaind(string EngineID, string nowOpName, string moveOpName)
        {
            string procedureName;
            procedureName = "北汽福田_总分线对应表_数据转移";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("总成号", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("当前工位号", nowOpName);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("转移工位号", moveOpName);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }



        static public void SLResult_Add(string SLResult, string EngineID, string EngineType, int EngineTypeID, int TurnLineWork)
        {
            string procedureName;
            procedureName = "试漏结果_增加";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@测量结果", SLResult);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@总成码", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@机型号", EngineType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@机型代码", EngineTypeID);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@转线工件", TurnLineWork);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }


        //        ALTER PROCEDURE[dbo].[测量数据报警全部_增加数据]
        //        @TagID nvarchar(50),
        //@OpName nvarchar(50),
        //@TagValue int,
        //@State int,
        //@alarmStartTime datetime,
        //@alarmEndTime datetime,
        //@TimeDiff int,
        //@Text1 nvarchar(255),
        //@Text2 nvarchar(255)

        /// <summary>
        /// 
        /// </summary>
        /// <param name="TagID"></param>
        /// <param name="opName"></param>
        /// <param name="TagValue"></param>
        /// <param name="State"></param>
        /// <param name="alarmStartTime"></param>
        /// <param name="alarmEndTime"></param>
        /// <param name="TimeDiff"></param>
        /// <param name="Text1">报警级别</param>
        /// <param name="Text2">报文</param>
        /// <param name="TagOrderBy"></param>
        /// <returns></returns>
        public static bool Alarm_Insert(string TagID, string tagTypeID, string opName, int TagValue,
            DateTime alarmStartTime, DateTime alarmEndTime, int TimeDiff,
            string Text1, string Text2, string TagOrderBy)
        {


            string produceName = "测量数据工位报警全部_增加数据";
            SqlParameter[] thisParms = new SqlParameter[10];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@TagID", TagID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@TagTypeID", tagTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@opName", opName);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@TagValue", TagValue);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@alarmStartTime", alarmStartTime);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@alarmEndTime", alarmEndTime);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@TimeDiff", TimeDiff);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@Text1", Text1);
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@Text2", Text2);
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@TagOrderBy", TagOrderBy);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {

                return true;
            }
            return false;
        }

    }
}
