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 partial class BaseDataSystemMES
    {
        //[北汽福田变速器序列号总线上线_是否重号]
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        public static bool EngineTypeID_IsNotRepeatedNumber(string sn, string OpName)
        {
            DataTable dt = new DataTable();
            int count;


            string produceName = "北汽福田变速器序列号总线上线_是否重号";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@变速器序列号", sn);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位号", OpName);

            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    count = Convert.ToInt32(dt.Rows[0]["数量"]);
                    if (count == 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;

                    }
                }
            }
            return true;

        }



        //北汽福田_配方内容_根据配方号查询
        public static bool PLCRcipeByOpName(string OpName, out byte[] bytes, out string tagStartAdr, int PLCRcipe)
        {
            DataTable dt = new DataTable();
            string produceName = "北汽福田_配方内容_根据配方号查询";
            tagStartAdr = "";
            bytes = new byte[0];
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@配方号", PLCRcipe);


            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, dt))
            {
                if (dt.Rows.Count > 0)
                {
                    tagStartAdr = dt.Rows[0]["地址"].ToString();
                    bytes = new byte[dt.Rows.Count];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        bytes[i] = Convert.ToByte(dt.Rows[0]["操作号码"]);
                    }
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 北汽福田_配方当前_查询
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static bool PLCRcipeCurrent(string opName, out byte[] bytes, out string tagStartAdr)
        {
            DataTable dt = new DataTable();
            string produceName = "北汽福田_配方当前_查询";
            tagStartAdr = "";
            bytes = null;
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            if (DataAccess.ExecuteStoredProcedure(produceName, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    tagStartAdr = dt.Rows[0]["地址"].ToString();
                    bytes = new byte[dt.Rows.Count];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        bytes[i] = Convert.ToByte(dt.Rows[0]["操作号码"]);
                    }
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 北汽福田BOM_上线需要数据_查询
        /// </summary>
        /// <param name="sn">零件号</param>
        /// <param name="PTO">PTO检测</param>
        /// <param name="NgearSwitch">空挡开关检测</param>
        /// <param name="RgearSwitch">倒挡开关检测</param>
        /// <param name="SpeedSensor">里程表检测</param>
        /// <param name="PartTypeMid">大机型扩展</param>
        /// <returns></returns>
        public static bool UpLoadPTO(string sn, out int PTO, out int NgearSwitch, out int RgearSwitch, out int SpeedSensor, out string PartTypeMid)
        {
            DataTable dt = new DataTable();
            int count;
            PTO = 0;
            NgearSwitch = 0;
            RgearSwitch = 0;
            SpeedSensor = 0;
            PartTypeMid = "";
            //select @倒挡开关 as RgearSwitch,@空挡开关 as NgearSwitch,@里程表 as SpeedSensor,@型号 as PartTypeMid,@PTO as PTO
            //
            string produceName = "北汽福田BOM_上线需要数据_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@零件号", sn);

            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    PTO = Convert.ToInt32(dt.Rows[0]["PTO"]);
                    NgearSwitch = Convert.ToInt32(dt.Rows[0]["NgearSwitch"]);
                    RgearSwitch = Convert.ToInt32(dt.Rows[0]["RgearSwitch"]);
                    SpeedSensor = Convert.ToInt32(dt.Rows[0]["SpeedSensor"]);
                    PartTypeMid = dt.Rows[0]["PartTypeMid"].ToString();
                    return true;
                }
            }
            return false;

        }
        /// <summary>
        /// 北汽福田变速器序列号总线上线_获得机型信息
        /// </summary>
        /// <param name="partSn"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineID"></param>
        /// <param name="OrderForm"></param>
        /// <param name="Recipe1"></param>
        /// <param name="Recipe2"></param>
        /// <returns></returns>
        public static bool GetEngineTypeUpLoadOpName(string sn, string partNo, string OpName, string orderNo, string batchNo, out int IsTodayPlan)
        {
            DataTable dt = new DataTable();
            IsTodayPlan = 0;

            string produceName = "北汽福田变速器序列号总线上线_获得机型信息";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@变速箱总成号", sn);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@零件号", partNo);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@工位号", OpName);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@订单号", orderNo);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@批次号", batchNo);

            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    IsTodayPlan = Convert.ToInt32(dt.Rows[0]["存在订单"]);
                    return true;
                }
            }
            return false;
        }
        //MES_计划BOM_工位与名称_查询_MQTT监控工位

        public static DataTable GetCheckOpName_BQ()
        {
            DataTable dt = new DataTable();
            string produceName = "MES_计划BOM_工位与名称_查询_MQTT监控工位";
            SqlParameter[] thisParms = null;


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

            return dt;
        }
        public static DataTable GetCheckOpName()
        {
            DataTable dt = new DataTable();
            string produceName = "MES_计划BOM_工位与名称_查询";
            SqlParameter[] thisParms = null;


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

            return dt;
        }
        /// <summary>
        /// 测量数据工位_监控系统_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 DataTable GetOrder_BQ()
        {
            DataTable dt = new DataTable();
            string produceName = "北汽福田生产订单计划_查询";
            SqlParameter[] thisParms = null;


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

            return dt;
        }

        public static DataTable GetOrderOpName_BQ()
        {
            DataTable dt = new DataTable();
            string produceName = "MES_计划BOM_工位与名称_上线工位号查询";
            SqlParameter[] thisParms = null;


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

            return dt;
        }
        /// <summary>
        /// 北汽福田工位状态监控MOBY_增加_线首工位订单下达
        /// </summary>
        /// <param name="orderForm"></param>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static void DownOrderToOpName(string orderForm, string opName)
        {
            string produceName = "北汽福田工位状态监控MOBY_增加_线首工位订单下达";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new SqlParameter("@订单号", orderForm);
            thisParms[1] = new SqlParameter("@工位号", opName);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);

        }

        public static DataTable DownOrderToOpNameMobyList(string OpName)
        {
            DataTable dt = new DataTable();
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new SqlParameter("@工位号", OpName);
            string produceName = "北汽福田工位状态监控MOBY_查询_订单下达用";
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);

            return dt;
        }

        /// <summary>
        /// 北汽福田工位状态监控MOBY历史数据_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static void MobySaveData(string opName)
        {
            string produceName = "北汽福田工位状态监控MOBY历史数据_增加";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new SqlParameter("@工位号", opName);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);

        }


        public static string GetOrderDataBySn(string sn)
        {

            DataTable dt = new DataTable();
            string orderForm = "";
            string produceName = "北汽福田变速器序列号_查询订单号";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@变速器序列号", sn);
            if (DataAccess.ExecuteStoredProcedure(produceName, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    orderForm = dt.Rows[0]["订单号"].ToString();
                }
            }
            return orderForm;
        }

    }
}

