private void OpenLogPage(object sender, LogPageViewModel viewModel) { var page = new LogPage(viewModel); NavigationPage.SetHasBackButton(page, true); MainPage.Navigation.PushAsync(page); }
public LogPage(LogPageViewModel viewModel) { InitializeComponent(); BindingContext = viewModel; }
/// <summary> /// 获取日志信息 /// </summary> /// <param name="model">查询条件,日志信息实体,logDate存起始时间</param> /// <param name="endTime">截止时间</param> /// <returns></returns> public LogPageViewModel GetList(LogQueryViewModel model) { var pLogList = db.OT_Log.Where(a => true); //按操作用户查询 if (!string.IsNullOrEmpty(model.UserName)) { pLogList = pLogList.Where(a => a.UserName.Contains(model.UserName)); } //按操作类型查询,如果类型为所有则不增加改条件 if (!string.IsNullOrEmpty(model.Type) && model.Type != Common.OperationType.All) { pLogList = pLogList.Where(a => a.Type == model.Type); } //按报表名称查询 if (!string.IsNullOrEmpty(model.RptName)) { pLogList = pLogList.Where(a => a.RptName.Contains(model.RptName)); } //某时间段之间的所有日志 if (model.EndDate != DateTime.Parse("0001/1/1 0:00:00") && model.StartDate != DateTime.Parse("0001/1/1 0:00:00") && model.EndDate != null && model.StartDate != null && model.StartDate <= model.EndDate) { DateTime dt = model.EndDate.AddSeconds(1); pLogList = pLogList.Where(a => a.LogDate >= model.StartDate & a.LogDate <= dt); } //大于某时间的所日志 else if (model.StartDate != null && model.StartDate != DateTime.Parse("0001/1/1 0:00:00")) { pLogList = pLogList.Where(a => a.LogDate >= model.StartDate); } //小于某时间的所日志 else if (model.EndDate != null && model.EndDate != DateTime.Parse("0001/1/1 0:00:00")) { DateTime dt = model.EndDate.AddSeconds(1); pLogList = pLogList.Where(a => a.LogDate <= dt); } int pageCount, count;//总页数,总行数 //获取数据总条数 count = pLogList.Count(); //获取总页数 pageCount = count % model.PageSize > 0 ? count / model.PageSize + 1 : count / model.PageSize; //如果页数大于总页数,或者小于1,则返回第一页 if (model.PageIndex > pageCount || model.PageIndex < 1) { model.PageIndex = 1; } List <LogManageViewModel> list; //获取日志信息 if (model.PageIndex == 1) { list = pLogList.OrderByDescending(a => a.LogDate).Take(model.PageSize).Select(a => new LogManageViewModel { RoleName = a.RoleName, LogDate = a.LogDate, Type = a.Type, Describe = a.Describe, RptName = a.RptName, UserName = a.UserName }).ToList(); } else { int excludedRows = (model.PageIndex - 1) * model.PageSize;//计算起始索引 list = pLogList.OrderByDescending(a => a.LogDate).Skip(excludedRows).Take(model.PageSize).Select(a => new LogManageViewModel { RoleName = a.RoleName, LogDate = a.LogDate, Type = a.Type, Describe = a.Describe, RptName = a.RptName, UserName = a.UserName }).ToList(); } //构建分页日志信息并返回 LogPageViewModel lpModel = new LogPageViewModel(); lpModel.Count = count; lpModel.PageCount = pageCount; lpModel.PageIndex = model.PageIndex; lpModel.LogList = list; return(lpModel); }