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 GetAllCellWorkOrderFormula() { using (var Context = new BakingEntities()) { var workOrderFormulaList = Context.Set().Join(Context.Set(), 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 GeAll() { using (var Context = new BakingEntities()) { return Context.Set().ToList(); } } public TProductionInformation GetCurrentProductInfo() { using (var Context = new BakingEntities()) { return (from p in Context.Set() where p.CurrentProduct == true select p).FirstOrDefault(); } } public TProductionInformation QueryWorkOrderById(int Id) { using (var Context = new BakingEntities()) { var query = Context.Set().FirstOrDefault(p => p.Id == Id); return query; } } public TProductionInformation GetProductionInformation(string jobNum) { using (var Context = new BakingEntities()) { return Context.Set().Where(x => x.JobNum == jobNum).FirstOrDefault(); } } //public TProductionInformation GetJobNum() //{ // using (var Context = new BakingEntities()) // { // TProductionInformation productionInformation = Context.Set().Where(x => x.CurrentProduct == true).FirstOrDefault(); // return productionInformation; // } //} public List QueryWorkOrder(string workOrderName) { using (var Context = new BakingEntities()) { var queryList = Context.Set().Join(Context.Set(), 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() where ts.ProcessParamId == ParameterId select ts).FirstOrDefault(); if (q != null) { Context.Set().Remove(q); return Context.SaveChanges(); } return 0; } } public bool GetIsInUse(int ID) { using (var Context = new BakingEntities()) { TProductionInformation productionInformation = Context.Set().Where(x => x.Id == ID).FirstOrDefault(); if (productionInformation.CurrentProduct == true) { return true; } return false; } } } }