Exemplo n.º 1
0
 private void btnLuuSP_Click(object sender, EventArgs e)
 {
     try
     {
         if (tam == 0)
         {
             GetDataChiTiet();
             if (sp_BUS.ThemSanPham(spChon_DTO))
             {
                 if (picSanPham.Image != null)
                 {
                     picSanPham.Image.Save(spChon_DTO.HinhAnh);
                 }
                 MessageBox.Show("Thêm sản phẩm thành công!");
                 LoadDSSP();
             }
             else
             {
                 MessageBox.Show("Thêm sản phẩm không thành công!");
                 spChon_DTO = null;
             }
         }
         if (tam == 1)
         {
             GetDataChiTiet();
             if (sp_BUS.CapNhatSanPham(spChon_DTO))
             {
                 if (picSanPham.Image != null)
                 {
                     picSanPham.Image.Save(spChon_DTO.HinhAnh);
                 }
                 MessageBox.Show("Sửa sản phẩm thành công!");
                 LoadDSSP();
             }
             else
             {
                 MessageBox.Show("Sửa sản phẩm không thành công!");
                 spChon_DTO = null;
             }
         }
         DisGiaoDien();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
 private void btnLuu_Click(object sender, RoutedEventArgs e)
 {
     if (txtTenSP.Text == "" || txtGiaSP.Text == "" || imgHinhAnh.Source == null)
     {
         MessageBox.Show("Vui lòng nhập đầy đủ thông tin");
     }
     else
     {
         try
         {
             if (tam == 0)
             {
                 GetDataChiTiet();
                 if (sp_BUS.ThemSanPham(spChon_DTO))
                 {
                     if (imgHinhAnh.Source != null)
                     {
                         string destinationPath = strPath2 + spChon_DTO.HinhAnh;
                         File.Copy(filepath, destinationPath, true);
                     }
                     MessageBox.Show("Thêm sản phẩm thành công!");
                     Grid_Loaded(sender, e);
                 }
                 else
                 {
                     MessageBox.Show("Thêm sản phẩm không thành công!");
                     spChon_DTO = null;
                 }
             }
             if (tam == 1)
             {
                 GetDataChiTiet();
                 if (sp_BUS.CapNhatSanPham(spChon_DTO))
                 {
                     if (imgHinhAnh.Source != null)
                     {
                         string destinationPath = strPath + spChon_DTO.HinhAnh;
                         try
                         {
                             if (File.Exists(destinationPath))
                             {
                                 imgHinhAnh.Source = null;
                                 File.Delete(destinationPath);
                             }
                             File.Copy(filepath, destinationPath, true);
                         }
                         catch (Exception ex)
                         {
                         }
                     }
                     MessageBox.Show("Sửa sản phẩm thành công!");
                     Grid_Loaded(sender, e);
                 }
                 else
                 {
                     MessageBox.Show("Sửa sản phẩm không thành công!");
                     spChon_DTO = null;
                 }
             }
             DisGiaoDien();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }