using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebAPI.Models;
namespace WebAPI.Service
{
    public class LuBaoSevice
    {
        /// 
        /// 工序汇报扫码方法 
        /// 
        public static ApiResult GetHbarCodeDetail(string sBillBarCode)
        {
            if (string.IsNullOrEmpty(sBillBarCode))
                return new ApiResult { code = -1, msg = "条码不能为空" };
            sBillBarCode = sBillBarCode.CompareTo("#") > 0 ? sBillBarCode.Split(Convert.ToChar("#"))[0] : sBillBarCode;
            var dataSet = GetBarCodeDb(sBillBarCode);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "不存在派工单号" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet GetBarCodeDb(string billBarCode)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Sc_ProcessSendWorkList  where HBillType='3712' and  单据号= '" + billBarCode + "'", "h_v_Sc_ProcessSendWorkList");
            return dataSet;
        }
        /// 
        /// 委外工序汇报扫码方法 
        /// 
        public static ApiResult WWGetHbarCodeDetail(string sBillBarCode)
        {
            if (string.IsNullOrEmpty(sBillBarCode))
                return new ApiResult { code = -1, msg = "条码不能为空" };
            sBillBarCode = sBillBarCode.CompareTo("#") > 0 ? sBillBarCode.Split(Convert.ToChar("#"))[0] : sBillBarCode;
            var dataSet = WWGetBarCodeDb(sBillBarCode);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "不存在委外派工单号" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet WWGetBarCodeDb(string billBarCode)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_WW_EntrustProcSendWorkBillList  where HBillType='3740' and 单据号= '" + billBarCode + "'", "h_v_WW_EntrustProcSendWorkBillList");
            return dataSet;
        }
        /// 
        /// PDA汇报单回车方法 
        /// 
        public static ApiResult GetProcDetail(string sBillNo, string sProcNo)
        {
            if (string.IsNullOrEmpty(sBillNo) || string.IsNullOrEmpty(sProcNo))
                return new ApiResult { code = -1, msg = "条码和流转卡不能为空" };
            var dataSet = GetProcDb(sBillNo, sProcNo);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "流水号或流转卡号为空" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet GetProcDb(string sBillNo, string sProcNo)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Sc_ProcessSendWorkList  where HBillType='3712' and  单据号= '" + sBillNo + "' and HprocID='" + sProcNo + "'", "h_v_Sc_ProcessSendWorkList");
            return dataSet;
        }
        /// 
        /// PDA委外汇报单回车方法 
        /// 
        public static ApiResult WWGetProcDetail(string sBillNo, string sProcNo)
        {
            if (string.IsNullOrEmpty(sBillNo) || string.IsNullOrEmpty(sProcNo))
                return new ApiResult { code = -1, msg = "条码和流转卡不能为空" };
            var dataSet = WWGetProcDb(sBillNo, sProcNo);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "流水号或流转卡号为空" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet WWGetProcDb(string sBillNo, string sProcNo)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_WW_EntrustProcSendWorkBillList  where HBillType='3740' and  单据号= '" + sBillNo + "' and HprocID='" + sProcNo + "'", "h_v_WW_EntrustProcSendWorkBillList");
            return dataSet;
        }
        /// 
        /// 检验方案根据id获取信息
        /// 
        public static ApiResult GetCheckProjectDetail(string HID)
        {
            if (string.IsNullOrEmpty(HID))
                return new ApiResult { code = -1, msg = "ID不能为空" };
            var dataSet = GetProjectDb(HID);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "不存在检验单号" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet GetProjectDb(string HID)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Gy_Edit_QCCheckProjectList  where hmainid= " + HID +" ", "h_v_Gy_Edit_QCCheckProjectList");
            return dataSet;
        }
        /// 
        /// 来料检验根据id获取信息
        /// 
        public static ApiResult GetPOStockInCheckBillDetail(string HID)
        {
            if (string.IsNullOrEmpty(HID))
                return new ApiResult { code = -1, msg = "ID不能为空" };
            var dataSet = GetPOStockInDb(HID);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "不存在来料检验单号" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet GetPOStockInDb(string HID)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_QC_Edit_POStockInCheckBillList  where hmainid= " + HID + " ", "h_v_QC_Edit_POStockInCheckBillList");
            return dataSet;
        }
        /// 
        /// 首料检验根据id获取信息
        /// 
        public static ApiResult GetQC_FirstPieceCheckBillDetail(string HID)
        {
            if (string.IsNullOrEmpty(HID))
                return new ApiResult { code = -1, msg = "ID不能为空" };
            var dataSet = GetFirstPieceCheckDb(HID);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "不存在首料检验单号" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet GetFirstPieceCheckDb(string HID)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_QC_Edit_FirstPieceCheckBillList  where hmainid= " + HID + " ", "h_v_QC_Edit_FirstPieceCheckBillList");
            return dataSet;
        }
        /// 
        /// 巡检单根据id获取信息
        /// 
        public static ApiResult GetQC_PatrolProcCheckBillDetail(string HID)
        {
            if (string.IsNullOrEmpty(HID))
                return new ApiResult { code = -1, msg = "ID不能为空" };
            var dataSet = GetPatrolProcCheckDb(HID);
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "不存在巡检单号" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        public static DataSet GetPatrolProcCheckDb(string HID)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_QC_Edit_PatrolProcCheckBillList  where hmainid= " + HID + " ", "h_v_QC_Edit_PatrolProcCheckBillList");
            return dataSet;
        }
    }
}