Files
6098/Cowain.Bake.BLL/ProductionInformationService.cs

138 lines
5.1 KiB
C#
Raw Permalink Normal View History

using Cowain.Bake.Common.Core;
using Cowain.Bake.Model;
using Cowain.Bake.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
namespace Cowain.Bake.BLL
{
public class ProductionInformationService : ServiceBase
{
public ProductionInformationService(IUnityContainer unityContainer) : base(unityContainer)
{
}
//所有的工单,匹配对应的配方
public List<WorkOrderFormulaEntity> GetAllCellWorkOrderFormula()
{
using (var Context = new BakingEntities())
{
var workOrderFormulaList = Context.Set<TProductionInformation>().Join(Context.Set<TProcessParameter>(),
c => c.ProcessParamId,
p => p.Id,
(c, p) => new WorkOrderFormulaEntity
{
Id = c.Id,
JobNum = c.JobNum,
ProductionDatetime = c.ProductionDatetime,
CurrentProduct = c.CurrentProduct,
ProcessParamId = c.ProcessParamId,
DummyRule = c.DummyRule,
ReProcessParamId = c.ReProcessParamId,
Parameters = p.Parameters,
BaseFlag = p.BaseFalg,
ProcessParamName = p.ProcessParamName
}).OrderBy(x => x.Id).ThenByDescending(x => x.ProductionDatetime).ToList();
return workOrderFormulaList;
}
}
public List<TProductionInformation> GeAll()
{
using (var Context = new BakingEntities())
{
return Context.Set<TProductionInformation>().ToList();
}
}
public TProductionInformation GetCurrentProductInfo()
{
using (var Context = new BakingEntities())
{
return (from p in Context.Set<TProductionInformation>()
where p.CurrentProduct == true
select p).FirstOrDefault();
}
}
public TProductionInformation QueryWorkOrderById(int Id)
{
using (var Context = new BakingEntities())
{
var query = Context.Set<TProductionInformation>().FirstOrDefault(p => p.Id == Id);
return query;
}
}
public TProductionInformation GetProductionInformation(string jobNum)
{
using (var Context = new BakingEntities())
{
return Context.Set<TProductionInformation>().Where(x => x.JobNum == jobNum).FirstOrDefault();
}
}
//public TProductionInformation GetJobNum()
//{
// using (var Context = new BakingEntities())
// {
// TProductionInformation productionInformation = Context.Set<TProductionInformation>().Where(x => x.CurrentProduct == true).FirstOrDefault();
// return productionInformation;
// }
//}
public List<WorkOrderFormulaEntity> QueryWorkOrder(string workOrderName)
{
using (var Context = new BakingEntities())
{
var queryList = Context.Set<TProductionInformation>().Join(Context.Set<TProcessParameter>(),
c => c.ProcessParamId,
p => p.Id,
(c, p) => new WorkOrderFormulaEntity
{
Id = c.Id,
JobNum = c.JobNum,
ProductionDatetime = c.ProductionDatetime,
CurrentProduct = c.CurrentProduct,
ReProcessParamId = c.ReProcessParamId,
DummyRule = c.DummyRule,
ProcessParamId = c.ProcessParamId,
Parameters = p.Parameters,
BaseFlag = p.BaseFalg,
ProcessParamName = p.ProcessParamName
}).Where(x => x.JobNum == workOrderName).ToList();
return queryList;
}
}
public int Delete(int ParameterId)
{
using (var Context = new BakingEntities())
{
var q = (from ts in Context.Set<TProductionInformation>()
where ts.ProcessParamId == ParameterId
select ts).FirstOrDefault();
if (q != null)
{
Context.Set<TProductionInformation>().Remove(q);
return Context.SaveChanges();
}
return 0;
}
}
public bool GetIsInUse(int ID)
{
using (var Context = new BakingEntities())
{
TProductionInformation productionInformation = Context.Set<TProductionInformation>().Where(x => x.Id == ID).FirstOrDefault();
if (productionInformation.CurrentProduct == true)
{
return true;
}
return false;
}
}
}
}