public static int CapNhatChiTietDonHang(SanPhamGioHang nd) { string query = String.Format("UPDATE ChiTietDonHang SET SoLuong = " + nd.SoLuong + ", DonGia = " + nd.Gia + ", ThanhTien = " + nd.ThanhTien + " WHERE ID = " + nd.ID + ""); try { conn.Open(); command.CommandText = query; return command.ExecuteNonQuery(); } catch (Exception ex) { } finally { conn.Close(); } return 0; }
public static List<SanPhamGioHang> LayDanhSachChiTietDonHangTheoMaHoaDon(int maHoaDon) { DonHang dh = LoadDonHangTheoMaHoaDon(maHoaDon); if (dh == null) { return new List<SanPhamGioHang>(); } List<SanPhamGioHang> list = new List<SanPhamGioHang>(); string query = String.Format("SELECT CTDH.MaDH, CTDH.ID ,SP.TenSP, CTDH.SoLuong, SP.GiaMoi, CTDH.ThanhTien, DH.TinhTrang, SP.HinhSP, SP.MaSP FROM ChiTietDonHang as CTDH, SanPham as SP, DonHang as DH Where CTDH.MaSP = SP.MaSP and DH.ID = CTDH.MaDH and DH.ID = " + maHoaDon + " and CTDH.Status = 1"); string ErrMsg = string.Empty; try { conn.Open(); command.CommandText = query; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Int32 madonhang = reader.GetInt32(0); Int32 machitietdonhang = reader.GetInt32(1); String tensanpham = reader.GetString(2); Int32 soluong = reader.GetInt32(3); Int64 GiaSanPham = reader.GetInt64(4); Int64 thanhTien = reader.GetInt64(5); String tinhtrang = reader.GetString(6); String hinhsp = reader.GetString(7); String masanpham = reader.GetString(8); SanPhamGioHang sp = new SanPhamGioHang(madonhang, machitietdonhang, tensanpham, soluong, GiaSanPham, thanhTien, tinhtrang, hinhsp, masanpham); sp.TinhTrang = dh.TinhTrang; list.Add(sp); } } catch (Exception ex) { ErrMsg = ex.Message; } finally { conn.Close(); } return list; }