public FormAddBill(Bill billToUpdate) { InitializeComponent(); _billToUpdate = billToUpdate; _isNew = false; _fillForm(); _Init(); btnBrowseCustomer.Enabled = false; }
private void saveItem_Click(object sender, EventArgs e) { if (!Utility.RequiredCheck(errorProvider, txtCustomerCode, txtProductCode, txtQuantity)) { return; } var quantity = int.Parse(txtQuantity.Text); var now = DateTime.Now; if (_isNew) { _billToUpdate = _saveModel(new Bill { CustomerId = _customerToInclude.Id, Customer = _customerToInclude, Paid = false, Tax = 0.1, CreatedAt = now, UpdatedAt = now }); _isNew = false; dgv.AutoGenerateColumns = true; btnBrowseCustomer.Enabled = false; editItem.Enabled = true; deleteItem.Enabled = true; } if (_isUpdateOrder) { _orderToUpdate.Quantity = quantity; _Reload(); _isUpdateOrder = false; _ClearForm(); } else { var query = _billToUpdate.Orders.SingleOrDefault(x => x.ProductId == _productToInclude.Id); if (query == null) { _billToUpdate.Orders.Add(new Order { ProductId = _productToInclude.Id, Product = _productToInclude, Quantity = quantity, CreatedAt = now, UpdatedAt = now }); _Reload(); } else { MessageBox.Show("Menu makanan telah ditambahkan ke pesanan sebelumnya"); } } deleteItem.Enabled = true; editItem.Enabled = true; btnBrowseProduct.Enabled = true; _ClearForm(); }