Create a Lotus Notes/Domino calendar application

Source: Internet
Author: User
Tags repetition
Many Lotus Notes The calendar is "out-of-the-box ". But you know, you can also integrate the calendar features into your custom Application Program . This article explains how to do this.
Lotus Notes calendar is one of the most popular and easy-to-use Lotus Notes Use . A calendar can be used for many different purposes, including:
· Meeting room reservation
· Device reservation
· Share the business or department calendar
· Resource or event plan
· Holiday plan

In addition to its terminal User In addition to the features, the notes calendar for Applications Development Personnel are also very useful. In this article, we provide step-by-step instructions for building an example calendar application. Assume that you are an experienced Lotus Notes/ Domino Developers are familiar with basic notes calendar features.
Application Architecture
A calendar application consists of two parts: a form and a view. A form is used to capture dates, times, and topics of a date.Information . View is based on Form Specifies the date and time to display the topic. Believe it or not, you can use these two parts to build Management A calendar application that repeats events.
Before starting programming, we must first understand the rules for building a calendar application and understand the process of managing repeated events.
Rules:
· The Appointment Form must have a start date field. This field determines where the event is displayed in the calendar. The start date is the anchor of the calendar application.
· The appointment form must contain a duration ). This field must be a number indicating the number of days that have elapsed. (The Appointment Form can also contain a start time and end time. However, this is an optional value, which is not required when an event is actually displayed on the calendar .)
· The first column of the calendar view must contain a date/time value and be sorted in ascending order. This column should be hidden to users. (The first column must be sorted in ascending order for correct display .)
· The second column of the calendar view must contain the calendar event duration. This value determines how many consecutive days the appointment should be displayed. The duration value can be positive or negative. If it is a positive number, the calendar event is displayed to the right (or future) of the start date ). If it is a negative number, the calendar event is displayed on the left (or before) of the start date ).
· The view style must be set to calendar. This Set Change the appearance of a view from the traditional appearance to the actual calendar.

Now let's take a deeper look at the architecture and implementation options for managing repetitive calendar events. The complexity of applications is built around the process of managing repeated events. Same as any Software The same language, Design , Develop and implement Solution Solution There are many methods. The following sections will discuss two possible architectures.
Use a single document to manage repeated events
We have discussed the main components of the calendar application, namely a form and a view. Next we will talk about the different options for managing repeated events. The first method is a simple and effective method for managing continuous calendar events.
Continuous events refer to the appointment that continues from the start date. In other words, you can create an appointment that will be displayed on multiple calendar dates. However, all calendar dates must be consecutive, for example, from January 1, April 4-4 to September 7. The single document method creates only one document and displays the appointment within the calendar date range (see figure 1 ). This method is easy to implement. This can be a good start if you want to quickly build a calendar application or add a calendar to an existing application.
Figure 1. Single-document repetition event

The main advantage of this method is that it is easy to implement. You can easily generate a new application (or enhance an existing application by adding two fields and creating a calendar view ). In addition, since all calendar dates reference the same (single) document, you only need to update one document. Document updates can be reflected in every calendar date. For example, assume that the author wants to include a Conference phone number in the subject of the appointment. The change takes effect immediately on all calendar dates. Other team members can right-click any document and view consistent information.
The disadvantage of this method is that it cannot manage complex repetitive events. If you want to schedule events on the second Friday of each month or on the third day of each month, the document method requires you to manually create entries on each date.
The following section describes a more robust and comprehensive architecture for repetitive events.
Manage repeated events using multiple documents
The "Multi-document" method creates a separate document based on the repeated event parameters specified in the first appointment. For example, you can create an appointment that generates a separate document for each calendar date (see figure 2 ). This architecture provides more flexibility in scheduling, but it is much more complicated to implement.
Figure 2. Multi-document repetition event

To implement the second method, additional information needs to be captured in the initial appointment form. This is managed through a separate dialog box window, which prompts you to specify repeated event parameters: Weekly (weekly), daily (daily), day of the week (day of the week), skip weekends (skip the weekend), monthly (monthly), custom dates (custom date), and so on. When saving the first appointment, this method calculates the dates of all repeated events and generates a separate document for each calendar date.
You can use the second method to achieve greater flexibility and have more options to manage repeated events. When implementing this architecture, you can create various events:
Event Type example
By Date January 1, April 4 (single-day event)
Daily by date April 4-4-7 (continuous)
Weekly by day Monday, Wednesday, and Friday
Monthly by date the first day of each month
Monthly by day the third Friday of each month
A set of discontinuous dates customized by custom dates
Skip weekends is not created if the event falls on Saturday or Sunday.
Next business day if you encounter a weekend, move the event to Monday
Another advantage is the ability to move and delete events. Because each event is stored as a unique document, you can move, delete, or update a calendar event without affecting other related events.
The disadvantage of this method is that it is complicated to calculate the event date.Algorithm . In addition, this method creates a separate document for each event. If the author wants to update the topic or subject of all related events, each document needs to be updated independently.
You may also encounter challenges when deleting or removing a scheduled appointment. To delete all related appointments, the author needs to delete each appointment one by one or add a subroutine to automatically delete related events.
Build a simple Event Calendar
Now let's focus on building a simple single-document calendar application. Start the Lotus Domino designer client and create a blank Database (See figure 3 ). To this end, open the domino designer Customer And select file-database-New. Specify the title and File Name. Make sure that "-blank-" is selected as the template type.
Figure 3. New Database Screen

It is helpful to delete all spaces in the "file name" field. In useWeb In applications, spaces may cause some problems. For example, replace "meetingcalendar. nsf" with "meetingcalendar. nsf ".
Create an Appointment Form
The Appointment Form captures the event start date and end date, duration, author, topic, and details. The duration is calculated automatically. Most jobs related to the calendar application are in the appointment form, including the management of repetitive events.
To create a form, click the new form button or select the create-design-form menu option.
Define Fields
Next, add the fields specified in the following table. To create a field, select the create-field menu option. Make sure that the data type, Formula And other attributes.
Field name type formula remarks
Startdate date/time, editable default startdate: = @ if (@ isnewdoc; @ today; @ return (startdatetime); startdate sets the style to calendar/time control in the field attribute dialog box
Enddate date/time, editable N/A in the field attribute dialog box, set style to calendar Ar/Time Control
Duration number, computed @ if (startdate = ""; 0; enddate = ""; 0; @ businessdays (startdate; enddate )) the formula automatically calculates the duration based on the start date and end date.
Person text, computed when composed @ name ([CN]; @ username) this formula will automatically generate the author's name
Subject text, editable N/
Body Rich Text, editable N/
Field Names, types, and styles are defined in the Properties dialog box. The field formula is placed in the value or defaultvalue section of the programmer's pane, which is located in a region under the designer client. If you do not see this pane, select View-programmer's pane. (See Domino designer product documentation for details about how to use the domino designer client .)
Define Global Objects
The next step is to define the global object related to the form in the (globals) section. You can define an object only once and then reference it in the entire form. This simplifies Code And make the application code more efficient.
Make the following settings in the "declarations" section under the "(global)" title:
Dim doc as notesdocument ''refers to the current calendar document dim ws as notesuiworkspace ''refers to the current applicationworkspace dim s as notessession ''refers to the currentnotes session dim dB as notesdatabas'' refers to thecurrent Notes database dim sdate as notesdatetime ''temporary variable for start date calculations dim edate asnotesdatetime'' temporary variable for end date calculations
We recommend that you add "option explicit" in the "(options)" section ". This will force you to declare all variables (such as dim) and facilitate debugging. If the variable is not defined, the statement is marked as a syntax error. In this way, you can easily find problems in the Code (such as incorrect variable names ).
Now your calendar appointment form should look like 4:
Figure 4. Calendar Appointment Form

Set the window title to appointment. Whenever this form is opened in the Lotus Notes client, the title is displayed at the top of the window. This title helps make the application more user-friendly. The window title is not used elsewhere in the application. You can change the window title to any value you like (such as appointment, meeting, or "meeting by" + person name ).
After opening the document, set a default start date in the Appointment Form:
Sub queryopen (source as notesuidocument, mode as integer, isnewdoc asvariant, continue as variant) set Ws = new notesuiworkspace set S = new notessession apptdate = ws. currentcalendardatetime end sub
After the appointment is displayed, a handle of the document is obtained. The doc object is used in multiple Lotus script events to set and retrieve information in the appointment record:
Sub postopen (source as notesuidocument) set Doc = source. Document end sub
Calculate the two variables used in the calendar view: startdatetime and calendardatetime. These two variables will include an array of consecutive calendar dates. The following code formats the data and sets the values in the appointment form.
Sub postrecalc (source as notesuidocument) dim mydate asnotesitem set Doc = source. document Set mydate = Doc. getfirstitem ("startdate") set sdate = newnotesdatetime (mydate. datetimevalue. dateonly) setdoc. startdatetime = sdate set edate = new notesdatetime ("") set edate = sdate edate. adjustday (Doc. duration (0)-1) set Doc. enddatetime = edate Doc. calendardatetime = Doc. startdatetime end sub
Refresh the current document whenever you save the document. This ensures that the most recent data is displayed to the user whenever the form is saved (for example, when the user selects file-save.
Sub querysave (source as notesuidocument, continue as variant) source. Refresh end sub
Set form attributes
Finally, in the form Properties dialog box, select the "automatically refresh fields" option in the options section of the first tab (see figure 5 ). This option refreshes the calculated field when you change the data on the Appointment Form. For example, when the start date and end date are changed, the duration value is automatically updated.
Figure 5. Form attributes

To complete this form, specify appointment | APPT as the form name in the Properties dialog box. The vertical bars indicate the aliases of the form. Then, save and close the form. (It is a good practice to always provide a form name and an alias, so that all subsequent code can reference the alias. In this way, you can change the form name without affecting the existing code and/or view formula, so as to have more flexibility .)
Create a calendar View
So far, most of the applications have been completed. The only remaining step is to display the calendar view of the appointment event. Each time a database is created, a default view named "(untitled)" is automatically generated. Double-click the view to open it in edit mode. Convert the Properties dialog box from column to view. Set the name to calendar and the alias to Cal.
Define Columns
The next step is to define columns. You can add a column by clicking an existing column title and selecting the create-Insert new column menu option. Next, add the following columns.
Column1 is a hidden column that must contain the start date/time value in ascending order. For this project, select the "show multiple values asseparate entries" option. This option is used to display a document between multiple calendar dates (see figure 1 ). On programmer's pane, change the display type to formula and set the column formula:
Rem "column1 contains the list of start dates as defined in theappointment form"; starttime: = @ time (calendardatetime); datelist: = @ explode (@ texttotime (@ text (calendardatetime) + "-" + @ text (enddatetime); @ texttotime (@ text (datelist) + "" + @ text (starttime ))
To set the sorting type, select the second tab in the column Properties dialog box and click the ascending radio button option. Select "showmultiple values as separate entries ". To hide the column, select the last tab in the column Properties dialog box. Double-click column1 title to bring up the Properties dialog box. Then select the hide column check box on the last tab:
Figure 6. Column Properties

Column2 is a hidden column that must contain the event duration so that the calendar view can correctly display events. If the second column does not contain a valid value, you will receive an error message. Set the column formula:
Rem "column2 contains the duration for each appointment form ";
Duration;
Use the same steps as when setting column1 to hide column2.
Column3 only displays the text value of a calendar event. This value is displayed in the actual calendar view. Set the column formula:
Rem
"Column3 represents the value displayed on the calendar ";
Person;
Alternatively, this column can contain personal names and themes, or a combination of other data elements and texts. You may also want to set the background color of this column to enhance the ease of use of the application. In this way, you can highlight entries to help you find calendar events in the view. To set the background color, select the third tab in the View Properties dialog box. The background settings are in the entry section.
Note: The column title is not displayed in the calendar view. However, by providing a column title name, you and other developers can understand the view design and the content in the column.
Set view objects and attributes
The regiondoubleclick event allows you to double-click a calendar date to automatically open a new appointment form. After the form is displayed, the start date is displayed on the calendar. This event also contains a data validity check to determine whether the selected date is before the current date. If the selected date is in the past, the user will receive the prompt: "date in past... Do you want tocontinue? "If you select Yes, the variable" Answer "is set to 6 (which is the default value automatically set by the Lotus Notes application ).
If the selected date is in the future, or the user answers yes to the above question to create a record in the past, a new appointment form will appear. The following routine is executed only when you double-click a calendar date. (Alternatively, you can select the newappointment button described later in this section, or select the create-appointment menu option .)
Sub regiondoubleclick (source as notesuiview) dim Doc asnotesdocument Dim workspace as new notesuiworkspace dim uidoc as notesuidocument dim view as notesview dim datetime as new notesdatetime ("") calldatetime. setnow ''display warning if selected date is in thepast. if source. calendardatetime <cdat (datetime. dateonly) Then answer % = MessageBox ("date inpast... do you want to continue? ", 292," Continue? ") End if ''create the appointment if date is in the past and userclicked yes, or ''create the appointment if date is in theure ure. if (answer % = 6) or (source. calendardatetime> = cdat (datetime. dateonly) then set view = source. view set uidoc = workspace. composedocument ("", "", "APPT") set Doc = uidoc. document Doc. startdate = source. calendardatetime end if end sub
You may want to add this code to any application that contains a calendar view. Therefore, you only need to change the APPT to the appropriate form name. This makes the application more user-friendly and increases ease of use.
Create action buttons for views
Select create-action-actions to create a new appointment. Set the button title to new appointment and enter the following formula in programmer's Pane:
Rem "create new calendar events ";
@ Postedcommand ([compose]; "": "APPT ")

To create a button that allows users to jump to the current calendar date, select create-action-actions. Set the button title to today and enter the following formula in programmer's Pane:
Rem "Jump to today's calendar
Date ";
@ Command ([calendargoto]; @ date (@ now ));

Save and close the view.
Congratulations, you have completed this calendar application!
Conclusion
In this article, we discuss the components of a simple single-document calendar and the components of repetitive events. We also provide instructions on how to create a simple calendar application. I hope this article will help you. Please tell us your thoughts andArticleOther topics are recommended.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.