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); }