/// <summary> /// This method validate the data imput, create a new gift card, /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { // Validate data input Boolean Voyage = UtilityClass.isValidInt(txtVoyage, lblVoyage, "*", "Insert digits!"); Boolean Saildate = UtilityClass.isValidDate(txtSilingDate, lblSailingDate, "*", "Format (MM/DD/YYYY)!"); Boolean Deliverydate = UtilityClass.isValidDate(txtDeliveryDate, lblDeliveryDate, "*", "Format (MM/DD/YYYY)!"); Boolean DeliverydateChronolog = false; if (Saildate && Deliverydate) DeliverydateChronolog = UtilityClass.isChronologicalDate(txtSilingDate, txtDeliveryDate, lblDeliveryDate, "Chronological error!"); Boolean Cabin = UtilityClass.isValidInt(txtStateroom, lblStateroom, "*", "Insert digits!"); Boolean Amenity = UtilityClass.isValidText(ddlAmenity, lblAmenity, "*"); Boolean Qty = UtilityClass.isValidInt(txtQuantity, lblQuantity, "*", "Insert digits greater than zero!"); Boolean DeliveryType = UtilityClass.isValidText(ddlDeliverTo, lblDelivery, "*"); Boolean dinning = false; Boolean seating = false; Boolean table = false; if (DeliveryType && ddlDeliverTo.SelectedItem.Text == "Dinning room") { dinning = UtilityClass.isValidText(txtDiningRoom, lblDiningRoom, "*", null); seating = UtilityClass.isValidText(txtSeating, lblSeating, "*", null); table = UtilityClass.isValidText(txtTable, lblTable, "*", null); }// end if Boolean typeflag = false; if((DeliveryType && ddlDeliverTo.SelectedItem.Text.CompareTo("Dinning room")!=0) || (dinning && seating && table )) { typeflag = true; }// end if Boolean Compliments = UtilityClass.isValidText(txtCompliments, lblCompliments, "*", "Insert leters or digits!"); Boolean Message = UtilityClass.isValidText(txtMessage, lblMessage, "*", "Insert leters or digits!"); // if all the input are correct create a new GiftCard and add it to the list. if (Voyage && Saildate && Deliverydate && DeliverydateChronolog && Cabin && Amenity && Qty && typeflag && Compliments && Message) { GiftCard newBe = new GiftCard(); // create a new object GiftCard int stateroom = int.Parse(txtStateroom.Text.Trim()); List<Gift_Cards.GuestService.GuestView> passenger = UtilityClass.TryGetGuestInfo(stateroom, lblCreated); // 9219, if (passenger == null) { lblStateroom.Text = "The stateroom does not exist!"; } else { newBe.Ship = UtilityClass.shipName.Trim(); newBe.Voyage = txtVoyage.Text.Trim(); newBe.Saildate = txtSilingDate.Text.Trim(); newBe.Deliverydate = txtDeliveryDate.Text.Trim(); newBe.Amenity = ddlAmenity.SelectedItem.Text.Trim(); newBe.Cabin = txtStateroom.Text.Trim(); //find the amenity type and update it in the GiftCard newBe.Type = Amenities.Find((t) => t.amenity == newBe.Amenity).type; newBe.Qty = int.Parse(txtQuantity.Text); newBe.Compliments = txtCompliments.Text; newBe.Message = txtMessage.Text; newBe.DeliveryType = ddlDeliverTo.SelectedItem.Text; newBe.Cabin = txtStateroom.Text; if (dinning && seating && table) { newBe.DRoom = txtDiningRoom.Text; newBe.Table = txtTable.Text; newBe.Seating = txtSeating.Text; }// end if // set the names of the passengers newBe.setNamens(passenger); this.Cards.Add(newBe);// add the new GiftCard to the list //Apend the new gift card to the end of the file if (this.Cards.Count == 1) { UtilityClass.overrideGiftCardFile(this.Cards); } else { try { //Apend the new gift card to the end of the file var filePath = UtilityClass.GetFilePath(UtilityClass.giftcardFile); using (StreamWriter sw = File.AppendText(filePath)) { sw.WriteLine(newBe.toStringToFile()); sw.Close(); sw.Dispose(); }// end using } catch (Exception ex) { UtilityClass.ReportLog(ex.Message); }//end catch } //Create a list with the new GiftCard and send it to print. List<GiftCard> toPrint = new List<GiftCard>(); toPrint.Add(this.Cards[this.Cards.Count - 1]); Session["newGiftCard"] = toPrint; lblCreated.Text = "Gift Card succesfully created!"; //Set to unvisible Dinning Room, Table, and Seating. this.toUnvisible(); } // end if (newBe != null) }// end if(Voyage && Saildate && ------ ) }