示例#1
0
        /// <summary>
        /// Creator: Timothy Lickteig
        /// Created: 04/27/2020
        /// Approver: Zoey McDonald
        ///
        /// method for inserting foster appointments
        /// </summary>
        /// <remarks>
        /// Updater: N/A
        /// Updated: N/A
        /// Update: N/A
        /// </remarks>
        /// <param name="appointment">The record to insert</param>
        /// <returns>The number of rows affected</returns>
        public int InsertFosterAppointment(FosterAppointment appointment)
        {
            //Declare variables
            int rows = 0;
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_insert_foster_appointment");

            //Setup cmd object
            cmd.Connection  = conn;
            cmd.CommandType = CommandType.StoredProcedure;

            //Add parameters
            cmd.Parameters.AddWithValue("@VolunteerID", appointment.VolunteerID);
            cmd.Parameters.AddWithValue("@StartTime", appointment.StartTime);
            cmd.Parameters.AddWithValue("@EndTime", appointment.EndTime);
            cmd.Parameters.AddWithValue("@Description", appointment.Description);

            //Try to execute the query
            try
            {
                conn.Open();
                rows = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(rows);
        }
        /// <summary>
        /// Creator: Timothy Lickteig
        /// Created: 04/27/2020
        /// Approver: Zoey McDonald
        ///
        /// Submit button event handler
        /// </summary>
        /// <remarks>
        /// Updater: N/A
        /// Updated: N/A
        /// Update: N/A
        /// </remarks>
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            //Basic input validation
            if (null == cboVolunteerList.SelectedItem)
            {
                MessageBox.Show("Please select a volunteer");
            }
            else if (txtStartTime.Text == "")
            {
                MessageBox.Show("Please enter a valid start time");
            }
            else if (txtEndTime.Text == "")
            {
                MessageBox.Show("Please enter a valid end time");
            }
            else
            {
                try
                {
                    //Try to format the start and end times
                    DateTime startTime = DateTime.Parse(txtStartTime.Text);
                    DateTime endTime   = DateTime.Parse(txtEndTime.Text);

                    //Get the volunteer ID
                    int volunteerID = volManager.GetVolunteerByName(
                        volunteers[cboVolunteerList.SelectedIndex].FirstName,
                        volunteers[cboVolunteerList.SelectedIndex].LastName)
                                      [0].VolunteerID;

                    //Create a new foster appointment
                    FosterAppointment appointment = new FosterAppointment()
                    {
                        VolunteerID = volunteerID,
                        StartTime   = startTime,
                        EndTime     = endTime,
                        Description = txtDescription.Text
                    };

                    if (null == toEdit)
                    {
                        fosterManager.ScheduleFosterAppointment(appointment);
                        MessageBox.Show("Foster appointment scheduled");
                    }
                    else
                    {
                        fosterManager.UpdateFosterAppointment(toEdit, appointment);
                        MessageBox.Show("Appointment updated");
                    }
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#3
0
 /// <summary>
 /// Creator: Timothy Lickteig
 /// Created: 04/27/2020
 /// Approver: Zoey McDonald
 ///
 /// method for updating foster appointments
 /// </summary>
 /// <remarks>
 /// Updater: N/A
 /// Updated: N/A
 /// Update: N/A
 /// </remarks>
 /// <param name="oldAppt">The old appointment</param>
 /// <param name="oldAppt">The old appointment</param>
 /// <returns>Whether the operation was successful</returns>
 public bool UpdateFosterAppointment(FosterAppointment oldAppt, FosterAppointment newAppt)
 {
     try
     {
         return(1 == accessor.UpdateFosterAppointment(oldAppt, newAppt));
     }
     catch (Exception ex)
     {
         throw new ApplicationException("There was an error updating: " + ex.Message, ex);
     }
 }
        public void TestFosterAppointmentManagerCannotScheduleInvalidAppointmentTime()
        {
            FosterAppointment appointment = new FosterAppointment()
            {
                VolunteerID = 1000000,
                StartTime   = new DateTime(1, 1, 1, 14, 0, 0),
                EndTime     = new DateTime(1, 1, 1, 12, 0, 0),
            };

            manager.ScheduleFosterAppointment(appointment);
        }
        /// <summary>
        /// Creator: Timothy Lickteig
        /// Created: 04/27/2020
        /// Approver: Zoey McDonald
        ///
        /// Update appointment constructor
        /// </summary>
        /// <remarks>
        /// Updater: N/A
        /// Updated: N/A
        /// Update: N/A
        /// </remarks>
        public frmScheduleFosterAppointment(FosterAppointmentVM appointment)
        {
            InitializeComponent();

            populateVolunteerComboBox();

            toEdit = appointment;

            cboVolunteerList.SelectedItem = appointment.FirstName + " " + appointment.LastName;
            txtStartTime.Text             = appointment.StartTime.ToShortTimeString();
            txtEndTime.Text     = appointment.EndTime.ToShortTimeString();
            txtDescription.Text = appointment.Description;
        }
        public void TestFosterAppointmentManagerScheduleAppointment()
        {
            bool success = false;
            FosterAppointment appointment = new FosterAppointment()
            {
                VolunteerID = 1000000,
                StartTime   = new DateTime(1, 1, 1, 12, 0, 0),
                EndTime     = new DateTime(1, 1, 1, 14, 0, 0),
            };

            success = manager.ScheduleFosterAppointment(appointment);

            Assert.AreEqual(true, success);
        }
示例#7
0
        /// <summary>
        /// Creator: Timothy Lickteig
        /// Created: 04/27/2020
        /// Approver: Zoey McDonald
        ///
        /// method for scheduling foster appointments
        /// </summary>
        /// <remarks>
        /// Updater: N/A
        /// Updated: N/A
        /// Update: N/A
        /// </remarks>
        /// <param name="fosterAppointmentID">The ID of the record to delete</param>
        /// <returns>Whether the operation was successful</returns>
        public bool ScheduleFosterAppointment(FosterAppointment appointment)
        {
            if (appointment.EndTime < appointment.StartTime)
            {
                throw new ApplicationException("End time cannot be before start time");
            }

            try
            {
                return(1 ==
                       accessor.InsertFosterAppointment(appointment));
            }
            catch (Exception ex)
            {
                throw new ApplicationException("There was an error scheduling the appointment: " + ex.Message, ex);
            }
        }
        public void TestFosterAppointmentManagerUpdateFosterAppointment()
        {
            FosterAppointment oldAppt = new FosterAppointment()
            {
                FosterAppointmentID = 27,
                VolunteerID         = 1
            };
            FosterAppointment newAppt = new FosterAppointment()
            {
                FosterAppointmentID = 27,
                VolunteerID         = 2
            };

            manager.ScheduleFosterAppointment(oldAppt);
            bool result = manager.UpdateFosterAppointment(oldAppt, newAppt);

            Assert.IsTrue(result);
        }
示例#9
0
        /// <summary>
        /// Creator: Timothy Lickteig
        /// Created: 04/27/2020
        /// Approver: Zoey McDonald
        ///
        /// method for updating foster appointments
        /// </summary>
        /// <remarks>
        /// Updater: N/A
        /// Updated: N/A
        /// Update: N/A
        /// </remarks>
        /// <param name="oldAppt">The old record</param>
        /// <param name="newAppt">The new record</param>
        /// <returns>The number of rows affected</returns>
        public int UpdateFosterAppointment(FosterAppointment oldAppt, FosterAppointment newAppt)
        {
            //Declare variables
            int rows = 0;
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_update_foster_appointment");

            //Setup cmd object
            cmd.Connection  = conn;
            cmd.CommandType = CommandType.StoredProcedure;

            //Add parameters for old appt
            cmd.Parameters.AddWithValue("@FosterAppointmentID", oldAppt.FosterAppointmentID);
            cmd.Parameters.AddWithValue("@OldVolunteerID", oldAppt.VolunteerID);
            cmd.Parameters.AddWithValue("@OldStartTime", oldAppt.StartTime);
            cmd.Parameters.AddWithValue("@OldEndTime", oldAppt.EndTime);
            cmd.Parameters.AddWithValue("@OldDescription", oldAppt.Description);

            //Add params for new appt
            cmd.Parameters.AddWithValue("@NewVolunteerID", newAppt.VolunteerID);
            cmd.Parameters.AddWithValue("@NewStartTime", newAppt.StartTime.ToShortTimeString());
            cmd.Parameters.AddWithValue("@NewEndTime", newAppt.EndTime.ToShortTimeString());
            cmd.Parameters.AddWithValue("@NewDescription", newAppt.Description);

            //Try to excecute the query
            try
            {
                conn.Open();
                rows = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(rows);
        }
示例#10
0
        /// <summary>
        /// Creator: Timothy Lickteig
        /// Created: 04/27/2020
        /// Approver: Zoey McDonald
        ///
        /// method for updating foster appointments
        /// </summary>
        /// <remarks>
        /// Updater: N/A
        /// Updated: N/A
        /// Update: N/A
        /// </remarks>
        /// <param name="oldAppt">The old record</param>
        /// <param name="newAppt">The new record</param>
        /// <returns>The number of rows affected</returns>
        public int UpdateFosterAppointment(FosterAppointment oldAppt, FosterAppointment newAppt)
        {
            int rows  = 0;
            int index = 0;

            foreach (FosterAppointment tempAppt in appointments)
            {
                if (tempAppt.FosterAppointmentID == oldAppt.FosterAppointmentID)
                {
                    rows = 1;
                    break;
                }
                index++;
            }

            if (rows == 1)
            {
                appointments[index] = newAppt;
            }
            return(rows);
        }
示例#11
0
        /// <summary>
        /// Creator: Timothy Lickteig
        /// Created: 04/27/2020
        /// Approver: Zoey McDonald
        ///
        /// method for deleting foster appointments
        /// </summary>
        /// <remarks>
        /// Updater: N/A
        /// Updated: N/A
        /// Update: N/A
        /// </remarks>
        /// <param name="fosterAppointmentID">The ID of the record to delete</param>
        /// <returns>The number of rows affected</returns>
        public int DeleteFosterAppointment(int fosterAppointmentID)
        {
            int rows = 0;
            FosterAppointment toDelete = new FosterAppointment()
            {
                FosterAppointmentID = 0
            };

            foreach (FosterAppointment appt in appointments)
            {
                if (appt.FosterAppointmentID == fosterAppointmentID)
                {
                    toDelete = appt;
                }
            }

            if (toDelete.FosterAppointmentID != 0)
            {
                rows = 1;
                appointments.Remove(toDelete);
            }

            return(rows);
        }
示例#12
0
 /// <summary>
 /// Creator: Timothy Lickteig
 /// Created: 04/27/2020
 /// Approver: Zoey McDonald
 ///
 /// method for inserting foster appointments
 /// </summary>
 /// <remarks>
 /// Updater: N/A
 /// Updated: N/A
 /// Update: N/A
 /// </remarks>
 /// <param name="appointment">The record to insert</param>
 /// <returns>The number of rows affected</returns>
 public int InsertFosterAppointment(FosterAppointment appointment)
 {
     appointments.Add(appointment);
     return(1);
 }