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.
 
 
 
 
 

214 lines
8.2 KiB

using CK.SCP.Models;
using CK.SCP.Models.ExchangeCenterTables;
using CK.SCP.Utils;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CK.SCP.Controller
{
public class UN_EC_CONTROLLER_BOM
{
public static void Get_TES_BOM_List(TES_BOM p_entity, Action<ResultObject<IQueryable<TES_BOM>>> p_action)
{
ResultObject<IQueryable<TES_BOM>> _ret = new ResultObject<IQueryable<TES_BOM>>();
try
{
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
{
IQueryable<TES_BOM> q = db.TES_BOM;
if (!string.IsNullOrEmpty(p_entity.ParentPart))
{
q = q.Where(p => p.ParentPart.Contains(p_entity.ParentPart));
}
if (!string.IsNullOrEmpty(p_entity.ComponentPart))
{
q = q.Where(p => p.ComponentPart.Contains(p_entity.ComponentPart));
}
if (!string.IsNullOrEmpty(p_entity.Reference))
{
q = q.Where(p => p.Reference.Contains(p_entity.Reference));
}
if (p_entity.QuantityPer != 0)
{
q = q.Where(p => p.QuantityPer == p_entity.QuantityPer);
}
if (!string.IsNullOrEmpty(p_entity.StructureType))
{
q = q.Where(p => p.StructureType.Contains(p_entity.StructureType));
}
if (!string.IsNullOrEmpty(p_entity.Remarks))
{
q = q.Where(p => p.Remarks.Contains(p_entity.Remarks));
}
if (!string.IsNullOrEmpty(p_entity.EndEffective))
{
q = q.Where(p => p.EndEffective.Contains(p_entity.EndEffective));
}
if (p_entity.Scrap != 0)
{
q = q.Where(p => p.Scrap == p_entity.Scrap);
}
if (p_entity.LeadTimeOffset != 0)
{
q = q.Where(p => p.LeadTimeOffset == p_entity.LeadTimeOffset);
}
if (p_entity.Operation != 0)
{
q = q.Where(p => p.Operation == p_entity.Operation);
}
if (p_entity.SequenceNumber != 0)
{
q = q.Where(p => p.SequenceNumber == p_entity.SequenceNumber);
}
if (p_entity.FporecastPercent != 0)
{
q = q.Where(p => p.FporecastPercent == p_entity.FporecastPercent);
}
if (!string.IsNullOrEmpty(p_entity.OptionGroup))
{
q = q.Where(p => p.OptionGroup.Contains(p_entity.OptionGroup));
}
if (!string.IsNullOrEmpty(p_entity.Process))
{
q = q.Where(p => p.Process.Contains(p_entity.Process));
}
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.CreateUser))
{
q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser));
}
if (!string.IsNullOrEmpty(p_entity.Remark))
{
q = q.Where(p => p.Remark.Contains(p_entity.Remark));
}
if (!string.IsNullOrEmpty(p_entity.CommandType))
{
q = q.Where(p => p.CommandType.Contains(p_entity.CommandType));
}
if (!string.IsNullOrEmpty(p_entity.Domain))
{
q = q.Where(p => p.Domain.Contains(p_entity.Domain));
}
if (!string.IsNullOrEmpty(p_entity.Site))
{
q = q.Where(p => p.Site.Contains(p_entity.Site));
}
if (p_entity.GUID != Guid.Empty)
{
q = q.Where(p => p.GUID == p_entity.GUID);
}
if (p_entity.TaskID != Guid.Empty)
{
q = q.Where(p => p.TaskID == p_entity.TaskID);
}
if (p_entity.DataID != Guid.Empty)
{
q = q.Where(p => p.DataID == p_entity.DataID);
}
if (p_entity.CreateTime != DateTime.MinValue)
{
q = q.Where(p => p.CreateTime.Year == p_entity.CreateTime.Year && p.CreateTime.Day == p_entity.CreateTime.Day && p.CreateTime.Month == p_entity.CreateTime.Month);
}
if (p_entity.StartEffective != DateTime.MinValue)
{
q = q.Where(p => p.StartEffective.Year == p_entity.StartEffective.Year && p.StartEffective.Day == p_entity.StartEffective.Day && p.StartEffective.Month == p_entity.StartEffective.Month);
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_BOM), "Get_TES_BOM_List", e.Message);
throw e;
}
}
public static ResultObject<bool> Save_TES_BOM(List<TES_BOM> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
{
foreach (var itm in p_entitys)
{
db.TES_BOM.AddOrUpdate(itm);
}
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_BOM), "Save_TES_BOM", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public ResultObject<bool> Del_TES_BOM(List<TES_BOM> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
{
foreach (var itm in p_entitys)
{
db.TES_BOM.Remove(itm);
}
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_BOM), "Del_TES_BOM", e.Message); throw e;
}
return _ret;
}
}
}