private void btnAdd_Click(object sender, EventArgs e) { if (IsNameEmpty()) { return; } if (StockInService.IsNameExisted(txtBatch.Text.Trim())) { MessageBox.Show("This " + txtBatch.Text.Trim() + " already exists."); } else { int productId = Convert.ToInt32(txtProductId.Text.Trim()); Product product = ProductService.GetProductById(productId); string batch = txtBatch.Text; int count = Convert.ToInt32(txtCount.Text.Trim()); decimal subTotal = Convert.ToDecimal(txtSubtotal.Text.Trim()); int userId = UserLogined.UserId; DateTime inStockTime = dtpInStockTime.Value; StockIn stockIn = new StockIn() { ProductId = productId, Batch = batch, Count = count, Subtotal = subTotal, UserId = userId, InStockTime = inStockTime }; int stockInId = StockInService.Add(stockIn); int supplierId = Convert.ToInt32(txtSupplierId.Text); Inventory inventory = new Inventory() { ProductId = productId, SupplierId = supplierId, Batch = batch, Count = count, Price = product.SellingPrice, InStockTime = DateTime.Now, StockInId = stockInId }; InventoryService.Add(inventory); } ResetUIInputtdData(); }