using System ;
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 ;
using System.Text.RegularExpressions ;
using System.Threading.Tasks ;
using CK.SCP.Models ;
using CK.SCP.Models.Enums ;
using CK.SCP.Models.ScpEntity ;
using CK.SCP.Models.ScpEntity.ExcelExportEnttity ;
using CK.SCP.Models.ScpEntity.ExcelImportEntity ;
using CK.SCP.Utils ;
namespace CK.SCP.Controller
{
public class SCP_EXCEL_CONTROLLER
{
public static DataSet GET_PO_EXECEL ( List < string > p_lst , bool p_IsDetail = false )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
if ( p_IsDetail = = false )
{
var _l s = db . V_TB_PO . Where ( p = > p_lst . Contains ( p . PoBillNum ) ) . ToList ( ) ;
var _ exportList = new List < SCP_PO_EXPORT > ( ) ;
_l s . ForEach ( itm = >
{
SCP_PO_EXPORT _ export = new SCP_PO_EXPORT ( ) ;
_ export . 状 态 = itm . State_DESC ;
_ export . 订 单 类 型 = itm . ModType_DESC ;
_ export . 订 单 编 号 = itm . PoBillNum ;
_ export . Erp订单编号 = itm . ErpBillNum ;
_ export . 供 应 商 编 码 = itm . VendId ;
_ export . 供 应 商 名 称 = itm . VendName ;
_ export . 订 货 日 期 = itm . BeginTime = = null ? string . Empty : ( ( DateTime ) itm . BeginTime ) . ToString ( "yyyyMMdd" ) ;
_ export . 收 货 地 点 = itm . Site ;
_ export . 收 货 人 = itm . Buyer ;
_ export . 收 货 人 电 话 = itm . BuyerPhone ;
_ export . 备 注 = itm . Remark ;
_ exportList . Add ( _ export ) ;
} ) ;
var _d t = ConvertHelper . ToDataTable ( _ exportList ) ;
_d s . Tables . Add ( _d t ) ;
}
var _d etailList = db . V_TB_PO_DETAIL . Where ( p = > p_lst . Contains ( p . PoBillNum ) ) . ToList ( ) ;
_d etailList = SCP_PO_CONTROLLER . LOAD_PO_DETAIL_SUM ( _d etailList ) ;
var _ exportDetailList = new List < SCP_PO_DETAIL_EXPORT > ( ) ;
_d etailList . ForEach ( itm = >
{
var po_detail = new SCP_PO_DETAIL_EXPORT ( ) ;
po_detail . 订 单 编 号 = itm . PoBillNum ;
po_detail . 供 应 商 编 码 = itm . VendId ;
po_detail . 供 应 商 名 称 = itm . VendName ;
po_detail . 状 态 = itm . State_DESC ;
po_detail . 行 号 = itm . PoLine . ToString ( ) ;
po_detail . 零 件 名 = itm . PartDesc1 ;
po_detail . 零 件 编 = itm . PartCode ;
po_detail . 订 单 数 = itm . PlanQty . ToString ( ) ;
po_detail . 已 要 数 = itm . TempQty = = null ? string . Empty : itm . TempQty . ToString ( ) ;
po_detail . 发 货 数 = itm . ShippedQty . ToString ( ) ;
po_detail . 收 货 数 = itm . ReceivedQty . ToString ( ) ;
po_detail . 退 货 数 = itm . RejectQty ;
po_detail . 到 货 日 期 = itm . EndTime = = null ? string . Empty : ( ( DateTime ) itm . BeginTime ) . ToString ( "yyyyMMdd" ) ; ;
po_detail . 单 位 = itm . PoUnit ;
_ exportDetailList . Add ( po_detail ) ;
} ) ;
var _l ist_dt = ConvertHelper . ToDataTable ( _ exportDetailList ) ;
_d s . Tables . Add ( _l ist_dt ) ;
}
return _d s ;
}
public static List < SCP_PO_DETAIL_EXPORT_MODEL > GET_PO_EXECEL_Model ( List < string > p_lst , bool p_IsDetail = false )
{
DataSet _d s = new DataSet ( ) ;
var _ exportDetailList = new List < SCP_PO_DETAIL_EXPORT_MODEL > ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _d etailList = db . V_TB_PO_DETAIL . Where ( p = > p_lst . Contains ( p . UID . ToString ( ) ) ) . ToList ( ) ;
var polist = _d etailList . Select ( p = > p . PoBillNum ) ;
var _ po = db . V_TB_PO . Where ( p = > polist . Contains ( p . PoBillNum ) ) . FirstOrDefault ( ) ;
_d etailList . ForEach ( itm = >
{
var po_detail = new SCP_PO_DETAIL_EXPORT_MODEL ( ) ;
po_detail . 订 单 编 号 = itm . PoBillNum ;
po_detail . 行 号 = itm . PoLine . ToString ( ) ;
po_detail . 零 件 名 = itm . PartDesc1 ;
if ( ! string . IsNullOrEmpty ( itm . PartDesc2 ) )
{
po_detail . 零 件 名 + = itm . PartDesc2 ;
}
po_detail . 零 件 编 码 = itm . PartCode ;
po_detail . 订 单 数 = "0" ;
po_detail . 供 应 商 = itm . VendName ;
po_detail . 供 应 商 编 码 = itm . VendId ;
po_detail . 订 货 日 期 = DateTime . Now . ToShortDateString ( ) ;
po_detail . 到 货 日 期 = DateTime . Now . ToShortDateString ( ) ;
po_detail . 单 位 = itm . PoUnit ;
po_detail . 域 名 = _ po . Site ;
po_detail . 地 点 = _ po . SubSite ;
po_detail . 计 划 员 = _ po . Buyer ;
po_detail . 计 划 员 电 话 = _ po . BuyerPhone ;
po_detail . 价 格 = itm . Price . ToString ( ) ;
po_detail . 币 种 = itm . Currency ;
po_detail . 收 货 口 = itm . DockCode ;
po_detail . 项 目 编 号 = itm . ProjectId ;
_ exportDetailList . Add ( po_detail ) ;
} ) ;
//var _list_dt = ConvertHelper.ToDataTable(_exportDetailList);
//_ds.Tables.Add(_list_dt);/
}
return _ exportDetailList ;
}
public static DataSet GET_PALLET_EXECEL ( List < string > p_lst )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l s = db . V_TB_PALLET_DETAIL . Where ( p = > p_lst . Contains ( p . AsnBillNum ) ) . ToList ( ) ;
var _ exportList = new List < SCP_PALLET_EXPORT > ( ) ;
_l s . ForEach ( itm = >
{
SCP_PALLET_EXPORT _ entity = new SCP_PALLET_EXPORT ( ) ;
_ entity . 订 单 号 = itm . PoBillNum ;
_ entity . 发 货 单 号 = itm . AsnBillNum ;
_ entity . 托 盘 号 = itm . PalletNum ;
_ entity . 托 盘 名 = itm . PlateNumber ;
_ entity . 零 件 编 号 = itm . PartCode ;
_ entity . 零 件 名 称 = itm . PartDesc1 + itm . PartDesc2 ;
_ entity . 数 量 = itm . Qty . ToString ( ) ;
_ entity . 包 装 数 量 = itm . PackQty . ToString ( ) ;
_ entity . 供 应 商 = itm . VendName ;
_ exportList . Add ( _ entity ) ;
} ) ;
var _d t = ConvertHelper . ToDataTable ( _ exportList ) ;
_d s . Tables . Add ( _d t ) ;
}
return _d s ;
}
public static DataSet GET_ASK_EXECEL ( List < string > p_lst )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l s = db . V_TB_ASK . Where ( p = > p_lst . Contains ( p . AskBillNum ) ) . ToList ( ) ;
var _ exportList = new List < SCP_ASK_EXPORT > ( ) ;
_l s . ForEach ( itm = >
{
SCP_ASK_EXPORT _ entity = new SCP_ASK_EXPORT ( ) ;
_ entity . 状 态 = itm . State_DESC ;
_ entity . 单 据 类 型 = itm . ModType_DESC ;
_ entity . 要 货 单 号 = itm . AskBillNum ;
_ entity . 订 单 号 = itm . PoBillNum ;
_ entity . ERP订单号 = itm . ErpBillNum ;
_ entity . 供 应 商 = itm . VendName ;
_ entity . 订 货 日 期 = itm . BeginTime = = null ? string . Empty : itm . BeginTime . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 地 点 = itm . Site_Desc ;
_ entity . 到 货 日 期 = itm . EndTime = = null ? string . Empty : itm . EndTime . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 收 货 人 = itm . Buyer ;
_ entity . 收 货 电 话 = itm . BuyerPhone ;
_ exportList . Add ( _ entity ) ;
} ) ;
var _d t = ConvertHelper . ToDataTable ( _ exportList ) ;
_d s . Tables . Add ( _d t ) ;
var _d etailList = db . V_TB_ASK_DETAIL . Where ( p = > p_lst . Contains ( p . AskBillNum ) ) . ToList ( ) ;
var _ exportDetailList = new List < SCP_ASK_DETAIL_EXPORT > ( ) ;
_d etailList . ForEach ( itm = >
{
SCP_ASK_DETAIL_EXPORT _ entity = new SCP_ASK_DETAIL_EXPORT ( ) ;
_ entity . 要 货 单 号 = itm . AskBillNum ;
_ entity . 行 号 = itm . PoLine . ToString ( ) ;
_ entity . 零 件 名 称 = itm . PartDesc1 ;
_ entity . 零 件 号 = itm . PartCode ;
_ entity . 单 位 = itm . PoUnit ;
_ entity . 标 包 数 量 = itm . PackQty . ToString ( ) ;
_ entity . 币 种 = itm . CurrencyDesc ;
_ entity . 价 格 = itm . Price . ToString ( ) ;
_ entity . 要 货 数 量 = itm . AskQty . ToString ( ) ;
_ entity . 说 明 = string . IsNullOrEmpty ( itm . Remark ) ? string . Empty : itm . Remark . ToString ( ) ;
_ entity . 订 货 日 期 = itm . BeginTime = = null ? string . Empty : itm . BeginTime . Value . ToString ( "yyyyMMdd" ) ;
_ exportDetailList . Add ( _ entity ) ;
} ) ;
var _l ist_dt = ConvertHelper . ToDataTable ( _ exportDetailList ) ;
_d s . Tables . Add ( _l ist_dt ) ;
}
return _d s ;
}
public static DataSet GET_ASN_EXECEL ( List < string > p_lst )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l s = db . V_TB_ASN . Where ( p = > p_lst . Contains ( p . AsnBillNum ) ) . ToList ( ) ;
var _ exportList = new List < SCP_ASN_EXPORT > ( ) ;
_l s . ForEach ( itm = >
{
var _ entity = new SCP_ASN_EXPORT ( ) ;
_ entity . 状 态 = itm . State_DESC ;
_ entity . 发 货 单 号 = itm . AsnBillNum ;
_ entity . 车 牌 号 = itm . PlateNumber ;
_ entity . 供 应 商 = itm . VendName ;
_ entity . 订 单 号 = itm . PoBillNum ;
_ entity . 发 货 时 间 = itm . ShipTime = = null ? string . Empty : itm . ShipTime . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 发 货 人 = itm . ShipUser ;
_ entity . 收 货 时 间 = itm . ReceiveTime = = null ? string . Empty : itm . ReceiveTime . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 收 货 人 = itm . ReceiveUser ;
_ entity . 发 往 地 点 = itm . Site_Desc ;
_ entity . 备 注 = itm . Remark ;
_ exportList . Add ( _ entity ) ;
} ) ;
var _d t = ConvertHelper . ToDataTable ( _ exportList ) ;
_d s . Tables . Add ( _d t ) ;
var _ exportDetailList = new List < SCP_ASN_DETAIL_EXPORT > ( ) ;
var _d etailList = db . V_TB_ASN_DETAIL . Where ( p = > p_lst . Contains ( p . AsnBillNum ) ) . ToList ( ) ;
_d etailList . ForEach ( itm = > {
var _ entity = new SCP_ASN_DETAIL_EXPORT ( ) ;
_ entity . 发 货 单 号 = itm . AsnBillNum ;
_ entity . 标 包 数 量 = itm . PackQty . ToString ( ) ;
_ entity . 发 货 数 量 = itm . Qty . ToString ( ) ;
_ entity . 零 件 编 号 = itm . PartCode ;
_ entity . 零 件 名 称 = itm . PartDesc1 ;
_ entity . 币 种 = itm . CurrencyDesc ;
_ entity . 批 次 = itm . Batch ;
_ entity . 供 应 商 批 次 = itm . VendBatch ;
_ entity . 生 产 日 期 = itm . ProduceDate = = null ? string . Empty : itm . ProduceDate . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 单 位 = itm . PoUnit ;
_ entity . 价 格 = itm . Price . ToString ( ) ;
_ exportDetailList . Add ( _ entity ) ;
} ) ;
var _l ist_dt = ConvertHelper . ToDataTable ( _ exportDetailList ) ;
_d s . Tables . Add ( _l ist_dt ) ;
}
return _d s ;
}
public static List < SCP_PRICE_EXPORT > GET_PRICE_EXECEL_Mode2 ( List < string > p_lst , bool p_IsDetail = false )
{
DataSet _d s = new DataSet ( ) ;
var _ exportDetailList = new List < SCP_PRICE_EXPORT > ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _ po = db . TB_PRICE . Where ( p = > p_lst . Contains ( p . UID . ToString ( ) ) ) . ToList ( ) ;
_ po . ForEach ( itm = >
{
var po_detail = new SCP_PRICE_EXPORT ( ) ;
po_detail . 标 识 = itm . UID . ToString ( ) ;
po_detail . 币 种 = itm . Curr ;
po_detail . 单 位 = itm . Unit ;
po_detail . 备 注 = itm . Remarks ;
po_detail . 域 = itm . Site ;
po_detail . 零 件 编 码 = itm . PartCode ;
po_detail . 供 应 商 编 号 = itm . VendId ;
po_detail . 地 点 = itm . SubSite ;
po_detail . 是 否 临 时 价 格 = itm . TemporaryPrice . ToString ( ) ;
po_detail . 零 件 基 础 价 格 = itm . Amt . ToString ( ) ;
po_detail . 开 始 时 间 = itm . StartTime . ToString ( ) ;
po_detail . 结 束 时 间 = itm . EndTime . ToString ( ) ;
po_detail . 最 新 开 始 时 间 = "" ;
po_detail . 最 新 结 束 时 间 = "" ;
_ exportDetailList . Add ( po_detail ) ;
} ) ;
//var _dt = ConvertHelper.ToDataTable(_exportList);
//_ds.Tables.Add(_dt);
}
return _ exportDetailList ;
}
public static DataSet GET_INVOICE_EXECEL ( List < string > p_lst )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l s = db . V_TB_INVOICE . Where ( p = > p_lst . Contains ( p . InvcBillNum ) ) . ToList ( ) ;
var _ exportList = new List < SCP_INVOICE_EXPORT > ( ) ;
_l s . ForEach ( itm = >
{
var _ entity = new SCP_INVOICE_EXPORT ( ) ;
_ entity . 状 态 = itm . State_DESC ;
_ entity . 发 票 单 号 = itm . InvcBillNum ;
_ entity . 金 税 票 号 = itm . InvoiceNum ;
_ entity . 供 应 商 = itm . VendName ;
_ entity . 金 额 = itm . Amount . ToString ( ) ;
_ entity . 税 率 = itm . Tax . ToString ( ) ;
_ entity . 税 额 = itm . TaxAmount . ToString ( ) ;
_ entity . 折 扣 金 额 = itm . ContractPrice . ToString ( ) ;
_ entity . 税 额 调 整 = itm . BlancePrice . ToString ( ) ;
_ entity . 开 票 金 额 = itm . Total . ToString ( ) ;
_ entity . 创 建 时 间 = itm . CreateTime = = null ? string . Empty : itm . CreateTime . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 快 递 单 号 = itm . ExpressNum ;
_ entity . 备 注 = itm . Remark ;
_ exportList . Add ( _ entity ) ;
} ) ;
var _d t = ConvertHelper . ToDataTable ( _ exportList ) ;
_d s . Tables . Add ( _d t ) ;
var _ exportDetailList = new List < SCP_INVOICE_DETAIL_EXPORT > ( ) ;
var _d etailList = db . V_TB_INVOICE_DETAIL . Where ( p = > p_lst . Contains ( p . InvcBillNum ) ) . ToList ( ) ;
_d etailList . ForEach ( itm = > {
var _ entity = new SCP_INVOICE_DETAIL_EXPORT ( ) ;
_ entity . 发 票 编 号 = itm . InvcBillNum ;
_ entity . 金 税 票 号 = itm . InvoiceNum ;
_ entity . 项 目 编 号 = ! string . IsNullOrEmpty ( itm . ProjectId ) ? itm . ProjectId : string . Empty ;
_ entity . 订 单 号 = itm . PoBillNum ;
_ entity . 订 单 行 = itm . PoLineNum . ToString ( ) ;
_ entity . 发 货 单 = itm . AsnBillNum ;
_ entity . 零 件 名 称 = itm . PartDesc1 ;
_ entity . 零 件 号 = itm . PartCode ;
_ entity . 币 种 = itm . Currency ;
_ entity . 单 价 = itm . Price . ToString ( ) ;
_ entity . 要 货 日 期 = itm . BeginTime = = null ? string . Empty : itm . BeginTime . Value . ToString ( "yyyyMMdd" ) ;
_ entity . 折 扣 价 格 = itm . DiscountPrice . ToString ( ) ;
_ entity . 折 扣 备 注 = itm . DiscountRemark ;
_ entity . 开 票 数 量 = itm . Qty . ToString ( ) ;
_ entity . 备 注 = itm . Remark ;
_ exportDetailList . Add ( _ entity ) ;
} ) ;
var _l ist_dt = ConvertHelper . ToDataTable ( _ exportDetailList ) ;
_d s . Tables . Add ( _l ist_dt ) ;
}
return _d s ;
}
public static DataSet GET_ARRIVE_EXECEL ( List < string > p_lst , string p_vendid = "" )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
List < V_TB_ARRIVE > _l s = new List < V_TB_ARRIVE > ( ) ;
if ( ! string . IsNullOrEmpty ( p_vendid ) )
{ _l s = db . V_TB_ARRIVE . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) & & p . VendId = = p_vendid ) . ToList ( ) ; }
else
{
_l s = db . V_TB_ARRIVE . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) ) . ToList ( ) ;
}
var str = JsonHelper . GetJson ( _l s ) ;
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 > ( ) ;
List < V_TB_ARRIVE_DETAIL > _d etailList = new List < V_TB_ARRIVE_DETAIL > ( ) ;
if ( ! string . IsNullOrEmpty ( p_vendid ) )
{
_d etailList = db . V_TB_ARRIVE_DETAIL . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) & & p . VendId = = p_vendid ) . ToList ( ) ;
}
else
{
_d etailList = db . V_TB_ARRIVE_DETAIL . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) ) . ToList ( ) ;
}
_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 ;
}
// 分地点导出
public static DataSet GET_ARRIVE_EXECELBySite ( List < string > p_lst , string p_vendid = "" , string site = "" )
{
DataSet _d s = new DataSet ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
db . Database . CommandTimeout = 3 0 0 ;
List < V_TB_ARRIVE > _l s = new List < V_TB_ARRIVE > ( ) ;
if ( ! string . IsNullOrEmpty ( p_vendid ) )
{
if ( ! string . IsNullOrWhiteSpace ( site ) )
{
_l s = db . V_TB_ARRIVE . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) & & ( p . VendId = = p_vendid ) & & ( p . SubSite = = site ) ) . ToList ( ) ;
}
else
{
_l s = db . V_TB_ARRIVE . Where ( p = > ( p_lst . Contains ( p . ArrvBillNum ) ) & & ( p . VendId = = p_vendid ) ) . ToList ( ) ;
}
}
else
{
if ( ! string . IsNullOrWhiteSpace ( site ) )
{
_l s = db . V_TB_ARRIVE . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) & & ( p . SubSite = = site ) ) . ToList ( ) ;
}
else
{
_l s = db . V_TB_ARRIVE . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) ) . ToList ( ) ;
}
}
var str = JsonHelper . GetJson ( _l s ) ;
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 > ( ) ;
List < V_TB_ARRIVE_DETAIL > _d etailList = new List < V_TB_ARRIVE_DETAIL > ( ) ;
if ( ! string . IsNullOrEmpty ( p_vendid ) )
{
if ( ! string . IsNullOrWhiteSpace ( site ) )
{
_d etailList = db . V_TB_ARRIVE_DETAIL . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) & & ( p . VendId = = p_vendid ) & & ( p . SubSite = = site ) ) . ToList ( ) ;
}
else
{
_d etailList = db . V_TB_ARRIVE_DETAIL . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) & & ( p . VendId = = p_vendid ) ) . ToList ( ) ;
}
}
else
{
if ( ! string . IsNullOrWhiteSpace ( site ) )
{
_d etailList = db . V_TB_ARRIVE_DETAIL . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) & & ( p . SubSite = = site ) ) . ToList ( ) ;
}
else
{
_d etailList = db . V_TB_ARRIVE_DETAIL . Where ( p = > p_lst . Contains ( p . ArrvBillNum ) ) . ToList ( ) ;
}
}
_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 ;
var partModel = db . TA_PART . FirstOrDefault ( p = > p . PartCode = = itm . PartCode & & p . Site = = itm . Site ) ;
if ( partModel ! = null )
{
_ entity . 零 件 名 称 = partModel . PartDesc1 ;
_ entity . 单 位 = partModel . 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 ;
}
/// <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 ;
}
}
}