Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf
CREATING A CLASS LIBRARY |
Chapter 16 |
551 |
|
|
|
|
|
<HEAD>
<title>WebForm1</title>
<meta name=”GENERATOR” Content=”Microsoft Visual Studio 7.0”> <meta name=”CODE_LANGUAGE” Content=”C#”>
<meta name=”vs_defaultClientScript” content=”JavaScript”>
<meta name=”vs_targetSchema” content=”http://schemas.microsoft.com/ intellisense/ie5”>
</HEAD>
<body MS_POSITIONING=”GridLayout”>
<form id=”Form1” method=”post” runat=”server”>
<asp:Button id=”Button1” style=”Z-INDEX: 101; LEFT: 73px; POSITION: absolute; TOP: 206px” runat=”server” Text=”Calculate TAX” Width=”122px” Height=”36px” Font-Bold=”True”></asp:Button>
<asp:Label id=”Label1” style=”Z-INDEX: 104; LEFT: 13px; POSITION: absolute; TOP: 62px” runat=”server” Width=”92px” Height=”27px” Font-Bold=”True”>Total Salary:</asp:Label>
<asp:TextBox id=”TextBox1” style=”Z-INDEX: 102; LEFT: 135px; POSITION: absolute; TOP: 61px” runat=”server” Width=”129px” Height=”23px” AutoPostBack=”True”></asp:TextBox>
<asp:DropDownList id=”DropDownList1” style=”Z-INDEX: 103; LEFT: 136px; POSITION: absolute; TOP: 117px” runat=”server” Width=”127px” Height=”27px”>
<asp:ListItem Value=”1”>Manager</asp:ListItem> <asp:ListItem Value=”2”>Executives</asp:ListItem> <asp:ListItem Value=”3”>Junior Staff</asp:ListItem> </asp:DropDownList>
<asp:Label id=”Label2” style=”Z-INDEX: 105; LEFT: 27px; POSITION: absolute; TOP: 263px” runat=”server” Width=”280px” Height=”69px” Font-Bold=”True” Font-Names=”Arial Black”></asp:Label>
<asp:RequiredFieldValidator id=”RequiredFieldValidator1” style=”Z-INDEX: 106; LEFT: 142px; POSITION: absolute; TOP: 90px” runat=”server” ErrorMessage=”ERROR: Please enter a valid salary” ControlToValidate=”TextBox1”></asp:RequiredFieldValidator>
<asp:Label id=”Label3” style=”Z-INDEX: 107; LEFT: 14px; POSITION: absolute; TOP: 116px” runat=”server” Width=”108px” Height=”37px” FontBold=”True”>Choose Grade:</asp:Label>
<asp:Label id=”Label4” style=”Z-INDEX: 108; LEFT: 40px; POSITION: absolute; TOP: 5px” runat=”server” Font-Bold=”True” Height=”32px” Width=”226px” Font-Names=”Arial Black” BackColor=”#C0C0FF” BorderWidth=”3px”>Simple Tax
CREATING A CLASS LIBRARY |
Chapter 16 |
553 |
|
|
|
|
|
All that is now left for you to do is to use the functionality of the class library in your ASP.NET application. In the Web form, double-click on the Calculate Tax button. This will open the code for the event handler for the Click event in the editor. Add the following code to the event handler:
private void Button1_Click(object sender, System.EventArgs e)
{
int taxv; int sal; int grd;
sal = Convert.ToInt32(TextBox1.Text);
grd = Convert.ToInt32(DropDownList1.SelectedItem.Value); TaxCalculator.Class1 obj1 = new TaxCalculator.Class1(); taxv = obj1.CalculateTotalTax(sal,grd);
TextBox2.Text = Convert.ToString(sal - taxv);
Label2.Text = “Note: Your Total Tax liability is Rs. “ + taxv;
}
ASP.NET applications need to have a page designated as the start page. This is the page that will be opened when a browser connects to the virtual directory containing the ASP.NET application. To do this, right-click the ASPX file in the project and select Set As Start Page.
Now you can build the application. Once built, the application can be tested by connecting to the virtual directory where you initially stored your ASP.NET application.
NOTE
As part of this chapter, you were introduced to Visual C#.NET — a new addition to the family of languages. If you are interested in knowing more about Visual C#.NET, Appendix E gives you an overview of Visual C#.
554 Project 4 CREATING A MANAGED EXTENSIONS CLASS LIBRARY
Summary
In this chapter, you created a simple Managed C++ class library and used the class library to house business logic for an ASP.NET application created using C#. This chapter showed how you can leverage existing business logic libraries written in C++ for .NET Web applications.
PARTVIProfessional
Project – 5
This page intentionally left blank
Project 5
Creating a COM
Component
Using ATL
