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.
330 lines
14 KiB
330 lines
14 KiB
using System;
|
|
using System.Linq;
|
|
using CK.SCP.Models.Enums;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Utils;
|
|
using CK.SCP.Models;
|
|
using System.Data;
|
|
using System.Data.Entity.Core;
|
|
using System.Text;
|
|
using CK.SCP.Models.ScpEntity.ExcelExportEnttity;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity.Migrations;
|
|
|
|
namespace CK.SCP.Controller
|
|
{
|
|
public class SCP_ToleranceProportion_Controller
|
|
{
|
|
/// <summary>
|
|
/// 获取容差控制列表
|
|
/// </summary>
|
|
/// <param name="p_entity"></param>
|
|
/// <param name="p_action"></param>
|
|
public static void Get_TA_ToleranceProportion_List(TA_ToleranceProportion p_entity, Action<ResultObject<IQueryable<V_TA_ToleranceProportion>>> p_action)
|
|
{
|
|
ResultObject<IQueryable<V_TA_ToleranceProportion>> _ret = new ResultObject<IQueryable<V_TA_ToleranceProportion>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<V_TA_ToleranceProportion> q = db.V_TA_ToleranceProportion;
|
|
if (!string.IsNullOrEmpty(p_entity.PartCode))
|
|
{
|
|
q = q.Where(p => p.PartCode == p_entity.PartCode);
|
|
}
|
|
_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_ToleranceProportion_Controller), "Get_TA_ToleranceProportion_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_ToleranceProportion_Controller), "Get_TA_ToleranceProportion_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_ToleranceProportion_Controller), "Get_TA_ToleranceProportion_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_ToleranceProportion_Controller), "Get_TA_ToleranceProportion_List", e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 模具分摊导入
|
|
/// </summary>
|
|
/// <param name="p_order_list"></param>
|
|
/// <param name="site"></param>
|
|
/// <param name="p_creator"></param>
|
|
/// <returns></returns>
|
|
public static ResultObject<bool> EXCEL_MOLDSHARING_MOD(List<SCP_PART_ToleranceProportion> p_order_list, string site, string p_creator)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
List<TA_ToleranceProportion> list = new List<TA_ToleranceProportion>();
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = true;
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
var _lst = p_order_list;
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _ls = CheckExcelMode_MoldSharing(db, p, site);
|
|
if (_ls.Count > 0)
|
|
{
|
|
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
|
|
}
|
|
});
|
|
if (ErrorList.Count > 0)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.MessageList.AddRange(ErrorList);
|
|
_ret.Result = false;
|
|
}
|
|
else
|
|
{
|
|
_lst.ForEach(p =>
|
|
{
|
|
var mold = db.TA_ToleranceProportion.FirstOrDefault(t => t.PartCode.ToUpper() == p.零件号.ToUpper() && t.Site == p.工厂编码.Trim());
|
|
if (mold == null)
|
|
{
|
|
mold = new TA_ToleranceProportion
|
|
{
|
|
PartCode = p.零件号.ToUpper(),
|
|
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
CreateUser = p_creator,
|
|
Site = p.工厂编码.Trim(),
|
|
ToleranceProportion = decimal.Parse(p.容差),
|
|
};
|
|
}
|
|
else
|
|
{
|
|
mold.ToleranceProportion = decimal.Parse(p.容差);
|
|
mold.UpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
mold.UpdateUser = p_creator;
|
|
}
|
|
list.Add(mold);
|
|
});
|
|
|
|
if (_ret.MessageList.Count == 0)
|
|
{
|
|
|
|
db.TA_ToleranceProportion.AddOrUpdate(q => q.UID, list.ToArray());
|
|
int state = db.SaveChanges();
|
|
if (state != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = true;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList())
|
|
{
|
|
|
|
error.ValidationErrors.ToList().ForEach(i =>
|
|
{
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
|
|
});
|
|
}
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ToleranceProportion_Controller), "EXCEL_MOLDSHARING_MOD", 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_ToleranceProportion_Controller), "EXCEL_MOLDSHARING_MOD", 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_ToleranceProportion_Controller), "EXCEL_MOLDSHARING_MOD", 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_ToleranceProportion_Controller), "EXCEL_MOLDSHARING_MOD", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
_ret.MessageList.Add("保存失败" + e.Message);
|
|
}
|
|
return _ret;
|
|
}
|
|
/// <summary>
|
|
/// 数据检验
|
|
/// </summary>
|
|
/// <param name="db"></param>
|
|
/// <param name="p_excel"></param>
|
|
/// <param name="site"></param>
|
|
/// <returns></returns>
|
|
public static List<string> CheckExcelMode_MoldSharing(ScpEntities db, SCP_PART_ToleranceProportion p_excel, string site)
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
|
|
if (string.IsNullOrEmpty(p_excel.零件号) || string.IsNullOrEmpty(p_excel.工厂编码) || string.IsNullOrEmpty(p_excel.容差))
|
|
{
|
|
ErrorList.Add(string.Format("零件编号【{0}】有填写为空!", p_excel.零件号));
|
|
}
|
|
else
|
|
{
|
|
int count = db.TA_PART.Count(p => p.PartCode == p_excel.零件号 && p.Site == site);
|
|
if (count <= 0)
|
|
{
|
|
ErrorList.Add(string.Format("零件编号{0}不存在!", p_excel.零件号));
|
|
}
|
|
decimal ty = 0.00m;
|
|
if (!decimal.TryParse(p_excel.容差, out ty))
|
|
{
|
|
ErrorList.Add(string.Format("零件编号{0},容差填写不正确,不是数字类型!", p_excel.零件号));
|
|
}
|
|
else
|
|
{
|
|
if (ty > 1 || ty < 0)
|
|
{
|
|
ErrorList.Add(string.Format("零件编号{0},容差填写不正确,只能填写0到1之间小数!", p_excel.零件号));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return ErrorList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查是否超出容差数据
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <param name="QtyAll"></param>
|
|
/// <returns></returns>
|
|
public static List<string> CheckToleranceProportion(V_TB_ASK_DETAIL entity, decimal QtyAll)
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
var canQty = entity.AskQty - entity.ShippedQty - entity.ReduceQty;
|
|
// WS 和 WG 类型物料 填写的 发货数 不能大于 (要货数量-已发数量)
|
|
if (entity.DockCode == "WS" || entity.DockCode == "WG")
|
|
{
|
|
if (canQty > 0)
|
|
{
|
|
if (QtyAll > canQty)
|
|
{
|
|
ErrorList.Add(entity.PartCode + "发货数量>可发数量");
|
|
}
|
|
}
|
|
}
|
|
// YC 和 WT 填写的 发货数 能大于 (要货数 - 已发数量) 但是 不能 大于容差范围 并且 要货数 - 已发数量 不能小于等于0
|
|
else if (entity.DockCode == "YC" || entity.DockCode == "WT")
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var toleranceProportion = db.TA_ToleranceProportion.FirstOrDefault(q => q.PartCode == entity.PartCode);
|
|
if (toleranceProportion == null)
|
|
{
|
|
ErrorList.Add(entity.PartCode + "没有容差控制,请联系管理员进行填写");
|
|
}
|
|
else
|
|
{
|
|
decimal maxqty = entity.AskQty * (1 + toleranceProportion.ToleranceProportion);
|
|
if (canQty <= 0)
|
|
{
|
|
ErrorList.Add(entity.PartCode + "只能超发一次哦");
|
|
}
|
|
// 最大要货数量(要货数* 1+容差) - 累计发货数量 <当前填写的 要货数量
|
|
else if ((maxqty - entity.ShippedQty - entity.ReduceQty )< QtyAll)
|
|
{
|
|
ErrorList.Add(entity.PartCode + "容差控制为"+ (toleranceProportion.ToleranceProportion * 100)+"% ,本次填写发货数量超出"+ Math.Abs((maxqty - entity.ShippedQty - QtyAll).Value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if ((canQty <= 0) && (QtyAll > 0))
|
|
{
|
|
ErrorList.Add(entity.PartCode + "只能超发一次哦");
|
|
}
|
|
|
|
|
|
return ErrorList;
|
|
}
|
|
|
|
}
|
|
}
|
|
|