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

using System.Data.OleDb;


using DataLinkMesWork;

//using SystemFramework;
namespace bizFacade
{
    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 = "保存完成";




        /// [机床上电],[循环开始],[机床故障],[上料无件],[下料堵塞],[工件到位]
        /// [传递机型],[申请上件],[允许保存],[保存完成],[合格标志],[前序合格]
        /// [工号],[班次],[是否返修件],[合格放行],[不合格放行]
        /// [到达时间],[离开时间],[持续时间]
        //        engineTypeID = Convert.ToInt32(thisParms[2].Value);
        //engineType = thisParms[3].Value.ToString();
        //engineID = thisParms[4].Value.ToString();
        //palletCode = thisParms[5].Value.ToString();
    }
    public partial class BaseDataSystemMES
    {
        /// <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="palletCode"></param>
        /// <param name="isRepair"></param>
        /// <param name="repairCode"></param>
        /// <returns></returns>
        public static bool OpName_MIS_Moby_Select(string opName,
            out string orderForm, out int engineTypeID, out string engineType,
            out string engineID, out string palletCode, out int isRepair, out string repairCode)
        {
            orderForm = "";
            engineTypeID = 0;
            engineType = "";
            engineID = "";
            palletCode = "";
            isRepair = 0;
            repairCode = "";

            string produceName = "测量数据工位_监控系统_MOBY_查询";
            SqlParameter[] thisParms = new SqlParameter[8];
            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;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                orderForm = thisParms[1].Value.ToString();
                engineTypeID = Convert.ToInt32(thisParms[2].Value);
                engineType = thisParms[3].Value.ToString();
                engineID = thisParms[4].Value.ToString();
                palletCode = thisParms[5].Value.ToString();
                isRepair = Convert.ToInt32(thisParms[6].Value);
                repairCode = thisParms[7].Value.ToString();
                return true;
            }
            return false;
        }

        /// <summary>
        /// 测量数据工位_获得订单_查询
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="orderForm"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="engineID"></param>
        /// <param name="palletCode"></param>
        /// <param name="isRepair"></param>
        /// <param name="repairCode"></param>
        /// <returns></returns>
        public static bool OrderFormByOpName_Select(string opName,
            out string orderForm, out int engineTypeID, out string engineType,
            out string engineID, out string palletCode, out int isRepair, out string repairCode)
        {
            orderForm = "";
            engineTypeID = 0;
            engineType = "";
            engineID = "";
            palletCode = "";
            isRepair = 0;
            repairCode = "";

            string produceName = "测量数据工位_获得订单_查询";
            SqlParameter[] thisParms = new SqlParameter[8];
            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;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                orderForm = thisParms[1].Value.ToString();
                engineTypeID = Convert.ToInt32(thisParms[2].Value);
                engineType = thisParms[3].Value.ToString();
                engineID = thisParms[4].Value.ToString();
                palletCode = thisParms[5].Value.ToString();
                isRepair = Convert.ToInt32(thisParms[6].Value);
                repairCode = thisParms[7].Value.ToString();
                return true;
            }
            return false;
        }

        /// <summary>
        /// 北汽福田工位状态监控MOBY_增加
        /// 工位号],[订单号],[产品型号代码],[变速器序列号],[发动机型号],[机型基本代码],[变速器总成号] ,[托盘号]
        /// [产品型号代码_MES],[变速器序列号_MES],[发动机型号_MES]
        /// [机床上电],[循环开始],[机床故障],[上料无件],[下料堵塞],[工件到位]
        /// [传递机型],[申请上件],[允许保存],[保存完成],[合格标志],[前序合格]
        /// [工号],[班次],[是否返修件],[合格放行],[不合格放行],[扫描条码]
        /// [到达时间],[离开时间],[持续时间]
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagType"></param>
        /// <param name="tagValue"></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>
        /// 测量数据工位_监控系统_MOBY_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="orderForm"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="engineID"></param>
        /// <param name="palletCode"></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 orderForm,
            int engineTypeID, string engineType, string engineID, int palletCode, int repairCode, int Is_repairBarcode, string repairBarcode)
        {
            string produceName = "测量数据工位_监控系统_MOBY_增加";
            SqlParameter[] thisParms = new SqlParameter[9];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@产品型号代码", engineTypeID);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@托盘号", palletCode);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@返修标志", repairCode);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@拆解标志", Is_repairBarcode);
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@拆解返修条码", repairBarcode);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        public static bool OpName_MIS_MOBY_Insert_FirstOpName(string opName,
    int engineTypeID, string engineType, string engineID, int palletCode, int repairCode, int Is_repairBarcode, string repairBarcode)
        {
            string produceName = "测量数据工位_监控系统_MOBY_线首_增加";
            SqlParameter[] thisParms = new SqlParameter[8];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@产品型号代码", engineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@托盘号", palletCode);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@返修标志", repairCode);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@拆解标志", Is_repairBarcode);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@拆解返修条码", repairBarcode);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 测量数据工位_监控系统_订单号_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="orderForm"></param>
        /// <returns></returns>
        public static bool OpName_MIS_OrderForm_Insert(string opName, string orderForm)
        {
            string produceName = "测量数据工位_监控系统_订单号_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 测量数据工位_监控系统_操作者工号_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="opperatorCode"></param>
        /// <returns></returns>
        public static bool OpName_MIS_Operator_Insert(string opName, string opperatorCode)
        {
            string produceName = "AMES_物料拉动_测量数据工位_监控系统_操作者工号_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@操作者工号", opperatorCode);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 测量数据工位_监控系统_发动机号_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineID"></param>
        /// <returns></returns>
        public static bool OpName_MIS_EngineID_Insert(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>
        /// <param name="opName"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="engineID"></param>
        /// <returns></returns>
        public static bool OpName_MIS_OrderForm_EngineType_Update(string opName, int engineTypeID, string engineType, string engineID)
        {
            string produceName = "测量数据工位_监控系统_订单号_发动机型号_修改";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@产品型号代码", engineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// 测量数据工位_监控系统_发动机型号_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <returns></returns>
        public static bool OpName_MIS_EngineType_Insert(string opName, int engineTypeID, string engineType)
        {
            string produceName = "测量数据工位_监控系统_发动机型号_增加";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@产品型号代码", engineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 测量数据工位_监控系统_托盘号_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="palletCode"></param>
        /// <returns></returns>
        public static bool OpName_MIS_PalletCode_Insert(string opName, int palletCode)
        {
            string produceName = "测量数据工位_监控系统_托盘号_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@托盘号", palletCode);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 测量数据工位_监控系统_返修_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="repairCode"></param>
        /// <param name="repairBarcode"></param>
        /// <returns></returns>
        public static bool OpName_MIS_Repair_Insert(string opName, int repairCode, int Is_repairBarcode, string repairBarcode)
        {
            string produceName = "测量数据工位_监控系统_返修_增加";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@返修标志", repairCode);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@拆解标志", Is_repairBarcode);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@拆解返修条码", repairBarcode);
            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>
        /// [电子看板_装配零件_临时表_增加_北汽]
        /// </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>
        /// <returns></returns>
        public static bool ProcessDataToTemp(string opName,int EngineTypeID,string OrderForm,string EngineID)
        {
            string produceName = "电子看板_工序内容_转入临时";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@机型代码", EngineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@工件编号", OrderForm);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@订单号", EngineID);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }
        /// <summary>
        /// [电子看板_装配零件_临时表_增加_北汽线首]
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool MesServer_Process_EngineTypeOver_BQ_FirstOP(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="MainLineAllowWork"></param>
        /// <returns></returns>
        public static DataTable Create_OutLineBarCode(string EngineID, string OrderForm)
        {
            DataTable dt;
            string produceName = "自制件条码记录_创建";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@总成号", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", OrderForm);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        /// <summary>
        /// 合力_OPA90是否允许工作_判断  如果允许工作则将两个轮毂状态设为待匹配
        /// </summary>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineTypeID_QiaoKe"></param>
        /// <param name="EngineID"></param>
        /// <param name="OrderForm"></param>
        /// <param name="MatchResult"></param>
        /// <param name="MatchResultStr"></param>
        /// <returns></returns>
        public static bool OP50_OPA90_MatchResult(int EngineTypeID, int EngineTypeID_QiaoKe, string EngineID, string OrderForm, out int MatchResult, out string MatchResultStr)
        {
            DataTable dt = new DataTable();
            MatchResult = 3;// 默认是报警 程序出错
            MatchResultStr = "默认是报警 程序出错";// 默认是报警 程序出错
            string produceName = "合力_OPA90是否允许工作_判断";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@轮毂机型", EngineTypeID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@轮毂总成号", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@桥壳_机型", EngineTypeID_QiaoKe);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@订单号", OrderForm);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    MatchResult = Convert.ToInt32(dt.Rows[0]["最终结果"]);
                    MatchResultStr = dt.Rows[0]["最终结果说明"].ToString();
                    return true;
                }
            }
            return false;
        }

        public static bool OP051_OP050_NeedWork(string EngineID, string opName, string orderForm, out int MatchResult, out string resultMsg)
        {
            DataTable dt = new DataTable();
            MatchResult = 0;
            resultMsg = "";

            string produceName = "合力_OP050前停判断_下工位是否需要工作";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@桥壳总成号", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    MatchResult = Convert.ToInt32(dt.Rows[0]["是否需要工作"]);
                    resultMsg = dt.Rows[0]["msg"].ToString();
                    return true;
                }
            }
            return false;
        }

        public static bool OP051_OP050_NeedWork_Save(string EngineID, int MatchResult, string Cause)
        {

            string produceName = "合力_OP050是否需要工作_插入";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@桥壳总成号", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@是否需要工作", MatchResult);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@原因", Cause);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 合力_工位报警记录表_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool HeLi_OoNameAlarmRecord_Add(string opName, string EngineID, string alarmText)
        {
            string produceName = "合力_工位报警记录表_增加";
            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("@报警内容", alarmText);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

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

        public static bool GetEngineTypeByEngineID(string engineID, out DataTable dt)
        {
            string procedureName = "测量数据发动机在线状态_下线工位_是否存在_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@EngineID", engineID);
            //return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);


        }
        //测量数据发动机在线状态_下线工位_是否存在_查询


        /// <summary>
        /// 测量数据发动机在线状态_跟踪发动机条码状态_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool MaterialPush_EngineIDStatus_Insert(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 PartMaterialUseNum_Update(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="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>
        ///[北汽福田工位J07MA40_验证线外工位零件是否与工位J07MA20匹配] @EngineID nvarchar(50),@BarCode nvarchar(50)
        /// </summary>
        /// <param name="EngineID"></param>
        /// <param name="BarCode"></param>
        /// <param name="IsAllowWork"></param>
        /// <returns></returns>
        public static bool MesServer_J07MA20_Judge_IsCanWork(string EngineID, string BarCode, out int IsAllowWork)
        {
            IsAllowWork = 0;
            string produceName = "北汽福田工位J07MA40_验证线外工位零件是否与工位J07MA20匹配";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@EngineID", EngineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@BarCode", BarCode);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out DataTable dt))
            {
                IsAllowWork = Convert.ToInt32(dt.Rows[0][0]);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 条码扫描_判断条码类型
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="barCode"></param>
        /// <param name="barCodeType"></param>
        /// <returns></returns>
        public static bool GetBarcodeType(string opName, string barCode, out string barCodeType)
        {
            barCodeType = "";
            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("@条码类型", barCodeType);
            thisParms[2].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                barCodeType = thisParms[2].Value.ToString();
                return true;
            }
            return false;
        }

        /// <summary>
        /// 物料拉动_线边库存_修改
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="barcode"></param>
        /// <param name="MaterialIsExsit"></param>
        /// <param name="BarCodeIsExsit"></param>
        /// <param name="IsBillOk"></param>
        /// <param name="IsCanUpdateBetch"></param>
        /// <param name="IsScaningMulti"></param>
        /// <param name="IsMultiPC"></param>
        /// <returns></returns>
        public static bool ReceiveCard_Update(string OpName, string barcode,
            out bool MaterialIsExsit, out bool BarCodeIsExsit, out bool IsBillOk, out bool IsCanUpdateBetch, out bool IsScaningMulti, out bool IsMultiPC)
        {
            MaterialIsExsit = true;//@物料是否存在
            BarCodeIsExsit = true;//@条码是否存在
            IsBillOk = true;//@扫描是否符合订单
            IsCanUpdateBetch = true;//@是否可以更新批次
            IsScaningMulti = false;//@是否重复扫描
            IsMultiPC = false;//是否多箱追踪批次


            string produceName = "物料拉动_线边库存_修改";
            SqlParameter[] thisParms = new SqlParameter[8];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", OpName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@卡片条码", barcode);

            thisParms[2] = new System.Data.SqlClient.SqlParameter("@物料是否存在", MaterialIsExsit);
            thisParms[2].Direction = ParameterDirection.Output;
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@条码是否存在", BarCodeIsExsit);
            thisParms[3].Direction = ParameterDirection.Output;
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@扫描是否符合订单", IsBillOk);
            thisParms[4].Direction = ParameterDirection.Output;
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@是否可以更新批次", IsCanUpdateBetch);
            thisParms[5].Direction = ParameterDirection.Output;
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@是否重复扫描", IsScaningMulti);
            thisParms[6].Direction = ParameterDirection.Output;
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@是否多箱消耗", IsMultiPC);
            thisParms[7].Direction = ParameterDirection.Output;

            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                MaterialIsExsit = Convert.ToBoolean(thisParms[2].Value);
                BarCodeIsExsit = Convert.ToBoolean(thisParms[3].Value);
                IsBillOk = Convert.ToBoolean(thisParms[4].Value);
                IsCanUpdateBetch = Convert.ToBoolean(thisParms[5].Value);
                IsScaningMulti = Convert.ToBoolean(thisParms[6].Value);
                IsMultiPC = Convert.ToBoolean(thisParms[7].Value);
                return true;
            }
            return false;
        }

        /// <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="opName"></param>
        /// <param name="barCode"></param>
        /// <param name="IsSuccess"></param>
        /// <returns></returns>
        public static bool BusPartLine_Check(string PartCode, string OpName, string orderForm, out bool IsSuccess)
        {
            IsSuccess = false;
            string produceName = "北汽福田_总分线对应表_验证";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@分线总成号", PartCode);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位号", OpName);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@Count", IsSuccess);
            thisParms[3].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                IsSuccess = Convert.ToBoolean(thisParms[3].Value);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 北汽福田_总分线对应表_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="barCode"></param>
        /// <param name="IsSuccess"></param>
        /// <returns></returns>
        public static void BusPartLine_Add(string BusCode, string PartCode, string opName, string orderForm, string EngineID)
        {
            string produceName = "北汽福田_总分线对应表_增加";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@主线总成号", BusCode);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@分线总成号", PartCode);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@机型号", EngineID);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// AMES_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>
        /// 北汽福田工位BOM换型比对
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineType">新零件号(机型)</param>
        /// <returns></returns>
        public static DataTable EngineTypeChange(string opName, string engineType)
        {
            DataTable dt = new DataTable();
            string produceName = "北汽福田工位BOM换型比对";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@新零件号", engineType);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }

        /// <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>
        /// 北汽福田_TCU_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="nameplate"></param>
        /// <param name="assemblyCode"></param>
        /// <param name="EngineTypeID"></param>
        /// <returns></returns>
        public static DataTable TCU_Add(string opName, string nameplate, string EngineID, string EngineTypeID)
        {
            DataTable dt = new DataTable();
            string produceName = "北汽福田_TCU_增加";
            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("@物料码", nameplate);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@机型代码", EngineTypeID);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
            return dt;
        }
        //
        /// <summary>
        /// MES_装配数据_零部件追溯_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static bool Material_Insert(string opName)
        {
            string produceName = "MES_装配数据_零部件追溯_增加";
            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_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)
        {
            workGroupIndex = 0;
            BoltCode = "";
            sn_WorkingStepIsOver = true;

            string produceName = "电子看板_工位机型_质量数据测量位置_临时表_查询_完成情况";
            SqlParameter[] thisParms = new SqlParameter[4];
            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;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms))
            {
                workGroupIndex = Convert.ToInt32(thisParms[1].Value);
                BoltCode = thisParms[2].Value.ToString();
                sn_WorkingStepIsOver = 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>
        /// 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>
        /// 生产计划_派工订单_工件追溯_校验
        /// </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>
        /// 生产计划_派工订单_工件追溯_工位完工
        /// </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 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);
        }

    }
}
