// Thêm phòng vào bảng phong public void themPhong(DSPhong dsphong) { string sql = "Insert Into phong (TenPhong, TrangThai, MaLoaiPhong) Values (@TenPhong, @TrangThai, @MaLoaiPhong)"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("TenPhong", dsphong.TenPhong); cmd.Parameters.AddWithValue("TrangThai", dsphong.TrangThai); cmd.Parameters.AddWithValue("MaLoaiPhong", dsphong.MaLoaiPhong); cmd.ExecuteNonQuery(); conn.Close(); }
// Cập nhật thông tin phòng public void updateRoom(DSPhong dsphong) { string sql = "Update phong Set TenPhong=@TenPhong, TrangThai=@TrangThai, MaLoaiPhong=@MaLoaiPhong Where MaPhong=@MaPhong"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("TenPhong", dsphong.TenPhong); cmd.Parameters.AddWithValue("TrangThai", dsphong.TrangThai); cmd.Parameters.AddWithValue("MaLoaiPhong", dsphong.MaLoaiPhong); cmd.Parameters.AddWithValue("MaPhong", dsphong.MaPhong); cmd.ExecuteNonQuery(); conn.Close(); }
// Get tất cả các phòng còn trống chưa có người đặt public List <DSPhong> getphongTrong() { List <DSPhong> dsPhong = new List <DSPhong>(); string sql = "select * from phong where TrangThai = 0"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DSPhong phong = new DSPhong(); phong.MaPhong = (int)reader["MaPhong"]; phong.TenPhong = reader["TenPhong"].ToString(); phong.TrangThai = (Boolean)reader["TrangThai"]; phong.MaLoaiPhong = (int)reader["MaLoaiPhong"]; dsPhong.Add(phong); } conn.Close(); return(dsPhong); }
// Lấy phòng theo mã phòng MaPhong public DSPhong get1Room(int MaPhong) { string sql = "Select * From phong, loaiphong where phong.MaLoaiPhong=loaiphong.MaLoaiPhong And MaPhong=@MaPhong"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("MaPhong", MaPhong); SqlDataReader reader = cmd.ExecuteReader(); DSPhong dsphong = null; if (reader.Read()) { dsphong = new DSPhong(); dsphong.MaPhong = (int)reader["MaPhong"]; dsphong.TenPhong = (string)reader["TenPhong"]; dsphong.TrangThai = (Boolean)reader["TrangThai"]; dsphong.MaLoaiPhong = (int)reader["MaLoaiPhong"]; } conn.Close(); return(dsphong); }