Exploring the TimeCheck Application (Part 13)

The previous post (Exploring the TimeCheck Application (Part 12)) discussed how to manage the project and task entries that the user needs to sign into the system. In this post, you see the code used to manage the remaining configuration options on frmConfigure. The last administrator-specific configuration options are the Allow Custom Project and Allow Custom Task Entry check boxes. Checking these two boxes will allow the user to type non-standard entries for signing into the system. Otherwise, the user must sign in using the administrator-provided options. Providing separate configuration options makes sense because there are times when you want to control these features individually. Here is the simple code used for the check box CheckChanged event handlers.

private void chkCustomProject_CheckedChanged(object sender, EventArgs e)
{
   // Modify the status of the group data to match the
   // checked status of the checkbox.
   GroupData.CustomProject = chkCustomProject.Checked;
 
   // Save the data to disk.
   GroupSettings.SaveSettings(GroupData);
}
 
private void chkCustomWork_CheckedChanged(object sender, EventArgs e)
{
   // Modify the status of the group data to match the
   // checked status of the checkbox.
   GroupData.CustomTask = chkCustomWork.Checked;
 
   // Save the data to disk.
   GroupSettings.SaveSettings(GroupData);
}

As you can see, the event handlers simply make a change to the GroupData properties and then save GroupData to disk. Other parts of the application read the GroupData information and use it to configure the interface as appropriate. As with other administrator-level settings, you’ll see how to hide these options in a later post. For now, all you’re trying to do is create a working application.

One of the configuration options, Network Location, is administrator-specific, even though the application stores it as part of the user settings. Hiding the setting from view is helpful, but realistically, this is one option that the user can change without permission by editing the configuration file directly. Most users won’t have the required skills, but you need to be aware of the potential for problems with this one setting. Here is the code used to set the network location that is used to provide a pointer to group data on the server.

private void btnNetSelect_Click(object sender, EventArgs e)
{
   // Display the network location selector.
   if (NetworkSelect.ShowDialog(this) == DialogResult.OK)
   {
 
      // Place the selected location in the textbox.
      txtNetLocation.Text = NetworkSelect.SelectedPath;
 
      // Save the data to disk.
      UserData.NetworkPath = NetworkSelect.SelectedPath;
      UserSettings.SetUserSettings(UserData);
   }
}

Notice that the application shows the NetworkSelect dialog box to the user. If the user chooses a new network location and clicks OK, the application will change the network location in the txtNetLocation text box and also saves the data to disk.

The last two configuration options are user-specific, so you always see them displayed on screen. The user needs to be able to select a default project and task. Doing so makes the task of logging into the system easier and faster. Anything that speeds user activities will only give the reader more reasons to use your application. Here is the code used for these last two options.

private void cbProjectName_SelectedIndexChanged(object sender, EventArgs e)
{
   // Modify the user data to reflect the change
   // in default project selection.
   UserData.DefaultProject = cbProjectName.SelectedItem.ToString();
 
   // Save the data to disk.
   UserSettings.SetUserSettings(UserData);
}
 
private void cbWorkType_SelectedIndexChanged(object sender, EventArgs e)
{
   // Modify the user data to reflect the change
   // in default task selection.
   UserData.DefaultTask = cbWorkType.SelectedItem.ToString();
 
   // Save the data to disk.
   UserSettings.SetUserSettings(UserData);
}

As in other cases in this post, the application stores the information in the appropriate place and then stores it on disk. At this point, you have all of the code required to configure the application for use. Next week, we’ll discuss the remaining code used to make frmConfigure work. Let me know if you have any questions about this segment of the code at John@JohnMuellerBooks.com.