Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.33 KB | None | 0 0
  1.  Protected Sub LoadCarbonFootprint()
  2.         Dim data As New DataCarbonFootprint
  3.         Dim ProdName As String = ""
  4.         Dim ProdNameStored As String = ""
  5.         Dim newDt As New DataTable
  6.         newDt.Columns.Add("ProdName", GetType(String))
  7.         newDt.Columns.Add("DisplayName", GetType(String))
  8.         newDt.Columns.Add("ValidityYear", GetType(Integer))
  9.         newDt.Columns.Add("Toe1", GetType(Decimal))
  10.         newDt.Columns.Add("Toe2", GetType(Decimal))
  11.         newDt.Columns.Add("Toe3", GetType(Decimal))
  12.         newDt.Columns.Add("Toe4", GetType(Decimal))
  13.         newDt.Columns.Add("Toe5", GetType(Decimal))
  14.         newDt.Columns.Add("Toe6", GetType(Decimal))
  15.         newDt.Columns.Add("Toe7", GetType(Decimal))
  16.         newDt.Columns.Add("Toe8", GetType(Decimal))
  17.         newDt.Columns.Add("Toe9", GetType(Decimal))
  18.         newDt.Columns.Add("Toe10", GetType(Decimal))
  19.  
  20.         For Each prodrow As DataRow In productList
  21. //hämtar en rad från databawsen med ProdName, MIll, Year och 10 decimalvärden
  22.             Dim dt As DataTable = data.CalculateCarbonFootprint(prodrow("productno"), prodrow("DelSupNo"), theYear.Year, 1, userId).Tables(0)
  23. //lägger in det i mina nya tabell
  24.             If dt.Rows.Count > 0 Then
  25.                 newDt.ImportRow(dt.Rows(0))
  26.             End If
  27.         Next
  28. //här är det jag funderar över. Även om ingen data finns, ska namnet samt mill visas för kund. Utan värden. Hur många rader ska ska vara kan jag se i min productList, där hitar jag även vilken produkt det är. Nedan jämför jag om de är lika stora, och om den produkten med det bruket (mill/displayname) finns i newdt, då gör jag inget, annat lägger jag in namn, bruk, år och tomma värden.
  29.         If productList.Count <> newDt.Rows.Count Then
  30.             Dim exist As Boolean
  31.             For Each prodrow As DataRow In productList
  32.                 ProdName = data.GetProdNameOnProdNo(prodrow("productno"), userId)
  33.                 For Each row As DataRow In newDt.Rows
  34.                     If row("ProdName").Trim = ProdName.Trim And prodrow("displayname").Trim = row("displayname").Trim Then
  35.                         exist = True
  36.                     End If
  37.                 Next
  38.                 If Not exist Then
  39.                     newDt.Rows.Add(ProdName, prodrow("displayname"), theYear.Year, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
  40.                 End If
  41.             Next
  42.         End If
  43.  
  44.         'TG 2018-01-18 select distinct
  45.         Dim results As DataTable = newDt.AsEnumerable().Distinct().CopyToDataTable()
  46.         For Each row As DataRow In results.Rows
  47.  
  48.             Dim info As ProductInfo = New ProductInfo(CStr(row("ProdName")).Trim, row("displayname"), row)
  49.  
  50.             products.Add(info)
  51.         Next
  52.  
  53.     End Sub
  54.     Public Class ProductInfo
  55.         Public ProductName As String
  56.         Public MillName As String
  57.         Public CarbonTable As New DataTable
  58.  
  59.         Public Sub New(ByVal bajs1 As String, ByVal bajs2 As String, ByVal dtRow As DataRow)
  60.             ProductName = bajs1
  61.             MillName = bajs2
  62.             CarbonTable = addDatarow(dtRow)
  63.         End Sub
  64.  
  65.         Public Function addDatarow(ByVal row As DataRow) As DataTable
  66.  
  67.             CarbonTable.ImportRow(row)
  68.  
  69.             Return CarbonTable
  70.         End Function
  71.     End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement