The default Web.config file added when you created the solution does not contain the configuration code needed to access the COBOL runtime and configure the project to run COBOL applications. Here, you replace the default file with a provided updated file.
<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>
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.
.
This calls the legacy program and provides input values.
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.
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.