Example #1
0
        // sets datasources and bind data to controls.

        private void Bind()
        {
            var service = new Service();
            var order   = service.GetOrder(orderId);

            // sets the date

            LabelHeader.Text    = "Order Line Items";
            LabelOrderDate.Text = "Order date: " + order.OrderDate.ToShortDateString();
            HyperLinkBack.Text  = "< back to orders ";


            var orderDetails = service.GetOrderDetails(orderId);

            foreach (var detail in orderDetails)
            {
                // caching products would be more effective. however, # of details is usually fairly small.

                var product = service.GetProduct(detail.ProductId);
                detail.ProductName = product.ProductName;
            }

            GridViewOrderDetails.DataSource = orderDetails;
            GridViewOrderDetails.DataBind();
        }
Example #2
0
    protected void ButtonInsertRecord_Click(object sender, EventArgs e)
    {
        short quantity;

        //If we don't get an OrderID or a number, just return
        if (TextBoxOrderIDInsert.Text.Length == 0 || !short.TryParse(TextBoxQuantity.Text, out quantity))
        {
            return;
        }

        int OrderID, ProductID;

        try
        {
            //Get the integers for IDs
            OrderID   = int.Parse(TextBoxOrderIDInsert.Text);
            ProductID = int.Parse(DropDownListProductList.SelectedValue);
        }
        catch
        {
            //Couldn't parse out the OrderID and the ProductID
            return;
        }
        //Insert the record and update the status bar
        LabelStatusInsert.Text = $"Inserted {NorthwindAccess.InsertOrderDetails(OrderID, ProductID,quantity)} records";
        //Update the gridview
        GridViewOrderDetails.DataBind();
    }
Example #3
0
 /// <summary>
 /// update a piece of orderdetails record by its corresponding orderdetailsid when textbox textchanged
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void TxbQuantity_TextChanged(object sender, EventArgs e)
 {
     try
     {
         GridViewRow  gridRow = ((sender as TextBox).Parent.Parent) as GridViewRow;
         HiddenField  hf      = (HiddenField)gridRow.FindControl(HFOrderDetailId);
         DropDownList pn      = (DropDownList)gridRow.FindControl(DdlProductName);
         TextBox      q       = (TextBox)gridRow.FindControl(TxbQuantity);
         TextBox      tp      = (TextBox)gridRow.FindControl(TxbTotalPrice);
         ProductId      = Convert.ToInt32(pn.SelectedValue);
         tp.Text        = (_presenter.GetProductById().ProductPrice *Convert.ToInt32(q.Text)).ToString();
         OrderDetailsId = Convert.ToInt32(hf.Value.ToString());
         ProductId      = Convert.ToInt32(pn.SelectedValue);
         OrderId        = Convert.ToInt32(ViewState[OrderIdVS]);
         Quantity       = Convert.ToInt32(q.Text);
         TotalPrice     = Convert.ToDecimal(tp.Text);
         _presenter.UpdateOrderDetails();
         GridViewOrderDetails.DataSource = _presenter.GetOrderDetailsByOrderId();
         GridViewOrderDetails.DataBind();
     }
     catch (Exception ex)
     {
         this.ShowErrorMessage(ex);
     }
 }
Example #4
0
 /// <summary>
 /// insert a order record and use this orderid to insert a new orderdetails
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void BtnCreateNewRow_Click(object sender, EventArgs e)
 {
     try
     {
         if (DdlCustomer.Text != "Please Select!")
         {
             if (ViewState[FirstNewRowVS] == null)
             {
                 CustomerName         = DdlCustomer.SelectedValue;
                 ViewState[OrderIdVS] = _presenter.InsertOrder().OrderId;
                 OrderId = Convert.ToInt32(ViewState[OrderIdVS]);
                 _presenter.InsertOrderDetails();
                 GridViewOrderDetails.DataSource = _presenter.GetOrderDetailsByOrderId();
                 GridViewOrderDetails.DataBind();
                 ViewState[FirstNewRowVS] = false;
                 DdlCustomer.Enabled      = false;
             }
             else
             {
                 OrderId = Convert.ToInt32(ViewState[OrderIdVS]);
                 _presenter.OpenOrder();
                 _presenter.InsertOrderDetails();
                 GridViewOrderDetails.DataSource = _presenter.GetOrderDetailsByOrderId();
                 GridViewOrderDetails.DataBind();
             }
         }
         BtnSave.Enabled = true;
     }
     catch (Exception ex)
     {
         this.ShowErrorMessage(ex);
     }
 }
Example #5
0
 /// <summary>
 /// provide a datasource of two types for gridview
 /// </summary>
 private void GridViewOrderDetailsDataSource()
 {
     //Proxy client = new Proxy();
     if (Request.QueryString["id"] != null)
     {
         GridViewOrderDetails.DataSource = new Proxy().GetOrderDetailsByOrderId(Convert.ToInt32(Request.QueryString["id"]));
         GridViewOrderDetails.DataBind();
     }
     else
     {
         GridViewOrderDetails.DataSource = new Proxy().GetAllOrderDetails();
         GridViewOrderDetails.DataBind();
     }
 }
Example #6
0
        /// <summary>
        /// Sets datasources and bind data to controls.
        /// </summary>
        private void Bind()
        {
            var repository = new OrderRepository();

            ActionServiceReference.Order order = repository.GetOrder(OrderId);

            // Set the date
            LabelHeader.Text    = "Order Line Items";
            LabelOrderDate.Text = "Order date: " + order.OrderDate.ToShortDateString();
            HyperLinkBack.Text  = "< back to orders ";

            GridViewOrderDetails.DataSource = order.OrderDetails;
            GridViewOrderDetails.DataBind();
        }
Example #7
0
 /// <summary>
 /// provide a datasource of two types for gridview
 /// </summary>
 private void GridViewOrderDetailsDataSource()
 {
     if (Request.QueryString[QueryOrderId] != null)
     {
         OrderId = Convert.ToInt32(Request.QueryString[QueryOrderId]);
         GridViewOrderDetails.DataSource = _presenter.GetOrderDetailsByOrderId();
         GridViewOrderDetails.DataBind();
     }
     else
     {
         GridViewOrderDetails.DataSource = _presenter.GetAllOrderDetails();
         GridViewOrderDetails.DataBind();
     }
 }
Example #8
0
    protected void ButtonDelete_Click(object sender, EventArgs e)
    {
        //Get the orderID and productID of the selected item
        int orderID, productID;

        try
        {
            orderID   = int.Parse(GridViewOrderDetails.SelectedDataKey.Values["OrderID"].ToString());
            productID = int.Parse(GridViewOrderDetails.SelectedDataKey.Values["ProductID"].ToString());
        }
        catch { return; }
        //Delete the row
        LabelStatus.Text = NorthwindAccess.DeleteOrderDetails(orderID, productID);
        //Update the gridview
        GridViewOrderDetails.DataBind();
    }
Example #9
0
 /// <summary>
 /// delete a piece of orderdetails record by its corresponding orderdetailsid
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void GridViewOrderDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     try
     {
         OrderDetailsId = Convert.ToInt32(GridViewOrderDetails.DataKeys[e.RowIndex].Values[0].ToString());
         OrderId        = Convert.ToInt32(ViewState[OrderIdVS]);
         DropDownList ddlProductName = (DropDownList)GridViewOrderDetails.Rows[e.RowIndex].FindControl(DdlProductName);
         TextBox      txbQuantity    = (TextBox)GridViewOrderDetails.Rows[e.RowIndex].FindControl(TxbQuantity);
         TextBox      txbTotalPrice  = (TextBox)GridViewOrderDetails.Rows[e.RowIndex].FindControl(TxbTotalPrice);
         ProductId  = Convert.ToInt32(ddlProductName.SelectedValue);
         Quantity   = Convert.ToInt32(txbQuantity.Text);
         TotalPrice = Convert.ToDecimal(txbTotalPrice.Text);
         _presenter.DeleteOrderDetails();
         GridViewOrderDetails.DataSource = _presenter.GetOrderDetailsByOrderId();
         GridViewOrderDetails.DataBind();
     }
     catch (Exception ex)
     {
         this.ShowErrorMessage(ex);
     }
 }
Example #10
0
 protected void ButtonGetOrderDetails_Click(object sender, EventArgs e)
 {
     //Update the gridview
     GridViewOrderDetails.DataBind();
 }