Exemple #1
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");
            }
        }
        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");
            }
        }
Exemple #3
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");
            }
        }
Exemple #4
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");
            }
        }
Exemple #5
0
        protected void getProducts()
        {
            using (sales db = new sales())
            {
                //fills product data to drop down list
                var products = from p in db.Products
                              orderby p.name
                              select p;

                ddlProduct.DataSource = products.ToList();
                ddlProduct.DataBind();
            }
        }
 public void getOrders()
 {
     try
     {
         //connect to db
         using (sales db = new sales())
         {
             //fills order grid
             var orders = (from o in db.Orders
                           select new { o.orderID, o.orderDate, o.shipDate, o.qty, o.price, o.estimateShipDate, o.productID });
             grdOrders.DataSource = orders.ToList();
             grdOrders.DataBind();
         }
     }
     catch (Exception ex)
     {
         Response.Redirect("/error.aspx");
     }
 }
Exemple #7
0
        protected void getRetail()
        {
            try
            {
                using (sales db = new sales())
                {
                    //fills retail to dropdown
                    var retails = from s in db.Retails
                                  orderby s.name
                                  select s;

                    ddlRetail.DataSource = retails.ToList();
                    ddlRetail.DataBind();
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }