Exemple #1
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            OrderLinesTable orderLine = (OrderLinesTable)dgvList.SelectedRows[0].DataBoundItem;
            ProductsTable   product   = OrderingRepository.getInstance.GetProducts().First(c => c.Id == orderLine.ProductID);

            if (nudRemoveQuantity.Value == nudRemoveQuantity.Maximum)
            {
                orderList.Remove(orderLine);
            }
            else
            {
                orderLine.QuantityOrdered -= (int)nudRemoveQuantity.Value;
                orderLine.TotalForItem    -= (double)nudRemoveQuantity.Value * product.Price;
            }

            //orderList.Remove(orderLine);
            RefreshOrderList();

            nudRemoveQuantity.Maximum = orderLine.QuantityOrdered;
            nudRemoveQuantity.Value   = nudRemoveQuantity.Maximum;
            btnRemove.Text            = "Remove All";

            float total = 0;

            foreach (var item in orderList)
            {
                total += (float)item.TotalForItem;
            }

            lblTotal.Text = total.ToString();
        }
Exemple #2
0
 private void dgvList_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (orderList.Count > 0)
     {
         OrderLinesTable currentOrderLine = (OrderLinesTable)dgvList.SelectedRows[0].DataBoundItem;
         nudRemoveQuantity.Maximum = currentOrderLine.QuantityOrdered;
         nudRemoveQuantity.Value   = currentOrderLine.QuantityOrdered;
         btnRemove.Text            = "Remove All";
     }
 }
Exemple #3
0
        private void btnAddList_Click(object sender, EventArgs e)
        {
            if (dgvAllProducts.SelectedRows.Count == 1)
            {
                ProductsTable   product = (ProductsTable)dgvAllProducts.SelectedRows[0].DataBoundItem;
                OrderLinesTable line    = new OrderLinesTable();
                line.OrdersTable     = _order;
                line.ProductsTable   = product;
                line.ProductID       = product.Id;
                line.QuantityOrdered = (int)nudQuantity.Value;
                line.SellingPrice    = product.Price;
                line.TotalForItem    = product.Price * (int)nudQuantity.Value;

                bool itemFound = false;
                if (orderList.Count > 0)
                {
                    foreach (var item in orderList)
                    {
                        if (item.ProductID == product.Id)
                        {
                            //if there is id of product adding to the list is already in the list
                            //quantity and total values are changed instead of adding the same product twice to the datagridview
                            itemFound             = true;
                            item.QuantityOrdered += line.QuantityOrdered;
                            item.TotalForItem    += line.QuantityOrdered * product.Price;
                        }
                    }
                }
                if (itemFound == false)
                {
                    orderList.Add(line);
                }

                RefreshOrderList();

                nudQuantity.Value = 1;

                float total = 0;
                foreach (var item in orderList)
                {
                    total += (float)item.TotalForItem;
                }

                lblTotal.Text = total.ToString();
            }
            else
            {
                MessageBox.Show("Select product to add!");
            }
        }
Exemple #4
0
 private void nudRemoveQuantity_ValueChanged(object sender, EventArgs e)
 {
     if (dgvList.RowCount > 0)
     {
         OrderLinesTable currentOrderLine = (OrderLinesTable)dgvList.SelectedRows[0].DataBoundItem;
         if (nudRemoveQuantity.Value == nudRemoveQuantity.Maximum)
         {
             btnRemove.Text = "Remove All";
         }
         else
         {
             btnRemove.Text = "Remove " + nudRemoveQuantity.Value;
         }
     }
 }