/// <summary> /// Tyler Collins /// Created: 2015/02/11 /// DELETEs (Sets Boolean Active field to false) an ItemListing record in the Database using a Stored Procedure. /// </summary> /// <remarks> /// Tyler Collins /// Updated: 2015/02/26 /// Now up to date with most recent ItemListing object class /// </remarks> /// <param name="itemListingToDelete">Requires the ItemListing object which matches the record to be DELETED in the Database.</param> /// <returns>Returns the number of rows affected.</returns> public static int DeleteItemListing(ItemListing itemListingToDelete) { var conn = DatabaseConnection.GetDatabaseConnection(); string storedProcedure = "spDeleteItemListing"; var cmd = new SqlCommand(storedProcedure, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ItemListID", itemListingToDelete.ItemListID); cmd.Parameters.AddWithValue("@StartDate", itemListingToDelete.StartDate); cmd.Parameters.AddWithValue("@EndDate", itemListingToDelete.EndDate); cmd.Parameters.AddWithValue("@EventItemID", itemListingToDelete.EventID); cmd.Parameters.AddWithValue("@Price", itemListingToDelete.Price); cmd.Parameters.AddWithValue("@MaxNumGuests", itemListingToDelete.MaxNumGuests); cmd.Parameters.AddWithValue("@CurrentNumGuests", itemListingToDelete.CurrentNumGuests); cmd.Parameters.AddWithValue("@SupplierID", itemListingToDelete.SupplierID); int rowsAffected; try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return rowsAffected; }
/// <summary> /// Miguel Santana /// Created: 2015/04/05 /// Initializes the AddEditListing screen if it is edit or readonly /// Combined the Edit/Add screens /// </summary> /// <exception cref="WanderingTurtleException">Occurs making components readonly.</exception> public AddEditListing(ItemListing currentItemListing, bool readOnly = false) { CurrentItemListing = currentItemListing; Setup(); Title = "Editing Listing: " + CurrentItemListing.EventName; EventCbox.IsEnabled = false; SupplierCbox.IsEnabled = false; if (readOnly) { (Content as Panel).MakeReadOnly(BtnCancel); } }
public void ArchiveItemListing_ValidItemListing() { Setup(); SupplierManager myMan = new SupplierManager(); ProductManager otherMan = new ProductManager(); myMan.AddANewSupplier(testSupp, "Test"); modSupp = getSupplierListCompName(suppList); itemListingToTest.SupplierID = modSupp.SupplierID; otherMan.AddItemListing(itemListingToTest); itemListingToTest = getItemListingTestObject(itemList); itemListingToTest.CurrentNumGuests = 0; listResult actual = pMgr.ArchiveItemListing(itemListingToTest); Assert.AreEqual(listResult.Success, actual); Cleanup(); }
/// <summary> /// Hunter Lind /// Created: 2015/02/18 /// validates the user input and passes data to Business logic /// </summary> /// <remarks> /// Miguel Santana /// Updated: 2015/04/05 /// Combined Edit and Add screens /// </remarks> private async void AddItemListing() { if (!Validator()) return; ItemListing newListing = new ItemListing(); try { DateTime formStartDate = (DateTime)(DateStart.SelectedDate); DateTime formEndDate = (DateTime)(DateEnd.SelectedDate); DateTime formStartTime = (DateTime)(TpStartTime.Value); DateTime formEndTime = (DateTime)(TpEndTime.Value); //date is your existing Date object, time is the nullable DateTime object from your TimePicker newListing.StartDate = DateTime.Parse(string.Format("{0} {1}", formStartDate.ToShortDateString(), formStartTime.ToLongTimeString())); newListing.EndDate = DateTime.Parse(string.Format("{0} {1}", formEndDate.ToShortDateString(), formEndTime.ToLongTimeString())); if (newListing.StartDate > newListing.EndDate) { throw new WanderingTurtleException(this, "End Date must be after Start Date"); } newListing.EventID = ((Event)EventCbox.SelectedItem).EventItemID; newListing.SupplierID = ((Supplier)SupplierCbox.SelectedItem).SupplierID; newListing.Price = (decimal)(UdPrice.Value); newListing.MaxNumGuests = (int)(UdSeats.Value); } catch (Exception) { throw new WanderingTurtleException(this, "Please enter valid start and end dates."); } try { _productManager.AddItemListing(newListing); await this.ShowMessageDialog("Listing successfully added!"); DialogResult = true; Close(); } catch (Exception) { throw new WanderingTurtleException(this, "Error adding the Item Listing."); } }
/// <summary> /// Matt Lapka /// Created: 2015/02/14 /// Send a new ItemListing object to the Data Access Layer to be added to the database /// </summary> /// <param name="newItemListing">ItemListing object that contains the information to be added</param> /// <returns>An int reflecting the number of rows affected -- 1 if successful, 0 if not</returns> public listResult AddItemListing(ItemListing newItemListing) { try { if (ItemListingAccessor.AddItemListing(newItemListing) == 1) { DataCache._currentItemListingList = ItemListingAccessor.GetItemListingList(); DataCache._ItemListingListTime = DateTime.Now; DataCache._currentAllItemListingList = ItemListingAccessor.GetAllItemListingList(); DataCache._AllItemListingListTime = DateTime.Now; return listResult.Success; } return listResult.NotAdded; } catch (Exception) { return listResult.DatabaseError; } }
public void EditSetup() { SupplierManager mySupMan = new SupplierManager(); mySupMan.AddANewSupplier(testSupp, "Test"); modSupp = getSupplierListCompName(suppList); itemListingToEdit.SupplierID = modSupp.SupplierID; ItemListingAccessor.AddItemListing(itemListingToTest); itemListingToTest = getItemListingTestObject(itemList); itemListingToEdit.SupplierID = modSupp.SupplierID; }
public void EditItemListing_StartEndDateError() { Setup(); EditSetup(); itemListingToEdit.StartDate = new DateTime(2525, 5, 28, 10, 30, 0); itemListingToEdit.EndDate = new DateTime(2015, 5, 28, 8, 30, 0); itemListingToTest = itemListingToEdit; listResult actual = pMgr.EditItemListing(itemListingToEdit, itemListingToTest); Setup(); Cleanup(); Assert.AreEqual(listResult.StartEndDateError, actual); }
/// <summary> /// Matt Lapka /// Created 2015/04/16 /// Handles the updating of a listing. includes input validation, messaging and necessary session variables /// </summary> public void UpdateList() { string errorText = ""; lblError.Text = ""; int ItemListID = int.Parse(Request.Form["itemID"]); try { ItemListing myList = _listedLists.Where(ev => ev.ItemListID == ItemListID).FirstOrDefault(); ItemListing newList = new ItemListing(myList.ItemListID, myList.EventID, myList.SupplierID, myList.StartDate, myList.EndDate, myList.Price, myList.MaxNumGuests, myList.MinNumGuests, myList.CurrentNumGuests); DateTime start; DateTime end; if (DateTime.TryParse(Request.Form["start"], out start)) { newList.StartDate = start; } else { errorText = addError(errorText, "<li>Invalid Start Date. Please use the Calendar.</li>"); } if (DateTime.TryParse(Request.Form["end"], out end)) { newList.EndDate = end; } else { errorText = addError(errorText, "<li>Invalid End Date. Please use the Calendar.</li>"); } newList.Price = decimal.Parse(Request.Form["price"]); newList.MaxNumGuests = int.Parse(Request.Form["max"]); newList.MinNumGuests = 0; listResult result; if (!newList.Price.ToString("G").ValidateDecimal(minPrice)) { errorText = addError(errorText, "<li>Please add a valid, positive price</li>"); } if (!newList.StartDate.ToString().ValidateDateTime()) { errorText = addError(errorText, "<li>Please add a valid start date</li>"); } if (!newList.EndDate.ToString().ValidateDateTime(newList.StartDate)) { errorText = addError(errorText, "<li>Please add a valid end date after your start date</li>"); } if (!newList.MaxNumGuests.ToString().ValidateInt(newList.MinNumGuests)) { errorText = addError(errorText, "<li>Please add a valid max number of guests greater than zero.</li>"); } if (myList != null && errorText.Length == 0) { result = _myManager.EditItemListing(newList, myList); if (result == listResult.NoDateChange) { errorText = addError(errorText, "<li>You cannot change the date after guests have signed up!</li>"); } if (result == listResult.NoPriceChange) { errorText = addError(errorText, "<li>You cannot change the price after guests have signed up!</li>"); } if (result == listResult.MaxSmallerThanCurrent) { errorText = addError(errorText, "<li>You cannot change the Max Number of Guests to be lower than the number signed up!</li>"); } if (result == listResult.StartEndDateError) { errorText = addError(errorText, "<li>Start Date cannot be after End Date!</li>"); } if (result == listResult.DateInPast) { errorText = addError(errorText, "<li>Date cannot be in the past!</li>"); } if (errorText.Length > 0) { lblMessage.Text = "Please see the following errors: <ul>" + errorText + "</ul>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "showit", "showMessage()", true); } if (result==listResult.Success) { lblMessage.Text = "Event Updated!"; Page.ClientScript.RegisterStartupScript(this.GetType(), "showit", "showMessage()", true); } return; } else { lblMessage.Text = "Please see the following errors: <ul>" + errorText + "</ul>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "showit", "showMessage()", true); } } catch (Exception ex) { lblMessage.Text = "Event updating listing: " + ex.Message; Page.ClientScript.RegisterStartupScript(this.GetType(), "showit", "showMessage()", true); } }
/// <summary> /// Matt Lapka /// Created: 2015/02/14 /// Archive an ItemListing so it does not appear in active searches /// </summary> /// <param name="itemListToDelete">ItemListing object containing the information to delete</param> /// <returns>An int reflecting number of rows affected</returns> public listResult ArchiveItemListing(ItemListing itemListToDelete) { try { if (itemListToDelete.CurrentNumGuests == 0) { if (ItemListingAccessor.DeleteItemListing(itemListToDelete) == 1) { DataCache._currentItemListingList = ItemListingAccessor.GetItemListingList(); return listResult.Success; } } return listResult.NotChanged; } catch (Exception) { return listResult.DatabaseError; } }
/// <summary> /// Matt Lapka /// Created: 2015/02/14 /// Updates an ItemListing object by sending the object in its original form and the object with the updated information /// </summary> /// <param name="newItemList">The ItemListing object containing the new data</param> /// <param name="oldItemList">The ItemListing object containing the original data</param> /// <returns>An int reflecting the number of rows affected-- should be 1</returns> public listResult EditItemListing(ItemListing newItemLists, ItemListing oldItemLists) { if (newItemLists.CurrentNumGuests > 0) { if (newItemLists.StartDate != oldItemLists.StartDate || newItemLists.EndDate != oldItemLists.EndDate) { return listResult.NoDateChange; } if (newItemLists.MaxNumGuests < newItemLists.CurrentNumGuests) { return listResult.MaxSmallerThanCurrent; } if(newItemLists.Price != oldItemLists.Price) { return listResult.NoPriceChange; } } if (newItemLists.StartDate > newItemLists.EndDate) { return listResult.StartEndDateError; } if (newItemLists.StartDate < DateTime.Now) { return listResult.DateInPast; } try { if (ItemListingAccessor.UpdateItemListing(newItemLists, oldItemLists) == 1) { DataCache._currentItemListingList = ItemListingAccessor.GetItemListingList(); return listResult.Success; } return listResult.NotChanged; } catch (Exception) { return listResult.DatabaseError; } }
/// <summary> /// Tyler Collins /// Created: 2015/02/11 /// UPDATEs an ItemListing record in the Database with new data using a Stored Procedure. /// </summary> /// <remarks> /// Tyler Collins /// Updated: 2015/02/26 /// Now up to date with most recent ItemListing object class /// </remarks> /// <param name="newItemListing">Requires the ItemListing object containing the new information</param> /// <param name="oldItemListing">Requires the ItemListing object to replace that matches the record in the Database</param> /// <returns>Returns the number of rows affected.</returns> public static int UpdateItemListing(ItemListing newItemListing, ItemListing oldItemListing) { var conn = DatabaseConnection.GetDatabaseConnection(); string storedProcedure = "spUpdateItemListing"; var cmd = new SqlCommand(storedProcedure, conn); cmd.CommandType = CommandType.StoredProcedure; //newItemListing cmd.Parameters.AddWithValue("@StartDate", newItemListing.StartDate); cmd.Parameters.AddWithValue("@EndDate", newItemListing.EndDate); cmd.Parameters.AddWithValue("@EventItemID", newItemListing.EventID); cmd.Parameters.AddWithValue("@Price", newItemListing.Price); cmd.Parameters.AddWithValue("@MaxNumberOfGuests", newItemListing.MaxNumGuests); cmd.Parameters.AddWithValue("@CurrentNumberOfGuests", newItemListing.CurrentNumGuests); cmd.Parameters.AddWithValue("@SupplierID", newItemListing.SupplierID); //oldItemListing cmd.Parameters.AddWithValue("@ItemListID", oldItemListing.ItemListID); cmd.Parameters.AddWithValue("@originalStartDate", oldItemListing.StartDate); cmd.Parameters.AddWithValue("@originalEndDate", oldItemListing.EndDate); cmd.Parameters.AddWithValue("@originalEventItemID", oldItemListing.EventID); cmd.Parameters.AddWithValue("@originalPrice", oldItemListing.Price); cmd.Parameters.AddWithValue("@originalMaxNumberOfGuests", oldItemListing.MaxNumGuests); cmd.Parameters.AddWithValue("@originalCurrentNumberOfGuests", oldItemListing.CurrentNumGuests); cmd.Parameters.AddWithValue("@originalSupplierID", oldItemListing.SupplierID); int rowsAffected; try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return rowsAffected; }
/// <summary> /// Tyler Collins /// Created: 2015/02/10 /// Retrieves all ItemListing data from the Database using a Stored Procedure. /// Creates an ItemListing object from retrieved data. /// Adds ItemListing object to List of ItemListing objects. /// </summary> /// <remarks> /// Tyler Collins /// Updated: 2015/02/26 /// Now up to date with most recent ItemListing object class /// </remarks> /// <returns>List of Active ItemListing objects</returns> public static List<ItemListing> GetItemListingList() { List<ItemListing> itemListingList = new List<ItemListing>(); var conn = DatabaseConnection.GetDatabaseConnection(); string storedProcedure = "spSelectAllItemListings"; var cmd = new SqlCommand(storedProcedure, conn); cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { ItemListing currentItemListing = new ItemListing(); currentItemListing.StartDate = reader.GetDateTime(0); currentItemListing.EndDate = reader.GetDateTime(1); currentItemListing.ItemListID = reader.GetInt32(2); currentItemListing.EventID = reader.GetInt32(3); currentItemListing.Price = reader.GetDecimal(4); currentItemListing.SupplierID = reader.GetInt32(5); currentItemListing.CurrentNumGuests = reader.GetInt32(6); currentItemListing.MaxNumGuests = reader.GetInt32(7); currentItemListing.MinNumGuests = reader.GetInt32(8); currentItemListing.EventName = reader.GetString(9); currentItemListing.SupplierName = reader.GetString(10); if (currentItemListing.EndDate > DateTime.Now) { itemListingList.Add(currentItemListing); } } } else { var pokeball = new ApplicationException("Data Not Found!"); throw pokeball; } } catch (Exception) { throw; } finally { conn.Close(); } return itemListingList; }
/// <summary> /// Tyler Collins /// Created: 2015/02/10 /// Retrieves ItemListing data from the Database using a Stored Procedure. /// Creates an ItemListing object. /// </summary> /// <remarks> /// Tyler Collins /// Updated: 2015/02/26 /// Now up to date with most recent ItemListing object class /// </remarks> /// <param name="itemListID">Requires the ItemListID to SELECT the correct ItemListing record.</param> /// <returns>ItemListing object</returns> public static ItemListing GetItemListing(string itemListID) { ItemListing itemListingToRetrieve = new ItemListing(); SqlConnection conn = DatabaseConnection.GetDatabaseConnection(); string storedProcedure = "spSelectItemListing"; SqlCommand cmd = new SqlCommand(storedProcedure, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ItemListID", itemListID); try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); itemListingToRetrieve.StartDate = reader.GetDateTime(0); itemListingToRetrieve.EndDate = reader.GetDateTime(1); itemListingToRetrieve.ItemListID = reader.GetInt32(2); itemListingToRetrieve.EventID = reader.GetInt32(3); itemListingToRetrieve.Price = reader.GetDecimal(4); //Are we using QuanityOffered and ProductSize since these are Event Items? O.o itemListingToRetrieve.SupplierID = reader.GetInt32(5); itemListingToRetrieve.MaxNumGuests = reader.GetInt32(7); itemListingToRetrieve.MinNumGuests = reader.GetInt32(8); itemListingToRetrieve.CurrentNumGuests = reader.GetInt32(6); } else { var pokeball = new ApplicationException("Requested ID did not match any records."); throw pokeball; } } catch (Exception) { throw; } finally { conn.Close(); } return itemListingToRetrieve; }
/// <summary> /// Bryan Hurst /// Created: 4/23/2015 /// Method for deletion of test records created with the unit tests /// </summary> /// <param name="TestListing">The ItemListing added during testing -- to be deleted</param> /// <returns>Number of rows affected</returns> public static int DeleteItemListingTestItem(ItemListing TestListing) { var conn = DatabaseConnection.GetDatabaseConnection(); var cmdText = "spDeleteTestItemListing"; var cmd = new SqlCommand(cmdText, conn); var rowsAffected = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@EndDate", TestListing.EndDate); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new ApplicationException("Concurrency Violation"); } } catch (Exception) { throw; } finally { conn.Close(); } return rowsAffected; // needs to be rows affected }
/// <summary> /// Matt Lapka /// Created 2015/04/15 /// Saves new listing data, validates data and saves appropriate session vars /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { lblAddError.Text = ""; Event myEvent; Supplier mySupplier; try { myEvent = (Event)Session["Event"]; mySupplier = (Supplier)Session["user"]; } catch (Exception) { return; } string errors = ""; DateTime start; DateTime end; //validate form if (String.IsNullOrEmpty(Request.Form["startdate"])) { errors += "<li>You must enter a valid starting date!</li>"; } if (String.IsNullOrEmpty(Request.Form["enddate"])) { errors += "<li>You must enter a valid ending date!</li>"; } if (String.IsNullOrEmpty(Request.Form["price"]) || !Request.Form["price"].ValidateDouble(0.01)) { errors += "<li>You must enter a valid price!</li>"; } if (String.IsNullOrEmpty(Request.Form["tickets"]) || !Request.Form["tickets"].ValidateDouble(1)) { errors += "<li>You must enter a valid number of tickets available</li>"; } //make new item listing ItemListing myListing = new ItemListing(); if (DateTime.TryParse(Request.Form["startdate"], out start)) { myListing.StartDate = start; } else { errors += "<li>Invalid Date. Please use the Calendar.</li>"; } if (DateTime.TryParse(Request.Form["enddate"], out end)) { myListing.EndDate = end; } else { errors += "<li>Invalid Date. Please use the Calendar.</li>"; } //check date values if (start < DateTime.Now) { errors += "<li>You cannot list an event in the past.</li>"; } //if errors, stop and display them if (errors.Length > 0) { showError("Please see the following errors: <ul> " + errors + "</ul>"); return; } //add values to listing myListing.EventID = myEvent.EventItemID; myListing.Price = (decimal)double.Parse(Request.Form["price"]); myListing.MaxNumGuests = int.Parse(Request.Form["tickets"]); myListing.SupplierID = mySupplier.SupplierID; if (_myprodMan.AddItemListing(myListing) == listResult.Success) { addListing.Style.Add("display", "none"); theLists.Style.Add("display", "block"); showError("Event Listing Added!"); } }
public void DeleteItemListing_ValidItemListing() { int expected = 1; setup(); SupplierAccessor.AddSupplier(testSupp, "Test", "Password#1"); modSupp = getSupplierListCompName(suppList); itemListingToTest.SupplierID = modSupp.SupplierID; ItemListingAccessor.AddItemListing(itemListingToTest); itemListingToTest = getItemListingTestObject(itemList); int actual = ItemListingAccessor.DeleteItemListing(itemListingToTest); ItemListingAccessor.DeleteItemListingTestItem(itemListingToTest); testSupp.SupplierID = modSupp.SupplierID; testLog = sLA.RetrieveSupplierLogin("Password#1", "Test"); SupplierLoginAccessor.DeleteTestSupplierLogin(testLog); TestCleanupAccessor.DeleteTestSupplier(testSupp); Assert.AreEqual(expected, actual); }
/// <summary> /// Miguel Santana /// Created: 2015/04/15 /// opens the window with a selected item /// </summary> /// <param name="selectedItem"></param> /// <param name="readOnly"></param> private void OpenListing(ItemListing selectedItem = null, bool readOnly = false) { try { if (selectedItem == null) { if (new AddEditListing().ShowDialog() == false) return; RefreshData(); } else { if (new AddEditListing(selectedItem, readOnly).ShowDialog() == false) return; if (readOnly) return; RefreshData(); } } catch (Exception ex) { throw new WanderingTurtleException(this, ex); } }
/// <summary> /// Hunter Lind /// Created: 2015/02/10 /// Takes input from form to update the item listing /// </summary> /// <remarks> /// Pat Banks /// Updated: 2015/02/19 /// fields updated to reflect all required data /// Added spinners and calendar for user input restrictions /// </remarks> private async void UpdateItemListing() { try { DateTime formStartDate = (DateTime)(DateStart.SelectedDate); DateTime formEndDate = (DateTime)(DateEnd.SelectedDate); DateTime formStartTime = (DateTime)(TpStartTime.Value); DateTime formEndTime = (DateTime)(TpEndTime.Value); ItemListing newListing = new ItemListing { ItemListID = CurrentItemListing.ItemListID, EventID = CurrentItemListing.EventID, StartDate = DateTime.Parse(string.Format("{0} {1}", formStartDate.ToShortDateString(), formStartTime.ToLongTimeString())), EndDate = DateTime.Parse(string.Format("{0} {1}", formEndDate.ToShortDateString(), formEndTime.ToLongTimeString())), Price = (decimal)(UdPrice.Value), MaxNumGuests = (int)(UdSeats.Value), CurrentNumGuests = CurrentItemListing.CurrentNumGuests, SupplierID = CurrentItemListing.SupplierID }; var numRows = _productManager.EditItemListing(newListing, CurrentItemListing); if (numRows == listResult.Success) { await this.ShowMessageDialog("Item successfully changed."); DialogResult = true; Close(); } } catch (Exception ex) { throw new WanderingTurtleException(this, ex, "There was an error updating the Item Listing."); } }