frmFlujoArbitraje.vb 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. Public Class frmFlujoArbitraje
  2. Dim ds As New DataSet
  3. Private Operaciones As New Operaciones
  4. Private FlujoArbitrajeDAO As New FlujoArbitrajeDAO
  5. Dim Todos As String = String.Empty
  6. Dim dsOrdenado As New DataSet
  7. Dim PosicionBucles As Integer = 0
  8. Public CodigoA As String = String.Empty
  9. Sub New()
  10. ' Esta llamada es exigida por el diseñador.
  11. InitializeComponent()
  12. ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
  13. End Sub
  14. Sub New(CodigoAsociado As String)
  15. Me.New
  16. Me.CodigoA = CodigoAsociado
  17. End Sub
  18. Private Sub frmFlujoArbitraje_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  19. OrdenarTablas()
  20. 'GeneradorFlujo()
  21. AgregarEstructura()
  22. End Sub
  23. Sub RecorrerOrdenarTablas(ByRef Tabla As DataTable, ByRef Cantidad As Integer, ByRef PosicionTabla As Integer)
  24. Dim TablaPadre As New DataTable
  25. TablaPadre = Tabla.Copy
  26. For Each FilasTabla As DataRow In TablaPadre.Rows
  27. Dim Indice As Integer = 0
  28. Dim Index As Integer = PosicionTabla
  29. Dim NivelAnterior As Integer = 0
  30. Indice = FilasTabla("Indice")
  31. While Index <= Cantidad
  32. Dim JIndice As Integer = 0
  33. Dim TablasHijas As DataTable = ds.Tables(Index).Copy
  34. For Each JFilasTabla As DataRow In TablasHijas.Rows
  35. JIndice = JFilasTabla("NivelAnterior")
  36. If JIndice = Indice Then
  37. If Not dsOrdenado.Tables.Contains(TablasHijas.TableName) Then
  38. PosicionBucles += 1
  39. TablasHijas.Rows.Add(0, 0, "Posicion", PosicionBucles)
  40. dsOrdenado.Tables.Add(TablasHijas)
  41. RecorrerOrdenarTablas(TablasHijas, Cantidad, Index)
  42. PosicionBucles -= 1
  43. End If
  44. Exit For
  45. End If
  46. Next
  47. Index += 1
  48. End While
  49. Next
  50. End Sub
  51. Sub OrdenarTablas()
  52. ds = FlujoArbitrajeDAO.CargarArbitraje(Me.CodigoA)
  53. Dim Index As Integer = 0
  54. Dim CantidadTablas As Integer = ds.Tables.Count - 1
  55. While Index <= CantidadTablas
  56. Dim TablaRaiz As New DataTable
  57. TablaRaiz = ds.Tables(Index).Copy
  58. If Not dsOrdenado.Tables.Contains(TablaRaiz.TableName) Then
  59. TablaRaiz.Rows.Add(0, 0, "Posicion", Index)
  60. dsOrdenado.Tables.Add(TablaRaiz)
  61. RecorrerOrdenarTablas(TablaRaiz, CantidadTablas, Index)
  62. End If
  63. Index += 1
  64. End While
  65. ds.Dispose()
  66. ds = New DataSet
  67. ds = dsOrdenado
  68. End Sub
  69. Sub GeneradorFlujo()
  70. Dim CantidadTablas As Integer = ds.Tables.Count - 1
  71. Dim Index As Integer = 0
  72. While Index <= CantidadTablas
  73. Dim dgvTablas As New DataGridView
  74. dgvTablas.DataSource = ds.Tables(Index)
  75. flpContenedorTemporal.Controls.Add(dgvTablas)
  76. Index += 1
  77. End While
  78. End Sub
  79. Sub AgregarEstructura()
  80. Dim ds As New DataSet
  81. ds = Me.ds
  82. Dim CantidadTablas As Integer = ds.Tables.Count - 1
  83. Dim Index As Integer = 0
  84. While Index <= CantidadTablas
  85. Dim Tabla As New DataTable
  86. Tabla = ds.Tables(Index)
  87. Dim Codigo As String = String.Empty
  88. Dim Reporto As String = String.Empty
  89. Dim CodigoTitulo As String = String.Empty
  90. Dim NivelAnterior As Integer = 0
  91. For Each Filas As DataRow In Tabla.Rows
  92. If Filas("Descripcion") = "Raiz" Then
  93. If String.IsNullOrEmpty(Codigo) Then
  94. Codigo += " " + Filas("Codigo")
  95. Else
  96. Codigo += "," + Filas("Codigo")
  97. End If
  98. Else
  99. If Filas("Descripcion") = "Titulo" Then
  100. If String.IsNullOrEmpty(CodigoTitulo) Then
  101. Codigo += " " + Filas("Codigo")
  102. Else
  103. Codigo += "," + Filas("Codigo")
  104. End If
  105. ElseIf Filas("Descripcion") = "Posicion" Then
  106. NivelAnterior = Filas("Codigo") * Filas("Codigo")
  107. End If
  108. End If
  109. If Filas("Descripcion").ToString.Trim(" ") = "Reporto" Then
  110. Reporto = Filas("Codigo").ToString.Trim(" ")
  111. End If
  112. If Filas("Descripcion") = "Titulo Generado" Then
  113. If String.IsNullOrEmpty(CodigoTitulo) Then
  114. CodigoTitulo += " " + Filas("Codigo")
  115. Else
  116. CodigoTitulo += "," + Filas("Codigo")
  117. End If
  118. End If
  119. Next
  120. If Index = 0 Then
  121. ObtenerNodosInicio(0, Codigo)
  122. ObtenerNodosInicio(0, Reporto)
  123. ObtenerNodosInicio(1, CodigoTitulo)
  124. Else
  125. ObtenerNodosInicio(NivelAnterior + 1, Codigo)
  126. ObtenerNodosInicio(NivelAnterior + 2, Reporto)
  127. ObtenerNodosInicio(NivelAnterior + 3, CodigoTitulo)
  128. End If
  129. Index += 1
  130. End While
  131. End Sub
  132. Sub ObtenerNodos(ByRef Node As TreeNode, ByVal Nivel As Integer, ByRef Valor As String)
  133. For Each nodo As TreeNode In Node.Nodes
  134. If nodo.Level = Nivel Then
  135. If nodo.Parent.LastNode.Text = nodo.Text Then
  136. GuardarTrv(Nivel, Valor, nodo)
  137. Exit Sub
  138. End If
  139. Else
  140. If nodo.Parent.LastNode.Text = nodo.Text Then
  141. ObtenerNodos(nodo, Nivel, Valor)
  142. End If
  143. End If
  144. Next
  145. End Sub
  146. Sub GuardarTrv(ByVal Nivel As Integer, ByRef Valor As String, ByRef node As TreeNode)
  147. Dim Cantidad As Integer = 0
  148. If Not node.Parent Is Nothing Then
  149. Cantidad = node.Parent.LastNode.Nodes.Count - 1
  150. End If
  151. If Not (Cantidad <= 0) Then
  152. node.Nodes.Add(Valor)
  153. Else
  154. node.Nodes.Add(Valor)
  155. End If
  156. Valor = String.Empty
  157. End Sub
  158. Sub ObtenerNodosInicio(ByVal Nivel As Integer, ByVal Valor As String)
  159. Dim Cantidad As Integer = trvFlujo.Nodes.Count
  160. If Cantidad > 0 Then
  161. For Each nodo As TreeNode In trvFlujo.Nodes
  162. If nodo.Level = Nivel Then
  163. GuardarTrv(Nivel, Valor, nodo)
  164. Exit Sub
  165. Else
  166. ObtenerNodos(nodo, Nivel, Valor)
  167. End If
  168. Next
  169. Else
  170. trvFlujo.Nodes.Add(Valor)
  171. End If
  172. End Sub
  173. End Class