using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using MESClassLibrary.BLL.Log; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using Newtonsoft.Json; using Newtonsoft.Json.Converters; namespace MESClassLibrary.BLL.Stock { public class AppendColorBLL { BasicBLL db = new BasicBLL(); public string SearchInfoAll(string page, string pageSize, string barCode, string startTime, string endTime) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = db.SearchAllInfo(); if (!string.IsNullOrWhiteSpace(barCode)) { list = list.Where(p => p.Barcode != null && p.Barcode.Contains(barCode)).ToList(); } if (!string.IsNullOrWhiteSpace(startTime)) { list = list.Where(p => p.CreateTime >= Convert.ToDateTime(startTime) && p.CreateTime <= Convert.ToDateTime(endTime)).ToList(); } list = list.OrderBy(p => p.CreateTime).ToList(); if (list.Count > 0) { total = list.Count; int skipCount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pageSize); list = list.Skip(skipCount).Take(Convert.ToInt32(pageSize)).ToList(); JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = list; IsoDateTimeConverter timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }; jsonStr = JsonConvert.SerializeObject(md, Formatting.Indented, timeConverter); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public List> SearchForExcel(string page, string pageSize, string barCode, string startTime, string endTime) { try { List> list = new List>(); string jsonStr = "[]"; int total = 0;//总行数 List listProduct = db.SearchAllInfo().OrderBy(p => p.CreateTime).ToList(); if (!String.IsNullOrEmpty(barCode)) { listProduct = listProduct.Where(p => p.Barcode != null && p.Barcode.Contains(barCode)).ToList(); } if (!String.IsNullOrEmpty(startTime)) { listProduct = listProduct.Where(p => p.CreateTime >= Convert.ToDateTime(startTime) && p.CreateTime <= Convert.ToDateTime(endTime)).ToList(); } if (listProduct != null && listProduct.Count() > 0) { List title_ = new List(); title_.Add("条码"); title_.Add("颜色"); title_.Add("操作人"); title_.Add("操作时间"); //title_.Add("描述"); list.Add(title_); foreach (var item in listProduct) { List rowList = new List(); rowList.Add(item.Barcode == null ? "" : item.Barcode); rowList.Add(item.ColorInfo == null ? "" : item.ColorInfo); rowList.Add(item.CreateBy == null ? "" : item.CreateBy); rowList.Add(item.CreateTime.ToString()); //rowList.Add(item.SupplierDes == null ? "" : item.SupplierDes); list.Add(rowList); } } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } } }