示例#1
0
 /// <summary>
 /// 分页查询
 /// </summary>
 /// <param name="uid">编号</param>
 /// <param name="name">名称</param>
 /// <param name="pageIndex">当前页</param>
 /// <param name="pageSize">每次显示条数</param>
 /// <returns></returns>
 public IActionResult QueryPage(string searchModel, int pageIndex, int pageSize)
 {
     try
     {
         int total = 0;
         SearchAttendance model = new SearchAttendance();
         if (searchModel != "")
         {
             model = JsonConvert.DeserializeObject <SearchAttendance>(searchModel);
         }
         var list   = GetData(model, pageIndex, pageSize, out total);
         var result = new
         {
             code      = 0,
             data      = list,
             pageIndex = pageIndex,
             pageSize  = pageSize,
             count     = total
         };
         return(new JsonResult(result));
     }
     catch (Exception ex)
     {
         return(new JsonResult(new { code = 1, msg = "查询失败!" + ex.Message }));
     }
 }
示例#2
0
        private List <AttendanceViewModel> GetData(SearchAttendance search, int pageIndex, int pageSize, out int total)
        {
            if (search == null)
            {
                search = new SearchAttendance();
            }
            string shipId = base.user.ShipId;

            if (ManagerHelp.IsShipPort)
            {
                shipId = "";
            }
            var arrWhere = _context.Attendance.Where(c => c.ShipId == shipId);

            if (!(string.IsNullOrEmpty(search.StartTime)) && !(string.IsNullOrEmpty(search.EndTime)))
            {
                DateTime dtStart = DateTime.Parse(search.StartTime);
                DateTime dtEnd   = DateTime.Parse(search.EndTime);
                arrWhere = arrWhere.Where(c => c.Time >= dtStart && c.Time <= dtEnd);
            }
            else if (!(string.IsNullOrEmpty(search.StartTime)))
            {
                DateTime dtStart = DateTime.Parse(search.StartTime);
                arrWhere = arrWhere.Where(c => c.Time >= dtStart);
            }
            else if (!(string.IsNullOrEmpty(search.EndTime)))
            {
                DateTime dtEnd = DateTime.Parse(search.EndTime);
                arrWhere = arrWhere.Where(c => c.Time <= dtEnd);
            }
            if (!string.IsNullOrEmpty(search.Behavior))
            {
                int dehav = Convert.ToInt32(search.Behavior);
                arrWhere = arrWhere.Where(c => c.Behavior == dehav);
            }
            if (!string.IsNullOrEmpty(search.Name))
            {
                arrWhere = arrWhere.Where(c => c.CrewName.Contains(search.Name));
            }
            if (!string.IsNullOrEmpty(search.Job))
            {
                arrWhere = arrWhere.Where(c => c.CrewJob.Contains(search.Job));
            }
            var attdata = arrWhere.ToList();

            total = attdata.Count;
            var pices = _context.AttendancePicture.Where(c => attdata.Select(c => c.Id).Contains(c.AttendanceId)).ToList();
            List <AttendanceViewModel> list = new List <AttendanceViewModel>();
            var pageData = (from a in attdata
                            select new
            {
                a.Id,
                a.CrewId,
                a.Behavior,
                a.CreateTime,
                a.Time,
                Job = a.CrewJob,
                Name = a.CrewName
            }).OrderByDescending(c => c.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize);

            foreach (var item in pageData)
            {
                string picture = "";
                if (pices.Where(c => c.AttendanceId == item.Id).Any())
                {
                    picture = Convert.ToBase64String(pices.FirstOrDefault(c => c.AttendanceId == item.Id).Picture);
                }
                AttendanceViewModel model = new AttendanceViewModel()
                {
                    Behavior = item.Behavior == 0 ? "入" : "出",
                    Time     = item.Time.ToString("yyyy-MM-dd HH:mm:ss"),
                    Picture  = picture,
                    Job      = item.Job,
                    Name     = item.Name
                };
                list.Add(model);
            }
            return(list);
        }