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

namespace MesServerFunctions
{
    public class Db
    {
        /// <summary>
        /// 合力_OP050前停判断_下工位是否需要工作
        /// </summary>
        /// <param name="EngineID"></param>
        /// <param name="opName"></param>
        /// <param name="orderForm"></param>
        /// <param name="MatchResult"></param>
        /// <param name="resultMsg"></param>
        /// <returns></returns>
        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);
        }
        public static bool OPA90_TO_OP50_CheckTwoFinish(out int MainLineAllowWork)
        {
            DataTable dt;
            MainLineAllowWork = 2;
            string produceName = "合力_OP050是否允许工作_判断";
            SqlParameter[] thisParms = new SqlParameter[0];
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    MainLineAllowWork = Convert.ToInt32(dt.Rows[0]["是否允许工作"]);
                    return true;
                }
            }
            return false;
        }
    }
}
