Example #1
0
    protected void repeaterItemInformation_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // check if there is on going rental extenson for item selected
        Extension itemExtension = ExtensionDB.getLastExtensionofItem(Request.QueryString["itemID"], "On-going");


        if (itemExtension.ExtensionID == null)
        {
            List <Rental> itemRental = RentalDB.getRentalofItem(Request.QueryString["itemID"], "On-going");
            if (itemRental.Count == 0)
            {
                itemStatus = "Available";
            }
            else
            {
                itemStatus = "On-going";
                // itemRental[0].
            }
        }
        else
        {
            itemStatus = "On-going Extended";
            // itemExtension.NewEndDate
        }

        // To display the status of the item to the user
        if (e.Item.ItemType == ListItemType.Item)
        {
            // allow renting if no extension, allow reserve if there is
            Button btnRent = (Button)e.Item.FindControl("btnRent");

            Label lblItemStatus = e.Item.FindControl("lblItemStatus") as Label;
            lblItemStatus.Text = itemStatus;
            if (itemStatus == "On-going" || itemStatus == "On-going Extended")
            {
                btnRent.Text = "Reserve Now";
            }
            else
            {
                btnRent.Text = "Rent Now";
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["pageRedirectAfterLogin"] = Request.RawUrl;
            Response.Redirect("Login.aspx");
            return;
        }

        if (Request.QueryString["itemID"] == null)
        {
            Response.Redirect("Categories.aspx");
            return;
        }

        lblDepositAmount.Text = ItemDB.getItembyID(Request.QueryString["itemID"]).Deposit.ToString();

        List <Item> itemInfo = new List <Item>();

        itemInfo.Add(ItemDB.getItembyID(Request.QueryString["itemID"]));
        rptItemRentalInfo.DataSource = itemInfo;
        rptItemRentalInfo.DataBind();


        var selectedDates = new List <DateTime?>();

        Extension itemExtension = ExtensionDB.getLastExtensionofItem(Request.QueryString["itemID"], "On-going");

        List <Rental> itemRental     = RentalDB.getRentalofItem(Request.QueryString["itemID"], "Scheduled");
        List <Rental> itemRentalInfo = RentalDB.getRentalofItem(Request.QueryString["itemID"], "On-going");

        if (itemExtension != null)
        {
            for (var date = itemRentalInfo[0].StartDate; date <= itemExtension.NewEndDate; date = date.AddDays(1))
            {
                selectedDates.Add(date);
            }
        }


        foreach (Rental rental in itemRental)
        {
            for (var date = rental.StartDate; date <= rental.EndDate; date = date.AddDays(1))
            {
                selectedDates.Add(date);
            }
        }



        for (int i = 0; i < selectedDates.Count(); i++)
        {
            string temp = selectedDates[i].ToString();
            temp = temp.Replace(" 12:00:00 AM", "");
            DateTime dt    = new DateTime();
            int      temp2 = temp.IndexOf("/");

            // Make sure that the day is single digit
            if (temp2 == 1)
            {
                dt = DateTime.ParseExact(temp, "d/M/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                dt = DateTime.ParseExact(temp, "dd/M/yyyy", CultureInfo.InvariantCulture);
            }

            disabledDate = disabledDate + "'" + dt.ToString("yyyy-MM-dd") + "'" + ", ";
        }


        ClientScript.RegisterStartupScript(GetType(), "datePickerInit", "var datepicker = new HotelDatepicker(document.getElementById('input-id'), { disabledDates: [ " + disabledDate + "   ]   });", true);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        List <Item> itemInfo = new List <Item>();

        // check if logged in
        if (Session["user"] == null) // not logged in
        {
            Session["pageRedirectAfterLogin"] = Request.RawUrl;
            Response.Redirect("Login.aspx"); // transfer to  login page
            return;
        }

        // check if user wants to extend
        if (Session["itemExtension"].ToString() == "ExtendItem")
        {
            if (RentalDB.isRentalOfMemberPresent(Request.QueryString["rentalID"].ToString(), MemberDB.getMemberbyEmail(Session["user"].ToString()).MemberID))
            {
                Rental rentalInfo = RentalDB.getRentalbyID(Request.QueryString["rentalID"].ToString());
                tbxPickUpLocation.Value = rentalInfo.PickUpLocation;
                tbxPickUpTime.Value     = rentalInfo.PickUpTime.ToString();
                tbxReturnLocation.Value = rentalInfo.ReturnLocation;
                tbxReturnTime.Value     = rentalInfo.ReturnTime.ToString();


                tbxPickUpLocation.Disabled = true;
                tbxPickUpTime.Disabled     = true;
                tbxReturnLocation.Disabled = true;
                tbxReturnTime.Disabled     = true;
                itemInfo.Add(ItemDB.getItembyID(RentalDB.getRentalbyID(Request.QueryString["rentalID"].ToString()).Item.ItemID));
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Inaccessible Page!')", true);
                Response.Redirect("RentalHistory.aspx");
            }
        }
        else if (Request.QueryString["itemID"] == null)
        {
            Response.Redirect("Categories.aspx");
            return;
        }
        else
        {
            lblDepositAmount.Text = ItemDB.getItembyID(Request.QueryString["itemID"]).Deposit.ToString();
            itemInfo.Add(ItemDB.getItembyID(Request.QueryString["itemID"]));
        }

        rptItemRentalInfo.DataSource = itemInfo;
        rptItemRentalInfo.DataBind();
        var selectedDates = new List <DateTime?>();


        List <Rental> currentRental = RentalDB.getRentalofItem(Request.QueryString["itemID"], "On-going");

        if (currentRental.Count > 0)
        {
            foreach (Rental rental in currentRental)
            {
                for (var date = rental.StartDate; date <= rental.EndDate; date = date.AddDays(1))
                {
                    selectedDates.Add(date);
                }
            }
        }

        List <Rental> scheduledRental = RentalDB.getRentalofItem(Request.QueryString["itemID"], "Scheduled");

        if (scheduledRental.Count > 0)
        {
            foreach (Rental rental in scheduledRental)
            {
                for (var date = rental.StartDate; date <= rental.EndDate; date = date.AddDays(1))
                {
                    selectedDates.Add(date);
                }
            }
        }

        Extension itemExtension = ExtensionDB.getLastExtensionofItem(Request.QueryString["itemID"], "On-going");

        if (itemExtension.ExtensionID != null)
        {
            for (var date = currentRental[0].StartDate; date <= itemExtension.NewEndDate; date = date.AddDays(1))
            {
                selectedDates.Add(date);
            }
        }


        for (int i = 0; i < selectedDates.Count(); i++)
        {
            string temp = selectedDates[i].ToString();
            temp = temp.Substring(0, temp.IndexOf(" "));
            //temp = temp.Replace(" 12:00:00 AM", "");
            DateTime dt    = new DateTime();
            int      temp2 = temp.IndexOf("/");

            // Make sure that the day is single digit
            if (temp2 == 1)
            {
                dt = DateTime.ParseExact(temp, "d/M/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                dt = DateTime.ParseExact(temp, "dd/M/yyyy", CultureInfo.InvariantCulture);
            }

            disabledDate = disabledDate + "'" + dt.ToString("yyyy-MM-dd") + "'" + ", ";
        }

        ClientScript.RegisterStartupScript(GetType(),
                                           "datePickerInit", "var datepicker = new HotelDatepicker(document.getElementById('input-id'), { disabledDates: [ " + disabledDate + "   ]   });",
                                           true);
    }