private void cmdThemGioPhong_Click(object sender, RoutedEventArgs e) { try { HyperlinkButton cmdThemGioPhong = (HyperlinkButton)sender; List<Gio_PhongInfo> ListGioPhong = new List<Gio_PhongInfo>(); ListGioPhong = (List<Gio_PhongInfo>)grvTheoGio.ItemsSource; //add new row int Gio_PhongID = 0; Gio_PhongInfo GioPhong = null; if (cmdThemGioPhong.Content.Equals("Thêm")) { if (GioPhongNextID != -1) { Gio_PhongID = GioPhongNextID; } GioPhong = new Gio_PhongInfo(); GioPhong.Gio_PhongID = Gio_PhongID; GioPhong.GiaTien = 0; GioPhong.GioPhongName = ""; GioPhong.ImageUrl = "Xóa"; ListGioPhong.Add(GioPhong); } else { Gio_PhongID = int.Parse(cmdThemGioPhong.CommandParameter.ToString()); for (int i = 0; i < ListGioPhong.Count; i++) { if (ListGioPhong[i].Gio_PhongID == Gio_PhongID) { ListGioPhong.RemoveAt(i); break; } } } GioPhongNextID = Gio_PhongID + 1; grvTheoGio.ItemsSource = null; grvTheoGio.ItemsSource = ListGioPhong; } catch (Exception ex) { throw ex; } }
void Gio_PhongClient_Gio_Phong_GetItemByPhongIDCompleted(object sender, Gio_Phong_GetItemByPhongIDCompletedEventArgs e) { if (e.Result.Count > 0) { grvTheoGio.ItemsSource = e.Result; List<Gio_PhongInfo> Gio_Phong = e.Result; List<Gio_PhongInfo> Gio_PhongNew = new List<Gio_PhongInfo>(); Gio_PhongInfo Item = null; if (Gio_Phong.Count > 0) { for (int i = 0; i < Gio_Phong.Count; i++) { Item = new Gio_PhongInfo(); Item.Gio_PhongID = Gio_Phong[i].Gio_PhongID; Item.GiaTien = Gio_Phong[i].GiaTien; Item.GioPhongName = Gio_Phong[i].GioPhongName; Item.GiaTien = Gio_Phong[i].GiaTien; Item.PhanTram = Gio_Phong[i].PhanTram; if (i == 0) Item.ImageUrl = "Thêm"; else Item.ImageUrl = "Xóa"; Gio_PhongNew.Add(Item); } grvTheoGio.ItemsSource = Gio_PhongNew; } } else Gio_Phong_Load(); }
protected void Gio_Phong_Load() { try { //Tao Du Lieu Trong List<Gio_PhongInfo> GioPhong = new List<Gio_PhongInfo>(); Gio_PhongInfo Item = new Gio_PhongInfo(); Item.Gio_PhongID = 1; Item.GioPhongName = "1"; Item.GiaTien = 0; Item.PhanTram = 0; Item.ImageUrl = "Thêm"; GioPhong.Add(Item); GioPhongNextID = 2; grvTheoGio.ItemsSource = GioPhong; } catch (Exception) { throw; } }