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.BasicInfo { public class LogBLL { BasicBLL db=new BasicBLL(); public string SearchSearchInfoAll(string page, string pagesize, string StartTime, string EndTime, string Op) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = db.SearchAllInfo().OrderByDescending(p => p.ID).ToList(); DateTime st, et; if (!DateTime.TryParse(StartTime, out st)) st = DateTime.Now.AddDays(-1); if (!DateTime.TryParse(EndTime, out et)) et = DateTime.Now; if (!String.IsNullOrEmpty(Op)) { list = list.Where(p => p.CreateTime >= st && p.CreateTime <= et && p.Op == Op).OrderByDescending(p => p.ID).ToList(); } else { list = list.Where(p => p.CreateTime >= st && p.CreateTime <= et) .OrderByDescending(p => p.ID).Take(100).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(); List modelList=new List(); BasicBLL userdb=new BasicBLL(); var s_list = userdb.SearchAllInfo(); foreach (var item in list) { LogModel dm = Tool.Mapper(item); var info = s_list.FirstOrDefault(p => p.UserID.ToString()== item.UserID.ToLower()); if (info != null) { dm.UserName = info.UserName; } modelList.Add(dm); } JsonDataModel md=new JsonDataModel(); md.total = total.ToString(); md.rows = modelList; IsoDateTimeConverter timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }; jsonStr = JsonConvert.SerializeObject(md, Formatting.Indented, timeConverter); //jsonStr = JSONTools.ScriptSerialize>(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod()); return null; } } } }