using IWareDataAccess.EF;
|
using IWareDataAccess.Entity.Base;
|
using IWareDataAccess.Entity.Summary;
|
using IWareDataAccess.Helper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IWareDataAccess.Base.PLACEVSCONTAINER
|
{
|
public static class PlaceVsContainerSqlFunc
|
{
|
/// <summary>
|
/// 搜索表
|
/// </summary>
|
/// <param name="keyValue"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public static List<BASE_PLACE_VS_CONTAINER> Search(PlaceVsContainerWebEntity webEntity, int page, int onePageNum, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
var f = PredicateBuilder.True<BASE_PLACE_VS_CONTAINER>();
|
//便利所有属性
|
Type type = webEntity.GetType();
|
foreach (var i in type.GetProperties())
|
{
|
object v = Helper.Helper.GetFieldValueByName(webEntity, i.Name);
|
if (i.PropertyType == typeof(String))
|
{
|
string value;
|
if (v != null)
|
{
|
value = v.ToString();
|
f = f.And(x => Helper.Helper.GetFieldValueByName(x, i.Name) != null ? Helper.Helper.GetFieldValueByName(x, i.Name).ToString().Contains(value) : false);
|
}
|
}
|
else if (i.PropertyType == typeof(DateTime?))
|
{
|
if (v != null)
|
{
|
DateTime value = DateTime.Parse(v.ToString());
|
if (i.Name == "updateTimeStart")
|
{
|
f = f.And(x => x.UPDATETIME > value);
|
}
|
if (i.Name == "updateTimeEnd")
|
{
|
f = f.And(x => x.UPDATETIME < value);
|
}
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
}
|
}
|
}
|
List<BASE_PLACE_VS_CONTAINER> list = edm.BASE_PLACE_VS_CONTAINER.Where(f.Compile()).Skip((page - 1) * onePageNum).Take(onePageNum).ToList();
|
|
return list;
|
}
|
}
|
|
/// <summary>
|
/// 搜索视图
|
/// </summary>
|
/// <param name="keyValue"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public static List<View_BASE_PLACE_VS_CONTAINER> SearchView(PlaceVsContainerWebEntity webEntity, int page, int onePageNum, out int totalnum, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
if (!string.IsNullOrEmpty(webEntity.isEmptyContainer))
|
{
|
webEntity.enable2 = null;
|
}
|
Dictionary<string, object> parm = new Dictionary<string, object>();
|
var f = PredicateBuilder.True<View_BASE_PLACE_VS_CONTAINER>();
|
//便利所有属性
|
Type type = webEntity.GetType();
|
foreach (var i in type.GetProperties())
|
{
|
object v = Helper.Helper.GetFieldValueByName(webEntity, i.Name);
|
if (i.PropertyType == typeof(String))
|
{
|
string value;
|
if (v != null)
|
{
|
value = v.ToString();
|
f = f.And(x => Helper.Helper.GetFieldValueByName(x, i.Name) != null ? Helper.Helper.GetFieldValueByName(x, i.Name).ToString().Contains(value) : false);
|
parm.Add(i.Name, value);
|
}
|
}
|
else if (i.PropertyType == typeof(DateTime?))
|
{
|
if (v != null)
|
{
|
DateTime value = DateTime.Parse(v.ToString());
|
if (i.Name == "updateTimeStart")
|
{
|
f = f.And(x => x.updateTime > value);
|
parm.Add("updateTime", value);
|
}
|
if (i.Name == "updateTimeEnd")
|
{
|
f = f.And(x => x.updateTime < value);
|
parm.Add("updateTime", value);
|
}
|
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
parm.Add(i.Name, v);
|
}
|
}
|
}
|
List<View_BASE_PLACE_VS_CONTAINER> list = new List<View_BASE_PLACE_VS_CONTAINER>();
|
View_BASE_PLACE_VS_CONTAINER pvi = new View_BASE_PLACE_VS_CONTAINER();
|
var data = SearchHelper.GetSearchData(edm, page, onePageNum, out totalnum, parm, pvi);
|
list = data;
|
return list;
|
}
|
}
|
|
|
/// <summary>
|
/// 搜索视图数量
|
/// </summary>
|
/// <param name="keyValue"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public static int SearchViewNum(PlaceVsContainerWebEntity webEntity, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
var f = PredicateBuilder.True<View_BASE_PLACE_VS_CONTAINER>();
|
//便利所有属性
|
Type type = webEntity.GetType();
|
foreach (var i in type.GetProperties())
|
{
|
object v = Helper.Helper.GetFieldValueByName(webEntity, i.Name);
|
if (i.PropertyType == typeof(String))
|
{
|
string value;
|
if (v != null)
|
{
|
value = v.ToString();
|
f = f.And(x => Helper.Helper.GetFieldValueByName(x, i.Name) != null ? Helper.Helper.GetFieldValueByName(x, i.Name).ToString().Contains(value) : false);
|
}
|
}
|
else if (i.PropertyType == typeof(DateTime?))
|
{
|
if (v != null)
|
{
|
DateTime value = DateTime.Parse(v.ToString());
|
if (i.Name == "updateTimeStart")
|
{
|
f = f.And(x => x.updateTime > value);
|
}
|
if (i.Name == "updateTimeEnd")
|
{
|
f = f.And(x => x.updateTime < value);
|
}
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
}
|
}
|
}
|
|
int num = 0;
|
//补丁
|
if (string.IsNullOrEmpty(webEntity.itemName))
|
{
|
num = edm.View_BASE_PLACE_VS_CONTAINER.Where(f.Compile()).Count();
|
}
|
else
|
{
|
num = edm.View_BASE_PLACE_VS_CONTAINER.Where(x => x.itemName.Contains(webEntity.itemName)).Where(f.Compile()).Count();
|
}
|
|
return num;
|
}
|
}
|
|
/// <summary>
|
/// 搜索总库存数量
|
/// </summary>
|
/// <param name="keyValue"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public static int SearchItemAllNum(PlaceVsContainerWebEntity webEntity, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
var f = PredicateBuilder.True<View_BASE_PLACE_VS_CONTAINER>();
|
//便利所有属性
|
Type type = webEntity.GetType();
|
foreach (var i in type.GetProperties())
|
{
|
object v = Helper.Helper.GetFieldValueByName(webEntity, i.Name);
|
if (i.PropertyType == typeof(String))
|
{
|
string value;
|
if (v != null)
|
{
|
value = v.ToString();
|
f = f.And(x => Helper.Helper.GetFieldValueByName(x, i.Name) != null ? Helper.Helper.GetFieldValueByName(x, i.Name).ToString().Contains(value) : false);
|
}
|
}
|
else if (i.PropertyType == typeof(DateTime?))
|
{
|
if (v != null)
|
{
|
DateTime value = DateTime.Parse(v.ToString());
|
if (i.Name == "updateTimeStart")
|
{
|
f = f.And(x => x.updateTime > value);
|
}
|
if (i.Name == "updateTimeEnd")
|
{
|
f = f.And(x => x.updateTime < value);
|
}
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
}
|
}
|
}
|
int num = edm.View_BASE_PLACE_VS_CONTAINER.Where(x => x.itemName.Contains(webEntity.itemName)).Where(f.Compile()).Sum(x => x.itemNum) ?? 0;
|
|
return num;
|
}
|
}
|
|
/// <summary>
|
/// 搜索有效库存数量
|
/// </summary>
|
/// <param name="keyValue"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public static int SearchItemCanUseNum(PlaceVsContainerWebEntity webEntity, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
|
//int numCanUse = edm.BASE_CONTAINER_VS_ITEM.Where(x => (x.OUTPLANID ?? 0) == 0 && x.BASE_ITEM.ITEMNAME==webEntity.itemName && x.ENABLE==1).Sum(x => x.ITEMNUM) ?? 0;
|
int numCanUse = edm.BASE_CONTAINER_VS_ITEM.Where(x => x.BASE_ITEM.ITEMNAME == webEntity.itemName && x.ENABLE == 1).Sum(x => x.ITEMNUM) ?? 0;
|
List<ORDER_OUTORDER> orderList = edm.ORDER_OUTORDER.Where(x => x.BASE_ITEM.ITEMNAME == webEntity.itemName && x.ORDERSTATUS == "执行中" && x.ENABLE == 1).ToList();
|
foreach (var i in orderList)
|
{
|
numCanUse = numCanUse - ((i.TOTALOUTNUM ?? 0) - (i.CHECKOUTNUM ?? 0));
|
}
|
return numCanUse;
|
}
|
}
|
|
/// <summary>
|
/// 添加修改
|
/// </summary>
|
/// <param name="role"></param>
|
/// <returns></returns>
|
public static bool Add(PlaceVsContainerWebEntity webEntity, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
|
BASE_PLACE_VS_CONTAINER pvc = new BASE_PLACE_VS_CONTAINER();
|
pvc = edm.BASE_PLACE_VS_CONTAINER.FirstOrDefault(x => x.PVCCODE == webEntity.pvcCode);
|
if (pvc != null)
|
{
|
//msg = "此库存编号已存在";
|
//return false;
|
}
|
else
|
{
|
pvc = new BASE_PLACE_VS_CONTAINER();
|
pvc.STATUS = "IN";
|
pvc.BASE_PLACE.ISFULL = 1;
|
}
|
BASE_CONTAINER container = edm.BASE_CONTAINER.FirstOrDefault(x => x.CONTAINERNAME == webEntity.containerName);
|
if (container == null)
|
{
|
msg = "无此托盘";
|
return false;
|
}
|
pvc.BASE_CONTAINER = container;
|
BASE_PLACE place = edm.BASE_PLACE.FirstOrDefault(x => x.PLACE == webEntity.place);
|
if (place == null)
|
{
|
msg = "无此库位";
|
return false;
|
}
|
if (place.ISFULL == 1)
|
{
|
msg = "此库位已有东西";
|
return false;
|
}
|
pvc.BASE_PLACE = place;
|
pvc.UPDATETIME = DateTime.Now;
|
|
pvc.ENABLE = webEntity.enable ?? pvc.ENABLE;
|
pvc.PVCCODE = webEntity.pvcCode ?? pvc.PVCCODE;
|
|
edm.BASE_PLACE_VS_CONTAINER.AddOrUpdateExtension(pvc);
|
if (edm.SaveChanges() > 0)
|
{
|
return true;
|
}
|
else
|
{
|
msg = "保存失败";
|
return false;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="webDevice"></param>
|
/// <returns></returns>
|
public static bool Delete(PlaceVsContainerWebEntity webEntity, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
|
BASE_PLACE_VS_CONTAINER pvc = edm.BASE_PLACE_VS_CONTAINER.FirstOrDefault(x => x.BASE_PLACE.PLACE == webEntity.place);
|
if (pvc == null)
|
{
|
msg = "无此库存";
|
return false;
|
}
|
else
|
{
|
///更改库位状态
|
var place = edm.BASE_PLACE.FirstOrDefault(x => x.ID == pvc.PLACEID);
|
if (place != null)
|
{
|
place.ISFULL = 0;
|
}
|
///删除托盘物料关系
|
var cvilst = edm.BASE_CONTAINER_VS_ITEM.Where(x => x.CONTAINERID == pvc.CONTAINERID).ToList();
|
if (cvilst != null && cvilst.Count > 0)
|
{
|
edm.BASE_CONTAINER_VS_ITEM.RemoveRange(cvilst);
|
}
|
///删除托盘库位关系
|
edm.BASE_PLACE_VS_CONTAINER.Remove(pvc);
|
|
if (edm.SaveChanges() > 0)
|
{
|
//记录删除托盘和物料绑定关系日志 【Editby shaoc,2023-03-07】
|
IWareDataAccess.Helper.Helper.LogRemoveBASE_CONTAINER_VS_ITEM(cvilst, "PlaceVsContainerSqlFunc.Delete", "删除");
|
WZ.Useful.Commons.LogTextHelper.WriteLine("PlaceVsContainerSqlFunc", "Delete", "成功删除" + pvc.BASE_PLACE.PLACE + ",器具" + pvc.BASE_CONTAINER.CONTAINERNAME);
|
return true;
|
}
|
else
|
{
|
msg = "保存失败";
|
return false;
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 获取组盘号
|
/// </summary>
|
/// <returns></returns>
|
public static string GetCode()
|
{
|
using (Model edm = new Model())
|
{
|
string month = DateTime.Now.Month.ToString("00");
|
string day = DateTime.Now.Day.ToString("00");
|
string hour = DateTime.Now.Hour.ToString("00");
|
string minute = DateTime.Now.Minute.ToString("00");
|
string second = DateTime.Now.Second.ToString("00");
|
string millSecond = DateTime.Now.Millisecond.ToString("0000");
|
string time = DateTime.Now.Year.ToString() + month + day + hour + minute + second + millSecond;
|
|
return "PC" + time;
|
}
|
}
|
|
public static List<HomeNumDataEntity> SearchEmptyContainerPlace(PlaceVsContainerWebEntity model, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
var item = edm.BASE_ITEM.FirstOrDefault(x => x.ITEMNAME == model.itemName);
|
int allcout = 0;
|
int cout = 0;
|
if (item != null && !string.IsNullOrEmpty(item.USECONTAINERTYPE))
|
{
|
List<string> typeList = item.USECONTAINERTYPE.Split(',').ToList();
|
foreach (var i in typeList)
|
{
|
var place = edm.BASE_PLACE_VS_CONTAINER.Where(x => x.BASE_CONTAINER.BASE_CONTAINER_VS_ITEM.Count == 0 && i.Contains(x.BASE_CONTAINER.CONTAINERTYPE)).ToList();
|
allcout = (place == null ? 0 : place.Select(x => x.CONTAINERID).ToList().Distinct().ToList().Count) + allcout;
|
cout = (place == null ? 0 : place.Where(x => x.STATUS == "IN").Select(x => x.CONTAINERID).ToList().Distinct().ToList().Count) + cout;
|
}
|
}
|
List<HomeNumDataEntity> hndlst = new List<HomeNumDataEntity>();
|
hndlst.Add(new HomeNumDataEntity() { no = 1, titel = "总空器具数", value = allcout });
|
hndlst.Add(new HomeNumDataEntity() { no = 2, titel = "有效空器具数", value = cout });
|
return hndlst;
|
}
|
}
|
}
|
}
|