public bool checkOutReservation(DateTime currentDate) { //update status status = "checked-out"; //add checkout activity log LoggedActivity logCheckout = new LoggedActivity(); logCheckout.logActivity(userID, 5, this.confirmatonID, currentDate, 17); //update customer rewards point balance Reward checkoutReward = new Reward(); checkoutReward.setRewardsPoints(userID, points, 17, currentDate); //update reservation price if (endDate != currentDate) { endDate = currentDate; Utilities recalc = new Utilities(); Room roomDetails = new Room(roomNumList[0], locationID); totalPrice = recalc.calculatePrice(((endDate - startDate).TotalDays), roomDetails.price); if ((endDate - startDate).TotalDays == 0) { //cancelation fee totalPrice = recalc.getMinCharge(); status = "cancelled"; } points = Convert.ToInt32(recalc.calculatePoints(((endDate - startDate).TotalDays))); amountDue = totalPrice - amountPaid; } //charge customer remaining balance on reservation try { PaymentRecord checkoutPayment = new PaymentRecord(); DBConnect checkinConn = new DBConnect(); MySqlCommand cmd = new MySqlCommand("SELECT ccNum from dbo.payment where confirmationID = @confirm"); cmd.Parameters.Add("@confirm", MySqlDbType.Int32).Value = confirmatonID; DBConnect ccNumConn = new DBConnect(); string ccNum = ccNumConn.stringScalar(cmd); ccNumConn.CloseConnection(); checkoutPayment.makePayment(userID, confirmatonID, amountDue, "Credit Card", false, currentDate, ccNum); amountPaid += amountDue; amountDue = 0; } catch (Exception ex) { MessageBox.Show("Unable to retrieve previous credit card number." + ex); } if (updateReservation(this)) { MessageBox.Show("Reservation with confirmation id " + confirmatonID + " was checked out."); return(true); } return(false); }
private void btnCheckinout_Click(object sender, EventArgs e) { Utilities getFileSettings = new Utilities(); if (resListDataGrid.SelectedRows.Count > 0) { { // begin checkin/checkout process int confirmationID = getConfirmationID(); Reservation resInfo = new Reservation(confirmationID); // check if reservation can be checked in/out if (resInfo.status == "cancelled") { displayError("This reservation has already been cancelled"); } else if (resInfo.status == "checked-out") { displayError("This reservation has already been completed"); } else if (resInfo.status == "checked-in") //checkout reservation { resInfo.checkOutReservation(currentDate); MessageBox.Show("User " + resInfo.userID + " was checked out"); } else if (resInfo.status == "upcoming") { if (resInfo.endDate < currentDate) { displayError("Reservation end date is before today. Please create a new reservation instead."); } else { resInfo.checkInReservation(currentDate); } } if (resInfo.amountDue < 0) { PaymentRecord issueRefund = new PaymentRecord(); issueRefund.makePayment(17, resInfo.confirmatonID, resInfo.amountDue, "refund", false, currentDate, "12345"); } // update reservation record //resInfo.updateReservation(resInfo); GetData(); //update table } } else { displayError("No reservation selected"); } }
private void btnSubmit_Click(object sender, EventArgs e) { bool proceed = true; if (cboxMethod.SelectedItem == null) { lblMethodError.Visible = true; lblMethodError.Text = "Error: You should select a payment method"; proceed = false;//don't proceed with payment process } else if (cboxMethod.SelectedItem.ToString() == "Credit Card") { if (String.IsNullOrEmpty(txtCardNum.Text)) { lblCardNumError.Visible = true; lblCardNumError.Text = "Error: Enter your credit card number"; proceed = false; } else if (long.TryParse(txtCardNum.Text.Replace(" ", string.Empty), out _) == false) { lblCardNumError.Visible = true; lblCardNumError.Text = "Error: Your credit card number is not numeric"; proceed = false; } else if (txtCardNum.Text.Length != 16) { lblCardNumError.Visible = true; lblCardNumError.Text = "Error: Invalid card number entry"; proceed = false; } } if (chkReward.Checked && userInfo.pointsBalance < 50) { lblrewardError.Text = "You don't have enough points"; lblrewardError.Visible = true; proceed = false; } if (!isReserving) { if (String.IsNullOrEmpty(txtPrice.Text)) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Enter your payment amount"; proceed = false; } else if (double.TryParse(txtPrice.Text, out _) == false) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Amount entered is not numeric"; proceed = false; } else if (double.Parse(txtPrice.Text) == 0) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Amount should not be zero"; proceed = false; } else if (double.Parse(txtPrice.Text) > resInfo.amountDue) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Amount exceeds your\nbalance due"; proceed = false; } if (chkReward.Checked && getInfo.checkIfRewardApplied(resInfo.confirmatonID)) { lblrewardError.Text = "Error: 10% is already applied to this reservation"; lblrewardError.Visible = true; proceed = false; } if (proceed) { if (chkReward.Checked) { resInfo.totalPrice *= 0.9; // resInfo.amountDue = resInfo.totalPrice - resInfo.amountPaid; // update reservation in database resInfo.updateReservation(resInfo); } ccNumber = txtCardNum.Text; PaymentRecord payment = new PaymentRecord(); if (payment.makePayment(userInfo.userID, resInfo.confirmatonID, double.Parse(txtPrice.Text), cboxMethod.SelectedItem.ToString(), this.appliedReward, currentDate, ccNumber)) { lblBalance.Text = "$" + (resInfo.amountDue);// - double.Parse(txtPrice.Text)); if (resInfo.amountDue != 0) { MessageBox.Show("Your payment was successful! Please be adviced that your card will be charged any remaining balance at check out."); } else { MessageBox.Show("Your payment was successful!"); } } this.Close(); Application.OpenForms["ReservationList"].Close(); } } else { if (String.IsNullOrEmpty(txtPrice.Text)) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Enter your payment amount"; proceed = false; } else if (double.TryParse(txtPrice.Text, out _) == false) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Amount entered is not numeric"; proceed = false; } else if (double.Parse(txtPrice.Text) == 0) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Amount should not be zero"; proceed = false; } else if (double.Parse(txtPrice.Text) < getInfo.getMinCharge()) { lblAmountError.Visible = true; lblAmountError.Text = "Error: You should pay the minimum charge"; proceed = false; } else if (double.Parse(txtPrice.Text) > resInfo.amountDue) { lblAmountError.Visible = true; lblAmountError.Text = "Error: Amount exceeds your\nbalance due"; proceed = false; } if (proceed) { if (chkReward.Checked) { resInfo.totalPrice *= 0.9; //resInfo.amountDue = resInfo.totalPrice - resInfo.amountPaid; resInfo.updateReservation(resInfo); } // update reservation in database ccNumber = txtCardNum.Text; PaymentRecord payment = new PaymentRecord(); if (payment.makePayment(userInfo.userID, resInfo.confirmatonID, double.Parse(txtPrice.Text), cboxMethod.SelectedItem.ToString(), this.appliedReward, currentDate, ccNumber)) { lblBalance.Text = "$" + resInfo.amountDue; if (resInfo.amountDue != 0) { MessageBox.Show("Your payment was successful! Please be adviced that your card will be charged any remaining balance at check out."); } else { MessageBox.Show("Your payment was successful!"); } } this.Close(); Application.OpenForms["CreateReservation"].Close(); Application.OpenForms["ReservationList"].Close(); } } }
// DESCRIPTION: Reservation cancellation process private void btnCancel_Click(object sender, EventArgs e) { Utilities getFileSettings = new Utilities(); if (resListDataGrid.SelectedRows.Count > 0) { string cancelMessage = "Please note, a " + getFileSettings.getCancelCharge() + " charge will apply to any reservation cancelled within " + getFileSettings.getCancelWindow() + " days of the start date. Continue with cancellation?"; var selectedOption = MessageBox.Show(cancelMessage, "Cancel reservation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (selectedOption == DialogResult.Yes) { { // begin cancellation process int confirmationID = getConfirmationID(); Reservation resInfo = new Reservation(confirmationID); // check if reservation can be cancelled if (resInfo.status == "cancelled") { displayError("This reservation has already been cancelled"); } else if (resInfo.status == "checked-out") { displayError("This reservation has already been completed"); } else if (resInfo.status == "checked-in") { // update reservation info Utilities recalc = new Utilities(); DateTime newEndDate = currentDate; Room roomDetails = new Room(resInfo.roomNumList[0], resInfo.locationID); resInfo.totalPrice = recalc.calculatePrice((newEndDate - resInfo.endDate).TotalDays, roomDetails.price); resInfo.points = Convert.ToInt32(recalc.calculatePoints((newEndDate - resInfo.endDate).TotalDays)); resInfo.amountDue = resInfo.totalPrice - resInfo.amountPaid; resInfo.status = "checked-out"; } else if (resInfo.status == "upcoming") { // if reservation is within 3 days if (((resInfo.startDate - currentDate).TotalDays) <= getFileSettings.getCancelWindow()) { resInfo.totalPrice = (double)getFileSettings.getCancelCharge(); } else { resInfo.totalPrice = 0; } resInfo.status = "cancelled"; resInfo.points = 0; resInfo.amountDue = resInfo.totalPrice - resInfo.amountPaid; } if (resInfo.amountDue < 0) { PaymentRecord issueRefund = new PaymentRecord(); issueRefund.makePayment(17, resInfo.confirmatonID, resInfo.amountDue, "refund", false, currentDate, "12345"); } // update reservation record resInfo.updateReservation(resInfo); // log cancellation if (userInfo.isCustomer) { resInfo.logCancellation(userInfo.userID, userInfo.userID, currentDate); } else { resInfo.logCancellation(userInfo.userID, resUserID, currentDate); } GetData(); } } } else { displayError("No reservation selected"); } }