50 lines
2.0 KiB
C#
50 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Dapper;
|
|
namespace NX.ERP.U8.Mom
|
|
{
|
|
public class BomDAL
|
|
{
|
|
public IEnumerable<NX.ERP.Model.Response.MOM.Bom> GetList(string strWhere="", object Params = null)
|
|
{
|
|
var strSQL = @"select a.BomId,a.Version, a.VersionDesc,a.BomType,c.InvCode as ParentCode ,' ' as id ,d.BomId, d.SortSeq,
|
|
e.InvCode as ComponentCode ,d.BaseQtyN, d.BaseQtyD ,f.WIPType,d.EffBegDate,d.EffEndDate from bom_bom as a
|
|
left join bom_parent as b on a.BomId=b.BomId
|
|
left join bas_part as c on b.ParentId=c.PartId
|
|
left join Inventory as x on c.InvCode=x.cInvCode
|
|
left join bom_opcomponent as d on a.BomId=d.BomId
|
|
left join bom_opcomponentopt as f on d.OpComponentId=f.OptionsId
|
|
left join bas_part as e on d.ComponentId=e.PartId
|
|
left join Inventory as y on e.InvCode=y.cInvCode";
|
|
if (!string.IsNullOrEmpty(strWhere))
|
|
{
|
|
strSQL += $" where {strWhere} ";
|
|
}
|
|
using (var conn = U8LoginContext.Instance.Connection)
|
|
{
|
|
var lookup = new Dictionary<int, Model.Response.MOM.Bom>();
|
|
conn.Query<Model.Response.MOM.Bom, Model.Response.MOM.OptionComponent, Model.Response.MOM.Bom>(strSQL, (bom, comp) =>
|
|
{
|
|
if (!lookup.TryGetValue(bom.BomId, out var _bom))
|
|
{
|
|
lookup.Add(bom.BomId, bom);
|
|
|
|
}
|
|
else
|
|
{
|
|
bom = _bom;
|
|
}
|
|
bom.OptionComponents.Add(comp);
|
|
return bom;
|
|
}, Params, null, true, "id", 10, System.Data.CommandType.Text); ;
|
|
return lookup.Values;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|