using MESClassLibrary.BLL.Log; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace MESClassLibrary.BLL.Stock { public class StockInBLL { BBMPTEntities dbe = new BBMPTEntities(); BasicBLL db = new BasicBLL(); BasicBLL Resultdb = new BasicBLL(); /// /// 查询信息 /// /// public string SearchInfo(string page, string pagesize, string StartTime, string EndTime, string workClass, string color, string productInfo) { try { string jsonStr = "[]"; int total = 0;//总行数 //List list = db.SearchAllInfo(); DateTime start = Convert.ToDateTime(StartTime); DateTime end = Convert.ToDateTime(EndTime); List list = dbe.tb_StockIn.Where(p => p.createTime >= start && p.createTime <= end && "1".Equals(p.pass)).ToList(); //list = list.Where(p => p.createTime >= start && p.createTime <= end && "1".Equals(p.pass)).ToList(); List barcodeList = list.Select(m => m.barcode).ToList(); var resultList = dbe.tb_InspectResult.Where(p => barcodeList.Contains(p.barcode) && p.inspectResult.Contains("合格")).ToList(); if (!String.IsNullOrEmpty(workClass)) { resultList = resultList.Where(p => p.workClass != null && p.workClass.Contains(workClass)).ToList(); } if (!String.IsNullOrEmpty(color)) { resultList = resultList.Where(p => p.productInfo != null && p.productInfo.Contains(color)).ToList(); } if (!String.IsNullOrEmpty(productInfo)) { resultList = resultList.Where(p => p.productInfo != null && p.productInfo.Contains(productInfo)).ToList(); } list = list.Where(p => resultList.Select(m => m.barcode).ToList().Contains(p.barcode)).ToList(); if (list.Count > 0) { total = list.Count; int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); list = list.OrderByDescending(p => p.createTime).Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList(); List StockInList = new List(); foreach (var item in list) { StockInModel dm = Tool.Mapper(item); var info = resultList.FirstOrDefault(p => p.barcode == item.barcode); if (info != null) { dm.workClass = info.workClass; dm.productInfo = info.productInfo; } StockInList.Add(dm); } JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = StockInList; jsonStr = JSONTools.ScriptSerialize(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } /// /// 查询信息 /// /// public List SearchInfoAll(string StartTime, string EndTime, string workClass, string color, string productInfo) { try { List list = db.SearchAllInfo(); DateTime start = Convert.ToDateTime(StartTime); DateTime end = Convert.ToDateTime(EndTime); list = list.Where(p => p.createTime >= start && p.createTime <= end && "1".Equals(p.pass)).ToList(); List barcodeList = list.Select(m => m.barcode).ToList(); var resultList = dbe.tb_InspectResult.Where(p => barcodeList.Contains(p.barcode) && p.inspectResult.Contains("合格")).ToList(); if (!String.IsNullOrEmpty(workClass)) { resultList = resultList.Where(p => p.workClass != null && p.workClass.Contains(workClass)).ToList(); } if (!String.IsNullOrEmpty(color)) { resultList = resultList.Where(p => p.productInfo != null && p.productInfo.Contains(color)).ToList(); } if (!String.IsNullOrEmpty(productInfo)) { resultList = resultList.Where(p => p.productInfo != null && p.productInfo.Contains(productInfo)).ToList(); } list = list.Where(p => resultList.Select(m => m.barcode).ToList().Contains(p.barcode)).ToList(); List StockInList = new List(); if (list.Count > 0) { foreach (var item in list) { StockInModel dm = Tool.Mapper(item); var info = resultList.FirstOrDefault(p => p.barcode == item.barcode); if (info != null) { dm.workClass = info.workClass; dm.productInfo = info.productInfo; } StockInList.Add(dm); } } return StockInList; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } } }