using DataLinkMesWork;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bizFacade
{
    public partial class BaseDataSystemMES
    {
        /// <summary>
        /// 测量数据工位_监控系统_自动手动_查询
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static DataTable OpName_MIS_AutoOrMaunal_Select(string opName)
        {
            DataTable dt = null;
            string sql;
            sql = "SELECT top 1 自动手动 from 测量数据工位_监控系统_自动手动 where 工位号='" + opName + "' ";
            DataAccess.ExecuteDataTable(sql, out dt);
            return dt;
        }
        /// <summary>
        /// 订单下达到线首工位
        /// 北汽福田工位状态监控MOBY_增加_线首工位订单下达
        /// </summary>
        /// <param name="opName"></param>
        /// <returns></returns>
        public static void OrderWorkStartToOpName(string opName,string orderForm)
        {
            string procedureName = "北汽福田工位状态监控MOBY_增加_线首工位订单下达";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);

            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }

        /// <summary>
        /// 电子看板_发动机号_线首工位_流水号_修改
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineID"></param>
        /// <returns></returns>
        static public bool FirstOpName_Code_Update(string opName, string engineID, string partcode)
        {
            string 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("@托盘号", partcode);
            if (DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 测量数据工位_监控系统_自动手动_增加
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="isAutoOrManul"></param>
        /// <returns></returns>
        public static bool OpName_MIS_AutoOrMaunal_Insert(string opName, int isAutoOrManul)
        {
            string produceName = "测量数据工位_监控系统_自动手动_增加";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@自动手动", isAutoOrManul);
            return DataAccess.ExecuteStoredProcedure(produceName, 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="dt"></param>
        /// <returns></returns>
        public static bool OpName_MIS_MaualPrint_Select(string opName, out DataTable dt)
        {
            string sql;
            sql = "SELECT top 1 * FROM [测量数据工位_监控系统_手动打印] "
                + "where  工位号='" + opName + "'";
            return DataAccess.ExecuteDataTable(sql, out 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 bool OpName_MIS_CreateMoby_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>
        /// 电子看板_工位机型_质量数据测量位置_临时表_查询_完成情况
        /// </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)
        {
            BoltCode = 0;
            ProcessCode = 512;
            workStepProperty = 0;
            sn_WorkingStepIsOver = true;

            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.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;
            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);
                return true;
            }
            return false;
        }


    }
}
