using DeviceRepair.DataAccess.Data;
using DeviceRepair.Models;
using DeviceRepair.Models.SFC;
using NLog;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace DeviceRepair.DataAccess.SFC
{
    public class BatchDa : BaseDa
    {
        private static readonly Logger log = LogManager.GetCurrentClassLogger();
        
        public BatchDa(IDictionary<string, string> apiParams) : base(apiParams)
        {

        }

        /// <summary>
        /// 判断批次是否存在
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public APIResponseData GetBatchInfoToStaff(out bool BatchExists)
        {
            BatchExists = false;
            try
            {
                string Batch = base.GetParamString("Batch", "批次号");
                int Count = sfcData.Queryable<InspBatchInfo>().Count(x => x.Batch.ToUpper().Equals(Batch.ToUpper()));
                BatchExists = Count > 0;
                return new APIResponseData { Code = 1 };
            }
            catch (SqlException sqlEx)
            {
                throw sqlEx;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }
    }
}
