コード例 #1
0
        private void removeButton_Click(object sender, EventArgs e)
        {
            if (m_products.Count == 0)
            {
                return;
            }

            ItemSearchUI itemSearcher = new ItemSearchUI(m_products, true, true);
            DialogResult tempDR       = itemSearcher.ShowDialog();

            if (tempDR != DialogResult.OK)
            {
                return;
            }

            Product toRemove = itemSearcher.Product;

            int  index   = -1;
            bool removed = true;

            foreach (DataGridViewRow row in listOfProducts.Rows)
            {
                if (Int32.Parse(row.Cells[0].Value.ToString()) == toRemove.SN.IntValue)
                {
                    if (toRemove.Quantity == Int32.Parse(row.Cells[3].Value.ToString()))
                    {
                        index   = row.Index;
                        removed = false;
                        break;
                    }
                    else
                    {
                        int temp = Int32.Parse(row.Cells[3].Value.ToString());
                        temp -= toRemove.Quantity;
                        row.Cells[3].Value = temp;
                        UpdateReturn();
                    }
                }
            }

            if (removed)
            {
                return;
            }

            if (index != -1)
            {
                listOfProducts.Rows.Remove(listOfProducts.Rows[index]);
                UpdateReturn();
            }
            else
            {
                throw new Exception("Error removing item from shipment!");
            }
        }
コード例 #2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            ItemSearchUI itemSearcher = new ItemSearchUI(m_register.Products, false, true);
            DialogResult tempDR       = itemSearcher.ShowDialog();

            if (tempDR != DialogResult.OK)
            {
                return;
            }

            Product toAdd = itemSearcher.Product;
            bool    added = false;

            foreach (DataGridViewRow row in listOfProducts.Rows)
            {
                if (Int32.Parse(row.Cells[0].Value.ToString()) == toAdd.SN.IntValue)
                {
                    int temp = Int32.Parse(row.Cells[3].Value.ToString());
                    row.Cells[3].Value = temp + toAdd.Quantity;
                    added = true;
                    UpdateReturn();
                }
            }

            if (added)
            {
                return;
            }

            var index = listOfProducts.Rows.Add();

            listOfProducts.Rows[index].Cells[0].Value = toAdd.SN;
            listOfProducts.Rows[index].Cells[1].Value = toAdd.ItemName;
            listOfProducts.Rows[index].Cells[2].Value = toAdd.Price;
            listOfProducts.Rows[index].Cells[3].Value = toAdd.Quantity;
            UpdateReturn();
        }