//Phương thức sửa số lượng private void SuaSoLuong(object sender, EventArgs e) { //Lấy thông tin KiemKeSuaPresentation wpf = (KiemKeSuaPresentation)sender; SanPhamPublic _sp = wpf._sp; //Cập nhật số lượng if (KiemKeBusiness.CapNhatSoLuong(_sp.MaSP_SP, _sp.SoLuong_SP)) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Content = "Cập nhật thành công sản phẩm: " + _sp.TenSP_SP + " số lượng: " + _sp.SoLuong_SP; //Cập nhật dữ liệu trên listSP _listSP.Where(item => item.MaSP_SP == _sp.MaSP_SP).First().SoLuong_SP = _sp.SoLuong_SP; dgDsSanPham.ItemsSource = _listSP; dgDsSanPham.Items.Refresh(); int _index = _listSP.FindIndex(item => item.MaSP_SP == _sp.MaSP_SP); dgDsSanPham.SelectedIndex = _index; dgDsSanPham.ScrollIntoView(dgDsSanPham.SelectedItem); HienThiTongSP(); } else { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Content = "Thao tác cập nhật thất bại"; } }
//Nút sửa số lượng private void btnSua_Click(object sender, RoutedEventArgs e) { //Lấy thông tin SanPhamPublic _spTemp = (dgDsSanPham.SelectedItem as SanPhamPublic); SanPhamPublic _sp = new SanPhamPublic(); _sp.MaSP_SP = _spTemp.MaSP_SP; _sp.TenSP_SP = _spTemp.TenSP_SP; _sp.SoLuong_SP = _spTemp.SoLuong_SP; //Hiển thị sửa KiemKeSuaPresentation wpf = new KiemKeSuaPresentation(); wpf._SuaSoLuong += new EventHandler(SuaSoLuong); wpf._sp = _sp; wpf.ShowDialog(); dgDsSanPham.Focus(); }