You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1835 lines
85 KiB
1835 lines
85 KiB
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;
|
|
|
|
namespace CK.SCP.Controller
|
|
{
|
|
public static class SCP_BARCODE_CONTROLLER
|
|
{
|
|
|
|
public static ResultObject<bool> Save_TB_PRINT_COUNT(TB_PRINT_COUNT p_entity)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var _print=db.TB_PRINT_COUNT.Where(p => p.BillNo == p_entity.BillNo).FirstOrDefault();
|
|
if (_print == null)
|
|
{
|
|
_print = new TB_PRINT_COUNT();
|
|
_print.BillNo = p_entity.BillNo;
|
|
_print.PrintType = p_entity.PrintType;
|
|
_print.PrintCount = 1;
|
|
}
|
|
db.TB_PRINT_COUNT.AddOrUpdate(p => new {p.PrintType,p.BillNo }, p_entity);
|
|
|
|
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_BARCODE_CONTROLLER), "Save_TB_PRINT_COUNT", 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_BARCODE_CONTROLLER), "Save_TB_PRINT_COUNT", 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_BARCODE_CONTROLLER), "Save_TB_PRINT_COUNT", 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_BARCODE_CONTROLLER), "Save_TB_PRINT_COUNT", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static ResultObject<bool> DELETE_TB_PALLETS_BTL(List<string> _ls)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
foreach(var ls in _ls)
|
|
{
|
|
List<TB_ASN_PARTBOX> list = new List<TB_ASN_PARTBOX>();
|
|
var _pallete = db.TB_PALLETS_BTL.FirstOrDefault(p=>p.UID.ToString()==ls);
|
|
if (!string.IsNullOrEmpty(_pallete.PartCode))
|
|
{
|
|
var _asnpart = db.TB_ASN_PARTBOX.FirstOrDefault(p=>p.PartCode== _pallete.PartCode&&p.AsnBillNum== _pallete.AsnBillNum);
|
|
_asnpart.Box = _asnpart.Box +int.Parse(_pallete.Box);
|
|
list.Add(_asnpart);
|
|
}
|
|
if (!string.IsNullOrEmpty(_pallete.PartCode1))
|
|
{
|
|
var _asnpart = db.TB_ASN_PARTBOX.FirstOrDefault(p => p.PartCode == _pallete.PartCode1 && p.AsnBillNum == _pallete.AsnBillNum);
|
|
_asnpart.Box = _asnpart.Box + int.Parse(_pallete.Box1);
|
|
list.Add(_asnpart);
|
|
}
|
|
if (!string.IsNullOrEmpty(_pallete.PartCode2))
|
|
{
|
|
var _asnpart = db.TB_ASN_PARTBOX.FirstOrDefault(p => p.PartCode == _pallete.PartCode2 && p.AsnBillNum == _pallete.AsnBillNum);
|
|
_asnpart.Box = _asnpart.Box + int.Parse(_pallete.Box2);
|
|
list.Add(_asnpart);
|
|
}
|
|
if (!string.IsNullOrEmpty(_pallete.PartCode3))
|
|
{
|
|
var _asnpart = db.TB_ASN_PARTBOX.FirstOrDefault(p => p.PartCode == _pallete.PartCode3 && p.AsnBillNum == _pallete.AsnBillNum);
|
|
_asnpart.Box = _asnpart.Box + int.Parse(_pallete.Box3);
|
|
list.Add(_asnpart);
|
|
}
|
|
if (!string.IsNullOrEmpty(_pallete.PartCode4))
|
|
{
|
|
var _asnpart = db.TB_ASN_PARTBOX.FirstOrDefault(p => p.PartCode == _pallete.PartCode4 && p.AsnBillNum == _pallete.AsnBillNum);
|
|
_asnpart.Box = _asnpart.Box + int.Parse(_pallete.Box4);
|
|
list.Add(_asnpart);
|
|
}
|
|
if (!string.IsNullOrEmpty(_pallete.PartCode5))
|
|
{
|
|
var _asnpart = db.TB_ASN_PARTBOX.FirstOrDefault(p => p.PartCode == _pallete.PartCode5 && p.AsnBillNum == _pallete.AsnBillNum);
|
|
_asnpart.Box = _asnpart.Box + int.Parse(_pallete.Box5);
|
|
list.Add(_asnpart);
|
|
}
|
|
_pallete.IsDeleted = true;
|
|
var _ts = db.TS_BARCODE.Where(p => p.PalletNum == _pallete.PalletNum).ToList();
|
|
_ts.ForEach(p=>{
|
|
p.PalletNum = "";
|
|
});
|
|
db.TS_BARCODE.AddOrUpdate(_ts.ToArray());
|
|
db.TB_ASN_PARTBOX.AddOrUpdate(list.ToArray());
|
|
db.TB_PALLETS_BTL.AddOrUpdate(_pallete);
|
|
}
|
|
|
|
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 void Get_TS_PALLETS_BTL_List(TB_PALLETS_BTL p_entity, Action<ResultObject<IQueryable<TB_PALLETS_BTL>>> p_action)
|
|
{
|
|
ResultObject<IQueryable<TB_PALLETS_BTL>> _ret = new ResultObject<IQueryable<TB_PALLETS_BTL>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<TB_PALLETS_BTL> q = db.TB_PALLETS_BTL;
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PalletNum))
|
|
{
|
|
q = q.Where(p => p.PalletNum == p_entity.PalletNum);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.AsnBillNum))
|
|
{
|
|
q = q.Where(p => p.AsnBillNum == p_entity.AsnBillNum);
|
|
}
|
|
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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_List", e.Message);
|
|
throw e;
|
|
}
|
|
|
|
}
|
|
|
|
public static ResultObject<List<TB_PRINT_COUNT>> Get_TB_PRINT_COUNT_List(TB_PRINT_COUNT p_entity)
|
|
{
|
|
ResultObject<List<TB_PRINT_COUNT>> _ret = new ResultObject<List<TB_PRINT_COUNT>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<TB_PRINT_COUNT> q = db.TB_PRINT_COUNT;
|
|
if (!string.IsNullOrEmpty(p_entity.BillNo))
|
|
{
|
|
q = q.Where(p => p.BillNo.Contains(p_entity.BillNo));
|
|
}
|
|
if (p_entity.PrintCount != 0)
|
|
{
|
|
q = q.Where(p => p.PrintCount == p_entity.PrintCount);
|
|
}
|
|
if (p_entity.PrintType != 0)
|
|
{
|
|
q = q.Where(p => p.PrintType == p_entity.PrintType);
|
|
}
|
|
if (p_entity.UID != 0)
|
|
{
|
|
q = q.Where(p => p.UID == p_entity.UID);
|
|
}
|
|
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = q.ToList();
|
|
}
|
|
}
|
|
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_BARCODE_CONTROLLER), "Get_TB_PRINT_COUNT_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_BARCODE_CONTROLLER), "Get_TB_PRINT_COUNT_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_BARCODE_CONTROLLER), "Get_TB_PRINT_COUNT_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_BARCODE_CONTROLLER), "Get_TB_PRINT_COUNT_List", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
public static void Get_TS_BARCODE_List(TS_BARCODE p_entity, Action<ResultObject<IQueryable<TS_BARCODE>>> p_action)
|
|
{
|
|
ResultObject<IQueryable<TS_BARCODE>> _ret = new ResultObject<IQueryable<TS_BARCODE>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<TS_BARCODE> q = db.TS_BARCODE;
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.BarCode))
|
|
{
|
|
q = q.Where(p => p.BarCode == p_entity.BarCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.FullBarCode))
|
|
{
|
|
q = q.Where(p => p.FullBarCode == p_entity.FullBarCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.PartCode))
|
|
{
|
|
q = q.Where(p => p.PartCode == p_entity.PartCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.VendPartCode))
|
|
{
|
|
q = q.Where(p => p.VendPartCode == p_entity.VendPartCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.Batch))
|
|
{
|
|
q = q.Where(p => p.Batch == p_entity.Batch);
|
|
}
|
|
if (p_entity.ManageType != 0)
|
|
{
|
|
q = q.Where(p => p.ManageType == p_entity.ManageType);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.SerialNum))
|
|
{
|
|
q = q.Where(p => p.SerialNum.Contains(p_entity.SerialNum));
|
|
}
|
|
if (p_entity.Qty != 0)
|
|
{
|
|
q = q.Where(p => p.Qty == p_entity.Qty);
|
|
}
|
|
if (p_entity.BarCodeType != 0)
|
|
{
|
|
q = q.Where(p => p.BarCodeType == p_entity.BarCodeType);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.BillNum))
|
|
{
|
|
q = q.Where(p => p.BillNum.Contains(p_entity.BillNum));
|
|
}
|
|
if (p_entity.PoBillLine != 0)
|
|
{
|
|
q = q.Where(p => p.PoBillLine == p_entity.PoBillLine);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.VendId))
|
|
{
|
|
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.VendBatch))
|
|
{
|
|
q = q.Where(p => p.VendBatch == p_entity.VendBatch);
|
|
}
|
|
if (p_entity.PackQty != 0)
|
|
{
|
|
q = q.Where(p => p.PackQty == p_entity.PackQty);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.CreateOper))
|
|
{
|
|
q = q.Where(p => p.CreateOper.Contains(p_entity.CreateOper));
|
|
}
|
|
if (p_entity.State != 0)
|
|
{
|
|
q = q.Where(p => p.State == p_entity.State);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.Remark))
|
|
{
|
|
q = q.Where(p => p.Remark.Contains(p_entity.Remark));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.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.IsScanned)
|
|
{
|
|
q = q.Where(p => p.IsScanned==false);
|
|
}
|
|
//if (!string.IsNullOrEmpty(p_entity.PartName))
|
|
//{
|
|
// q = q.Where(p => p.PartName.Contains(p_entity.PartName));
|
|
//}
|
|
//if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
|
|
//{
|
|
// q = q.Where(p => p_entity.UserInAddress.Contains(p.Address));
|
|
//}
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = q;
|
|
p_action(_ret);
|
|
}
|
|
}
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList())
|
|
{
|
|
|
|
error.ValidationErrors.ToList().ForEach(i =>
|
|
{
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
|
|
});
|
|
}
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_List", e.Message);
|
|
throw e;
|
|
}
|
|
|
|
}
|
|
|
|
public static void Get_TS_BARCODE_SMALL_List(TS_BARCODE_SMALL p_entity, Action<ResultObject<IQueryable<TS_BARCODE_SMALL>>> p_action)
|
|
{
|
|
ResultObject<IQueryable<TS_BARCODE_SMALL>> _ret = new ResultObject<IQueryable<TS_BARCODE_SMALL>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<TS_BARCODE_SMALL> q = db.TS_BARCODE_SMALL;
|
|
if (!string.IsNullOrEmpty(p_entity.BarCode))
|
|
{
|
|
q = q.Where(p => p.BarCode == p_entity.BarCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.FullBarCode))
|
|
{
|
|
q = q.Where(p => p.FullBarCode == p_entity.FullBarCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.PartCode))
|
|
{
|
|
q = q.Where(p => p.PartCode == p_entity.PartCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.VendPartCode))
|
|
{
|
|
q = q.Where(p => p.VendPartCode == p_entity.VendPartCode);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.Batch))
|
|
{
|
|
q = q.Where(p => p.Batch == p_entity.Batch);
|
|
}
|
|
if (p_entity.ManageType != 0)
|
|
{
|
|
q = q.Where(p => p.ManageType == p_entity.ManageType);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.SerialNum))
|
|
{
|
|
q = q.Where(p => p.SerialNum.Contains(p_entity.SerialNum));
|
|
}
|
|
if (p_entity.Qty != 0)
|
|
{
|
|
q = q.Where(p => p.Qty == p_entity.Qty);
|
|
}
|
|
if (p_entity.BarCodeType != 0)
|
|
{
|
|
q = q.Where(p => p.BarCodeType == p_entity.BarCodeType);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.BillNum))
|
|
{
|
|
q = q.Where(p => p.BillNum.Contains(p_entity.BillNum));
|
|
}
|
|
if (p_entity.PoBillLine != 0)
|
|
{
|
|
q = q.Where(p => p.PoBillLine == p_entity.PoBillLine);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.VendId))
|
|
{
|
|
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.VendBatch))
|
|
{
|
|
q = q.Where(p => p.VendBatch == p_entity.VendBatch);
|
|
}
|
|
if (p_entity.SmallPackQty != 0)
|
|
{
|
|
q = q.Where(p => p.SmallPackQty == p_entity.SmallPackQty);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.CreateOper))
|
|
{
|
|
q = q.Where(p => p.CreateOper.Contains(p_entity.CreateOper));
|
|
}
|
|
if (p_entity.State != 0)
|
|
{
|
|
q = q.Where(p => p.State == p_entity.State);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.Remark))
|
|
{
|
|
q = q.Where(p => p.Remark.Contains(p_entity.Remark));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.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));
|
|
}
|
|
_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_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_BARCODE_CONTROLLER), "Get_TS_BARCODE_List", e.Message);
|
|
throw e;
|
|
}
|
|
}
|
|
public static ResultObject<List<TS_BARCODE_SMALL>> CreateSmallBarcodeList(V_TB_ASN_DETAIL p_entity, int cnt = 1)
|
|
{
|
|
ResultObject<List<TS_BARCODE_SMALL>> _ret = new ResultObject<List<TS_BARCODE_SMALL>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var list = new List<TS_BARCODE_SMALL>();
|
|
var part = db.TA_PART.FirstOrDefault(p => p.PartCode == p_entity.PartCode);
|
|
if (part == null)
|
|
{
|
|
_ret.MessageList.Add("基础信息未找到该编号零件!");
|
|
}
|
|
var vendPart= db.TA_VEND_PART.FirstOrDefault(p => p.PartCode == p_entity.PartCode && p.VendId == p_entity.VendId);
|
|
var ret = GetSmallBarcodeRule(p_entity.PartCode, p_entity.Batch, cnt);
|
|
var _part = db.TA_PART.FirstOrDefault(p => p.PartCode == p_entity.PartCode && p.Site == p_entity.Site);
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
var barcodeRule = ret.Result;
|
|
for (int i = cnt; i > 0; i--)
|
|
{
|
|
var createTime = ScpCache.GetServerTime();
|
|
var code = GetLastSmallBarCode(p_entity.PartCode, p_entity.Batch, barcodeRule.LastNumber - i + 1);
|
|
if (part.PartDesc1.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT") ||
|
|
part.PartDesc2.ToUpper().Contains("左") || part.PartDesc2.ToUpper().Contains("LEFT"))
|
|
p_entity.Remark = "L" + p_entity.Remark;
|
|
if (part.PartDesc1.ToUpper().Contains("右") || part.PartDesc1.ToUpper().Contains("RIGHT") ||
|
|
part.PartDesc2.ToUpper().Contains("右") || part.PartDesc2.ToUpper().Contains("RIGHT"))
|
|
p_entity.Remark = "R" + p_entity.Remark;
|
|
string _check = (_part.Ischeck == false || _part.Ischeck == null) ? "" : "(免检)";
|
|
var barcode = new TS_BARCODE_SMALL
|
|
{
|
|
BarCode = code,
|
|
PartCode = part.PartCode,
|
|
VendPartCode = vendPart?.VendPartCode,
|
|
Batch = p_entity.Batch,
|
|
ProduceDate = (DateTime)p_entity.ProduceDate,
|
|
SerialNum = barcodeRule.LastNumber.ToString(ScpCache.Config.条码序列号格式),
|
|
PoUnit = p_entity.PoUnit,
|
|
Qty = p_entity.Qty,
|
|
BarCodeType = 1,
|
|
BillNum = p_entity.AsnBillNum,
|
|
PoBillNum = p_entity.PoBillNum,
|
|
PoBillLine = p_entity.PoLine,
|
|
VendId = p_entity.VendId,
|
|
VendBatch = p_entity.VendBatch,
|
|
CreateTime = p_entity.CreateTime,
|
|
CreateOper = p_entity.CreateUser,
|
|
State = 0,
|
|
Remark = p_entity.Remark,
|
|
SmallPackQty = p_entity.PackQty,
|
|
Site = p_entity.Site
|
|
|
|
};
|
|
if (_part == null)
|
|
{
|
|
_ret.MessageList.Add("未找到零件,可能是零件编号或地点信息错误,零件编号" + p_entity.PartCode);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "CreateBarcodeList", "未找到零件,可能是零件编号或地点信息错误,零件编号" + p_entity.PartCode);
|
|
}
|
|
else
|
|
{
|
|
var _isCheck = (_part.Ischeck == null) ? false : _part.Ischeck;
|
|
barcode.Qlevel = _part.Qlevel;
|
|
barcode.QMark = (_isCheck == true) ? "免检" : "全检";
|
|
barcode.ProjectId = _part.ProjectId;
|
|
}
|
|
var fullCode = GetFullCode_Small(barcode);
|
|
barcode.FullBarCode = fullCode;
|
|
list.Add(barcode);
|
|
}
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = list;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_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.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "CreateSmallBarcodeList", 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_BARCODE_CONTROLLER), "CreateSmallBarcodeList", 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_BARCODE_CONTROLLER), "CreateSmallBarcodeList", 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_BARCODE_CONTROLLER), "CreateSmallBarcodeList", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
public static ResultObject<TB_PALLETS> CreatePallets(TB_PALLETS p_entity, int cnt = 1)
|
|
{
|
|
ResultObject<TB_PALLETS> _ret = new ResultObject<TB_PALLETS>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var ret = GetPalletsRule(p_entity.PartCode, p_entity.Batch, cnt);
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
var barcodeRule = ret.Result;
|
|
for (int i = cnt; i > 0; i--)
|
|
{
|
|
var createTime = ScpCache.GetServerTime();
|
|
var code = GetLastPalletsBarCode(p_entity.PartCode, p_entity.Batch, barcodeRule.LastNumber - i + 1);
|
|
p_entity.PalletNum = code;
|
|
}
|
|
var fullCode = GetFullCode_Pallets(p_entity);
|
|
p_entity.FullBarCode = fullCode;
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = p_entity;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_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.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "CreateSmallBarcodeList", 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_BARCODE_CONTROLLER), "CreateSmallBarcodeList", 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_BARCODE_CONTROLLER), "CreateSmallBarcodeList", 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_BARCODE_CONTROLLER), "CreateSmallBarcodeList", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
/// <summary>
|
|
/// 批量生成条码(必须是相同零件号,调用时慎重!!!)
|
|
/// </summary>
|
|
/// <param name="details"></param>
|
|
/// <returns></returns>
|
|
public static ResultObject<List<TS_BARCODE>> CreateBatchBarcodeList(List<V_TB_ASN_DETAIL> details)
|
|
{
|
|
|
|
ResultObject<List<TS_BARCODE>> _ret = new ResultObject<List<TS_BARCODE>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var checkitem = details.Select(r => new { r.PartCode, r.Batch }).Distinct();
|
|
|
|
if (checkitem.Count() > 1)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Message = "批量生成条码出错,存在多批次不能调用批量打印,联系管理员!";
|
|
return _ret;
|
|
}
|
|
var list = new List<TS_BARCODE>();
|
|
var ret = GetBarcodeRule(details[0].PartCode, details[0].Batch, details.Count);
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
var barcodeRule = ret.Result;
|
|
var partcode = details[0].PartCode;
|
|
var vendId = details[0].VendId;
|
|
var asnBillNum = details[0].AsnBillNum;
|
|
var site= details[0].Site;
|
|
var poBillNum= details[0].PoBillNum;
|
|
var part = db.TA_PART.FirstOrDefault(p => p.PartCode == partcode);
|
|
if (part == null)
|
|
{
|
|
_ret.MessageList.Add("基础信息未找到该编号零件!");
|
|
//throw e;
|
|
}
|
|
var vendPart = db.TA_VEND_PART.FirstOrDefault(p => p.PartCode == partcode && p.VendId == vendId && p.Site == site);
|
|
var _part1 = db.TB_ASN_DETAIL.FirstOrDefault(p => p.PartCode == partcode && p.AsnBillNum == asnBillNum && p.PoBillNum == poBillNum);
|
|
string coustomer = "";
|
|
if (_part1.Extend1 == "FT")
|
|
{
|
|
var _coustomer = db.TA_SubPart.FirstOrDefault(p => p.PartCode == partcode);
|
|
if (_coustomer != null)
|
|
{
|
|
coustomer = _coustomer.SubPart.Replace("-", "");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
coustomer = part.PartCode.Replace("-", "");
|
|
}
|
|
var _part = db.TA_PART.FirstOrDefault(p => p.PartCode == partcode && p.Site == site);
|
|
var _AsnBillNum = db.TB_ASN.FirstOrDefault(p => p.AsnBillNum == asnBillNum);
|
|
var _Ask = db.TB_ASK_DETAIL.FirstOrDefault(p => p.PartCode == part.PartCode);
|
|
var _Askde = db.TB_ASK_DETAIL.FirstOrDefault(p => p.PartCode == part.PartCode && p.AskBillNum == _AsnBillNum.AskBillNum);
|
|
string str;
|
|
string str1;
|
|
string str2;
|
|
string str3;
|
|
string str4;
|
|
string str5;
|
|
string str6;
|
|
str2 = _AsnBillNum.ReceiveTime.ToString();
|
|
var _PinFan = db.TA_PinFan.FirstOrDefault(p => p.PartCode == partcode);
|
|
str6 = _PinFan == null ? "" : _PinFan.Barcodnt;
|
|
var _Appliance = db.TA_Appliance.FirstOrDefault(p => p.VendID == _AsnBillNum.VendId && p.PartNumber == _Askde.SubSite);
|
|
str = _Appliance == null ? "" : _Appliance.Model;//车型
|
|
str1 = _Appliance == null ? "" : _Appliance.ReciteNumber;//背番号
|
|
str3 = _Appliance == null ? "" : _Appliance.SufanLand;//所番地
|
|
str4 = _Appliance == null ? "" : _Appliance.BoxType;//箱种
|
|
str5 = _Appliance == null ? "" : _Appliance.PostEngineering;//后工程
|
|
for (int i = 0; i < details.Count; i++)
|
|
{
|
|
var barcodenum = barcodeRule.LastNumber - details.Count+i+1;
|
|
V_TB_ASN_DETAIL p_entity = details[i];
|
|
var createTime = ScpCache.GetServerTime();
|
|
var code = GetLastBarCode(p_entity.PartCode, p_entity.Batch, barcodenum);
|
|
if (part.PartDesc1.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT") ||
|
|
part.PartDesc2.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT"))
|
|
p_entity.Remark = "L" + p_entity.Remark;
|
|
if (part.PartDesc1.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT") ||
|
|
part.PartDesc2.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT"))
|
|
p_entity.Remark = "R" + p_entity.Remark;
|
|
string _check = (_part.Ischeck == false || _part.Ischeck == null) ? "" : "(免检)";
|
|
var barcode = new TS_BARCODE
|
|
{
|
|
BarCode = code,
|
|
PartCode = part.PartCode,
|
|
Extend12 = coustomer,
|
|
|
|
VendPartCode = vendPart?.VendPartCode,
|
|
Batch = p_entity.Batch,
|
|
ProduceDate = (DateTime)p_entity.ProduceDate,
|
|
SerialNum = barcodenum.ToString(ScpCache.Config.条码序列号格式),
|
|
PoUnit = p_entity.PoUnit,
|
|
Qty = p_entity.Qty,
|
|
BarCodeType = 1,
|
|
BillNum = p_entity.AsnBillNum,
|
|
PoBillNum = p_entity.PoBillNum,
|
|
PoBillLine = p_entity.PoLine,
|
|
VendId = p_entity.VendId,
|
|
VendBatch = p_entity.VendBatch,
|
|
Extend1 = _part.PartDesc2,
|
|
Extend2 = _part.ReceivePort,//零件毛重
|
|
Extend3 = _part.PalletSize,//零件净重
|
|
CreateTime = p_entity.CreateTime,
|
|
CreateOper = p_entity.CreateUser,
|
|
State = 0,
|
|
Remark = p_entity.UpdateInfo,
|
|
PackQty = p_entity.PackQty,
|
|
Site = p_entity.Site,
|
|
IsScanned = false,
|
|
Extend4 = _Askde.SubSite,//零件号不是物料号
|
|
Extend5 = str,//车型
|
|
Extend7 = part.PartDesc1,
|
|
Extend6 = DateTime.Parse(str2),
|
|
Extend8 = str1,//背番号
|
|
Extend9 = str3,//所番地
|
|
Extend10 = str4,//箱种
|
|
Extend11 = str5,//后工程
|
|
Extend13 = (_AsnBillNum.ShipTime).Value,
|
|
Extend14 = _part1.Extend2,
|
|
Extend15 = str6,//品番
|
|
Extend16 = _part1.Extend1,
|
|
ProjectId = p_entity.UpdateUser,
|
|
OtherVendName = _Appliance?.OtherVendName
|
|
};
|
|
|
|
if (_part == null)
|
|
{
|
|
_ret.MessageList.Add("未找到零件,可能是零件编号或地点信息错误,零件编号" + p_entity.PartCode);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "CreateBarcodeList", "未找到零件,可能是零件编号或地点信息错误,零件编号" + p_entity.PartCode);
|
|
}
|
|
else
|
|
{
|
|
var _isCheck = (_part.Ischeck == null) ? false : _part.Ischeck;
|
|
barcode.Qlevel = _part.Qlevel;
|
|
barcode.QMark = (_isCheck == true) ? "免检" : "全检";
|
|
//barcode.ProjectId = _part.ProjectId;
|
|
}
|
|
var fullCode = GetFullCode(barcode);
|
|
barcode.FullBarCode = fullCode;
|
|
list.Add(barcode);
|
|
}
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = list;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_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.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "CreateBatchBarcodeList", 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_BARCODE_CONTROLLER), "CreateBatchBarcodeList", 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_BARCODE_CONTROLLER), "CreateBatchBarcodeList", 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_BARCODE_CONTROLLER), "CreateBarcodeList", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static ResultObject<List<TS_BARCODE>> CreateBarcodeList(V_TB_ASN_DETAIL p_entity, int cnt = 1)
|
|
{
|
|
|
|
ResultObject<List<TS_BARCODE>> _ret = new ResultObject<List<TS_BARCODE>>();
|
|
try
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var list = new List<TS_BARCODE>();
|
|
var part = db.TA_PART.FirstOrDefault(p => p.PartCode == p_entity.PartCode);
|
|
if (part == null)
|
|
{
|
|
_ret.MessageList.Add("基础信息未找到该编号零件!");
|
|
//throw e;
|
|
}
|
|
var vendPart = db.TA_VEND_PART.FirstOrDefault(p => p.PartCode == p_entity.PartCode && p.VendId == p_entity.VendId && p.Site == p_entity.Site);
|
|
var ret = GetBarcodeRule(p_entity.PartCode, p_entity.Batch, cnt);
|
|
var _part1 = db.TB_ASN_DETAIL.FirstOrDefault(p => p.PartCode == p_entity.PartCode && p.AsnBillNum == p_entity.AsnBillNum && p.PoBillNum == p_entity.PoBillNum);
|
|
string coustomer = "";
|
|
if (_part1.Extend1 == "FT")
|
|
{
|
|
var _coustomer = db.TA_SubPart.FirstOrDefault(p => p.PartCode == p_entity.PartCode);
|
|
if (_coustomer != null)
|
|
{
|
|
coustomer = _coustomer.SubPart.Replace("-", "");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
coustomer = part.PartCode.Replace("-", "");
|
|
}
|
|
|
|
|
|
var _part=db.TA_PART.FirstOrDefault(p=>p.PartCode==p_entity.PartCode && p.Site==p_entity.Site);
|
|
var _AsnBillNum=db.TB_ASN.FirstOrDefault(p => p.AsnBillNum == p_entity.AsnBillNum );
|
|
var _Ask = db.TB_ASK_DETAIL.FirstOrDefault(p => p.PartCode == part.PartCode);
|
|
var _Askde = db.TB_ASK_DETAIL.FirstOrDefault(p => p.PartCode == part.PartCode&&p.AskBillNum== _AsnBillNum.AskBillNum);
|
|
string str;
|
|
string str1;
|
|
string str2;
|
|
string str3;
|
|
string str4;
|
|
string str5;
|
|
string str6;
|
|
str2 = _AsnBillNum.ReceiveTime.ToString();
|
|
var _PinFan = db.TA_PinFan.FirstOrDefault(p => p.PartCode == p_entity.PartCode);
|
|
str6 = _PinFan == null ? "" : _PinFan.Barcodnt;
|
|
var _Appliance = db.TA_Appliance.FirstOrDefault(p => p.VendID == _AsnBillNum.VendId && p.PartNumber == _Askde.SubSite);
|
|
str = _Appliance == null ? "" : _Appliance.Model;//车型
|
|
str1 = _Appliance == null ? "" : _Appliance.ReciteNumber;//背番号
|
|
str3 = _Appliance == null ? "" : _Appliance.SufanLand;//所番地
|
|
str4 = _Appliance == null ? "" : _Appliance.BoxType;//箱种
|
|
str5 = _Appliance == null ? "" : _Appliance.PostEngineering;//后工程
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
var barcodeRule = ret.Result;
|
|
for (int i = cnt; i > 0; i--)
|
|
{
|
|
var createTime = ScpCache.GetServerTime();
|
|
var code = GetLastBarCode(p_entity.PartCode, p_entity.Batch, barcodeRule.LastNumber - i + 1);
|
|
if (part.PartDesc1.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT") ||
|
|
part.PartDesc2.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT"))
|
|
p_entity.Remark = "L" + p_entity.Remark;
|
|
if (part.PartDesc1.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT") ||
|
|
part.PartDesc2.ToUpper().Contains("左") || part.PartDesc1.ToUpper().Contains("LEFT"))
|
|
p_entity.Remark = "R" + p_entity.Remark;
|
|
string _check = (_part.Ischeck == false || _part.Ischeck == null) ? "" : "(免检)";
|
|
var barcode = new TS_BARCODE
|
|
{
|
|
BarCode = code,
|
|
PartCode = part.PartCode,
|
|
Extend12 = coustomer,
|
|
|
|
VendPartCode = vendPart?.VendPartCode,
|
|
Batch = p_entity.Batch,
|
|
ProduceDate = (DateTime)p_entity.ProduceDate,
|
|
SerialNum = barcodeRule.LastNumber.ToString(ScpCache.Config.条码序列号格式),
|
|
PoUnit = p_entity.PoUnit,
|
|
Qty = p_entity.Qty,
|
|
BarCodeType = 1,
|
|
BillNum = p_entity.AsnBillNum,
|
|
PoBillNum = p_entity.PoBillNum,
|
|
PoBillLine = p_entity.PoLine,
|
|
VendId = p_entity.VendId,
|
|
VendBatch = p_entity.VendBatch,
|
|
Extend1 = _part.PartDesc2,
|
|
Extend2 = _part.ReceivePort,//零件毛重
|
|
Extend3 = _part.PalletSize,//零件净重
|
|
CreateTime = p_entity.CreateTime,
|
|
CreateOper = p_entity.CreateUser,
|
|
State = 0,
|
|
Remark = p_entity.UpdateInfo,
|
|
PackQty = p_entity.PackQty,
|
|
Site = p_entity.Site,
|
|
IsScanned = false,
|
|
Extend4 = _Askde.SubSite,//零件号不是物料号
|
|
Extend5 = str,//车型
|
|
Extend7 = part.PartDesc1,
|
|
Extend6 = DateTime.Parse(str2),
|
|
Extend8 = str1,//背番号
|
|
Extend9 = str3,//所番地
|
|
Extend10 = str4,//箱种
|
|
Extend11 = str5,//后工程
|
|
Extend13 = (_AsnBillNum.ShipTime).Value,
|
|
Extend14 = _part1.Extend2,
|
|
Extend15 = str6,//品番
|
|
Extend16 = _part1.Extend1,
|
|
ProjectId = p_entity.UpdateUser,
|
|
OtherVendName= _Appliance?.OtherVendName
|
|
|
|
|
|
};
|
|
|
|
if (_part == null)
|
|
{
|
|
_ret.MessageList.Add("未找到零件,可能是零件编号或地点信息错误,零件编号"+ p_entity.PartCode);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "CreateBarcodeList", "未找到零件,可能是零件编号或地点信息错误,零件编号" + p_entity.PartCode);
|
|
}
|
|
else
|
|
{
|
|
var _isCheck=(_part.Ischeck == null)?false:_part.Ischeck;
|
|
barcode.Qlevel = _part.Qlevel;
|
|
barcode.QMark = (_isCheck == true) ? "免检" : "全检";
|
|
//barcode.ProjectId = _part.ProjectId;
|
|
}
|
|
var fullCode = GetFullCode(barcode);
|
|
barcode.FullBarCode = fullCode;
|
|
list.Add(barcode);
|
|
}
|
|
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = list;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_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.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BARCODE_CONTROLLER), "CreateBarcodeList", 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_BARCODE_CONTROLLER), "CreateBarcodeList", 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_BARCODE_CONTROLLER), "CreateBarcodeList", 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_BARCODE_CONTROLLER), "CreateBarcodeList", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static string GetFullCode_Small(TS_BARCODE_SMALL barcode)
|
|
{
|
|
var fullcode = string.Empty;
|
|
switch (ScpCache.Config.二维码格式)
|
|
{
|
|
case "1":
|
|
fullcode =
|
|
GetFullCode(barcode.BarCode, barcode.Qty, barcode.VendId, barcode.VendBatch, barcode.PoBillNum,
|
|
barcode.PoBillLine, barcode.ProduceDate, barcode.BillNum);
|
|
break;
|
|
}
|
|
return fullcode;
|
|
}
|
|
|
|
public static string GetFullCode_Pallets(TB_PALLETS barcode)
|
|
{
|
|
var fullcode = string.Empty;
|
|
switch (ScpCache.Config.二维码格式)
|
|
{
|
|
case "1":
|
|
fullcode =
|
|
GetFullCode(barcode.PalletNum, barcode.Qty, barcode.VendId, barcode.VendBatch, barcode.PoBillNum,
|
|
barcode.PoBillLine, barcode.ProduceDate, barcode.AsnBillNum);
|
|
break;
|
|
}
|
|
return fullcode;
|
|
}
|
|
public static string GetFullCode(TS_BARCODE barcode)
|
|
{
|
|
var fullcode = string.Empty;
|
|
switch (ScpCache.Config.二维码格式)
|
|
{
|
|
case "1":
|
|
fullcode =
|
|
GetFullCode(barcode.BarCode, barcode.Qty, barcode.VendId, barcode.VendBatch, barcode.PoBillNum,
|
|
barcode.PoBillLine, barcode.ProduceDate,barcode.BillNum);
|
|
break;
|
|
//case "2":
|
|
// var barcodeS = new TS_BARCODE_S
|
|
// {
|
|
// B = barcode.BarCode,
|
|
// P = barcode.PartCode,
|
|
// T = barcode.Batch,
|
|
// D = barcode.ProduceDate.Date,
|
|
// Q = barcode.Qty,
|
|
// N = barcode.BillNum,
|
|
// L = barcode.PoBillLine,
|
|
// V = barcode.VendId,
|
|
// C = barcode.Batch,
|
|
// //E = barcode.EqptCode,
|
|
// K = barcode.PackQty,
|
|
// };
|
|
// fullcode = JsonHelper.GetJson(barcodeS);
|
|
// break;
|
|
}
|
|
return fullcode;
|
|
}
|
|
public static string GetFullCode(string code, decimal qty, string vendId, string vendBatch, string billnum, int linnum,
|
|
DateTime productDate,string asnbillnum)
|
|
{
|
|
string sp = ";";
|
|
string fullCode = string.Empty;
|
|
fullCode += code + sp;
|
|
fullCode += qty + sp;
|
|
fullCode += vendId + sp;
|
|
fullCode += vendBatch + sp;
|
|
fullCode += billnum + "." + linnum + sp;
|
|
fullCode += productDate.ToString("yyyy/MM/dd") + sp;
|
|
fullCode += asnbillnum + sp;
|
|
|
|
return fullCode;
|
|
}
|
|
|
|
|
|
public static TS_BARCODE CreateBarcode(V_TB_ASN_DETAIL p_entity)
|
|
{
|
|
var ret = CreateBarcodeList(p_entity);
|
|
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
return ret.Result[0];
|
|
}
|
|
return null;
|
|
|
|
}
|
|
public static TS_BARCODE_SMALL CreateSmallBarcode(V_TB_ASN_DETAIL p_entity)
|
|
{
|
|
var ret = CreateSmallBarcodeList(p_entity);
|
|
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
return ret.Result[0];
|
|
}
|
|
return null;
|
|
|
|
}
|
|
private static ResultObject<TS_BARCODE_RULE_SMALL> GetSmallBarcodeRule(string partcode, string batch, int cnt = 1)
|
|
{
|
|
ResultObject<TS_BARCODE_RULE_SMALL> _ret = new ResultObject<TS_BARCODE_RULE_SMALL>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var ruleBatch = batch.Substring(0, 4);
|
|
var barcodeRule = db.TS_BARCODE_RULE_SMALL.Find(partcode, ruleBatch);
|
|
if (barcodeRule == null)
|
|
{
|
|
barcodeRule = new TS_BARCODE_RULE_SMALL
|
|
{
|
|
PartCode = partcode,
|
|
RuleBatch = ruleBatch,
|
|
LastNumber = cnt,
|
|
State = 0
|
|
};
|
|
}
|
|
else
|
|
{
|
|
barcodeRule.LastNumber += cnt;
|
|
}
|
|
barcodeRule.LastBarCode = GetLastSmallBarCode(partcode, batch, barcodeRule.LastNumber);
|
|
barcodeRule.LastTime = ScpCache.GetServerTime();
|
|
db.TS_BARCODE_RULE_SMALL.AddOrUpdate(p => new { p.PartCode, p.RuleBatch }, barcodeRule);
|
|
if (db.SaveChanges() != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = barcodeRule;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
}
|
|
}
|
|
}
|
|
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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static ResultObject<TS_BARCODE> updatebarder(List<String> barder)
|
|
{
|
|
ResultObject<TS_BARCODE> _ret = new ResultObject<TS_BARCODE>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
foreach (var yy in barder)
|
|
{
|
|
var _barder = db.TS_BARCODE.SingleOrDefault(t => t.UID.ToString() == yy);
|
|
var _second1 = db.TS_BARCODE.Where(p => p.PartCode == _barder.PartCode).Select(r => r.SerialNum).Max();
|
|
var _bard = db.TS_BARCODE.SingleOrDefault(t => t.SerialNum.ToString() == _second1.ToString()&&t.PartCode==_barder.PartCode);
|
|
string str = _barder.BarCode;
|
|
//str.Split('.');
|
|
|
|
//string str1 = str.Substring(str.Length - 6);
|
|
string str1 = _bard.SerialNum;
|
|
string str3 = str.Substring(0, str.Length - 6);
|
|
int i = Int32.Parse(str1);
|
|
i = i + 1;
|
|
string ss = i.ToString().PadLeft(6, '0');
|
|
string str4=str3+ss;
|
|
var _barder1 = db.TS_BARCODE.Count(t => t.BarCode.ToString() == str4);
|
|
_barder.BarCode = str4;
|
|
_barder.SerialNum = ss;
|
|
db.TS_BARCODE.AddOrUpdate(_barder);
|
|
|
|
|
|
if (db.SaveChanges() != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static string Save_TS_Asn(string ls)
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var TT= db.TS_BARCODE.Where(p => p.UID.ToString() == ls).FirstOrDefault();
|
|
var SS=db.TA_PART.Where(p => p.PartCode == TT.PartCode).FirstOrDefault();
|
|
string part = SS.PartGroup;
|
|
return part;
|
|
}
|
|
}
|
|
private static ResultObject<TS_BARCODE_RULE> GetBarcodeRule(string partcode, string batch, int cnt = 1)
|
|
{
|
|
ResultObject<TS_BARCODE_RULE> _ret = new ResultObject<TS_BARCODE_RULE>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
var ruleBatch = batch.Substring(0, 4);
|
|
var barcodeRule = db.TS_BARCODE_RULE.Find(partcode, ruleBatch);
|
|
if (barcodeRule == null)
|
|
{
|
|
barcodeRule = new TS_BARCODE_RULE
|
|
{
|
|
PartCode = partcode,
|
|
RuleBatch = ruleBatch,
|
|
LastNumber = cnt,
|
|
State = 0
|
|
};
|
|
}
|
|
else
|
|
{
|
|
barcodeRule.LastNumber += cnt;
|
|
}
|
|
|
|
barcodeRule.LastBarCode = GetLastBarCode(partcode, batch, barcodeRule.LastNumber);
|
|
barcodeRule.LastTime = ScpCache.GetServerTime();
|
|
|
|
db.TS_BARCODE_RULE.AddOrUpdate(p => new { p.PartCode, p.RuleBatch }, barcodeRule);
|
|
if (db.SaveChanges() != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = barcodeRule;
|
|
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
}
|
|
}
|
|
}
|
|
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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", 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_BARCODE_CONTROLLER), "GetBarcodeRule", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
private static ResultObject<TB_PALLETS_RULL> GetPalletsRule(string partcode, string batch, int cnt = 1)
|
|
{
|
|
ResultObject<TB_PALLETS_RULL> _ret = new ResultObject<TB_PALLETS_RULL>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
var ruleBatch = batch.Substring(0, 4);
|
|
var barcodeRule = db.TB_PALLETS_RULL.Find(partcode, ruleBatch);
|
|
if (barcodeRule == null)
|
|
{
|
|
barcodeRule = new TB_PALLETS_RULL
|
|
{
|
|
PartCode = partcode,
|
|
RuleBatch = ruleBatch,
|
|
LastNumber = cnt,
|
|
State = 0
|
|
};
|
|
}
|
|
else
|
|
{
|
|
barcodeRule.LastNumber += cnt;
|
|
}
|
|
|
|
barcodeRule.LastBarCode = GetLastPalletsBarCode(partcode, batch, barcodeRule.LastNumber);
|
|
barcodeRule.LastTime = ScpCache.GetServerTime();
|
|
|
|
db.TB_PALLETS_RULL.AddOrUpdate(p => new { p.PartCode, p.RuleBatch }, barcodeRule);
|
|
if (db.SaveChanges() != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = barcodeRule;
|
|
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
}
|
|
}
|
|
}
|
|
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_BARCODE_CONTROLLER), "GetPalletsRule", 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_BARCODE_CONTROLLER), "GetPalletsRule", 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_BARCODE_CONTROLLER), "GetPalletsRule", 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_BARCODE_CONTROLLER), "GetPalletsRule", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
private static string GetLastBarCode(string partcode, string batch, int lastnum)
|
|
{
|
|
|
|
var barcode = string.Empty;
|
|
barcode += partcode + ScpCache.Config.条码分隔符;
|
|
|
|
if (ScpCache.Config.条码包含供应商简称)
|
|
{
|
|
barcode += batch + ScpCache.Config.条码分隔符;
|
|
}
|
|
else
|
|
{
|
|
barcode += batch + ScpCache.Config.条码分隔符;
|
|
}
|
|
barcode += lastnum.ToString(ScpCache.Config.条码序列号格式);
|
|
return barcode;
|
|
}
|
|
private static string GetLastPalletsBarCode(string partcode, string batch, int lastnum)
|
|
{
|
|
|
|
var barcode = string.Empty;
|
|
barcode += partcode + ScpCache.Config.条码分隔符;
|
|
|
|
if (ScpCache.Config.条码包含供应商简称)
|
|
{
|
|
barcode += batch + ScpCache.Config.条码分隔符;
|
|
}
|
|
else
|
|
{
|
|
barcode += batch + ScpCache.Config.条码分隔符;
|
|
}
|
|
barcode += lastnum.ToString(ScpCache.Config.托码序列号格式);
|
|
return barcode;
|
|
}
|
|
private static string GetLastSmallBarCode(string partcode, string batch, int lastnum)
|
|
{
|
|
|
|
var barcode = string.Empty;
|
|
barcode += partcode + ScpCache.Config.条码分隔符;
|
|
if (ScpCache.Config.条码包含供应商简称)
|
|
{
|
|
barcode += batch + ScpCache.Config.条码分隔符;
|
|
}
|
|
else
|
|
{
|
|
barcode += batch + ScpCache.Config.条码分隔符;
|
|
}
|
|
barcode += lastnum.ToString(ScpCache.Config.小包装条码序列号格式);
|
|
return barcode;
|
|
}
|
|
}
|
|
|
|
public class TS_BARCODE_S
|
|
{
|
|
public string B { get; set; }//barcode
|
|
|
|
public string P { get; set; }//partcode
|
|
|
|
public string T { get; set; }//batch
|
|
|
|
public DateTime D { get; set; }//producedate
|
|
|
|
public decimal Q { get; set; }//qty
|
|
|
|
public string N { get; set; }//billnum
|
|
|
|
public int L { get; set; }//billline
|
|
|
|
public string V { get; set; }//VendId
|
|
|
|
public string C { get; set; }//vendbatch
|
|
|
|
public string E { get; set; }//eqptcode
|
|
|
|
public decimal K { get; set; }//packqty
|
|
|
|
}
|
|
}
|