using MESClassLibrary.BLL.Log;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace MESClassLibrary.DAL.painting
{
    public class PunchNotStockBarCodeDal
    {
        public DataTable PunchNotStockBarCode(string time1, string time2)
        {
            DataTable res = null;

            try
            {
                string sql = @"if OBJECT_ID(N'tempdb..#a',N'U') is not null
                                    DROP TABLE #a
                                    CREATE TABLE #a(barcode nvarchar(50))
                                    INSERT INTO #a
                                            ( barcode )
                                    (SELECT DISTINCT barcode FROM dbo.tb_Punch_Code_Record p1
									WHERE  createTime BETWEEN  '" + time1 + @"' AND '" + time2 + @"' and barcode like '22%'
									UNION
									SELECT  DISTINCT barcode FROM dbo.tb_Punch_Code_Record_DoorSill_214 p2
									WHERE  createTime BETWEEN  '" + time1 + @"' AND '" + time2 + @"' and barcode like '22%')
                                    
                                    SELECT #a.barcode FROM #a LEFT OUTER JOIN dbo.tb_StockIn s ON #a.barcode=s.barcode where s.ID is null ";
                return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
            }
            catch (Exception ex)
            {
                LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
            }

            return res;
        }
    }
}