Testing the Employee Maintenance Function


As before, you need to make an entry in the database and add some code to frmMain to be able to test your Employee objects. Take the following steps to test the Employee objects:

  1. Rebuild the solution.

  2. Copy the NorthwindDC and NorthwindShared objects to the \bin folder in IIS.

  3. Edit the web.config file and add the following wellknown tag:

     <wellknown mode="Singleton"    type="NorthwindTraders.NorthwindDC.EmployeeDC, NorthwindDC"    objectUri="EmployeeDC.rem"/> 

  4. Next, edit frmMain and add a new Case statement to the MainMenu_Click method as follows:

     Case "&Employees"      LoadEmployees() 

  5. Add a new module-level variable to frmMain for the frmEmployeeList form:

     Private WithEvents mfrmEmployeeList As frmEmployeeList 

  6. Next, add a LoadEmployees method as shown in Listing 9-37.

    Listing 9-37: The LoadEmployees Method

    start example
     Private Sub LoadEmployees()      Try           If mfrmEmployeeList Is Nothing Then                Cursor = Cursors.WaitCursor                mfrmEmployeeList = New frmEmployeeList()                mfrmEmployeeList.MdiParent = Me                mfrmEmployeeList.Show()           Else                mfrmEmployeeList.Focus()           End If      Catch exc As Exception           LogException(exc)      Finally           Cursor = Cursors.Default      End Try End Sub 
    end example

The last thing you need to do is add a method that sets the mfrmEmployeeList equal to nothing when the Employee List form closes:

 Private Sub mfrmEmployeeList_Closed(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles mfrmEmployeeList.Closed    mfrmEmployeeList = Nothing End Sub 

Now you can run the application and play with it a little. To see how the server-side errors are handled, change the birth date to the current day. No error will be generated until you click the OK button; then you will see the error returned by the server!

Caution

The beta version of .NET 1.1 this was tested against produced an interesting error. When you try to save an employee record with no photo, it fails. Trying this in version 1.0 worked fine, though. The reason it is failing is because even when you assign a value of DBNull.Value to a photo parameter, it actually assigns a value of "." and there is no way to get rid of it.




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

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