public static void Delete_KH(KhachHangDTO kh) { try { HoaDonDTO hd = new HoaDonDTO(); PhieuDatHangDTO pdh = new PhieuDatHangDTO(); List <string> ds = new List <string>(); string delete_kh = string.Format("DELETE FROM db_khach_hang WHERE ma_kh='{0}'", kh.ma_kh); string delete_hd_in_kh = string.Format("SELECT ma_hd FROM db_hoa_don WHERE ma_kh = '{0}'", kh.ma_kh); string delete_pdh_in_kh = string.Format("SELECT ma_pdh FROM db_phieu_dat_hang WHERE ma_kh = '{0}'", kh.ma_kh); ds = Xoa_thong_tin(delete_hd_in_kh); for (int i = 0; i < ds.Count; i++) { hd.ma_hd = ds[0]; ChiTietHoaDonDAO.delete_SPHD(hd); HoaDonDAO.Delete_HD(hd); } ds = Xoa_thong_tin(delete_pdh_in_kh); for (int i = 0; i < ds.Count; i++) { pdh.ma_pdh = ds[0]; ChiTietPhieuDatHangDAO.delete_SPPDH(pdh); PhieuDatHangDAO.Delete_PDH(pdh); } cnn = DataProvider.ConnectData(); DataProvider.Execute(cnn, delete_kh); cnn.Close(); } catch (Exception ex) { throw ex; } }
public void Add(List <CTHDDTO> entity) { SqlDataAdapter da = new SqlDataAdapter("Select * from CTHD", conn); HoaDonDTO hoaDonDTO = new HoaDonDTO(); HoaDonDAO hoaDonDAO = new HoaDonDAO(); int _HDId = hoaDonDAO.GetByLastestId(); foreach (var item in entity) { item.HDId = _HDId; //CTHDDTO tempcthd = new CTHDDTO(_HDId, item[0], item[1], item[2]); Add(item); } }
public void Add(GiaoHangDTO entity) { SqlDataAdapter da = new SqlDataAdapter("Select * from GiaoHang", conn); DataTable dt = new DataTable(); da.Fill(dt); HoaDonDAO hoaDonDAO = new HoaDonDAO(); int _HDId = hoaDonDAO.GetByLastestId(); DataRow r = dt.NewRow(); var _dateDeli = DateTime.Now; r[0] = entity.Id; r[1] = _HDId; r[2] = entity.TotalPrice; r[3] = _dateDeli; r[4] = entity.CustomerName; r[5] = entity.DeliveryContact; r[6] = entity.DeliveryAddress; dt.Rows.Add(r); SqlCommandBuilder cm = new SqlCommandBuilder(da); da.Update(dt); }