Public Class frmSeleccionTitulosReportos Dim DAOGeneral As New DAOGeneral Dim Operaciones As New Operaciones Dim NombreTrasladar As String = String.Empty Dim ObtenerInstanciaObjetotexto As New TextBox Dim ObtenerInstanciaObjetocheque As New CheckBox Dim SeleccionDAO As New SeleccionTitulosReportosDAO Dim General As New DAOGeneral Dim CodigoAsociado As String = String.Empty Dim MontoUsado As Double = 0 Dim Empresa As String = String.Empty Dim NombreEm As String = String.Empty Dim CodigoReporto As String = String.Empty Dim IdFlujo As Integer = 0 Private Sub frmSeleccionTitulosReportos_Load(sender As Object, e As EventArgs) Handles MyBase.Load Formato() DefinirValoresIniciales() CargarTitulos() SaldoGarantia() Controladores(0) End Sub Sub DefinirValoresIniciales() txtCodigoAsociado.Text = CodigoAsociado txtMonto.Text = MontoUsado End Sub Sub New() ' Esta llamada es exigida por el diseñador. InitializeComponent() ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Sub New(DicDatos As Dictionary(Of String, Object)) Me.New If DicDatos.ContainsKey("MontoUsado") Then Me.MontoUsado = DicDatos.Item("MontoUsado") End If If DicDatos.ContainsKey("CodigoAsociado") Then Me.CodigoAsociado = DicDatos.Item("CodigoAsociado") End If If DicDatos.ContainsKey("Empresa") Then Me.Empresa = DicDatos.Item("Empresa") End If If DicDatos.ContainsKey("NombreEmpresa") Then Me.NombreEm = DicDatos.Item("NombreEmpresa") End If If DicDatos.ContainsKey("CodigoReporto") Then Me.CodigoReporto = DicDatos.Item("CodigoReporto") End If If DicDatos.ContainsKey("IdFlujo") Then Me.IdFlujo = DicDatos.Item("IdFlujo") End If End Sub Sub CargarTitulos() Dim dt As New DataTable dt = DAOGeneral.ListaInstrumentos("Propuesta") For Each Item As DataRow In dt.Rows ''GeneracionCheques Dim cheque As New CheckBox cheque.Width = 215 cheque.Margin = New Padding(90, 10, 0, 10) cheque.Name = Item("Codigo").ToString cheque.Text = Item("Descripcion").ToString flpTitulos.AutoScroll = True ''GeneracionTexto Dim texto As New TextBox Dim Label As New Label Label.Text = " " Label.ForeColor = Color.Maroon Label.Name = Item("Codigo").ToString texto.Width = 150 texto.Margin = New Padding(0, 10, 0, 10) Label.Margin = New Padding(50, 10, 0, 10) texto.Name = Item("Codigo").ToString texto.Text = 0 flpValor.AutoScroll = True texto.ReadOnly = True texto.BorderStyle = BorderStyle.FixedSingle texto.BackColor = SystemColors.Control AddHandler cheque.CheckedChanged, AddressOf ObtenerNombre AddHandler cheque.MouseMove, AddressOf Focuss flpTitulos.Controls.Add(cheque) flpValor.Controls.Add(Label) flpValor.Controls.Add(texto) Next End Sub Sub Focuss() flpValor.VerticalScroll.Value = flpTitulos.VerticalScroll.Value End Sub Sub ObtenerNombre(sender As Object, e As EventArgs) Controladores(1) NombreTrasladar = sender.name.ToString For Each Item In flpValor.Controls If TypeOf Item Is TextBox Then If Item.Name = NombreTrasladar Then If sender.checked Then ObtenerInstanciaObjetotexto = Item ObtenerInstanciaObjetocheque = sender Seleccionado() Else ObtenerInstanciaObjetotexto = Item NombreTrasladar = sender.name.ToString Item.Text = 0 ObtenerInstanciaObjetotexto.BackColor = SystemColors.Control ObtenerInstanciaObjetotexto.ForeColor = Color.Black ObtenerInstanciaObjetotexto = Nothing NombreTrasladar = String.Empty ObtenerInstanciaObjetocheque = Nothing End If End If ElseIf TypeOf Item Is Label Then If Item.Name = NombreTrasladar Then Item.text = "------>" Else Item.text = " " End If End If Next flpValor.VerticalScroll.Value = flpTitulos.VerticalScroll.Value End Sub Function TrasladarMonto() Dim MoverLimpio As Double = Operaciones.ConvertirDecimal(txtMover.Text.ToString) Dim PorcRest As Double = Operaciones.ConvertirDecimal(lblPorcentajeRestanteValor.Text.ToString) Dim MontoDisponible As Double = Operaciones.ConvertirDecimal(lblMontoDisponible.Text.ToString) Dim MontoTotal As Double = Operaciones.ConvertirDecimal(lblMontoPorcentaje.Text.ToString) If rdbMonto.Checked Then If (MoverLimpio <= 0) Then MsgBox("Ingrese un numero mayor a 0") Return 0 ElseIf MoverLimpio > MontoTotal Then MsgBox("El Monto Máximo es de " + MontoTotal.ToString) Return 0 ElseIf MoverLimpio > MontoDisponible Then MsgBox("Monto Fuera de Rango") Return 0 Else If Not String.IsNullOrEmpty(NombreTrasladar) And Not ObtenerInstanciaObjetotexto Is Nothing Then If Not lblMontoDisponible.Text = 0 Then ObtenerInstanciaObjetotexto.BackColor = Color.Brown ObtenerInstanciaObjetotexto.ForeColor = Color.White End If End If CalculoSaldoUsado() Return 1 End If Else If (MoverLimpio <= 0) Then MsgBox("Ingrese un numero mayor a 0") Return 0 ElseIf MoverLimpio > 100 Then MsgBox("El Porcentaje máximo es de 100 %") Return 0 ElseIf MoverLimpio > PorcRest Then MsgBox("Porcentaje Fuera de Rango") Return 0 Else If Not String.IsNullOrEmpty(NombreTrasladar) And Not ObtenerInstanciaObjetotexto Is Nothing Then If Not lblMontoDisponible.Text = 0 Then ObtenerInstanciaObjetotexto.BackColor = Color.Brown ObtenerInstanciaObjetotexto.ForeColor = Color.White End If End If CalculoSaldoUsado() Return 1 End If End If End Function Sub CalculoSaldoUsado() Dim TipoValor As String = String.Empty If rdbMonto.Checked Then TipoValor = "Monto" Else TipoValor = "Porc" End If ''Es Positivo If TipoValor = "Monto" Then ObtenerInstanciaObjetotexto.Text = txtMover.Text txtMover.Text = 0 Else If Not lblMontoDisponible.Text = 0 Then ObtenerInstanciaObjetotexto.Text = (Operaciones.ConvertirDecimal(lblMontoPorcentaje.Text) * (Operaciones.ConvertirDecimal(txtMover.Text) / 100)) Else MsgBox("No cuenta con suficientes fondos") End If End If End Sub Private Sub tlpValor_Paint(sender As Object, e As PaintEventArgs) End Sub Private Sub flpTitulos_Scroll(sender As Object, e As ScrollEventArgs) Handles flpTitulos.Scroll flpValor.VerticalScroll.Value = flpTitulos.VerticalScroll.Value End Sub Private Sub btnMover_Click(sender As Object, e As EventArgs) Handles btnMover.Click Dim Continuar As Integer = TrasladarMonto() If Continuar = 1 Then Controladores(2) End If End Sub Function ConteoSaldoUsado() Dim Monto As Double = 0 Dim CantidadFilas = dgvDetalles.Rows.Count - 1 Dim Index As Integer = 0 While (CantidadFilas >= Index) Monto += Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Monto").Value.ToString) Index += 1 End While Return Monto End Function Function CalculoSaldo() Dim MontoActualPorcentaje As Double = 0 Dim MontoUsado As Double = 0 Dim MontoDisponible As Double = 0 Dim Positivo As Boolean = False MontoActualPorcentaje = Operaciones.ConvertirDecimal(lblMontoPorcentaje.Text.ToString) MontoUsado = Operaciones.ConvertirDecimal(ConteoSaldoUsado.ToString) lblMontoUsado.Text = MontoUsado MontoDisponible = MontoActualPorcentaje - MontoUsado If MontoDisponible >= 0 Then lblMontoDisponible.Text = MontoDisponible Positivo = True Else Positivo = False End If Return Positivo End Function Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click txtMover.Text = 0 If Not ObtenerInstanciaObjetocheque Is Nothing Then ObtenerInstanciaObjetocheque.Checked = False ObtenerInstanciaObjetocheque = Nothing End If Controladores(0) End Sub Private Sub btnAgregar_Click(sender As Object, e As EventArgs) Handles btnAgregar.Click End Sub Sub Seleccionado() End Sub Private Sub flpTitulos_CursorChanged(sender As Object, e As EventArgs) Handles flpTitulos.CursorChanged End Sub Sub SaldoGarantia() Dim PorcentajeIngresado As Double = Operaciones.ConvertirDecimal(txtPorcentaje.Text.ToString) If PorcentajeIngresado > 100 Then txtPorcentaje.Text = "100 %" MsgBox("Porcentaje Demasiado Alto,Ingrese uno menor") End If Dim Porcentaje As Double = 0 Dim ValorTitulo As Double = 0 If Not String.IsNullOrEmpty(txtPorcentaje.Text) Then Porcentaje = (Operaciones.ConvertirDecimal(txtPorcentaje.Text.ToString) / 100) End If Dim Monto As Double = Operaciones.ConvertirDecimal(txtMonto.Text.ToString) Dim MontoDisponible As Double = Monto * Porcentaje ValorTitulo = Monto - MontoDisponible txtValorTitulo.Text = ValorTitulo lblMontoDisponible.Text = MontoDisponible lblMontoPorcentaje.Text = MontoDisponible End Sub Private Sub lblMontoDisponible_Click(sender As Object, e As EventArgs) Handles lblMontoDisponible.Click End Sub Private Sub txtPorcentaje_TextChanged(sender As Object, e As EventArgs) Handles txtPorcentaje.TextChanged SaldoGarantia() End Sub Sub Guardar() Dim Valores As New Collection Valores = GuardarValores() SeleccionDAO.ProcesoDatos(Valores) End Sub Function GuardarValores() As Collection Dim ColRegistros As New Collection Dim Tipo As String = String.Empty If rdbMonto.Checked Then Tipo = "Monto" Else Tipo = "Porcentaje" End If Dim CantidadFilas = dgvDetalles.Rows.Count - 1 Dim Index As Integer = 0 While (CantidadFilas >= Index) Dim DicRegistrosInstrumentos As New Dictionary(Of String, Object) Dim CodigoAso As String = Me.CodigoAsociado Dim CodigoReporto As String = Me.CodigoReporto Dim IdFlujo As Integer = Operaciones.ConvertirEntero(Me.IdFlujo.ToString) Dim NombreInstrumento As String = dgvDetalles.Rows(Index).Cells("NombreInstrumento").Value.ToString Dim NombreEmpresa As String = dgvDetalles.Rows(Index).Cells("NombreEmpresa").Value.ToString Dim TipoAsignacion As String = Tipo Dim MontoInicial As Double = Operaciones.ConvertirDecimal(txtMonto.Text.ToString) Dim MontoTotalUsado As Double = Operaciones.ConvertirDecimal(lblMontoPorcentaje.Text.ToString) Dim PorcentajeRestante As Double = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("PorcentajeRestantes").Value.ToString) Dim PorcentajeMontoUsado As Double = Operaciones.ConvertirDecimal(txtPorcentaje.Text.ToString) Dim MontoDisponible As Double = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("SaldoDisponible").Value.ToString) Dim MontoUsado As Double = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("SaldoUsado").Value.ToString) Dim MontoTitulo As Double = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Monto").Value.ToString) Dim MontoNoUsado As Double = Operaciones.ConvertirDecimal(txtValorTitulo.Text.ToString) Dim FechaCreado As Date = Date.Now.Date Dim EstadoProceso As String = "P" Dim Asociado As String = "No" ''AgregarCampos al Dicionario DicRegistrosInstrumentos.Add("CodigoAsociado", CodigoAso) DicRegistrosInstrumentos.Add("NombreInstrumento", NombreInstrumento) DicRegistrosInstrumentos.Add("NombreEmpresa", NombreEmpresa) DicRegistrosInstrumentos.Add("TipoAsignacion", TipoAsignacion) DicRegistrosInstrumentos.Add("MontoInicial", MontoInicial) DicRegistrosInstrumentos.Add("MontoTotalUsado", MontoTotalUsado) DicRegistrosInstrumentos.Add("PorcentajeRestante", PorcentajeRestante) DicRegistrosInstrumentos.Add("PorcentajeMontoUsado", PorcentajeMontoUsado) DicRegistrosInstrumentos.Add("MontoDisponible", MontoDisponible) DicRegistrosInstrumentos.Add("MontoUsado", MontoUsado) DicRegistrosInstrumentos.Add("MontoTitulo", MontoTitulo) DicRegistrosInstrumentos.Add("MontoNoUsado", MontoNoUsado) DicRegistrosInstrumentos.Add("FechaCreado", FechaCreado) DicRegistrosInstrumentos.Add("EstadoProceso", EstadoProceso) DicRegistrosInstrumentos.Add("Asociado", Asociado) DicRegistrosInstrumentos.Add("CodigoReporto", CodigoReporto) DicRegistrosInstrumentos.Add("IdFlujo", IdFlujo) ColRegistros.Add(DicRegistrosInstrumentos) Index += 1 End While Return ColRegistros End Function Private Sub btnGenerar_Click(sender As Object, e As EventArgs) Handles btnGenerar.Click Guardar() frmColaTitulos.Inicializacion() frmColaTitulos.dgvDetalles.DataSource = Nothing Me.Close() End Sub Private Sub btnAgregarSiguiente_Click(sender As Object, e As EventArgs) Handles btnAgregarSiguiente.Click Dim Estado As String = String.Empty AgregarSiguiente() CalculoSaldo() PorcentajeRestante() Limpiar() Controladores(3) End Sub Sub AgregarSiguiente() Dim Nombre As String = String.Empty Dim NombreInstrumento As String = String.Empty Dim Monto As Double = 0 Dim SaldoDisponible As Double = 0 Dim SaldoUsado As Double = 0 Dim PorcentajeRestante As Double = 0 Dim Codigo As String = Variables.Codigo Dim Empresa As String = Me.Empresa Dim NombreEmpresa As String = Me.NombreEm For Each Item In flpValor.Controls If TypeOf Item Is TextBox Then If Item.BackColor = Color.Brown Then Nombre = Item.name.ToString Monto = Operaciones.ConvertirDecimal(Item.text.ToString) SaldoDisponible = Operaciones.ConvertirDecimal(lblMontoDisponible.Text.ToString) - Monto SaldoUsado = Operaciones.ConvertirDecimal(lblMontoUsado.Text.ToString) + Monto PorcentajeRestante = (SaldoDisponible / Operaciones.ConvertirDecimal(lblMontoPorcentaje.Text.ToString)) * 100 End If End If Next For Each Item In flpTitulos.Controls If TypeOf Item Is CheckBox Then If Item.checked Then NombreInstrumento = Item.text.ToString If Not String.IsNullOrEmpty(NombreInstrumento) Then Exit For End If End If End If Next If String.IsNullOrEmpty(Nombre) And String.IsNullOrEmpty(Monto.ToString) Or String.IsNullOrEmpty(SaldoDisponible.ToString) Or String.IsNullOrEmpty(SaldoUsado.ToString) Or String.IsNullOrEmpty(PorcentajeRestante.ToString) Or String.IsNullOrEmpty(Empresa.ToString) Or String.IsNullOrEmpty(NombreInstrumento.ToString) Or String.IsNullOrEmpty(NombreEm.ToString) Then MsgBox("Error en Traspaso") Else dgvDetalles.Rows.Add(Nombre, NombreInstrumento, Empresa, NombreEm, Monto.ToString, SaldoDisponible.ToString, SaldoUsado.ToString, PorcentajeRestante.ToString + " %".ToString) End If End Sub Private Sub btnAgregarMismoIns_Click(sender As Object, e As EventArgs) End Sub Sub Limpiar() For Each Item In flpValor.Controls If TypeOf Item Is TextBox Then Item.text = 0 Item.backcolor = SystemColors.Control End If If TypeOf Item Is Label Then Item.text = " " End If Next For Each Item In flpTitulos.Controls If TypeOf Item Is CheckBox Then Item.checked = False End If Next End Sub Public Function SoloNumeros(ByVal strCadena As String) As String Dim SoloNumero As String = "" strCadena = Replace(strCadena, " ", "") Dim index As Integer For index = 1 To Len(strCadena) If (Mid$(strCadena, index, 1) Like "#") _ Or Mid$(strCadena, index, 1) = "." Then SoloNumero = SoloNumero & Mid$(strCadena, index, 1) End If Next Return SoloNumero End Function Private Sub lblMontoUsado_Click(sender As Object, e As EventArgs) Handles lblMontoUsado.Click End Sub Sub PorcentajeRestante() Dim PorcentajeCompleto As Integer = 0 Dim MontoCompleto As Double = 0 Dim MontoUsado As Double = 0 Dim Porcentaje As Double = 0 MontoCompleto = Operaciones.ConvertirDecimal(lblMontoPorcentaje.Text.ToString) MontoUsado = Operaciones.ConvertirDecimal(lblMontoUsado.Text.ToString) Porcentaje = 100 - ((MontoUsado / MontoCompleto) * 100) lblPorcentajeRestanteValor.Text = Porcentaje.ToString + " %" End Sub Sub Controladores(ByRef PasoDatos As Integer) If PasoDatos = 0 Then btnAgregarSiguiente.Enabled = False pnlControladores.Enabled = False btnCancelar.Enabled = False btnAgregar.Enabled = False flpTitulos.Enabled = True ElseIf PasoDatos = 1 Then flpTitulos.Enabled = False pnlControladores.Enabled = True btnCancelar.Enabled = True ElseIf PasoDatos = 2 Then btnAgregarSiguiente.Enabled = True pnlControladores.Enabled = False ElseIf PasoDatos = 3 Then btnAgregar.Enabled = False flpTitulos.Enabled = True pnlControladores.Enabled = False btnCancelar.Enabled = False btnAgregarSiguiente.Enabled = False If rdbMonto.Checked Then txtMover.Text = "1 " Else txtMover.Text = "1 %" End If End If End Sub Private Sub txtPorcentaje_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPorcentaje.KeyPress If String.IsNullOrEmpty(sender.Text) Then If e.KeyChar = "." Then sender.Text = "0" Exit Sub End If End If If (Not sender.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Sub Formato() If rdbPorcentaje.Checked Then Dim Porcentaje As String = txtPorcentaje.Text.Trim(" ").Trim("%") Dim PorcentajeNumero As Double = 0 PorcentajeNumero = Operaciones.ConvertirDecimal(Porcentaje) If PorcentajeNumero = 0 Then PorcentajeNumero = 1 End If Porcentaje = PorcentajeNumero.ToString + " %" txtPorcentaje.Text = Porcentaje End If End Sub Private Sub txtPorcentaje_Leave(sender As Object, e As EventArgs) Handles txtPorcentaje.Leave Formato() End Sub Private Sub rdbMonto_CheckedChanged(sender As Object, e As EventArgs) Handles rdbMonto.CheckedChanged CambioCalculo() Formato() End Sub Private Sub rdbPorcentaje_CheckedChanged(sender As Object, e As EventArgs) Handles rdbPorcentaje.CheckedChanged CambioCalculo() Formato() End Sub Sub CambioCalculo() If rdbPorcentaje.Checked Then txtPorcentaje.Text = "100 %" txtMover.Text = "1 %" Else txtPorcentaje.Text = "100 %" txtMover.Text = "1" End If End Sub Private Sub lblPorcentajeRestanteValor_Click(sender As Object, e As EventArgs) Handles lblPorcentajeRestanteValor.Click End Sub Private Sub txtMover_Leave(sender As Object, e As EventArgs) Handles txtMover.Leave If rdbPorcentaje.Checked Then txtMover.Text = Operaciones.ConvertirDecimal(txtMover.Text.ToString).ToString + " %" End If End Sub Private Sub dgvDetalles_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellContentClick End Sub End Class