using System ;
using System.Collections.Generic ;
using System.Data.Entity.Migrations ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using CK.SCP.Models ;
using CK.SCP.Models.ScpEntity ;
using CK.SCP.Utils ;
using CK.SCP.Controller ;
using CK.SCP.Models.Enums ;
using CK.SCP.Models.AppBoxEntity ;
using System.Data.Entity.Core ;
using CK.SCP.Models.ScpEntity.ExcelImportEntity ;
using System.Data ;
using System.Data.SqlClient ;
using System.Text.RegularExpressions ;
namespace CK.SCP.Controller
{
public class SCP_RECIVECE_CONTROLLER
{
public static void Get_V_TB_RECEIVE_GG_List ( V_TB_RECEIVE p_entity , Action < ResultObject < IQueryable < V_TB_RECEIVE > > > p_action )
{
ResultObject < IQueryable < V_TB_RECEIVE > > _ ret = new ResultObject < IQueryable < V_TB_RECEIVE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_RECEIVE > q = db . V_TB_RECEIVE ;
if ( ! string . IsNullOrEmpty ( p_entity . RecvBillNum ) )
{
q = q . Where ( p = > p . RecvBillNum . Contains ( p_entity . RecvBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( p_entity . UserInAddress ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInAddress . Contains ( p . Site ) ) ;
}
if ( p_entity . UserInSubSite ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInSubSite . Contains ( p . SubSite ) ) ;
}
if ( p_entity . UserInVendIds ! = null & & p_entity . UserInVendIds . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInVendIds . Contains ( p . VendId ) ) ;
}
if ( p_entity . State = = 0 | | p_entity . State = = 1 | | p_entity . State = = 2 )
{
q = q . Where ( p = > p . State = = p_entity . State ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Remark ) )
{
q = q . Where ( p = > p . Remark . Contains ( p_entity . Remark ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . OperName ) )
{
q = q . Where ( p = > p . OperName . Contains ( p_entity . OperName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site_Desc ) )
{
q = q . Where ( p = > p . Site_Desc . Contains ( p_entity . Site_Desc ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . BillType_DESC ) )
{
q = q . Where ( p = > p . BillType_DESC . Contains ( p_entity . BillType_DESC ) ) ;
}
//if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
//{
// q = q.Where(p => p_entity.UserInAddress.Contains(p.Address));
//}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , e . Message ) ;
throw e ;
}
}
public static void Get_V_TB_RECEIVE_List ( V_TB_RECEIVE p_entity , Action < ResultObject < IQueryable < V_TB_RECEIVE > > > p_action )
{
ResultObject < IQueryable < V_TB_RECEIVE > > _ ret = new ResultObject < IQueryable < V_TB_RECEIVE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_RECEIVE > q = db . V_TB_RECEIVE ;
if ( ! string . IsNullOrEmpty ( p_entity . RecvBillNum ) )
{
q = q . Where ( p = > p . RecvBillNum . Contains ( p_entity . RecvBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site . Contains ( p_entity . Site ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId . Contains ( p_entity . VendId ) ) ;
}
if ( p_entity . State = = 0 | | p_entity . State = = 1 | | p_entity . State = = 2 )
{
q = q . Where ( p = > p . State = = p_entity . State ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Remark ) )
{
q = q . Where ( p = > p . Remark . Contains ( p_entity . Remark ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . OperName ) )
{
q = q . Where ( p = > p . OperName . Contains ( p_entity . OperName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site_Desc ) )
{
q = q . Where ( p = > p . Site_Desc . Contains ( p_entity . Site_Desc ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . BillType_DESC ) )
{
q = q . Where ( p = > p . BillType_DESC . Contains ( p_entity . BillType_DESC ) ) ;
}
//if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
//{
// q = q.Where(p => p_entity.UserInAddress.Contains(p.Address));
//}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_List" , e . Message ) ;
throw e ;
}
}
public static void Get_V_TB_RECEIVE_DETAIL_List ( List < V_TB_RECEIVE > p_list , Action < ResultObject < IQueryable < V_TB_RECEIVE_DETAIL > > > p_action )
{
ResultObject < IQueryable < V_TB_RECEIVE_DETAIL > > _ ret = new ResultObject < IQueryable < V_TB_RECEIVE_DETAIL > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _ ary = p_list . Select ( p = > "'" + p . RecvBillNum + "'" ) . ToList ( ) . ToArray ( ) ;
if ( _ ary . Count ( ) > 0 )
{
string str = string . Join ( "," , _ ary ) ;
string _ sql = string . Format ( "SELECT * FROM [V_TB_RECEIVE_DETAIL] where RecvBillNum in ({0})" , str ) ;
IQueryable < V_TB_RECEIVE_DETAIL > q = db . Database . SqlQuery < V_TB_RECEIVE_DETAIL > ( _ sql ) . AsQueryable ( ) ;
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , e . Message ) ;
throw e ;
}
}
/// <summary>
/// 保存到货
/// </summary>
/// <param name="p_entity"></param>
/// <param name="p_list"></param>
/// <param name="currentuser"></param>
/// <returns></returns>
public static ResultObject < bool > Save_TB_RECEIVE ( V_TB_ASN_DETAIL p_entity , List < V_TB_ASN_DETAIL > p_list , string currentuser )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
var scpRcvList = new List < TB_RECEIVE > ( ) ;
var scpRcveDetailList = new List < TB_RECEIVE_DETAIL > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
DateTime now = DateTime . Now ;
var _ asn = db . TB_ASN . Where ( p = > p . IsDeleted = = false & & p . AsnBillNum = = p_entity . AsnBillNum ) . ToList ( ) ;
if ( _ asn ! = null & & _ asn . Count > 0 )
{
_ asn . ForEach ( p = >
{
p . State = ( int ) AsnState . Receive ;
p . CreateTime = now ;
} ) ;
db . TB_ASN . AddOrUpdate ( p = > p . UID , _ asn . ToArray ( ) ) ;
var _ asndetail = db . TB_ASN_DETAIL . Where ( p = > p . IsDeleted = = false & & p . AsnBillNum = = p_entity . AsnBillNum ) . ToList ( ) ;
_ asndetail . ForEach ( p = >
{
p . State = ( int ) AsnState . Receive ;
p . CreateTime = now ;
} ) ;
db . TB_ASN_DETAIL . AddOrUpdate ( p = > p . UID , _ asndetail . ToArray ( ) ) ;
TB_RECEIVE scpRcv = new TB_RECEIVE ( ) ;
scpRcv . RecvBillNum = SCP_BILLCODE_CONTROLLER . MakeReviceCode_ASN ( ) ; //收货单号
scpRcv . State = ( int ) FormState . 开 放 ;
scpRcv . Remark = "" ;
scpRcv . CreateTime = DateTime . Now ; //创建日期
scpRcv . CreateUser = currentuser ; //创建用户
scpRcv . IsDeleted = false ;
scpRcv . GUID = System . Guid . NewGuid ( ) ;
scpRcv . BillType = 0 ;
scpRcv . PoBillNum = p_entity . PoBillNum ; //采购单
scpRcv . AsnBillNum = p_entity . AsnBillNum ; //发货单号
scpRcv . Site = p_entity . Site ; //地点
scpRcv . VendId = p_entity . VendId ; //供货商名称
scpRcv . ShipTime = now ; //收货日期
scpRcvList . Add ( scpRcv ) ;
db . TB_RECEIVE . AddOrUpdate ( p = > p . UID , scpRcvList . ToArray ( ) ) ;
p_list . ForEach ( item = >
{
TB_RECEIVE_DETAIL scpRcvDetail = new TB_RECEIVE_DETAIL ( ) ;
scpRcvDetail . RecvBillNum = SCP_BILLCODE_CONTROLLER . MakeReviceCode_ASN ( ) ; //收货单号
scpRcvDetail . PoBillNum = item . PoBillNum ; //采购单
scpRcvDetail . PoLine = item . PoLine ; //订单行
scpRcvDetail . PartCode = item . PartCode ; //零件号
scpRcvDetail . Batch = item . Batch ; //批次
scpRcvDetail . VendBatch = item . VendBatch ; //供应商批号
scpRcvDetail . PoUnit = item . PoUnit ; //采购单位
scpRcvDetail . LocUnit = item . LocUnit ; //基本单位
scpRcvDetail . Qty = item . Qty ; //收货总量
//scpRcvDetail.DockCode = "";//收货口
scpRcvDetail . State = ( int ) FormState . 开 放 ; // (int)FormState.关闭,
scpRcvDetail . Remark = item . Remark ;
scpRcvDetail . CreateTime = DateTime . Now ; //创建日期
scpRcvDetail . CreateUser = currentuser ; //创建用户
scpRcvDetail . IsDeleted = false ;
scpRcvDetail . GUID = System . Guid . NewGuid ( ) ;
scpRcvDetail . BillType = 0 ;
scpRcveDetailList . Add ( scpRcvDetail ) ;
} ) ;
db . TB_RECEIVE_DETAIL . AddOrUpdate ( p = > p . UID , scpRcveDetailList . ToArray ( ) ) ;
}
if ( db . SaveChanges ( ) ! = - 1 )
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
}
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static void Get_V_TB_RECEIVE_DETAIL_List ( V_TB_RECEIVE_DETAIL p_entity , Action < ResultObject < IQueryable < V_TB_RECEIVE_DETAIL > > > p_action )
{
ResultObject < IQueryable < V_TB_RECEIVE_DETAIL > > _ ret = new ResultObject < IQueryable < V_TB_RECEIVE_DETAIL > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_RECEIVE_DETAIL > q = db . V_TB_RECEIVE_DETAIL ;
if ( ! string . IsNullOrEmpty ( p_entity . RecvBillNum ) )
{
q = q . Where ( p = > p . RecvBillNum = = p_entity . RecvBillNum ) ;
}
if ( p_entity . PoLine ! = 0 )
{
q = q . Where ( p = > p . PoLine = = p_entity . PoLine ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
q = q . Where ( p = > p . PartCode . Contains ( p_entity . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Batch ) )
{
q = q . Where ( p = > p . Batch . Contains ( p_entity . Batch ) ) ;
}
if ( p_entity . Qty ! = 0 )
{
q = q . Where ( p = > p . Qty = = p_entity . Qty ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . DockCode ) )
{
q = q . Where ( p = > p . DockCode . Contains ( p_entity . DockCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Remark ) )
{
q = q . Where ( p = > p . Remark . Contains ( p_entity . Remark ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site . Contains ( p_entity . Site ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId . Contains ( p_entity . VendId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . OperName ) )
{
q = q . Where ( p = > p . OperName . Contains ( p_entity . OperName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( p_entity . State ! = 0 )
{
q = q . Where ( p = > p . State = = p_entity . State ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
//if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
//{
// q = q.Where(p => p_entity.UserInAddress.Contains(p.Address));
//}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_DETAIL_List" , e . Message ) ;
throw e ;
}
}
public static ResultObject < bool > Save_TB_RECEIVE_STATE ( List < string > p_list , ReceiveState p_state , string userName )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
if ( p_state = = ReceiveState . Check )
{
var _l s = db . V_TB_RECEIVE . Where ( p = > p_list . Contains ( p . RecvBillNum ) ) . ToList ( ) ;
int count = _l s . Count ( p = > p . State = = ( int ) ReceiveState . Receive ) ;
if ( count = = _l s . Count & & _l s . Count > 0 )
{
_l s . ForEach ( p = >
{
p . OperName = userName ;
p . State = ( int ) ReceiveState . Check ;
var _l ist = db . TB_RECEIVE_DETAIL . Where ( itm = > itm . RecvBillNum = = p . RecvBillNum ) . ToList ( ) ;
_l ist . ForEach ( itm = > itm . State = ( int ) ReceiveState . Check ) ;
db . TB_RECEIVE_DETAIL . AddOrUpdate ( itm = > itm . UID , _l ist . ToArray ( ) ) ;
#region 收货审核提醒供应商提起发票申请
TB_PENING_ITEMS _ item = new TB_PENING_ITEMS ( ) ;
_ item . ROLE_NAME = "供应商" ;
_ item . ITEM_NO = p . RecvBillNum ;
_ item . ITEM_CONTENT = string . Format ( "收货单号{0}发货单号{1},已收货!请申请发票" , p . RecvBillNum , _l s [ 0 ] . AsnBillNum ) ;
_ item . ITEM_TYPE = ( int ) PENDING_MESSAGE_TYPE . PO_AUDIT_PASS ;
_ item . ITEM_STATE = ( int ) PENDING_STATE . WAITING ;
_ item . SENDER = p . CreateUser ;
_ item . VEND_ID = p . VendId ;
_ item . SENDING_TIME = DateTime . Now ;
//_item.ITEM_ADDRESS = p.Site_Desc;
_ item . ITEM_ADDRESS = p . Site ;
_ item . GUID = Guid . NewGuid ( ) ;
db . TB_PENING_ITEMS . Add ( _ item ) ;
#endregion
}
) ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = "选择的记录,有不是收货状态记录!" ;
}
if ( db . SaveChanges ( ) ! = - 1 )
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = "数据更新失败!" ;
}
}
if ( p_state = = ReceiveState . Reject )
{
var _l s = db . V_TB_RECEIVE . Where ( p = > p_list . Contains ( p . RecvBillNum ) ) . ToList ( ) ;
int count = _l s . Count ( p = > p . State = = ( int ) ReceiveState . Receive ) ;
if ( count = = _l s . Count & & _l s . Count > 0 )
{
_l s . ForEach ( p = >
{
p . OperName = userName ;
p . State = ( int ) ReceiveState . Reject ;
p . IsDeleted = true ;
var _l ist = db . TB_RECEIVE_DETAIL . Where ( itm = > itm . RecvBillNum = = p . RecvBillNum ) . ToList ( ) ;
_l ist . ForEach ( itm = >
{
itm . State = ( int ) ReceiveState . Reject ;
itm . IsDeleted = true ;
}
) ;
db . TB_RECEIVE_DETAIL . AddOrUpdate ( itm = > itm . UID , _l ist . ToArray ( ) ) ;
}
) ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = "选择的记录,有不是收货状态记录!" ;
}
if ( db . SaveChanges ( ) ! = - 1 )
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = "数据更新失败!" ;
}
}
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE_STATE" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE_STATE" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE_STATE" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_RECEIVE_STATE" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static List < V_TB_RECEIVE_LIST > Get_V_TB_RECEIVE_LIST ( List < V_TB_RECEIVE_LIST > p_list )
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
p_list . ForEach ( itm = >
{
//var _sum= db.TB_INVOICE_DETAIL.Where(p => p.RecvBillNum == itm.RecvBillNum && p.PartCode == itm.PartCode && p.Batch==itm.Batch && p.IsDeleted==false).Select(p=>p.Qty).Sum();
var _ sum = db . TB_INVOICE_DETAIL . Where ( p = > p . RecvBillNum = = itm . RecvBillNum & & p . PartCode = = itm . PartCode & & p . PoBillNum = = itm . PoBillNum & & p . PoLineNum = = itm . PoLine & & p . Batch = = itm . Batch & & p . IsDeleted = = false & & p . Site = = itm . Site & & p . SubSite = = itm . SubSite ) .
ToArray ( ) . Sum ( p = > new decimal? ( p . Qty ) ) . GetValueOrDefault ( ) ;
itm . CanQty = itm . Qty - _ sum ;
} ) ;
}
return p_list ;
}
public static List < V_TB_INVOICE_DETAIL > Get_V_TB_INVOICE_LIST ( List < V_TB_INVOICE_DETAIL > p_list )
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
p_list . ForEach ( itm = >
{
try
{
var _ recSum = db . V_TB_RECEIVE_DETAIL . Where ( p = > p . RecvBillNum = = itm . RecvBillNum & & p . PartCode = = itm . PartCode & & p . Batch = = itm . Batch & & p . IsDeleted = = false ) . Select ( p = > p . Qty ) . Sum ( ) ;
if ( itm . RecvBillNum . Substring ( 0 , 1 ) = = "R" )
{
_ recSum = 0 - Math . Abs ( _ recSum ) ;
}
var _ sum = db . V_TB_INVOICE_DETAIL . Where ( p = > p . RecvBillNum = = itm . RecvBillNum & & p . PartCode = = itm . PartCode & & p . Batch = = itm . Batch & & p . IsDeleted = = false ) . Select ( p = > p . Qty ) . Sum ( ) ;
if ( _ recSum - _ sum < = 0 )
{
itm . CanQty = 0 ;
}
else
{
itm . CanQty = _ recSum - _ sum ;
}
}
catch
{
itm . CanQty = 0 ;
}
} ) ;
}
return p_list ;
}
public static DataTable Get_TB_RECEIVE_PLAN ( V_TB_ARRIVE_DETAIL p_plan , string p_date , int p_State = 1 )
{
string _ sql = string . Empty ;
if ( p_State = = 1 )
{
_ sql = "SELECT D.PROJECTID,b.VENDNAME, c.* FROM(SELECT partcode,PartDesc1, Qty, CONVERT(varchar(100), CreateTime, 23) as endtime,PoUnit,SubSite,VendId FROM V_TB_ARRIVE_DETAIL where BillType_DESC='到货单'\n" +
" ) A\n" +
" pivot(sum(Qty) for a.endtime in ( {1}\n" +
"\n" +
" )\n" +
" ) as C left join TA_VENDER B ON C.VENDID=B.VENDID LEFT JOIN TA_PART D ON C.PARTCODE=D.PARTCODE where {0};" ;
}
if ( p_State = = 2 )
{
_ sql = "SELECT D.PROJECTID,b.VENDNAME, c.* FROM(SELECT partcode,PartDesc1, Qty, CONVERT(varchar(100), CreateTime, 23) as endtime,PoUnit,SubSite,VendId FROM V_TB_ARRIVE_DETAIL where BillType_DESC='退货单'\n" +
" ) A\n" +
" pivot(sum(Qty) for a.endtime in ( {1}\n" +
"\n" +
" )\n" +
" ) as C left join TA_VENDER B ON C.VENDID=B.VENDID LEFT JOIN TA_PART D ON C.PARTCODE=D.PARTCODE where {0};" ;
}
string _ sqlDate = "select '[' + convert(varchar(10), DATEADD(day, number, CAST('{0}' as datetime)), 23) + ']' endtime\n" +
" from master.dbo.spt_values\n" +
" where type = 'p'\n" +
" AND number<= DATEDIFF(day, CAST('{0}' as datetime), DATEADD(DAY, -1, DATEADD(MM, DATEDIFF(MM, 0, CAST('{0}' as datetime)) + 1, 0)))" ;
DataTable dt = new DataTable ( ) ;
DataTable _ tbDate = new DataTable ( ) ;
var dbSetting = GlobalConfig . ScpDatabase ;
SqlConnection conn = new System . Data . SqlClient . SqlConnection ( ) ;
try
{
var strConn = EntitiesFactory . GetEfConnectionString ( dbSetting ) ;
conn . ConnectionString = strConn ;
if ( conn . State ! = ConnectionState . Open )
{
conn . Open ( ) ;
}
SqlCommand cmdDate = new SqlCommand ( ) ;
cmdDate . Connection = conn ;
cmdDate . CommandText = string . Format ( _ sqlDate , p_date ) ;
SqlDataAdapter adapter1 = new SqlDataAdapter ( cmdDate ) ;
adapter1 . Fill ( _ tbDate ) ;
List < string > _d ateList = new List < string > ( ) ;
foreach ( DataRow row in _ tbDate . Rows )
{
_d ateList . Add ( row [ "endtime" ] . ToString ( ) ) ;
}
SqlCommand cmd = new SqlCommand ( ) ;
cmd . Connection = conn ;
string where1 = " 1=1 " ;
if ( ! string . IsNullOrEmpty ( p_plan . PartCode ) )
{
where1 + = string . Format ( " and C.partcode='{0}' " , p_plan . PartCode ) ;
}
if ( ! string . IsNullOrEmpty ( p_plan . VendId ) )
{
where1 + = string . Format ( " and C.VendId='{0}' " , p_plan . VendId ) ;
}
if ( ! string . IsNullOrEmpty ( p_plan . ProjectId ) )
{
where1 + = string . Format ( " and ProjectId like '{0}%' " , p_plan . ProjectId ) ;
}
if ( ! string . IsNullOrEmpty ( p_plan . SubSite ) )
{
where1 + = string . Format ( " and C.SUBSITE = '{0}' " , p_plan . SubSite ) ;
}
//if (!string.IsNullOrEmpty(p_plan.PoBillNum))
//{
// where1 += string.Format(" and PoBillNum='{0}' ", p_plan.PoBillNum);
//}
//if (p_plan.EndTime_Begin != null)
//{
// where1 += string.Format(" and EndTime>='{0}'", p_plan.EndTime_Begin.Value.ToString("yyyy-MM-dd"));
//}
//else
//{
// where1 += string.Format(" and EndTime>='{0}'", DateTime.Now.ToString("yyyy-MM-dd"));
//}
//if (p_plan.EndTime_End != null)
//{
// where1 += string.Format(" and EndTime<='{0}'", p_plan.EndTime_End.Value.ToString("yyyy-MM-dd"));
//}
//else
//{
// where1 += string.Format(" and EndTime<='{0}'", DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd"));
//}
cmd . CommandText = string . Format ( _ sql , where1 , string . Join ( "," , _d ateList . ToArray ( ) ) ) ;
SqlDataAdapter adapter = new SqlDataAdapter ( cmd ) ;
adapter . Fill ( dt ) ;
dt . Columns . Add ( "合计" ) ;
dt . Columns [ "PartCode" ] . ColumnName = "零件编号" ;
dt . Columns [ "VendId" ] . ColumnName = "供应商编号" ;
dt . Columns [ "VendName" ] . ColumnName = "供应商名称" ;
dt . Columns [ "PartDesc1" ] . ColumnName = "零件名称" ;
dt . Columns [ "SubSite" ] . ColumnName = "分厂地点" ;
dt . Columns [ "PoUnit" ] . ColumnName = "单位" ;
dt . Columns [ "Projectid" ] . ColumnName = "项目编号" ;
foreach ( DataRow row in dt . Rows )
{
decimal num = 0 ;
foreach ( DataColumn column in dt . Columns )
{
var _ reg = Regex . Match ( column . ColumnName , @"\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}" ) ;
if ( ! string . IsNullOrEmpty ( _ reg . Value ) )
{
if ( row [ column . ColumnName ] ! = null & & ! string . IsNullOrEmpty ( row [ column . ColumnName ] . ToString ( ) ) )
{
num + = decimal . Parse ( row [ column . ColumnName ] . ToString ( ) ) ;
}
}
}
row [ "合计" ] = num ;
}
conn . Close ( ) ;
}
catch ( SqlException ex )
{
conn . Close ( ) ;
throw new Exception ( $"系统无法连接到数据库:{dbSetting},请检查配置的服务器,数据库,用户名和密码等信息是否正确。{Environment.NewLine}{ex}" ) ;
}
return dt ;
}
public static ResultObject < IQueryable < V_TB_RECEIVE_LIST > > Get_V_TB_RECEIVE_LIST_List ( V_TB_RECEIVE_LIST p_entity , Action < ResultObject < IQueryable < V_TB_RECEIVE_LIST > > > p_action )
{
ResultObject < IQueryable < V_TB_RECEIVE_LIST > > _ ret = new ResultObject < IQueryable < V_TB_RECEIVE_LIST > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_RECEIVE_LIST > q = db . V_TB_RECEIVE_LIST ;
if ( ! string . IsNullOrEmpty ( p_entity . ProjectId ) )
{
q = q . Where ( p = > p . ProjectId . Contains ( p_entity . ProjectId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . RecvBillNum ) )
{
q = q . Where ( p = > p . RecvBillNum = = p_entity . RecvBillNum ) ;
}
if ( p_entity . PoLine ! = 0 )
{
q = q . Where ( p = > p . PoLine = = p_entity . PoLine ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
q = q . Where ( p = > p . PartCode . Contains ( p_entity . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Batch ) )
{
q = q . Where ( p = > p . Batch . Contains ( p_entity . Batch ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Remark ) )
{
q = q . Where ( p = > p . Remark . Contains ( p_entity . Remark ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site . Contains ( p_entity . Site ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId . Contains ( p_entity . VendId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
q = q . Where ( p = > p . PartCode . Contains ( p_entity . PartCode ) ) ;
}
if ( p_entity . BeginTime ! = null )
{
q = q . Where ( p = > p . ShipTime > = p_entity . BeginTime ) ;
}
if ( p_entity . Site ! = null )
{
q = q . Where ( p = > p . Site = = p_entity . Site ) ;
}
if ( p_entity . SubSite ! = null )
{
q = q . Where ( p = > p . SubSite = = p_entity . SubSite ) ;
}
if ( p_entity . EndTime ! = null )
{
q = q . Where ( p = > p . ShipTime < = p_entity . EndTime ) ;
}
if ( p_entity . UserInVendIds ! = null & & p_entity . UserInVendIds . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInVendIds . Contains ( p . VendId ) ) ;
}
if ( p_entity . UIDList ! = null & & p_entity . UIDList . Count > 0 )
{
q = q . Where ( p = > p_entity . UIDList . Contains ( p . UID ) ) ;
}
//if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
//{
// q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
//}
if ( p_entity . UserInSubSite ! = null & & p_entity . UserInSubSite . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInSubSite . Contains ( p . SubSite ) ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , e . Message ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < IQueryable < TB_PRICE > > Get_V_TB_RECEIVE_LIST_PRICE ( string p_vendId , List < V_TB_RECEIVE_LIST > p_list , Action < ResultObject < IQueryable < TB_PRICE > > > p_action )
{
var _l s = p_list . Select ( itm = > itm . PartCode ) ;
StringBuilder _ buffer = new StringBuilder ( ) ;
_ buffer . Append ( " SELECT * FROM TB_PRICE WHERE UID IN" ) ;
_ buffer . Append ( "( SELECT MAX(UID) AS UID FROM TB_PRICE AS A" ) ;
_ buffer . AppendFormat ( " where A.VendId='{0}' AND A.PartCode IN ('{1}') " , p_vendId , String . Join ( "','" , _l s ) ) ;
_ buffer . Append ( " GROUP BY VendId, Site,SubSite, PartCode, StartTime, EndTime)" ) ;
ResultObject < IQueryable < TB_PRICE > > _ ret = new ResultObject < IQueryable < TB_PRICE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < TB_PRICE > q = db . Database . SqlQuery < TB_PRICE > ( _ buffer . ToString ( ) ) . AsQueryable ( ) ;
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_RECEIVE_LIST_List" , e . Message ) ;
throw e ;
}
return _ ret ;
}
public static void Get_V_TB_ARRIVE_List ( V_TB_ARRIVE p_entity , Action < ResultObject < IQueryable < V_TB_ARRIVE > > > p_action )
{
ResultObject < IQueryable < V_TB_ARRIVE > > _ ret = new ResultObject < IQueryable < V_TB_ARRIVE > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_ARRIVE > q = db . V_TB_ARRIVE ;
if ( p_entity . BeginTime ! = null )
{
q = q . Where ( p = > p . ShipTime > = p_entity . BeginTime ) ;
}
if ( p_entity . EndTime ! = null )
{
q = q . Where ( p = > p . ShipTime < = p_entity . EndTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ArrvBillNum ) )
{
q = q . Where ( p = > p . ArrvBillNum = = p_entity . ArrvBillNum ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum = = p_entity . PoBillNum ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum = = p_entity . AsnBillNum ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AskBillNum ) )
{
q = q . Where ( p = > p . AskBillNum = = p_entity . AskBillNum ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site = = p_entity . Site ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . SubSite ) )
{
q = q . Where ( p = > p . SubSite = = p_entity . SubSite ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . BillType_DESC ) )
{
q = q . Where ( p = > p . BillType_DESC = = p_entity . BillType_DESC ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Remark ) )
{
q = q . Where ( p = > p . Remark . Contains ( p_entity . Remark ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . OperName ) )
{
q = q . Where ( p = > p . OperName . Contains ( p_entity . OperName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site_Desc ) )
{
q = q . Where ( p = > p . Site_Desc . Contains ( p_entity . Site_Desc ) ) ;
}
if ( p_entity . UserInSubSite ! = null & & p_entity . UserInSubSite . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInSubSite . Contains ( p . SubSite ) ) ;
}
if ( p_entity . UserInVendIds ! = null & & p_entity . UserInVendIds . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInVendIds . Contains ( p . VendId ) ) ;
}
//if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
//{
// q = q.Where(p => p_entity.UserInAddress.Contains(p.Address));
//}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
Console . WriteLine ( ex . ToString ( ) ) ;
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
Console . WriteLine ( ex . ToString ( ) ) ;
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
//Console.WriteLine(inner?.StateEntries[0].EntitySet.Name);
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_List" , e . Message ) ;
throw e ;
}
}
public static ResultObject < bool > Save_TB_ARRIVE_STATE ( List < string > p_list , ReceiveState p_state , string userName )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l s = db . V_TB_ARRIVE . Where ( p = > p_list . Contains ( p . ArrvBillNum ) ) . ToList ( ) ;
int count = _l s . Count ( p = > p . State = = ( int ) ReceiveState . Receive ) ;
if ( count = = _l s . Count & & _l s . Count > 0 )
{
_l s . ForEach ( p = >
{
p . OperName = userName ;
p . State = ( int ) ReceiveState . Check ;
var _l ist = db . TB_ARRIVE_DETAIL . Where ( itm = > itm . ArrvBillNum = = p . ArrvBillNum ) . ToList ( ) ;
_l ist . ForEach ( itm = > itm . State = ( int ) ReceiveState . Check ) ;
db . TB_ARRIVE_DETAIL . AddOrUpdate ( itm = > itm . UID , _l ist . ToArray ( ) ) ;
#region 收货审核提醒供应商提起发票申请
TB_PENING_ITEMS _ item = new TB_PENING_ITEMS ( ) ;
_ item . ROLE_NAME = "供应商" ;
_ item . ITEM_NO = p . ArrvBillNum ;
_ item . ITEM_CONTENT = string . Format ( "到货单号{0}发货单号{1},已到货!请申请发票" , p . ArrvBillNum , _l s [ 0 ] . AsnBillNum ) ;
_ item . ITEM_TYPE = ( int ) PENDING_MESSAGE_TYPE . PO_AUDIT_PASS ;
_ item . ITEM_STATE = ( int ) PENDING_STATE . WAITING ;
_ item . SENDER = p . CreateUser ;
_ item . VEND_ID = p . VendId ;
_ item . SENDING_TIME = DateTime . Now ;
//_item.ITEM_ADDRESS = p.Site_Desc;
_ item . ITEM_ADDRESS = p . Site ;
_ item . GUID = Guid . NewGuid ( ) ;
db . TB_PENING_ITEMS . Add ( _ item ) ;
#endregion
}
) ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = "选择的记录,有不是到货状态记录!" ;
}
if ( db . SaveChanges ( ) ! = - 1 )
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = "数据更新失败!" ;
}
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_ARRIVE_STATE" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
Console . WriteLine ( ex . ToString ( ) ) ;
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_ARRIVE_STATE" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
Console . WriteLine ( ex . ToString ( ) ) ;
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_ARRIVE_STATE" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
//Console.WriteLine(inner?.StateEntries[0].EntitySet.Name);
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Save_TB_ARRIVE_STATE" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static void GetNumber ( string p_asnBillNum )
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l ist = db . TB_ASN . Where ( p = > p . AsnBillNum = = p_asnBillNum & & p . IsDeleted = = false ) . ToList ( ) ;
if ( _l ist . Count > 0 )
{
_l ist . ForEach ( itm = > itm . State = ( int ) AsnState . Receive ) ;
db . TB_ASN . AddOrUpdate ( p = > p . UID , _l ist . ToArray ( ) ) ;
var _ entity = _l ist . FirstOrDefault ( ) ;
var _ asnList = db . TB_ASN . Where ( p = > p . AskBillNum = = _ entity . AskBillNum & & p . IsDeleted = = false ) ;
var _ count = _ asnList . Count ( p = > p . State = = ( int ) AsnState . Receive ) ;
if ( _ asnList . Count ( ) = = _ count )
{
var _ askList = db . TB_ASK . Where ( p = > p . AskBillNum = = _ entity . AskBillNum & & p . IsDeleted = = false ) . ToList ( ) ;
_ askList . ForEach ( itm = > itm . State = ( int ) AskState . Receive ) ;
db . TB_ASK . AddOrUpdate ( p = > p . UID , _ askList . ToArray ( ) ) ;
}
}
}
}
public static void Get_V_TB_ARRIVE_DETAIL_List ( V_TB_ARRIVE_DETAIL p_entity , Action < ResultObject < IQueryable < V_TB_ARRIVE_DETAIL > > > p_action )
{
ResultObject < IQueryable < V_TB_ARRIVE_DETAIL > > _ ret = new ResultObject < IQueryable < V_TB_ARRIVE_DETAIL > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_ARRIVE_DETAIL > q = db . V_TB_ARRIVE_DETAIL ;
if ( ! string . IsNullOrEmpty ( p_entity . ArrvBillNum ) )
{
q = q . Where ( p = > p . ArrvBillNum = = p_entity . ArrvBillNum ) ;
}
if ( p_entity . PoLine ! = 0 )
{
q = q . Where ( p = > p . PoLine = = p_entity . PoLine ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartCode ) )
{
q = q . Where ( p = > p . PartCode . Contains ( p_entity . PartCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Batch ) )
{
q = q . Where ( p = > p . Batch . Contains ( p_entity . Batch ) ) ;
}
if ( p_entity . Qty ! = 0 )
{
q = q . Where ( p = > p . Qty = = p_entity . Qty ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . DockCode ) )
{
q = q . Where ( p = > p . DockCode . Contains ( p_entity . DockCode ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Remark ) )
{
q = q . Where ( p = > p . Remark . Contains ( p_entity . Remark ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site . Contains ( p_entity . Site ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . SubSite ) )
{
q = q . Where ( p = > p . SubSite . Contains ( p_entity . SubSite ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId . Contains ( p_entity . VendId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . OperName ) )
{
q = q . Where ( p = > p . OperName . Contains ( p_entity . OperName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_DETAIL_List" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
Console . WriteLine ( ex . ToString ( ) ) ;
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_DETAIL_List" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
Console . WriteLine ( ex . ToString ( ) ) ;
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_DETAIL_List" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
//Console.WriteLine(inner?.StateEntries[0].EntitySet.Name);
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "Get_V_TB_ARRIVE_DETAIL_List" , e . Message ) ;
throw e ;
}
}
public static List < V_TB_PO_DETAIL > COMPARE_DETAIL_SUM ( string p_number )
{
List < V_TB_PO_DETAIL > _l s = new List < V_TB_PO_DETAIL > ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l ist = db . V_TB_PO_DETAIL . Where ( p = > p . PoBillNum = = p_number ) . ToList ( ) ;
if ( _l ist . Count > 0 )
{
//var _detail = p_list[0];
foreach ( V_TB_PO_DETAIL _d etail in _l ist )
{
//var _ask = db.TB_ASK_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { AskSum = p.Sum(itm => itm.AskQty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
var rec = db . TB_RECEIVE_DETAIL . Where ( p = > p . PoBillNum = = _d etail . PoBillNum & & p . IsDeleted = = false & & p . BillType = = 0 ) . GroupBy ( p = > new { p . PoBillNum , p . PoLine , p . PartCode } ) . Select ( p = > new { ReceiveSum = p . Sum ( itm = > itm . Qty ) , PoLine = p . Key . PoLine , PoBillNum = p . Key . PoBillNum , PartCode = p . Key . PartCode } ) ;
var reject = db . TB_RECEIVE_DETAIL . Where ( p = > p . PoBillNum = = _d etail . PoBillNum & & p . IsDeleted = = false & & p . BillType = = 1 ) . GroupBy ( p = > new { p . PoBillNum , p . PoLine , p . PartCode } ) . Select ( p = > new { RejectSum = p . Sum ( itm = > itm . Qty ) , PoLine = p . Key . PoLine , PoBillNum = p . Key . PoBillNum , PartCode = p . Key . PartCode } ) ;
var asn = db . TB_ASN_DETAIL . Where ( p = > p . PoBillNum = = _d etail . PoBillNum & & p . IsDeleted = = false & & p . State = = ( int ) AsnState . Ship ) . GroupBy ( p = > new { p . PoBillNum , p . PoLine , p . PartCode } ) . Select ( p = > new { AsSum = p . Sum ( itm = > itm . Qty ) , PoLine = p . Key . PoLine , PoBillNum = p . Key . PoBillNum , PartCode = p . Key . PartCode } ) ;
//var arrive = db.TB_ARRIVE_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.BillType == (int)ArriveBillType.Receive).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
_d etail . PartDesc1 = _d etail . PartDesc1 + _d etail . PartDesc2 ;
rec . ToList ( ) . ForEach ( itm = >
{
if ( _d etail . PoBillNum = = itm . PoBillNum & & _d etail . PoLine = = itm . PoLine & & _d etail . PartCode = = itm . PartCode )
{
_d etail . ReceivedQty = itm . ReceiveSum ;
}
} ) ;
reject . ToList ( ) . ForEach ( itm = >
{
if ( _d etail . PoBillNum = = itm . PoBillNum & & _d etail . PoLine = = itm . PoLine & & _d etail . PartCode = = itm . PartCode )
{
_d etail . RejectQty = itm . RejectSum . ToString ( ) ;
}
} ) ;
asn . ToList ( ) . ForEach ( itm = >
{
if ( _d etail . PoBillNum = = itm . PoBillNum & & _d etail . PoLine = = itm . PoLine & & _d etail . PartCode = = itm . PartCode )
{
_d etail . ShippedQty = itm . AsSum ;
}
} ) ;
//_ask.ToList().ForEach(itm =>
//{
// if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
// {
// _detail.TempQty = itm.AskSum;
// }
//});
//arrive.ToList().ForEach(itm =>
//{
// if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
// {
// _detail.ArriveQty = itm.ArriveSum.ToString();
// }
//});
}
}
_l s = _l ist ;
}
return _l s ;
}
public static List < V_TB_PO_DETAIL > COMPARE_PO ( string p_number )
{
List < V_TB_PO_DETAIL > _l s = new List < V_TB_PO_DETAIL > ( ) ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l ist = db . V_TB_PO_DETAIL . Where ( p = > p . PoBillNum = = p_number ) . ToList ( ) ;
if ( _l ist . Count > 0 )
{
//var _detail = p_list[0];
foreach ( V_TB_PO_DETAIL _d etail in _l ist )
{
//var _ask = db.TB_ASK_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { AskSum = p.Sum(itm => itm.AskQty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
var rec = db . TB_RECEIVE_DETAIL . Where ( p = > p . PoBillNum = = _d etail . PoBillNum & & p . IsDeleted = = false & & p . BillType = = 0 ) . GroupBy ( p = > new { p . PoBillNum , p . PoLine , p . PartCode } ) . Select ( p = > new { ReceiveSum = p . Sum ( itm = > itm . Qty ) , PoLine = p . Key . PoLine , PoBillNum = p . Key . PoBillNum , PartCode = p . Key . PartCode } ) ;
var reject = db . TB_RECEIVE_DETAIL . Where ( p = > p . PoBillNum = = _d etail . PoBillNum & & p . IsDeleted = = false & & p . BillType = = 1 ) . GroupBy ( p = > new { p . PoBillNum , p . PoLine , p . PartCode } ) . Select ( p = > new { RejectSum = p . Sum ( itm = > itm . Qty ) , PoLine = p . Key . PoLine , PoBillNum = p . Key . PoBillNum , PartCode = p . Key . PartCode } ) ;
var asn = db . TB_ASN_DETAIL . Where ( p = > p . PoBillNum = = _d etail . PoBillNum & & p . IsDeleted = = false & & p . State = = ( int ) AsnState . Ship ) . GroupBy ( p = > new { p . PoBillNum , p . PoLine , p . PartCode } ) . Select ( p = > new { AsSum = p . Sum ( itm = > itm . Qty ) , PoLine = p . Key . PoLine , PoBillNum = p . Key . PoBillNum , PartCode = p . Key . PartCode } ) ;
//var arrive = db.TB_ARRIVE_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.BillType == (int)ArriveBillType.Receive).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
_d etail . PartDesc1 = _d etail . PartDesc1 + _d etail . PartDesc2 ;
rec . ToList ( ) . ForEach ( itm = >
{
if ( _d etail . PoBillNum = = itm . PoBillNum & & _d etail . PoLine = = itm . PoLine & & _d etail . PartCode = = itm . PartCode )
{
_d etail . ReceivedQty = itm . ReceiveSum ;
}
} ) ;
reject . ToList ( ) . ForEach ( itm = >
{
if ( _d etail . PoBillNum = = itm . PoBillNum & & _d etail . PoLine = = itm . PoLine & & _d etail . PartCode = = itm . PartCode )
{
_d etail . RejectQty = itm . RejectSum . ToString ( ) ;
}
} ) ;
asn . ToList ( ) . ForEach ( itm = >
{
if ( _d etail . PoBillNum = = itm . PoBillNum & & _d etail . PoLine = = itm . PoLine & & _d etail . PartCode = = itm . PartCode )
{
_d etail . ShippedQty = itm . AsSum ;
}
} ) ;
//_ask.ToList().ForEach(itm =>
//{
// if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
// {
// _detail.TempQty = itm.AskSum;
// }
//});
//arrive.ToList().ForEach(itm =>
//{
// if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
// {
// _detail.ArriveQty = itm.ArriveSum.ToString();
// }
//});
}
}
_l s = _l ist ;
}
return _l s ;
}
public static ResultObject < bool > Save_Reject ( List < V_TB_RECEIVE_DETAIL > p_list )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l s = p_list . Select ( p = > p . UID ) . ToList ( ) ;
var _l ist = db . TB_RECEIVE_DETAIL . Where ( p = > _l s . Contains ( p . UID ) ) . ToList ( ) ;
_l ist . ForEach ( p = > {
var _ entity = p_list . Where ( itm = > itm . UID = = p . UID ) . FirstOrDefault ( ) ;
if ( _ entity ! = null )
{
p . Remark = _ entity . Remark ;
//p.AsnBillNum = _entity.AsnBillNum;
}
} ) ;
db . TB_RECEIVE_DETAIL . AddOrUpdate ( _l ist . ToArray ( ) ) ;
int state = db . SaveChanges ( ) ;
if ( state ! = - 1 )
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
}
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Save_ASK_TO_ASN" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Save_ASK_TO_ASN" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Save_ASK_TO_ASN" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASK_CONTROLLER ) , "Save_ASK_TO_ASN" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
/// <summary>
/// 获取退货数量
/// </summary>
/// <param name="p_list"></param>
/// <returns></returns>
public static List < V_TB_ASN_DETAIL > Get_V_TB_ASN_DETAIL ( List < V_TB_ASN_DETAIL > p_list )
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
p_list . ForEach ( itm = >
{
var _ sum = db . V_TB_RECEIVE_DETAIL . Where ( p = > p . AsnBillNum = = itm . AsnBillNum & & p . PartCode = = itm . PartCode & & p . Batch = = itm . Batch & & p . IsDeleted = = false & & p . VendBatch = = itm . VendBatch & & p . BillType_DESC = = "退货单" ) . Select ( p = > p . Qty ) . DefaultIfEmpty ( ) . Sum ( ) ;
itm . CanRejectQty = itm . Qty - _ sum ;
} ) ;
}
return p_list ;
}
/// <summary>
/// 数据导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_buyer"></param>
/// <param name="p_site"></param>
/// <param name="p_time"></param>
/// <returns></returns>
public static ResultObject < bool > EXCEL_RECEIVE ( List < SCP_ASN_EXCEL > p_order_list , string p_creator , string p_buyer , string p_site , DateTime p_time )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
int number = 1 ;
List < string > lineError = new List < string > ( ) ;
List < string > ErrorList = new List < string > ( ) ;
p_order_list . ForEach
( p = >
{
var _l s = CheckExcel ( db , p ) ;
if ( _l s . Count > 0 )
{
lineError . Add ( number . ToString ( ) ) ;
ErrorList . Add ( string . Join ( "<br>" , _l s . ToArray ( ) ) ) ;
}
number + + ;
} ) ;
if ( lineError . Count > 0 )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . MessageList . AddRange ( ErrorList ) ;
_ ret . Result = false ;
}
else
{
var GroupList = p_order_list . GroupBy ( p = > new { p . 采 购 订 单 号 , p . 行 号 , p . 零 件 编 号 , p . 价 格 , p . 供 应 商 编 码 , p . 单 位 } ) . Select ( p = > new { 数 量 = p . Sum ( itm = > decimal . Parse ( itm . 数 量 ) ) , 行 号 = p . Key . 行 号 , 采 购 订 单 号 = p . Key . 采 购 订 单 号 , p . Key . 零 件 编 号 , p . Key . 价 格 , p . Key . 供 应 商 编 码 , p . Key . 单 位 } ) . ToList ( ) ;
var OrderList = GroupList . GroupBy ( p = > p . 采 购 订 单 号 ) . ToList ( ) ;
OrderList . ForEach ( ( p ) = >
{
var list_distinct = p . GroupBy ( t = > new { t . 零 件 编 号 , t . 行 号 } ) . ToList ( ) ;
var list = p . ToList ( ) ;
if ( list_distinct . Count < list . Count )
{
_ ret . MessageList . Add ( "相同组号,存在同一编号、行号的数据" ) ;
return ;
}
if ( list . Count > 0 )
{
var _ entity = list . FirstOrDefault ( ) ;
TB_ASK _ ask = new TB_ASK ( ) ;
_ ask . AskBillNum = SCP_BILLCODE_CONTROLLER . MakeASKCode ( ) ;
_ ask . State = ( int ) AskState . Receive ;
_ ask . PoBillNum = _ entity . 采 购 订 单 号 . ToUpper ( ) ;
_ ask . ModType = ( int ) BillModType . Contract ;
_ ask . Site = p_site ;
_ ask . BeginTime = p_time ;
_ ask . Buyer = p_creator ;
_ ask . BuyerPhone = "" ;
_ ask . ErpBillNum = _ entity . 采 购 订 单 号 . ToUpper ( ) ;
_ ask . EndTime = p_time ;
_ ask . CreateTime = p_time ;
_ ask . CreateUser = p_creator ;
_ ask . VendId = _ entity . 供 应 商 编 码 . ToUpper ( ) ;
_ ask . GUID = Guid . NewGuid ( ) ;
_ ask . IsDeleted = false ;
db . TB_ASK . Add ( _ ask ) ;
TB_ASN _ asn = new TB_ASN ( ) ;
_ asn . AsnBillNum = SCP_BILLCODE_CONTROLLER . MakeASNCode ( ) ;
_ asn . AskBillNum = _ ask . AskBillNum ;
_ asn . VendId = _ entity . 供 应 商 编 码 . ToUpper ( ) ; ;
_ asn . State = ( int ) AsnState . Receive ;
_ asn . PoBillNum = _ entity . 采 购 订 单 号 . ToUpper ( ) ;
_ asn . Site = p_site ;
_ asn . CreateTime = p_time ;
_ asn . CreateUser = p_creator ;
_ asn . UpdateTime = p_time ;
_ asn . UpdateUser = p_creator ;
_ asn . ShipTime = p_time ;
_ asn . ShipUser = p_creator ;
_ asn . ReceiveTime = p_time ;
_ asn . ReceiveUser = p_creator ;
_ asn . GUID = Guid . NewGuid ( ) ;
_ asn . IsDeleted = false ;
db . TB_ASN . Add ( _ asn ) ;
list . ForEach ( ( itm ) = >
{
TB_ASK_DETAIL _ t_ASK_Detail = new TB_ASK_DETAIL ( ) ;
_ t_ASK_Detail . PoLine = Int32 . Parse ( itm . 行 号 ) ;
_ t_ASK_Detail . Currency = "" ;
_ t_ASK_Detail . AskBillNum = _ ask . AskBillNum ;
_ t_ASK_Detail . PoBillNum = _ ask . PoBillNum ;
_ t_ASK_Detail . PoUnit = itm . 单 位 ;
_ t_ASK_Detail . CreateTime = DateTime . Now ;
_ t_ASK_Detail . CreateUser = _ ask . CreateUser ;
_ t_ASK_Detail . PartCode = itm . 零 件 编 号 . ToUpper ( ) ;
_ t_ASK_Detail . BeginTime = p_time ;
_ t_ASK_Detail . EndTime = p_time ;
_ t_ASK_Detail . TempQty = itm . 数 量 ;
_ t_ASK_Detail . AskQty = itm . 数 量 ;
_ t_ASK_Detail . IsDeleted = false ;
_ t_ASK_Detail . LocUnit = itm . 单 位 ;
_ t_ASK_Detail . UnConv = 1 ;
_ t_ASK_Detail . State = _ ask . State ;
_ t_ASK_Detail . Price = string . IsNullOrEmpty ( itm . 价 格 ) ? 0 : decimal . Parse ( itm . 价 格 ) ;
_ t_ASK_Detail . GUID = Guid . NewGuid ( ) ;
db . TB_ASK_DETAIL . Add ( _ t_ASK_Detail ) ;
TB_ASN_DETAIL _ t_ASN_Detail = new TB_ASN_DETAIL ( ) ;
_ t_ASN_Detail . AsnBillNum = _ asn . AsnBillNum ;
_ t_ASN_Detail . PoLine = Int32 . Parse ( itm . 行 号 ) ;
_ t_ASN_Detail . Currency = "" ;
_ t_ASN_Detail . PoBillNum = _ asn . PoBillNum ;
_ t_ASN_Detail . PoUnit = itm . 单 位 ;
_ t_ASN_Detail . CreateTime = DateTime . Now ;
_ t_ASN_Detail . CreateUser = _ asn . CreateUser ;
_ t_ASN_Detail . PartCode = itm . 零 件 编 号 . ToUpper ( ) ;
_ t_ASN_Detail . Batch = p_time . ToString ( "yyyyMMdd" ) ;
_ t_ASN_Detail . VendBatch = p_time . ToString ( "yyyyMMdd" ) ;
_ t_ASN_Detail . Qty = itm . 数 量 ;
_ t_ASN_Detail . State = ( int ) AsnState . Receive ;
_ t_ASN_Detail . CreateTime = p_time ;
_ t_ASN_Detail . CreateUser = p_creator ;
_ t_ASN_Detail . IsDeleted = false ;
_ t_ASN_Detail . GUID = Guid . NewGuid ( ) ;
_ t_ASN_Detail . PoUnit = itm . 单 位 ;
_ t_ASN_Detail . ProduceDate = p_time ;
db . TB_ASN_DETAIL . Add ( _ t_ASN_Detail ) ;
var _ reclist = p_order_list . Where ( t = > t . 零 件 编 号 = = itm . 零 件 编 号 & & t . 采 购 订 单 号 = = itm . 采 购 订 单 号 & & t . 行 号 = = itm . 行 号 ) . GroupBy ( t = > t . 收 货 单 号 ) . ToList ( ) ;
_ reclist . ForEach ( ( q ) = >
{
var reclist = q . FirstOrDefault ( ) ;
TB_RECEIVE _ rec = new TB_RECEIVE ( ) ;
_ rec . RecvBillNum = reclist . 收 货 单 号 ;
_ rec . State = ( int ) FormState . 开 放 ;
_ rec . Remark = _ ask . AskBillNum ;
_ rec . CreateTime = p_time ;
_ rec . CreateUser = p_creator ;
_ rec . IsDeleted = false ;
_ rec . GUID = System . Guid . NewGuid ( ) ;
_ rec . BillType = 0 ;
_ rec . PoBillNum = reclist . 采 购 订 单 号 . ToUpper ( ) ;
_ rec . AsnBillNum = reclist . 采 购 订 单 号 . ToUpper ( ) ;
_ rec . Site = p_site ;
_ rec . VendId = reclist . 供 应 商 编 码 . ToUpper ( ) ;
_ rec . ShipTime = p_time ;
db . TB_RECEIVE . Add ( _ rec ) ;
var _ recdetaillist = p_order_list . Where ( f = > f . 收 货 单 号 = = reclist . 收 货 单 号 ) . ToList ( ) ;
_ recdetaillist . ForEach ( ( n ) = >
{
TB_RECEIVE_DETAIL _ t_RECEIVE_Detail = new TB_RECEIVE_DETAIL ( ) ;
_ t_RECEIVE_Detail . RecvBillNum = n . 收 货 单 号 ;
_ t_RECEIVE_Detail . PoBillNum = n . 采 购 订 单 号 . ToUpper ( ) ;
_ t_RECEIVE_Detail . PoLine = Int32 . Parse ( n . 行 号 ) ;
_ t_RECEIVE_Detail . PartCode = n . 零 件 编 号 . ToUpper ( ) ;
_ t_RECEIVE_Detail . Batch = n . 批 次 ;
_ t_RECEIVE_Detail . VendBatch = n . 供 应 商 批 次 ;
_ t_RECEIVE_Detail . PoUnit = n . 单 位 ;
_ t_RECEIVE_Detail . LocUnit = "" ;
_ t_RECEIVE_Detail . Qty = decimal . Parse ( n . 数 量 ) ;
_ t_RECEIVE_Detail . State = ( int ) FormState . 开 放 ;
_ t_RECEIVE_Detail . Remark = _ ask . AskBillNum ;
_ t_RECEIVE_Detail . CreateTime = p_time ;
_ t_RECEIVE_Detail . CreateUser = p_creator ;
_ t_RECEIVE_Detail . IsDeleted = false ;
_ t_RECEIVE_Detail . GUID = System . Guid . NewGuid ( ) ;
_ t_RECEIVE_Detail . BillType = 0 ;
db . TB_RECEIVE_DETAIL . Add ( _ t_RECEIVE_Detail ) ;
} ) ;
} ) ;
} ) ;
}
else
{
_ ret . MessageList . Add ( "请检查数据后,重新导入!" ) ;
return ;
}
if ( _ ret . MessageList . Count = = 0 )
{
int state = db . SaveChanges ( ) ;
if ( state ! = - 1 )
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
}
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
}
}
) ;
}
}
}
catch ( System . Data . Entity . Validation . DbEntityValidationException dbEx ) //捕获实体验证异常
{
var sb = new StringBuilder ( ) ;
foreach ( var error in dbEx . EntityValidationErrors . ToList ( ) )
{
error . ValidationErrors . ToList ( ) . ForEach ( i = >
{
sb . AppendFormat ( "表:{0},字段:{1},信息:{2}\r\n" , error . Entry . Entity . GetType ( ) . Name , i . PropertyName , i . ErrorMessage ) ;
} ) ;
}
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( dbEx ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "EXCEL_RECEIVE" , sb . ToString ( ) ) ;
throw new ScpException ( ResultCode . DbEntityValidationException , sb . ToString ( ) , "字段验证失败" + sb . ToString ( ) ) ;
}
catch ( OptimisticConcurrencyException ex ) //并发冲突异常
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "EXCEL_RECEIVE" , ex . ToString ( ) ) ;
throw new ScpException ( ResultCode . Exception , "9999" , ex . ToString ( ) ) ;
}
catch ( ScpException ex )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( ex ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "EXCEL_RECEIVE" , ex . ToString ( ) ) ;
if ( ex . InnerException ! = null & & ex . InnerException . GetType ( ) = = typeof ( UpdateException ) )
{
var inner = ( UpdateException ) ex . InnerException ;
throw new ScpException ( ResultCode . Exception , "0000" , ex . ToString ( ) ) ;
}
else
{
if ( ex . InnerException ! = null ) throw ex . InnerException ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_RECIVECE_CONTROLLER ) , "EXCEL_RECEIVE" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
private static List < string > CheckExcel ( ScpEntities db , SCP_ASN_EXCEL p_excel )
{
List < string > ErrorList = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( p_excel . 采 购 订 单 号 ) )
{
int count = db . TB_PO_DETAIL . Count ( p = > p . PoBillNum = = p_excel . 采 购 订 单 号 & & p . PartCode = = p_excel . 零 件 编 号 & & p . PoLine . ToString ( ) = = p_excel . 行 号 ) ;
if ( count = = 0 )
{
ErrorList . Add ( string . Format ( "订单编号{0}零件号{1}行号{2}不存在!" , p_excel . 采 购 订 单 号 , p_excel . 零 件 编 号 , p_excel . 行 号 ) ) ;
}
}
else
{
ErrorList . Add ( string . Format ( "订单编号为空!" ) ) ;
}
if (
string . IsNullOrEmpty ( p_excel . 收 货 单 号 ) | |
string . IsNullOrEmpty ( p_excel . 采 购 订 单 号 ) | |
string . IsNullOrEmpty ( p_excel . 供 应 商 编 码 ) | |
string . IsNullOrEmpty ( p_excel . 价 格 ) | |
string . IsNullOrEmpty ( p_excel . 零 件 编 号 ) | |
string . IsNullOrEmpty ( p_excel . 行 号 ) | |
string . IsNullOrEmpty ( p_excel . 批 次 ) | |
string . IsNullOrEmpty ( p_excel . 数 量 ) | |
string . IsNullOrEmpty ( p_excel . 单 位 ) | |
string . IsNullOrEmpty ( p_excel . 价 格 ) )
{
ErrorList . Add ( string . Format ( "收货单号【{1}】零件号【{0}】有填写为空!" , p_excel . 零 件 编 号 , p_excel . 收 货 单 号 ) ) ;
}
return ErrorList ;
}
}
}