daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim pb As Object = Nothing
  2.  
  3.  If radCars.Checked = True Then
  4.  
  5.      Dim productBase As ProductsBase(Of CarColumns)
  6.      productBase = New Cars(fileLocation)
  7.  
  8.      pb = productBase
  9.  
  10.   ElseIf radTrucks.Checked = True Then
  11.  
  12.      Dim productBase As ProductsBase(Of TruckColumns)
  13.      productBase = New Truck(fileLocation)
  14.  
  15.      pb = productBase
  16.  
  17.   End If
  18.  
  19.   pb.Parse()
  20.   pb.AddRows()
  21.   ....
  22.    
  23. Public MustInherit Class ProductsBase(Of T)
  24.  
  25.     Sub New(filePathString As String)
  26.         FilePath = filePathString
  27.     End Sub
  28.  
  29.     MustOverride Sub Parse()
  30.     MustOverride Sub DeleteRows()
  31.     MustOverride Sub AddRows(ByVal rows As IEnumerable(Of T), pageNumber As Integer)
  32.  
  33.     Property ParseResult As ProductLookupContainer(Of T)
  34.  
  35. End Class
  36.    
  37. Public Class Cars
  38.     Inherits ProductsBase(Of CarColumns)
  39.  
  40.     Sub New(filePath As String)
  41.         MyBase.New(filePath)
  42.     End Sub
  43.  
  44.     Public Overrides Sub AddRows(rows As IEnumerable(Of CarColumns), pageNumber As Integer)
  45.         DatabaseHelper.AddItemsToDB(Of CarProduct)(ConnectionString, rows, pageNumber)
  46.     End Sub
  47.  
  48.     Public Overrides Sub DeleteRows()
  49.         DatabaseHelper.DeleteRows(ConnectionString, "CarProducts")
  50.     End Sub
  51.  
  52.     Public Overrides Sub Parse()
  53.  
  54.         Dim pf As New ParseFile(FilePath)
  55.         Dim result = New ProductLookupContainer(Of CarColumns)
  56.         result = pf.ParseCars
  57.  
  58.        'Set object
  59.        ParseResult = result
  60.  
  61.     End Sub
  62.  
  63. End Class
  64.    
  65. Public Interface IProducts
  66.  
  67.     Sub DeleteRows()
  68.     Sub Parse()
  69.  
  70. End Interface
  71.    
  72. Public Class ProductsFactory
  73.  
  74.     Public Shared Function CreateTruck(fileLocation as string) As IProducts
  75.          Return New Truck(fileLocation)
  76.     End Function
  77.  
  78.     Public Shared Function CreateCar(fileLocation as string) As IProducts
  79.          Return New Car(fileLocation)
  80.     End Function
  81.  
  82. End Class
  83.    
  84. Dim pb As IProducts
  85.  
  86.   If radCars.Checked = True Then  
  87.      pb = ProductsFactory.CreateCar(fileLocation)
  88.   ElseIf radTrucks.Checked = True Then
  89.      pb = ProductsFactory.CreateTruck(fileLocation)
  90.   End If
  91.  
  92.   pb.Parse()
  93.   pb.AddRows()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top