private void BtnLuu_Click(object sender, RoutedEventArgs e) { if (txtSoLuongNhap.Text == "") { MessageBox.Show("Bạn phải nhập số lượng!", "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error); txtSoLuongNhap.Focus(); } else if (txtGia.Text == "") { MessageBox.Show("Bạn phải nhập giá nguyên liệu!", "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error); txtGia.Focus(); } else { NguyenLieuController nguyenLieu = new NguyenLieuController(); ChiTietPhieuNhapCollection chitiet = new ChiTietPhieuNhapCollection(); chitiet.TenNL = cbbTenNguyenLieu.Text; chitiet.SoLuongNhap = Convert.ToInt32(txtSoLuongNhap.Text); DateTime hsd = (DateTime)dtpHanSuDung.SelectedDate; chitiet.HanSuDung = hsd.ToShortDateString(); chitiet.Gia = Convert.ToInt32(txtGia.Text); chitiet.GhiChu = txtGhiChu.Text; chitiet.TongTien = chitiet.Gia * chitiet.SoLuongNhap; if (isEditing) { ChiTietPhieuNhapCollection rm = dgvPhieuNhap.SelectedItem as ChiTietPhieuNhapCollection; ctpn.Remove(rm); isEditing = false; } else { ctpn.Add(chitiet); } btnThem.IsEnabled = true; btnSua.IsEnabled = true; btnXoa.IsEnabled = true; btnLuu.IsEnabled = false; btnHuy.IsEnabled = false; cbbTenNguyenLieu.IsEnabled = false; txtSoLuongNhap.IsEnabled = false; dtpHanSuDung.IsEnabled = false; txtGia.IsEnabled = false; txtGhiChu.IsEnabled = false; dgvPhieuNhap.SelectedIndex = 0; int tongtien = 0; foreach (var item in ctpn) { tongtien += item.TongTien; } txtTongTien.Text = tongtien.ToString(); } }
private void DgvPhieuNhap_SelectionChanged(object sender, SelectionChangedEventArgs e) { ChiTietPhieuNhapCollection chitiet = dgvPhieuNhap.SelectedItem as ChiTietPhieuNhapCollection; if (chitiet != null) { cbbTenNguyenLieu.SelectedItem = chitiet.TenNL; txtSoLuongNhap.Text = chitiet.SoLuongNhap.ToString(); dtpHanSuDung.SelectedDate = Convert.ToDateTime(chitiet.HanSuDung); txtGia.Text = chitiet.Gia.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) { ChiTietPhieuNhapCollection rm = dgvPhieuNhap.SelectedItem as ChiTietPhieuNhapCollection; ctpn.Remove(rm); } dgvPhieuNhap.SelectedIndex = 0; int tongtien = 0; foreach (var item in ctpn) { tongtien += item.TongTien; } txtTongTien.Text = tongtien.ToString(); }