/// <summary> /// The event is triggered when the insert button is clicked. It will instantiate a new DVDCopy and add /// it to the list corresponding to the DVD object. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnInsert_Click(object sender, EventArgs e) { // Checks whether the barcode is not empty, and has a valid barcode. if (this.txtBarcode.Text != String.Empty && this.validateBarcode(this.txtBarcode.Text)) { // Fetches the current DVD object. DVD dvd = DVD.Fetch(Convert.ToInt32(this.dvdID.Value)); if (dvd != null) // If the DVD object exists. // It will instantiate a new DVDCopy object based on the insert record fields. It will // then add the object into the copies list contained inside the DVD object. //dvd.copies.Add(new DVDCopy(dvd, this.txtBarcode.Text, this.chkAvailability.Checked)); { if (dvd.AddCopy(this.txtBarcode.Text, ((this.chkAvailability.Checked) ? DVDCopy.Status.AVAILABLE : DVDCopy.Status.UNAVAILABLE))) { // Shows a friendly message letting them know it has been added. this.lblMessage.Text = "A new copy has been added."; this.lblMessage.ForeColor = System.Drawing.Color.Green; this.lblMessage.Visible = true; // Reloads the DVDCopy DataGridView to reflect the changes. RefreshCopies(); } else { // Shows a message stating the barcode is invalid. this.lblMessage.Text = "Barcode already exists."; this.lblMessage.ForeColor = System.Drawing.Color.Red; this.lblMessage.Visible = true; } } } // Sets the input barcode textbox to empty. this.txtBarcode.Text = String.Empty; // Sets the input availability checkbox back to true. this.chkAvailability.Checked = true; }
/// <summary> /// The addCopy method is used to add a DVDCopy object that was selected in the DVDCopy dropdown box to /// either the rentals or purchases dictionary (depending on the received boolean). It will then reload /// the copies dropdown box to reflect the changes. /// </summary> /// <param name="isRental"></param> private void addCopy(Boolean isRental) { // If a copy is selected. if (this.copies.SelectedValue != String.Empty) { // It will fetch the DVD that the copy belongs to. DVD dvd = DVD.Fetch(Convert.ToInt32(this.dvds.SelectedValue.ToString())); // It will then fetch the copy from the DVD (by passing in the barcode). DVDCopy copy = DVDCopy.FetchCopy(Convert.ToInt32(this.copies.SelectedItem.Value)); // If the copy doesn't already exist in both dictionaries if (!(this.lstRentals.ContainsKey(this.copies.SelectedItem.Text) || this.lstPurchases.ContainsKey(this.copies.SelectedItem.Text))) { // Then it will add it to either the rentals or purchases if (isRental) { this.lstRentals.Add(copy.barcode, copy); } else { this.lstPurchases.Add(copy.barcode, copy); } } // Reloads the copies. this.loadCopies(); } // Reshows the creditcard payment option. this.checkPaymentType(); // Loads the list boxes (with the new copy included). this.loadListBoxes(); }
/// <summary> /// The loadCopies method is used to show another dropdown box containing the DVDCopy objects that belong to the selected DVD. /// It will check whether a DVD is selected, and if so; it will add available copies into the dropdown box. /// </summary> private void loadCopies() { // Clears the copies dropdown list. this.copies.Items.Clear(); // If a DVD is selected if (this.dvds.SelectedValue != String.Empty) { this.dvdCopies.Visible = true; // shows the dropdown box // Fetches the DVD object relating to the selected item DVD dvd = DVD.Fetch(Convert.ToInt32(this.dvds.SelectedValue.ToString())); // Grabs the DVD copies belonging to that object List <DVDCopy> list = dvd.copies; foreach (DVDCopy copy in list) // Iterates for each copy // If the copy is available & doesn't already exist on the form { if (copy.isAvailable && (!this.copyExists(copy))) { // Adds the copy to the dropdown box. this.copies.Items.Add(new ListItem(copy.barcode, copy.copyID.ToString())); } } // If the copies dropdown list has no items it will // reload the DVDs, which will hide the copies. if (this.copies.Items.Count == 0) { this.loadDVDS(); } } else { // Otherwise, if no DVD is selected it will hide the copies. this.dvdCopies.Visible = false; } }
/// <summary> /// The page load event will Fetch the object which corresponds to the unqiue key received, /// and invoke the ShowRecord method on the form usercontrol passing the object as an argument. /// It will then set the visibility of the form to true. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { DVDEzy.CheckSession(); try { DVD dvd = DVD.Fetch(Convert.ToInt32(Request.QueryString["view"])); if (dvd != null) { dvdForm.ShowRecord(dvd); dvdForm.Visible = true; } } catch (Exception ex) {} }
/// <summary> /// The RefreshCards method initialises the datasource of the DataGridView to point to the copies list contained /// in the viewed DVD object. It binds it to the object list. /// </summary> private void RefreshCopies() { // Fetches the DVD object DVD dvd = DVD.Fetch(Convert.ToInt32(this.dvdID.Value)); if (dvd != null) { // Sets the source & binds it to the list. this.gridCopies.DataSource = dvd.copies; this.gridCopies.DataBind(); } }
/// <summary> /// The event is triggered when the save button is pressed. It will either fetch the DVD (in view mode) or create a new one (add mode). /// It will set the properties of the object to the contents of the form. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { // Fetches or creates a new DVD object. DVD dvd = ((this.dvdID.Value != String.Empty) ? DVD.Fetch(Convert.ToInt32(this.dvdID.Value)) : new DVD()); // Sets the properties to the contents of the form. dvd.title = this.title.Text; dvd.director = this.director.Text; dvd.yearReleased = Convert.ToInt32(this.yearReleased.Text.ToString()); dvd.salePrice = Convert.ToDouble(this.salePrice.Text.ToString()); dvd.rentalPrice = Convert.ToDouble(this.rentalPrice.Text.ToString()); dvd.Save(); // Saves the object. It will ensure it has been added to the list. this.dvdID.Value = dvd.dvdID.ToString(); // Shows a friendly message stating it has been saved. this.lblMessage.Text = "The record has been saved."; this.lblMessage.ForeColor = System.Drawing.Color.Green; this.lblMessage.Visible = true; // Refreshes the DVDCopy DataGridView. this.RefreshCopies(); this.chkAvailability.Checked = true; }