예제 #1
0
        private void DeleteItem()
        {
            var materialId = int.Parse(dgvInvoiceItems.SelectedRows[0].Cells[0].Value.ToString());
            var deletedMaterialQuantity = decimal.Parse(dgvInvoiceItems.SelectedRows[0].Cells["Quantity"].Value
                                                        .ToString());

            InvoiceItemVms.Remove(InvoiceItemVms.Find(item => item.MaterialId == materialId));
            MaterialsList.Find(material => material.Id == materialId).AvailableQuantity += deletedMaterialQuantity;
            FillGrid();
            SetTotalPrice();
            ResetInsertControls();
        }
예제 #2
0
        private void InsertItem()
        {
            ErrorProvider.Clear();
            var isFormValid = true;

            if (cmbMaterials.SelectedIndex == 0)
            {
                isFormValid = false;
                ErrorProvider.SetError(cmbMaterials, Resources.ShouldSelectMaterial);
            }
            if (Math.Abs(dblInQuantity.Value) <= 0)
            {
                isFormValid = false;
                ErrorProvider.SetError(dblInQuantity, Resources.ThisFieldIsRequired);
            }
            if (!isFormValid)
            {
                return;
            }
            var addedQuantity = (decimal)dblInQuantity.Value;
            var materialId    = int.Parse(cmbMaterials.SelectedValue.ToString());

            if (InvoiceItemVms.Exists(item => item.MaterialId == materialId))
            {
                var invoiceItem = InvoiceItemVms.Find(item => item.MaterialId == materialId);
                invoiceItem.Quantity  += addedQuantity;
                invoiceItem.TotalPrice = GetMaterialPrice(materialId) * invoiceItem.Quantity;
            }
            else
            {
                InvoiceItemVms.Add(new InvoiceItemVm
                {
                    MaterialId   = materialId,
                    MaterialCode = MaterialsList.FirstOrDefault(material => material.Id == materialId)?.Code,
                    MaterialName = ((KeyValuePair <int, string>)cmbMaterials.SelectedItem).Value,
                    Quantity     = addedQuantity,
                    TotalPrice   = GetMaterialPrice(materialId) * addedQuantity,
                    Notes        = txtNotes.Text.FullTrim()
                });
            }
            MaterialsList.Find(material => material.Id == materialId).AvailableQuantity -= addedQuantity;
            FillGrid();
            SetTotalPrice();
            ResetInsertControls();
        }