/// <summary> /// NAME: Josh Jackson /// DATE: 04/26/2020 /// Checked By: /// This is a data access method create a foster record /// </summary> /// <remarks> /// UPDATED BY: /// UPDATE DATE: /// WHAT WAS CHANGED: /// </remarks> /// <param name="volunteer"></param> /// <param name="newFoster"></param> /// <returns></returns> public int CreateFoster(Volunteer volunteer, Foster newFoster) { int fosterID = 0; var conn = DBConnection.GetConnection(); var cmd1 = new SqlCommand("sp_insert_foster", conn); cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.AddWithValue("@VolunteerID", volunteer.VolunteerID); cmd1.Parameters.AddWithValue("@AddressLine1", newFoster.AddressLineOne); cmd1.Parameters.AddWithValue("@AddressLine2", newFoster.AddressLineTwo); cmd1.Parameters.AddWithValue("@City", newFoster.City); cmd1.Parameters.AddWithValue("@State", newFoster.State); cmd1.Parameters.AddWithValue("@Zipcode", newFoster.Zip); try { conn.Open(); fosterID = Convert.ToInt32(cmd1.ExecuteScalar()); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(fosterID); }
/// <summary> /// NAME: Josh Jackson /// DATE: 02/07/2020 /// Checked By: Zoey M /// This method populates the lstUnassignedSKills with the skills that a volunteer could have /// </summary> /// <remarks> /// UPDATED BY: /// UPDATE DATE: /// WHAT WAS CHANGED: /// </remarks> private void populateSkills() { try { var vSkills = _volunteerManager.GetVolunteerSkillsByID(_volunteer.VolunteerID); lstAssignedSkills.ItemsSource = vSkills; var skills = _volunteerManager.GetAllSkills(); foreach (string r in vSkills) { skills.Remove(r); } lstUnassignedSkills.ItemsSource = skills; if (lstAssignedSkills.Items.Contains("Foster")) { rowSkills.Height = new GridLength(115); rowFoster.Height = new GridLength(260); gridFoster.Visibility = Visibility.Visible; int volunteerID = _volunteer.VolunteerID; _foster = _volunteerManager.GetFosterDetailsByVolunteerID(volunteerID); } else { rowSkills.Height = new GridLength(375); rowFoster.Height = new GridLength(0); gridFoster.Visibility = Visibility.Hidden; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message); } }
protected void btnSubmit_Click(object sender, EventArgs e) { // Session["UserID"] = 1; if (IsValid) { try { Foster us = new Foster(); us.UserID = Int32.Parse(Session["UserID"].ToString()); us.FosterAdd = TbFosterAdd.Text.Trim(); us.FosterTime = DateTime.Parse(TbFosterTime.Text.Trim()); us.FosterUserPhone = TbFosterUserPhone.Text.Trim(); us.FosterStatus = TbFosterStatus.Text.Trim(); us.FosterPetPhoto = TbFosterPetPhoto.Text.Trim(); us.FosterContent = TbFosterContent.Text.Trim(); int i = FosterService.insert(us); if (i >= 1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('提交成功!');location='zhaoling.aspx'</script>"); } } catch (Exception ex) { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('提交失败!失败原因如下:" + ex.Message + "');</script>"); Response.Write("错误原因:" + ex); } } }
/// <summary> /// NAME: Josh Jackson /// DATE: 04/26/2020 /// Checked By: /// This is a data access method gets a foster record by volunteer id /// </summary> /// <remarks> /// UPDATED BY: /// UPDATE DATE: /// WHAT WAS CHANGED: /// </remarks> /// <param name="volunteerID"></param> /// <returns></returns> public Foster GetFosterDetailsByVolunteerID(int volunteerID) { Foster foster = null; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_get_foster_details_by_volunteer_id"); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@VolunteerID", SqlDbType.Int); cmd.Parameters["@VolunteerID"].Value = volunteerID; try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { foster = new Foster(); foster.FosterID = reader.GetInt32(0); foster.VolunteerID = reader.GetInt32(1); foster.AddressLineOne = reader.GetString(2); foster.AddressLineTwo = reader.GetString(3); foster.City = reader.GetString(4); foster.State = reader.GetString(5); foster.Zip = reader.GetString(6); } reader.Close(); } catch (Exception ex) { throw ex; } return(foster); }
public void TestUpdateFoster() { // arrange Foster oldFoster = new Foster() { FosterID = 1, VolunteerID = 3, AddressLineOne = "22 Hell St", AddressLineTwo = "#666", City = "Cedar Rapids", State = "IA", Zip = "52403" }; Foster newFoster = new Foster() { FosterID = 1, VolunteerID = 3, AddressLineOne = "221 Hell St", AddressLineTwo = "#666", City = "Cedar Rapids", State = "IA", Zip = "52403" }; IVolunteerManager _volunteerManager = new VolunteerManager(_volunteerAccessor); //Act bool expectedResults = true; bool actualResult = _volunteerManager.UpdateFoster(oldFoster, newFoster); //Assert Assert.AreEqual(actualResult, expectedResults); }
/// <summary> /// NAME: Josh Jackson /// DATE: 04/26/2020 /// Checked By: /// this method passes the foster record data to be updated in the db from the presentation layer /// </summary> /// <remarks> /// UPDATED BY: /// UPDATE DATE: /// WHAT WAS CHANGED: /// <param name="foster"></param> /// <param name="newFoster"></param> /// </remarks> public bool UpdateFoster(Foster foster, Foster newFoster) { bool rows = true; try { rows = _volunteerAccessor.UpdateFoster(foster, newFoster) > 0; } catch (Exception ex) { throw ex; } return(rows); }
/// <summary> /// NAME: Josh Jackson /// DATE: 04/26/2020 /// Checked By: /// this method creates a foster record for a volunteer /// </summary> /// <remarks> /// UPDATED BY: /// UPDATE DATE: /// WHAT WAS CHANGED: /// <param name="volunteer"></param> /// <param name="newFoster"></param> /// </remarks> public bool CreateFoster(Volunteer volunteer, Foster newFoster) { bool rows = true; try { rows = _volunteerAccessor.CreateFoster(volunteer, newFoster) > 0; } catch (Exception ex) { throw ex; } return(rows); }
/// <summary> /// NAME: Josh Jackson /// DATE: 04/26/2020 /// Checked By: /// /// This is a fake method used for testing updating a volunteer /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="foster"></param> /// <param name="newFoster"></param> /// <returns></returns> public int UpdateFoster(Foster foster, Foster newFoster) { Foster oldFoster = foster; try { oldFoster = newFoster; return(1); } catch (Exception ex) { return(0); throw ex; } }
public int insert(Foster fos) { string sql = "insert into Foster values(@FosterID ,@UserID,@FosterAdd ,@FosterTime,@FosterUserPhone,@FosterContent,@FosterStatus,@FosterPetPhoto)"; SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@FosterID", fos.FosterID), new SqlParameter("@UserID", fos.UserID), new SqlParameter("@UserAdd", fos.FosterAdd), new SqlParameter("@FosterTime", fos.FosterTime), new SqlParameter("@UserPhone", fos.FosterUserPhone), new SqlParameter("@FContent", fos.FosterContent), new SqlParameter("@FStatus", fos.FosterStatus), new SqlParameter("@PetPhoto", fos.FosterPetPhoto), }; return (DBHelper.GetExcuteNonQuery(sql, sp)); }
/// <summary> /// NAME: Josh Jackson /// DATE: 04/26/2020 /// Checked By: /// this method passes the foster record data to be updated in the db from the logic layer /// </summary> /// <remarks> /// UPDATED BY: /// UPDATE DATE: /// WHAT WAS CHANGED: /// <param name="foster"></param> /// <param name="newFoster"></param> /// </remarks> public int UpdateFoster(Foster foster, Foster newFoster) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_foster", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FosterID", foster.FosterID); cmd.Parameters.AddWithValue("@NewAdd1", newFoster.AddressLineOne); cmd.Parameters.AddWithValue("@NewAdd2", newFoster.AddressLineTwo); cmd.Parameters.AddWithValue("@NewCity", newFoster.City); cmd.Parameters.AddWithValue("@NewState", newFoster.State); cmd.Parameters.AddWithValue("@NewZip", newFoster.Zip); cmd.Parameters.AddWithValue("@OldAdd1", foster.AddressLineOne); cmd.Parameters.AddWithValue("@OldAdd2", foster.AddressLineTwo); cmd.Parameters.AddWithValue("@OldCity", foster.City); cmd.Parameters.AddWithValue("@OldState", foster.State); cmd.Parameters.AddWithValue("@OldZip", foster.Zip); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// NAME: Josh Jackson /// DATE: 02/07/2020 /// Checked By: Zoey M /// This validates the data entered into the Volunteer Record fields and passes the values to be added to the database upon pressing /// the save button /// </summary> /// <remarks> /// UPDATED BY: Josh J /// UPDATE DATE: 2020/03/28 /// WHAT WAS CHANGED: Changed how the save button interacts with the Pages. /// </remarks> private void btnSave_Click(object sender, RoutedEventArgs e) { if (txtFirstName.Text == "") { MessageBox.Show("You must enter a first name."); txtFirstName.Focus(); return; } if (txtLastName.Text == "") { MessageBox.Show("You must enter a last name."); txtLastName.Focus(); return; } if (txtPhoneNumber.Text.ToString().Length > 12) { MessageBox.Show("You must enter a valid phone number."); txtPhoneNumber.Focus(); return; } if (txtEmailAddress.Text.ToString().Length < 7) { MessageBox.Show("You must enter a valid email address."); txtEmailAddress.Focus(); return; } if (!(txtEmailAddress.Text.ToString().Contains("@") && txtEmailAddress.Text.ToString().Contains("."))) { MessageBox.Show("You must enter a valid email address."); txtEmailAddress.Focus(); return; } if ((txtNotes.Text.Length >= 2000)) { MessageBox.Show("Character limit reached for field: Notes - Try again"); txtNotes.Focus(); return; } if (gridFoster.Visibility == Visibility.Visible) { if (txtAdd1.Text.Length > 500) { MessageBox.Show("Character limit reached for field: Address Line One - Try again"); txtAdd1.Focus(); return; } if (txtAdd1.Text.Length < 5) { MessageBox.Show("Insufficient number of characters for field: Address Line One - Try again"); txtAdd1.Focus(); return; } if (txtAdd2.Text.Length > 100) { MessageBox.Show("Character limit reached for field: Address Line Two - Try again"); txtAdd2.Focus(); return; } if (txtCity.Text.Length > 200) { MessageBox.Show("Character limit reached for field: City - Try again"); txtCity.Focus(); return; } if (txtCity.Text.Length < 3) { MessageBox.Show("Insufficient number of characters for field: City - Try again"); txtCity.Focus(); return; } if (txtState.Text.Length != 2) { MessageBox.Show("Incorrect format for field: State - Hint: Try abbreviating (Al, IA, etc.)"); txtState.Focus(); return; } if (txtZip.Text.Length != 5) { MessageBox.Show("Incorrect format for field: Zipcode - Try again"); txtZip.Focus(); return; } } Foster newFoster = null; Volunteer newVolunteer = new Volunteer() { FirstName = txtFirstName.Text.ToString(), LastName = txtLastName.Text.ToString(), PhoneNumber = txtPhoneNumber.Text.ToString(), Email = txtEmailAddress.Text.ToString(), OtherNotes = txtNotes.Text.ToString(), Active = (bool)chkActive.IsChecked }; if (gridFoster.Visibility == Visibility.Visible) { newFoster = new Foster() { VolunteerID = _volunteer.VolunteerID, AddressLineOne = txtAdd1.Text.ToString(), AddressLineTwo = txtAdd2.Text.ToString(), City = txtCity.Text.ToString(), State = txtState.Text.ToString(), Zip = txtZip.Text.ToString(), }; } if (_addMode) { try { if (_volunteerManager.AddVolunteer(newVolunteer)) { this.NavigationService?.Navigate(new ViewVolunteers()); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message); } } else { try { _volunteerManager.UpdateVolunteer(_volunteer, newVolunteer); if (gridFoster.Visibility == Visibility.Visible) { if (_foster == null) { _volunteerManager.CreateFoster(_volunteer, newFoster); } else { _volunteerManager.UpdateFoster(_foster, newFoster); } } this.NavigationService?.Navigate(new ViewVolunteers()); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message); } } }
public static int insert(Foster fos) { return(IFoster.insert(fos)); }
/// <summary> /// NAME: Josh Jackson /// DATE: 04/26/2020 /// Checked By: /// /// This is a data access method used for testing inserting a foster /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="volunteer"></param> /// <param name="newFoster"></param> /// <returns></returns> public int CreateFoster(Volunteer volunteer, Foster newFoster) { newFoster.VolunteerID = volunteer.VolunteerID; fosters.Add(newFoster); return(1); }