using IWareDataAccess.EF;
|
using IWareDataAccess.Entity.Task;
|
using IWareDataAccess.Helper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IWareDataAccess.Task.TASK
|
{
|
public class SrmRecordSqlFunc
|
{ /// <summary>
|
/// 搜索表
|
/// </summary>
|
/// <param name="keyValue"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public static List<TASK_SRMRECORD> Search(SrmRecordWebEntity webEntity, int page, int onePageNum, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
var f = PredicateBuilder.True<TASK_SRMRECORD>();
|
//便利所有属性
|
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 == "createTimeStart")
|
{
|
f = f.And(x => x.createTime > value);
|
}
|
if (i.Name == "createTimeEnd")
|
{
|
f = f.And(x => x.createTime < value);
|
}
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
}
|
}
|
}
|
List<TASK_SRMRECORD> list = edm.TASK_SRMRECORD.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_TASK_SRMRECORD> SearchView(SrmRecordWebEntity webEntity, int page, int onePageNum, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
var f = PredicateBuilder.True<View_TASK_SRMRECORD>();
|
//便利所有属性
|
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();
|
//特殊处理
|
if (i.Name == "taskType")
|
{
|
if (value == "移库")
|
{
|
f = f.And(x => (x.useSrmId == 1 && x.toPlace != "02-01-01" && x.sourcePlace != "01-01-01" && x.toPlace != "01-19-01" && x.sourcePlace != "02-19-01") || x.useSrmId != 1);
|
f = f.And(x => (x.useSrmId == 2 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-20-01" && x.sourcePlace != "03-20-01") || x.useSrmId != 2);
|
f = f.And(x => (x.useSrmId == 3 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-19-01" && x.sourcePlace != "03-19-01") || x.useSrmId != 3);
|
f = f.And(x => (x.useSrmId == 4 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-21-01" && x.sourcePlace != "03-21-01") || x.useSrmId != 4);
|
f = f.And(x => (x.useSrmId == 5 && x.toPlace != "02-01-01" && x.sourcePlace != "01-01-01" && x.toPlace != "01-20-01" && x.sourcePlace != "02-20-01") || x.useSrmId != 5);
|
f = f.And(x => (x.useSrmId == 6 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-20-01" && x.sourcePlace != "03-20-01") || x.useSrmId != 6);
|
f = f.And(x => (x.useSrmId == 7 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-24-01" && x.sourcePlace != "03-24-01") || x.useSrmId != 7);
|
f = f.And(x => (x.useSrmId == 8 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-25-01" && x.sourcePlace != "03-25-01") || x.useSrmId != 8);
|
f = f.And(x => (x.useSrmId == 9 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-23-01" && x.sourcePlace != "03-23-01") || x.useSrmId != 9);
|
}
|
}
|
else
|
{
|
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 == "createTimeStart")
|
{
|
f = f.And(x => x.createTime > value);
|
}
|
if (i.Name == "createTimeEnd")
|
{
|
f = f.And(x => x.createTime < value);
|
}
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
}
|
}
|
}
|
|
List<View_TASK_SRMRECORD> list = edm.View_TASK_SRMRECORD.OrderByDescending(x => x.createTime).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_TASK_SRMRECORD> SearchViewAll(SrmRecordWebEntity webEntity, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
var f = PredicateBuilder.True<View_TASK_SRMRECORD>();
|
//便利所有属性
|
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();
|
//特殊处理
|
if (i.Name == "taskType")
|
{
|
if (value == "移库")
|
{
|
f = f.And(x => (x.useSrmId == 1 && x.toPlace != "02-01-01" && x.sourcePlace != "01-01-01" && x.toPlace != "01-19-01" && x.sourcePlace != "02-19-01") || x.useSrmId != 1);
|
f = f.And(x => (x.useSrmId == 2 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-20-01" && x.sourcePlace != "03-20-01") || x.useSrmId != 2);
|
f = f.And(x => (x.useSrmId == 3 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-19-01" && x.sourcePlace != "03-19-01") || x.useSrmId != 3);
|
f = f.And(x => (x.useSrmId == 4 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-21-01" && x.sourcePlace != "03-21-01") || x.useSrmId != 4);
|
f = f.And(x => (x.useSrmId == 5 && x.toPlace != "02-01-01" && x.sourcePlace != "01-01-01" && x.toPlace != "01-20-01" && x.sourcePlace != "02-20-01") || x.useSrmId != 5);
|
f = f.And(x => (x.useSrmId == 6 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-20-01" && x.sourcePlace != "03-20-01") || x.useSrmId != 6);
|
f = f.And(x => (x.useSrmId == 7 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-24-01" && x.sourcePlace != "03-24-01") || x.useSrmId != 7);
|
f = f.And(x => (x.useSrmId == 8 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-25-01" && x.sourcePlace != "03-25-01") || x.useSrmId != 8);
|
f = f.And(x => (x.useSrmId == 9 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-23-01" && x.sourcePlace != "03-23-01") || x.useSrmId != 9);
|
}
|
}
|
else
|
{
|
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 == "createTimeStart")
|
{
|
f = f.And(x => x.createTime > value);
|
}
|
if (i.Name == "createTimeEnd")
|
{
|
f = f.And(x => x.createTime < value);
|
}
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
}
|
}
|
}
|
|
List<View_TASK_SRMRECORD> list = edm.View_TASK_SRMRECORD.OrderByDescending(x => x.createTime).Where(f.Compile()).ToList();
|
|
return list;
|
}
|
}
|
|
/// <summary>
|
/// 搜索视图
|
/// </summary>
|
/// <param name="keyValue"></param>
|
/// <param name="page"></param>
|
/// <returns></returns>
|
public static int SearchViewNum(SrmRecordWebEntity webEntity)
|
{
|
using (Model edm = new Model())
|
{
|
var f = PredicateBuilder.True<View_TASK_SRMRECORD>();
|
//便利所有属性
|
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(); //特殊处理
|
if (i.Name == "taskType")
|
{
|
if (value == "移库")
|
{
|
f = f.And(x => (x.useSrmId == 1 && x.toPlace != "02-01-01" && x.sourcePlace != "01-01-01" && x.toPlace != "01-19-01" && x.sourcePlace != "02-19-01") || x.useSrmId != 1);
|
f = f.And(x => (x.useSrmId == 2 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-20-01" && x.sourcePlace != "03-20-01") || x.useSrmId != 2);
|
f = f.And(x => (x.useSrmId == 3 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-19-01" && x.sourcePlace != "03-19-01") || x.useSrmId != 3);
|
f = f.And(x => (x.useSrmId == 4 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-21-01" && x.sourcePlace != "03-21-01") || x.useSrmId != 4);
|
f = f.And(x => (x.useSrmId == 5 && x.toPlace != "02-01-01" && x.sourcePlace != "01-01-01" && x.toPlace != "01-20-01" && x.sourcePlace != "02-20-01") || x.useSrmId != 5);
|
f = f.And(x => (x.useSrmId == 6 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-20-01" && x.sourcePlace != "03-20-01") || x.useSrmId != 6);
|
f = f.And(x => (x.useSrmId == 7 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-24-01" && x.sourcePlace != "03-24-01") || x.useSrmId != 7);
|
f = f.And(x => (x.useSrmId == 8 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-25-01" && x.sourcePlace != "03-25-01") || x.useSrmId != 8);
|
f = f.And(x => (x.useSrmId == 9 && x.toPlace != "03-01-01" && x.sourcePlace != "02-01-01" && x.toPlace != "02-23-01" && x.sourcePlace != "03-23-01") || x.useSrmId != 9);
|
}
|
}
|
else
|
{
|
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 == "createTimeStart")
|
{
|
f = f.And(x => x.createTime > value);
|
}
|
if (i.Name == "createTimeEnd")
|
{
|
f = f.And(x => x.createTime < value);
|
}
|
}
|
}
|
else
|
{
|
if (v != null)
|
{
|
f = f.And(x => Object.Equals(Helper.Helper.GetFieldValueByName(x, i.Name), v));
|
}
|
}
|
}
|
|
int num = edm.View_TASK_SRMRECORD.Where(f.Compile()).Count();
|
|
return num;
|
}
|
}
|
|
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="webDevice"></param>
|
/// <returns></returns>
|
public static bool Delete(SrmRecordWebEntity webEntity, out string msg)
|
{
|
msg = "";
|
using (Model edm = new Model())
|
{
|
|
var task = edm.TASK_SRMRECORD.FirstOrDefault(x => x.id == webEntity.id);
|
if (task == null)
|
{
|
//无此角色
|
msg = "无此任务";
|
return false;
|
}
|
else
|
{
|
edm.TASK_SRMRECORD.Remove(task);
|
if (edm.SaveChanges() > 0)
|
{
|
return true;
|
}
|
else
|
{
|
msg = "保存失败";
|
return false;
|
}
|
}
|
}
|
}
|
}
|
}
|