Пример #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="row"></param>
        private void AddItemToOrder(DataGridViewRow row)
        {
            var dataRow = row.DataBoundItem as DataRowView;
            Int64 productId = (Int64)dataRow["id"];

            foreach (ListViewItem listItem in listViewOrderDetails.Items)
            {
                var orderItem = listItem.Tag as OrderItem;

                if (orderItem.ID == productId)
                {
                    ++orderItem.Count;
                    UpdateOrderItem(listItem);
                    UpdateOrderSummaryView();

                    return;
                }
            }

            OrderItem newOrderItem = new OrderItem();

            newOrderItem.ID = productId;
            newOrderItem.Price = (double)row.Cells["price"].Value;
            newOrderItem.PrimeCost = (double)row.Cells["prime_cost"].Value;
            newOrderItem.Count = 1;
            newOrderItem.Tag = row;

            var newListItem = new ListViewItem();

            newListItem.Text = row.Cells["name"].Value as string;
            newListItem.SubItems.Add(newOrderItem.Price.ToString());
            newListItem.SubItems.Add(newOrderItem.Count.ToString());
            newListItem.Tag = newOrderItem;

            listViewOrderDetails.Items.Add(newListItem);
            _orderItems.Add(newOrderItem);

            UpdateOrderSummaryView();

            makeOrderButton.Enabled = true;
            cancelOrderButton.Enabled = true;
        }
Пример #2
0
        private void listViewCheckDetails_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item = listViewOrderDetails.SelectedItems.Count > 0 ? listViewOrderDetails.SelectedItems[0] : null;

            _selectedListViewItemToCheckOut = item;

            if (item != null)
            {
                _selectedOrderItem = item.Tag as OrderItem;

                numericUpDown1.Enabled = true;
                numericUpDown1.Value = _selectedOrderItem.Count;

                removeItemFromOrderButton.Enabled = true;
            }
            else
            {
                _selectedOrderItem = null;

                numericUpDown1.Enabled = false;
                numericUpDown1.Value = 1;

                removeItemFromOrderButton.Enabled = false;
            }
        }