Exemple #1
0
        private void ViewOrders()
        {
            LinkedList <Ordder> orders;

            // if not logged in cant view orders
            if (Session["login"] == null)
            {
                Response.Redirect("/Accounts/Login.aspx");
            }
            if (Session["type"].Equals("admin"))
            {
                //orders = ConnectionClass.GetAllOrders();
                grdOrders.Visible = true;
            }
            else
            {
                int id = Convert.ToInt32(Session["id"].ToString());                             // user id
                orders = ConnectionClass.GetAllOrdersForClient(id);
                string str = "";
                foreach (Ordder order in orders)
                {
                    Item item = ConnectionClass.GetProductByID(order.ProductID);
                    str += "<table caption='Order ID: " + order.Id + "' class='ordersTable'>" +
                           "<tr><td><b>Product:</b></td><td>" + item.Category + " " + item.Type + " " + item.Name + "</td></tr>" +
                           "<tr><td><b>Price:</b></td><td>" + order.Price + "</td></tr>" +
                           "<tr><td><b>Date:</b></td><td>" + order.Date + "</td></tr>" +
                           "<tr><td><b>Address:</b></td><td>" + order.Info + "</td></tr>" +
                           "<table>";
                }
                lblOut.Text    = str;
                lblOut.Visible = true;
            }
        }
        public static string ViewInfoBeforeBuyProduct(int ProductID)
        {
            Item item = ConnectionClass.GetProductByID(ProductID);

            if (item == null)
            {
                return("Sorry this product doesnt exist.");
                //Response.Redirect("/Default.aspx");
            }
            string[] des = item.Description.Split(',');
            for (int i = 0; i < des.Length; i++)
            {
                des[i] = des[i].Substring(0, des[i].LastIndexOf(' '));
            }
            string outStr = "";

            if (item.Category.Equals("Desktop"))
            {
                outStr += "<table class='buyTable'>" +
                          "<tr><td rowspan='9'><img runat='server' src='" + item.Image + "' /></td>" +
                          "<td colspan='2' style='text-align:center'><b>" + item.Category + " " + item.Type + " " + item.Name + "</b></td></tr>" +
                          "<tr bgcolor='#eeeeee'><td>Proccessor</td><td>" + des[0] + "</td></tr>" +
                          "<tr><td>Motherboard</td><td>" + des[1] + "</td></tr>" +
                          "<tr bgcolor='#eeeeee'><td>Video</td><td>NVIDIA GeForce GTX650 1GB</td></tr>" +
                          "<tr><td>RAM</td><td>" + des[2] + "</td></tr>" +
                          "<tr bgcolor='#eeeeee'><td>Memory</td><td>" + des[3] + "</td></tr>" +
                          "<tr><td>PSU</td><td>Seasonic 620W</td></tr>" +
                          "<tr bgcolor='#eeeeee'><td>Disc Drive</td><td>LG SATA 22X SUPER-MULTI DVD Burner</td></tr>" +
                          "<tr><td>Warranty</td><td>15 Years</td></tr>" +
                          "</table>";
            }
            if (item.Category.Equals("Notebook"))
            {
                outStr += "<table class='buyTable' style='width: 80%;'>" +
                          "<tr><td rowspan='9'><img runat='server' src='" + item.Image + "' /></td>" +
                          "<td colspan='2' style='text-align:center'><b>" + item.Category + " " + item.Type + " " + item.Name + "</b></td></tr>" +
                          "<tr bgcolor='#eeeeee'><td>Proccessor</td><td>" + des[0] + "</td></tr>" +
                          "<tr><td>Video</td><td>Intel® HD Graphics</td></tr>" +
                          "<tr bgcolor='#eeeeee'><td>RAM</td><td>" + des[1] + "</td></tr>" +
                          "<tr><td>Memory</td><td>" + des[2] + "</td></tr>" +
                          "<tr bgcolor='#eeeeee'><td>Disc Drive</td><td>LG SATA 22X SUPER-MULTI DVD Burner</td></tr>" +
                          "<tr><td>Varranty</td><td>15 Years</td></tr>" +
                          "</table>";
            }
            if (item.Category.Equals("Tablet"))
            {
                outStr += "<table class='buyTable' style='width: 80%;'>" +
                          "<tr><td rowspan='9'><img runat='server' src='" + item.Image + "' /></td>" +
                          "<td colspan='2' style='text-align:center'><b>" + item.Category + " " + item.Type + " " + item.Name + "</b></td></tr>" +
                          "<tr colspan='2'><td>Proccessor</td><td>" + item.Description + "</td></tr>" +
                          "</table>";
            }

            return(outStr);
        }
        // order the product for user
        // function that takes money from client doesn't exist for yet
        // redirect to client orders page
        public static string BuyItem(int ProductID, int userID, string addres)
        {
            // place for fields validation
            Item item = ConnectionClass.GetProductByID(ProductID);

            if (item == null || item.Quantity <= 0)
            {
                return("Cannot buy this product. Please try other one.");
            }
            User   user  = ConnectionClass.GetUserByID(userID);
            Ordder order = new Ordder(1, user.Id, ProductID, 1, item.Price, DateTime.Now.ToString("d.M.yyyy"), addres);

            ConnectionClass.AddOrder(order);
            ConnectionClass.ReduceQuantity(ProductID);
            // function that draws money from client
            //Response.Redirect("/Orders.aspx");
            return("");
        }