|
|
|
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.Enums;
|
|
|
|
using CK.SCP.Models.ScpEntity;
|
|
|
|
using CK.SCP.Utils;
|
|
|
|
using System.Data.Entity.Core;
|
|
|
|
using System.Web;
|
|
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
|
|
|
|
|
|
namespace CK.SCP.Controller
|
|
|
|
{
|
|
|
|
public class SCP_ASK_CONTROLLER
|
|
|
|
{
|
|
|
|
public static void Get_V_TB_ASK_List(V_TB_ASK p_entity, Action<ResultObject<IQueryable<V_TB_ASK>>> p_action)
|
|
|
|
{
|
|
|
|
ResultObject<IQueryable<V_TB_ASK>> _ret = new ResultObject<IQueryable<V_TB_ASK>>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
IQueryable<V_TB_ASK> q = db.V_TB_ASK;
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
|
|
|
|
{
|
|
|
|
//q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
|
|
|
|
q = q.Where(p => p.PoBillNum.Contains(p_entity.PoBillNum));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.ErpBillNum))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.ErpBillNum.Contains(p_entity.ErpBillNum));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.AskBillNum))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.AskBillNum.Contains(p_entity.AskBillNum));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.VendId))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.VendId == p_entity.VendId);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.Site))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.Site.Contains(p_entity.Site));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.Buyer))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.Buyer.Contains(p_entity.Buyer));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.BuyerPhone))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.BuyerPhone.Contains(p_entity.BuyerPhone));
|
|
|
|
}
|
|
|
|
if (p_entity.BillStateList != null && p_entity.BillStateList.Count > 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p_entity.BillStateList.Contains((int)p.State));
|
|
|
|
}
|
|
|
|
if (p_entity.BeginTime != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.BeginTime >= p_entity.BeginTime);
|
|
|
|
}
|
|
|
|
if (p_entity.BeginTime_End != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.BeginTime <= p_entity.BeginTime_End);
|
|
|
|
}
|
|
|
|
if (p_entity.EndTime != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.EndTime <= p_entity.EndTime);
|
|
|
|
}
|
|
|
|
if (p_entity.EndTime_start != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.EndTime >= p_entity.EndTime_start);
|
|
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
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 (!string.IsNullOrEmpty(p_entity.CreateUser))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.CreateUser == p_entity.CreateUser);
|
|
|
|
}
|
|
|
|
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.Contains(p_entity.SubSite));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.Extend1))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.Extend1.Contains(p_entity.Extend1));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.Extend2))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.Extend2.Contains(p_entity.Extend2));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.Extend3))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.Extend3.Contains(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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_List", e.Message);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static List<TA_ASK_SUBPART> Getlist(string ASK)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
return db.TA_ASK_SUBPART.Where(p => p.AskBillNum == ASK && string.IsNullOrEmpty(p.VendBatch)).ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Update_User_ErrorCount(string p_userName, int count)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (AppBoxContext _appdb = EntitiesFactory.CreateAppBoxInstance())
|
|
|
|
{
|
|
|
|
var user = _appdb.Users.FirstOrDefault(p => p.Name == p_userName);
|
|
|
|
if (user != null)
|
|
|
|
{
|
|
|
|
user.ErrorCount = user.ErrorCount + 1;
|
|
|
|
if (user.ErrorCount == count)
|
|
|
|
{
|
|
|
|
user.Enabled = false;
|
|
|
|
_ret.Message = $"密码错误超过【{count}】次,账号已锁定请联系管理员";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.Message = $"密码错误,再输入错【{count - user.ErrorCount}】次后账户将锁定!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int state = _appdb.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), "Update_User_ErrorCount", 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), "Update_User_ErrorCount", 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), "Update_User_ErrorCount", 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), "Update_User_ErrorCount", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Add_Vendusers(List<string> p_order_list, string site)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (AppBoxContext _appdb = EntitiesFactory.CreateAppBoxInstance())
|
|
|
|
{
|
|
|
|
foreach (var vend in p_order_list)
|
|
|
|
{
|
|
|
|
string na = vend + "@" + site;
|
|
|
|
var user = _appdb.Users.FirstOrDefault(p => p.Name == na);
|
|
|
|
if (user != null)
|
|
|
|
{
|
|
|
|
VenderUsers _entit = new VenderUsers();
|
|
|
|
_entit.UserId = user.ID;
|
|
|
|
_entit.VenderId = vend;
|
|
|
|
_appdb.VenderUsers.Add(_entit);
|
|
|
|
_appdb.SaveChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//int state = _appdb.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), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_state", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Add_ASK_SUBPART(string ask)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var askdetail = db.TB_ASK_DETAIL.Where(p => p.AskBillNum == ask).ToList();
|
|
|
|
var subcount = db.TA_ASK_SUBPART.Count(p => p.AskBillNum == ask);
|
|
|
|
if (subcount == 0)
|
|
|
|
{
|
|
|
|
foreach (var ak in askdetail)
|
|
|
|
{
|
|
|
|
var sub = db.TA_SubPartCode.Where(p => p.PartCode == ak.PartCode).ToList();
|
|
|
|
if (sub.Count() > 0)
|
|
|
|
{
|
|
|
|
foreach (var su in sub)
|
|
|
|
{
|
|
|
|
TA_ASK_SUBPART subpart = new TA_ASK_SUBPART();
|
|
|
|
subpart.PartCode = su.PartCode;
|
|
|
|
subpart.SubPartCode = su.SubPartCode;
|
|
|
|
subpart.BOMedtiton = su.BOMedtiton;
|
|
|
|
subpart.AskBillNum = ask;
|
|
|
|
subpart.Qty = su.Qty;
|
|
|
|
db.TA_ASK_SUBPART.AddOrUpdate(subpart);
|
|
|
|
db.TA_SubPartCode.Remove(su);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ret.MessageList.Count > 0)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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_ASK_CONTROLLER), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_state", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ResultObject<bool> Add_Vend_User(List<string> p_order_list, string site)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (AppBoxContext _appdb = EntitiesFactory.CreateAppBoxInstance())
|
|
|
|
{
|
|
|
|
foreach (var vend in p_order_list)
|
|
|
|
{
|
|
|
|
var user = _appdb.Users.FirstOrDefault(p => p.Name == vend);
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
{
|
|
|
|
var _factory = _appdb.TA_FACTORY.Where(p => p.ErpDomain == site).FirstOrDefault();
|
|
|
|
var _vend = _appdb.Roles.Where(p => p.Name == "供应商").FirstOrDefault();
|
|
|
|
User _entity = new User();
|
|
|
|
string na = vend + "@" + site;
|
|
|
|
_entity.Name = na;
|
|
|
|
_entity.Remark = site;
|
|
|
|
_entity.Password = PasswordUtil.CreateDbPassword("555555");
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var vendname = db.TA_VENDER.FirstOrDefault(p => p.VendId == vend);
|
|
|
|
_entity.ChineseName = vendname.VendName;
|
|
|
|
}
|
|
|
|
_entity.Email = vend + "@163.com";
|
|
|
|
_entity.Gender = "男";
|
|
|
|
_entity.Enabled = true;
|
|
|
|
_entity.Roles = new List<Role>();
|
|
|
|
|
|
|
|
Role t = _appdb.Set<Role>().Local.Where(x => x.ID == _vend.ID).FirstOrDefault();
|
|
|
|
if (t == null)
|
|
|
|
{
|
|
|
|
t = new Role { ID = _vend.ID };
|
|
|
|
_appdb.Set<Role>().Attach(t);
|
|
|
|
}
|
|
|
|
_entity.Roles.Add(t);
|
|
|
|
_entity.TA_FACTORY = new List<TA_FACTORY>();
|
|
|
|
TA_FACTORY f = _appdb.Set<TA_FACTORY>().Local.Where(x => x.ID == _factory.ID).FirstOrDefault();
|
|
|
|
if (f == null)
|
|
|
|
{
|
|
|
|
f = new TA_FACTORY { ID = _factory.ID };
|
|
|
|
_appdb.Set<TA_FACTORY>().Attach(f);
|
|
|
|
}
|
|
|
|
_entity.TA_FACTORY.Add(f);
|
|
|
|
_appdb.Users.Add(_entity);
|
|
|
|
_appdb.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//int state = _appdb.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), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_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_ASK_CONTROLLER), "Change_Vend_state", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 要货看板减产数量
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_entitys">要货看板业务类</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static ResultObject<bool> Update_ReduceQty(List<V_TB_ASK_DETAIL> p_entitys)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
foreach (var itm in p_entitys)
|
|
|
|
{
|
|
|
|
var _entity = db.TB_ASK_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
|
|
|
|
_entity.ReduceQty = itm.ReduceQty;
|
|
|
|
_entity.Remark = itm.Remark;
|
|
|
|
var asn = db.V_TB_ASN_DETAIL.Where(p => p.PoBillNum == itm.PoBillNum && p.AskBillNum == itm.AskBillNum && p.IsDeleted == false)
|
|
|
|
.GroupBy(p => new { p.PoBillNum, p.AskBillNum, p.PoLine, p.PartCode })
|
|
|
|
.Select(p => new { AsSum = p.Sum(item => item.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode, AskBillNum = p.Key.AskBillNum });
|
|
|
|
asn.ToList().ForEach(itm1 =>
|
|
|
|
{
|
|
|
|
if (itm.PoBillNum == itm1.PoBillNum && itm.PoLine == itm1.PoLine && itm.PartCode == itm1.PartCode && itm.AskBillNum == itm1.AskBillNum)
|
|
|
|
{
|
|
|
|
if (itm.ReduceQty > itm.AskQty - itm1.AsSum)
|
|
|
|
{
|
|
|
|
_ret.MessageList.Add(string.Format("零件编号{0}零件名称{1}减产数量>要货数量-发货数量", itm.PartCode, itm.PartDesc1 + itm.PartDesc2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(p => p.UID, _entity);
|
|
|
|
}
|
|
|
|
if (_ret.MessageList.Count > 0)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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_ASK_CONTROLLER), "Save_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_ASK_CONTROLLER), "Save_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_ASK_CONTROLLER), "Save_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;
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
public static void DEL_V_TB_ASK_DETAIL(List<V_TB_ASK_DETAIL> p_list, Action<ResultObject<bool>> p_action)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var _list = p_list.Select(itm => itm.UID).ToList();
|
|
|
|
var _ls = db.TB_ASK_DETAIL.Where(p => _list.Contains(p.UID)).ToList();
|
|
|
|
db.TB_ASK_DETAIL.RemoveRange(_ls);
|
|
|
|
if (db.SaveChanges() != -1)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Succeed;
|
|
|
|
_ret.Result = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
}
|
|
|
|
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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_List", e.Message);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Get_V_TB_ASK_ASN_View_List(V_TB_INCOMPLETE_ASK p_entity, Action<ResultObject<IQueryable<V_TB_INCOMPLETE_ASK>>> p_action)
|
|
|
|
{
|
|
|
|
ResultObject<IQueryable<V_TB_INCOMPLETE_ASK>> _ret = new ResultObject<IQueryable<V_TB_INCOMPLETE_ASK>>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
IQueryable<V_TB_INCOMPLETE_ASK> q = db.V_TB_INCOMPLETE_ASK;
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.AskBillNum))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.AskBillNum == p_entity.AskBillNum);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PartCode))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.CreateUser))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.Buyer))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.Buyer.Contains(p_entity.Buyer));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PartDesc1))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.PartDesc1.Contains(p_entity.PartDesc1));
|
|
|
|
}
|
|
|
|
if (p_entity.BeginTimeStart != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.BeginTime >= p_entity.BeginTimeStart);
|
|
|
|
}
|
|
|
|
if (p_entity.BeginTimeEnd != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.BeginTime <= p_entity.BeginTimeEnd);
|
|
|
|
}
|
|
|
|
if (p_entity.EndTimeStart != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.EndTime >= p_entity.EndTimeStart);
|
|
|
|
}
|
|
|
|
if (p_entity.EndTimeEnd != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.EndTime <= p_entity.EndTimeEnd);
|
|
|
|
}
|
|
|
|
if (p_entity.VendId != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
|
|
|
|
}
|
|
|
|
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 (p_entity.DayState == 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.ValidityDays <= 0);
|
|
|
|
}
|
|
|
|
if (p_entity.DayState > 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => (p.ValidityDays - p_entity.DayState) <= 0 && p.ValidityDays > 0);
|
|
|
|
}
|
|
|
|
if (p_entity.SendState == 1)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.AskQty != p.ReduceQty + p.Qty);
|
|
|
|
}
|
|
|
|
if (p_entity.SendState == 2)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.AskQty == p.ReduceQty + p.Qty);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
|
|
|
|
_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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_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_ASK_CONTROLLER), "Get_V_TB_ASK_ASN_View_List", e.Message);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<V_TB_INCOMPLETE_ASK> RejectQty_SUM(List<V_TB_INCOMPLETE_ASK> p_list)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
if (p_list.Count > 0)
|
|
|
|
{
|
|
|
|
//var _detail = p_list[0];
|
|
|
|
foreach (V_TB_INCOMPLETE_ASK _detail in p_list)
|
|
|
|
{
|
|
|
|
var reject = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.BillType == 3).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { RejectSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
reject.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.Number = _detail.Number + Math.Abs(itm.RejectSum);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p_list;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 加载货物详细数量信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_list"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static List<V_TB_INCOMPLETE_ASK> Load_Qty_Sum(List<V_TB_INCOMPLETE_ASK> p_list)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
if (p_list.Count > 0)
|
|
|
|
{
|
|
|
|
//var _detail = p_list[0];
|
|
|
|
foreach (V_TB_INCOMPLETE_ASK _detail in p_list)
|
|
|
|
{
|
|
|
|
//合格数量
|
|
|
|
var rec = db.TB_RECEIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ReceiveState.Check && p.BillType == 0)
|
|
|
|
.GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { ReceiveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
//到货数量
|
|
|
|
var arrive = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.Qty > 0).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
//退货数量
|
|
|
|
var back = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.Qty < 0).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
//开票数量
|
|
|
|
var invoice = db.V_TB_INVOICE_DETAIL.Where(p => p.AskBillNum == _detail.AskBillNum)
|
|
|
|
.GroupBy(p => new { p.AskBillNum, p.PoLineNum, p.PartCode }).Select(p => new { InvoiceQty = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLineNum, AskBillNum = p.Key.AskBillNum, PartCode = p.Key.PartCode });
|
|
|
|
//寄售退货
|
|
|
|
var reject = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.BillType == 3).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { RejectSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
reject.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.Number = _detail.Number + Math.Abs(itm.RejectSum);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
invoice.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.AskBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.InvoiceQty = itm.InvoiceQty;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
back.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.RejectQty = itm.ArriveSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
arrive.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.ArriveQty = itm.ArriveSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
rec.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.ReceivedQty = itm.ReceiveSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_detail.OnRoadQty = Convert.ToDecimal(_detail.Qty) - _detail.ArriveQty;
|
|
|
|
_detail.DepositQty = _detail.ArriveQty - _detail.ReceivedQty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p_list;
|
|
|
|
}
|
|
|
|
public static List<V_TB_ASK_DETAIL> LOAD_ASK_DETAIL_SUM(List<V_TB_ASK_DETAIL> p_list)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
if (p_list.Count > 0)
|
|
|
|
{
|
|
|
|
//var _detail = p_list[0];
|
|
|
|
foreach (V_TB_ASK_DETAIL _detail in p_list)
|
|
|
|
{
|
|
|
|
var _ask = db.TB_ASK_DETAIL.Where(p => p.AskBillNum == _detail.AskBillNum && p.IsDeleted == false).GroupBy(p => new { p.AskBillNum, p.PoLine, p.PartCode }).Select(p => new { AskSum = p.Sum(itm => itm.AskQty), PoLine = p.Key.PoLine, AskBillNum = p.Key.AskBillNum, PartCode = p.Key.PartCode });
|
|
|
|
|
|
|
|
//合格
|
|
|
|
var rec = db.TB_RECEIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ReceiveState.Check && p.BillType == 0)
|
|
|
|
.GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { ReceiveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
|
|
|
|
// var reject = db.TB_RECEIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)RejectState.Check && p.BillType == 1).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { RejectSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark , PartCode = p.Key.PartCode });
|
|
|
|
//发货
|
|
|
|
var asn = db.V_TB_ASN_DETAIL.Where(p => p.AskBillNum == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)AsnState.Ship)
|
|
|
|
.GroupBy(p => new { p.AskBillNum, p.PoLine, p.PartCode })
|
|
|
|
.Select(p => new { AsSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, AskBillNum = p.Key.AskBillNum, PartCode = p.Key.PartCode });
|
|
|
|
|
|
|
|
//var arrive = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.BillType == (int)ArriveBillType.Receive).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
//到货
|
|
|
|
var arrive = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.Qty > 0).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
//退货
|
|
|
|
var reject = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == _detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.Qty < 0).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode });
|
|
|
|
//发票
|
|
|
|
var invoice = db.V_TB_INVOICE_DETAIL.Where(p => p.AskBillNum == _detail.AskBillNum)
|
|
|
|
.GroupBy(p => new { p.AskBillNum, p.PoLineNum, p.PartCode }).Select(p => new { InvoiceQty = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLineNum, AskBillNum = p.Key.AskBillNum, PartCode = p.Key.PartCode });
|
|
|
|
|
|
|
|
_detail.PartDesc1 = _detail.PartDesc1 + _detail.PartDesc2;
|
|
|
|
rec.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.ReceivedQty = itm.ReceiveSum;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
reject.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.RejectQty = itm.ArriveSum;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
asn.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.AskBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.ShippedQty = itm.AsSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_ask.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.AskBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.TempQty = itm.AskSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
arrive.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.Remark && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.ArriveQty = itm.ArriveSum;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
invoice.ToList().ForEach(itm =>
|
|
|
|
{
|
|
|
|
if (_detail.AskBillNum == itm.AskBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
_detail.InvoiceQty = itm.InvoiceQty;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
_detail.OnRoadQty = Convert.ToDecimal(_detail.ShippedQty) - _detail.ArriveQty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return p_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<V_TB_ASK> LOAD_ASK_DETAIL_CAN(List<V_TB_ASK> p_list)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
|
|
|
|
if (p_list.ToList().Count > 0)
|
|
|
|
{
|
|
|
|
foreach (V_TB_ASK _detail in p_list)
|
|
|
|
{
|
|
|
|
_detail.Month = Convert.ToDateTime(_detail.EndTime).Month.ToString() + "月订单";
|
|
|
|
if (_detail.State == 0 || _detail.State == 1 || _detail.State == 2)
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (_detail.State == 6 || _detail.State == -1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var _ask = db.V_TB_ASK_DETAIL.Where(p => p.AskBillNum == _detail.AskBillNum && p.IsDeleted == false).ToList();
|
|
|
|
var _ask_can = Get_CAN_SHIPQTY(_ask.ToList()).Where(p => p.CanQty > 0).ToList();
|
|
|
|
|
|
|
|
if (_ask_can.Count != 0)
|
|
|
|
{
|
|
|
|
_detail.Flag = "1";//未完成
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_detail.Flag = "0";//完成
|
|
|
|
}
|
|
|
|
//_detail.Flag = (_ask_can.Count).ToString()+ "/" +(_ask.Count).ToString();
|
|
|
|
//_detail.Month = _detail.CreateTime.Month.ToString() + "月订单";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p_list;
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Save_TB_ASK_DETAIL_DATE(List<V_TB_ASK_DETAIL> p_entitys)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
string askBill = string.Empty;
|
|
|
|
DateTime beginTime = DateTime.Now;
|
|
|
|
DateTime endTime = DateTime.Now;
|
|
|
|
foreach (var itm in p_entitys)
|
|
|
|
{
|
|
|
|
var _entity = db.TB_ASK_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
|
|
|
|
askBill = _entity.AskBillNum;
|
|
|
|
_entity.BeginTime = (DateTime)itm.BeginTime;
|
|
|
|
beginTime = (DateTime)itm.BeginTime;
|
|
|
|
_entity.EndTime = (DateTime)itm.EndTime;
|
|
|
|
endTime = (DateTime)itm.EndTime;
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(p => p.UID, _entity);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(askBill))
|
|
|
|
{
|
|
|
|
var _entity = db.TB_ASK.Where(p => p.AskBillNum == askBill).FirstOrDefault();
|
|
|
|
_entity.BeginTime = beginTime;
|
|
|
|
_entity.EndTime = endTime;
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.UID, _entity);
|
|
|
|
}
|
|
|
|
if (_ret.MessageList.Count > 0)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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_ASK_CONTROLLER), "Save_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_ASK_CONTROLLER), "Save_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_ASK_CONTROLLER), "Save_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;
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Save_TB_ASK_DETAIL(List<TB_ASK_DETAIL> p_entitys, AskState p_state)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
foreach (var itm in p_entitys)
|
|
|
|
{
|
|
|
|
itm.State = (int)p_state;
|
|
|
|
var _entity = db.TB_ASK_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
|
|
|
|
_entity.AskQty = itm.AskQty;
|
|
|
|
if (itm.EndTime != null)
|
|
|
|
{
|
|
|
|
_entity.EndTime = itm.EndTime;
|
|
|
|
}
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(p => p.UID, _entity);
|
|
|
|
}
|
|
|
|
if (_ret.MessageList.Count > 0)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (db.SaveChanges() != -1)
|
|
|
|
{
|
|
|
|
|
|
|
|
using (ScpEntities db1 = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var _ls = p_entitys.Select(p => p.UID).ToList();
|
|
|
|
if (_ls.Count > 0)
|
|
|
|
{
|
|
|
|
var _entityList = db.V_TB_ASK_DETAIL.Where(p => _ls.Contains(p.UID)).ToList();
|
|
|
|
|
|
|
|
var _item = _entityList.FirstOrDefault();
|
|
|
|
|
|
|
|
if (_item.AskBillNum.Contains("U"))
|
|
|
|
{
|
|
|
|
var _planList = db1.TB_PO_PLAN_EXTEND.Where(p => p.Domain == _item.Site && p.EndTime == _item.EndTime && p.PoBillNum == _item.PoBillNum).ToList();
|
|
|
|
_planList.ForEach(p =>
|
|
|
|
{
|
|
|
|
|
|
|
|
var _first = _entityList.Where(itm => itm.PoBillNum == p.PoBillNum && itm.PartCode == p.PartCode && itm.EndTime == p.EndTime).FirstOrDefault();
|
|
|
|
if (_first != null)
|
|
|
|
{
|
|
|
|
p.PlanQty = _first.AskQty;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
db1.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_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_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_ASK_CONTROLLER), "Save_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_ASK_CONTROLLER), "Save_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;
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Update_TB_ASK(TB_ASK p_entitys)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
|
|
|
|
var ret = db.TB_ASK.Where(p => p.AskBillNum == p_entitys.AskBillNum).FirstOrDefault();
|
|
|
|
ret.Extend1 = p_entitys.Extend1;
|
|
|
|
|
|
|
|
db.TB_ASK.AddOrUpdate(ret);
|
|
|
|
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_ASK_CONTROLLER), "Save_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_ASK_CONTROLLER), "Save_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_ASK_CONTROLLER), "Save_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;
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_entitys"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static ResultObject<bool> Save_TB_PO(List<TB_PO> p_entitys)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
foreach (var itm in p_entitys)
|
|
|
|
{
|
|
|
|
db.TB_PO.AddOrUpdate(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_ASK_CONTROLLER), "Save_TB_PO", 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_TB_PO", 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_TB_PO", 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_TB_PO", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void test(string p_askBillNum)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var _list = db.V_TB_ASK_DETAIL.Where(p => p.AskBillNum == p_askBillNum && p.IsDeleted == false).ToList();
|
|
|
|
var _lst = Get_CAN_SHIPQTY(_list);
|
|
|
|
if (_lst.Select(p => p.CanQty).Sum() <= 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ResultObject<bool> COPY_ASK(V_TB_ASK p_ask)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var _ask = db.TB_ASK.Where(p => p.AskBillNum == p_ask.AskBillNum).FirstOrDefault();
|
|
|
|
_ask = ConvertHelper.GetObjectClone(_ask);
|
|
|
|
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode();
|
|
|
|
_ask.GUID = Guid.NewGuid();
|
|
|
|
|
|
|
|
_ask.State = (int)AskState.New;
|
|
|
|
db.TB_ASK.Add(_ask);
|
|
|
|
var _askDetailList = db.TB_ASK_DETAIL.Where(p => p.AskBillNum == p_ask.AskBillNum).ToList();
|
|
|
|
_askDetailList = ConvertHelper.GetObjectClone(_askDetailList);
|
|
|
|
_askDetailList.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.AskBillNum = _ask.AskBillNum;
|
|
|
|
p.State = (int)AskState.New;
|
|
|
|
p.GUID = Guid.NewGuid();
|
|
|
|
db.TB_ASK_DETAIL.Add(p);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
int state = db.SaveChanges();
|
|
|
|
if (state != -1)
|
|
|
|
{
|
|
|
|
_ret.MessageList.Add("复制要货单号" + _ask.AskBillNum + ",请去要货明细修改要货单订货日期和要货日期");
|
|
|
|
_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_PO_CONTROLLER), "Save_PO_TO_ASK", 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_PO_CONTROLLER), "Save_PO_TO_ASK", 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_PO_CONTROLLER), "Save_PO_TO_ASK", 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_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ResultObject<bool> Save_ASK_TO_WWDZJASN(V_TB_ASK p_ask, List<V_TB_ASK_DETAIL> p_order_list, string p_PlateNumber
|
|
|
|
, string p_buyer, string p_buyerPhone)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
TB_ASN _t = new TB_ASN();
|
|
|
|
_t.AsnBillNum = SCP_BILLCODE_CONTROLLER.MakeASNCode();
|
|
|
|
_t.AskBillNum = p_ask.AskBillNum;
|
|
|
|
_t.PoBillNum = p_ask.PoBillNum;
|
|
|
|
_t.ReceivedPort = p_ask.ReceivedPort;
|
|
|
|
_t.CreateUser = p_buyer;
|
|
|
|
_t.CreateTime = DateTime.Now;
|
|
|
|
_t.UpdateUser = p_buyer;
|
|
|
|
_t.UpdateTime = _t.CreateTime;
|
|
|
|
_t.ReceiveUser = p_ask.Buyer;
|
|
|
|
_t.ReceiveTime = p_ask.BeginTime;
|
|
|
|
_t.VendId = p_ask.VendId;
|
|
|
|
_t.IsDeleted = false;//操作员
|
|
|
|
_t.CreateTime = DateTime.Now;
|
|
|
|
_t.CreateUser = p_buyer;
|
|
|
|
_t.Site = p_ask.Site;
|
|
|
|
_t.SubSite = p_ask.SubSite;
|
|
|
|
_t.Remark = p_ask.Remark;
|
|
|
|
_t.State = (int)AsnState.New;
|
|
|
|
_t.Remark = p_ask.Remark;
|
|
|
|
_t.GUID = Guid.NewGuid();
|
|
|
|
_t.PlateNumber = p_PlateNumber;
|
|
|
|
_t.ShipUser = p_ask.ShipUser;
|
|
|
|
_t.ShipTime = p_ask.ShipTime;
|
|
|
|
_t.ReceiveTime = p_ask.ReceiveTime;
|
|
|
|
foreach (var itm in p_order_list)
|
|
|
|
{
|
|
|
|
var partgroup = db.TA_PART.Where(p => p.PartCode == itm.PartCode).FirstOrDefault();
|
|
|
|
_t.Extend3 = partgroup.PartGroup;
|
|
|
|
}
|
|
|
|
db.TB_ASN.AddOrUpdate(p => p.AsnBillNum, _t);
|
|
|
|
List<TB_ASN_DETAIL> _list = new List<TB_ASN_DETAIL>();
|
|
|
|
foreach (var itm in p_order_list)
|
|
|
|
{
|
|
|
|
TB_ASN_DETAIL _tDetail = new TB_ASN_DETAIL();
|
|
|
|
_tDetail.PoBillNum = _t.PoBillNum;
|
|
|
|
_tDetail.AsnBillNum = _t.AsnBillNum;
|
|
|
|
_tDetail.PoLine = itm.PoLine;
|
|
|
|
_tDetail.PoUnit = itm.PoUnit;
|
|
|
|
_tDetail.Batch = itm.Batch;
|
|
|
|
if (itm.VendBatch == "55")
|
|
|
|
{
|
|
|
|
_tDetail.VendBatch = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_tDetail.VendBatch = itm.VendBatch;
|
|
|
|
}
|
|
|
|
var subpart = db.TA_ASK_SUBPART.Where(p => p.PartCode == itm.PartCode && p.AskBillNum == itm.AskBillNum).ToList();
|
|
|
|
string str1 = "";
|
|
|
|
string str2 = "";
|
|
|
|
foreach (var sub in subpart)
|
|
|
|
{
|
|
|
|
string str = sub.SubPartCode + "," + sub.BOMedtiton + "," + sub.VendBatch + "#";
|
|
|
|
str2 = str2 + sub.VendBatch;
|
|
|
|
str1 = str1 + str;
|
|
|
|
}
|
|
|
|
_tDetail.VendBatch = str1;
|
|
|
|
_tDetail.UpdateUser = str2;
|
|
|
|
_tDetail.PackQty = itm.PackQty == 0 ? 1 : itm.PackQty;
|
|
|
|
_tDetail.PartCode = itm.PartCode;
|
|
|
|
_tDetail.State = (int)AsnState.New;
|
|
|
|
_tDetail.Qty = (decimal)itm.TempQty;
|
|
|
|
_tDetail.Price = itm.Price;
|
|
|
|
_tDetail.EndTime = itm.EndTime;
|
|
|
|
_tDetail.CreateTime = _t.CreateTime;
|
|
|
|
_tDetail.CreateUser = _t.CreateUser;
|
|
|
|
_tDetail.ProduceDate = itm.ProduceDate;
|
|
|
|
_tDetail.IsDeleted = false;
|
|
|
|
_tDetail.DockCode = itm.ReceivedPort;
|
|
|
|
_tDetail.LocUnit = itm.LocUnit;
|
|
|
|
_tDetail.UnConv = itm.UnConv;
|
|
|
|
_tDetail.State = _t.State;
|
|
|
|
_tDetail.UpdateInfo = itm.UpdateInfo;
|
|
|
|
_tDetail.ReceivedPort = itm.ReceivedPort;
|
|
|
|
_tDetail.GUID = Guid.NewGuid();
|
|
|
|
_tDetail.SubSite = itm.SubSite;
|
|
|
|
_tDetail.Site = itm.Site;
|
|
|
|
_tDetail.Extend2 = itm.ReceivedQty.ToString();
|
|
|
|
_tDetail.Remark = itm.ReceivedQty.ToString();
|
|
|
|
_tDetail.UpdateInfo = itm.UpdateInfo;
|
|
|
|
var partgroup = db.TA_PART.Where(p => p.PartCode == itm.PartCode).FirstOrDefault();
|
|
|
|
_tDetail.Extend3 = partgroup.PartGroup;
|
|
|
|
db.TB_ASN_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);
|
|
|
|
foreach (var sub in subpart)
|
|
|
|
{
|
|
|
|
TS_UNI_API uni = new TS_UNI_API();
|
|
|
|
uni.InterfaceType = "Receive";
|
|
|
|
uni.TableName = "TS_UNI_API";
|
|
|
|
uni.BillType = 0;
|
|
|
|
uni.SubBillType = 0;
|
|
|
|
uni.BillNum = _tDetail.AsnBillNum;
|
|
|
|
uni.PartCode = _tDetail.PartCode;
|
|
|
|
uni.Batch = _tDetail.Batch;
|
|
|
|
uni.Qty = _tDetail.Qty;
|
|
|
|
uni.State = 2;
|
|
|
|
uni.CreateOper = _t.CreateUser;
|
|
|
|
uni.CreateTime = DateTime.Now;
|
|
|
|
uni.PutTime = DateTime.Now;
|
|
|
|
uni.VendId = _t.VendId;
|
|
|
|
uni.PoUnit = _tDetail.PoUnit;
|
|
|
|
uni.LocUnit = _tDetail.PoUnit;
|
|
|
|
uni.ValidDate = DateTime.Now;
|
|
|
|
uni.ErpBillNum = _tDetail.PoBillNum;
|
|
|
|
uni.ErpLineNum = _tDetail.PoLine;
|
|
|
|
uni.VendBatch = sub.VendBatch;
|
|
|
|
uni.PackQty = _tDetail.Qty;
|
|
|
|
uni.Price = _tDetail.Price;
|
|
|
|
uni.UmConv = 1;
|
|
|
|
uni.Buyer = _t.ShipUser;
|
|
|
|
uni.BuyerPhone = "";
|
|
|
|
uni.Site = _t.Site;
|
|
|
|
uni.Domain = _t.Site;
|
|
|
|
uni.ModType = sub.SubPartCode;
|
|
|
|
uni.Barcode = sub.BOMedtiton;
|
|
|
|
uni.Extend3 = _tDetail.PoLine.ToString();
|
|
|
|
db.TS_UNI_API.Add(uni);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var subpartcode = db.TA_ASK_SUBPART.Where(p => p.AskBillNum == _t.AskBillNum).ToList();
|
|
|
|
foreach (var sub in subpartcode)
|
|
|
|
{
|
|
|
|
sub.VendBatch = "";
|
|
|
|
db.TA_ASK_SUBPART.AddOrUpdate(sub);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Save_ASK_TO_ASN(V_TB_ASK p_ask, List<V_TB_ASK_DETAIL> p_order_list, string p_PlateNumber
|
|
|
|
, string p_buyer, string p_buyerPhone)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var po = db.TB_PO.FirstOrDefault(p => p.PoBillNum == p_ask.PoBillNum);
|
|
|
|
TB_ASN _t = new TB_ASN();
|
|
|
|
_t.AsnBillNum = SCP_BILLCODE_CONTROLLER.MakeASNCode();
|
|
|
|
_t.AskBillNum = p_ask.AskBillNum;
|
|
|
|
_t.PoBillNum = p_ask.PoBillNum;
|
|
|
|
_t.ReceivedPort = p_ask.ReceivedPort;
|
|
|
|
_t.CreateUser = p_buyer;
|
|
|
|
_t.CreateTime = DateTime.Now;
|
|
|
|
_t.UpdateUser = p_buyer;
|
|
|
|
_t.UpdateTime = _t.CreateTime;
|
|
|
|
_t.ReceiveUser = p_ask.Buyer;
|
|
|
|
_t.ReceiveTime = p_ask.BeginTime;
|
|
|
|
_t.VendId = p_ask.VendId;
|
|
|
|
_t.IsDeleted = false;//操作员
|
|
|
|
_t.CreateTime = DateTime.Now;
|
|
|
|
_t.CreateUser = p_buyer;
|
|
|
|
_t.Site = p_ask.Site;
|
|
|
|
_t.SubSite = p_ask.SubSite;
|
|
|
|
_t.Remark = p_ask.Remark;
|
|
|
|
_t.State = (int)AsnState.New;
|
|
|
|
_t.Remark = p_ask.Remark;
|
|
|
|
_t.GUID = Guid.NewGuid();
|
|
|
|
_t.PlateNumber = p_PlateNumber;
|
|
|
|
_t.ShipUser = p_ask.ShipUser;
|
|
|
|
_t.ShipTime = p_ask.ShipTime;
|
|
|
|
_t.ReceiveTime = p_ask.ReceiveTime;
|
|
|
|
foreach (var itm in p_order_list)
|
|
|
|
{
|
|
|
|
var partgroup = db.TA_PART.Where(p => p.PartCode == itm.PartCode).FirstOrDefault();
|
|
|
|
_t.Extend3 = partgroup.PartGroup;
|
|
|
|
}
|
|
|
|
db.TB_ASN.AddOrUpdate(p => p.AsnBillNum, _t);
|
|
|
|
List<TB_ASN_DETAIL> _list = new List<TB_ASN_DETAIL>();
|
|
|
|
foreach (var itm in p_order_list)
|
|
|
|
{
|
|
|
|
TB_ASN_DETAIL _tDetail = new TB_ASN_DETAIL();
|
|
|
|
_tDetail.PoBillNum = _t.PoBillNum;
|
|
|
|
_tDetail.AsnBillNum = _t.AsnBillNum;
|
|
|
|
_tDetail.PoLine = itm.PoLine;
|
|
|
|
_tDetail.PoUnit = itm.PoUnit;
|
|
|
|
_tDetail.Batch = itm.Batch;
|
|
|
|
if (itm.VendBatch == "55")
|
|
|
|
{
|
|
|
|
_tDetail.VendBatch = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_tDetail.VendBatch = itm.VendBatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_t.PoBillNum.Substring(0, 5) == "CYD03" && _t.Site == "W21")
|
|
|
|
{
|
|
|
|
var podetail = db.TB_PO_DETAIL.FirstOrDefault(t => t.PoBillNum == _t.PoBillNum && t.PartCode == itm.PartCode && t.PoLine == itm.PoLine);
|
|
|
|
_tDetail.VendBatch = podetail.SubSite + "," + podetail.Extend3 + "," + itm.VendBatch + "#";
|
|
|
|
}
|
|
|
|
_tDetail.UpdateUser = itm.VendBatch;
|
|
|
|
_tDetail.PackQty = itm.PackQty == 0 ? 1 : itm.PackQty;
|
|
|
|
_tDetail.PartCode = itm.PartCode;
|
|
|
|
_tDetail.State = (int)AsnState.New;
|
|
|
|
_tDetail.Qty = (decimal)itm.TempQty;
|
|
|
|
_tDetail.Price = itm.Price;
|
|
|
|
_tDetail.EndTime = itm.EndTime;
|
|
|
|
_tDetail.CreateTime = _t.CreateTime;
|
|
|
|
_tDetail.CreateUser = _t.CreateUser;
|
|
|
|
_tDetail.ProduceDate = itm.ProduceDate;
|
|
|
|
_tDetail.IsDeleted = false;
|
|
|
|
_tDetail.DockCode = itm.ReceivedPort;
|
|
|
|
_tDetail.LocUnit = itm.LocUnit;
|
|
|
|
_tDetail.UnConv = itm.UnConv;
|
|
|
|
_tDetail.State = _t.State;
|
|
|
|
_tDetail.UpdateInfo = itm.UpdateInfo;
|
|
|
|
_tDetail.ReceivedPort = itm.ReceivedPort;
|
|
|
|
_tDetail.GUID = Guid.NewGuid();
|
|
|
|
_tDetail.SubSite = itm.SubSite;
|
|
|
|
_tDetail.Site = itm.Site;
|
|
|
|
_tDetail.Extend2 = itm.ReceivedQty.ToString();
|
|
|
|
_tDetail.Remark = itm.ReceivedQty.ToString();
|
|
|
|
_tDetail.UpdateInfo = itm.UpdateInfo;
|
|
|
|
var partgroup = db.TA_PART.Where(p => p.PartCode == itm.PartCode).FirstOrDefault();
|
|
|
|
var askdetail = db.TB_ASK_DETAIL.Where(p => p.PartCode == itm.PartCode && p.AskBillNum == itm.AskBillNum).FirstOrDefault();
|
|
|
|
_tDetail.Extend3 = partgroup.PartGroup;
|
|
|
|
_tDetail.Extend1 = po.VendId;
|
|
|
|
if (itm.Site == "U32")
|
|
|
|
{
|
|
|
|
var _applin = db.TA_Appliance.FirstOrDefault(p => p.PartNumber == itm.SubSite && p.VendID == p_ask.VendId);
|
|
|
|
if (_applin != null)
|
|
|
|
{
|
|
|
|
var _boxtype = db.TA_BOXTYPE.FirstOrDefault(p => p.BoxType == _applin.BoxType && p.Enabled == true);
|
|
|
|
if (_boxtype != null)
|
|
|
|
{
|
|
|
|
TB_ASN_PARTBOX PARTBOX = new TB_ASN_PARTBOX();
|
|
|
|
PARTBOX.AsnBillNum = _t.AsnBillNum;
|
|
|
|
PARTBOX.PartCode = itm.PartCode;
|
|
|
|
PARTBOX.BoxType = _boxtype.BoxType;
|
|
|
|
PARTBOX.Box = Convert.ToInt32(_tDetail.Qty) / Convert.ToInt32(_tDetail.PackQty);
|
|
|
|
if (Convert.ToInt32(_tDetail.Qty) % Convert.ToInt32(_tDetail.PackQty) > 0)
|
|
|
|
{
|
|
|
|
PARTBOX.Box = PARTBOX.Box + 1;
|
|
|
|
}
|
|
|
|
PARTBOX.SumBox = PARTBOX.Box;
|
|
|
|
PARTBOX.PoBillNum = _t.PoBillNum;
|
|
|
|
PARTBOX.VendId = _t.VendId;
|
|
|
|
PARTBOX.ShipTime = DateTime.Parse(_t.ShipTime.ToString()).ToShortDateString();
|
|
|
|
PARTBOX.Batch = _tDetail.Batch;
|
|
|
|
PARTBOX.PoLine = _tDetail.PoLine;
|
|
|
|
PARTBOX.PackQty = _tDetail.PackQty;
|
|
|
|
db.TB_ASN_PARTBOX.AddOrUpdate(PARTBOX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(askdetail.Extend2))
|
|
|
|
{
|
|
|
|
var ModelList = db.TA_CarModel.ToList();
|
|
|
|
foreach (var model in ModelList)
|
|
|
|
{
|
|
|
|
if (model.Model.Length <= askdetail.Extend2.Length)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (askdetail.Extend2.Contains(model.Model))
|
|
|
|
{
|
|
|
|
_tDetail.Extend1 = "FT";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_tDetail.Extend1 = "PT";
|
|
|
|
}
|
|
|
|
//if (askdetail.Extend2.Contains("941B") || askdetail.Extend2.Contains("330B") || askdetail.Extend2.Contains("812B") || askdetail.Extend2.Contains("260B") || askdetail.Extend2.Contains("875B") || askdetail.Extend2.Contains("710B") || askdetail.Extend2.Contains("280B") || askdetail.Extend2.Contains("770B") || askdetail.Extend2.Contains("290D") || askdetail.Extend2.Contains("891B") || askdetail.Extend2.Contains("031D") || askdetail.Extend2.Contains("822B") || askdetail.Extend2.Contains("845B") || askdetail.Extend2.Contains("067D") || askdetail.Extend2.Contains("115D"))
|
|
|
|
//{
|
|
|
|
// _tDetail.Extend1 = "FT";
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// _tDetail.Extend1 = "PT";
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_tDetail.Extend1 = "PT";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
db.TB_ASN_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<V_TB_ASK> GET_IS_COMPLETED_SEND(List<V_TB_ASK> p_list)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var _ls = p_list.Select(p => p.AskBillNum);
|
|
|
|
StringBuilder _buffer = new StringBuilder();
|
|
|
|
_buffer.Append(" select distinct (C.AskBillNum)from V_TB_ASK_DETAIL C");
|
|
|
|
_buffer.Append(" left JOIN ");
|
|
|
|
_buffer.Append(" (select SUM(Qty) as Qty, a.PoLine, a.AskBillNum, a.PartCode from v_tb_asn_detail a where a.IsDeleted=0 ");
|
|
|
|
_buffer.Append(" group by a.PoLine, a.AskBillNum, a.PartCode) AS D ");
|
|
|
|
_buffer.Append(" ON C.AskBillNum = D.AskBillNum AND C.PoLine = D.PoLine AND C.PartCode = D.PartCode ");
|
|
|
|
_buffer.Append(" WHERE C.AskQty>isnull(D.Qty,0)");
|
|
|
|
_buffer.Append(" and c.AskBillNum in ('{0}')");
|
|
|
|
var _str = string.Format(_buffer.ToString(), string.Join("','", _ls.ToArray()));
|
|
|
|
var _list = db.Database.SqlQuery<string>(_str).ToList();
|
|
|
|
|
|
|
|
p_list.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.IsComplete = true;
|
|
|
|
if (_list.Contains(p.AskBillNum))
|
|
|
|
{
|
|
|
|
p.IsComplete = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
return p_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<V_TB_ASK> GET_IS_COMPLETED_SEND1(List<V_TB_ASK> p_list, string lz)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
List<V_TB_ASK> lt = new List<V_TB_ASK>();
|
|
|
|
var _ls = p_list.Select(p => p.AskBillNum);
|
|
|
|
StringBuilder _buffer = new StringBuilder();
|
|
|
|
_buffer.Append(" select AskBillNum from V_TB_ASK_DETAIL ");
|
|
|
|
_buffer.Append($" WHERE Currency like '%{lz}%'");
|
|
|
|
var _str = string.Format(_buffer.ToString(), string.Join("','", _ls.ToArray()));
|
|
|
|
var _list = db.Database.SqlQuery<string>(_str).ToList();
|
|
|
|
var ll = p_list.Where(p => _list.Contains(p.AskBillNum)).ToList();
|
|
|
|
return ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public static List<V_TB_ASK> GET_IS_COMPLETED_SEND2(List<V_TB_ASK> p_list, string lz)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
List<V_TB_ASK> lt = new List<V_TB_ASK>();
|
|
|
|
var _ls = p_list.Select(p => p.AskBillNum);
|
|
|
|
StringBuilder _buffer = new StringBuilder();
|
|
|
|
_buffer.Append(" select AskBillNum from V_TB_ASK_DETAIL ");
|
|
|
|
_buffer.Append($" WHERE SubSite='{lz}'");
|
|
|
|
var _str = string.Format(_buffer.ToString(), string.Join("','", _ls.ToArray()));
|
|
|
|
var _list = db.Database.SqlQuery<string>(_str).ToList();
|
|
|
|
var ll = p_list.Where(p => _list.Contains(p.AskBillNum)).ToList();
|
|
|
|
return ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public static decimal Get_ASN_DETAIL_CAN(V_TB_ASK_DETAIL p_asn_detail)
|
|
|
|
{
|
|
|
|
decimal _canqty = 0;
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
if (p_asn_detail != null)
|
|
|
|
{
|
|
|
|
var ask = db.V_TB_ASK_DETAIL.FirstOrDefault(p => p.IsDeleted == false && p_asn_detail.AskBillNum == p.AskBillNum && p.PartCode == p_asn_detail.PartCode
|
|
|
|
&& p.PoLine == p_asn_detail.PoLine && p.PoBillNum == p_asn_detail.PoBillNum);
|
|
|
|
if (ask != null)
|
|
|
|
{
|
|
|
|
p_asn_detail = ask;
|
|
|
|
var list = db.V_TB_ASN_DETAIL.Where(p => p.IsDeleted == false && p_asn_detail.AskBillNum == p.AskBillNum && p.PartCode == p_asn_detail.PartCode
|
|
|
|
&& p.PoLine == p_asn_detail.PoLine && p.PoBillNum == p_asn_detail.PoBillNum).ToList();
|
|
|
|
var list_back = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == p_asn_detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.Qty < 0 && p.BillType == 3
|
|
|
|
&& p.PartCode == p_asn_detail.PartCode && p.PoLine == p_asn_detail.PoLine && p.PoBillNum == p_asn_detail.PoBillNum).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode, p.PoBillNum }).Select(p => new { BackSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode, PoBillNum = p.Key.PoBillNum }).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();
|
|
|
|
groupList.ForEach(p =>
|
|
|
|
{
|
|
|
|
if (p.PoBillNum == p_asn_detail.PoBillNum && p.PoLine == p_asn_detail.PoLine && p.PartCode == p_asn_detail.PartCode)
|
|
|
|
{
|
|
|
|
p_asn_detail.ShippedQty = p.ShipSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
list_back.ForEach(p =>
|
|
|
|
{
|
|
|
|
if (p.PoBillNum == p_asn_detail.PoBillNum && p.PoLine == p_asn_detail.PoLine && p.PartCode == p_asn_detail.PartCode)
|
|
|
|
{
|
|
|
|
p_asn_detail.RejectQty = Math.Abs(p.BackSum);//寄售退货数
|
|
|
|
}
|
|
|
|
});
|
|
|
|
decimal a = p_asn_detail.AskQty - (p_asn_detail.ShippedQty == null ? 0 : (decimal)p_asn_detail.ShippedQty) + p_asn_detail.RejectQty - (p_asn_detail.ReduceQty == null ? 0 : (decimal)p_asn_detail.ReduceQty);
|
|
|
|
_canqty = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _canqty;
|
|
|
|
}
|
|
|
|
public static List<V_TB_ASK_DETAIL> Get_CAN_SHIPQTY(List<V_TB_ASK_DETAIL> p_list)
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
if (p_list.Count > 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
var detail = p_list[0];
|
|
|
|
var list = db.V_TB_ASN_DETAIL.Where(p => p.IsDeleted == false && detail.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
var list_back = db.TB_ARRIVE_DETAIL.Where(p => p.Remark == detail.AskBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.Qty < 0 && p.BillType == 3).GroupBy(p => new { p.Remark, p.PoLine, p.PartCode, p.PoBillNum }).Select(p => new { BackSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, Remark = p.Key.Remark, PartCode = p.Key.PartCode, PoBillNum = p.Key.PoBillNum }).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 =>
|
|
|
|
{
|
|
|
|
var maxtime = db.TB_ASN_DETAIL.Where(p => p.PartCode == itm.PartCode && p.State > -1).Select(t => t.ProduceDate).Max();
|
|
|
|
|
|
|
|
itm.MaxTime = maxtime.ToString();
|
|
|
|
groupList.ForEach(p =>
|
|
|
|
{
|
|
|
|
if (p.PoBillNum == itm.PoBillNum && p.PoLine == itm.PoLine && p.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
itm.ShippedQty = p.ShipSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
list_back.ForEach(p =>
|
|
|
|
{
|
|
|
|
if (p.PoBillNum == itm.PoBillNum && p.PoLine == itm.PoLine && p.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
itm.RejectQty = Math.Abs(p.BackSum);//寄售退货数
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
decimal a = itm.AskQty - (itm.ShippedQty == null ? 0 : (decimal)itm.ShippedQty) + itm.RejectQty - (itm.ReduceQty == null ? 0 : (decimal)itm.ReduceQty);
|
|
|
|
itm.CanQty = a;
|
|
|
|
itm.PackQty = (itm.PackQty == 0) ? 1 : itm.PackQty;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (p_list.Count > 0)
|
|
|
|
{
|
|
|
|
return p_list;
|
|
|
|
}
|
|
|
|
return new List<V_TB_ASK_DETAIL>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void Get_V_TB_ASK_DETAIL_List(V_TB_ASK_DETAIL p_entity, Action<ResultObject<IQueryable<V_TB_ASK_DETAIL>>> p_action)
|
|
|
|
{
|
|
|
|
|
|
|
|
ResultObject<IQueryable<V_TB_ASK_DETAIL>> _ret = new ResultObject<IQueryable<V_TB_ASK_DETAIL>>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
IQueryable<V_TB_ASK_DETAIL> q = db.V_TB_ASK_DETAIL;
|
|
|
|
if (p_entity.UID != 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.UID == p_entity.UID);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.PoBillNum == 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 == p_entity.PartCode);
|
|
|
|
}
|
|
|
|
if (p_entity.ShippedQty != null && p_entity.ShippedQty != 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.ShippedQty == p_entity.ShippedQty);
|
|
|
|
}
|
|
|
|
if (p_entity.ReceivedQty != 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.ReceivedQty == p_entity.ReceivedQty);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PoUnit))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.PoUnit.Contains(p_entity.PoUnit));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_entity.EndTime != null)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p_entity.EndTime < p.EndTime);
|
|
|
|
}
|
|
|
|
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 != 0)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.Site))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.Site == p_entity.Site);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.VendName))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.VendName.Contains(p_entity.VendName));
|
|
|
|
}
|
|
|
|
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 == p_entity.AskBillNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_DETAIL_List", e.Message);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void Get_V_TB_ASK_DETAIL_Sum(V_TB_ASK_DETAIL p_entity, Action<ResultObject<IQueryable<V_TB_ASK_DETAIL>>> p_action)
|
|
|
|
{
|
|
|
|
|
|
|
|
ResultObject<IQueryable<V_TB_ASK_DETAIL>> _ret = new ResultObject<IQueryable<V_TB_ASK_DETAIL>>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
IQueryable<V_TB_ASK_DETAIL> q = db.V_TB_ASK_DETAIL;
|
|
|
|
if (p_entity.UID != 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
q = q.Where(p => p.UID == p_entity.UID);
|
|
|
|
}
|
|
|
|
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.ShippedQty != null && p_entity.ShippedQty != 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.ShippedQty == p_entity.ShippedQty);
|
|
|
|
}
|
|
|
|
if (p_entity.ReceivedQty != 0)
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.ReceivedQty == p_entity.ReceivedQty);
|
|
|
|
}
|
|
|
|
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 != 0)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
|
|
|
|
|
|
|
|
|
|
|
|
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.AskBillNum))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.AskBillNum.Contains(p_entity.AskBillNum));
|
|
|
|
}
|
|
|
|
_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_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_ASK_CONTROLLER), "Get_V_TB_ASK_DETAIL_List", e.Message);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 沈阳金杯
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="_num"></param>
|
|
|
|
/// <param name="p_remark"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static ResultObject<bool> Save_TB_ASK(string _num, string p_remark)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.FirstOrDefault(p => p.AskBillNum == _num);
|
|
|
|
if (_ls != null)
|
|
|
|
{
|
|
|
|
_ls.Remark = p_remark;
|
|
|
|
db.TB_ASK.AddOrUpdate(_ls);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "无法找到看板!";
|
|
|
|
}
|
|
|
|
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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_STATE", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ResultObject<bool> Save_TB_ASK_STATE(List<string> p_list, AskState p_state)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (p_state)
|
|
|
|
{
|
|
|
|
case AskState.Close:
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
if (_ls.Count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
var _asnlist = db.TB_ASN.Where(x => x.AskBillNum == p.AskBillNum && x.State == (int)AsnState.New).ToList();
|
|
|
|
if (_asnlist.Count > 0)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.MessageList.Add(p.AskBillNum + "存在未发货的发货单!");
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Close;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm => itm.State = (int)AskState.Close);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (_ret.MessageList.Count == 0)
|
|
|
|
{
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,不能关闭!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.Complete:
|
|
|
|
var _ls1 = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count1 = _ls1.Count(p => p.State == (int)AskState.Ship);
|
|
|
|
if (count1 == _ls1.Count && _ls1.Count > 0)
|
|
|
|
{
|
|
|
|
_ls1.ForEach(p =>
|
|
|
|
{
|
|
|
|
var _asnlist = db.TB_ASN.Where(x => x.AskBillNum == p.AskBillNum && x.State == (int)AsnState.New).ToList();
|
|
|
|
if (_asnlist.Count > 0)
|
|
|
|
{
|
|
|
|
_ret.MessageList.Add(p.AskBillNum + "存在未发货的发货单!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Complete;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm => itm.State = (int)AskState.Complete);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls1.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录非已发货状态,不能关闭!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.Confirm:
|
|
|
|
var _ls2 = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count2 = _ls2.Count(p => p.State == (int)AskState.Release);
|
|
|
|
if (count2 == _ls2.Count && _ls2.Count > 0)
|
|
|
|
{
|
|
|
|
_ls2.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Confirm;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
|
|
|
|
itm.State = (int)AskState.Confirm;
|
|
|
|
|
|
|
|
itm.UpdateTime = DateTime.Now;
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
#region 供应商确认要货状态完成
|
|
|
|
//var _pendingList = db.TB_PENING_ITEMS.Where(itm => itm.ITEM_NO == p.AskBillNum).ToList();
|
|
|
|
//_pendingList.ForEach(itm => {
|
|
|
|
// itm.ITEM_STATE = (int)PENDING_STATE.COMPLETED;
|
|
|
|
// itm.ITEM_CONTENT = "要货看板已完成!";
|
|
|
|
//}
|
|
|
|
//);
|
|
|
|
//db.TB_PENING_ITEMS.AddOrUpdate(itm => itm.GUID, _pendingList.ToArray());
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls2.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是发布状态记录!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.New:
|
|
|
|
var _ls3 = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count3 = _ls3.Count(p => p.State == (int)AskState.Release);
|
|
|
|
if (count3 == _ls3.Count && _ls3.Count > 0)
|
|
|
|
{
|
|
|
|
_ls3.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.New;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm => itm.State = (int)AskState.New);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls3.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是发布状态记录!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.Release:
|
|
|
|
List<TB_ASK> _ls4 = new List<TB_ASK>();
|
|
|
|
foreach (var item in p_list)
|
|
|
|
{
|
|
|
|
TB_ASK ask = db.TB_ASK.FirstOrDefault(q => q.AskBillNum == item);
|
|
|
|
if (ask != null)
|
|
|
|
{
|
|
|
|
_ls4.Add(ask);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//var _ls4 = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
foreach (var mail in _ls4)
|
|
|
|
{
|
|
|
|
TB_SUPPLIER_MAIL mall = new TB_SUPPLIER_MAIL();
|
|
|
|
mall.State = 0;
|
|
|
|
mall.SupplicerCode = mail.VendId;
|
|
|
|
mall.MailBody = "有新的要货订单" + mail.AskBillNum;
|
|
|
|
mall.Email = mail.PoBillNum;
|
|
|
|
db.TB_SUPPLIER_MAIL.Add(mall);
|
|
|
|
}
|
|
|
|
int count4 = _ls4.Count(p => p.State == (int)AskState.New);
|
|
|
|
if (count4 > 0)
|
|
|
|
{
|
|
|
|
_ls4.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Release;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Release;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls4.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是新建状态记录!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.Reject:
|
|
|
|
var _ls5 = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count5 = _ls5.Count(p => p.State == (int)AskState.New || p.State == (int)AskState.Release);
|
|
|
|
if (count5 == _ls5.Count && _ls5.Count > 0)
|
|
|
|
{
|
|
|
|
_ls5.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Reject;
|
|
|
|
p.IsDeleted = true;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Reject;
|
|
|
|
itm.IsDeleted = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
//#region 供应商要货代办作废
|
|
|
|
//var _pendingList = db.TB_PENING_ITEMS.Where(itm => itm.ITEM_NO == p.AskBillNum).ToList();
|
|
|
|
//db.TB_PENING_ITEMS.RemoveRange(_pendingList);
|
|
|
|
//#endregion
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls5.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是新建或发布状态记录!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.CompleteForce:
|
|
|
|
var _ls6 = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum) && p.IsDeleted == false).ToList();
|
|
|
|
int count6 = _ls6.Count(p => p.State == (int)AskState.Confirm || p.State == (int)AskState.Ship);
|
|
|
|
if (count6 == _ls6.Count && _ls6.Count > 0)
|
|
|
|
{
|
|
|
|
_ls6.ForEach(p =>
|
|
|
|
{
|
|
|
|
if (p.State == (int)AskState.Complete)
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Reject;
|
|
|
|
p.IsDeleted = true;
|
|
|
|
}
|
|
|
|
// p.State = (int)AskState.CompleteForce;
|
|
|
|
#region 修改发货单
|
|
|
|
var _asnList = db.TB_ASN.Where(itm => itm.IsDeleted == false && itm.AskBillNum == p.AskBillNum && itm.State == 0).ToList();
|
|
|
|
_asnList.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AsnState.Reject;
|
|
|
|
itm.IsDeleted = true;
|
|
|
|
var _asnDetailList = db.TB_ASN_DETAIL.Where(asn => asn.IsDeleted == false && asn.AsnBillNum == itm.AsnBillNum).ToList();
|
|
|
|
_asnDetailList.ForEach(ad =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AsnState.Reject;
|
|
|
|
ad.IsDeleted = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASN_DETAIL.AddOrUpdate(asndetail => asndetail.UID, _asnDetailList.ToArray());
|
|
|
|
});
|
|
|
|
db.TB_ASN.AddOrUpdate(_asnList.ToArray());
|
|
|
|
#endregion
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum && itm.IsDeleted == false).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.AskQty = 0;
|
|
|
|
var asn = db.V_TB_ASN_DETAIL.Where(ask => ask.AskBillNum == itm.AskBillNum && ask.IsDeleted == false && (ask.State == (int)AsnState.Ship || ask.State == (int)AsnState.Receive))
|
|
|
|
.GroupBy(ask => new { ask.AskBillNum, ask.PoLine, ask.PartCode })
|
|
|
|
.Select(ask => new { AsSum = ask.Sum(itm1 => itm1.Qty), PoLine = ask.Key.PoLine, AskBillNum = ask.Key.AskBillNum, PartCode = ask.Key.PartCode }).ToList();
|
|
|
|
|
|
|
|
asn.ForEach(itm1 =>
|
|
|
|
{
|
|
|
|
if (itm1.AskBillNum == itm.AskBillNum && itm1.PoLine == itm.PoLine && itm1.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
itm.AskQty = itm1.AsSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//itm.State = (int)AskState.CompleteForce;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls6.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是【已确认】或【已发货】状态,【发布状态】请用取消发布或看板作废!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.Receive:
|
|
|
|
var _ls7 = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count7 = _ls7.Count(p => p.State == (int)AskState.New || p.State == (int)AskState.Release);
|
|
|
|
if (count7 > 0)
|
|
|
|
{
|
|
|
|
_ls7.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Receive;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Receive;
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls7.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是新建或发布状态记录!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AskState.NoConfirm:
|
|
|
|
var _ls8 = db.TB_ASN.Where(p => p_list.Contains(p.AskBillNum) && p.IsDeleted == false).ToList();
|
|
|
|
if (_ls8.Count == 0)
|
|
|
|
{
|
|
|
|
var _askList = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum) && p.IsDeleted == false).ToList();
|
|
|
|
_askList.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Release;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Release;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _askList.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录已经有发货单据不能取消!";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(_ret.Message))
|
|
|
|
{
|
|
|
|
if (db.SaveChanges() != -1)
|
|
|
|
{
|
|
|
|
if (p_state == AskState.CompleteForce)
|
|
|
|
{
|
|
|
|
|
|
|
|
using (ScpEntities db1 = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
if (p_list.Count > 0)
|
|
|
|
{
|
|
|
|
var _entityList = db.V_TB_ASK_DETAIL.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
|
|
|
|
var _item = _entityList.FirstOrDefault();
|
|
|
|
|
|
|
|
if (_item.AskBillNum.Contains("U"))
|
|
|
|
{
|
|
|
|
var _planList = db1.TB_PO_PLAN_EXTEND.Where(p => p.Domain == _item.Site && p.EndTime == _item.EndTime && p.PoBillNum == _item.PoBillNum).ToList();
|
|
|
|
_planList.ForEach(p =>
|
|
|
|
{
|
|
|
|
|
|
|
|
var _first = _entityList.Where(itm => itm.PoBillNum == p.PoBillNum && itm.PartCode == p.PartCode && itm.EndTime == p.EndTime).FirstOrDefault();
|
|
|
|
if (_first != null)
|
|
|
|
{
|
|
|
|
p.PlanQty = _first.AskQty;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
db1.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_STATE", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
public static ResultObject<bool> Save_ASK_MODIF_QTY(V_TB_ASK p_ask, List<V_TB_ASK_DETAIL> p_list)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
|
|
|
|
var _list = db.V_TB_ASK_DETAIL.Where(p => p.AskBillNum == p_ask.AskBillNum && p.IsDeleted == false).ToList();
|
|
|
|
var _ls = Get_CAN_SHIPQTY(_list);
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
var _entity = p_list.Where(itm => itm.AskBillNum == p.AskBillNum && itm.PoLine == p.PoLine && itm.PartCode == p.PartCode && itm.PoBillNum == p.PoBillNum).FirstOrDefault();
|
|
|
|
if (_entity != null)
|
|
|
|
{
|
|
|
|
p.AskQty = _entity.AskQty;
|
|
|
|
if (_entity.AskQty < p.ShippedQty)
|
|
|
|
{
|
|
|
|
_ret.MessageList.Add(string.Format("零件编号{0}行号{1},【要货数量】必须大于等于【已发数量】", p.PartCode, p.PoLine.ToString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (_ret.MessageList.Count > 0)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Succeed;
|
|
|
|
_ret.Result = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int state = db.SaveChanges();
|
|
|
|
if (state != -1)
|
|
|
|
{
|
|
|
|
using (ScpEntities db1 = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
|
|
|
|
if (p_ask.AskBillNum.Contains("U"))
|
|
|
|
{
|
|
|
|
var _planList = db1.TB_PO_PLAN_EXTEND.Where(p => p.Domain == p_ask.Site && p.EndTime == p_ask.EndTime && p.PoBillNum == p_ask.PoBillNum).ToList();
|
|
|
|
|
|
|
|
_planList.ForEach(p =>
|
|
|
|
{
|
|
|
|
|
|
|
|
var _first = _ls.Where(itm => itm.PoBillNum == p.PoBillNum && itm.PartCode == p.PartCode && itm.EndTime == p.EndTime).FirstOrDefault();
|
|
|
|
if (_first != null)
|
|
|
|
{
|
|
|
|
p.PlanQty = _first.AskQty;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
db1.SaveChanges();
|
|
|
|
}
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ResultObject<bool> Save_TB_ASK_STATE_CC(List<string> p_list, AskState p_state, User p_user, string p_fail = null)
|
|
|
|
{
|
|
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
if (p_state == AskState.Confirm)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count = _ls.Count(p => p.State == (int)AskState.Release);
|
|
|
|
if (count == _ls.Count && _ls.Count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.UpdateUser = p_user.ChineseName;
|
|
|
|
p.UpdateTime = DateTime.Now;
|
|
|
|
p.State = (int)AskState.Confirm;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm => itm.State = (int)AskState.Confirm);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是发布状态记录!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_state == AskState.New)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count = _ls.Count(p => p.State == (int)AskState.Release);
|
|
|
|
if (count == _ls.Count && _ls.Count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.UpdateUser = p_user.ChineseName;
|
|
|
|
p.UpdateTime = DateTime.Now;
|
|
|
|
p.State = (int)AskState.New;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm => itm.State = (int)AskState.New);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是发布状态记录!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_state == AskState.Back)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count = _ls.Count(p => p.State == (int)AskState.New);
|
|
|
|
if (count == _ls.Count && _ls.Count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.UpdateUser = p_user.ChineseName;
|
|
|
|
p.UpdateTime = DateTime.Now;
|
|
|
|
p.State = (int)AskState.Back;
|
|
|
|
if (!string.IsNullOrEmpty(p_fail))
|
|
|
|
{
|
|
|
|
p.UpdateInfo = p_fail;
|
|
|
|
}
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Back;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是新建状态记录!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_state == AskState.Release)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count = _ls.Count(p => p.State == (int)AskState.New);
|
|
|
|
if (count == _ls.Count && _ls.Count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.UpdateUser = p_user.ChineseName;
|
|
|
|
p.UpdateTime = DateTime.Now;
|
|
|
|
p.State = (int)AskState.Release;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Release;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
#region 供应商代办任务新
|
|
|
|
TB_PENING_ITEMS _item = new TB_PENING_ITEMS();
|
|
|
|
_item.ROLE_NAME = "供应商";
|
|
|
|
_item.ITEM_NO = p.AskBillNum;
|
|
|
|
_item.ITEM_CONTENT = "要货看盘有信息";
|
|
|
|
_item.ITEM_TYPE = (int)PENDING_MESSAGE_TYPE.NEW_ASK;
|
|
|
|
_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;
|
|
|
|
_item.GUID = Guid.NewGuid();
|
|
|
|
db.TB_PENING_ITEMS.Add(_item);
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是新建状态记录!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_state == AskState.Reject)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count = _ls.Count(p => p.State == (int)AskState.New || p.State == (int)AskState.Release);
|
|
|
|
if (count == _ls.Count && _ls.Count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Reject;
|
|
|
|
p.IsDeleted = true;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Reject;
|
|
|
|
itm.IsDeleted = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
//#region 供应商要货代办作废
|
|
|
|
//var _pendingList = db.TB_PENING_ITEMS.Where(itm => itm.ITEM_NO == p.AskBillNum).ToList();
|
|
|
|
//db.TB_PENING_ITEMS.RemoveRange(_pendingList);
|
|
|
|
//#endregion
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是新建或发布状态记录!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_state == AskState.CompleteForce)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum) && p.IsDeleted == false).ToList();
|
|
|
|
int count = _ls.Count(p => p.State == (int)AskState.Confirm || p.State == (int)AskState.Ship);
|
|
|
|
if (count == _ls.Count && _ls.Count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
if (p.State == (int)AskState.Complete)
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Reject;
|
|
|
|
p.IsDeleted = true;
|
|
|
|
}
|
|
|
|
// p.State = (int)AskState.CompleteForce;
|
|
|
|
#region 修改发货单
|
|
|
|
var _asnList = db.TB_ASN.Where(itm => itm.IsDeleted == false && itm.AskBillNum == p.AskBillNum && itm.State == 0).ToList();
|
|
|
|
_asnList.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AsnState.Reject;
|
|
|
|
itm.IsDeleted = true;
|
|
|
|
var _asnDetailList = db.TB_ASN_DETAIL.Where(asn => asn.IsDeleted == false && asn.AsnBillNum == itm.AsnBillNum).ToList();
|
|
|
|
_asnDetailList.ForEach(ad =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AsnState.Reject;
|
|
|
|
ad.IsDeleted = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASN_DETAIL.AddOrUpdate(asndetail => asndetail.UID, _asnDetailList.ToArray());
|
|
|
|
});
|
|
|
|
db.TB_ASN.AddOrUpdate(_asnList.ToArray());
|
|
|
|
#endregion
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum && itm.IsDeleted == false).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.AskQty = 0;
|
|
|
|
var asn = db.V_TB_ASN_DETAIL.Where(ask => ask.AskBillNum == itm.AskBillNum && ask.IsDeleted == false && (ask.State == (int)AsnState.Ship || ask.State == (int)AsnState.Receive))
|
|
|
|
.GroupBy(ask => new { ask.AskBillNum, ask.PoLine, ask.PartCode })
|
|
|
|
.Select(ask => new { AsSum = ask.Sum(itm1 => itm1.Qty), PoLine = ask.Key.PoLine, AskBillNum = ask.Key.AskBillNum, PartCode = ask.Key.PartCode }).ToList();
|
|
|
|
asn.ForEach(itm1 =>
|
|
|
|
{
|
|
|
|
if (itm1.AskBillNum == itm.AskBillNum && itm1.PoLine == itm.PoLine && itm1.PartCode == itm.PartCode)
|
|
|
|
{
|
|
|
|
itm.AskQty = itm1.AsSum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//itm.State = (int)AskState.CompleteForce;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是【已确认】或【已发货】状态,【发布状态】请用取消发布或看板作废!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_state == AskState.Receive)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum)).ToList();
|
|
|
|
int count = _ls.Count(p => p.State == (int)AskState.New || p.State == (int)AskState.Release);
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
_ls.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Receive;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Receive;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _ls.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录,有不是新建或发布状态记录!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_state == AskState.NoConfirm)
|
|
|
|
{
|
|
|
|
var _ls = db.TB_ASN.Where(p => p_list.Contains(p.AskBillNum) && p.IsDeleted == false).ToList();
|
|
|
|
if (_ls.Count == 0)
|
|
|
|
{
|
|
|
|
var _askList = db.TB_ASK.Where(p => p_list.Contains(p.AskBillNum) && p.IsDeleted == false).ToList();
|
|
|
|
_askList.ForEach(p =>
|
|
|
|
{
|
|
|
|
p.State = (int)AskState.Release;
|
|
|
|
var _list = db.TB_ASK_DETAIL.Where(itm => itm.AskBillNum == p.AskBillNum).ToList();
|
|
|
|
_list.ForEach(itm =>
|
|
|
|
{
|
|
|
|
itm.State = (int)AskState.Release;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _askList.ToArray());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.Message = "选择的记录已经有发货单据不能取消!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_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_ASK_CONTROLLER), "Save_TB_ASK_STATE", e.Message);
|
|
|
|
_ret.Result = false;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|