コード例 #1
0
ファイル: ucSanPham.cs プロジェクト: truongmanhsang/DAWinform
 void XuLyThemSanPham(clsSanPham_DTO sanPham)
 {
     if (_SanPhamBUS.ThemSanPham(sanPham))
     {
         FormMessage.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         TaiDuLieu();
     }
     else
     {
         FormMessage.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
ファイル: ucSanPham.cs プロジェクト: cisky2105/DoAn
 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);
     }
 }
コード例 #3
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);
         }
     }
 }