Beispiel #1
0
    public string checkEndDate(string rentalID)
    {
        Extension itemExtension = ExtensionDB.getLastExtensionofRental(rentalID);
        Rental    itemRental    = RentalDB.getRentalbyID(rentalID);


        if (itemExtension.ExtensionID == null)
        {
            return(String.Format("{0:MM/dd/yy}", itemRental.StartDate) + " - " + String.Format("{0:MM/dd/yy}", itemRental.EndDate));
        }
        else
        {
            return(String.Format("{0:MM/dd/yy}", itemRental.StartDate) + " - " + String.Format("{0:MM/dd/yy}", itemExtension.NewEndDate));
        }
    }
Beispiel #2
0
    public string checkEndDate(string rentalID)
    {
        Extension itemExtension = ExtensionDB.getLastExtensionofRental(rentalID);


        if (itemExtension.ExtensionID == null)
        {
            Rental itemRental = RentalDB.getRentalbyID(rentalID);
            return(itemRental.EndDate.ToString());
        }
        else
        {
            return(itemExtension.NewEndDate.ToString());
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Item   itemRental = ItemDB.getItembyID(Request.QueryString["itemID"]);
        string inputDates = String.Format("{0}", Request.Form["input-id"]);

        if (inputDates != "")
        {
            DateTime startDate = Convert.ToDateTime(inputDates.Substring(0, 10));
            DateTime endDate   = Convert.ToDateTime(inputDates.Substring(inputDates.Length - 10));

            int numOfDays = Convert.ToInt32((endDate - startDate).TotalDays);

            if (Session["itemExtension"].ToString() == "ExtendItem")
            {
                Extension lastExtension = ExtensionDB.getLastExtensionofRental(Request.QueryString["rentalID"].ToString());
                if (lastExtension.ExtensionID != null)
                {
                    if (startDate.CompareTo(lastExtension.NewEndDate.AddDays(1)) != 0)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Extension must start right after your rental period ends')", true);
                        return;
                    }
                }
                else
                {
                    Rental currentRental = RentalDB.getRentalbyID(Request.QueryString["rentalID"].ToString());
                    if (startDate.CompareTo(currentRental.EndDate.AddDays(1)) != 0)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Extension must start right after your rental period ends')", true);
                        return;
                    }
                }
            }

            decimal totalDayPrice = 0, totalWeekPrice = 0, totalMonthPrice = 0, amountDue = 0;

            if (itemRental.PricePerMonth != 0)
            {
                totalMonthPrice = (numOfDays / 30) * itemRental.PricePerMonth;

                if (itemRental.PricePerWeek != 0)
                {
                    totalWeekPrice = (numOfDays % 30) / 7 * itemRental.PricePerWeek;
                    if (itemRental.PricePerDay != 0)
                    {
                        totalDayPrice = (numOfDays % 30) % 7 * itemRental.PricePerDay;
                    }
                }
                else
                {
                    totalDayPrice = (numOfDays % 30) * itemRental.PricePerDay;
                }
            }
            else
            {
                if (itemRental.PricePerWeek != 0)
                {
                    totalWeekPrice = numOfDays / 7 * itemRental.PricePerWeek;

                    if (itemRental.PricePerDay != 0)
                    {
                        totalDayPrice = (numOfDays % 7) * itemRental.PricePerDay;
                    }
                }
                else
                {
                    totalDayPrice = (numOfDays * itemRental.PricePerDay);
                }
            }


            amountDue          = totalDayPrice + totalWeekPrice + totalMonthPrice;
            lblRentalRate.Text = amountDue.ToString();

            Rental rental = new Rental();

            Session["rentalPeriod"] = inputDates;
            Session["rentalRate"]   = lblRentalRate.Text;
            try
            {
                rental.PickUpLocation = tbxPickUpLocation.Value;
                rental.PickUpTime     = Convert.ToDateTime(tbxPickUpTime.Value).TimeOfDay;
                rental.ReturnLocation = tbxReturnLocation.Value;
                rental.ReturnTime     = Convert.ToDateTime(tbxReturnTime.Value).TimeOfDay;
                rental.ReturnLocation = tbxReturnLocation.Value;
            }
            catch (Exception E)
            {
                Session["error"] = E.Message;
                return;
            }

            if (Session["itemExtension"].ToString() == "ExtendItem")
            {
                rental.RentalFee           = amountDue;
                lblTotalAmountPayable.Text = rental.RentalFee.ToString();
                Session["rental"]          = rental;
                Response.Redirect("Payment.aspx?itemID=" + Request.QueryString["itemID"] + "&rentalID=" + Request.QueryString["rentalID"].ToString());
            }
            else
            {
                rental.RentalFee           = amountDue + itemRental.Deposit;
                lblTotalAmountPayable.Text = rental.RentalFee.ToString();
                Session["rental"]          = rental;
                Response.Redirect("Payment.aspx?itemID=" + Request.QueryString["itemID"]);
            }
        }
        else
        {
            pnlMessageOutput.Visible = true;
            lblOutput.Text           = "Please select the dates";
        }
    }