coletteck8
asked on
method that returns a class
not sure how to explain and this might be too vague, but- i am working on a project with another person and am not sure how to use what they wrote since i'm unfamiliar with this level of code. could someone please help explain how i would use a method that is returning a class? i need to pass a value to the method and am unsure how to do that since it returns a class. i also need to take the results of the method and assign some of the data to labels on a form. if someone has a site with further information, maybe that would help also?
#Region "GetPermit"
Friend Function GetPermit(ByVal permitId As Integer) As PSI.Common.Permit
Dim cn As SqlConnection = Me.CreateConnection()
cn.Open()
Dim retval As Permit = Me.GetPermitImpl(permitId, cn)
cn.Close()
Return retval
End Function
Private Function GetPermitImpl(ByVal permitId As Integer, ByVal cn As System.Data.SqlClient.SqlC onnection) As PSI.Common.Permit
Dim cmd As New SqlCommand("spPermit", cn)
Dim dt As New DataTable
Dim p As Permit
Dim imgr As New InspectionMgr
'Permit
With cmd
.CommandType = CommandType.StoredProcedur e
.Parameters.Add("@PermitId ", SqlDbType.Int).Value = permitId
.Parameters.Add("@Mode", SqlDbType.VarChar).Value = "SELECT"
End With
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
If dt.Rows.Count = 0 Then
cn.Close()
Return New Permit
End If
p = New Permit(dt.Rows(0))
'Applicant, Property and Municipality
p.Applicant = Me.GetApplicant(p.Applican tIdLink)
p.Applicant.[Property] = Me.GetProperty(p.Applicant .PropertyI dLink)
p.Applicant.[Property].Mun icipality = Me.GetMunicipality(p.Appli cant.[Prop erty].Muni cipalityId Link)
'PermitContractor relationships
cmd = New SqlCommand("spPermitContra ctor", cn)
dt = New DataTable
With cmd
.CommandType = CommandType.StoredProcedur e
.Parameters.Add("@PermitId Link", SqlDbType.Int).Value = p.PermitId
.Parameters.Add("@Mode", SqlDbType.VarChar).Value = "SELECTBYPERMIT"
End With
da = New SqlDataAdapter(cmd)
da.Fill(dt)
'Inspections and Contractors
For i As Integer = 0 To dt.Rows.Count - 1
Dim c As New PermitContractor(dt.Rows(i ))
Dim dt2 As DataTable
c.Contractor = Me.GetContractorImpl(c.Con tractorIdL ink, cn)
c.ContractorType = Me.GetContractorType(c.Con tractorTyp eIdLink, cn)
dt2 = imgr.GetInspections(c.Perm itContract orId, cn)
For ii As Integer = 0 To dt2.Rows.Count - 1
Dim ins As New Inspection(dt2.Rows(ii))
ins.InspectionType = imgr.GetInspectionType(ins .Inspectio nTypeIdLin k, cn)
c.Inspections.Add(ins)
Next
p.PermitContractors.Add(c)
Next
Return p
End Function
#End Region
#Region "GetPermit"
Friend Function GetPermit(ByVal permitId As Integer) As PSI.Common.Permit
Dim cn As SqlConnection = Me.CreateConnection()
cn.Open()
Dim retval As Permit = Me.GetPermitImpl(permitId,
cn.Close()
Return retval
End Function
Private Function GetPermitImpl(ByVal permitId As Integer, ByVal cn As System.Data.SqlClient.SqlC
Dim cmd As New SqlCommand("spPermit", cn)
Dim dt As New DataTable
Dim p As Permit
Dim imgr As New InspectionMgr
'Permit
With cmd
.CommandType = CommandType.StoredProcedur
.Parameters.Add("@PermitId
.Parameters.Add("@Mode", SqlDbType.VarChar).Value = "SELECT"
End With
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
If dt.Rows.Count = 0 Then
cn.Close()
Return New Permit
End If
p = New Permit(dt.Rows(0))
'Applicant, Property and Municipality
p.Applicant = Me.GetApplicant(p.Applican
p.Applicant.[Property] = Me.GetProperty(p.Applicant
p.Applicant.[Property].Mun
'PermitContractor relationships
cmd = New SqlCommand("spPermitContra
dt = New DataTable
With cmd
.CommandType = CommandType.StoredProcedur
.Parameters.Add("@PermitId
.Parameters.Add("@Mode", SqlDbType.VarChar).Value = "SELECTBYPERMIT"
End With
da = New SqlDataAdapter(cmd)
da.Fill(dt)
'Inspections and Contractors
For i As Integer = 0 To dt.Rows.Count - 1
Dim c As New PermitContractor(dt.Rows(i
Dim dt2 As DataTable
c.Contractor = Me.GetContractorImpl(c.Con
c.ContractorType = Me.GetContractorType(c.Con
dt2 = imgr.GetInspections(c.Perm
For ii As Integer = 0 To dt2.Rows.Count - 1
Dim ins As New Inspection(dt2.Rows(ii))
ins.InspectionType = imgr.GetInspectionType(ins
c.Inspections.Add(ins)
Next
p.PermitContractors.Add(c)
Next
Return p
End Function
#End Region
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
in addition, the method above in my first question is in a separate class(called PermitMgr) from the two forms.
ASKER
Dim pt = New Point(e.X, e.Y)
Dim IntID As Integer
Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid1.CurrentCell = New DataGridCell(hti.Row, hti.Column)
DataGrid1.Select(hti.Row)
IntID = CType(RTrim(DataGrid1.Item
I need to pass the value above (IntID) into the method in my first question, however, i would like the return to be usable in form1 so that i can populate label boxes with the return. I'm not at all sure how to do this.