예제 #1
0
        protected void BtnBuy_Click(object sender, EventArgs e)
        {
            if (Session["tourist_id"] == null && Session["tourguide_id"] == null)
            {
                Response.Redirect("Login.aspx");
            }

            else
            {
                try
                {
                    Label1.Text = Session["tourist_id"].ToString();
                }
                catch (NullReferenceException)
                {
                    Label1.Text = Session["tourguide_id"].ToString();
                }
            }
            var      user_id = Convert.ToInt32(Session["tourist_id"]);
            string   attName = lbTicketName.Text;
            string   attDesc = lbTicketDesc.Text;
            double   price   = Convert.ToDouble(lblPrice.Text);
            DateTime expDate = Convert.ToDateTime(tbDate.Text);
            Random   random  = new Random();

            //check whether a code exists already
            int           quantity = Convert.ToInt32(tbQuantity.Text);
            string        code     = random.Next(1000000, 9999999).ToString();
            Ticket        ticket   = new Ticket();
            List <String> codeList = ticket.GetCodes();

            while (true && codeList != null)
            {
                if (codeList.Contains(code))
                {
                    code = random.Next(1000000, 9999999).ToString();
                }
                else
                {
                    break;
                }
            }


            Cart cart = new Cart(attName, attDesc, price, quantity, user_id, AttractionImage.ImageUrl);

            cart.InsertCartTicket();

            Cart newCart = new Cart();

            newCart = newCart.GetCartId(attName, user_id);
            Ticket tkt = new Ticket(attName, attDesc, price, expDate, code, "not paid", user_id, newCart.productId, AttractionImage.ImageUrl);

            tkt.AddNewTicket();


            Response.Redirect("ShoppingCart.aspx");
        }
예제 #2
0
        protected void btnPurchase_Click(object sender, EventArgs e)
        {
            int user_id = Convert.ToInt32(Session["tourist_id"]);

            //update your paid = paid before ItemPay();

            foreach (RepeaterItem ri in Repeater1.Items)
            {
                Label   prodId       = (Label)ri.FindControl("lbProdId");
                Label   prodName     = (Label)ri.FindControl("lbProdName");
                TextBox prodQuantity = (TextBox)ri.FindControl("tbQuantity");

                Random random          = new Random();
                int    productId       = Convert.ToInt32(prodId.Text);
                string productName     = prodName.Text.ToString();
                int    productQuantity = Convert.ToInt32(prodQuantity.Text);



                Cart newItem = new Cart();
                newItem = newItem.GetCartId(productName, user_id);
                if (newItem.productId != 0 && newItem.itemType == "Ticket")
                {
                    int    Count   = productQuantity - 1;
                    int    i       = 0;
                    Ticket dupeTix = new Ticket();
                    dupeTix.TicketPay(productId, user_id);
                    dupeTix = dupeTix.getTicketDetail(productId, user_id);
                    while (i < Count)
                    {
                        string   itemName  = dupeTix.attractionName;
                        string   itemDesc  = dupeTix.attractionDesc;
                        double   itemPrice = dupeTix.price;
                        DateTime itemExp   = dupeTix.dateExpire;
                        int      cart_id   = newItem.productId;
                        string   itemImg   = dupeTix.ticketImage;

                        string        code     = random.Next(1000000, 9999999).ToString();
                        Ticket        ticket   = new Ticket();
                        List <String> codeList = ticket.GetCodes();
                        while (true && codeList != null)
                        {
                            if (codeList.Contains(code))
                            {
                                code = random.Next(1000000, 9999999).ToString();
                            }
                            else
                            {
                                break;
                            }
                        }

                        Ticket newTix = new Ticket(itemName, itemDesc, itemPrice, itemExp, code, "paid", user_id, cart_id, itemImg);
                        newTix.AddNewTicket();

                        i++;
                    }
                }
                else
                {
                    //your stuff here Michael
                    HotelTrans updateHotelBook = new HotelTrans();
                    updateHotelBook.hotelPay(productId, productQuantity, user_id);
                }
            }

            Cart cart = new Cart();

            cart.ItemPay(user_id);
            Response.Redirect("ShoppingCart.aspx");
        }