美文网首页
ews-java-api学习:新建Single Appointm

ews-java-api学习:新建Single Appointm

作者: 大写K | 来源:发表于2018-04-12 22:11 被阅读0次
    
    /**
    
     * Appointment:创建单一约会(全天和非全天)
    
    */
    
    private void createSingleAppointment(String userName, String password, String domain, String subject, String location, String startsTime, String endsTime, String body, boolean isAllDay) {
    
    ExchangeService service = new EWS().connectEWS(userName, password, domain);
    
        try {
    
             Appointment appointment = new Appointment(service);
    
            // 中国标准时间
    
            TimeZoneDefinition tz = getTimeZoneDefinition(service, TIME_ZONE_CTT);
    
            appointment.setSubject(subject); // 约会标题
    
            appointment.setLocation(location); // 约会地点
    
            appointment.setBody(MessageBody.getMessageBodyFromText(body)); // 约会正文
    
            HashMap times = getStartsAndEndsTime(startsTime, endsTime);
    
            appointment.setStart((Date) times.get("startsTime"));
    
            appointment.setStartTimeZone(tz);
    
            appointment.setEnd((Date) times.get("endsTime")); 
    
            appointment.setEndTimeZone(tz);
    
            appointment.setIsAllDayEvent(isAllDay); // 是否全天事件    
    
            appointment.save(WellKnownFolderName.Calendar, SendInvitationsMode.SendToNone);
    
        } catch (Exception e) {
    
            System.out.println("Error: Fail to create single appointment!");
    
            e.printStackTrace();
    
         }
    
    }
    
    private TimeZoneDefinition getTimeZoneDefinition(ExchangeService service, String timeZoneID) {
    
        TimeZoneDefinition timeZoneDefinition = null;
    
        try {
    
            for (TimeZoneDefinition tzd : service.getServerTimeZones()) {
    
                if(tzd.getId().equalsIgnoreCase(timeZoneID)) {     
    
                    timeZoneDefinition = tzd;          
    
                    break;     
    
                   }
    
            }
    
        } catch (Exception e) {
    
            e.printStackTrace();
    
        }
    
        return timeZoneDefinition;
    
    }

    相关文章

      网友评论

          本文标题:ews-java-api学习:新建Single Appointm

          本文链接:https://www.haomeiwen.com/subject/qoxqkftx.html