private void LoadTodayAttendanceForCourse() { try { var data = _repo.GetTodayAttendanceByCourse(_courseId); if (data != null && data.Count > 0) { dataGrid.DataSource = data; dataGrid.Columns["Id"].Visible = false; dataGrid.Columns["SessionSemester"].Visible = false; dataGrid.Columns["Course"].Visible = false; dataGrid.Columns["DepartmentName"].Visible = false; dataGrid.Columns["MarkedBy"].Visible = false; dataGrid.Columns["StudentLevel"].Visible = false; dataGrid.Columns["DateMarked"].Visible = false; dataGrid.Columns["StudentMatricNo"].HeaderText = "Matric Number"; dataGrid.Columns["StudentName"].HeaderText = "Student Name"; dataGrid.Columns["TimeIn"].HeaderText = "Time In"; } else { var dt = new DataTable(); dataGrid.Columns.Clear(); dt.Columns.Add("Message", typeof(string)); dt.Rows.Add("No record found"); dataGrid.DataSource = dt; } } catch (Exception e) { MessageBox.Show(this, e.Message, "Error occured loading attendance", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void getTodayAttendance() { try { var todayAttendance = _attendanceRepo.GetTodayAttendanceByCourse(courseId); foreach (var item in todayAttendance) { DataGridViewRow rw = (DataGridViewRow)gdvAttendance.Rows[0].Clone(); rw.Cells[0].Value = item.StudentName; rw.Cells[1].Value = item.StudentMatricNo; rw.Cells[2].Value = item.TimeIn; gdvAttendance.Rows.Add(rw); } } catch (Exception ex) { MessageBox.Show("An error occured while getting today's attendance " + ex.Message + " inner exception: " + ex.InnerException.ToString(), "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }