2021-01-13 14:02:33 +08:00
using Dapper ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
namespace NX.ERP.U8.Sale
{
public class DispatchListDAL
{
public IEnumerable < Model . Sale . DispatchList > GetList ( string strWhere = "" , object Params = null )
{
2021-01-21 16:20:31 +08:00
var strSql = @ "select a.DLID as SalesOrderId ,a.dDate as SalesOrderDate,a.cDLCode as SalesOrderNo ,A.cCusCode AS CustomerCode,b.DLID as id,b.AutoID as SalesOrderDtlId,b.DLID as SalesOrderId ,b.cInvCode as MaterialCode ,b.cInvName as InvName,b.iQuantity AS Qty
2021-01-13 14:02:33 +08:00
from DispatchList as a
2021-01-28 15:37:47 +08:00
left join DispatchLists as b on a . DLID = b . DLID where ISNULL ( a . cverifier , ' ' ) < > ' ' ";
2021-01-13 14:02:33 +08:00
2021-01-15 09:26:17 +08:00
if ( ! string . IsNullOrEmpty ( strWhere ) )
{
2021-01-28 15:37:47 +08:00
strSql + = $" and {strWhere} " ;
2021-01-15 09:26:17 +08:00
}
2021-01-25 09:47:41 +08:00
using ( var conn = U8LoginContext . Instance . Connection )
2021-01-13 14:02:33 +08:00
{
var lookup = new Dictionary < int , Model . Sale . DispatchList > ( ) ;
// return conn.Query<Model.Purchase.Arrival>(strSQL,null);
var list = conn . Query < NX . ERP . Model . Sale . DispatchList , NX . ERP . Model . Sale . DispatchListDetail , NX . ERP . Model . Sale . DispatchList > ( strSql , ( Dispatch , DispatchDetail ) = >
{
2021-01-21 16:20:31 +08:00
if ( ! lookup . TryGetValue ( Dispatch . SalesOrderId , out var _Dispatch ) )
2021-01-13 14:02:33 +08:00
{
2021-01-21 16:20:31 +08:00
lookup . Add ( Dispatch . SalesOrderId , Dispatch ) ;
2021-01-13 14:02:33 +08:00
}
else
{
Dispatch = _Dispatch ;
}
2021-01-21 16:20:31 +08:00
Dispatch . SalesOrderDtlLst . Add ( DispatchDetail ) ;
2021-01-13 14:02:33 +08:00
return Dispatch ;
} , Params , null , true , "id" , 10 , System . Data . CommandType . Text ) ;
return lookup . Values ;
}
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Model . Sale . DispatchList GetModel ( int id )
{
2021-01-15 09:26:17 +08:00
return this . GetList ( " a.DLID=@id" , new { id } ) . FirstOrDefault ( ) ;
2021-01-13 14:02:33 +08:00
}
2021-01-21 16:20:31 +08:00
public IEnumerable < Model . Sale . DispatchList > GetList ( Model . Request . Dispatch dispatch )
{
string where = "" ;
if ( ! string . IsNullOrEmpty ( dispatch . SalesOrderNo ) )
{
where = "a.cDLCode like @SalesOrderNo" ;
}
return this . GetList ( where , new { SalesOrderNo = $"%{dispatch.SalesOrderNo}%" } ) ;
}
2021-01-13 14:02:33 +08:00
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
2021-01-15 09:26:17 +08:00
public Model . Sale . DispatchList GetModel ( string Code )
2021-01-13 14:02:33 +08:00
{
2021-01-15 09:26:17 +08:00
return this . GetList ( " a.cDLCode=@Code" , new { Code } ) . FirstOrDefault ( ) ;
2021-01-13 14:02:33 +08:00
}
/// <summary>
///
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
public IEnumerable < Model . Sale . DispatchList > GetListByLastID ( int ID )
{
return this . GetList ( " a.DLID>=@ID " , new { ID } ) ;
}
}
}