Exercise 2 - Create Weather WinForm Application

Version 6

    Estimated Completion Time: 8 hrs


    Objective: Create your own AF applet for end users to be able to:


    1. Select the PI AF server they want to connect to.
    2. Select the city to view its attributes.
    3. Choose one of the 6 attributes to view the data.
    4. Choose the UOM.
    5. Specify the start time and end time.
    6. Choose the retrieval method (Recorded, Interpolated, or Summary).
      1. If the selected method is Interpolated, the user must choose the interval for the interpolation.
      2. If the selected method is Summary, the results will be shown using the default UOM, for the entire time range, and be time-weighted.
    7. If the user clicks on Get Data, the results/values should appear on the ListBox with the selected UOM.
    8. If the user clicks on View Element Settings, another form with the settings of the selected city/element would appear.


    IMPORTANT TIP: To find help on the AF UI controls, search your local drives at %PIHOME%\help\AFUIRef.chm.


    You should develop something similar to the screenshots below.  It does not have to look exactly as shown.  The more adventurous may choose to use a DataGridView instead of a ListBox:

         Exercise 2_1.png


    The above was for Recorded Values, so you will note that the Interval combo box appears disabled.  Below is for Interpolated, and you will note that Interval combo box is enabled.


         Exercise 2_2.png


    Both of the previous 2 examples use 2 columns in the list box to display values.  For Summary, there is an extra column in the ListBox in order to show which summary type is being displayed.  The Summary is time-weighted and aggregates for the full timerange.


    Exercise 2_3.png


    Finally, here's a shot of viewing AF properties when the user clicks on "View Element Settings".

         Exercise 2_4.png


    Remember that your application should handle all types of errors (example: Invalid StartTime or EndTime, City element not selected when clicking on Get Data, etc.)


    Tip: The following objects should be used in this exercise:









    About the Interval ComboBox:


    Feel free to make something suitable for your company needs.  Example code used in the above screenshots:


    private void FillIntervalPicks()
        cboxInterval.SelectedIndex = 2;



    Tips on calling a form dependent upon another form


    Let's say you have a form named MainForm and it needs to open a form named AttributesForm and somehow MainForm needs to let AttributesForm what AFElement to use.  That is to say that AttributesForm depends on something from MainForm.  It is against Microsoft's best practices for AttributesForm to directly access controls on MainForm.  One way around this is that you would have a read-only public property in MainForm expose its control's current value.  Yet another way that works particularly well in this use-case is to have AttributesForm's constructor require an AFElement as an argument.  Then all MainForm needs to do is create the AttributesForm while simultaneously passing the currently selected AFElement.


    Look for help in your local drives at %PIHOME%\help\AFUIRef.chm.  You are encouraged to research these methods:

    • AFViewControl.AFSetObject
    • AFViewControl.AFSelection


    Please use this discussion forum to discuss any ideas or questions related to Exercise 2