Ejemplo n.º 1
0
        private void btnXoa_Click(object sender, RoutedEventArgs e)
        {
            PHIEU_NHAP_HH temp = (PHIEU_NHAP_HH)lvNhaCungCap.SelectedItem;

            //Bắt lỗi chưa chọn nhà cung cấp trong listview
            if (lvNhaCungCap.SelectedIndex < 0)
            {
                MessageBox.Show("Bạn chưa chọn Nhà cung cấp!", "Thông báo");
                return;
            }

            if (MessageBox.Show("Bạn có chắc chắn muốn xoá không!", "Cảnh báo", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (QLKHOEntities db = new QLKHOEntities())
                {
                    var entry = db.Entry(temp);
                    if (entry.State == EntityState.Detached)
                    {
                        db.PHIEU_NHAP_HH.Attach(temp);
                    }
                    db.PHIEU_NHAP_HH.Remove(temp);
                    db.SaveChanges();
                    MessageBox.Show("Xoá thành công!", "Thông báo");
                    LoadDuLieu();
                }
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 2
0
        private void lvNhaCungCap_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            PHIEU_NHAP_HH test = (PHIEU_NHAP_HH)lvNhaCungCap.SelectedItem;

            //txtMa.Text = test.MA_NCC;
            AreaText.DataContext = test;
        }
Ejemplo n.º 3
0
        private void btnThem_Click(object sender, RoutedEventArgs e)
        {
            //Biến tạm lưu dữ liệu nhập
            PHIEU_NHAP_HH test = new PHIEU_NHAP_HH();

            //NHA_CUNG_CAP test = (NHA_CUNG_CAP)AreaText.DataContext;

            //Gán dữ liệu
            test.NGAYNHAP = DateTime.Parse(txtNgay.Text);
            test.MANCC    = txtMaNCC.Text.Trim();
            test.MAHH     = txtMaHH.Text.Trim();
            test.SOLUONG  = Int32.Parse(txtSL.Text.Trim());
            test.GIA      = Int32.Parse(txtGia.Text.Trim());
            test.TIEN     = Int32.Parse(txtSL.Text.Trim()) * Int32.Parse(txtGia.Text.Trim());
            test.DIENGIAI = txtDienGiai.Text.Trim();

            //kiểm tra dữ liệu nhập
            if (CheckDataInput() == false)
            {
                return;
            }

            //
            //if (CheckID() == false)
            //return;

            //Nhắc nhở lưu đối tượng
            if (MessageBox.Show("Bạn muốn thêm phiếu nhập mới?", "Thông báo", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (QLKHOEntities db = new QLKHOEntities())
                {
                    db.PHIEU_NHAP_HH.Add(test);
                    db.SaveChanges();
                }
                MessageBox.Show("Thêm thành công!");
            }
            else
            {
                return;
            }

            //Load lại bảng
            LoadDuLieu();
        }
Ejemplo n.º 4
0
        private void btnLuu_Click(object sender, RoutedEventArgs e)
        {
            //Tạm lưu dữ liệu nhập
            PHIEU_NHAP_HH temp = (PHIEU_NHAP_HH)lvNhaCungCap.SelectedItem;

            //Gán dữ liệu
            temp.NGAYNHAP = DateTime.Parse(txtNgay.Text);
            temp.MANCC    = txtMaHH.Text.Trim();
            temp.MAHH     = txtMaHH.Text.Trim();
            temp.SOLUONG  = Int32.Parse(txtSL.Text.Trim());
            temp.GIA      = Int32.Parse(txtGia.Text.Trim());
            temp.TIEN     = Int32.Parse(txtSL.Text.Trim()) * Int32.Parse(txtGia.Text.Trim());
            temp.DIENGIAI = txtDienGiai.Text.Trim();

            //kiểm tra dữ liệu nhập
            if (CheckDataInput() == false)
            {
                return;
            }

            //Bắt lỗi chưa chọn nhà cung cấp trong listview
            if (lvNhaCungCap.SelectedIndex < 0)
            {
                MessageBox.Show("Bạn chưa chọn Nhà cung cấp!", "Thông báo");
                return;
            }

            if (MessageBox.Show("Bạn có chắc chắn muốn lưu không!", "Cảnh báo", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (QLKHOEntities db = new QLKHOEntities())
                {
                    db.Entry(temp).State = EntityState.Modified;
                    db.SaveChanges();
                    MessageBox.Show("Lưu thành công!", "Thông báo");
                    LoadDuLieu();
                }
            }
        }