private void update() { emp_dtgrid.ItemsSource = db1.employee.ToList(); List <employee> lst_e = db1.employee.ToList(); List <employee> employees = new List <employee>(); string today_date = DateTime.Now.ToString("dd/MM/yyyy"); foreach (employee emp in lst_e) { shift sh = findShift(emp); if (sh != null) { string shift_date = sh.date.ToString("dd/MM/yyyy"); if (emp.is_working_now == "not at shift" && emp.deleted == "exist" && today_date == shift_date) { employees.Add(emp); } } } emp_dtgrid.ItemsSource = employees; emp_dtgrid.Columns[10].Visibility = Visibility.Collapsed; emp_dtgrid.Columns[11].Visibility = Visibility.Collapsed; emp_dtgrid.Columns[12].Visibility = Visibility.Collapsed; emp_dtgrid.Columns[13].Visibility = Visibility.Collapsed; emp_dtgrid.Columns[14].Visibility = Visibility.Collapsed; }
private void emp_dtgrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { sh = new shift(); try { sh = (shift)shift_dtgrid.SelectedItem; calendar.SelectedDate = new DateTime(Convert.ToInt32(sh.date.ToString().Substring(7, 4)), Convert.ToInt32(sh.date.ToString().Substring(3, 2)), Convert.ToInt32(sh.date.ToString().Substring(0, 2))); no_lsb.IsSelected = true; id_num_txb.Text = sh.employee.id_number; name_txb.Text = sh.employee.first_name + " " + sh.employee.last_name; if (sh.shift_time.time == "Morning") { mornng_rdb.IsChecked = true; } else { evnng_rdb.IsChecked = true; } } catch { MessageBox.Show("you selected a non-existent employee", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void tickEvent(object sender, EventArgs e) { string time_now = DateTime.Now.ToString().Substring(DateTime.Now.ToString().IndexOf(" ") + 1); if (time_now == "23:59:00") { List <employee> lst_e = db1.employee.ToList(); foreach (employee emp in lst_e) { emp.is_working_now = "not at shift"; shift shift = findShift(emp); if (shift != null) { double time_of_working; shift.shift_time.checkout_time = "23:59:00"; double entry_hour = Convert.ToInt32(shift.shift_time.entry_time.ToString().Substring(0, 2)); double entry_minute = Convert.ToInt32(shift.shift_time.entry_time.ToString().Substring(3, 2)); double exit_hour = Convert.ToInt32(shift.shift_time.checkout_time.ToString().Substring(0, 2)); double exit_minute = Convert.ToInt32(shift.shift_time.checkout_time.ToString().Substring(3, 2)); time_of_working = exit_hour - entry_hour; double total_minutes = exit_minute - entry_minute; time_of_working += total_minutes / 60; shift.time_of_working += Convert.ToDecimal(time_of_working); } db1.SaveChanges(); } } datetime_lbl.Content = DateTime.Now.ToString("MM/dd/yyyy , hh:mm:ss , dddd"); }
private bool IsAlreadyShift(shift shift_emp) { List <shift> l_sh = db1.shift.ToList(); foreach (shift sh in l_sh) { if (shift_emp.date == sh.date && shift_emp.employee == sh.employee && shift_emp.shift_time == sh.shift_time) { return(true); } } return(false); }
private void sbmt_btn_Click(object sender, RoutedEventArgs e) { int id_time; if (calendar.SelectedDate == null) { msg_lsb.Items.Add("Failure! Enter the date"); } else if (calendar.SelectedDate.Value.DayOfWeek.ToString() == "Friday" || calendar.SelectedDate.Value.DayOfWeek.ToString() == "Saturday") { msg_lsb.Items.Add("Failure! The Pizza doesn't work on this day"); } else if (mornng_rdb.IsChecked == false && evnng_rdb.IsChecked == false) { msg_lsb.Items.Add("Failure Enter the time"); } else if (emp == null) { msg_lsb.Items.Add("Failure! Select the worker"); } else { if (mornng_rdb.IsChecked == true) { id_time = 1; } else { id_time = 2; } DateTime dt = calendar.SelectedDate.Value; shift_time sht = db1.shift_time.ToArray()[id_time - 1]; shift shift_emp = new shift { shift_time = sht, shift_time_id = id_time, employee = emp, date = dt, time_of_working = Convert.ToDecimal(0.00) }; if (!IsAlreadyShift(shift_emp)) { this.db1.shift.Add(shift_emp); this.db1.SaveChanges(); MessageBox.Show("The shift has been added", "Succes", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } else { MessageBox.Show("The shift you want to add is already exist in the system", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } } }
private void emp_dtgrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { sh = new shift(); try { sh = (shift)shift_dtgrid.SelectedItem; week_txb.Text = sh.week; no_lsb.IsSelected = true; id_num_txb.Text = sh.employee.id_number; name_txb.Text = sh.employee.name; if (sh.time == "Morning") { mornng_rdb.IsChecked = true; } else { evnng_rdb.IsChecked = true; } if (sh.day == "Sunday") { day_cmbbx.SelectedIndex = 0; } else if (sh.day == "Monday") { day_cmbbx.SelectedIndex = 1; } else if (sh.day == "Tuesday") { day_cmbbx.SelectedIndex = 2; } else if (sh.day == "Wednesday") { day_cmbbx.SelectedIndex = 3; } else if (sh.day == "Thursday") { day_cmbbx.SelectedIndex = 4; } else { day_cmbbx.SelectedIndex = 5; } } catch { MessageBox.Show("you selected a non-existent employee", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void entry_btn_Click(object sender, RoutedEventArgs e) { if (emp != null) { if (MessageBox.Show("Do you want to put in " + emp.first_name + " " + emp.last_name + " to the system?", "Enter?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { emp.is_working_now = "at shift"; shift shift = findShift(emp); string entry_time = DateTime.Now.ToString().Substring(DateTime.Now.ToString().IndexOf(" ") + 1); shift.shift_time.entry_time = entry_time; db1.SaveChanges(); } } else { MessageBox.Show("you selected a non-existent employee", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } update(); }
private void sbmt_btn_Click(object sender, RoutedEventArgs e) { string time; string week; string day; if (week_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter the week"); } else if (mornng_rdb.IsChecked == false && evnng_rdb.IsChecked == false) { msg_lsb.Items.Add("Failure Enter the time"); } else if (day_cmbbx.SelectedItem == null) { msg_lsb.Items.Add("Failure! Select the day"); } else if (emp == null) { msg_lsb.Items.Add("Failure! Select the worker"); } else { if (mornng_rdb.IsChecked == true) { time = mornng_rdb.Content.ToString(); } else { time = evnng_rdb.Content.ToString(); } week = week_txb.Text; day = day_cmbbx.Text; shift shift_emp = new shift { day = day, time = time, week = week, employee = emp }; this.db1.shift.Add(shift_emp); this.db1.SaveChanges(); this.Close(); } }
private void exit_btn_Click(object sender, RoutedEventArgs e) { if (emp != null) { if (MessageBox.Show("Do you want to take out " + emp.first_name + " " + emp.last_name + " from the system?", "EXIT?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { emp.is_working_now = "not at shift"; shift shift = findShift(emp); string checkout_time = DateTime.Now.ToString().Substring(DateTime.Now.ToString().IndexOf(" ") + 1); shift.shift_time.checkout_time = checkout_time; double total_minutes; double time_of_working = 0; double entry_hour = Convert.ToInt32(shift.shift_time.entry_time.ToString().Substring(0, 2)); double entry_minute = Convert.ToInt32(shift.shift_time.entry_time.ToString().Substring(3, 2)); double exit_hour = Convert.ToInt32(shift.shift_time.checkout_time.ToString().Substring(0, 2)); double exit_minute = Convert.ToInt32(shift.shift_time.checkout_time.ToString().Substring(3, 2)); time_of_working += exit_hour - entry_hour; if (exit_minute - entry_minute > 0) { total_minutes = exit_minute - entry_minute; time_of_working += total_minutes / 60; } else { time_of_working -= 1; total_minutes = exit_minute - entry_minute + 60; time_of_working += total_minutes / 60; } shift.time_of_working += Convert.ToDecimal(time_of_working); db1.SaveChanges(); } } else { MessageBox.Show("you selected a non-existent employee", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } update(); }