Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim pb As Object = Nothing
- If radCars.Checked = True Then
- Dim productBase As ProductsBase(Of CarColumns)
- productBase = New Cars(fileLocation)
- pb = productBase
- ElseIf radTrucks.Checked = True Then
- Dim productBase As ProductsBase(Of TruckColumns)
- productBase = New Truck(fileLocation)
- pb = productBase
- End If
- pb.Parse()
- pb.AddRows()
- ....
- Public MustInherit Class ProductsBase(Of T)
- Sub New(filePathString As String)
- FilePath = filePathString
- End Sub
- MustOverride Sub Parse()
- MustOverride Sub DeleteRows()
- MustOverride Sub AddRows(ByVal rows As IEnumerable(Of T), pageNumber As Integer)
- Property ParseResult As ProductLookupContainer(Of T)
- End Class
- Public Class Cars
- Inherits ProductsBase(Of CarColumns)
- Sub New(filePath As String)
- MyBase.New(filePath)
- End Sub
- Public Overrides Sub AddRows(rows As IEnumerable(Of CarColumns), pageNumber As Integer)
- DatabaseHelper.AddItemsToDB(Of CarProduct)(ConnectionString, rows, pageNumber)
- End Sub
- Public Overrides Sub DeleteRows()
- DatabaseHelper.DeleteRows(ConnectionString, "CarProducts")
- End Sub
- Public Overrides Sub Parse()
- Dim pf As New ParseFile(FilePath)
- Dim result = New ProductLookupContainer(Of CarColumns)
- result = pf.ParseCars
- 'Set object
- ParseResult = result
- End Sub
- End Class
- Public Interface IProducts
- Sub DeleteRows()
- Sub Parse()
- End Interface
- Public Class ProductsFactory
- Public Shared Function CreateTruck(fileLocation as string) As IProducts
- Return New Truck(fileLocation)
- End Function
- Public Shared Function CreateCar(fileLocation as string) As IProducts
- Return New Car(fileLocation)
- End Function
- End Class
- Dim pb As IProducts
- If radCars.Checked = True Then
- pb = ProductsFactory.CreateCar(fileLocation)
- ElseIf radTrucks.Checked = True Then
- pb = ProductsFactory.CreateTruck(fileLocation)
- End If
- pb.Parse()
- pb.AddRows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement