private void btnSubmit_Click(object sender, EventArgs e) { if (txtName.Text == null || txtPrice.Text == null || cmbCategory.SelectedIndex <= 0) { MessageBox.Show("please fill all the required fields"); } else { MenuItem currentItem; bool ExistingItem = int.TryParse(lblProductID.Text, out int pID); if (ExistingItem) { // currentItem = new MenuItem { Name = txtName.Text, ProductID = pID, PreparationTime = Convert.ToInt32(numPrep.Value), Category = (Category)cmbCategory.SelectedItem, Price = Convert.ToDecimal(txtPrice.Text), Quantity = Convert.ToInt32(numQuantity.Value), }; int rows = menuItemSrv.EditMenuItem(currentItem); ShowResult(rows, "item edited sucessfully", "btn submit, add menu item"); } else { currentItem = new MenuItem { Name = txtName.Text, //ProductID = Convert.ToInt32(lblProductID.Text), PreparationTime = Convert.ToInt32(numPrep.Value), Category = (Category)cmbCategory.SelectedItem, Price = Convert.ToDecimal(txtPrice.Text), Quantity = Convert.ToInt32(numQuantity.Value), }; int rows = menuItemSrv.AddMenuItem(currentItem); ShowResult(rows, "item added sucessfully", "btn submit click, edit menu item"); } } RefreshPanel(); FillListView(); }