示例#1
0
文件: Form1.cs 项目: rkj/ieat
        private void addButton_Click(object sender, EventArgs e)
        {
            try
            {
                FridgeProduct fp = new FridgeProduct();

                fp.Description = productsNewDescription.Text;
                fp.Product = dataManager.ProductsList.getByName(productsNewName.Text);
                fp.Amount = float.Parse(productsNewQuantity.Text);
                fp.ExpireDate = productsNewExpire.Value;
                dataManager.Fridge.Add(fp);

                fridgeProductBindingSource.ResetBindings(false);

                productsNewName.Text = "";
                productsNewDescription.Text = "";
                productsNewQuantity.Text = "";
                productsNewExpire.Value = DateTime.Now;

                MessageBox.Show("Product added to the fridge!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured. Cannot add a new product. Please try again");
            }
        }