// This selects a list of Person Schedule view models from the database. They are selected based upon the // supplied PersonID. public List <PersonScheduleVM> SelectSchedulesByPersonID(int personID) { List <PersonScheduleVM> personSchedules = new List <PersonScheduleVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_schedule_by_person_id", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PersonID", personID); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var personSchedule = new PersonScheduleVM(); personSchedule.PersonID = reader.GetInt32(0); personSchedule.ScheduleID = reader.GetInt32(1); personSchedule.FirstName = reader.GetString(2); personSchedule.LastName = reader.GetString(3); personSchedule.Type = reader.GetString(4); personSchedule.Start = reader.GetDateTime(5); personSchedule.End = reader.GetDateTime(6); personSchedule.ActivityName = reader.GetString(7); personSchedule.Description = reader.GetString(8); personSchedule.ActivityID = reader.GetInt32(9); personSchedule.LocationName = reader.GetString(10); personSchedule.Address1 = reader.GetString(11); personSchedule.Address2 = reader.GetString(12); personSchedule.City = reader.GetString(13); personSchedule.State = reader.GetString(14); personSchedule.Zip = reader.GetString(15); personSchedule.ActivityTypeID = reader.GetString(16); personSchedules.Add(personSchedule); } } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(personSchedules); }
// This selects a list of Person Schedule view models from the database. They are selected based upon and activityID, // scheduleType, and if they are active. public List <PersonScheduleVM> SelectUserScheduleByActivityID(int activityID, string scheduleType, bool active) { List <PersonScheduleVM> personSchedules = new List <PersonScheduleVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_user_schedule_by_activity_id_and_type", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ActivityID", activityID); cmd.Parameters.AddWithValue("@Type", scheduleType); cmd.Parameters.AddWithValue("@Active", active); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var personSchedule = new PersonScheduleVM(); personSchedule.PersonID = reader.GetInt32(0); personSchedule.FirstName = reader.GetString(1); personSchedule.LastName = reader.GetString(2); personSchedule.ScheduleID = reader.GetInt32(3); personSchedule.ActivityID = reader.GetInt32(4); personSchedule.Start = reader.GetDateTime(5); personSchedule.End = reader.GetDateTime(6); personSchedule.Type = reader.GetString(7); personSchedules.Add(personSchedule); } } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(personSchedules); }
// This event handler fires when the selected item in the dgSchedule data grid is changed. It then // populates the various text boxes with their respective information. private void DgSchedule_SelectionChanged(object sender, SelectionChangedEventArgs e) { _schedule = (PersonScheduleVM)dgSchedule.SelectedItem; txtActivityName.Text = _schedule.ActivityName; txtScheduleType.Text = _schedule.Type; txtStartTime.Text = _schedule.Start.ToShortDateString() + _schedule.Start.ToShortTimeString(); txtEndTime.Text = _schedule.End.ToShortDateString() + _schedule.End.ToShortTimeString(); txtActivityType.Text = _schedule.ActivityTypeID; txtAddress1.Text = _schedule.Address1; txtAddress2.Text = _schedule.Address2; txtCity.Text = _schedule.City; txtLocationName.Text = _schedule.LocationName; txtState.Text = _schedule.State; txtZip.Text = _schedule.Zip; txtFirstName.Text = _schedule.FirstName; txtLastName.Text = _schedule.LastName; txtDescription.Text = _schedule.Description; }