Code the OO Web Page

Provides step-by-step instructions that guide you through the process of coding your ASP.NET Web page.

Paint the Form

  1. In the Solution Explorer, right-click Default.aspx; then select View Designer from the context menu.
  2. At the bottom of the Form Designer, click Source in the toolbar.
  3. Add the following code immediately before the closing </asp:Content> element:
        <asp:Label ID="Label1" runat="server" Text="CATALOG SEARCH"></asp:Label>
        <asp:Label ID="catalogNumberLabel" runat="server" Text="Catalog Number"></asp:Label>
        <asp:TextBox ID="textBoxStockNo" runat="server"></asp:TextBox>
        <asp:Button ID="searchButton" runat="server" Text="Search" OnClick="searchButton_Click" />
        <asp:Label ID="errorLabel" runat="server" Text="Status" Visible="False"></asp:Label>
        <asp:TextBox ID="errorField" runat="server"></asp:TextBox>
        <asp:Label ID="Label2" runat="server" Text="RESULTS"></asp:Label>
        <asp:Label ID="titleLabel" runat="server" Text="Title"></asp:Label>
        <asp:TextBox ID="textBoxTitle" runat="server"></asp:TextBox>
        <asp:Label ID="authorLabel" runat="server" Text="Author"></asp:Label>
        <asp:TextBox ID="textBoxAuthor" runat="server"></asp:TextBox>
        <asp:Label ID="typeLabel" runat="server" Text="Type"></asp:Label>
        <asp:TextBox ID="textBoxType" runat="server"></asp:TextBox>
        <asp:Label ID="priceLabel" runat="server" Text="Price"></asp:Label>
        <asp:TextBox ID="textBoxPrice" runat="server"></asp:TextBox>
        <asp:Label ID="soldLabel" runat="server" Text="Sold"></asp:Label>
        <asp:TextBox ID="textBoxSold" runat="server"></asp:TextBox>
        <asp:Label ID="onHandLabel" runat="server" Text="On Hand"></asp:Label>
        <asp:TextBox ID="textBoxOnHand" runat="server"></asp:TextBox>
        <asp:Label ID="stockValueLabel" runat="server" Text="Stock Value"></asp:Label>
        <asp:TextBox ID="textBoxStockValue" runat="server"></asp:TextBox>
    Note: This is a short-cut method to painting the form. Alternatively, you could paint the form using the Toolbox. For more information, see the Painting a Button and a Label section in Tutorial: Developing .NET COBOL Applications.
  4. Save the form, but do not close the Form Designer.

Create a Click Event

  1. At the bottom of the Form Designer, click Design.
  2. Double-click the Search button on the form.

    This opens Default.aspx.cbl in the COBOL editor, and inserts a searchButton_Click method into the code. This method is known as a Click Event. At this point in development, the method is empty.

  3. Click Save All Save All.
  4. Close the Default.aspx file in the Form Designer.

Code the searchButton_Click method

This calls the legacy program and provides input values.

  1. In the COBOL editor, edit the code for the searchButton_Click method to read as follows:
           method-id searchButton_Click protected.
           working-storage section.
           01 book type OOSqlBookWrapper.SqlBook.
           01 anException type System.Exception.
           01 bookFunction string.
           local-storage section.
    
           procedure division using by value lnkSender as object
                                    by value lnkEvent as type EventArgs.
               try
                   set book to type OOSqlBookWrapper.SqlBook::New()
                   set book::StockNumber to textBoxStockNo::Text
                   set bookFunction to "1"
                   invoke book::CallLegacyWithRunUnit(bookFunction)
                   invoke self::PopulateForm(book)
               catch anException
                   invoke self::DisplayException(anException)
               end-try
           end method.

Code the PopulateForm and DisplayException methods

  1. In the COBOL editor, add code for the PopulateForm and DisplayException methods as follows:
           method-id PopulateForm final private.
           procedure division using aBook as type OOSqlBookWrapper.SqlBook.
    
               if aBook <> null
                   set errorLabel::Visible to false
                   set errorField::Visible to false
                   set textBoxStockNo::Text    to aBook::StockNumber
                   set textBoxTitle::Text      to aBook::Title
                   set textBoxAuthor::Text     to aBook::Author
                   set textBoxType::Text       to aBook::Type
                   set textBoxPrice::Text      to type System.Convert::ToString(aBook::RetailPrice)
                   set textBoxOnhand::Text     to type System.Convert::ToString(aBook::NumberOnHand)
                   set textBoxSold::Text       to type System.Convert::ToString(aBook::NumberSold)
                   set textBoxStockValue::Text to type System.Convert::ToString(aBook::StockValue)
               else
                   set textBoxStockNo::Text    to "****"
                   set textBoxTitle::Text      to "*************************************"
                   set textBoxAuthor::Text     to "*************************************"
                   set textBoxType::Text       to "****"
                   set textBoxPrice::Text      to "****"
                   set textBoxOnhand::Text     to "****"
                   set textBoxSold::Text       to "****"
                   set textBoxStockValue::Text to "*****"
               end-if
    
           end method.
           
           method-id DisplayException private.
           procedure division using by value lnkException as type System.Exception.
               set my-book to null
               set errorLabel::Visible to true
               set errorField::Visible to true
               set errorField::Text to lnkException::Message
               invoke self::PopulateForm(my-book)
           end method.
  2. Save the file and close the editor.