private void buttonadd_Click(object sender, EventArgs e) { openminiformaddfooddrink(new Addfooddrink()); Addfooddrink formAddfooddrink = new Addfooddrink("add"); formAddfooddrink.ShowDialog(); if (Addfooddrink.fooddrink != null) { Fooddrinkcs p = new Fooddrinkcs(Addfooddrink.fooddrink); // value type: int, double, char, string, boolean // reference type: Doctor, Patient, ... //AddDoctor.doctor; trong bộ nhớ address : 123 //d trong bộ nhớ address: 234 //d= AddDoctor.doctor; address của d = address của AddDoctor.doctor; if (string.IsNullOrEmpty(p.id.ToString()) || string.IsNullOrEmpty(p.quantity.ToString()) || string.IsNullOrEmpty(p.name.ToString()) || string.IsNullOrEmpty(p.dayimport.ToString()) || string.IsNullOrEmpty(p.dayout.ToString())) { // không có gì thay đổi vì thông tin nhập vào không đầy dủ } else { listFooddrink.Add(p); MessageBox.Show("Add successful"); LoadFooddrink(); } } }
private void buttonupdate_Click(object sender, EventArgs e) { openminiformaddfooddrink(new Addfooddrink()); Addfooddrink formUpdate = new Addfooddrink("Update"); int index = Fooddrink.listFooddrink.IndexOf(this.fooddrinkSelected); Addfooddrink.fooddrink.id = fooddrinkSelected.id; Addfooddrink.fooddrink.name = fooddrinkSelected.name; Addfooddrink.fooddrink.quantity = fooddrinkSelected.quantity; Addfooddrink.fooddrink.dayimport = fooddrinkSelected.dayimport; Addfooddrink.fooddrink.dayout = fooddrinkSelected.dayout; formUpdate.ShowDialog(); Fooddrinkcs p = (Fooddrinkcs)listFooddrink[index]; p.id = Addfooddrink.fooddrink.id; p.name = Addfooddrink.fooddrink.name; p.quantity = Addfooddrink.fooddrink.quantity; p.dayimport = Addfooddrink.fooddrink.dayimport; p.dayout = Addfooddrink.fooddrink.dayout; Addfooddrink.fooddrink = null; LoadFooddrink(); MessageBox.Show("Update successful"); }