/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-04-07 /// CHECKED BY: Zoey McDonald /// Event handler for when editing of the datagrid has begun /// </summary> private void DgShiftList_BeginningEdit(object sender, DataGridBeginningEditEventArgs e) { if (((VolunteerShiftVM)dgShiftList.Items[dgShiftList.SelectedIndex]).VolunteerShiftID != 0) { _shiftBeingEdited = (VolunteerShiftVM)dgShiftList.Items[dgShiftList.SelectedIndex]; } }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-02-06 /// CHECKED BY: Zoey McDonald /// DESCRIPTION: Editing constructor for the class /// </summary> public CreateEditShift(VolunteerShiftVM shift) { InitializeComponent(); populateComboBoxes(); _volunteerShift = shift; txtShiftTitle.Text = _volunteerShift.ShiftTitle; chkIsSpecialEvent.IsChecked = _volunteerShift.IsSpecialEvent; dteShiftDate.SelectedDate = _volunteerShift.VolunteerShiftDate; txtShiftNotes.Text = _volunteerShift.ShiftNotes; cboRecurrance.SelectedItem = _volunteerShift.Recurrance; txtShiftDescription.Text = _volunteerShift.ShiftDescription; cboShiftStartAMorPM.SelectedIndex = _volunteerShift.ShiftStartTime.Hours >= 12 ? 1 : 0; cboShiftStartHour.SelectedIndex = twentyFourToTwelveHour( _volunteerShift.ShiftStartTime.Hours) - 1; cboShiftStartMinute.SelectedIndex = _volunteerShift.ShiftStartTime.Minutes; cboShiftEndAMorPM.SelectedIndex = _volunteerShift.ShiftEndTime.Hours >= 12 ? 1 : 0; cboShiftEndHour.SelectedIndex = twentyFourToTwelveHour( _volunteerShift.ShiftEndTime.Hours) - 1; cboShiftStartMinute.SelectedIndex = _volunteerShift.ShiftEndTime.Minutes; }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-02-10 /// CHECKED BY: Zoey McDonald /// Method for editing a shift inside the DB /// </summary> /// <param name="oldShift">The shift to be updated</param> /// <param name="newShift">The new shift</param> /// <returns>Number of rows affected</returns> public int UpdateShift(VolunteerShiftVM oldShift, VolunteerShiftVM newShift) { //Declare variables int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_volunteer_shift"); //Setup cmd object cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; //Add Parameters cmd.Parameters.Add("@VolunteerShiftID", SqlDbType.Int); cmd.Parameters.Add("@ShiftDescription", SqlDbType.NVarChar, 1080); cmd.Parameters.Add("@ShiftDate", SqlDbType.Date); cmd.Parameters.Add("@ShiftTitle", SqlDbType.NVarChar, 500); cmd.Parameters.Add("@ShiftStartTime", SqlDbType.Time); cmd.Parameters.Add("@ShiftEndTime", SqlDbType.Time); cmd.Parameters.Add("@Recurrance", SqlDbType.NVarChar, 100); cmd.Parameters.Add("@IsSpecialEvent", SqlDbType.Bit); cmd.Parameters.Add("@ShiftNotes", SqlDbType.NVarChar, 1080); cmd.Parameters.Add("@ScheduleID", SqlDbType.Int); //Set Parameter values cmd.Parameters["@VolunteerShiftID"].Value = oldShift.VolunteerShiftID; cmd.Parameters["@ShiftDescription"].Value = newShift.ShiftDescription; cmd.Parameters["@ShiftDate"].Value = newShift.VolunteerShiftDate; cmd.Parameters["@ShiftTitle"].Value = newShift.ShiftTitle; cmd.Parameters["@ShiftStartTime"].Value = newShift.ShiftStartTime; cmd.Parameters["@ShiftEndTime"].Value = newShift.ShiftEndTime; cmd.Parameters["@Recurrance"].Value = newShift.Recurrance; cmd.Parameters["@IsSpecialEvent"].Value = newShift.IsSpecialEvent; cmd.Parameters["@ShiftNotes"].Value = newShift.ShiftNotes; cmd.Parameters["@ScheduleID"].Value = newShift.ScheduleID; //Try to execute the query try { conn.Open(); rows = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-03-31 /// CHECKED BY: Zoey McDonald /// Event handler for the add shift button /// </summary> private void BtnAddShift_Click(object sender, RoutedEventArgs e) { try { VolunteerShiftVM shift = (VolunteerShiftVM)dgShiftList.SelectedItem; _shiftManager.SignVolunteerUpForShift(_volunteerID, shift.VolunteerShiftID); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Creator: Timothy Lickteig /// Created: 01/03/2020 /// Approver: Zoey McDonald /// /// Fake select shift method /// </summary> /// <remarks> /// Updater: N/A /// Updated: N/A /// Update: N/A /// </remarks> /// <param name="shiftID">The shiftID to query</param> /// <returns>A shift from the emulated database</returns> public VolunteerShiftVM SelectShift(int shiftID) { VolunteerShiftVM shift = new VolunteerShiftVM(); foreach (VolunteerShiftVM shift2 in _volunteerShifts) { if (shift2.VolunteerShiftID == shiftID) { shift = shift2; } } return(shift); }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-03-01 /// CHECKED BY: Zoey McDonald /// </summary> /// <param name="volunteerID">The volunteerID to query</param> /// <returns>A list of shifts from the database</returns> public List <VolunteerShiftVM> SelectAllShiftsForAVolunteer(int volunteerID) { //Declare variables List <VolunteerShiftVM> shifts = new List <VolunteerShiftVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_shifts_for_a_volunteer"); //Setup cmd object cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; //Add paramaters cmd.Parameters.Add("@VolunteerID", SqlDbType.Int); cmd.Parameters["@VolunteerID"].Value = volunteerID; //Try to execute the query try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { VolunteerShiftVM shift = new VolunteerShiftVM(); shift.VolunteerShiftID = reader.GetInt32(0); shift.ShiftDescription = reader.GetString(1); shift.ShiftTitle = reader.GetString(2); shift.VolunteerShiftDate = reader.GetDateTime(3); shift.ShiftStartTime = reader.GetTimeSpan(4); shift.ShiftEndTime = reader.GetTimeSpan(5); shift.Recurrance = reader.GetString(6); shift.IsSpecialEvent = reader.GetBoolean(7); shift.ShiftNotes = reader.GetString(8); shift.ScheduleID = reader.GetInt32(9); shift.VolunteerID = volunteerID; shift.VolunteerFirstName = reader.IsDBNull(10) ? "" : reader.GetString(10); shift.VolunteerLastName = reader.IsDBNull(11) ? "" : reader.GetString(11); shifts.Add(shift); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(shifts); }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-02-05 /// CHECKED BY: Zoey McDonald /// </summary> /// <param name="shift">Shift Object to be passed</param> /// <returns>Number of rows affected</returns> public int AddVolunteerShift(VolunteerShiftVM shift) { int rows = 0; try { rows = _accessor.AddShift(shift); } catch (Exception ex) { throw ex; } return(rows); }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-02-10 /// CHECKED BY: Zoey McDonald /// </summary> /// <param name="oldShift">Old shift to be replaced</param> /// <param name="newShift">Replacement shift</param> /// <returns>Number of rows affected</returns> public int EditVolunteerShift(VolunteerShiftVM oldShift, VolunteerShiftVM newShift) { int rows = 0; try { rows = _accessor.UpdateShift(oldShift, newShift); } catch (Exception ex) { throw ex; } return(rows); }
/// <summary> /// Creator: Timothy Lickteig /// Created: 02/05/2020 /// Approver: Zoey McDonald /// /// Fake to move a shift /// </summary> /// <remarks> /// Updater: N/A /// Updated: N/A /// Update: N/A /// </remarks> /// <param name="shift">ID of the Volunteer shift to remove</param> /// <returns>The number of rows affected</returns> public int RemoveShift(int shiftID) { int rows = 0; VolunteerShiftVM shiftToRemove = new VolunteerShiftVM(); foreach (VolunteerShiftVM shift in _volunteerShifts) { if (shiftID == shift.VolunteerShiftID) { shiftToRemove = shift; rows++; } } _volunteerShifts.Remove(shiftToRemove); return(rows); }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-02-17 /// CHECKED BY: Zoey McDonald /// </summary> /// <returns>A list of shifts from the database</returns> public List <VolunteerShiftVM> SelectAllShifts() { //Declare variables List <VolunteerShiftVM> shifts = new List <VolunteerShiftVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_all_volunteer_shifts"); //Setup cmd object cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; //Try to execute the query try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { VolunteerShiftVM shift = new VolunteerShiftVM(); shift.VolunteerShiftID = Convert.ToInt32(reader.GetValue(0)); shift.ShiftDescription = Convert.ToString(reader.GetValue(1)); shift.ShiftTitle = Convert.ToString(reader.GetValue(2)); shift.ShiftStartTime = (TimeSpan)(reader.GetValue(3)); shift.ShiftEndTime = (TimeSpan)(reader.GetValue(4)); shift.Recurrance = Convert.ToString(reader.GetValue(5)); shift.IsSpecialEvent = Convert.ToBoolean(reader.GetValue(6)); shift.ShiftNotes = Convert.ToString(reader.GetValue(7)); shift.VolunteerShiftDate = Convert.ToDateTime(reader.GetValue(8)); shift.ScheduleID = Convert.ToInt32(reader.GetValue(9)); shift.VolunteerID = reader.IsDBNull(10) ? 0 : reader.GetInt32(10); shift.VolunteerFirstName = reader.IsDBNull(11) ? "" : reader.GetString(11); shift.VolunteerLastName = reader.IsDBNull(12) ? "" : reader.GetString(12); shifts.Add(shift); } reader.Close(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(shifts); }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-03-01 /// CHECKED BY: Zoey McDonald /// </summary> /// <param name="shiftID">The shiftID to query</param> /// <returns>A shift from the database</returns> public VolunteerShiftVM SelectShift(int shiftID) { //Declare variables var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_volunteer_shift"); VolunteerShiftVM shift = new VolunteerShiftVM(); //Setup cmd object cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; //Add parameter cmd.Parameters.Add("@VolunteerShiftID", SqlDbType.Int); cmd.Parameters["@VolunteerShiftID"].Value = shiftID; //Try to execute the query try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.Read()) { shift.VolunteerShiftID = reader.GetInt32(0); shift.ShiftDescription = reader.GetString(1); shift.ShiftTitle = reader.GetString(2); shift.VolunteerShiftDate = reader.GetDateTime(3); shift.ShiftStartTime = reader.GetTimeSpan(4); shift.ShiftEndTime = reader.GetTimeSpan(5); shift.Recurrance = reader.GetString(6); shift.IsSpecialEvent = reader.GetBoolean(7); shift.ShiftNotes = reader.GetString(8); shift.ScheduleID = reader.GetInt32(9); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(shift); }
/// <summary> /// Creator: Timothy Lickteig /// Created: 02/10/2020 /// Approver: Zoey McDonald /// /// Fake to update shift /// </summary> /// <remarks> /// Updater: N/A /// Updated: N/A /// Update: N/A /// </remarks> /// <param name="oldShift">Old shift to be replaced</param> /// <param name="newShift">New shift as replacement</param> /// <returns>The number of rows affected</returns> public int UpdateShift(VolunteerShiftVM oldShift, VolunteerShiftVM newShift) { int rows = 0; int index = 0; foreach (VolunteerShiftVM tempShift in _volunteerShifts) { if (tempShift.VolunteerShiftID == oldShift.VolunteerShiftID) { rows = 1; break; } index++; } if (rows == 1) { _volunteerShifts[index] = newShift; } return(rows); }
/// <summary> /// AUTHOR: Timothy Lickteig /// DATE: 2020-04-07 /// CHECKED BY: Zoey McDonald /// Event handler for the selection being changed /// </summary> private void DgShiftList_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { _shiftBeingEdited = null; }
/// <summary> /// Creator: Timothy Lickteig /// Created: 02/05/2020 /// Approver: Zoey McDonald /// /// Fake add shift method /// </summary> /// <remarks> /// Updater: N/A /// Updated: N/A /// Update: N/A /// </remarks> /// <param name="shift">Volunteer shift to be added</param> /// <returns>The number of rows affected</returns> public int AddShift(VolunteerShiftVM shift) { _volunteerShifts.Add(shift); return(1); }