Files
U8-Import/NX.ERP.U8/Purchase/ArrivalDAL.cs

80 lines
3.2 KiB
C#
Raw Normal View History

2021-01-05 16:49:51 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dapper;
namespace NX.ERP.U8.Purchase
{
public class ArrivalDAL
{
2021-01-07 14:06:26 +08:00
public IEnumerable<Model.Purchase.Arrival> GetList(string strWhere = "", object param = null)
2021-01-05 16:49:51 +08:00
{
using (var conn = new System.Data.SqlClient.SqlConnection(U8LoginContext.Instance.Constr4Net))
{
2021-01-21 16:00:58 +08:00
string strSQL = @"select a.id AS ArrivalId,a.cCode as ArrivalCode,A.cbustype AS busType,a.cptcode as PTCode,a.iTaxRate as TaxRate,a.iexchrate as Exchrate,cexch_name as ExchName,cVenCode as VenCode,a.dDate as ArrivalDate,A.cVenCode AS SupplierCode,
2021-01-07 14:06:26 +08:00
B.Autoid as id,b.ID as ArrivalID,
b.cInvCode AS MaterielCode,
b.cBatch AS BatchNo,
2021-01-09 16:36:17 +08:00
b.cUnitID AS UnitCode,b.ioricost as oricost,b.ioritaxcost as oritaxcost ,b.icost as cost,b.iorimoney as orimoney,b.ioritaxprice as oritaxprice,b.iorisum as orisum,
2021-01-07 14:06:26 +08:00
B.iQuantity as Quantity,b.iposid as PosId ,B.CORDERCODE as OrderCode,C.POID as Poid from
pu_ArrHead as a
left join pu_arrbody as b on a.id=b.id
2021-01-21 16:00:58 +08:00
Left Join PO_Podetails C WITH (NOLOCK) ON B.iPOsID = C.ID ";
2021-01-07 14:06:26 +08:00
if (!string.IsNullOrEmpty(strWhere))
{
strSQL += $" where {strWhere} ";
}
2021-01-05 16:49:51 +08:00
var lookup = new Dictionary<int, Model.Purchase.Arrival>();
// return conn.Query<Model.Purchase.Arrival>(strSQL,null);
var list = conn.Query<Model.Purchase.Arrival, Model.Purchase.ArrivalDetail, Model.Purchase.Arrival>(strSQL, (arrival, ArrivalDetail) =>
{
2021-01-21 16:00:58 +08:00
if (!lookup.TryGetValue(arrival.ArrivalId, out var _arrival))
2021-01-05 16:49:51 +08:00
{
2021-01-21 16:00:58 +08:00
lookup.Add(arrival.ArrivalId, arrival);
2021-01-07 14:06:26 +08:00
}
else
2021-01-05 16:49:51 +08:00
{
arrival = _arrival;
}
2021-01-21 16:00:58 +08:00
arrival.ArrivalDtlLst.Add(ArrivalDetail);
2021-01-05 16:49:51 +08:00
return arrival;
2021-01-07 14:06:26 +08:00
}, param, null, true, "id", 10, System.Data.CommandType.Text);
2021-01-05 16:49:51 +08:00
return lookup.Values;
}
}
2021-01-07 14:06:26 +08:00
public Model.Purchase.Arrival GetModel(int id)
{
return this.GetList(" a.id=@Id ", new { id }).FirstOrDefault();
}
2021-01-21 16:00:58 +08:00
public IEnumerable<Model.Purchase.Arrival> Query(NX.ERP.Model.Request.Arrival arrival)
{
var where = "";
if (!string.IsNullOrEmpty(arrival.ArrivalNo))
{
where = " a.cCode like @Code ";
}
return this.GetList(where, new { Code = $"%{arrival.ArrivalNo}%" });
}
2021-01-07 14:06:26 +08:00
2021-01-13 10:21:56 +08:00
public IEnumerable<Model.Purchase.Arrival> GetListByLastId(int Id)
{
return this.GetList(" a.id>=@Id ", new { Id });
}
2021-01-07 14:06:26 +08:00
public Model.Purchase.Arrival GetModel(string Code)
{
return this.GetList(" a.cCode=@Code ", new { Code }).FirstOrDefault();
}
2021-01-05 16:49:51 +08:00
}
}