Lọc các cuộc hẹn từ Exchange Server

Aspose.Email cho C++ cho phép các nhà phát triển lọc các cuộc hẹn lịch trên Microsoft Exchange bằng cách sử dụng IEWSClient và ExchangeQueryBuilder API. Bạn có thể lọc các cuộc hẹn theo khoảng ngày, trạng thái chu kỳ, hoặc các thuộc tính khác của cuộc hẹn để chỉ lấy những sự kiện bạn cần.

Các mẫu trong bài viết này sử dụng các tiêu đề và không gian tên sau:

#include <Calendar/Appointment.h>
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/Search/ExchangeQueryBuilder.h>
#include <Clients/Exchange/Search/AppointmentQueryBuilder.h>
#include <Tools/Search/MailQuery.h>
#include <Tools/Search/DateComparisonField.h>
#include <Tools/Search/BoolComparisonField.h>
#include <system/array.h>
#include <system/convert.h>

using namespace System;
using namespace Aspose::Email::Calendar;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;
using namespace Aspose::Email::Tools::Search;

Lọc cuộc hẹn theo khoảng ngày

Cái Appointment thành viên của ExchangeQueryBuilder cung cấp các trường của mục lịch. Các điều kiện trên Start và End ngày chọn các cuộc hẹn trong một khoảng thời gian; GetQuery chuyển chúng thành một MailQuery đó ListAppointments được đánh giá trên máy chủ.

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

SharedPtr<ExchangeQueryBuilder> builder = MakeObject<ExchangeQueryBuilder>();
builder->get_Appointment()->get_Start()->Since(DateTime(2025, 9, 15));
builder->get_Appointment()->get_End()->BeforeOrEqual(DateTime(2025, 10, 10));

ArrayPtr<SharedPtr<Appointment>> appointments = client->ListAppointments(builder->GetQuery());
Console::WriteLine(u"Appointments in the period: " + Convert::ToString(appointments->get_Length()));

client->Dispose();

Lọc cuộc hẹn lặp lại hoặc không lặp lại

Cái IsRecurring trường tách chuỗi sự kiện khỏi sự kiện đơn. Mẫu liệt kê các cuộc hẹn không thuộc chuỗi.

SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");

SharedPtr<ExchangeQueryBuilder> builder = MakeObject<ExchangeQueryBuilder>();
builder->get_Appointment()->get_IsRecurring()->Equals(false);

ArrayPtr<SharedPtr<Appointment>> appointments = client->ListAppointments(builder->GetQuery());
for (SharedPtr<Appointment> appointment : appointments)
{
    Console::WriteLine(appointment->get_Summary() + u" - " + appointment->get_StartDate().ToString());
}

client->Dispose();