public void GetData(string id) { ManagerDAO dao = new ManagerDAO(); manageDTO dto = dao.getManageDTO(id); lbFNames.Text = dto.FullName; lbCars.Text = dto.numberOfCars.ToString(); lbParked.Text = dto.numberOfParked.ToString(); lbTimes.Text = dto.numberOfTimes; dgvHistory.DataSource = dto.HistoryLists; }
public manageDTO getManageDTO(string id) { manageDTO dto = new manageDTO(); DataClasses1DataContext db = new DataClasses1DataContext(); var user = (from table in db.tblUsers where table.userID == id select table).SingleOrDefault(); if (user != null) { dto.FullName = user.firstName + " " + user.lastName; } var carcount = (from table in db.tblCars where table.userID == id select table).Count(); if (carcount > 0) { dto.numberOfCars = carcount; } double gio = 0; double phut = 0; double ngay = 0; var totalhis = (from table in db.tblHistories where table.userID == id select table); if (totalhis != null) { foreach (var item in totalhis) { if (item.timeIn != null && item.timeOut != null) { phut += (item.timeOut - item.timeIn).Value.TotalMinutes; gio += (item.timeOut - item.timeIn).Value.TotalHours; ngay += (item.timeOut - item.timeIn).Value.TotalDays; } } } dto.numberOfTimes = ngay + " ngay " + gio + " gio " + phut + " phut "; dto.numberOfParked = totalhis.Count(); dto.HistoryLists = totalhis.ToList(); return(dto); }