using System; using System.Collections.Generic; using System.Linq; using System.Web; using Warehouse.Models.mesModel; using Warehouse.Models; using System.Data.Entity.Validation; namespace Warehouse.DAL.LCL { public class LCLDal { public pack_pallets QueryPallet(string Pallet) { using (var mescontext = new mesModel()) { var res = mescontext.pack_pallets.Where(a => a.pallet_nbr == Pallet).FirstOrDefault(); return res; } } public config_products QueryProduct(string ProductCode) { using (var mescontext = new mesModel()) { var res = mescontext.config_products.Where(a => a.product_code == ProductCode).FirstOrDefault(); return res; } } //pallet isLCL public tcontainerpallet QueryContainerBindPallet(string pallet) { using (var whcontext = new whModel()) { //var res = whcontext.tcontainerpallets.Count(a => a.palletno == pallet); //if (res > 0) //{ // return true; //} //else //{ // return false; //} //return whcontext.tcontainerpallets.Join(whcontext.tcontainers, a => a.ContainerNo, g => g.ContainerNo, (a, g) => new { a.ContainerNo,a.palletno,g.bartype,g.cellqty,g.color,g.Count,g.finalgrade,g.igrade,g.powergrade,g.modulespec }); return whcontext.tcontainerpallets.Where(a => a.palletno == pallet).FirstOrDefault(); } } public List QueryStockInfoByPallet(string pallet) { using (var context = new whModel()) { string sql = @"select a.palletno,a.storagelocationid ,createtime,b.locationname from wh.tstockinlog a left join wh.tstoragelocation b on a.storagelocationid = b.id where a.id = (select max(id) from tstockinlog where palletno = '"+pallet+"' )"; //context.Database.SqlQuery(" call prGetPalletOfContainer('" + container + "') ").ToList(); var res = context.DynamicListFromSql(sql, null); if (res != null) { return res.ToList(); } else { return null; } } } public List QueryPalletStockInfoByConatiner(string container) { using (var context = new whModel()) { //context.Database.SqlQuery(" call prGetPalletOfContainer('" + container + "') ").ToList(); var res = context.DynamicListFromSql("call prGetPalletOfContainer('" + container + "')", null); if (res.Count() != 0) { return res.ToList(); } else { return null; } } //return null; } public List QueryPalletAndProduct(string pallets) { using (var context = new mesModel()) { //var res = context.Database.SqlQuery(" EXEC [dbo].[prGetPalletAndPriduct] @pallets = N'"+pallets+"'"); //return res.ToList(); var res = context.DynamicListFromSql("EXEC[dbo].[prGetPalletAndProduct] @pallets = N'" + pallets + "'", null); if (res.Count()!= 0) { return res.ToList(); } else { return null; } } } public List QueryAllPalletOfConatiner(string container) { using (var whcontext = new whModel()) { var res = whcontext.tcontainerpallets.Where(a => a.ContainerNo == container); if (res != null) { return res.ToList(); } else { return null; } } } public bool UpdateContainerStatus(string container, string status) { using (var whcontext = new whModel()) { var containerres = whcontext.tcontainers.Where(a => a.ContainerNo == container).FirstOrDefault(); containerres.State = "complete"; var res = whcontext.tcontainerpallets.Where(a => a.ContainerNo == container); foreach (var item in res) { item.status = "complete"; } var saveres = whcontext.SaveChanges(); if (saveres > 0) { return true; } else { return false; } } } public tcontainer QueryContainer(string container) { using (var whcontext = new whModel()) { return whcontext.tcontainers.Where(a => a.ContainerNo == container).FirstOrDefault(); } } public bool CreateContainer(tcontainer container) { try { using (var whcontext = new whModel()) { //var res = whcontext.tcontainerpallets.Count(a => a.palletno == pallet); whcontext.tcontainers.Add(container); var res = whcontext.SaveChanges(); if (res > 0) { return true; } else { return false; } } } catch (DbEntityValidationException dbEx) { var a = dbEx.EntityValidationErrors; return false; } } public bool CreateContainerBindPallet(tcontainerpallet containpallet) { using (var whcontext = new whModel()) { //var res = whcontext.tcontainerpallets.Count(a => a.palletno == pallet); whcontext.tcontainerpallets.Add(containpallet); var res = whcontext.SaveChanges(); if (res > 0) { return true; } else { return false; } } } } }