using System; using System.Collections.Generic; using System.Linq; using System.Text; using Dapper; namespace NX.ERP.U8.Mom { public class MomOrderDAL { public IEnumerable GetList(string strWhere = "", object param = null) { using (var conn = new System.Data.SqlClient.SqlConnection(U8LoginContext.Instance.Constr4Net)) { string strSQL = @"select a.MoId as id,a.moCode as Code,a.*,b.MoDId as id ,b.*,c.AllocateId as id ,c.* from mom_order as a left join mom_orderdetail as b on a.MoId=b.MoId left join mom_moallocate as c on b.MoDId=c.MoDId "; if (!string.IsNullOrEmpty(strWhere)) { strSQL += $" where {strWhere} "; } var lookupDetail = new Dictionary(); var lookupOrder = new Dictionary(); // return conn.Query(strSQL,null); var list = conn.Query(strSQL, (Order, OrderDetail, MoAllocate) => { if (!lookupOrder.TryGetValue(Order.Id, out var _order)) { lookupOrder.Add(Order.Id, Order); } else { Order = _order; } if (!lookupDetail.TryGetValue(OrderDetail.Id, out var momDetail)) { lookupDetail.Add(OrderDetail.Id, OrderDetail); Order.Details.Add(OrderDetail); } else { OrderDetail = momDetail; } Order.Allocates.Add(MoAllocate); OrderDetail.moAllocates.Add(MoAllocate); return Order; }, param, null, true, "id", 10, System.Data.CommandType.Text); return lookupOrder.Values; } } public Model.MOM.MomOrder GetModel(string Code) { return this.GetList("a.moCode=@Code", new { Code }).FirstOrDefault(); } public IEnumerable GetListByLastID(int Id) { return this.GetList("a.moid >= @id", new { Id }); } } }