Adding Application Calendars with Calendar Go! 4.0 - ' Keeping Track of Resources ' (
Page 2 of 2 )
You need to provide some means of interacting with the user to get the appointment information; I chose a dialog box. In this case, the user provides the appointment date, start time, end time, a title for the appointment, and any comments about it. The code retrieves the information from the dialog box and adds it to an Appointment object.
This example doesn't show all of the entries you can change (in fact, it only shows a fraction of them), but it does show the important properties. The code then uses the Appointments.Add() method to add the new appointment. As with the linkage example, you really don't need to write a lot of code to accomplish the task.
ADVERTISEMENT
You could use this collection for more than just appointments. For example, I created a very simple work scheduler. I know that I can complete a certain number of lines of code in a day, and that various modules will contain approximately so-many lines. In about an hour, I created a simple program to predict when I would complete each module, based on my work hours and so on. In short, the concept of an appointment could include anything from a real appointment to work you have to complete.
Balancing Resources with the ResourceScheduler Control
The ResourceScheduler control keeps track of the resources you need to accomplish tasks. A resource can be anything from time, to physical entities (such as cars), to people. You create the resource, create an appointment, and then assign the appointment a resource. The result is a Gantt chart of appointments and associated resources. You can easily see where conflicts exist and modify the times to avoid them. Figure 3 shows a typical resource scheduler view for the company car.
Figure 3: Create resource schedules of any type to help manage your environment, rather than react to it.
Working with the ResourceScheduler control is similar to working with the calendars, but it's a little more complex, as shown in Listing 3. Notice that you must add a value to the ResourceIndex property when creating an appointment in this case. However, except for that little addition, creating the appointment is about the same.
Listing 3: Working with the ResourceScheduler Control
private void mnuAddAppointment_Click(object sender,
System.EventArgs e)
{
frmAppt GetAppt = new frmAppt(); // Appointment entry form
Appointment Appt = new Appointment();// New appointment.
// Display the appointment entry form.
if (GetAppt.ShowDialog(this) == DialogResult.OK)
{
// Get the information from the form and place it in the
// new appointment.
Appt.DateBegin = Convert.ToDateTime(
GetAppt.txtDate.Text + " " + GetAppt.txtStartTime.Text);
Appt.DateEnd = Convert.ToDateTime(
GetAppt.txtDate.Text + " " + GetAppt.txtEndTime.Text);
Appt.Text = GetAppt.txtText.Text;
Appt.ToolTip = GetAppt.txtComment.Text;
// When using a resource scheduler, you must also add a
// resource number.
Appt.ResourceIndex = Int32.Parse(GetAppt.txtResource.Text);
// Add the appointement to the resource scheduler.
rsTest.Appointments.Add(Appt);
}
}
private void mnuAddResource_Click(object sender,
System.EventArgs e)
{
frmRes GetRes = new frmRes();
Resource Res = new Resource();
// Display the resource entry form.
if (GetRes.ShowDialog(this) == DialogResult.OK)
{
// Get the resource information.
Res.Text = GetRes.txtText.Text;
Res.ForceEmpty = GetRes.chkForce.Checked;
// Add the resource to the resource scheduler.
rsTest.Resources.Add(Res);
}
}
You can use a number of optional appointment features with the ResourceScheduler control. For example, by changing the BeginTerminator and EndTerminator properties, you can modify the appearance of the appointment bars. Use the LinkWithNext property to connect appointments with a line, showing that one appointment depends on the successful completion of another. You can also show the current progress on an appointment by changing the Progress property value.
As you see from the code, all you really need to create a resource is the text. Entering data in the ForceEmpty property is optional. For example, if you don't want to allow someone to override existing appointments, you would retain the default ForceEmpty value. You should also place a limit on the size of the Text property. Otherwise, the chart tends to fill with resource names, leaving a lot less space for appointments.
After working with the ResourceScheduler for a while, I discovered that I could manually change the environment to accommodate longer names, but some type of automation in this regard would have been nice. Given the purpose of the controls, this omission is minor, to say the least, and you always have the option of changing this behavior if you get the professional edition of the controls.
Displaying Alerts with the MsgBox Control
The MsgBox control is perhaps the least-special control in the package; it's a fancy version of the MessageBox class that comes with Visual Studio .NET. Instead of defining the properties for the Show() method in code, however, you define them using the Properties window. It's a convenience feature, for the most part. Of course, convenience is always helpful in getting the job done faster. You don't have to remember as much, since the control remembers it for you.
The feature that makes this control worth using is that every kind of button push has an event handler. Consequently, you can create event handlers for different situations instead of reacting to the result within your code. Although this isn't a big deal when working with single-threaded applications, it could make working with multi-threaded applications easier; you wouldn't have to stop a thread to handle the result of a user query.
Source Code Included
When you get the professional version of the Calendar Go! Bundle, you also receive the source code for the various form and calendar DLLs. Getting the source code is appreciated, because it means you can customize the calendars to meet specific needs. That isn't always a major benefit; generally, getting the source code for a package means spending hours trying to figure out someone else's code. Yet, Calendar Go! provides some of the best source code I've had the pleasure to review. The author documented all the source code heavily, and it's even set up to generate the required XML files. In fact, the XML included with the source code will reproduce the help file provided with the software. However, the author wrote the source code in C#, so you'll need to know that language to use it.
One other nice addition to the source code is the documentation the author provides. For example, you aren't left out in the cold when it comes to making the controls fully interact with the .NET environment. The software has the necessary instructions, such as generating the strong name required to use the controls globally.
Speaking of the Help file: I was a little amazed to find that Calendar Go!'s help file isn't included as part of the Visual Studio .NET Combined Collection. In fact, at first I didn't think there was any documentation at all. The documentation appears as Calendar Demo Help in the Start\Programs\Component Go!\Calendar Go! folder. Because there's a demonstration called Calendar Demo, I naturally thought that the help entry was only for the demonstration program, but it turns out that this is the tool's help file.
Other than the file naming confusion, the help file is quite usable. It does lack some of the fit and finish of other help files that I've seen, though. For example, you won't find sample code here, nor will you find explanations of how things work. You will find complete documentation for each of the controls and forms, their associated classes, and listing of events, methods, and properties. In short, the help file is usable, but it's nothing spectacular.
Bottom Line
Calendars need not require a lot of programming effort on your part. Using the Calendar Go! Bundle changes a difficult task into one where you mainly need to consider how the user will work with the calendar. Instead of spending all of your time trying to wrangle the required functionality out of the default Visual Studio .NET controls, you can spend more time with important topics, such as playing that next game of Doom or watching television.