using Dapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace NX.ERP.U8.Sale { public class DispatchListDAL { public IEnumerable GetList(string strWhere = "", object Params = null) { var strSql = @"select a.DLID as id ,a.cDLCode as Code ,A.cCusCode AS CusCode,b.AutoID as id ,b.cInvCode as InvCode ,b.cInvName as InvName,b.iQuantity AS Quantity from DispatchList as a left join DispatchLists as b on a.DLID = b.DLID"; if (!string.IsNullOrEmpty(strWhere)) { strSql += $" where {strWhere} "; } using (var conn = new System.Data.SqlClient.SqlConnection(U8LoginContext.Instance.Constr4Net)) { var lookup = new Dictionary(); // return conn.Query(strSQL,null); var list = conn.Query(strSql, (Dispatch, DispatchDetail) => { if (!lookup.TryGetValue(Dispatch.ID, out var _Dispatch)) { lookup.Add(Dispatch.ID, Dispatch); } else { Dispatch = _Dispatch; } Dispatch.Details.Add(DispatchDetail); return Dispatch; }, Params, null, true, "id", 10, System.Data.CommandType.Text); return lookup.Values; } } /// /// /// /// /// public Model.Sale.DispatchList GetModel(int id) { return this.GetList(" a.DLID=@id", new { id }).FirstOrDefault(); } /// /// /// /// /// public Model.Sale.DispatchList GetModel(string Code) { return this.GetList(" a.cDLCode=@Code", new { Code }).FirstOrDefault(); } /// /// /// /// /// public IEnumerable GetListByLastID(int ID) { return this.GetList(" a.DLID>=@ID ", new { ID }); } } }