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