예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((Request.HttpMethod == "POST") && (string)Request.Form["action"] == "item_add")
            {
                //db.addItem((string)Request.Form["item_name"],(string)Request.Form["item_condition"],(string)Request.Form["item_initial_price"],(string)Request.Form["item_description"],Request.Form["item_quantity"] );
                DateTime end_time = DateTime.Now;
                switch (Request.Form["item_duration_type"])
                {
                case "minutes":
                    end_time = end_time.AddMinutes(Int32.Parse(Request.Form["item_duration"]));
                    break;

                case "hours":
                    end_time = end_time.AddHours(Int32.Parse(Request.Form["item_duration"]));
                    break;

                case "days":
                    end_time = end_time.AddDays(Int32.Parse(Request.Form["item_duration"]));
                    break;

                default:
                    Response.End();
                    break;
                }

                int itemid = db.CreateItem((int)Session["id"], (string)Request.Form["item_name"], (string)Request.Form["item_condition"], (int)Int32.Parse(Request.Form["item_initial_price"]), (string)Request.Form["item_description"], (int)Int32.Parse(Request.Form["item_quantity"]), end_time);

                // Create the pictures...
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFile file = Request.Files[i];
                    if (file.ContentLength > 0)
                    {
                        byte[] fileData     = null;
                        var    binaryReader = new BinaryReader(file.InputStream);
                        fileData = binaryReader.ReadBytes(file.ContentLength);
                        db.CreateItemPicture(itemid, file.FileName, fileData);
                    }
                }
                db.CreateBid((int)Session["id"], itemid, (int)Int32.Parse(Request.Form["item_initial_price"]), (DateTime)DateTime.Now);
            }
            else
            {
                //Response.Redirect("index.aspx");
            }
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.HttpMethod == "POST" && (string)context.Request.Form["action"] == "bid_add")
            {
                string referrer = context.Request.UrlReferrer.AbsoluteUri;
                try
                {
                    if (!Int32.TryParse(context.Request.Form["itemid"], out itemid))
                    {
                        // If the itemid cannot be parsed into an integer, redirect the user
                        context.Response.Redirect(referrer);
                        return;
                    }
                    if (!Double.TryParse(context.Request.Form["bid_amount"], out bid_amount))
                    {
                        // If the bid amount cannot be parsed into a Double, redirect the user
                        context.Response.Redirect(referrer);
                        return;
                    }
                    else
                    {
                        // If the bid amount is less than 0, redirect the user
                        if (bid_amount < 0)
                        {
                            context.Response.Redirect(referrer);
                        }
                    }

                    // Create the bid
                    db.CreateBid((int)context.Session["id"], itemid, bid_amount, DateTime.Now);
                }
                catch (SqlException SqlEx)
                {
                    if (SqlEx.Number == 2627)
                    {
                        // User already has a bid for this item, update it with the new value
                        db.UpdateBid((int)context.Session["id"], (int)Int32.Parse(context.Request.Form["itemid"]), (double)Double.Parse(context.Request.Form["bid_amount"]), DateTime.Now);
                    }
                    else
                    {
                        // Unknown Exception in the SQL Command
                        context.Response.StatusCode = 400;
                        context.Response.Write("Caught Exception: " + SqlEx.ToString());
                        context.Response.End();
                        return;
                    }
                }
                catch (Exception e)
                {
                    {
                        // Unknown Exception in try block
                        context.Response.StatusCode = 400;
                        context.Response.Write("Caught Exception: " + e.Message + ":<br>" + e.StackTrace.ToString());
                        context.Response.End();
                        return;
                    }
                }
                finally
                {
                    // Redirect the user to the referring uri
                    context.Response.Redirect(referrer);
                }
            }
        }