using System; using System.Collections.Generic; using Unity; using System.Linq; using Cowain.Bake.BLL; using Cowain.Bake.Model; using Cowain.Bake.Common.Core; using Cowain.Bake.Model.Entity; namespace Cowain.Bake.BLL { public class BatteryNGService : ServiceBase { public BatteryNGService(IUnityContainer unityContainer) : base(unityContainer) { } public List GetAllNGCell( ) { using (var Context = new BakingEntities()) { return Context.Set().ToList().OrderByDescending(x=>x.Id).Take(200).ToList(); } } public TBatteryNG GetCurrentNGBattery(string batteryCode) //存在多次复投 { using (var Context = new BakingEntities()) { return (from n in Context.Set() join b in Context.Set() on n.BatteryCode equals b.BatteryCode where b.BatteryCode == batteryCode orderby b.Id descending select n).FirstOrDefault(); } } public List QueryNGCell(DateTime startTime, DateTime endTime, string batteryCode) { using (var Context = new BakingEntities()) { if(string.IsNullOrEmpty(batteryCode)) { return (from n in Context.Set() where n.CreateTime > startTime && n.CreateTime < endTime select n).ToList(); } else { return (from n in Context.Set() where n.CreateTime > startTime && n.CreateTime < endTime && n.BatteryCode == batteryCode select n).ToList(); } } } public int Insert(string palletCode, string batteryCode, string desc) { TBatteryNG NG = new TBatteryNG() { PalletCode = palletCode, BatteryCode = batteryCode, CreateTime = DateTime.Now, Desc = desc, }; using (var Context = new BakingEntities()) { Context.Set().Add(NG); return Context.SaveChanges(); } } } }