Beispiel #1
0
        protected void grdOrders_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                //connect
                using (sales db = new sales())
                {
                    //get order id from grid
                    Int32 orderID = Convert.ToInt32(grdOrders.DataKeys[e.RowIndex].Values["orderID"]);
                    //find order
                    var order = (from o in db.Orders
                                 where o.orderID == orderID
                                 select o).FirstOrDefault();

                    //delete it
                    db.Orders.Remove(order);
                    db.SaveChanges();

                    //reload
                    getOrders();
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
Beispiel #2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                using (sales db = new sales())
                {
                    var id = (from i in db.Retails
                              where i.name == ddlRetail.SelectedItem.Text
                              select i.retailID).FirstOrDefault();

                    Product obj = new Product();
                    obj.model      = txtModel.Text;
                    obj.name       = txtName.Text;
                    obj.color      = txtColor.Text;
                    obj.retailerID = id;


                    //save
                    db.Products.Add(obj);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
Beispiel #3
0
        //saves an order
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (sales db = new sales())
                {
                    Order obj = new Order();
                    obj.qty              = Convert.ToInt32(txtqty.Text);
                    obj.orderDate        = Convert.ToDateTime(txtOrderDate.Text);
                    obj.shipDate         = Convert.ToDateTime(txtShipDate.Text);
                    obj.tax              = Convert.ToDouble(txtTax.Text);
                    obj.estimateShipDate = Convert.ToDateTime(txtEstShipDate.Text);
                    obj.price            = Convert.ToDecimal(txtPrice.Text);



                    //save
                    db.Orders.Add(obj);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
Beispiel #4
0
        //purchase product on btn click and save data to database
        protected void btnBuy_Click(object sender, EventArgs e)
        {
            try
            {
                using (sales db = new sales())
                {
                    DateTime today = DateTime.Now;

                    Order obj = new Order();
                    obj.productID = Convert.ToInt32(ddlProduct.SelectedValue);
                    obj.qty       = Convert.ToInt32(txtqty.Text);
                    obj.price     = 10000.00m;
                    obj.shipDate  = today;
                    obj.orderDate = today;
                    obj.tax       = .11;


                    //save
                    db.Orders.Add(obj);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }