// Hiển thị danh sách hóa đơn đã thanh toán public List <dshoadon> getHoaDon1() { List <dshoadon> li = new List <dshoadon>(); string sql = "Select * From HoaDon, datphong where HoaDon.MaDatPhong=datphong.MaDatPhong AND hoadon.TrangThai=1 ORDER BY IDHoaDon DESC"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { dshoadon bill = new dshoadon(); bill.IDHoaDon = (int)reader["IDHoaDon"]; bill.MaDatPhong = (int)reader["MaDatPhong"]; bill.soGio = (int)reader["soGio"]; bill.giaTien = Convert.ToInt32(reader["giaTien"]); bill.giaDichVu = Convert.ToInt32(reader["giaDichVu"]); bill.TongTien = Convert.ToInt32(reader["TongTien"]); bill.TrangThai = (Boolean)reader["TrangThai"]; bill.HoTen = (string)reader["HoTen"]; bill.sdt = (string)reader["sdt"]; li.Add(bill); } conn.Close(); return(li); }
// LayThongKeHoaDon public List <dshoadon> getHoaDon(DateTime from, DateTime to) { List <dshoadon> dshoadons = new List <dshoadon>(); conn.Open(); to = to.AddDays(1); string sql = "select * from HOADON where NgayGioTao >= @from and NgayGioTao <= @to"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@from", from); cmd.Parameters.AddWithValue("@to", to); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { dshoadon dshoadon = new dshoadon(); dshoadon.MaDatPhong = (int)reader["MaDatPhong"]; dshoadon.IDHoaDon = (int)reader["IDHoaDon"]; dshoadon.getDate_in = (string)reader["NgayGioTao"].ToString(); dshoadon.TongTien = (double)reader["TongTien"]; dshoadons.Add(dshoadon); } conn.Close(); return(dshoadons); }