using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.Entity.Migrations ;
using System.Data.Entity.Validation ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using CK.SCP.Models ;
using CK.SCP.Models.Enums ;
using CK.SCP.Models.ScpEntity ;
using CK.SCP.Utils ;
using System.Data.Entity.Core ;
using CK.SCP.Models.AppBoxEntity ;
using CK.SCP.Models.ScpEntity.ExcelExportEnttity ;
using System.Data.SqlClient ;
namespace CK.SCP.Controller
{
public class SCP_ASN_CONTROLLER
{
public static DataTable Get_CUSTOM_PAGE_List ( V_TB_ASN p_entity )
{
string _ sql = "SELECT COUNT(*) 标包数量,SUM(Qty) 发货数量,BillNum 发货单号,PoBillLine 行号,PoUnit 单位,PartDesc1 +PartDesc2 as 零件描述,a.PartCode 零件编号,'' as 分包数量\n" +
" from TS_BARCODE_CUSTOM A left join TA_PART B ON A.PartCode=B.PartCode AND A.Site=B.Site where BillNum='{0}' GROUP by a.PartCode,BillNum,PoBillLine,PoUnit,PartDesc1,PartDesc2" ;
string _ sql1 = "select qty FROM [TS_BARCODE_CUSTOM] where billnum ='{0}' and partcode='{1}'" ;
DataTable dt = 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 cmd = new SqlCommand ( ) ;
cmd . Connection = conn ;
cmd . CommandText = string . Format ( _ sql , p_entity . AsnBillNum ) ;
SqlDataAdapter adapter = new SqlDataAdapter ( cmd ) ;
adapter . Fill ( dt ) ;
foreach ( DataRow row in dt . Rows )
{
DataTable dt1 = new DataTable ( ) ;
SqlCommand cmd1 = new SqlCommand ( ) ;
cmd1 . Connection = conn ;
cmd1 . CommandText = string . Format ( _ sql1 , p_entity . AsnBillNum , row [ "零件编号" ] . ToString ( ) ) ;
SqlDataAdapter adapter1 = new SqlDataAdapter ( cmd1 ) ;
adapter1 . Fill ( dt1 ) ;
if ( dt1 . Rows . Count > 0 )
{
List < string > _l s = new List < string > ( ) ;
foreach ( DataRow _ row in dt1 . Rows )
{
_l s . Add ( _ row [ 0 ] . ToString ( ) ) ;
}
row [ "分包数量" ] = string . Join ( "(" + row [ "单位" ] . ToString ( ) + ")" + ";" , _l s . ToArray ( ) ) + "(" + row [ "单位" ] . ToString ( ) + ")" ;
}
}
}
catch ( Exception e )
{
conn . Close ( ) ;
throw e ;
}
return dt ;
}
public static void Get_V_TB_ASN_List ( V_TB_ASN p_entity , Action < ResultObject < IQueryable < V_TB_ASN > > > p_action , string p_language = "CN" )
{
ResultObject < IQueryable < V_TB_ASN > > _ ret = new ResultObject < IQueryable < V_TB_ASN > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_ASN > q = db . V_TB_ASN ;
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 . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum = = p_entity . PoBillNum ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( p_entity . State ! = null )
{
q = q . Where ( p = > p . State = = p_entity . State ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ShipUser ) )
{
q = q . Where ( p = > p . ShipUser . Contains ( p_entity . ShipUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ReceiveUser ) )
{
q = q . Where ( p = > p . ReceiveUser . Contains ( p_entity . ReceiveUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ErpBillNum ) )
{
q = q . Where ( p = > p . ErpBillNum . Contains ( p_entity . ErpBillNum ) ) ;
}
if ( p_entity . ModType ! = null )
{
q = q . Where ( p = > p . ModType = = p_entity . ModType ) ;
}
//if (!string.IsNullOrEmpty(p_entity.Contacter))
//{
// q = q.Where(p => p.Contacter.Contains(p_entity.Contacter));
//}
if ( p_entity . ShipTime ! = null )
{
q = q . Where ( p = > p . ShipTime = = p_entity . ShipTime ) ;
}
if ( p_entity . ReceiveTime ! = null )
{
q = q . Where ( p = > p . ReceiveTime = = p_entity . ReceiveTime ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Buyer ) )
{
q = q . Where ( p = > p . Buyer . Contains ( p_entity . Buyer ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . State_DESC ) )
{
q = q . Where ( p = > p . State_DESC . Contains ( p_entity . State_DESC ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ModType_DESC ) )
{
q = q . Where ( p = > p . ModType_DESC . Contains ( p_entity . ModType_DESC ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . UpdateUser ) )
{
q = q . Where ( p = > p . UpdateUser . Contains ( p_entity . UpdateUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . UpdateInfo ) )
{
q = q . Where ( p = > p . UpdateInfo . Contains ( p_entity . UpdateInfo ) ) ;
}
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
if ( p_entity . UserInAddress ! = null & & p_entity . UserInAddress . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInAddress . Contains ( p . Site ) ) ;
}
if ( p_entity . UserInVendIds ! = null & & p_entity . UserInVendIds . Count > 0 )
{
q = q . Where ( p = > p_entity . UserInVendIds . Contains ( p . VendId ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . SubSite ) )
{
q = q . Where ( p = > p . SubSite = = p_entity . SubSite ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Extend1 ) )
{
q = q . Where ( p = > p . Extend1 = = p_entity . Extend1 ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Extend2 ) )
{
q = q . Where ( p = > p . Extend2 = = p_entity . Extend2 ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Extend3 ) )
{
q = q . Where ( p = > p . Extend3 = = p_entity . Extend3 ) ;
}
_ 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_ASN_CONTROLLER ) , "Get_V_TB_ASN_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_ASN_CONTROLLER ) , "Get_V_TB_ASN_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_ASN_CONTROLLER ) , "Get_V_TB_ASN_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_ASN_CONTROLLER ) , "Get_V_TB_ASN_List" , e . Message ) ;
throw e ;
}
}
public static void Get_TB_Pallet_List ( V_TB_PALLETS p_entity , Action < ResultObject < IQueryable < V_TB_PALLETS > > > p_action )
{
ResultObject < IQueryable < V_TB_PALLETS > > _ ret = new ResultObject < IQueryable < V_TB_PALLETS > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_PALLETS > q = db . V_TB_PALLETS ;
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( p_entity . Qty ! = 0 )
{
q = q . Where ( p = > p . Qty = = p_entity . Qty ) ;
}
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 . VendId ) )
{
q = q . Where ( p = > p . VendId . Contains ( p_entity . VendId ) ) ;
}
_ 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_ASN_CONTROLLER ) , "Get_TB_Pallet_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_ASN_CONTROLLER ) , "Get_TB_Pallet_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_ASN_CONTROLLER ) , "Get_TB_Pallet_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_ASN_CONTROLLER ) , "Get_TB_Pallet_List" , e . Message ) ;
throw e ;
}
}
public static void Get_V_TB_ASN_DETAIL_List ( V_TB_ASN_DETAIL p_entity , Action < ResultObject < IQueryable < V_TB_ASN_DETAIL > > > p_action )
{
ResultObject < IQueryable < V_TB_ASN_DETAIL > > _ ret = new ResultObject < IQueryable < V_TB_ASN_DETAIL > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_ASN_DETAIL > q = db . V_TB_ASN_DETAIL ;
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
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 . PoUnit ) )
{
q = q . Where ( p = > p . PoUnit . Contains ( p_entity . PoUnit ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . LocUnit ) )
{
q = q . Where ( p = > p . LocUnit . Contains ( p_entity . LocUnit ) ) ;
}
if ( p_entity . Price ! = 0 )
{
q = q . Where ( p = > p . Price = = p_entity . Price ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Currency ) )
{
q = q . Where ( p = > p . Currency . Contains ( p_entity . Currency ) ) ;
}
if ( p_entity . PackQty ! = 0 )
{
q = q . Where ( p = > p . PackQty = = p_entity . PackQty ) ;
}
if ( p_entity . UnConv ! = 0 )
{
q = q . Where ( p = > p . UnConv = = p_entity . UnConv ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . DockCode ) )
{
q = q . Where ( p = > p . DockCode . Contains ( p_entity . DockCode ) ) ;
}
if ( p_entity . State ! = null )
{
q = q . Where ( p = > p . State = = p_entity . State ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . UpdateUser ) )
{
q = q . Where ( p = > p . UpdateUser . Contains ( p_entity . UpdateUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . UpdateInfo ) )
{
q = q . Where ( p = > p . UpdateInfo . Contains ( p_entity . UpdateInfo ) ) ;
}
if ( p_entity . IsDeleted ! = false )
{
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CurrencyDesc ) )
{
q = q . Where ( p = > p . CurrencyDesc . Contains ( p_entity . CurrencyDesc ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Site ) )
{
q = q . Where ( p = > p . Site . Contains ( p_entity . Site ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( p_entity . Qty ! = 0 )
{
q = q . Where ( p = > p . Qty = = p_entity . Qty ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendBatch ) )
{
q = q . Where ( p = > p . VendBatch . Contains ( p_entity . VendBatch ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Batch ) )
{
q = q . Where ( p = > p . Batch . Contains ( p_entity . Batch ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId . Contains ( p_entity . VendId ) ) ;
}
_ 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_ASN_CONTROLLER ) , "Get_V_TB_ASN_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_ASN_CONTROLLER ) , "Get_V_TB_ASN_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_ASN_CONTROLLER ) , "Get_V_TB_ASN_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_ASN_CONTROLLER ) , "Get_V_TB_ASN_DETAIL_List" , e . Message ) ;
throw e ;
}
}
public static ResultObject < bool > Save_TB_ASN_STATE ( List < string > p_list , AsnState p_state )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
if ( db . TB_ASN . Where ( p = > p_list . Contains ( p . AsnBillNum ) & & p . IsDeleted = = false ) . Count ( ) = = 0 )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = "存在删除记录不能操作!" ;
}
else
{
if ( p_state = = AsnState . New )
{
var _l s = db . TB_ASN . Where ( p = > p_list . Contains ( p . AsnBillNum ) ) . ToList ( ) ;
_l s . ForEach ( p = > p . State = ( int ) AskState . New ) ;
db . TB_ASN . AddOrUpdate ( p = > p . AsnBillNum , _l s . ToArray ( ) ) ;
}
//if (p_state == AsnState.Ship)
//{
// var _ls = db.TB_ASN.Where(p => p_list.Contains(p.AsnBillNum) && p.IsDeleted == false).ToList();
// if (_ls.Count(p => p.State == (int)ShipState.New) == _ls.Count)
// {
// var p = _ls[0];
// #region 代办流程提示收货人
// TB_PENING_ITEMS pending = new TB_PENING_ITEMS();
// pending.ITEM_NO = p.AsnBillNum;
// pending.ITEM_TYPE = (int)PENDING_MESSAGE_TYPE.NEW_ASN;
// pending.ITEM_STATE = (int)PENDING_STATE.WAITING;
// pending.GUID = Guid.NewGuid();
// pending.VEND_ID = p.VendId;
// pending.ROLE_NAME = "物流人员";
// pending.SENDER = p.CreateUser;
// pending.SENDING_TIME = p.CreateTime;
// pending.RENEWER = p.CreateUser;
// pending.RENEW_TIME = p.CreateTime;
// pending.ITEM_CONTENT = string.Format("订单编号{0}发货单编号{1}已发货", p.PoBillNum, p.AsnBillNum);
// db.TB_PENING_ITEMS.Add(pending);
// #endregion;
// }
// else
// {
// _ret.State = ReturnStatus.Failed;
// _ret.Result = false;
// _ret.Message = "选择数据有不是新建状态单据!";
// }
//}
if ( p_state = = AsnState . Reject )
{
var _l s = db . TB_ASN . Where ( p = > p_list . Contains ( p . AsnBillNum ) ) . ToList ( ) ;
int count = _l s . Count ( p = > p . State = = ( int ) AsnState . New ) ;
if ( _l s . Count = = count )
{
List < string > _ askbill = new List < string > ( ) ;
_l s . ForEach ( p = > {
p . State = ( int ) AskState . Reject ;
p . IsDeleted = true ;
var asnDetail = db . TB_ASN_DETAIL . Where ( itm = > itm . AsnBillNum = = p . AsnBillNum ) . ToList ( ) ;
asnDetail . ForEach ( itm = > {
itm . IsDeleted = true ;
itm . State = ( int ) AskState . Reject ;
} ) ;
db . TB_ASN_DETAIL . AddOrUpdate ( itm = > itm . UID , asnDetail . ToArray ( ) ) ;
} ) ;
db . TB_ASN . AddOrUpdate ( p = > p . AsnBillNum , _l s . ToArray ( ) ) ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . Message = string . Format ( "选择记录中有,不是新建状态不能作废!" ) ;
}
}
if ( string . IsNullOrEmpty ( _ 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_ASN_CONTROLLER ) , "Save_TB_ASN_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_ASN_CONTROLLER ) , "Save_TB_ASN_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_ASN_CONTROLLER ) , "Save_TB_ASN_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_ASN_CONTROLLER ) , "Save_TB_ASN_STATE" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static DataSet ASN_REPORT ( string p_AsnBillNum )
{
DataSet ds = new DataSet ( ) ;
SCP_ASN_CONTROLLER . Get_V_TB_ASN_List ( new V_TB_ASN { AsnBillNum = p_AsnBillNum } , ( ret ) = >
{
if ( ret . State = = ReturnStatus . Succeed )
{
if ( ret . Result . Count ( ) > 0 )
{
var _ asn = ret . Result . FirstOrDefault ( ) ;
V_ASN_PRINT _ print = new V_ASN_PRINT ( ) ;
_ print . FileNo = "" ;
_ print . DeliveryNo = _ asn . AsnBillNum ;
_ print . ChineseAddress = _ asn . Site_Desc ;
_ print . EnglishAddress = "" ;
_ print . SupplierNo = _ asn . VendId ;
_ print . SupplierName = _ asn . VendName ;
_ print . SupplierContacter = _ asn . ShipUser ;
_ print . DueDeliveryDate = _ asn . ReceiveTime . ToString ( ) ;
_ print . MaterialPlanner = _ asn . Buyer ;
_ print . CAAIPhone = "" ;
_ print . CAAIFax = "" ;
_ print . Site = _ asn . Site ;
_ print . Total = "0" ;
using ( AppBoxContext _ appdb = EntitiesFactory . CreateAppBoxInstance ( ) )
{
StringBuilder _ buffer = new StringBuilder ( ) ;
var _l s = _ appdb . Users . Where ( p = > p . Roles . Select ( itm = > itm . Name ) . Contains ( "物流人员" ) & & p . TA_FACTORY . Select ( itm = > itm . ErpDomain ) . Contains ( _ asn . Site ) ) . ToList ( ) ;
_l s . ForEach ( itm = >
{
_ buffer . Append ( itm . ChineseName + "/" + itm . CellPhone + ";" ) ;
} ) ;
_ print . CAAIPhone = _ buffer . ToString ( ) ;
}
var dt = ConvertHelper . ToDataTable ( new List < V_ASN_PRINT > { _ print } ) ;
ds . Tables . Add ( dt ) ;
List < V_TB_PO_DETAIL > _l st = new List < V_TB_PO_DETAIL > ( ) ;
SCP_PO_CONTROLLER . Get_V_TB_PO_DETAIL_List ( new V_TB_PO_DETAIL ( ) { PoBillNum = _ asn . PoBillNum } , rs = > {
if ( rs . State = = ReturnStatus . Succeed )
{
_l st = rs . Result . ToList ( ) ;
}
} ) ;
SCP_ASN_CONTROLLER . Get_V_TB_ASN_DETAIL_List ( new V_TB_ASN_DETAIL ( ) { AsnBillNum = p_AsnBillNum } , ( retobj ) = >
{
if ( retobj . State = = ReturnStatus . Succeed )
{
List < V_ASN_PRINT_DETAIL > _l sDetail = new List < V_ASN_PRINT_DETAIL > ( ) ;
var _l s = retobj . Result . OrderByDescending ( p = > p . PoLine ) . ToList ( ) ;
_l s . ForEach ( p = >
{
V_ASN_PRINT_DETAIL _d etail = new V_ASN_PRINT_DETAIL ( ) ;
_d etail . PartNo = p . PartCode ;
_d etail . PartDesc = p . PartDesc1 ;
_d etail . Unit = p . PoUnit ;
_d etail . STD = p . PackQty . ToString ( ) ;
_d etail . Boxes = ( Math . Truncate ( ( p . Qty / p . PackQty ) ) + ( ( ( p . Qty % p . PackQty ) > 0 ) ? 1 : 0 ) ) . ToString ( ) ;
_d etail . DeliverQty = p . Qty . ToString ( ) ;
_d etail . ReceiveQty = p . Qty . ToString ( ) ;
_d etail . PoNo = p . PoBillNum + "." + p . AskBillNum ;
_d etail . LineNO = p . PoLine . ToString ( ) ;
_d etail . Memo = p . Remark ;
_d etail . Batch = p . Batch ;
_d etail . DockCode = p . DockCode ;
_d etail . ProjectId = _l st . Where ( itm = > itm . PartCode = = p . PartCode ) . FirstOrDefault ( ) . ProjectId ;
_l sDetail . Add ( _d etail ) ;
} ) ;
var tb = ConvertHelper . ToDataTable ( _l sDetail ) ;
ds . Tables . Add ( tb ) ;
}
} ) ;
}
}
} ) ;
return ds ;
}
public static DataSet ASN_PALLET_REPORT ( string p_AsnBillNum )
{
DataSet ds = new DataSet ( ) ;
SCP_ASN_CONTROLLER . Get_V_TB_ASN_List ( new V_TB_ASN { AsnBillNum = p_AsnBillNum } , ( ret ) = >
{
if ( ret . State = = ReturnStatus . Succeed )
{
if ( ret . Result . Count ( ) > 0 )
{
var _ asn = ret . Result . FirstOrDefault ( ) ;
V_ASN_PRINT _ print = new V_ASN_PRINT ( ) ;
_ print . FileNo = "" ;
_ print . DeliveryNo = _ asn . AsnBillNum ;
_ print . ChineseAddress = _ asn . Site_Desc ;
_ print . EnglishAddress = "" ;
_ print . SupplierNo = _ asn . VendId ;
_ print . SupplierName = _ asn . VendName ;
_ print . SupplierContacter = _ asn . ShipUser ;
_ print . DueDeliveryDate = _ asn . ReceiveTime . ToString ( ) ;
_ print . MaterialPlanner = _ asn . Buyer ;
_ print . CAAIPhone = "" ;
_ print . CAAIFax = "" ;
_ print . Total = "0" ;
using ( AppBoxContext _ appdb = EntitiesFactory . CreateAppBoxInstance ( ) )
{
StringBuilder _ buffer = new StringBuilder ( ) ;
var _l s = _ appdb . Users . Where ( p = > p . Roles . Select ( itm = > itm . Name ) . Contains ( "物流人员" ) ) . ToList ( ) ;
_l s . ForEach ( itm = >
{
_ buffer . Append ( itm . ChineseName + "/" + itm . CellPhone + ";" ) ;
} ) ;
_ print . CAAIPhone = _ buffer . ToString ( ) ;
}
SCP_ASN_CONTROLLER . Get_TB_Pallet_List ( new V_TB_PALLETS ( ) { AsnBillNum = p_AsnBillNum } , ( retobj ) = >
{
if ( retobj . State = = ReturnStatus . Succeed )
{
List < V_TB_PALLETS > _l sDetail = new List < V_TB_PALLETS > ( ) ;
var _l s = retobj . Result . ToList ( ) ;
decimal count = 0 ;
_l s . ForEach ( p = >
{
V_TB_PALLETS _d etail = new V_TB_PALLETS ( ) ;
_d etail . PartCode = p . PartCode ;
_d etail . PartName = p . PartName ;
_d etail . PalletNum = p . PalletNum ;
_d etail . Batch = p . Batch ;
_d etail . Qty = p . Qty ;
_d etail . Box = p . Box ;
count + = p . Qty ;
_l sDetail . Add ( _d etail ) ;
} ) ;
_ print . Total = count . ToString ( ) ;
var tb = ConvertHelper . ToDataTable ( _l sDetail ) ;
ds . Tables . Add ( tb ) ;
}
} ) ;
var dt = ConvertHelper . ToDataTable ( new List < V_ASN_PRINT > { _ print } ) ;
ds . Tables . Add ( dt ) ;
}
}
} ) ;
return ds ;
}
public static DataSet ARRIVE_REPORT ( string p_AsnBillNum )
{
DataSet ds = new DataSet ( ) ;
SCP_ASN_CONTROLLER . Get_V_TB_ASN_List ( new V_TB_ASN { AsnBillNum = p_AsnBillNum } , ( ret ) = > {
if ( ret . State = = ReturnStatus . Succeed )
{
if ( ret . Result . Count ( ) > 0 )
{
var _ asn = ret . Result . FirstOrDefault ( ) ;
V_ARRIVE_PRINT _ print = new V_ARRIVE_PRINT ( ) ;
if ( _ asn . ShipTime ! = null )
{
DateTime dttemp ;
if ( DateTime . TryParse ( _ asn . ShipTime . ToString ( ) , out dttemp ) )
{
_ print . ShipTimeDate = dttemp . ToString ( "yyyy-MM-dd" ) ; //发货日期
}
}
if ( _ asn . ReceiveTime ! = null )
{
DateTime dttemp ;
if ( DateTime . TryParse ( _ asn . ReceiveTime . ToString ( ) , out dttemp ) )
{
_ print . DueDeliveryDate = dttemp . ToString ( "yyyy-MM-dd" ) ; //到货日期
}
}
_ print . SupplierName = _ asn . VendName ; //发货单位
_ print . SupplierNo = _ asn . VendId ; //供应商代码
_ print . SupplierContacter = _ asn . ShipUser ; //供应商联系人
_ print . DeliveryNo = _ asn . AsnBillNum ;
_ print . ChineseAddress = _ asn . Site_Desc ;
_ print . EnglishAddress = "" ;
_ print . MaterialPlanner = _ asn . Buyer ; //采购联系人
_ print . MaterialPhone = _ asn . BuyerPhone ; //采购联系人电话
_ print . CAAIPhone = "" ;
_ print . CAAIFax = "" ;
_ print . STDCOUNT = "0" ;
var dt = ConvertHelper . ToDataTable ( new List < V_ARRIVE_PRINT > { _ print } ) ;
ds . Tables . Add ( dt ) ;
SCP_ASN_CONTROLLER . Get_V_TB_ASN_DETAIL_List ( new V_TB_ASN_DETAIL ( ) { AsnBillNum = p_AsnBillNum } , ( retobj ) = > {
decimal stdtemp = 0 ;
if ( retobj . State = = ReturnStatus . Succeed )
{
List < V_ARRIVE_PRINT_DETAIL > _l sDetail = new List < V_ARRIVE_PRINT_DETAIL > ( ) ;
var _l s = retobj . Result . ToList ( ) ;
_l s . ForEach ( p = > {
V_ARRIVE_PRINT_DETAIL _d etail = new V_ARRIVE_PRINT_DETAIL ( ) ;
_d etail . PartNo = p . PartCode ;
_d etail . PartDesc = p . PartDesc1 ;
_d etail . Unit = p . PoUnit ;
_d etail . STD = p . PackQty . ToString ( ) ;
_d etail . Boxes = ( Math . Truncate ( ( p . Qty / p . PackQty ) ) + ( ( ( p . Qty % p . PackQty ) > 0 ) ? 1 : 0 ) ) . ToString ( ) ;
_d etail . DeliverQty = p . Qty . ToString ( ) ;
_d etail . ReceiveQty = p . Qty . ToString ( ) ;
_d etail . PoNo = _ print . DeliveryNo + "(" + p . PoBillNum + ")" ;
_d etail . LineNO = p . PoLine . ToString ( ) ;
_d etail . Memo = p . Remark ;
_d etail . DockCode = p . DockCode ;
_d etail . ArriveState = GetArriveState ( p . PoBillNum , p . PoLine , p . PartCode , p . Batch ) ;
_d etail . SpecialState = string . Empty ;
_d etail . VendBatch = p . VendBatch ;
if ( p . ProduceDate ! = null )
{
DateTime dttemp ;
if ( DateTime . TryParse ( p . ProduceDate . ToString ( ) , out dttemp ) )
{
_d etail . ProduecDate = dttemp . ToString ( "yyyy-MM-dd" ) ; //到货日期
}
}
// stdtemp +=_detail.Boxes;
stdtemp + = Convert . ToDecimal ( _d etail . Boxes ) ;
_l sDetail . Add ( _d etail ) ;
} ) ;
ds . Tables [ 0 ] . Rows [ 0 ] [ "STDCOUNT" ] = stdtemp . ToString ( ) ;
var tb = ConvertHelper . ToDataTable ( _l sDetail ) ;
ds . Tables . Add ( tb ) ;
}
} ) ;
}
}
} ) ;
return ds ;
}
private static string GetArriveState ( string PoBillNum , int PoLine , string PartCode , string Batch )
{
string strResult = "未到货" ;
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
TB_ARRIVE_DETAIL det = db . TB_ARRIVE_DETAIL . FirstOrDefault ( p = > p . PoBillNum = = PoBillNum & & p . PoLine = = PoLine & & p . PartCode = = PartCode & & p . Batch = = Batch ) ;
if ( det ! = null )
{
strResult = "已到货" ;
}
}
return strResult ;
}
public static ResultObject < bool > Del_TB_ASN ( List < TB_ASN > p_entitys )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
foreach ( var itm in p_entitys )
{
db . TB_ASN . Remove ( itm ) ;
}
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_ASN_CONTROLLER ) , "Del_TB_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_ASN_CONTROLLER ) , "Del_TB_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_ASN_CONTROLLER ) , "Del_TB_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 ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASN_CONTROLLER ) , "Del_TB_ASN" , e . Message ) ; throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Save_TB_CREATE_BARCODE_CUSTOM ( List < V_TB_ASK_DETAIL_PACKAGE > p_list )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
List < TS_BARCODE_CUSTOM > _l s = new List < TS_BARCODE_CUSTOM > ( ) ;
if ( p_list . Count > 0 )
{
string _ asnBillNum = p_list [ 0 ] . PoBillNum ;
var _ asn = db . TB_PO . Where ( p = > p . IsDeleted = = false & & p . PoBillNum = = _ asnBillNum ) . FirstOrDefault ( ) ;
List < V_TB_ASK_DETAIL_PACKAGE > _ asnList = new List < V_TB_ASK_DETAIL_PACKAGE > ( ) ;
p_list . ForEach ( p = >
{
int _ qty = 0 ;
int _ packQty = 0 ;
if ( int . TryParse ( p . Qty . ToString ( ) , out _ qty ) & & int . TryParse ( p . PackQty . ToString ( ) , out _ packQty ) )
{
int _ count = _ qty / _ packQty ;
if ( _ qty / _ packQty > 0 )
{
for ( int i = 0 ; i < _ count ; i + + )
{
V_TB_ASK_DETAIL_PACKAGE _ asndetail = new V_TB_ASK_DETAIL_PACKAGE ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ packQty ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . Batch = p . Batch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asnList . Add ( _ asndetail ) ;
}
if ( _ qty % _ packQty > 0 )
{
V_TB_ASK_DETAIL_PACKAGE _ asndetail = new V_TB_ASK_DETAIL_PACKAGE ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty % _ packQty ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . Batch = p . Batch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asnList . Add ( _ asndetail ) ;
}
}
else
{
if ( _ qty > 0 )
{
V_TB_ASK_DETAIL_PACKAGE _ asndetail = new V_TB_ASK_DETAIL_PACKAGE ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . Batch = p . Batch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asnList . Add ( _ asndetail ) ;
}
}
}
} ) ;
foreach ( var itm in _ asnList )
{
var _ bar = SCP_BARCODE_CONTROLLER_CUSTOM . CreateBarcode ( itm ) ;
_l s . Add ( _ bar ) ;
}
db . TS_BARCODE_CUSTOM . AddOrUpdate ( p = > new { p . BarCode , p . BillNum } , _l s . ToArray ( ) ) ;
}
else
{
_ ret . MessageList . Add ( "选择的发货明细数量为零!" ) ;
}
if ( _ ret . MessageList . Count = = 0 )
{
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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Save_TB_CREATE_SMALLBARCODE ( List < V_TB_ASN_DETAIL > p_list )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
List < TS_BARCODE_SMALL > _l s = new List < TS_BARCODE_SMALL > ( ) ;
if ( p_list . Count > 0 )
{
string _ asnBillNum = p_list [ 0 ] . AsnBillNum ;
var _ asn = db . TB_ASN . Where ( p = > p . IsDeleted = = false & & p . AsnBillNum = = _ asnBillNum ) . FirstOrDefault ( ) ;
List < V_TB_ASN_DETAIL > _ asnList = new List < V_TB_ASN_DETAIL > ( ) ;
p_list . ForEach ( p = >
{
var _ askDetail = db . TA_VEND_PART . Where ( itm = > itm . VendId = = p . VendId & & itm . PartCode = = p . PartCode ) . FirstOrDefault ( ) ;
if ( _ askDetail ! = null )
{
decimal _ qty = 0 ;
decimal _ smallpackQty = 0 ;
if ( decimal . TryParse ( p . Qty . ToString ( ) , out _ qty ) & & decimal . TryParse ( _ askDetail . MinPackQty . ToString ( ) , out _ smallpackQty ) )
{
if ( _ smallpackQty = = 0 )
{
_ ret . MessageList . Add ( "供应商:" + p . VendId + "零件号:" + p . PartCode + "最小包装为0!" ) ;
}
else
{
decimal _ n = _ qty / _ smallpackQty ;
var _ count = int . Parse ( Math . Truncate ( _ n ) . ToString ( ) ) ;
if ( _ qty / _ smallpackQty > 0 )
{
for ( int i = 0 ; i < _ count ; i + + )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ smallpackQty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = _ smallpackQty ; //小包装
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asnList . Add ( _ asndetail ) ;
}
if ( _ qty % _ smallpackQty > 0 )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty % _ smallpackQty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = _ smallpackQty ; //小包装
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asnList . Add ( _ asndetail ) ;
}
}
else
{
if ( _ qty > 0 )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = _ smallpackQty ; //小包装
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asnList . Add ( _ asndetail ) ;
}
}
}
}
}
} ) ;
foreach ( var itm in _ asnList )
{
var _ bar = SCP_BARCODE_CONTROLLER . CreateSmallBarcode ( itm ) ;
_l s . Add ( _ bar ) ;
}
db . TS_BARCODE_SMALL . AddOrUpdate ( p = > new { p . BarCode , p . BillNum } , _l s . ToArray ( ) ) ;
}
else
{
_ ret . MessageList . Add ( "选择的发货明细数量为零!" ) ;
}
if ( _ ret . MessageList . Count = = 0 )
{
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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Save_TB_CREATE_BARCODE ( List < V_TB_ASN_DETAIL > p_list )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
List < TS_BARCODE > _l s = new List < TS_BARCODE > ( ) ;
if ( p_list . Count > 0 )
{
string _ asnBillNum = p_list [ 0 ] . AsnBillNum ;
var _ asn = db . TB_ASN . Where ( p = > p . IsDeleted = = false & & p . AsnBillNum = = _ asnBillNum ) . FirstOrDefault ( ) ;
List < V_TB_ASN_DETAIL > _ asnList = new List < V_TB_ASN_DETAIL > ( ) ;
p_list . ForEach ( p = >
{
decimal _ qty = 0 ;
decimal _ packQty = 0 ;
if ( decimal . TryParse ( p . Qty . ToString ( ) , out _ qty ) & & decimal . TryParse ( p . PackQty . ToString ( ) , out _ packQty ) )
{
decimal _ n = _ qty / _ packQty ;
var _ count = int . Parse ( Math . Truncate ( _ n ) . ToString ( ) ) ;
if ( _ qty / _ packQty > 0 )
{
for ( int i = 0 ; i < _ count ; i + + )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ packQty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asndetail . UpdateInfo = p . UpdateInfo ;
_ asnList . Add ( _ asndetail ) ;
}
if ( _ qty % _ packQty > 0 )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty % _ packQty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . UpdateInfo = p . UpdateInfo ;
_ asndetail . Site = p . Site ;
_ asnList . Add ( _ asndetail ) ;
}
}
else
{
if ( _ qty > 0 )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asndetail . UpdateInfo = p . UpdateInfo ;
_ asnList . Add ( _ asndetail ) ;
}
}
}
} ) ;
foreach ( var itm in _ asnList )
{
var _ bar = SCP_BARCODE_CONTROLLER . CreateBarcode ( itm ) ;
_l s . Add ( _ bar ) ;
}
db . TS_BARCODE . AddOrUpdate ( p = > new { p . BarCode , p . BillNum } , _l s . ToArray ( ) ) ;
}
else
{
_ ret . MessageList . Add ( "选择的发货明细数量为零!" ) ;
}
if ( _ ret . MessageList . Count = = 0 )
{
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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Save_TB_PALLET ( List < V_TB_ASN_DETAIL > p_list )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
List < string > _l ist = new List < string > ( ) ;
int codenum = 1 ; //标签计数器
string _ oldpartcode = "" ; //上一个托盘所装零件编号
decimal _ oldbox = 0 ; //上一个托盘箱数计数
string _ oldpalletnum = "" ; //上一个托盘码
List < string > _l istm = new List < string > ( ) ;
p_list . ForEach ( p = >
{
var _ askDetail = db . TA_VEND_PART . Where
( itm = > itm . VendId = = p . VendId
& & itm . PartCode = = p . PartCode
) . FirstOrDefault ( ) ;
if ( _ askDetail ! = null )
{
var _ palletPack = _ askDetail . PalletPackQty ;
#region 补充未满托盘
if ( p . PartCode = = _ oldpartcode )
{
decimal _ box1 = 0 ;
int _ TempQty1 = Convert . ToInt32 ( p . Qty ) ;
int _ PackQty1 = Convert . ToInt32 ( p . PackQty ) ;
if ( _ TempQty1 / _ PackQty1 > 0 )
{
int _ count = _ TempQty1 / _ PackQty1 ;
_ box1 + = _ count ;
if ( p . Qty % p . PackQty > 0 )
{
_ box1 + + ;
}
}
else
{
if ( _ TempQty1 > 0 )
{
_ box1 + + ;
}
}
if ( _ box1 < _ oldbox )
{
TB_PALLETS pallet = new TB_PALLETS ( ) ;
pallet . AsnBillNum = p . AsnBillNum ;
pallet . PartCode = p . PartCode ;
pallet . Batch = p . Batch ;
pallet . VendId = p . VendId ;
pallet . Box = Convert . ToInt32 ( _ box1 ) ;
pallet . Qty = p . Qty ;
pallet . PalletNum = _ oldpalletnum ;
db . TB_PALLETS . Add ( pallet ) ;
p . Qty = 0 ;
}
else
{
TB_PALLETS pallet = new TB_PALLETS ( ) ;
pallet . AsnBillNum = p . AsnBillNum ;
pallet . PartCode = p . PartCode ;
pallet . Batch = p . Batch ;
pallet . VendId = p . VendId ;
pallet . Box = Convert . ToInt32 ( _ oldbox ) ;
pallet . Qty = _ oldbox * _ PackQty1 ;
pallet . PalletNum = _ oldpalletnum ;
db . TB_PALLETS . Add ( pallet ) ;
p . Qty = p . Qty - _ oldbox * _ PackQty1 ;
}
}
#endregion
#region 新托盘
if ( p . Qty ! = 0 )
{
decimal _ box = 0 ;
int _ TempQty = Convert . ToInt32 ( p . Qty ) ;
int _ PackQty = Convert . ToInt32 ( p . PackQty ) ;
if ( _ TempQty / _ PackQty > 0 )
{
int _ count = _ TempQty / _ PackQty ;
_ box + = _ count ;
if ( p . Qty % p . PackQty > 0 )
{
_ box + + ;
}
}
else
{
if ( _ TempQty > 0 )
{
_ box + + ;
}
}
if ( _ box < = _ palletPack )
{
TB_PALLETS pallet = new TB_PALLETS ( ) ;
pallet . AsnBillNum = p . AsnBillNum ;
pallet . PartCode = p . PartCode ;
pallet . Batch = p . Batch ;
pallet . VendId = p . VendId ;
pallet . Box = Convert . ToInt32 ( _ box ) ;
pallet . Qty = p . Qty ;
pallet . PalletNum = SCP_BILLCODE_CONTROLLER . MakePalletCode_QD ( codenum ) ;
db . TB_PALLETS . Add ( pallet ) ;
_ oldpartcode = p . PartCode ;
_ oldbox = Convert . ToInt32 ( _ palletPack ) - _ box ;
_ oldpalletnum = pallet . PalletNum ;
codenum + + ;
}
else
{
decimal _ pallet = 0 ;
_ pallet + = Convert . ToInt32 ( _ box ) / Convert . ToInt32 ( _ palletPack ) ;
if ( _ box % _ palletPack > 0 )
{
_ pallet + + ;
}
for ( int i = 1 ; i < = _ pallet ; i + + )
{
TB_PALLETS pallet = new TB_PALLETS ( ) ;
pallet . AsnBillNum = p . AsnBillNum ;
pallet . PartCode = p . PartCode ;
pallet . Batch = p . Batch ;
pallet . VendId = p . VendId ;
pallet . PalletNum = SCP_BILLCODE_CONTROLLER . MakePalletCode_QD ( codenum ) ;
if ( i = = _ pallet )
{
pallet . Box = Convert . ToInt32 ( _ box - Convert . ToDecimal ( _ palletPack ) * ( _ pallet - 1 ) ) ;
pallet . Qty = p . Qty - Convert . ToDecimal ( _ palletPack ) * ( _ pallet - 1 ) * _ PackQty ;
}
else
{
pallet . Box = Convert . ToInt32 ( _ palletPack ) ;
pallet . Qty = Convert . ToDecimal ( _ palletPack ) * _ PackQty ;
}
db . TB_PALLETS . Add ( pallet ) ;
codenum + + ;
}
}
}
#endregion
}
else
{
string _ str = string . Format ( "零件号:{0},供应商编号:{1},没有维护托盘标包数!请先维护供应商零件信息" , p . PartCode , p . VendBatch ) ;
_l ist . Add ( _ str ) ;
}
} ) ;
int state = db . SaveChanges ( ) ;
if ( state ! = - 1 )
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
else
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
_ ret . MessageList = _l istm ;
}
}
}
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_ASN_CONTROLLER ) , "Save_TB_PALLET" , 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_ASN_CONTROLLER ) , "Save_TB_PALLET" , 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_ASN_CONTROLLER ) , "Save_TB_PALLET" , 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_ASN_CONTROLLER ) , "Save_TB_PALLET" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Save_TB_CREATE_BARCODE_SYJB ( List < V_TB_ASN_DETAIL > p_list )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
List < TS_BARCODE > _l s = new List < TS_BARCODE > ( ) ;
if ( p_list . Count > 0 )
{
string _ asnBillNum = p_list [ 0 ] . AsnBillNum ;
var _ asn = db . TB_ASN . Where ( p = > p . IsDeleted = = false & & p . AsnBillNum = = _ asnBillNum ) . FirstOrDefault ( ) ;
List < V_TB_ASN_DETAIL > _ asnList = new List < V_TB_ASN_DETAIL > ( ) ;
p_list . ForEach ( p = >
{
int _ qty = 0 ;
int _ packQty = 0 ;
if ( int . TryParse ( p . Qty . ToString ( ) , out _ qty ) & & int . TryParse ( p . PackQty . ToString ( ) , out _ packQty ) )
{
int _ count = _ qty / _ packQty ;
if ( _ qty / _ packQty > 0 )
{
for ( int i = 0 ; i < _ count ; i + + )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ packQty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asndetail . AskBillNum = p . AskBillNum ;
_ asnList . Add ( _ asndetail ) ;
}
if ( _ qty % _ packQty > 0 )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty % _ packQty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asndetail . AskBillNum = p . AskBillNum ;
_ asnList . Add ( _ asndetail ) ;
}
}
else
{
if ( _ qty > 0 )
{
V_TB_ASN_DETAIL _ asndetail = new V_TB_ASN_DETAIL ( ) ;
_ asndetail . PoBillNum = p . PoBillNum ;
_ asndetail . Batch = p . Batch ;
_ asndetail . PartCode = p . PartCode ;
_ asndetail . ProduceDate = p . ProduceDate ;
_ asndetail . Qty = _ qty ;
_ asndetail . AsnBillNum = p . AsnBillNum ;
_ asndetail . PoLine = p . PoLine ;
_ asndetail . VendId = p . VendId ;
_ asndetail . VendBatch = p . VendBatch ;
_ asndetail . CreateTime = p . CreateTime ;
_ asndetail . CreateUser = p . CreateUser ;
_ asndetail . Remark = p . Remark ;
_ asndetail . PackQty = p . PackQty ;
_ asndetail . PoUnit = p . PoUnit ;
_ asndetail . Site = p . Site ;
_ asndetail . AskBillNum = p . AskBillNum ;
_ asnList . Add ( _ asndetail ) ;
}
}
}
} ) ;
foreach ( var itm in _ asnList )
{
var _ bar = SCP_BARCODE_CONTROLLER_SYJB . CreateBarcode ( itm ) ;
_l s . Add ( _ bar ) ;
}
db . TS_BARCODE . AddOrUpdate ( p = > new { p . BarCode , p . BillNum } , _l s . ToArray ( ) ) ;
}
else
{
_ ret . MessageList . Add ( "选择的发货明细数量为零!" ) ;
}
if ( _ ret . MessageList . Count = = 0 )
{
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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_CREATE_BARCODE" , 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Get_TS_UNI_API ( V_TB_ASN p_asn )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _l ist = db . TS_UNI_API . Where ( p = > p . BillNum = = p_asn . AsnBillNum ) . ToList ( ) ;
if ( _l ist . Count > 0 )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
}
else
{
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = true ;
}
}
}
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_ASN_CONTROLLER ) , "Get_TS_UNI_API" , 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_ASN_CONTROLLER ) , "Get_TS_UNI_API" , 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_ASN_CONTROLLER ) , "Get_TS_UNI_API" , 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_ASN_CONTROLLER ) , "Get_TS_UNI_API" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Save_TB_ASN_DETAIL ( V_TB_ASN p_asn , List < V_TB_ASN_DETAIL > p_entitys )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
DateTime now = DateTime . Now ;
List < TB_ASN_DETAIL > _l s = new List < TB_ASN_DETAIL > ( ) ;
var _ asn = db . TB_ASN . Where ( p = > p . IsDeleted = = false & & p . AsnBillNum = = p_asn . AsnBillNum ) . ToList ( ) ;
if ( _ asn ! = null & & _ asn . Count > 0 )
{
_ asn . ForEach ( p = > {
p . State = ( int ) AsnState . Ship ;
p . CreateTime = now ;
} ) ;
db . TB_ASN . AddOrUpdate ( p = > p . UID , _ asn . ToArray ( ) ) ;
var ask = db . TB_ASK . Where ( p = > p . IsDeleted = = false & & p . AskBillNum = = p_asn . AskBillNum ) . ToList ( ) ;
ask . ForEach ( p = > p . State = ( int ) AskState . Ship ) ;
db . TB_ASK . AddOrUpdate ( p = > p . UID , ask . ToArray ( ) ) ;
p_entitys . ForEach ( itm = >
{
var _ sum = db . V_TB_ASK_DETAIL . Where ( p = > p . AskBillNum = = p_asn . AskBillNum & & p . PartCode = = itm . PartCode
& & p . PoBillNum = = p_asn . PoBillNum & & p . PoLine = = itm . PoLine & & p . IsDeleted = = false ) . Select ( p = > p . AskQty ) . Sum ( ) ; //要货单要货数量
var _ currSum = db . V_TB_ASN_DETAIL . Where ( p = > p . AskBillNum = = p_asn . AskBillNum & & p . PartCode = = itm . PartCode
& & p . PoBillNum = = p_asn . PoBillNum & & p . PoLine = = itm . PoLine & & p . IsDeleted = = false ) . Select ( p = > p . Qty ) . Sum ( ) ; //当前存在发货单数量
var _ curr = db . V_TB_ASN_DETAIL . Where ( p = > p . AsnBillNum = = p_asn . AsnBillNum & & p . PartCode = = itm . PartCode
& & p . PoBillNum = = p_asn . PoBillNum & & p . PoLine = = itm . PoLine & & p . IsDeleted = = false ) . Select ( p = > p . Qty ) . Sum ( ) ;
var _ rejct = db . TB_ARRIVE_DETAIL . Where ( p = > p . Remark = = p_asn . AskBillNum & & p . PartCode = = itm . PartCode
& & p . PoBillNum = = p_asn . PoBillNum & & p . PoLine = = itm . PoLine & & p . IsDeleted = = false & & p . BillType = = 3 ) . Select ( p = > p . Qty ) . ToList ( ) . Sum ( ) ;
if ( _ currSum - _ curr + itm . Qty - Math . Abs ( _ rejct ) < = _ sum )
{
TB_ASN_DETAIL _d etail = new TB_ASN_DETAIL ( ) ;
_d etail . UID = itm . UID ;
_d etail . UnConv = itm . UnConv ;
_d etail . AsnBillNum = itm . AsnBillNum ;
_d etail . DockCode = itm . DockCode ;
_d etail . Currency = itm . Currency ;
_d etail . Batch = itm . Batch ;
_d etail . CreateUser = itm . CreateUser ;
_d etail . CreateTime = now ;
_d etail . PackQty = itm . PackQty ;
_d etail . PartCode = itm . PartCode ;
_d etail . PoLine = itm . PoLine ;
_d etail . PoBillNum = itm . PoBillNum ;
_d etail . Price = itm . Price ;
_d etail . VendBatch = itm . VendBatch ;
_d etail . ProduceDate = itm . ProduceDate ;
_d etail . Remark = itm . Remark ;
_d etail . Qty = itm . Qty ;
_d etail . PoUnit = itm . PoUnit ;
_d etail . LocUnit = itm . LocUnit ;
_d etail . IsDeleted = itm . IsDeleted ;
_d etail . State = ( int ) AsnState . Ship ;
_d etail . GUID = itm . Guid ;
_l s . Add ( _d etail ) ;
TS_UNI_API api = UniApiController . CreateBy ( p_asn , itm , UniApiType . Receive ) ;
api . State = 1 ;
db . TS_UNI_API . AddOrUpdate ( api ) ; //同步更新中间表
}
else
{
_ ret . MessageList . Add ( string . Format ( "行号{0}零件名称:{1}数量合计已大于要货单{2}数量" , itm . PoLine , itm . PartDesc1 , itm . AskBillNum ) ) ;
}
}
) ;
var _ asnBillNum = _ asn [ 0 ] . AsnBillNum ;
//var _barcodeList=db.TS_BARCODE.Where(p => p.BillNum == _asnBillNum).ToList();
//_barcodeList.ForEach(itm => {
// TS_UNI_API _api =UniApiController.CreateBy(_asn[0], itm, UniApiType.BarCode);
// _api.State = 1;
// db.TS_UNI_API.AddOrUpdate(_api);
//});
}
if ( _ ret . MessageList . Count > 0 )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . Result = false ;
}
else
{
db . TB_ASN_DETAIL . AddOrUpdate ( p = > p . UID , _l s . 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , 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_ASN_CONTROLLER ) , "Save_TB_ASN_DETAIL" , e . Message ) ;
_ ret . Result = false ;
_ ret . ErrorList . Add ( e ) ;
throw e ;
}
return _ ret ;
}
public static ResultObject < bool > Del_TB_ASK_DETAIL ( List < TB_ASK_DETAIL > p_entitys )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
foreach ( var itm in p_entitys )
{
db . TB_ASK_DETAIL . Remove ( itm ) ;
}
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_ASN_CONTROLLER ) , "Del_TB_ASK_DETAIL" , 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_ASN_CONTROLLER ) , "Del_TB_ASK_DETAIL" , 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_ASN_CONTROLLER ) , "Del_TB_ASK_DETAIL" , 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 . Result = false ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASN_CONTROLLER ) , "Del_TB_ASK_DETAIL" , e . Message ) ; throw e ;
}
return _ ret ;
}
public static void Get_V_TB_ASN_DETAIL_VIEW_List ( V_TB_ASN_DETAIL_VIEW p_entity , Action < ResultObject < IQueryable < V_TB_ASN_DETAIL_VIEW > > > p_action )
{
ResultObject < IQueryable < V_TB_ASN_DETAIL_VIEW > > _ ret = new ResultObject < IQueryable < V_TB_ASN_DETAIL_VIEW > > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
IQueryable < V_TB_ASN_DETAIL_VIEW > q = db . V_TB_ASN_DETAIL_VIEW ;
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
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 ( p_entity . Price ! = 0 )
{
q = q . Where ( p = > p . Price = = p_entity . Price ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Currency ) )
{
q = q . Where ( p = > p . Currency . Contains ( p_entity . Currency ) ) ;
}
if ( p_entity . PackQty ! = 0 )
{
q = q . Where ( p = > p . PackQty = = p_entity . PackQty ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . DockCode ) )
{
q = q . Where ( p = > p . DockCode . Contains ( p_entity . DockCode ) ) ;
}
if ( p_entity . State ! = null )
{
q = q . Where ( p = > p . State = = p_entity . State ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc1 ) )
{
q = q . Where ( p = > p . PartDesc1 . Contains ( p_entity . PartDesc1 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendName ) )
{
q = q . Where ( p = > p . VendName . Contains ( p_entity . VendName ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PartDesc2 ) )
{
q = q . Where ( p = > p . PartDesc2 . Contains ( p_entity . PartDesc2 ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AsnBillNum ) )
{
q = q . Where ( p = > p . AsnBillNum . Contains ( p_entity . AsnBillNum ) ) ;
}
if ( p_entity . Qty ! = 0 )
{
q = q . Where ( p = > p . Qty = = p_entity . Qty ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendBatch ) )
{
q = q . Where ( p = > p . VendBatch . Contains ( p_entity . VendBatch ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . Batch ) )
{
q = q . Where ( p = > p . Batch . Contains ( p_entity . Batch ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . VendId ) )
{
q = q . Where ( p = > p . VendId = = p_entity . VendId ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . AskBillNum ) )
{
q = q . Where ( p = > p . AskBillNum . Contains ( p_entity . AskBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PoBillNum ) )
{
q = q . Where ( p = > p . PoBillNum . Contains ( p_entity . PoBillNum ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ReceivedPort ) )
{
q = q . Where ( p = > p . ReceivedPort . Contains ( p_entity . ReceivedPort ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . PlateNumber ) )
{
q = q . Where ( p = > p . PlateNumber . Contains ( p_entity . PlateNumber ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ShipUser ) )
{
q = q . Where ( p = > p . ShipUser . Contains ( p_entity . ShipUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . ReceiveUser ) )
{
q = q . Where ( p = > p . ReceiveUser . Contains ( p_entity . ReceiveUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . CreateUser ) )
{
q = q . Where ( p = > p . CreateUser . Contains ( p_entity . CreateUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . UpdateUser ) )
{
q = q . Where ( p = > p . UpdateUser . Contains ( p_entity . UpdateUser ) ) ;
}
if ( ! string . IsNullOrEmpty ( p_entity . UpdateInfo ) )
{
q = q . Where ( p = > p . UpdateInfo . Contains ( p_entity . UpdateInfo ) ) ;
}
q = q . Where ( p = > p . IsDeleted = = p_entity . IsDeleted ) ;
if ( p_entity . ShipTimeBegin ! = null )
{
q = q . Where ( p = > p . ShipTime > = p_entity . ShipTimeBegin ) ;
}
if ( p_entity . ShipTimeEnd ! = null )
{
q = q . Where ( p = > p . ShipTime < = p_entity . ShipTimeEnd ) ;
}
if ( p_entity . ReceiveTimeBegin ! = null )
{
q = q . Where ( p = > p . ReceiveTime > = p_entity . ReceiveTimeBegin ) ;
}
if ( p_entity . ReceiveTimeEnd ! = null )
{
q = q . Where ( p = > p . ReceiveTime < = p_entity . ReceiveTimeEnd ) ;
}
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 . Site ) ) ;
}
_ ret . State = ReturnStatus . Succeed ;
_ ret . Result = q ;
p_action ( _ ret ) ;
}
}
catch ( Exception e )
{
_ ret . State = ReturnStatus . Failed ;
_ ret . ErrorList . Add ( e ) ;
LogHelper . Writlog ( LogHelper . LogType . Error , typeof ( SCP_ASN_CONTROLLER ) , "Get_V_TB_ASN__DETAIL_View_List" , e . Message ) ;
throw e ;
}
}
//public static List<V_TB_ASK_DETAIL> Get_CAN_SHIPQTY(List<V_TB_ASK_DETAIL> p_list)
//{
// using (ScpEntities db = EntitiesFactory.CreateScpInstance())
// {
// var detail = p_list[0];
// var list = db.V_TB_ASN_DETAIL.Where(p => p.IsDeleted == false && detail.AskBillNum == p.AskBillNum).ToList();
// var groupList = list.GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode, p.AskBillNum }).Select(
// p => new {
// ShipSum = p.Sum(itm => itm.Qty),
// PoLine = p.Key.PoLine,
// PoBillNum = p.Key.PoBillNum,
// PartCode = p.Key.PartCode,
// AskBillNum = p.Key.AskBillNum
// }).ToList();
// p_list.ForEach(itm => {
// groupList.ForEach(p =>
// {
// if (p.PoBillNum == itm.PoBillNum && p.PoLine == itm.PoLine && p.PartCode == itm.PartCode)
// {
// itm.ShippedQty = p.ShipSum;
// }
// });
// decimal a = itm.AskQty - (itm.ShippedQty == null ? 0 : (decimal)itm.ShippedQty);
// itm.CanQty = a;
// itm.PackQty = (itm.PackQty == 0) ? 1 : itm.PackQty;
// });
// }
// return p_list;
//}
public static List < V_TB_ASN_DETAIL > Get_CAN_PALLET_QTY ( List < V_TB_ASN_DETAIL > p_list )
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var detail = p_list [ 0 ] ;
var list = db . V_TB_PALLET_DETAIL . Where ( p = > p . IsDeleted = = false & & detail . AsnBillNum = = p . AsnBillNum ) . ToList ( ) ;
var groupList = list . GroupBy ( p = > new { p . AsnBillNum , p . PoBillNum , p . PoLine , p . PartCode } )
. Select (
p = > new
{
PalletSum = p . Sum ( itm = > itm . Qty ) ,
PoLine = p . Key . PoLine ,
PoBillNum = p . Key . PoBillNum ,
PartCode = p . Key . PartCode ,
AsnBillNum = p . Key . AsnBillNum ,
}
) . ToList ( ) ;
p_list . ForEach ( itm = >
{
decimal palletedNum = 0 ;
groupList . ForEach ( p = >
{
if ( p . PoBillNum = = itm . PoBillNum & & p . PoLine = = itm . PoLine & & p . PartCode = = itm . PartCode )
{
palletedNum = p . PalletSum ;
}
} ) ;
decimal a = itm . Qty - palletedNum ;
itm . CanQty = a ;
itm . PackQty = ( itm . PackQty = = 0 ) ? 1 : itm . PackQty ;
} ) ;
}
return p_list ;
}
/// <summary>
/// 创建发货单
/// </summary>
/// <param name="p_ask"></param>
/// <param name="p_list"></param>
/// <param name="p_PlateNumber"></param>
/// <param name="p_buyer"></param>
/// <param name="p_buyerPhone"></param>
/// <returns></returns>
public static ResultObject < bool > Save_ASN_TO_PALLET ( V_TB_ASN p_ask , List < V_TB_ASN_DETAIL > p_list , string p_PlateNumber
, string p_buyer , string p_buyerPhone )
{
ResultObject < bool > _ ret = new ResultObject < bool > ( ) ;
try
{
using ( ScpEntities db = EntitiesFactory . CreateScpInstance ( ) )
{
var _ asn = db . V_TB_ASN . Where ( p = > p . AsnBillNum = = p_ask . AsnBillNum ) . FirstOrDefault ( ) ;
TB_PALLET _ t = new TB_PALLET ( ) ;
_ t . AsnBillNum = _ asn . AsnBillNum ;
_ t . PalletNum = SCP_BILLCODE_CONTROLLER . MakePalletCode ( ) ;
_ t . AskBillNum = _ asn . AskBillNum ;
_ t . PoBillNum = _ asn . PoBillNum ;
_ t . ReceivedPort = _ asn . ReceivedPort ;
_ t . CreateUser = _ asn . CreateUser ;
_ t . CreateTime = _ asn . CreateTime ;
_ t . UpdateUser = p_buyer ;
_ t . UpdateTime = _ asn . CreateTime ;
_ t . ReceiveUser = _ asn . Buyer ;
_ t . ReceiveTime = _ asn . ReceiveTime ;
_ t . VendId = _ asn . VendId ;
_ t . IsDeleted = false ; //操作员
_ t . CreateTime = _ asn . CreateTime ;
_ t . CreateUser = _ asn . CreateUser ;
_ t . Site = _ asn . Site ;
_ t . Remark = _ asn . Remark ;
_ t . State = ( int ) AsnState . New ;
_ t . Remark = p_ask . Remark ;
_ t . GUID = Guid . NewGuid ( ) ;
_ t . PlateNumber = string . Empty ;
_ t . ShipUser = p_ask . ShipUser ;
_ t . ShipTime = p_ask . ShipTime ;
_ t . ReceiveTime = p_ask . ReceiveTime ;
db . TB_PALLET . AddOrUpdate ( p = > p . PalletNum , _ t ) ;
List < TB_PALLET_DETAIL > _l ist = new List < TB_PALLET_DETAIL > ( ) ;
foreach ( var itm in p_list )
{
var _ asndetail = db . V_TB_ASN_DETAIL . Where ( p = > p . AsnBillNum = = itm . AsnBillNum & & p . PartCode = = itm . PartCode & & p . PoBillNum = = itm . PoBillNum & & p . PoLine = = itm . PoLine & & p . IsDeleted = = false ) . FirstOrDefault ( ) ;
TB_PALLET_DETAIL _ tDetail = new TB_PALLET_DETAIL ( ) ;
_ tDetail . PoBillNum = _ t . PoBillNum ;
_ tDetail . AsnBillNum = _ t . AsnBillNum ;
_ tDetail . PalletNum = _ t . PalletNum ;
_ tDetail . PoLine = _ asndetail . PoLine ;
_ tDetail . PoUnit = _ asndetail . PoUnit ;
_ tDetail . Batch = _ asndetail . Batch ;
if ( ! string . IsNullOrEmpty ( _ asndetail . VendBatch ) )
{
_ tDetail . VendBatch = _ asndetail . VendBatch ;
}
else
{
_ tDetail . VendBatch = _ asndetail . Batch ;
}
_ tDetail . PackQty = _ asndetail . PackQty = = 0 ? 1 : _ asndetail . PackQty ;
_ tDetail . PartCode = _ asndetail . PartCode ;
_ tDetail . State = ( int ) AsnState . New ;
_ tDetail . Qty = ( decimal ) itm . Qty ;
_ tDetail . Price = _ asndetail . Price ;
_ tDetail . EndTime = _ asndetail . EndTime ;
_ tDetail . CreateTime = _ t . CreateTime ;
_ tDetail . CreateUser = _ t . CreateUser ;
_ tDetail . ProduceDate = _ asndetail . ProduceDate ;
_ tDetail . IsDeleted = false ;
_ tDetail . DockCode = _ asndetail . ReceivedPort ;
_ tDetail . LocUnit = _ asndetail . LocUnit ;
_ tDetail . UnConv = _ asndetail . UnConv ;
_ tDetail . State = _ t . State ;
_ tDetail . ReceivedPort = _ asndetail . ReceivedPort ;
_ tDetail . GUID = Guid . NewGuid ( ) ;
db . TB_PALLET_DETAIL . Add ( _ tDetail ) ;
//var _order_detail = db.TB_ASK_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
//_order_detail.ShippedQty = (decimal)itm.ShippedQty;
//db.TB_ASK_DETAIL.AddOrUpdate(p => p.UID, _order_detail);
}
int state = db . SaveChanges ( ) ;
if ( state ! = - 1 )
{
//var _askDetailList = db.V_TB_ASK_DETAIL.Where(p => p.AskBillNum == p_ask.AskBillNum && p.IsDeleted == false).ToList();//查询要货单明细
//var _lst = Get_CAN_SHIPQTY(_askDetailList);//算出可发数量
//if (_lst.Select(p => p.CanQty).Sum() <= 0)//可发数量为零时,修改状态
//{
// var _ary = db.TB_ASK.Where(p => p.AskBillNum == p_ask.AskBillNum && p.IsDeleted == false).ToList();
// _ary.ForEach(p => p.State = (int)AskState.Ship);
// if (_ary.Count() > 0)
// {
// db.TB_ASK.AddOrUpdate(_ary.ToArray());
// }
//}
_ 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 ;
}
}
}