示例#1
0
        private void AddProductToDatagrid()
        {
            var product = _productLogic.GetByProductCode(txtProductCode.Text.Trim());

            if (dgvInvoiceDetails.Rows.Count > 0)
            {
                foreach (DataGridViewRow row in dgvInvoiceDetails.Rows)
                {
                    if (product.ProductCode == row.Cells["ProductCode"].Value.ToString())
                    {
                        row.Cells["Quantity"].Value = Convert.ToDecimal(row.Cells["Quantity"].Value) + 1;
                        SetTotals();
                        return;
                    }
                }
            }

            DataGridViewRow newRow = new DataGridViewRow();

            newRow.CreateCells(dgvInvoiceDetails);
            newRow.SetValues(
                product.ProductCode,
                product.Description,
                $"{product.Price:C}",
                1,
                $"{product.Price:C}"
                );
            dgvInvoiceDetails.Rows.Add(newRow);
        }