コード例 #1
0
 private void btnXoa_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Bạn Chắc Chắn Muốn Xóa Chứ ?", "Thông Báo", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
     {
         var db      = new MyDatabaseEntities();
         var Element = db.SanPhams.Find(ID_OFItemSelected);
         Element.HienThi = 0;
         db.SaveChanges();
         DanhSachSanPham.LoadSanPham(); // Load Lai Hien Thi Danh Sach San Pham
         NavigationService.GoBack();
     }
 }
コード例 #2
0
        private void btnXacNhanSuaSanPham_Click(object sender, RoutedEventArgs e)
        {
            //Kiem Tra Form Rỗng
            if ("" == txtTenSanPham.Text || "" == txtGiaNhap.Text || "" == txtGiaBan.Text || "" == txtSoLuong.Text || cmbHangSanXuat.SelectedIndex == -1 || cmbMucDich.SelectedIndex == -1)
            {
                MessageBox.Show("Vui Lòng Không Để Trống");
                return;
            }

            if (Int32.Parse(txtSoLuong.Text) < 0 || Int32.Parse(txtGiaBan.Text) < 0 || Int32.Parse(txtGiaNhap.Text) < 0)
            {
                MessageBox.Show("Vui Lòng Kiểm Tra Lại Giá Trị Nhập");
                return;
            }

            var db      = new MyDatabaseEntities();
            var element = db.SanPhams.Find(ID_OFItemSelected);

            //Convert Ảnh
            byte[] imageData = new byte[bitmapImageSanPham.StreamSource.Length];
            bitmapImageSanPham.StreamSource.Seek(0, System.IO.SeekOrigin.Begin);
            bitmapImageSanPham.StreamSource.Read(imageData, 0, imageData.Length);

            //Tim ID Loai San Pham
            int ID_LoaiSanPham = -1;

            foreach (var value in db.LoaiSanPhams.ToList())
            {
                if (cmbHangSanXuat.SelectedValue.ToString() == value.HangSanXuat && cmbMucDich.SelectedValue.ToString() == value.MucDich)
                {
                    ID_LoaiSanPham = value.ID;
                    break;
                }
            }
            // Lay Gia Tri Hien Thi
            element.HinhAnh        = imageData;
            element.Ten            = txtTenSanPham.Text;
            element.LoaiSanPham_ID = ID_LoaiSanPham;
            element.GiaNhap        = Int32.Parse(txtGiaNhap.Text);
            element.GiaBan         = Int32.Parse(txtGiaBan.Text);
            element.SoLuong        = Int32.Parse(txtSoLuong.Text);

            db.SaveChanges();
            MessageBox.Show("Sữa Thành Công");
            DanhSachSanPham.LoadSanPham(); // Load Lai Sau Khi Sua
        }
コード例 #3
0
 private void imgBack_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     DanhSachSanPham.cmbSapXep_Temp.SelectedIndex = 0;
     DanhSachSanPham.LoadSanPham();
     NavigationService.GoBack();
 }