private void CheckBoxChanged(object sender, RoutedEventArgs e) { CheckBox checkBox = (CheckBox)e.OriginalSource; DataGridRow dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox); if ((bool)checkBox.IsChecked) { if (selectedPunch == null) { // store selected punch selectedPunch = (punch)dataGridRow.DataContext; checkedBox = checkBox; } else { // if another box already checked, uncheck the most recently checked box without triggering function call checkBox.Unchecked -= CheckBoxChanged; checkBox.IsChecked = false; checkBox.Unchecked += CheckBoxChanged; snackbar.MessageQueue.Enqueue("One selection at a time."); } } else { // it was unchecked selectedPunch = null; checkedBox = null; } }
public UpdatePunch(punch sp, timeclock tc) { InitializeComponent(); selectedPunch = sp; tmeclk = tc; updMsg.Text += sp.toString(); }
private void Delete_Punch(object sender, RoutedEventArgs e) { if (selectedPunch != null) { int id = selectedPunch.id; string name = selectedPunch.name; string pinInput = selectedPunch.pin; string date = selectedPunch.date; string time = selectedPunch.time; string status = selectedPunch.status; DateTime dt = Convert.ToDateTime(date + " " + time); string datetime = dt.ToString("yyyy-MM-dd"); string dt2 = dt.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:ss"); if (this.openConn()) { string query = "USE crst_dash; \n" + "DELETE FROM a_staff_time WHERE id = " + id + ";"; MySqlCommand cmd = new MySqlCommand(query, myconn); try { cmd.ExecuteNonQuery(); // change following punches to opposite status string dt3 = Convert.ToDateTime(dt2).AddDays(1).Date.ToString("yyyy-MM-dd HH-mm-ss"); string query2 = "USE crst_dash; \n" + "UPDATE a_staff_time SET status = IF(status = 1, 0, 1) WHERE pin = \"" + pinInput + "\" AND time >= \"" + dt2 + "\" AND time < \"" + dt3 + "\";"; MySqlCommand cmd2 = new MySqlCommand(query2, myconn); try { cmd2.ExecuteNonQuery(); selectedPunch = null; FillDatagrid(); snackbar.MessageQueue.Enqueue("Punch deleted."); } catch (Exception ex) { snackbar.MessageQueue.Enqueue("Error occured."); Console.WriteLine("Error: " + ex); } } catch (Exception ex) { snackbar.MessageQueue.Enqueue("Error occured."); Console.WriteLine("Error: " + ex); } } } else { snackbar.MessageQueue.Enqueue("Please select a punch to delete."); } }