private void btnUpdate_Click(object sender, EventArgs e) { int quantity = Int32.Parse(result["quantity"].ToString()); int value; int res = 0; UpdateDefinition <BsonDocument> update; try { value = Int32.Parse(txtQuantity.Text); }catch (Exception ex) { MessageBox.Show("Please enter a valid integer. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } switch (operation) { case Operation.ADD: res = quantity + value; break; case Operation.SUBTRACT: res = quantity - value; break; } update = Builders <BsonDocument> .Update .Set("quantity", res); collection.UpdateOne(filter, update); this.Hide(); frmInventory.loadInventory(); }
private void btnUpdate_Click(object sender, EventArgs e) { if (txtQuantity.Text.Trim() == "" || txtQuantity.Text.Trim() == "") { MessageBox.Show("Please fill up all the fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { Int32.Parse(txtQuantity.Text); }catch (System.FormatException ex) { Console.WriteLine(ex); MessageBox.Show("Please enter a valid integer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtQuantity.Focus(); txtQuantity.SelectAll(); return; } var update = Builders <BsonDocument> .Update .Set("item", txtItem.Text) .Set("quantity", txtQuantity.Text); collection.UpdateOne(filter, update); frmInventory.loadInventory(); this.Hide(); }