
using DataLinkMesWork1;
using MesServerFunctions;
using Newtonsoft.Json;
using Opc.Ua.Export;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics.Eventing.Reader;

namespace MisDataFunDll
{
    public partial class MisDataFun
    {

        public class MobyTagType
        {
            /// <summary>
            /// 配方号
            /// </summary>
            public static string PLCRcipe = "配方号";
            /// <summary>
            /// 工位号
            /// </summary>
            public static string OpName = "工位号";
            /// <summary>
            /// 订单号
            /// </summary>
            public static string OrderForm = "订单号";
            /// <summary>
            /// 订单号
            /// </summary>
            public static string OrderForm_MES = "订单号_MES";
            /// <summary>
            /// 产品型号代码
            /// </summary>
            public static string EngineTypeID = "产品型号代码";
            /// <summary>
            /// 变速器序列号
            /// </summary>变速器序列号
            public static string EngineID = "变速器序列号";

            /// <summary>
            /// 发动机型号
            /// </summary>
            public static string EngineType = "发动机型号";
            /// <summary>
            /// 机型基本代码
            /// </summary>
            public static string EngineTypeBasicID = "机型基本代码";
            /// <summary>
            /// 机型基本代码
            /// </summary>
            public static string EngineTypeBasic = "基本机型";
            /// <summary>
            /// 变速器总成号
            /// </summary>
            public static string EngineIDPrinte = "变速器总成号";
            /// <summary>
            /// 托盘号
            /// </summary>
            public static string PartPallet_Code = "托盘号";
            /// <summary>
            /// 产品型号代码_MES
            /// </summary>
            public static string EngineTypeID_MES = "产品型号代码_MES";
            /// <summary>
            /// 变速器序列号_MES
            /// </summary>
            public static string EngineID_MES = "变速器序列号_MES";
            /// <summary>
            /// 发动机型号_MES
            /// </summary>
            public static string EngineType_MES = "发动机型号_MES";
            /// <summary>
            /// 到达时间线外工位
            /// </summary>
            public static string WorkStartOutSideIn = "到达时间线外工位";
            /// <summary>
            /// 离开时间线外工位
            /// </summary>
            public static string WorkStartOutSideOut = "离开时间线外工位";
            /// <summary>
            /// 到达时间
            /// </summary>
            public static string WorkStartIn = "到达时间";
            /// <summary>
            /// 离开时间
            /// </summary>
            public static string WorkStartOut = "离开时间";
            /// <summary>
            /// 持续时间
            /// </summary>
            public static string WorkStartTime = "持续时间";
            /// <summary>
            /// 扫描条码
            /// </summary>
            public static string BarCode = "扫描条码";
            /// <summary>
            /// 工件到位 2
            /// </summary>
            public static string WorkStart = "工件到位";
            /// <summary>
            /// 传递机型  44
            /// </summary>
            public static string EngineTypeGetOverPLC = "传递机型";
            /// <summary>
            /// 申请上件  43
            /// </summary>
            public static string PartLoad = "申请上件";
            /// <summary>
            /// 允许保存  19
            /// </summary>
            public static string MesRead = "允许保存";
            /// <summary>
            /// 保存完成  20
            /// </summary>
            public static string MesReadOver = "保存完成";
            /// <summary>
            /// 允许工作  20
            /// </summary>
            public static string FixAllow = "允许工作";




            /// [机床上电],[循环开始],[机床故障],[上料无件],[下料堵塞],[工件到位]
            /// [传递机型],[申请上件],[允许保存],[保存完成],[合格标志],[前序合格]
            /// [工号],[班次],[是否返修件],[合格放行],[不合格放行]
            /// [到达时间],[离开时间],[持续时间]
            //        engineTypeID = Convert.ToInt32(thisParms[2].Value);
            //engineType = thisParms[3].Value.ToString();
            //engineID = thisParms[4].Value.ToString();
            //palletCode = thisParms[5].Value.ToString();
        }

        /// <summary>
        /// 测量数据工位_监控系统_MOBY_线首_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineTypeID_MES"></param>
        /// <param name="engineType"></param>
        /// <param name="engineType_MES"></param>
        /// <param name="engineID"></param>
        /// <param name="engineID_MES"></param>
        /// <param name="palletCode"></param>
        /// <param name="orderForm"></param>
        /// <param name="orderForm_MES"></param>
        /// <returns></returns>
        public static bool OpName_MIS_MOBY_Insert_FirstOpName(string opName, int engineTypeID, int engineTypeID_MES, string engineType, string engineType_MES, string engineID, string engineID_MES, int palletCode, string orderForm, string orderForm_MES)
        {
            string produceName = "测量数据工位_监控系统_MOBY_线首_增加";
            SqlParameter[] thisParms = new SqlParameter[10];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@产品型号代码", engineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@产品型号代码_MES", engineTypeID_MES);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@发动机型号_MES", engineType_MES);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@发动机号_MES", engineID_MES);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@订单号_MES", orderForm_MES);
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@托盘号", palletCode);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 测量数据工位_监控系统_MOBY_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="engineID"></param>
        /// <param name="palletCode"></param>
        /// <param name="orderForm"></param>
        /// <param name="repairCode"></param>
        /// <param name="Is_repairBarcode"></param>
        /// <param name="repairBarcode"></param>
        /// <returns></returns>
        public static bool OpName_MIS_MOBY_Insert(string opName, string tagType, string tagValue)
        {
            string produceName = "北汽福田工位状态监控MOBY_增加";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@变量类型", tagType);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@变量值", tagValue);

            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 生产计划_派工订单_工件追溯_校验
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static DataTable WorkOrderCheck(string opName, string EngineID, string OrderFrom, string EngineType)
        {
            string produceName = "生产计划_派工订单_工件追溯_校验";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工件编号", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@订单号", OrderFrom);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@机型", EngineType);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out DataTable dt);
            return dt;
        }

        /// <summary>
        /// 接口_IOT接口_报工记录_是否报工判断
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static DataTable IOT_ReqData_UpLoad_IsSend(string opName, string OrderFrom, string reqType, string engineID = "")
        {
            string produceName = "接口_IOT接口_报工记录_是否报工判断";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", OrderFrom);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@报工类型", reqType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@工件编号", engineID ?? "");
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out DataTable dt);
            return dt;
        }

        /// <summary>
        /// 测量数据工位_监控系统_MOBY_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="engineID"></param>
        /// <param name="palletCode"></param>
        /// <param name="orderForm"></param>
        /// <param name="repairCode"></param>
        /// <param name="Is_repairBarcode"></param>
        /// <param name="repairBarcode"></param>
        /// <returns></returns>
        public static bool OpName_MIS_MOBY_Insert_JZ(string opName, string engineID)
        {
            string produceName = "测量数据工位_监控系统_MOBY_静置工位_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        public static void BarCodeIsSecondVerification(string opName, out bool isSecondVerification)
        {
            isSecondVerification = false;
            DataTable dt = new DataTable();
            string produceName = "测量数据工位_监控系统_是否二次验证_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            if (dt.Rows.Count > 0)
            {
                string isVerification = dt.Rows[0]["是否验证"].ToString();
                if (isVerification == "1")
                {
                    isSecondVerification = true;
                }
            }
        }
        /// <summary>
        /// 日志_工位操作_增加
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="type"></param>
        /// <param name="msgType"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static bool LogRecording_OP(string OpName, string type, string msgType, string content)
        {
            string produceName = "日志_工位操作_增加";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", OpName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@消息类型", type);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@操作类型", msgType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@内容", content);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 电子看板_工序内容_临时表_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool MesServer_ProcessList_EngineTypeOver(string opName)
        {
            string produceName = "电子看板_工序内容_临时表_增加";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 电子看板_装配零件_临时表_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool MesServer_Process_EngineTypeOver(string opName)
        {
            string produceName = "电子看板_装配零件_临时表_增加";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 测量数据工位_监控系统_MOBY_查询
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="OrderForm"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineID"></param>
        /// <param name="PartPallet_Code"></param>
        /// <param name="IsrepairBarcode"></param>
        /// <param name="repairBarcode"></param>
        /// <param name="EngineTypeString"></param>
        public static void Moby_Select(string opName, out string OrderForm, out int EngineTypeID, out string EngineType, out string EngineID, out string PartPallet_Code, out int IsrepairBarcode, out string repairBarcode, out string EngineTypeString)
        {
            DataTable dt = new DataTable();
            OrderForm = "";
            EngineTypeID = 0;
            EngineType = "";
            EngineID = "";
            PartPallet_Code = "0";
            IsrepairBarcode = 0;
            repairBarcode = "0";
            EngineTypeString = "";
            try
            {
                string procedureName;
                procedureName = "测量数据工位_监控系统_MOBY_查询";
                SqlParameter[] thisParms = new SqlParameter[1];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);

                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
                if (dt.Rows.Count > 0)
                {
                    OrderForm = dt.Rows[0]["订单号"].ToString();
                    EngineTypeID = Convert.ToInt32(dt.Rows[0]["产品型号代码"]); ;
                    EngineType = dt.Rows[0]["发动机型号"].ToString();
                    EngineID = dt.Rows[0]["发动机号"].ToString();
                    PartPallet_Code = dt.Rows[0]["托盘号"].ToString();
                }
            }
            catch
            {
                OrderForm = "";
                EngineTypeID = 0;
                EngineType = "";
                EngineID = "";
                PartPallet_Code = "0";
                IsrepairBarcode = 0;
                repairBarcode = "";
                EngineTypeString = "";
            }
        }

        /// <summary>
        /// 测量数据工位_监控系统_MOBY_查询
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="OrderForm"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineID"></param>
        /// <param name="PartPallet_Code"></param>
        /// <param name="IsrepairBarcode"></param>
        /// <param name="repairBarcode"></param>
        /// <param name="EngineTypeString"></param>
        public static void Moby_Select(string opName, out string orderNum,
            out int EngineTypeID, out string EngineType, out string EngineID, out string PartPallet_Code,
            out int IsrepairBarcode, out string repairBarcode,
            out string workCode, out string projectName, out string splitCode, out string unidCode, out string engineType, out string engineTypeModel, out string startTime)
        {
            orderNum = "";
            EngineTypeID = 0;
            EngineType = "";
            EngineID = "";
            PartPallet_Code = "";
            IsrepairBarcode = 0;
            repairBarcode = "";
            workCode = ""; // 制造编号
            projectName = ""; // 项目名称
            splitCode = ""; // 间隔号
            unidCode = ""; // 单元号
            engineType = ""; // 本体类型
            engineTypeModel = ""; // 附件类型
            startTime = ""; // 开始时间

            try
            {
                string procedureName;
                procedureName = "测量数据工位_监控系统_MOBY_查询";
                SqlParameter[] thisParms = new SqlParameter[15];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", SqlDbType.NVarChar, 50, "订单号");
                thisParms[1].Direction = ParameterDirection.Output;
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@产品型号代码", SqlDbType.Int, 4, "产品型号代码");
                thisParms[2].Direction = ParameterDirection.Output;
                thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机型号", SqlDbType.NVarChar, 50, "发动机型号");
                thisParms[3].Direction = ParameterDirection.Output;
                thisParms[4] = new System.Data.SqlClient.SqlParameter("@发动机号", SqlDbType.NVarChar, 50, "发动机号");
                thisParms[4].Direction = ParameterDirection.Output;
                thisParms[5] = new System.Data.SqlClient.SqlParameter("@托盘号", SqlDbType.NVarChar, 50, "托盘号");
                thisParms[5].Direction = ParameterDirection.Output;
                thisParms[6] = new System.Data.SqlClient.SqlParameter("@拆解标志", SqlDbType.Int, 4, "拆解标志");
                thisParms[6].Direction = ParameterDirection.Output;
                thisParms[7] = new System.Data.SqlClient.SqlParameter("@拆解返修条码", SqlDbType.NVarChar, 50, "拆解返修条码");
                thisParms[7].Direction = ParameterDirection.Output;
                thisParms[8] = new System.Data.SqlClient.SqlParameter("@制造编号", SqlDbType.NVarChar, 50, "制造编号");
                thisParms[8].Direction = ParameterDirection.Output;
                thisParms[9] = new System.Data.SqlClient.SqlParameter("@间隔号", SqlDbType.NVarChar, 50, "间隔号");
                thisParms[9].Direction = ParameterDirection.Output;
                thisParms[10] = new System.Data.SqlClient.SqlParameter("@单元号", SqlDbType.NVarChar, 50, "单元号");
                thisParms[10].Direction = ParameterDirection.Output;
                thisParms[11] = new System.Data.SqlClient.SqlParameter("@项目名称", SqlDbType.NVarChar, 50, "项目名称");
                thisParms[11].Direction = ParameterDirection.Output;
                thisParms[12] = new System.Data.SqlClient.SqlParameter("@本体类型", SqlDbType.NVarChar, 50, "本体类型");
                thisParms[12].Direction = ParameterDirection.Output;
                thisParms[13] = new System.Data.SqlClient.SqlParameter("@附件类型", SqlDbType.NVarChar, 50, "附件类型");
                thisParms[13].Direction = ParameterDirection.Output;
                thisParms[14] = new System.Data.SqlClient.SqlParameter("@开始时间", SqlDbType.NVarChar, 50, "开始时间");
                thisParms[14].Direction = ParameterDirection.Output;
                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
                if (thisParms[1].Value != null && thisParms[2].Value != null && thisParms[3].Value != null && thisParms[4].Value != null && thisParms[5].Value != null && thisParms[6].Value != null && thisParms[7].Value != null)
                {
                    orderNum = thisParms[1].Value.ToString();
                    EngineTypeID = Convert.ToInt32(thisParms[2].Value); ;
                    EngineType = thisParms[3].Value.ToString();
                    EngineID = thisParms[4].Value.ToString();
                    PartPallet_Code = thisParms[5].Value.ToString();
                    IsrepairBarcode = Convert.ToInt32(thisParms[6].Value);
                    repairBarcode = thisParms[7].Value.ToString();
                    workCode = thisParms[8].Value.ToString(); // 制造编号
                    projectName = thisParms[9].Value.ToString(); // 项目名称
                    splitCode = thisParms[10].Value.ToString();// 间隔号
                    unidCode = thisParms[11].Value.ToString(); // 单元号
                    engineType = thisParms[12].Value.ToString(); // 本体类型
                    engineTypeModel = thisParms[13].Value.ToString(); // 附件类型
                    startTime = thisParms[14].Value.ToString(); // 开始时间
                }
            }
            catch
            {
                orderNum = "";
                EngineTypeID = 0;
                EngineType = "";
                EngineID = "";
                PartPallet_Code = "";
                IsrepairBarcode = 0;
                repairBarcode = "";
                workCode = ""; // 制造编号
                projectName = ""; // 项目名称
                splitCode = ""; // 间隔号
                unidCode = ""; // 单元号
                engineType = ""; // 本体类型
                engineTypeModel = ""; // 附件类型
            }
        }

        /// <summary>
        /// 电子看板_工序内容_查询
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="engineTypeID">产品型号代码</param>
        /// <param name="dt"></param>
        static public void Process_Select(string opName, int engineTypeID, string EngineType, out DataTable dt)
        {
            dt = null;
            string sql = "exec 电子看板_工序内容_查询 '" + opName + "'," + engineTypeID.ToString() + ",'" + EngineType + "'";
            DataAccess.ExecuteDataTable(sql, out dt);
        }
        /// <summary>
        /// 电子看板_装配零件_物料验证_查询 
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="engineID">发动机号</param>
        /// <param name="dt"></param>
        static public bool PartMaterialVerify_Select(string opName, int engineTypeID, string engineType, out DataTable dt)
        {
            dt = null;
            string procedureName;
            procedureName = "电子看板_装配零件_临时表_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        /// <summary>
        /// 电子看板_装配零件_临时表_判断_是否允许工作
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="IsAllowWork"></param>
        /// <returns></returns>
        public static bool MesServer_Judge_IsCanWork(string opName, out int IsAllowWork)
        {
            IsAllowWork = 0;
            string produceName = "电子看板_装配零件_临时表_判断_是否允许工作";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@是否允许工作", IsAllowWork);
            thisParms[1].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                IsAllowWork = Convert.ToInt32(thisParms[1].Value);
                return true;
            }
            return false;
        }

        /// <summary>
        /// [电子看板_装配零件_临时表_增加_北汽]
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool MesServer_Process_EngineTypeOverBQ(string opName)
        {
            string produceName = "电子看板_装配零件_临时表_增加_北汽";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 发送页面点位 同时存入数据库状态
        /// </summary>
        /// <param name="OpName"></param>
        public static void MobySendWebAndSaveData(string OpName, string tagType, string tagValue)
        {
            MisDataFun.OpName_MIS_MOBY_Insert(OpName, tagType, tagValue);
            // 判断是否为涉及前端页面的信号，如果是则同步发送点位
            string tagName = "";
            switch (tagType)
            {
                case "工件到位":
                    tagName = "WorkStart";
                    break;
                case "传递机型":
                    tagName = "EngineTypeGetOverPLC";
                    break;
                case "申请上件":
                    tagName = "PartLoad";
                    break;
                case "允许工作":
                    tagName = "FixAllow";
                    break;
                case "允许保存":
                    tagName = "MesRead";
                    break;
                case "保存完成":
                    tagName = "MesReadOver";
                    break;
                default:
                    break;
            }
            if (tagName != "")
            {
                SendMessageFun.SendInfomation(tagName, Convert.ToString(Convert.ToInt32(tagValue)), OpName);
            }
        }

        /// <summary>
        /// 电子看板_装配零件_临时表_修改_零件条码
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="barCode"></param>
        /// <param name="IsSuccess"></param>
        /// <returns></returns>
        public static bool PartMaterial_DM_Update(string opName, string barCode, out bool IsSuccess)
        {
            IsSuccess = false;
            string produceName = "电子看板_装配零件_临时表_修改_零件条码";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@条码", barCode);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@条码是否符合", IsSuccess);
            thisParms[2].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                IsSuccess = Convert.ToBoolean(thisParms[2].Value);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 测量数据合格索引_增加
        /// </summary>
        /// <param name="EngineID"></param>
        /// <param name="tagID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="opName"></param>
        /// <param name="isGoodBad"></param>
        /// <param name="PartPalletCode"></param>
        /// <param name="Id_tagCF"></param>
        /// <returns></returns>
        public static bool BaseData_tagTable_QualityData_B5A_IndexInsert(string EngineID, string tagID, string EngineType, int EngineTypeID, string opName, int isGoodBad, string PartPalletCode, out int Id_tagCF)
        {
            string procedureName;
            procedureName = "测量数据合格索引_增加";
            Id_tagCF = 0;
            SqlParameter[] thisParms = new SqlParameter[8];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@EngineID", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@TagID_CF", tagID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@EngineType", EngineType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@EngineTypeID", EngineTypeID);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@托盘编号", PartPalletCode);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@合格标志", isGoodBad);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@Id_tagCF", Id_tagCF);
            thisParms[7].Direction = ParameterDirection.Output;

            if (DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms))
            {
                Id_tagCF = Convert.ToInt32(thisParms[7].Value.ToString());
                return true;
            }
            return false;
        }
        /// <summary>
        /// 测量数据合格_增加
        /// </summary>
        /// <param name="Id_tagCF"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineID"></param>
        /// <param name="opName"></param>
        /// <param name="dt"></param>
        /// <param name="IsCheck"></param>
        /// <returns></returns>
        public static bool BaseData_tagTable_QualityData_B5A_Insert(int Id_tagCF, int engineTypeID, string engineID, string opName, DataTable dt, bool IsCheck = false)
        {
            string procedureName;
            procedureName = "测量数据合格_增加";
            SqlParameter[] thisParms = new SqlParameter[15];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@Id_tagCF", Id_tagCF);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@EngineTypeID", engineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@EngineID", engineID);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@TagID", SqlDbType.Int, 4, "TagID");
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@TagValue", SqlDbType.NVarChar, 100, "TagValue");
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@IsGoodBad", SqlDbType.Int, 4, "IsGoodBad");
            //是否保存无合格标志数据数据
            //thisParms[6] = new System.Data.SqlClient.SqlParameter("@IsCheck", IsCheck);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@测量位置", SqlDbType.NVarChar, 50, "测量位置");
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@测量项目", SqlDbType.NVarChar, 50, "测量项目");
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@工位号", opName);  //为了给J07MA020 保留四位精度而设置
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@理论值", SqlDbType.NVarChar, 50, "理论值");
            thisParms[10] = new System.Data.SqlClient.SqlParameter("@上限值", SqlDbType.NVarChar, 50, "上限值");
            thisParms[11] = new System.Data.SqlClient.SqlParameter("@下限值", SqlDbType.NVarChar, 50, "下限值");
            thisParms[12] = new System.Data.SqlClient.SqlParameter("@测量单位", SqlDbType.NVarChar, 50, "测量单位");
            thisParms[13] = new System.Data.SqlClient.SqlParameter("@列位置", SqlDbType.Int, 4, "列位置");
            thisParms[14] = new System.Data.SqlClient.SqlParameter("@变量排序", SqlDbType.Int, 4, "变量排序");
            //table.Columns.Add("TagID", typeof(System.Int32));
            //table.Columns.Add("TagValue", typeof(System.String));
            //table.Columns.Add("IsGoodBad", typeof(System.Int32));
            //table.Columns.Add("测量位置", typeof(System.String));
            //table.Columns.Add("测量项目", typeof(System.String));
            //table.Columns.Add("工位号", typeof(System.String));
            //table.Columns.Add("理论值", typeof(System.String));
            //table.Columns.Add("上限值", typeof(System.String));
            //table.Columns.Add("下限值", typeof(System.String));
            //table.Columns.Add("测量单位", typeof(System.String));
            //table.Columns.Add("列位置", typeof(System.Int32));
            //table.Columns.Add("变量排序", typeof(System.Int32));
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, dt);
        }
        /// <summary>
        /// 测量数据合格_手动拧紧_增加
        /// </summary>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="engineID"></param>
        /// <param name="tagValue"></param>
        /// <param name="isGoodBad"></param>
        /// <param name="opName"></param>
        /// <param name="partPallet"></param>
        /// <param name="tagID"></param>
        /// <param name="tagID_CF"></param>
        /// <returns></returns>
        public static bool BaseData_tagTable_QualityData_B5A_Insert(int engineTypeID, string engineType, string engineID, string tagValue, int isGoodBad, string opName, string partPallet, int tagID, int tagID_CF, string MaxValue, string MinValue)
        {
            string procedureName;
            procedureName = "测量数据合格_手动拧紧_增加";
            SqlParameter[] thisParms = new SqlParameter[11];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@EngineTypeID", engineTypeID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@EngineType", engineType);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@EngineID", engineID);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@TagValue", tagValue);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@合格标志", isGoodBad);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@托盘编号", partPallet);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@TagID", tagID);
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@TagID_CF", tagID_CF);
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@上限值", MaxValue);
            thisParms[10] = new System.Data.SqlClient.SqlParameter("@下限值", MinValue);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }
        /// <summary>
        /// 测量数据合格索引_增加_电芯
        /// </summary>
        /// <param name="EngineID"></param>
        /// <param name="tagID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="opName"></param>
        /// <param name="isGoodBad"></param>
        /// <param name="PartPalletCode"></param>
        /// <param name="Id_tagCF"></param>
        /// <returns></returns>
        public static bool BaseData_tagTable_QualityData_B5A_IndexInsert_cell(string EngineID, string tagID, string EngineType, int EngineTypeID, string opName, int isGoodBad, string PartPalletCode, out int Id_tagCF)
        {
            string procedureName;
            procedureName = "测量数据合格索引_增加_电芯";
            Id_tagCF = 0;
            SqlParameter[] thisParms = new SqlParameter[8];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@EngineID", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@TagID_CF", tagID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@EngineType", EngineType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@EngineTypeID", EngineTypeID);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@托盘编号", PartPalletCode);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@合格标志", isGoodBad);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@Id_tagCF", Id_tagCF);
            thisParms[7].Direction = ParameterDirection.Output;

            if (DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms))
            {
                Id_tagCF = Convert.ToInt32(thisParms[7].Value.ToString());
                return true;
            }
            return false;
        }
        /// <summary>
        /// 测量数据合格_增加_电芯
        /// </summary>
        /// <param name="Id_tagCF"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineID"></param>
        /// <param name="opName"></param>
        /// <param name="dt"></param>
        /// <param name="IsCheck"></param>
        /// <returns></returns>
        public static bool BaseData_tagTable_QualityData_B5A_Insert_cell(int Id_tagCF, int engineTypeID, string engineID, string opName, DataTable dt, bool IsCheck = false)
        {
            string procedureName;
            procedureName = "测量数据合格_增加_电芯";
            SqlParameter[] thisParms = new SqlParameter[15];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@Id_tagCF", Id_tagCF);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@EngineTypeID", engineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@EngineID", engineID);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@TagID", SqlDbType.Int, 4, "TagID");
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@TagValue", SqlDbType.NVarChar, 100, "TagValue");
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@IsGoodBad", SqlDbType.Int, 4, "IsGoodBad");
            //是否保存无合格标志数据数据
            //thisParms[6] = new System.Data.SqlClient.SqlParameter("@IsCheck", IsCheck);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@测量位置", SqlDbType.NVarChar, 50, "测量位置");
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@测量项目", SqlDbType.NVarChar, 50, "测量项目");
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@工位号", opName);  //为了给J07MA020 保留四位精度而设置
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@理论值", SqlDbType.NVarChar, 50, "理论值");
            thisParms[10] = new System.Data.SqlClient.SqlParameter("@上限值", SqlDbType.NVarChar, 50, "上限值");
            thisParms[11] = new System.Data.SqlClient.SqlParameter("@下限值", SqlDbType.NVarChar, 50, "下限值");
            thisParms[12] = new System.Data.SqlClient.SqlParameter("@测量单位", SqlDbType.NVarChar, 50, "测量单位");
            thisParms[13] = new System.Data.SqlClient.SqlParameter("@列位置", SqlDbType.Int, 4, "列位置");
            thisParms[14] = new System.Data.SqlClient.SqlParameter("@变量排序", SqlDbType.Int, 4, "变量排序");
            //table.Columns.Add("TagID", typeof(System.Int32));
            //table.Columns.Add("TagValue", typeof(System.String));
            //table.Columns.Add("IsGoodBad", typeof(System.Int32));
            //table.Columns.Add("测量位置", typeof(System.String));
            //table.Columns.Add("测量项目", typeof(System.String));
            //table.Columns.Add("工位号", typeof(System.String));
            //table.Columns.Add("理论值", typeof(System.String));
            //table.Columns.Add("上限值", typeof(System.String));
            //table.Columns.Add("下限值", typeof(System.String));
            //table.Columns.Add("测量单位", typeof(System.String));
            //table.Columns.Add("列位置", typeof(System.Int32));
            //table.Columns.Add("变量排序", typeof(System.Int32));
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, dt);
        }

        /// <summary>
        /// MES_装配数据_零部件追溯_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="m_ConfirmOkGo"></param>
        /// <returns></returns>
        public static bool Material_Insert(string opName, int m_ConfirmOkGo)
        {
            string produceName = "MES_装配数据_零部件追溯_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@放行方式", m_ConfirmOkGo);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 测量数据发动机在线状态_增加数据
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="isOK"></param>
        static public void WorkStartInsert_JZ(string opName, string engineID, int isOK)
        {
            string procedureName;
            procedureName = "测量数据发动机在线状态_增加数据_JZ";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@是否合格", isOK.ToString());
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }
        /// <summary>
        /// 测量数据发动机在线状态_增加数据
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="isOK"></param>
        static public void WorkStartInsert(string opName, int isOK)
        {
            string procedureName;
            procedureName = "测量数据发动机在线状态_增加数据";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@是否合格", isOK.ToString());
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }

        /// <summary>
        /// 接口_IOT接口_报工记录_增加
        /// </summary>
        /// <returns></returns>
        public static void IOT_Data_UpLode_Res_Save(string opName, string OrderID, string EngineID, string ReqType, bool reqIsOk, string ResText)
        {
            string produceName = "接口_IOT接口_报工记录_增加";
            SqlParameter[] thisParms = new SqlParameter[6];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@订单号", OrderID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@工件编号", EngineID);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@报工类型", ReqType);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@报工结果", reqIsOk);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@结果报文", ResText);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }


        /// <summary>
        /// CallWebApi_FactoryMes_NGRecordSave
        /// </summary>
        /// <returns></returns>
        public static void CallWebApi_FactoryMes_NGRecordSave(string InterfaceName, int AID, string InterfaceUrl, string ReqText, string ResText)
        {
            string produceName = "CallWebApi_FactoryMes_NGRecordSave";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@接口名称", InterfaceName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@AID", AID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@接口地址", InterfaceUrl);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@请求内容", ReqText);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@响应内容", ResText);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 生产计划_派工订单_工件追溯_工位完工
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static bool WorkOrderOpWorkOver(string opName, string EngineID, string OrderFrom)
        {
            string produceName = "生产计划_派工订单_工件追溯_工位完工";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", OrderFrom);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@工件编号", EngineID);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 生产计划_派工订单_工件追溯_工位完工
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static bool SaveQualityInterfaceData(string opName, string EngineID)
        {
            string produceName = "接口_质量数据_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工件编号", EngineID);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 数据表
        /// </summary>
        /// <returns></returns>
        static public DataTable BuildDataTables_WWW()
        {
            DataTable table;
            DataColumnCollection columns;
            table = new DataTable();
            columns = table.Columns;
            table.Columns.Add("TagID", typeof(System.String));
            table.Columns.Add("TagValue", typeof(System.String));
            table.Columns.Add("IsGoodBad", typeof(System.Int32));
            table.Columns.Add("测量位置", typeof(System.String));
            table.Columns.Add("测量项目", typeof(System.String));
            table.Columns.Add("工位号", typeof(System.String));
            table.Columns.Add("理论值", typeof(System.String));
            table.Columns.Add("上限值", typeof(System.String));
            table.Columns.Add("下限值", typeof(System.String));
            table.Columns.Add("测量单位", typeof(System.String));
            table.Columns.Add("列位置", typeof(System.Int32));
            table.Columns.Add("变量排序", typeof(System.Int32));

            return table;
        }

        static public DataTable GetMobyTableByOpName(string opName)
        {
            DataTable dt;
            string procedureName;
            procedureName = "北汽福田工位状态监控MOBY_工位_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
            return dt;
        }

        /// <summary>
        /// 生产计划_派工订单_工件追溯_工件下线
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static bool WorkOrderOpWorkOutLine(string EngineID, string OrderFrom)
        {
            string produceName = "生产计划_派工订单_工件追溯_工件下线";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@订单号", OrderFrom);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工件编号", EngineID);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }


        /// <summary>
        /// XD_提前上料记录_获取
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static DataTable Get_ReqEarlyFeedingData(string opName)
        {
            DataTable dt = new DataTable();
            string produceName = "XD_提前上料记录_获取";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagType"></param>
        /// <param name="tagValue"></param>
        /// <returns></returns>
        public static bool Location_MIS_MOBY_Insert(string opName, string tagType, string tagValue)
        {
            string produceName = "XD_库位Moby_增加";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@库位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@变量类型", tagType);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@变量值", tagValue);

            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        public static DataTable GetRequestReturnMaterials_Type(string opName, string type)
        {
            DataTable dt = new DataTable();
            string produceName = "XD_库位叫料_叫料类型装换";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@叫料类型", type);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        public static DataTable GetEngineType_Order(string opName, out int EngineTypeID, out string EngineType, out string EngineID, out string OrderForm, out int parType, out int isCheckOk, out string msg)
        {
            DataTable dt = new DataTable();
            isCheckOk = 2;
            EngineTypeID = 0;
            EngineType = "";
            EngineID = "";
            parType = 0;
            OrderForm = "";
            msg = "";
            string produceName = "XD_产品上线";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    EngineTypeID = Convert.ToInt32(dt.Rows[0]["产品型号代码"]);
                    EngineType = dt.Rows[0]["产品型号"].ToString();
                    EngineID = dt.Rows[0]["工件编号"].ToString();
                    OrderForm = dt.Rows[0]["订单号"].ToString();
                    parType = Convert.ToInt32(dt.Rows[0]["小机型"]);
                    isCheckOk = Convert.ToInt32(dt.Rows[0]["result"]);
                    msg = dt.Rows[0]["msg"].ToString();
                    return dt;
                }
            }
            return dt;
        }

        public static DataTable GetEngineType_Order(string opName, string Program_No, out int EngineTypeID, out string EngineType, out string EngineID, out string OrderForm, out int isCheckOk, out int planCount, out int haveUplaodCount, out int remainingQuantity, out string msg)
        {
            DataTable dt = new DataTable();
            isCheckOk = 2;
            EngineTypeID = 0;
            EngineType = "";
            EngineID = "";
            OrderForm = "";
            planCount = 0;
            haveUplaodCount = 0;
            remainingQuantity = 0;
            msg = "";
            string produceName = "平芝_生产上线_判断机型订单是否匹配_分线";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            //thisParms[1] = new System.Data.SqlClient.SqlParameter("@PLC_机型代码", Program_No);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    EngineTypeID = Convert.ToInt32(dt.Rows[0]["机型代码"]);
                    EngineType = dt.Rows[0]["机型"].ToString();
                    EngineID = dt.Rows[0]["变速箱总成号"].ToString();
                    OrderForm = dt.Rows[0]["订单号"].ToString();
                    isCheckOk = Convert.ToInt32(dt.Rows[0]["是否匹配"]);
                    planCount = Convert.ToInt32(dt.Rows[0]["计划上料数量"]);
                    haveUplaodCount = Convert.ToInt32(dt.Rows[0]["已上料数量"]);
                    remainingQuantity = Convert.ToInt32(dt.Rows[0]["待上料数量"]);
                    msg = dt.Rows[0]["msg"].ToString();
                    return dt;
                }
            }
            return dt;
        }

        /// <summary>
        /// 29 工位具体零件合格标志
        /// </summary>
        /// <param name="QualityData_GoodBad"></param>
        static public string GetQualityData_GoodBad_String(bool[] QualityData_GoodBad)
        {
            string str;
            str = "";
            if (QualityData_GoodBad != null)
            {

                for (int i = 0; i < QualityData_GoodBad.Length; i++)
                {
                    str = str + (Convert.ToInt32(QualityData_GoodBad[i])).ToString() + "|";
                }

            }
            return str;

        }

        /// <summary>
        /// 返回非标准real
        /// </summary>
        /// <param name="vDataValue"></param>
        /// <returns></returns>
        static public string GetNoNormalReal(object vDataValue)
        {
            try
            {
                string real_a;
                string real_b;
                string groupValueString;
                int length;

                //int real_b_Int;

                length = ((System.Array)(vDataValue)).Length;
                groupValueString = "";
                if (length != 2)
                    return "0.0";

                real_a = Convert.ToUInt16((((System.Array)(vDataValue)).GetValue(0))).ToString();
                real_b = Convert.ToUInt16((((System.Array)(vDataValue)).GetValue(1))).ToString("00");
                groupValueString = real_a + "." + real_b;
                return groupValueString;
            }
            catch
            {
                ////ApplicationLog.WriteLog(err, "GetNoNormalReal");
                return "0.0";

            }
        }

        /// <summary>
        /// 测量数据工位_监控系统_MOBY_查询_PDC
        /// </summary>
        /// <param name="EngineID"></param>
        /// <param name="OrderForm"></param>
        /// <param name="EngineType"></param>
        public static void Moby_Select_PDC(string EngineID, out string OrderForm, out string EngineType, out int EngineTypeCode)
        {
            DataTable dt = new DataTable();
            OrderForm = "";
            EngineType = "";
            EngineTypeCode = 0;
            try
            {
                string procedureName;
                procedureName = "测量数据工位_监控系统_MOBY_查询_PDC";
                SqlParameter[] thisParms = new SqlParameter[1];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@发动机号", EngineID);

                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
                if (dt.Rows.Count > 0)
                {
                    OrderForm = dt.Rows[0]["订单号"].ToString();
                    EngineType = dt.Rows[0]["产品型号"].ToString();
                    EngineTypeCode = Convert.ToInt32(dt.Rows[0]["机型代码"].ToString());
                }
            }
            catch
            {
                OrderForm = "";
                EngineType = "";
                EngineTypeCode = 0;
            }
        }

        /// <summary>
        /// 基本数据_工作日历_班次产量查询_Web页面显示_初始化查询
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="IsAllowWork"></param>
        /// <returns></returns>
        public static void InitOpNameOuputCount(string opName, out int outputValue, out int nowOutputValue,
            out int opNameBeatValue, out int NowOpNameBeatValue, out int classNumber)
        {
            outputValue = 0;//工位产量
            nowOutputValue = 0;//在线产量
            opNameBeatValue = 0;//工位节拍
            NowOpNameBeatValue = 0;//在线节拍
            classNumber = 0;//班次
            try
            {
                string procedureName;
                procedureName = "Web页面显示_计划产量初始化查询";
                SqlParameter[] thisParms = new SqlParameter[6];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位产量", SqlDbType.Int, 4, "工位产量");
                thisParms[1].Direction = ParameterDirection.Output;
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@工位节拍", SqlDbType.Int, 4, "工位节拍");
                thisParms[2].Direction = ParameterDirection.Output;
                thisParms[3] = new System.Data.SqlClient.SqlParameter("@在线产量", SqlDbType.Int, 4, "在线产量");
                thisParms[3].Direction = ParameterDirection.Output;
                thisParms[4] = new System.Data.SqlClient.SqlParameter("@在线节拍", SqlDbType.Int, 4, "在线节拍");
                thisParms[4].Direction = ParameterDirection.Output;
                thisParms[5] = new System.Data.SqlClient.SqlParameter("@班次代码", SqlDbType.Int, 4, "班次代码");
                thisParms[5].Direction = ParameterDirection.Output;
                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
                if (thisParms[1].Value != null && thisParms[2].Value != null && thisParms[3].Value != null && thisParms[4].Value != null && thisParms[5].Value != null)
                {
                    outputValue = Convert.ToInt32(thisParms[1].Value);
                    opNameBeatValue = Convert.ToInt32(thisParms[2].Value);
                    nowOutputValue = Convert.ToInt32(thisParms[3].Value);
                    NowOpNameBeatValue = Convert.ToInt32(thisParms[4].Value);
                    classNumber = Convert.ToInt32(thisParms[5].Value);
                }
            }
            catch
            {
                outputValue = 0;
                opNameBeatValue = 0;
                nowOutputValue = 0;
                NowOpNameBeatValue = 0;
                classNumber = 0;
            }
        }

        static public void GetImageFile(string opName, int engineTypeID, out byte[] pic)
        {
            string sql;
            DataTable dt;
            pic = null;
            sql = "exec 电子看板_工位名称与产品型号产品图片_查询 '" + opName + "'," + engineTypeID.ToString();
            DataAccess.ExecuteDataTable(sql, out dt);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    pic = (byte[])dt.Rows[0]["产品图片"];
                }
            }
        }

        /// <summary>
        /// 电子看板_工位机型_质量数据测量位置_查询_工作顺序
        /// </summary>
        /// <param name="opNum">工位号</param>
        /// <param name="EngineTypeID">产品型号代码</param>
        /// <param name="dt"></param>
        static public bool ShaftPositionSelect(string opNum, int EngineTypeID, out DataTable dt)
        {
            string procedureName = "电子看板_工位机型_质量数据测量位置_临时表_查询";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opNum);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@产品型号代码", EngineTypeID);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }


        /// <summary>
        /// 测量数据合格_查询
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineID"></param>
        /// <param name="tb"></param>
        /// <returns></returns>
        static public bool QualitySelect(string opName, string engineID, out DataTable dt)
        {
            string procedureName = "测量数据合格_查询";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        /// <summary>
        /// 生产计划_派工订单_查询_工位执行_完工判断
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="isCompleted"></param>
        /// <param name="num_plan"></param>
        /// <param name="num_complete"></param>
        public static void Select_OrderFormList_OrderComplete(string opName, out int isCompleted, out int num_plan, out int num_complete)
        {
            isCompleted = 0;//订单数量是否完全上线
            num_plan = 0;//计划数量
            num_complete = 0;//上线数量
            try
            {
                string procedureName;
                procedureName = "生产计划_派工订单_查询_工位执行_完工判断";
                SqlParameter[] thisParms = new SqlParameter[4];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@ISCOMPLETE", SqlDbType.Int, 4, "ISCOMPLETE");
                thisParms[1].Direction = ParameterDirection.Output;
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@NUM_PLAN", SqlDbType.Int, 4, "NUM_PLAN");
                thisParms[2].Direction = ParameterDirection.Output;
                thisParms[3] = new System.Data.SqlClient.SqlParameter("@NUM_COMPLETE", SqlDbType.Int, 4, "NUM_COMPLETE");
                thisParms[3].Direction = ParameterDirection.Output;

                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
                if (thisParms[1].Value != null && thisParms[2].Value != null && thisParms[3].Value != null)
                {
                    isCompleted = Convert.ToInt32(thisParms[1].Value);
                    num_plan = Convert.ToInt32(thisParms[2].Value);
                    num_complete = Convert.ToInt32(thisParms[3].Value);
                }
            }
            catch
            {
                isCompleted = 0;
                num_plan = 0;
                num_complete = 0;
            }
        }
        /// <summary>
        /// 生产计划_派工订单_查询_工位执行
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="dt"></param>
        static public void OrderFormList_Select(string opName, out DataTable dt)
        {
            dt = null;
            string sql = "exec 生产计划_派工订单_查询_工位执行 '" + opName + "'";
            DataAccess.ExecuteDataTable(sql, out dt);
        }
        /// <summary>
        /// MES界面显示_弹窗消息_查询
        /// </summary>
        /// <param name="opname"></param>
        /// <param name="tb"></param>
        /// <returns></returns>
        public static bool ShowWindowNotice(string opname, out DataTable dt)
        {
            string procedureName = "MES界面显示_弹窗消息_查询";
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new System.Data.SqlClient.SqlParameter("@工位号", opname);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref sqlParameters, out dt);
        }

        /// <summary>
        /// MES界面显示_消息滚动_查询
        /// </summary>
        /// <param name="opname"></param>
        /// <param name="tb"></param>
        /// <returns></returns>
        public static bool ShowLEDNotice(string opname, out DataTable dt)
        {
            string procedureName = "MES界面显示_消息滚动_查询";
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new System.Data.SqlClient.SqlParameter("@工位号", opname);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref sqlParameters, out dt);
        }
        /// <summary>
        /// 电子看板_工位机型_物料检测测量位置_查询_物料检测
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        static public bool MaterialCheckSelect(string opName, out DataTable dt)
        {
            string procedureName = "电子看板_工位机型_物料检测测量位置_查询_物料检测";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        /// <summary>
        /// 电芯进站 离站
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static bool Cell_CheckDataAdd(string opName, string EngineID, string operationTime, int isOK)
        {
            string produceName = "测量数据合格_增加数据_电芯";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@操作时间", operationTime);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@合格标志", isOK);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        public static bool Cell_PassStation(string opName, string EngineID, string operationTime, int passType, int isOK = 1)
        {
            string produceName = "测量数据发动机在线状态_增加数据_电芯";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@发动机号", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@操作时间", operationTime);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@合格标志", isOK);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@过站类型", passType);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 报警接口记录 存储
        /// 关机（0）/开机（1）/报警（2）/故障（3） 运行（4） 待机（5）
        /// 注意事项：当设备状态发生变化时，给表里插入一条数据。状态时间字段精确到年月日时分秒。当状态没变化时，不用重复去存数据，不同的故障告警，认为是不同的状态，当前如果是报警1，先存一条报警1，如果一直是报警1，就不用重复存报警1，当又产生了报警2时，需要给表里再存一条报警2。场景如下：
        ////1.开机后，状态先存一条开机，3秒后，再继续存一条待机
        ////2.设备运行后，存一条运行
        ////3.有故障1时，存一条故障，内容为故障1
        ////4.有故障2时，存一条故障，内容为故障2
        ////5.故障1解除后，先存一条运行，如果还有故障2, 继续再存一条故障，内容为故障2
        ////6.故障2解除后，存一条运行或者待机（看设备具体是运行还是待机状态）
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="DeviceStatus">状态代码</param>
        /// <param name="MalfunctionCode">故障代码 如状态为故障/报警，记录故障/报警代码。</param>
        /// <param name="MalfunctionName">故障名称 如状态为故障/报警，记录故障/报警名称</param>
        /// <param name="Malfunctionexplain">故障说明 如状态为故障/报警，记录故障/报警说明。</param>
        /// <param name="Remark">备注</param>
        /// <returns></returns>
        public static bool errorPortSave(string opName, string DeviceStatus, string MalfunctionCode = null, string MalfunctionName = null, string Malfunctionexplain = null, string Remark = null, int? alarmRemove = null)
        {
            string produceName = "接口_工位运行状态_增加";
            SqlParameter[] thisParms = new SqlParameter[7];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@状态代码", DeviceStatus);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@故障代码", MalfunctionCode);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@故障名称", MalfunctionName);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@故障说明", Malfunctionexplain);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@备注", Remark);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@alarmRemove", (object)alarmRemove ?? DBNull.Value);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }


        /// <summary>
        /// 工位运行状态 存储
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static bool WorkRunStatusSave(string opName, int toolPowered, int toolStart, float energy)
        {
            string produceName = "接口_工位使用情况_增加";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@机床上电", toolPowered);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@循环开始", toolStart);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@能耗", energy);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }


        /// <summary>
        /// MES界面显示_弹窗消息_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="notice"></param>
        /// <returns></returns>
        public static bool Web_Notice_Insert(string opName, string notice)
        {
            string produceName = "MES界面显示_弹窗消息_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@Notice", notice);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 基本数据_工作日历_班次产量查询_New
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="opNameCount">在线产量</param>
        /// <param name="opNameCountTime">在线节拍</param>
        static public void OpNameCount_New(string opName, out int opNameCount, out int opNameCountTime)
        {
            opNameCount = 0;
            opNameCountTime = 0;
            string procedureName;
            procedureName = "基本数据_工作日历_班次产量查询_New";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@在线产量", 0);
            thisParms[1].Direction = ParameterDirection.Output;
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@在线节拍", 0);
            thisParms[2].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms))
            {
                opNameCount = Convert.ToInt32(thisParms[1].Value);
                opNameCountTime = Convert.ToInt32(thisParms[2].Value);
            }
        }
        /// <summary>
        /// 基本数据_工作日历_班次产量查询_New
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="opNameCount">在线产量</param>
        /// <param name="opNameCountTime">在线节拍</param>
        static public void OpNameCount_BQ(string opName, out int opNameCount, out int opNameCountTime)
        {
            opNameCount = 0;
            opNameCountTime = 0;
            string procedureName;
            procedureName = "基本数据_工作日历_班次产量查询_北汽";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@在线产量", 0);
            thisParms[1].Direction = ParameterDirection.Output;
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@在线节拍", 0);
            thisParms[2].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms))
            {
                opNameCount = Convert.ToInt32(thisParms[1].Value);
                opNameCountTime = Convert.ToInt32(thisParms[2].Value);
            }
        }
        /// <summary>
        /// 电子看板_工位机型_质量数据测量位置_临时表_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool MesServer_ShaftPosition_EngineTypeOver(string opName)
        {
            string produceName = "电子看板_工位机型_质量数据测量位置_临时表_增加";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 电子看板_工位机型_质量数据测量位置_临时表_查询_完成情况
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="workGroupIndex"></param>
        /// <param name="BoltCode"></param>
        /// <param name="sn_WorkingStepIsOver"></param>
        /// <returns></returns>
        public static bool MesServer_ShaftPosition_Select_FinishResult(string opName, out int workGroupIndex, out string BoltCode, out bool sn_WorkingStepIsOver, out bool isHaveNg)
        {
            workGroupIndex = 0;
            BoltCode = "";
            sn_WorkingStepIsOver = true;
            isHaveNg = false;

            string produceName = "电子看板_工位机型_质量数据测量位置_临时表_查询_完成情况";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@组号", SqlDbType.Int, 4);
            thisParms[1].Direction = ParameterDirection.Output;
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@套筒号", SqlDbType.NVarChar, 50);
            thisParms[2].Direction = ParameterDirection.Output;
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@是否全部完成", SqlDbType.Int, 4);
            thisParms[3].Direction = ParameterDirection.Output;
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@是否全部完成", SqlDbType.Int, 4);
            thisParms[4].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                workGroupIndex = Convert.ToInt32(thisParms[1].Value);
                BoltCode = thisParms[2].Value.ToString();
                sn_WorkingStepIsOver = Convert.ToBoolean(thisParms[3].Value);
                isHaveNg = Convert.ToBoolean(thisParms[3].Value);
                return true;
            }
            return false;
        }


        /// <summary>
        /// 电子看板_工位机型_质量数据测量位置_临时表_修改
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="workGroupIndex"></param>
        /// <param name="IsOK"></param>
        /// <param name="IsFinish"></param>
        /// <returns></returns>
        public static bool MesServer_ShaftPosition_Update(string opName, int workGroupIndex, int IsOK, out bool IsFinish)
        {
            IsFinish = true;
            string produceName = "电子看板_工位机型_质量数据测量位置_临时表_修改";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@组号", workGroupIndex);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@合格标志", IsOK);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@是否全部完成", SqlDbType.Int, 4);
            thisParms[3].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                IsFinish = Convert.ToBoolean(thisParms[3].Value);
                return true;
            }
            return false;
        }
        /// <summary>
        /// 电子看板_工位机型_质量数据测量位置_临时表_查询_完成情况
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="ProcessCode">拧紧序号</param>
        /// <param name="BoltCode">套筒号</param>
        /// <param name="workStepProperty">工步属性</param>
        /// <param name="sn_WorkingStepIsOver">是否全部完成</param>
        /// <returns></returns>
        public static bool MesServer_ShaftPosition_Select_FinishResult(string opName, out int ProcessCode, out int BoltCode, out int workStepProperty, out bool sn_WorkingStepIsOver, out bool isHaveNg)
        {
            BoltCode = 0;
            ProcessCode = 512;
            workStepProperty = 0;
            sn_WorkingStepIsOver = true;
            isHaveNg = false;

            string produceName = "电子看板_工位机型_质量数据测量位置_临时表_查询_完成情况";
            SqlParameter[] thisParms = new SqlParameter[6];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@拧紧序号", SqlDbType.Int, 4);
            thisParms[1].Direction = ParameterDirection.Output;
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@套筒号", SqlDbType.Int, 4);
            thisParms[2].Direction = ParameterDirection.Output;
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@工步属性", SqlDbType.Int, 4);
            thisParms[3].Direction = ParameterDirection.Output;
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@是否全部完成", SqlDbType.Int, 4);
            thisParms[4].Direction = ParameterDirection.Output;
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@是否存在不合格", SqlDbType.Int, 4);
            thisParms[5].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                ProcessCode = Convert.ToInt32(thisParms[1].Value);
                BoltCode = Convert.ToInt32(thisParms[2].Value);
                workStepProperty = Convert.ToInt32(thisParms[3].Value);
                sn_WorkingStepIsOver = Convert.ToBoolean(thisParms[4].Value);
                isHaveNg = Convert.ToBoolean(thisParms[5].Value);
                return true;
            }
            return false;
        }


        /// <summary>
        /// 电子看板_工位机型_质量数据测量位置_临时表_修改_重新拧紧
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="ProcessCode">拧紧序号</param>
        /// <returns></returns>
        public static bool MesServer_ShaftPosition_FixAllow_Again(string opName, int ProcessCode)
        {
            string produceName = "电子看板_工位机型_质量数据测量位置_临时表_修改_重新拧紧";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@组号", ProcessCode);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 测量数据项目
        /// 用于B5A项目
        /// </summary>
        /// <returns></returns>
        public static DataTable BaseData_tagTable_QualityData_Item_B5A()
        {
            DataTable dt;
            string sql;
            sql = "SELECT  TagID,0 as TagValue,TagName,工位号,数据来源,TagTypeID,TagLong,列位置,测量位置,变量类型代码,测量项目,TagAdr,TagAdrDemo,变量特点,变量排序   FROM [MES_基本变量_原始数据] "
                + " where (TagID <> 0 )  and "
            + "  ((变量类型代码 = 9)  "
            + " or (变量类型代码 = 10)  "
            + " or (变量类型代码 = 11)  "
            + " or (变量类型代码 = 80)  "
            + " or (变量类型代码 = 101) "
            + " or (变量类型代码 = 102) "

            + " or (变量类型代码 = 78) "
            + " or (变量类型代码 = 79) "
            + " or (变量类型代码 = 41) "
            + " or (变量类型代码 = 51) "
            + " or (变量类型代码 = 8) "
            + " or (变量类型代码 = 21) "

            + " or (变量类型代码 = 105)) "
            + " and (是否启用 = 1)";

            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }

        /// <summary>
        /// 测量数据合格索引_分线数据_删除
        /// </summary>
        /// <param name="engineID"></param>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool BaseData_tagTable_QualityData_B5A_SubTable_Delete
                                            (string engineID, string opName)
        {
            string procedureName;
            procedureName = "测量数据合格索引_分线数据_删除";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@EngineID", engineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }
        /// <summary>
        /// MES_装配数据_零部件追溯_增加_不合格
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="m_ConfirmOkGo"></param>
        /// <returns></returns>
        public static bool Material_Insert_NG(string opName, int m_ConfirmOkGo)
        {
            string produceName = "MES_装配数据_零部件追溯_增加_不合格";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@放行方式", m_ConfirmOkGo);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 测量数据发动机在线状态_查询_是否已工作
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineType">新零件号(机型)</param>
        /// <returns></returns>
        public static DataTable EngineIsTwoWork(string opName, string OrderForm, string EngineID)
        {
            DataTable dt = new DataTable();
            string produceName = "测量数据发动机在线状态_查询_是否已工作";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", OrderForm);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@总成号", EngineID);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        /// <summary>
        /// 测量数据发动机在线状态_增加数据
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="isOK"></param>
        static public DataTable CheckAllFinish(string opName, string EngineID, int type)
        {
            string procedureName;
            DataTable dt = new DataTable();
            procedureName = "测量数据工位_测试工位状态_修改";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@type", type);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
            return dt;
        }

















        /// <summary>
        /// 报警工位记录表_新增
        /// </summary>
        /// <param name="TagID"></param>
        /// <param name="opName"></param>
        /// <param name="Text"></param>
        /// <param name="Status"></param>
        /// <param name="errType"></param>
        static public void Alarm_Insert2(int TagID, string opName, string Text, int Status, string errType)
        {
            //@TagID  ,
            //@工位号,	
            // @报警内容,
            // @报警类型,
            // @报警状态
            string procedureName;
            procedureName = "报警工位记录表_新增";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@TagID", TagID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@报警内容", Text);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@报警类型", errType);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@报警状态", Status);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }


        /// <summary>
        /// PLC物料扫码校验（含原始码与解析后的 6 段信息）
        /// 码格式：采购订单号|采购行号|物料代码|物料批次号|物料流水号|图号
        /// </summary>
        public static DataTable XD_MaterialsVerify(string opName, string engineID, string materialsCode, int MaterialsTypeCode,
            string purchaseOrderNo = "", string purchaseLineNo = "", string materialCode = "",
            string materialBatchNo = "", string materialSerialNo = "", string drawingNo = "")
        {
            DataTable dt = new DataTable();
            string produceName = "XD_物料记录_增加";
            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("@物料类型编号", MaterialsTypeCode);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@码值", materialsCode ?? "");
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@采购订单号", purchaseOrderNo ?? "");
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@采购行号", purchaseLineNo ?? "");
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@物料代码", materialCode ?? "");
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@物料批次号", materialBatchNo ?? "");
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@物料流水号", materialSerialNo ?? "");
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@图号", drawingNo ?? "");
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        /// <summary>
        /// 根据工件编号查询派工订单执行计划信息
        /// </summary>
        public static DataTable XD_GetPlanInfoByEngineID(string engineID)
        {
            DataTable dt = new DataTable();
            string procedureName = "XD_派工订单执行计划_按工件编号查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工件编号", engineID ?? "");
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
            return dt;
        }

        /// <summary>
        /// 报警工位记录表_MOBY_查询
        /// </summary>
        public static void Alarm_Moby_Search(out DataTable dt)
        {
            string procedureName;
            procedureName = "报警工位记录表_MOBY_查询";
            SqlParameter[] thisParms = new SqlParameter[0];
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }

        /// <summary>
        /// 生产计划_派工订单_配送信息_验证记录_校验
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static DataTable Get_MaterialsScanOverRes(string opName, string order, string engineID, string materialsCode)
        {
            DataTable dt = new DataTable();
            string produceName = "生产计划_派工订单_配送信息_验证记录_校验";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@订单号", order);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工件编号", engineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@物料编码", materialsCode);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }


        public static DataTable Rrunning_AGV_Arrive(string opName)
        {
            DataTable dt = new DataTable();
            string produceName = "XD_磨合_AGV到达";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@库位号", opName);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }
        public static DataTable Rrunning_AGV_Leave(string opName)
        {
            DataTable dt = new DataTable();
            string produceName = "XD_磨合_AGV离开";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@库位号", opName);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        public static DataTable Rrunning_GetNextStoreData(string opName, string EngineID, string EngineType)
        {
            DataTable dt = new DataTable();
            string produceName = "XD_磨合_获取下一序";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@库位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@产品编号", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@产品型号", EngineType);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        public static DataTable Rrunning_UpdateOpCallStatus(string opName, int status)
        {
            DataTable dt = new DataTable();
            string produceName = "XD_磨合_状态_是否呼叫_更新";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@库位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@是否呼叫", status);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }
    }
}
