RabbitMQ

Sub Read/Write Data c/ DataSet

'''
''' Rotina para atualizar Valores
'''

Private Sub SplitValores()
'dt.Rows(linha)(0) -> id
'dt.Rows(linha)(1) -> DataI
'dt.Rows(linha)(2) -> DataF
'dt.Rows(linha)(3) -> Valor

Dim dsProjeto As Data.DataSet = cldProjeto.GetProjetos()

Dim xQtdAnos As Integer = 0
Dim XANO As Integer
Dim XANOi As Integer
Dim XANOf As Integer
Dim XVALOR As Double
Dim XVALOR_TOTAL As Double

Dim XNAOEXECUTA As Boolean
Dim linha As Integer = 0
Dim dr As Data.DataRow
Dim dt As Data.DataTable

dt = dsProjeto.Tables(0)

For Each dr In dt.Rows
   xQtdAnos = DateDiff(DateInterval.Year, Convert.ToDateTime(dt.Rows(linha)(1)),    Convert.ToDateTime(dt.Rows(linha)(2)))
   xQtdAnos = xQtdAnos + 1 '+1 para funcionar calculo do split
   XANOi = Year(Convert.ToDateTime(dt.Rows(linha)(1)))
   XANOf = Year(Convert.ToDateTime(dt.Rows(linha)(2)))

If Not IsDBNull(dt.Rows(linha)(3)) Then
   XVALOR_TOTAL = dt.Rows(linha)(3)
   XVALOR = (XVALOR_TOTAL / xQtdAnos)
   XANO = XANOi XNAOEXECUTA = False
Else
   XNAOEXECUTA = True
End If

If Not XNAOEXECUTA Then
       If xQtdAnos > 1 Then
         Call cldProjeto.Delete_Valores_Projeto(dt.Rows(linha)(0))
            While (XANOf >= XANO)
               Call cldProjeto.Insert_Valores_Projeto(dt.Rows(linha)(0), XANO, XVALOR)
               XANO = XANO + 1
            End While
         ElseIf xQtdAnos = 1 Then
            Call cldProjeto.Delete_Valores_Projeto(dt.Rows(linha)(0))                    
            Call cldProjeto.Insert_Valores_Projeto(dt.Rows(linha)(0), XANO, XVALOR)
         End If
End If
      linha = linha + 1
   Next
   dsProjeto.Dispose()
End Sub

Comments