/// <summary> /// Event /// Click on the delete button /// </summary> private void Btn_Shifts_Delete_Click(object sender, RoutedEventArgs e) { try { //Verification if (m_Shift.id == null) { MessageBox.Show(this, m_Global_Handler.Resources_Handler.Get_Resources("NoShiftSelectedErrorText"), m_Global_Handler.Resources_Handler.Get_Resources("NoShiftSelectedErrorCaption"), MessageBoxButton.OK, MessageBoxImage.Warning); return; } //Confirm the delete MessageBoxResult result = MessageBox.Show(this, m_Global_Handler.Resources_Handler.Get_Resources("ShiftConfirmDelete"), m_Global_Handler.Resources_Handler.Get_Resources("ShiftConfirmDeleteCaption"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation); if (result == MessageBoxResult.No) { return; } //Delete in database string res = m_Database_Handler.Delete_ShiftFromDatabase(m_Shift.id); //Treat the result if (res.Contains("OK")) { //Action m_Global_Handler.Log_Handler.WriteAction("Shift " + m_Shift.id + " deleted"); //Delete from the datagrid int index = Datagrid_Shifts.SelectedIndex; m_Datagrid_Missions_ShiftsCollection.RemoveAt(index); Datagrid_Shifts.Items.Refresh(); //Delete from the mission m_Mission.id_list_shifts = m_Mission.id_list_shifts.Replace(m_Shift.id + ";", ""); m_Database_Handler.Edit_MissionToDatabase(m_Mission.address, m_Mission.city, m_Mission.client_name, m_Mission.country, m_Mission.date_billed, m_Mission.date_creation, m_Mission.date_declined, m_Mission.date_done, m_Mission.description, m_Mission.end_date, m_Mission.id, m_Mission.id_client, m_Mission.id_list_shifts, m_Mission.start_date, m_Mission.state, m_Mission.zipcode); //Delete from the collection SoftwareObjects.ShiftsCollection.Remove(SoftwareObjects.ShiftsCollection.Find(x => x.id.Equals(m_Shift.id))); m_Shift = null; //Clear boxes Cld_Shifts_Shift_Date.SelectedDate = DateTime.Today; Cld_Shifts_Shift_Date.DisplayDate = DateTime.Today; Txt_Shifts_Shift_HourlyRate.Text = ""; Txt_Shifts_Shift_Pause.Text = ""; Cmb_Shifts_Shift_EndHour_Hour.Text = ""; Cmb_Shifts_Shift_EndHour_Min.Text = ""; Cmb_Shifts_Shift_HostOrHostess.Text = ""; Cmb_Shifts_Shift_StartHour_Hour.Text = ""; Cmb_Shifts_Shift_StartHour_Min.Text = ""; Chk_Shifts_Shift_Suit.IsChecked = false; return; } else if (res.Contains("error")) { //Treatment of the error MessageBox.Show(this, res, m_Global_Handler.Resources_Handler.Get_Resources("Error"), MessageBoxButton.OK, MessageBoxImage.Error); m_Global_Handler.Log_Handler.WriteMessage(MethodBase.GetCurrentMethod().Name, res); return; } else { //Error connecting to web site MessageBox.Show(this, res, m_Global_Handler.Resources_Handler.Get_Resources("Error"), MessageBoxButton.OK, MessageBoxImage.Error); m_Global_Handler.Log_Handler.WriteMessage(MethodBase.GetCurrentMethod().Name, res); return; } } catch (Exception exception) { m_Global_Handler.Log_Handler.WriteException(MethodBase.GetCurrentMethod().Name, exception); return; } }