Components in PMS

Snoops

   

 
Migrating to .NET: A Pragmatic Path to Visual Basic .NET, Visual C++ .NET, and ASP.NET
By Dhananjay  Katre, Prashant  Halari, Narayana  Rao  Surapaneni, Manu  Gupta, Meghana  Deshpande

Table of Contents
Chapter 12.   Visual Basic .NET Migration Case Study


Components in PMS

The following components have been developed in Visual Basic 6.0:

  • VBLoginCom

  • VBStockServiceCom

  • VBBuySellCom

  • VBAdminCom

  • VBReportsCom

Because the migration methodology advocates packing business logic in the form of components, the listed components have been designed. A brief description of each of these components is given in the next subsections, which also cover development aspects of PMS in Visual Basic 6.0. These components have been developed in both Visual Basic and Visual C++ to illustrate migration concepts.

VBLoginCom

The VBLoginCom component has a class cLogin . This COM component is used for customer login and logout. Also, it contains functionality that allows customers to change their password when logging into the system. The code for this is kept in the VBLoginCOM directory of this chapter. Class cLogin uses the following functions:

  • Login. The Login function has four parameters. UserID and Password are the two input parameters. The function returns the status and a related message as the output parameters. Login is used to validate the users, check whether the user is already logged in or not, and check the validity of the password entered. When a customer has been added to the system, the system generates a password with the same name , which can be changed during the first login in the system. The stored procedure sp_Validate_Login is called from this method.

  • Logout. This function takes one parameter UserID and returns two output parameters, which give the Status and the related Message with it. It allows users to log out of the system. The stored procedure sp_Logut is called from this method.

  • ChangePassword. This function takes in the UserID, the OldPassword, and the NewPassword and returns the Status and related Message as the output. This function changes the password of the user against the validity of the UserID and the OldPassword entered. Figure 12-4 shows the login screen. The stored procedure sp_Change_Password is called from this method.

    Figure 12-4. Login screen.

    graphics/12fig04.gif

All methods of the COM components are called from the CGI code. We have written the CGI component in Visual Basic 6.0, which runs under the context of IIS. This CGI component takes the environment variables by the Environ method and returns the response to the standard output. The following code shows how the methods of the VBLoginCOM component are called from the CGI project. The methods are called in the ParseQuery String method of Module2.bas . The CGI project is kept in the CGICode folder for this chapter. This code also illustrates how the Login method for the administrator login is called. The actual COM component method call is placed in the function LoginHandler .

 graphics/icon01.gif '***********LOGIN METHOD FOR ADMIN / CUSTOMER *************     If (strMethodName = "login") _      Or (strMethodName = "adminlogin") Then        strCustomerId = ""        strPassword = ""        p = InStr(j, Urlstr, "=", vbTextCompare)        q = InStr(j + 1, Urlstr, "&", vbTextCompare)        strCustomerId = Mid(Urlstr, p + 1, q - (p + 1))        pp = InStr(p + 1, Urlstr, "&", vbTextCompare)        qq = InStr(q + 1, Urlstr, "=", vbTextCompare)        strPassword = Mid(Urlstr, qq + 1, _         intQueryStringLength)        intReturnCode = LoginHandler(strCustomerId, _         strPassword, strMessage, strMethodName)        Send intReturnCode & "^" & strMessage     End If  Public Function LoginHandler(strUser As String, _   strPassword As String, ByRef strMessage As String,_    strMethod As String) As Integer     If strMethod = "login" Then        LoginHandler = loginObj.Login(strUser, _         strPassword, strMessage)     Else        LoginHandler = adminObj.Login(strUser, _         strPassword, strMessage)     End If  End Function 

Now let us see how the CGI code gets called from the TraderWorkStation application. The following code shows how the login method of the VBLoginCOM is called when the OK command in the login form shown in Figure 12-4 is invoked. The TraderWorkStation code is kept in the TraderWorkstation folder for this chapter.

 graphics/icon01.gif Private Sub cmdOK_Click()     Dim sval As String     Dim msg As String     Dim strURL As String     Dim nlen As Integer     Dim i As Integer     Dim istat As String     On Error GoTo errlabel     cmdOK.Enabled = False     cmdCancel.Enabled = False     cmdChangePassword.Enabled = False     strURL = "http://"     strURL = strURL & GetCGIServerName("Server")     strURL = strURL & "/Scripts/"     strURL = strURL & "Stock_System_CGI_trial.exe?"     strURL = strURL & "method=login&param1="     strURL = strURL & txtName.Text     strURL = strURL & & "&param2=" & txtPassword.Text     sval = Inet1.OpenURL(strURL)     cmdOK.Enabled = True     cmdCancel.Enabled = True     cmdChangePassword.Enabled = True     nlen = Len(sval)     i = InStr(1, sval, "^", vbTextCompare)     istat = Left(sval, i - 1)     msg = Mid(sval, i + 1, nlen - i)     If ((istat = "0") Or (istat = "4")) Then        Me.Hide        frmDocument.Show     End If     If ((istat = "2") Or (istat = "3")) Then        txtName.Text = ""        txtPassword.Text = ""        MsgBox msg        OK = False     Else        strUserID = txtName.Text        OK = True     End If     Me.Hide     Exit Sub  errlabel:      MsgBox ("Exception occurred is:" & Err.Description)      cmdOK.Enabled = True      cmdCancel.Enabled = True  End Sub 

The server name has to be changed in the stocksystems.ini file. It has to be changed to localhost or the number of the PC on which you are compiling the CGI code. The CGI code has to be compiled in the Scripts subdirectory of the Inetpub folder of your system.

VBStockServiceCom

The VBStockServiceCom component is used by the system to display the current stocks in the system. When the TraderWorkStation application is loaded, the form lists all the stocks present in the database along with the details and the current prices. The MDI form has the menu items Reports and Quit on it.

The code for this is kept in the VBStockservice directory of this chapter. This COM component has a class called cStockService , which in turn defines the GetStockPrices function for obtaining the latest prices of the stock. This function gives an output of all the stocks in the database along with the details, a Status, and the related Message. The stored procedure sp_Get_Current_Stock_Prices is called from this function. Figure 12-5 shows a screen of stock names , current price, date/time, low price, high price, opening price, closing price, and last traded quantity. This function is called from the CGI project. The stock values are converted into XML format and returned to the TraderWorkStation application where the MS-XML parser is used to parse the XML file and display on the following screen.

Figure 12-5. Stock service screen.

graphics/12fig05.jpg

VBBuySellCom

The VBBuySellCom component deals with the transactions created by the users. It is used to complete the buy and sell transactions of the users for the various stocks. It contains the class cBuySell . The code for this is kept in the VBBuySellCOM directory of this chapter. This class cBuySell uses the PlaceOrder function. This function uses five parameters. The input parameters are the UserID, stockID, current price, quantity, and the type of transaction (buy or sell). The output parameters are the Status and the related Message . The stored procedure sp_Order is called from this method. This has been captured in Figure 12-5. The Transaction section of Stock Service screen allows customer to place an order .

VBAdminCom

The SurveillanceMonitor system used by the administrator uses the VBAdminCom. The code for this is kept in the VBAdminCOM directory of this chapter. The starting form for surveillance monitoring system is an MDI form with following menu items on it:

  • Customer information

  • Order approval

  • Reports

  • Help

  • Quit

The surveillance monitoring system will be available only to an administrator. The class associated with it is the cAdmin class. The COM component is used to log in the administrator, change the administrator password, add new users, update the existing user information, and get the list of unapproved transactions. The functions used in this class are

  • Login. This function is used to verify the user as the administrator and the password. The stored procedure called is sp_Validate_Admin_Login (see Figure 12-4).

  • Change Password. This function is used to authenticate the user and then change the password of the administrator. The stored procedure called is sp_Change_Admin_Password . This function has been incorporated with screen shown in Figure 12-4.

  • AddUser. This function is called in the Add New User Form to add the details of a new user in the database. The stored procedure called is sp_Customer . Figure 12-6 shows screen for adding a new user in the system.

    Figure 12-6. Screen for adding user in the system

    graphics/12fig06.gif

The screen in Figure 12-6 has fields such as CustomerID, CustomerName, and CustomerAddress. Through this screen the administrator should be able to add, delete, and update the customer information:

  • UpdateUser. This function is used to update the details of existing users. The stored procedure called is sp_Update_Customer . This function has been used in providing logic for Figure 12-6.

  • GetUnapprovedOrders. This function is used to get the list of the unapproved orders for the customers. The stored procedure called is sp_Get_Unapproved_Orders . This function has been used in providing logic for Figure 12-7, which shows a list of unapproved orders.

    Figure 12-7. Screen displaying list of unapproved orders.

    graphics/12fig07.gif

  • ApproveOrder. This function is used by the Order Approval form to approve a pending order and shift it into the approved list of orders. The stored procedure called is sp_Approved_Order .

  • CancelOrder. This function is used by the Order Approval form to cancel a pending order and shift the related information into the rejected list of orders. The stored procedure called is sp_Cancel_Order .

  • GetCustomers. This function returns all the list of all the customers registered in the system. The stored procedure called is sp_Get_Customer_Name . The Order Approval and the Customer Details forms use this function.

  • ViewCustomerDetails. This COM function is used in the Customer Details form to view all the details of a particular customer. The stored procedure called is sp_View_Customer_Details .

  • ReportApprovedOrders. This function is used in the Reports form of the application to obtain a list, with all the details, of the orders that have been approved by the administrator so far. The procedure called is sp_Get_Unapproved_Orders . Figure 12-8 shows a list of approved orders.

    Figure 12-8. Screen showing list of approved and unapproved orders.

    graphics/12fig08.gif

  • ReportCancelledOrders. This function is used in the Reports form of the application to obtain a list of all the orders that have been rejected by the administrator so far. The procedure sp_Get_ Cancelled_Orders is called. Figure 12-8 shows a list of unapproved orders.

VBReportsCOM

The VBReportsCOM is used by the TraderWorkStation System Reports form to create various kinds of reports. The code for this is kept in the VBReportsCOM directory of this chapter. The functions used in this class are as follows :

  • GetStockPerformance. This COM function is used in the view Stock Performance report, and it checks the prices of a selected stock for the last week. The stored procedure called is sp_Get_Prices_For_Week .

  • GetStocks. This function is used to return details of all the stocks in the system. The stored procedure called is sp_Get_All_Stocks .

  • GetUnapprovedOrders. This function is used to list all the unapproved orders for a particular customer. The customer can specify buy or sell orders as criteria. The stored procedure called is sp_Get_Unapproved_Orders .

  • ReportApprovedOrders. This function is used to list all the approved orders for a particular customer. The customer can specify buy or sell orders as criteria. The stored procedure called is sp_Get_Approved_Orders .

  • ReportCancelledOrders. This function is used in the Reports form of the application to obtain a list of all the orders that have been rejected by the administrator so far. The procedure sp_Get_ Cancelled_Orders is called. Figure 12-8 shows list of unapproved orders.


Snoops

   
Top


Migrating to. NET. A Pragmatic Path to Visual Basic. NET, Visual C++. NET, and ASP. NET
Migrating to. NET. A Pragmatic Path to Visual Basic. NET, Visual C++. NET, and ASP. NET
ISBN: 131009621
EAN: N/A
Year: 2001
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net