private void BtnLuu_Click(object sender, RoutedEventArgs e) { if (txtSoLuong.Text == "") { MessageBox.Show("Bạn phải nhập số lượng!", "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error); txtSoLuong.Focus(); } else { NguyenLieuController nguyenLieu = new NguyenLieuController(); ChiTietPhieuXuatCollection chitiet = new ChiTietPhieuXuatCollection(); chitiet.TenNL = cbbTenNguyenLieu.Text; chitiet.SoLuongXuat = Convert.ToInt32(txtSoLuong.Text); chitiet.GhiChu = txtGhiChu.Text; if (isEditing) { ChiTietPhieuXuatCollection rm = dgvPhieuXuat.SelectedItem as ChiTietPhieuXuatCollection; ctpx.Remove(rm); isEditing = false; } ctpx.Add(chitiet); btnThem.IsEnabled = true; btnSua.IsEnabled = true; btnXoa.IsEnabled = true; btnLuu.IsEnabled = false; btnHuy.IsEnabled = false; cbbTenNguyenLieu.IsEnabled = false; txtSoLuong.IsEnabled = false; txtGhiChu.IsEnabled = false; dgvPhieuXuat.SelectedIndex = 0; } }
private void DgvPhieuXuat_SelectionChanged(object sender, SelectionChangedEventArgs e) { ChiTietPhieuXuatCollection chitiet = dgvPhieuXuat.SelectedItem as ChiTietPhieuXuatCollection; if (chitiet != null) { cbbTenNguyenLieu.SelectedItem = chitiet.TenNL; txtSoLuong.Text = chitiet.SoLuongXuat.ToString(); txtGhiChu.Text = chitiet.GhiChu; } }
private void BtnXoa_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Bạn có chắc muốn xóa nguyên liệu này?", "Xác nhận!", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (result == MessageBoxResult.OK) { ChiTietPhieuXuatCollection rm = dgvPhieuXuat.SelectedItem as ChiTietPhieuXuatCollection; ctpx.Remove(rm); } dgvPhieuXuat.SelectedIndex = 0; }