using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
|
using iWareSql;
|
using iWareSql.Orm;
|
using iWareSql.DBModel;
|
|
namespace iWareSql.DataAccess
|
{
|
/// <summary>
|
/// 托盘和物料的绑定关系
|
/// </summary>
|
public class Salver_Material_Handler
|
{
|
|
/// <summary>
|
/// 根据 ContainerId 寻找 Base_Salver_V_Material 对象
|
/// </summary>
|
/// <param name="edm"></param>
|
/// <param name="placeId"></param>
|
/// <returns></returns>
|
public static Base_Salver_V_Material GetIVCByContainerId(DbModel edm, string ContainerId)
|
{
|
var items = edm.Base_Salver_V_Material.Where(x => x.SalverId == ContainerId);
|
if (items != null)
|
{
|
var readItems = items.ToList();
|
if (readItems == null)
|
{
|
return null;
|
}
|
else
|
{
|
if (readItems.Count > 1)
|
{
|
throw new Exception("同一个ContainerId:" + ContainerId + "关联了" + readItems.Count + "个 Base_Salver_V_Material 数据!");
|
}
|
else if (readItems.Count == 1)
|
{
|
return readItems[0];
|
}
|
else
|
{
|
return null;
|
}
|
}
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// 通过ItemId获取IVC数据
|
/// </summary>
|
/// <param name="edm"></param>
|
/// <param name="mat"></param>
|
public static Base_Salver_V_Material GetIVCByItemId(DbModel edm, string itemId)
|
{
|
Base_Salver_V_Material ivc = null;
|
var ivcs = edm.Base_Salver_V_Material.Where(x => x.MaterialId == itemId.ToString());
|
if (ivcs == null)
|
{
|
throw new Exception(string.Format("根据itemId:{0}没有找到ivc数据", itemId));
|
}
|
else
|
{
|
if (ivcs.Count() == 1)
|
{
|
ivc = ivcs.FirstOrDefault();
|
}
|
else
|
{
|
throw new Exception(string.Format("根据itemId:{0}找到{1}条ivc数据", itemId, ivcs.Count()));
|
}
|
}
|
return ivc;
|
}
|
|
/// <summary>
|
/// 创建一个托盘和物料的绑定关系
|
/// </summary>
|
/// <param name="ctn"></param>
|
/// <param name="item"></param>
|
/// <param name="remark">备注</param>
|
/// <returns></returns>
|
public static bool CreateCvIRelation(string userName, Base_Salver ctn, Base_Material item, string remark)
|
{
|
using (DbModel edm = new DbModel())
|
{
|
CreateCvIRelation(edm, userName, ctn, item, remark);
|
int i = edm.SaveChanges();
|
return i > 0 ? true : false;
|
};
|
}
|
|
/// <summary>
|
/// 创建一个托盘和物料的绑定关系
|
/// </summary>
|
/// <param name="ctn"></param>
|
/// <param name="item"></param>
|
/// <returns></returns>
|
public static void CreateCvIRelation(DbModel edm, string userName, Base_Salver salver, Base_Material item, string remark)
|
{
|
Base_Salver_V_Material cvI = new Base_Salver_V_Material()
|
{
|
Id = Guid.NewGuid().ToString(),
|
|
MaterialId = item.Id,
|
MaterialName = item.OrderNo,
|
|
|
SalverId = salver.Id,
|
SalverCode = salver.SalverCode,
|
OperationRemark = remark,
|
CreateTime = DateTime.Now,
|
CreateBy = userName,
|
ModifyBy = userName,
|
ModifyTime = DateTime.Now
|
};
|
edm.Base_Salver_V_Material.Add(cvI);
|
}
|
/// <summary>
|
/// 检验此上料单是否已经做过(有CVI关系的视为已经做过)
|
/// </summary>
|
/// <param name="itemId"></param>
|
/// <returns></returns>
|
public static bool IsAlsoDone(string itemId)
|
{
|
using (DbModel edm = new DbModel())
|
{
|
var cvi = edm.Base_Salver_V_Material.FirstOrDefault(x => x.MaterialId == itemId);
|
|
if (cvi != null)
|
return true;
|
else
|
return false;
|
}
|
}
|
|
}
|
}
|