示例#1
0
        protected void addToOrder(object sender, EventArgs e)
        {
            Button1.Enabled = true;
            int ItemID    = Convert.ToInt32((sender as Button).CommandArgument);
            int tempIndex = 0;
            int qty       = 0;

            List <int> CurrentCart         = new List <int>();
            List <int> CurrentCartQuantity = new List <int>();

            if (Session["list"] != null && Session["CartQuantity"] != null)
            {
                CurrentCart         = (List <int>)Session["list"];
                CurrentCartQuantity = (List <int>)Session["CartQuantity"];

                if (!CurrentCart.Contains(ItemID))
                {
                    CurrentCart.Add(ItemID);
                    CurrentCartQuantity.Add(1);
                }
                else
                {
                    tempIndex = CurrentCart.IndexOf(ItemID);

                    qty = CurrentCartQuantity[tempIndex];
                    qty = qty + 1;

                    CurrentCartQuantity[tempIndex] = qty;
                }
                Session["list"]         = CurrentCart;
                Session["CartQuantity"] = CurrentCartQuantity;
            }
            else
            {
                CurrentCart.Add(ItemID);
                CurrentCartQuantity.Add(1);
                Session["list"]         = CurrentCart;
                Session["CartQuantity"] = CurrentCartQuantity;
            }

            ListBox1.Items.Clear();
            Console.WriteLine(CurrentCart + " " + CurrentCartQuantity);
            int i = 0;

            foreach (int element in CurrentCart)
            {
                ListBox1.Items.Add(KahnLib.getOrder(CurrentCart[i], CurrentCartQuantity[i]));
                i++;
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            KahnoUser userPull = new KahnoUser();

            try
            {
                userPull = (KahnoUser)Session["localuser"];
                if (userPull.userid == 0)
                {
                    Response.Redirect("Login.aspx");
                }
                lblName.Text    = userPull.fname;
                lblPhone.Text   = userPull.phone;
                lblEmail.Text   = userPull.email;
                lblAddress.Text = (userPull.coodinateid).ToString();
                lblId.Text      = (userPull.userid).ToString();
            }
            catch
            {
                Response.Redirect("Login.aspx");
            }


            List <int> CurrentCart         = new List <int>();
            List <int> CurrentCartQuantity = new List <int>();

            if (Session["list"] != null && Session["CartQuantity"] != null)
            {
                CurrentCart         = (List <int>)Session["list"];
                CurrentCartQuantity = (List <int>)Session["CartQuantity"];
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
            double total      = 0;
            double grandtotal = 0;
            int    i          = 0;

            foreach (int element in CurrentCart)
            {
                total       = CurrentCartQuantity[i] * KahnLib.getOrderPrice(CurrentCart[i]);
                grandtotal += total;
                ListBox1.Items.Add(" " + KahnLib.getOrder(CurrentCart[i], CurrentCartQuantity[i]) + " = R" + total);
                i++;
            }
            ListBox1.Items.Add(" Total: R" + grandtotal);
        }
示例#3
0
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            restaurant = (KahnoRestaurant)Session["currentRestaurant"];


            DateTime time      = DateTime.Now;
            string   format    = "yyyy-MM-dd HH:mm:ss";
            string   finaltime = time.ToString(format);

            user = (KahnoUser)Session["localuser"];

            int user1 = Convert.ToInt32(user.userid);

            int restaurantSend = restaurant.restaurantID;

            //insert into db first then get orderNumber
            KahnLib.InsertOrder(finaltime, user1, restaurantSend);

            int orderNumber = KahnLib.getOrderNumber();

            List <int> CurrentCart         = new List <int>();
            List <int> CurrentCartQuantity = new List <int>();

            if (Session["list"] != null && Session["CartQuantity"] != null)
            {
                CurrentCart         = (List <int>)Session["list"];
                CurrentCartQuantity = (List <int>)Session["CartQuantity"];
            }
            else
            {
                Response.Redirect("Login.aspx");
            }

            double total = 0;
            int    i     = 0;

            foreach (int element in CurrentCart)
            {
                total = CurrentCartQuantity[i] * KahnLib.getOrderPrice(CurrentCart[i]);
                KahnLib.getOrder(CurrentCart[i], CurrentCartQuantity[i]);
                string        connectString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\KahnoDB.mdf;Integrated Security=True;Connect Timeout=30";
                SqlConnection conn          = new SqlConnection(connectString);
                conn.Open();
                SqlDataAdapter adapter      = new SqlDataAdapter();
                SqlConnection  con          = new SqlConnection(connectString);
                string         insert_query = "INSERT INTO [ORDERDETAIL] (Quantity,OrderNumber,PricePaidPerItem,ItemNumber) VALUES(@quantity,@OrderNo,@total,@itemNo)";
                SqlCommand     comm         = new SqlCommand(insert_query, conn);

                comm.Parameters.AddWithValue("@quantity", CurrentCartQuantity[i]);
                comm.Parameters.AddWithValue("@OrderNo", orderNumber);
                comm.Parameters.AddWithValue("@total", total);
                comm.Parameters.AddWithValue("@itemNo", CurrentCart[i]);
                comm.ExecuteNonQuery();
                con.Close();
                comm.Dispose();
                i++;
            }
            Response.Redirect("Success.aspx");
            Session["list"]         = null;
            Session["CartQuantity"] = null;
        }
示例#4
0
        protected void RemoveFromOrder(object sender, EventArgs e)
        {
            //this is the function triggered by the "remove from cart" button, ItemID is the id of the selected item, do with it what you will
            int ItemID = Convert.ToInt32((sender as Button).CommandArgument);

            Session["itemId"] = ItemID;
            Session["orderCount" + Session["itemId"]] = (Convert.ToInt32(Session["orderCount" + Session["itemId"]]) - 1).ToString();

            int tempIndex = 0;
            int qty       = 0;

            List <int> CurrentCart         = new List <int>();
            List <int> CurrentCartQuantity = new List <int>();

            //Check if session is empty - if it is it will create new and if it does have values will move to the remove side.
            if (Session["list"] != null && Session["CartQuantity"] != null)
            {
                //set both lists to the sessions holding values for order
                CurrentCart         = (List <int>)Session["list"];
                CurrentCartQuantity = (List <int>)Session["CartQuantity"];

                if (CurrentCart.Contains(ItemID))
                {
                    tempIndex = CurrentCart.IndexOf(ItemID);

                    qty = CurrentCartQuantity[tempIndex];
                    if (qty > 1)
                    {
                        qty = qty - 1;
                        CurrentCartQuantity[tempIndex] = qty;
                    }
                    else
                    {
                        CurrentCart.RemoveAt(tempIndex);
                        CurrentCartQuantity.RemoveAt(tempIndex);
                    }
                }
                else
                {
                    ListBox1.Items.Add("Could not remove non exsisting item. try again.");
                }
                Session["list"]         = CurrentCart;
                Session["CartQuantity"] = CurrentCartQuantity;
            }
            else
            {
                ListBox1.Items.Add("Could not remove non exsisting item. try again.");
            }

            //doubt I will need the else in the remove from order function.

            /*else
             * {
             *  CurrentCart.Add(ItemID);
             *  CurrentCartQuantity.Add(1);
             *  Session["list"] = CurrentCart;
             *  Session["CartQuantity"] = CurrentCartQuantity;
             * }*/

            //this will be the same to display the items with quantity
            ListBox1.Items.Clear();
            //Console.WriteLine(CurrentCart + " " + CurrentCartQuantity);
            int i = 0;

            foreach (int element in CurrentCart)
            {
                ListBox1.Items.Add(KahnLib.getOrder(CurrentCart[i], CurrentCartQuantity[i]));
                i++;
            }
        }