using ICSSoft.ERPWMS.Entity; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ICSSoft.ERPWMS.SQL { public class GetInspectionInfo { public static Result Get(GetInspectionCondition condition) { Result res = new Result(); try { if (condition.PageIndex == null) { throw new Exception("页码未传!"); } if (condition.PageSize == null) { throw new Exception("每页数量未传!"); } if (string.IsNullOrWhiteSpace(condition.WorkPoint)) { res.IsSuccess = false; res.Message = "站点参数为空!"; return res; } string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint); if (WorkPoint == "NotExit") { throw new Exception("站点编码不存在!"); } string sql = @"Select distinct d.ID,a.AsnCode as '送货单号',a.Sequence as '送货单行号',b.DNCode as '到货单号', n.POCode as '采购订单',n.Sequence as '采购订单行号',a.Lotno as '条码',d.InvCode as '物料编码',d.Quantity as '数量', d.QualifiedQuantity as '合格数量',d.UnqualifiedQuantity as '不合格数量',d.WaiveQuantity as '特采数量',d.BRCODE AS '不良原因代码', d.MUSER as '操作人',d.MUSERName as '操作人名称',d.MTime as '操作时间',d.WorkPoint as '站点',d.type as '类型' from ICSASNDETAIL a inner join ICSDeliveryNotice b on a.AsnCode = b.AsnCode and a.WorkPoint = b.WorkPoint INNER JOIN ICSInventoryLot e ON a.LotNo=e.LotNo AND b.InvCode=e.InvCode AND a.WorkPoint=e.WorkPoint INNER JOIN ICSInventoryLotDetail m on e.LotNo=m.LotNo and e.WorkPoint=m.WorkPoint INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND b.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint inner join ICSInspection d on a.Lotno = d.Lotno and a.WorkPoint = d.WorkPoint where a.WorkPoint ='{0}' and d.type='1' and d.Enable ='1'"; string sql2 = @"Select distinct d.ID,a.AsnCode as '送货单号',a.Sequence as '送货单行号',b.ODNCode as '到货单号', n.OOCode as '采购订单',n.Sequence as '采购订单行号',a.Lotno as '条码',d.InvCode as '物料编码',d.Quantity as '数量', d.QualifiedQuantity as '合格数量',d.UnqualifiedQuantity as '不合格数量',d.WaiveQuantity as '特采数量',d.BRCODE AS '不良原因代码', d.MUSER as '操作人',d.MUSERName as '操作人名称',d.MTime as '操作时间',d.WorkPoint as '站点',d.type as '类型' from ICSASNDETAIL a inner join ICSODeliveryNotice b on a.AsnCode = b.OASNCode and a.WorkPoint = b.WorkPoint INNER JOIN ICSInventoryLot e ON a.LotNo=e.LotNo AND b.InvCode=e.InvCode AND a.WorkPoint=e.WorkPoint INNER JOIN ICSInventoryLotDetail m on e.LotNo=m.LotNo and e.WorkPoint=m.WorkPoint INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND b.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint inner join ICSInspection d on a.Lotno = d.Lotno and a.WorkPoint = d.WorkPoint where a.WorkPoint ='{0}' and d.type='3' and d.Enable ='1'"; sql = string.Format(sql, WorkPoint); sql2 = string.Format(sql2, WorkPoint); if (condition.dModifyDateFrom != null) { sql += " and d.Mtime >= '{0}'"; sql = string.Format(sql, condition.dModifyDateFrom); sql2 += " and d.Mtime >= '{0}'"; sql2 = string.Format(sql2, condition.dModifyDateFrom); } if (condition.dModifyDateTo != null) { sql += " and d.Mtime <= '{0}'"; sql = string.Format(sql, condition.dModifyDateTo); sql2 += " and d.Mtime <= '{0}'"; sql2 = string.Format(sql2, condition.dModifyDateTo); } if (condition.ASNCode != null) { sql += " and a.ASNCode like '%{0}%'"; sql = string.Format(sql, condition.ASNCode); sql2 += " and a.ASNCode like '%{0}%'"; sql2 = string.Format(sql2, condition.ASNCode); } sql = sql + " Union All " + sql2; string sqlNew = @" select * from (select aa.*,rn=ROW_NUMBER() over(order by ID) from( "; sqlNew += sql; sqlNew += ") aa)bb where bb.rn between {0} and {1} "; sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize); DataTable dt = ICSHelper.GetDataTable(sqlNew); List entityList = new List(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { GetInspectionEntity entity = new GetInspectionEntity(); entity.ID = dr["ID"].ToString(); entity.ASNCode = dr["送货单号"].ToString(); entity.ASNLine = string.IsNullOrWhiteSpace(dr["送货单行号"].ToString()) ? 1 : Convert.ToInt32(dr["送货单行号"].ToString()); entity.DNCode = dr["到货单号"].ToString(); entity.DNLine = 1; entity.PO = dr["采购订单"].ToString(); entity.POLine = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 1 : Convert.ToInt32(dr["采购订单行号"].ToString()); entity.LotNo = dr["条码"].ToString(); entity.InvCode = dr["物料编码"].ToString(); entity.Quantity = string.IsNullOrWhiteSpace(dr["数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["数量"].ToString()); entity.QualifiedQuantity = string.IsNullOrWhiteSpace(dr["合格数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["合格数量"].ToString()); entity.UnqualifiedQuantity = string.IsNullOrWhiteSpace(dr["不合格数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["不合格数量"].ToString()); entity.WaiveQuantity = string.IsNullOrWhiteSpace(dr["特采数量"].ToString()) ? 0.00m : Convert.ToDecimal(dr["特采数量"].ToString()); entity.ECSCode = dr["不良原因代码"].ToString(); entity.Type = dr["类型"].ToString(); entity.MUSER = dr["操作人"].ToString(); entity.MUSERName = dr["操作人名称"].ToString(); if (string.IsNullOrWhiteSpace(dr["操作时间"].ToString())) { entity.dModifyDate = null; } else { entity.dModifyDate = Convert.ToDateTime(dr["操作时间"].ToString()); } entity.WorkPoint = dr["站点"].ToString(); entityList.Add(entity); } res.IsSuccess = true; res.Message = "执行成功!"; res.data = entityList; return res; } else { res.IsSuccess = true; res.Message = "查询无数据!"; res.data = entityList; return res; } } catch (Exception ex) { res.IsSuccess = false; res.Message = ex.Message; return res; } } } }