@ -2,6 +2,7 @@
using System.Collections ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.Entity.Infrastructure ;
using System.Data.Entity.Migrations ;
using System.Linq ;
using System.Text ;
@ -516,5 +517,152 @@ namespace CK.SCP.Controller
}
return _d s ;
}
/// <summary>
/// 到货单按条件导出excel
/// </summary>
/// <param name="p_lst"></param>
/// <param name="p_vendid"></param>
/// <param name="site"></param>
/// <returns></returns>
public static DataSet GET_ARRIVE_EXECELBycondition ( V_TB_ARRIVE enty )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
string sql = "SELECT * FROM V_TB_ARRIVE where IsDeleted = '0'" ;
string sql1 = "select a.* from V_TB_ARRIVE_DETAIL as a left join V_TB_ARRIVE as b on a.ArrvBillNum = b.ArrvBillNum and a.VendId = b.VendId and a.SubSite = b.SubSite where b.IsDeleted = '0'" ;
if ( enty . BeginTime ! = null )
{
sql + = " and ShipTime >= " + "'" + enty . BeginTime + "'" ;
sql1 + = " and b.ShipTime >= " + "'" + enty . BeginTime + "'" ;
}
if ( enty . EndTime ! = null )
{
sql + = " and ShipTime <= " + "'" + enty . EndTime + "'" ;
sql1 + = " and b.ShipTime <= " + "'" + enty . EndTime + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . ArrvBillNum ) )
{
sql + = " and ArrvBillNum = " + "'" + enty . ArrvBillNum + "'" ;
sql1 + = " and b.ArrvBillNum = " + "'" + enty . ArrvBillNum + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . PoBillNum ) )
{
sql + = " and PoBillNum = " + "'" + enty . PoBillNum + "'" ;
sql1 + = " and b.PoBillNum = " + "'" + enty . PoBillNum + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . AsnBillNum ) )
{
sql + = " and AsnBillNum = " + "'" + enty . AsnBillNum + "'" ;
sql1 + = " and b.AsnBillNum = " + "'" + enty . AsnBillNum + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . AskBillNum ) )
{
sql + = " and AskBillNum = " + "'" + enty . AskBillNum + "'" ;
sql1 + = " and b.AskBillNum = " + "'" + enty . AskBillNum + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . Site ) )
{
sql + = " and Site = " + "'" + enty . Site + "'" ;
sql1 + = " and b.Site = " + "'" + enty . Site + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . SubSite ) )
{
sql + = " and SubSite = " + "'" + enty . SubSite + "'" ;
sql1 + = " and b.SubSite = " + "'" + enty . SubSite + "'" ;
}
else if ( enty . UserInSubSite ! = null & & enty . UserInSubSite . Count > 0 )
{
string UserInSubSite = String . Join ( "," , enty . UserInSubSite ) ;
UserInSubSite = $"'{UserInSubSite.Replace(" , ", " ' , ' ")}'" ;
sql + = " and SubSite in " + "(" + UserInSubSite + ")" ;
sql1 + = " and b.SubSite in " + "(" + UserInSubSite + ")" ;
}
if ( ! string . IsNullOrEmpty ( enty . VendId ) )
{
sql + = " and VendId = " + "'" + enty . VendId + "'" ;
sql1 + = " and b.VendId = " + "'" + enty . VendId + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . BillType_DESC ) )
{
sql + = " and BillType_DESC = " + "'" + enty . BillType_DESC + "'" ;
sql1 + = " and b.BillType_DESC = " + "'" + enty . BillType_DESC + "'" ;
}
if ( ! string . IsNullOrEmpty ( enty . Remark ) )
{
sql + = " and Remark like " + "'%" + enty . Remark + "%'" ;
sql1 + = " and b.Remark like " + "'%" + enty . Remark + "%'" ;
}
if ( ! string . IsNullOrEmpty ( enty . CreateUser ) )
{
sql + = " and CreateUser like " + "'%" + enty . CreateUser + "%'" ;
sql1 + = " and b.CreateUser like " + "'%" + enty . CreateUser + "%'" ;
}
if ( ! string . IsNullOrEmpty ( enty . VendName ) )
{
sql + = " and VendName like " + "'%" + enty . VendName + "%'" ;
sql1 + = " and b.VendName like " + "'%" + enty . VendName + "%'" ;
}
if ( ! string . IsNullOrEmpty ( enty . OperName ) )
{
sql + = " and OperName like " + "'%" + enty . OperName + "%'" ;
sql1 + = " and b.OperName like " + "'%" + enty . OperName + "%'" ;
}
if ( ! string . IsNullOrEmpty ( enty . Site_Desc ) )
{
sql + = " and Site_Desc like " + "'%" + enty . Site_Desc + "%'" ;
sql1 + = " and b.Site_Desc like " + "'%" + enty . Site_Desc + "%'" ;
}
if ( enty . UserInVendIds ! = null & & enty . UserInVendIds . Count > 0 )
{
string UserInVendIds = String . Join ( "," , enty . UserInVendIds ) ;
UserInVendIds = $"'{UserInVendIds.Replace(" , ", " ' , ' ")}'" ;
sql + = " and VendId in " + "(" + UserInVendIds + ")" ;
sql1 + = " and b.VendId in " + "(" + UserInVendIds + ")" ;
}
DbRawSqlQuery < V_TB_ARRIVE > result = db . Database . SqlQuery < V_TB_ARRIVE > ( sql ) ;
DbRawSqlQuery < V_TB_ARRIVE_DETAIL > result1 = db . Database . SqlQuery < V_TB_ARRIVE_DETAIL > ( sql1 ) ;
List < V_TB_ARRIVE > _l s = result . ToList ( ) ;
List < V_TB_ARRIVE_DETAIL > _d etailList = result1 . ToList ( ) ;
var _ exportList = new List < SCP_ARRIVE_EXPORT > ( ) ;
_l s . ForEach ( itm = >
{
var _ entity = new SCP_ARRIVE_EXPORT ( ) ;
_ entity . 状 态 = itm . State_DESC ;
_ entity . 单 据 类 型 = itm . BillType_DESC ;
_ entity . 到 货 单 号 = itm . ArrvBillNum ;
_ entity . 发 货 单 号 = itm . AsnBillNum ;
_ entity . 要 货 看 板 号 = itm . AskBillNum ;
_ entity . 订 单 号 = itm . PoBillNum ;
_ entity . 供 应 商 = itm . VendName ;
_ entity . 供 应 商 编 码 = itm . VendId ;
_ entity . 地 点 = itm . SubSite ;
_ entity . 地 点 名 称 = itm . Site_Desc ;
_ entity . 到 货 日 期 = itm . ShipTime = = null ? string . Empty : itm . ShipTime . ToString ( "yyyyMMdd" ) ;
_ exportList . Add ( _ entity ) ;
} ) ;
var _d t = ConvertHelper . ToDataTable ( _ exportList ) ;
_d s . Tables . Add ( _d t ) ;
var _ exportDetailList = new List < SCP_ARRIVE_DETAIL_EXPORT > ( ) ;
_d etailList . ForEach ( itm = > {
var _ entity = new SCP_ARRIVE_DETAIL_EXPORT ( ) ;
_ entity . 单 据 号 = itm . ArrvBillNum ;
_ entity . 发 货 单 号 = itm . AsnBillNum ;
_ entity . 订 单 号 = itm . PoBillNum ;
_ entity . 订 单 行 = itm . PoLine . ToString ( ) ;
_ entity . 零 件 号 = itm . PartCode ;
_ entity . 零 件 名 称 = itm . PartDesc1 ;
_ entity . 单 位 = itm . Unit ;
_ entity . 数 量 = itm . Qty . ToString ( ) ;
_ entity . 时 间 = itm . ShipTime = = null ? string . Empty : itm . ShipTime . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 备 注 = itm . Remark ;
_ exportDetailList . Add ( _ entity ) ;
} ) ;
var _l ist_dt = ConvertHelper . ToDataTable ( _ exportDetailList ) ;
_d s . Tables . Add ( _l ist_dt ) ;
}
return _d s ;
}
}
}