/*private void LoadUserTimeRecording(user selectedUser) * { * var yesterday = DateTime.Now.Date; * selectedUser = GetUserTimeRecording(toolStripComboSelectUser.Text); * var entry = dbHelper.time_recording.Where(t => t.user_id == selectedUser.user_id && t.created_at > yesterday).ToList(); * if(entry.Count == 0) * { * btnClockIn.Enabled = true; * dataGridView1.DataSource = null; * return; * } * else * { * btnClockIn.Enabled = false; * dataGridView1.DataSource = entry.ToList(); * } * }*/ private void btnClockIn_Click(object sender, EventArgs e) { if (toolStripComboSelectUser.Text == string.Empty) { MessageBox.Show("Please select a user", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Convert.ToDateTime(dateTimePicker1.Text) > DateTime.Now) { MessageBox.Show("This is a future date", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var selectedUser = GetUserTimeRecording(toolStripComboSelectUser.Text); using (emedEntities db = new emedEntities()) { time_recording tr = new time_recording(); tr.creator_id = StartPage._loggedInUser.user_id; tr.user_id = selectedUser.user_id; tr.state = 1; tr.created_at = DateTime.Now; tr.date_from = Convert.ToDateTime(dateTimePicker1.Text); tr.trt_id = 1; db.time_recording.Add(tr); db.SaveChanges(); btnClockIn.Enabled = false; MessageBox.Show("You have clocked in", "Message"); //LoadUserTimeRecording(selectedUser); LoadUserAttendance(selectedUser); } } }
private time_recording GetUserTimeRecord(time_recording tc) { if (toolStripComboSelectUser.Text == string.Empty) { return(null); } else if (dataGridView1.DataSource == null) { return(null); } else { if (dataGridView1.CurrentRow.Index != -1) { tc.tc_id = Convert.ToInt32(dataGridView1.CurrentRow.Cells["Id"].Value); tc = dbHelper.time_recording.FirstOrDefault(t => t.tc_id == tc.tc_id); } return(tc); } }