コード例 #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            addFood formUpdate3 = new addFood("Update");
            int     index3      = Form3.listFood.IndexOf(this.foodSelected);

            addFood.food.ID   = foodSelected.ID;
            addFood.food.Name = foodSelected.Name;
            addFood.food.Unit = foodSelected.Unit;
            addFood.food.Kind = foodSelected.Kind;
            addFood.food.DOM  = foodSelected.DOM;
            addFood.food.ED   = foodSelected.ED;
            formUpdate3.ShowDialog();

            Food f = (Food)listFood[index3];

            f.ID         = addFood.food.ID;
            f.Name       = addFood.food.Name;
            f.Unit       = addFood.food.Unit;
            f.Kind       = addFood.food.Kind;
            f.DOM        = addFood.food.DOM;
            f.ED         = addFood.food.ED;
            addFood.food = null;
            LoadFood1();
            MessageBox.Show("Update Successful");
        }
コード例 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            addFood formAddFood = new addFood("Add");

            formAddFood.ShowDialog();
            if (addFood.food != null)
            {
                Food f = new Food(addFood.food);

                if (string.IsNullOrEmpty(f.ID.ToString()) || string.IsNullOrEmpty(f.Name.ToString()) || string.IsNullOrEmpty(f.Unit.ToString()) || string.IsNullOrEmpty(f.Kind.ToString()) || string.IsNullOrEmpty(f.DOM.ToString()) || string.IsNullOrEmpty(f.ED.ToString()))
                {
                }
                else
                {
                    listFood.Add(f);
                    MessageBox.Show("Add Successful");
                    LoadFood1();
                }
            }
        }