Imports System.Data.OleDb Imports System.IO Public Class frmAcciones Private TipoOperacion As String Public Sub New() ' Esta llamada es exigida por el diseñador. InitializeComponent() ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Public Sub New(ByVal ConsTOperacion As String) ' Esta llamada es exigida por el diseñador. InitializeComponent() TOperacion(ConsTOperacion) TipoOperacion = ConsTOperacion ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Dim PorcentajeComisionBolsa_Compra As Double = 0.070625 Dim PorcentajeComisionBolsa_Venta As Double = 0.0353125 Dim Cargar As Boolean = True Dim PorcentajeComisionCasa_Compra As Double = 0.45 Dim PorcentajeComisionCasa_Venta As Double = 0.4 Dim Agregar As Boolean = False Dim PorcentajeLIOF As Double = 0.25 Dim oAccionesCE As AccionesCE = New AccionesCE Dim oAccionesDAO As New AccionesDAO Dim oDAOGeneral As New DAOGeneral Dim Estado As String = "" Dim MostrarMensaje As Boolean = False Dim EditarDividendos As Boolean = False Dim EditarISR As Boolean = False Dim CambioCalculo = False Dim HabilitarBoton As Boolean = False Dim DobleClick As Boolean = False Dim Operaciones As New Operaciones Dim InstrumentoFinanciero As String = oDAOGeneral.ObtenerInstrumento(Variables.Codigo) Dim Cargado As Boolean = False Dim Cierre As Boolean = False Dim DatosCargados As Boolean = False Private _Modo As String Private _IdDocumento As Integer Private _TipoDocumento As String Private _CodigoInversion As String Private _TipoTransaccion As String Public Property TipoTransaccion As String Get Return _TipoTransaccion End Get Set(value As String) _TipoTransaccion = value End Set End Property Private Property IdDocumento As Integer Get Return _IdDocumento End Get Set(value As Integer) _IdDocumento = value End Set End Property Private Property TipoDocumento As String Get Return _TipoDocumento End Get Set(value As String) _TipoDocumento = value End Set End Property Private Property CodigoInversion As String Get Return _CodigoInversion End Get Set(value As String) _CodigoInversion = value End Set End Property Sub Instrumento() If (InstrumentoFinanciero = "ACCNC") Then lblTitulo.Text = "Acciones Nacionales Comunes" Me.Text = "Acciones Nacionales Comunes" ElseIf (InstrumentoFinanciero = "ACCNP") Then lblTitulo.Text = "Acciones Preferentes Nacionales" ModificacionesPreferentes() Me.Text = "Acciones Preferentes Nacionales" ElseIf (InstrumentoFinanciero = "ACCI") Then lblTitulo.Text = "Acciones Internacionales" Me.Text = "Acciones Internacionales" End If End Sub Function ColeccionDatos() Dim coleccion As New Collection Dim PrecioLimpioC, FOperC, FLiqC, DiasTC, GCapTotC, GCapUnC, RetAnBrC, RetAnNetC, UnC, ValTransC, MontoNetoC, PrecSucioC Dim PrecioLimpioV, FOperV, FLiqV, DiasTV, GCapTotV, GCapUnV, RetAnBrV, RetAnNetV, UnV, ValTransV, MontoNetoV, PrecSucioV Dim ComisionCompraCasa, ComisionCompraBolsa, ComisionVentaCasa, ComisionVentaBolsa As Double Dim IOF, Renta, Tipo, RetornoBruto, RetornoNeto Dim ComisionCompraCasaValor, ComisionCompraBolsaValor, ComisionVentaCasaValor, ComisionVentaBolsaValor As Double PrecioLimpioC = txtPrecioLimpioCompra.Text.Trim("%") FOperC = dtpFechaOperacionCompra.Value FLiqC = dtpFechaVencimientoCompra.Value DiasTC = txtDiasDeTenenciaCompra.Text.Trim("%") GCapTotC = txtGananciaCapitalTotalCompra.Text.Trim("%") GCapUnC = txtGananciaCapitalUnitarioCompra.Text.Trim("%") RetAnNetC = txtRetornoAnualNetoCompra.Text.Trim("%") UnC = txtUnidadesCompra.Text.Trim("%") ValTransC = txtValorTransadoCompra.Text.Trim("%") MontoNetoC = txtMontoNetoCompra.Text.Trim("%") PrecSucioC = txtPrecioSucioCompra.Text.Trim("%") PrecioLimpioV = txtPrecioLimpioVenta.Text.Trim("%") FOperV = dtpFechaOperacionVenta.Value FLiqV = dtpFechaVencimientoVenta.Value DiasTV = txtDiasDeTenenciaVenta.Text.Trim("%") GCapTotV = txtGananciaCapitalTotalVenta.Text.Trim("%") GCapUnV = txtGananciaCapitalUnitarioVenta.Text.Trim("%") RetAnBrV = txtRetornoAnualBrutoVenta.Text.Trim("%") RetAnNetV = txtRetornoAnualNetoVenta.Text.Trim("%") UnV = txtUnidadesVenta.Text.Trim("%") ValTransV = txtValorTransadoVenta.Text.Trim("%") MontoNetoV = txtMontoNetoVenta.Text.Trim("%") PrecSucioV = txtPrecioSucioVenta.Text.Trim("%") ComisionCompraCasa = txtComisionPorcentajeCasaCompra.Text.Trim("%") / 100 ComisionCompraBolsa = txtComisionPorcentajeBolsaCompra.Text.Trim("%") / 100 ComisionVentaCasa = txtComisionPorcentajeCasaVenta.Text.Trim("%") / 100 ComisionVentaBolsa = txtComisionPorcentajeBolsaVenta.Text.Trim("%") / 100 ComisionCompraCasaValor = txtComisionCasaCompra.Text ComisionCompraBolsaValor = txtComisionBolsaCompra.Text ComisionVentaCasaValor = txtComisionCasaVenta.Text ComisionVentaBolsaValor = txtComisionBolsaVenta.Text If (Not String.IsNullOrEmpty(txtRetornoAnualBrutoCompra.Text.ToString.ToString.Trim("%"))) Then RetornoBruto = txtRetornoAnualBrutoCompra.Text.Trim("%") / 100 Else RetornoBruto = 0 End If If (ChkIOF.Checked) Then IOF = 1 Else IOF = 0 End If If (ChkRenta.Checked) Then Renta = 1 Else Renta = 0 End If If rdbPorcentaje.Checked Then Tipo = "Porcentaje" Else Tipo = "Efectivo" End If coleccion.Add(PrecioLimpioC) coleccion.Add(FOperC) coleccion.Add(FLiqC) coleccion.Add(DiasTC) coleccion.Add(GCapTotC) coleccion.Add(GCapUnC) coleccion.Add(RetornoBruto) coleccion.Add(RetAnNetC) coleccion.Add(UnC) coleccion.Add(ValTransC) coleccion.Add(MontoNetoC) coleccion.Add(PrecSucioC) coleccion.Add(PrecioLimpioV) coleccion.Add(FOperV) coleccion.Add(FLiqV) coleccion.Add(DiasTV) coleccion.Add(GCapTotV) coleccion.Add(GCapUnV) coleccion.Add(RetAnBrV) coleccion.Add(RetAnNetV) coleccion.Add(UnV) coleccion.Add(ValTransV) coleccion.Add(MontoNetoV) coleccion.Add(PrecSucioV) coleccion.Add(ComisionCompraCasa) coleccion.Add(ComisionCompraBolsa) coleccion.Add(ComisionVentaCasa) coleccion.Add(ComisionVentaBolsa) coleccion.Add(IOF) coleccion.Add(Renta) coleccion.Add(Tipo) coleccion.Add(ComisionCompraCasaValor) coleccion.Add(ComisionCompraBolsaValor) coleccion.Add(ComisionVentaCasaValor) coleccion.Add(ComisionVentaBolsaValor) Return coleccion End Function Function Correlativo() Dim Index As Integer = 0 Dim IndexCantidad As Integer = dgvDividendos.Rows.Count - 2 Dim NumeroMayor As Integer = 0 While Index <= IndexCantidad Dim Numero As Integer = dgvDividendos.Rows(Index).Cells("NumDiv").Value If Numero > NumeroMayor Then NumeroMayor = Numero End If Index += 1 End While Return NumeroMayor + 1 End Function Sub CorrelativoSinBD() Dim Index As Integer = 0 Dim IndexCantidad As Integer = dgvDividendos.Rows.Count - 2 Dim NumeroMayor As Integer = 0 While Index <= IndexCantidad dgvDividendos.Rows(Index).Cells("Correlativo").Value = Index + 1 Index += 1 End While End Sub Function ColeccionesElementos(ByVal Index As Integer) Dim coleccion As New Collection Dim Fecha, Estado, Dividendo, CantidadBase, IngresoBruto, PorcISR, ISR, IngresoNeto, Correlativo, Tipo, FechaInicio, FechaCorte If rdbPorcentaje.Checked Then Tipo = "Porcentaje" Else Tipo = "Efectivo" End If Fecha = CDate(dgvDividendos.Rows(Index).Cells("Fecha").Value) Dividendo = dgvDividendos.Rows(Index).Cells("Dividendo").Value.ToString.Trim("%") If (Tipo = "Porcentaje") Then Dividendo /= 100 End If CantidadBase = dgvDividendos.Rows(Index).Cells("CantidadBase").Value.ToString.TrimEnd("%") IngresoBruto = dgvDividendos.Rows(Index).Cells("IngresoBruto").Value.ToString.TrimEnd("%") PorcISR = dgvDividendos.Rows(Index).Cells("PorcISR").Value.ToString.TrimEnd("%") ISR = dgvDividendos.Rows(Index).Cells("ISR").Value.ToString.TrimEnd("%") IngresoNeto = dgvDividendos.Rows(Index).Cells("IngresoNeto").Value.ToString.TrimEnd("%") Estado = "A" Correlativo = dgvDividendos.Rows(Index).Cells("NumDiv").Value.ToString.TrimEnd("%") FechaInicio = dgvDividendos.Rows(Index).Cells("FechaInicio").Value FechaCorte = dgvDividendos.Rows(Index).Cells("FechaCorte").Value If (Tipo = "Porcentaje") Then If FechaInicio Is DBNull.Value Or FechaCorte Is DBNull.Value Then MsgBox("Verifique las fechas") Exit Function Else If (String.IsNullOrEmpty(FechaInicio) Or String.IsNullOrEmpty(FechaCorte)) Then MsgBox("Verifique las fechas") Exit Function End If End If End If coleccion.Add(Fecha) coleccion.Add(CDec(Dividendo)) coleccion.Add(CDec(CantidadBase)) coleccion.Add(CDec(IngresoBruto)) coleccion.Add(CDec(PorcISR)) coleccion.Add(CDec(ISR)) coleccion.Add(CDec(IngresoNeto)) coleccion.Add(Estado) coleccion.Add(CInt(Correlativo)) coleccion.Add(FechaInicio) coleccion.Add(FechaCorte) Return coleccion End Function Sub NuevoElementoAccion(ByVal AgregarModificar As Boolean, ByVal Cantidad As Integer) Dim Codigo As String = Variables.Codigo Dim i As Integer = 0 Dim Index = dgvDividendos.Rows.Count - 2 i = Cantidad While i <= Index Dim coleccion = ColeccionesElementos(i) If (oAccionesDAO.NuevoElementoAccion(Codigo, coleccion) Is Nothing) Then Exit Sub End If i += 1 End While MsgBox("Registro de ingresos actualizados") End Sub Function CanRegistros() Dim Tabla As String = String.Empty Tabla = "ACC1" Dim Codigo = Variables.Codigo Dim Cantidad As Integer = oDAOGeneral.CantidadRegistros(Codigo, Tabla) Return Cantidad End Function Sub ModificarElementoAccion() Dim i As Integer = 0 Dim CantidadRegistrosDB = CanRegistros() While i < CantidadRegistrosDB Dim coleccion = ColeccionesElementos(i) If oAccionesDAO.ModificarElementoAccion(Codigo, coleccion) Is Nothing Then Exit Sub End If i += 1 End While NuevoElementoAccion(True, CantidadRegistrosDB) End Sub Function ColeccionNuevo(ByVal codigo As String) Dim i As Integer = 0 Dim diccionario As New Dictionary(Of String, Collection) Dim Index = dgvDividendos.Rows.Count - 2 While i <= Index Dim coleccion = ColeccionesElementos(i) diccionario.Add(i, coleccion) i += 1 End While Return diccionario End Function Public Function NuevaAccion() Dim Coleccion = ColeccionDatos() Return Coleccion End Function Sub Eliminar() Dim Codigo = Variables.Codigo oAccionesDAO.Eliminar(Codigo) End Sub Sub ModificacionesPreferentes() GrpVenta.Visible = False txtRetornoAnualBrutoCompra.Visible = True txtRetornoAnualBrutoCompra.ReadOnly = False txtRetornoAnualBrutoCompra.Text = "0.0" Label19.Visible = False End Sub Sub Redimencionar() dgvDividendos.Width = Me.Width - 10 dgvDividendos.Height = Me.Height - 50 End Sub Private Sub frmAcciones_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim VExisteInversion As Boolean = False VExisteInversion = ExisteInversion() If VExisteInversion Then TipoOperacion = "C" TipoTransaccion = "C" Else TipoOperacion = String.Empty TipoTransaccion = String.Empty End If If Variables.TipoOperacionCMVTA = "C" Then GrpVenta.Enabled = False GrpCompra.Enabled = True Else GrpVenta.Enabled = True GrpCompra.Enabled = False End If Call Instrumento() HabilitarBotones() PrepararTablaDividendos() If VExisteInversion Then TipoOperacion = "C" TipoTransaccion = "C" Else TipoOperacion = String.Empty TipoTransaccion = String.Empty End If If TipoTransaccion = "C" Then Call CargarRegistroBD() Formato() ValidarRentaIOF() CargarDividendos() End If ModificarDividendo() CalcularDividendos() Cargado = True ValidarExistencia() Formato() DatosCargados = True CargarTransladoNuevo() ConfiguracionCMVTA(VExisteInversion) End Sub Sub ConfiguracionCMVTA(ByRef VExisteInversion As Boolean) Dim Codigo As String = Variables.Codigo Dim ExisteCMVTA As Boolean = oDAOGeneral.ExisteCMVTA(Codigo) If Not ExisteCMVTA And Variables.InvocadorProInv = "frmINV" Then btnVenderTitulo.Visible = True End If If CantFormAbierto = False And Not VExisteInversion Then If Not Variables.TrasladarCMVTA Is Nothing Then dtpFechaOperacionCompra.Value = Variables.TrasladarCMVTA.FechaOperacionACC dtpFechaVencimientoCompra.Value = Variables.TrasladarCMVTA.FechaVencimientoACC txtPrecioLimpioCompra.Text = Variables.TrasladarCMVTA.PrecioLimpioACC txtUnidadesCompra.Text = Variables.TrasladarCMVTA.UnidadesACC txtComisionPorcentajeCasaCompra.Text = Variables.TrasladarCMVTA.PorcentajeCasaACC txtComisionPorcentajeBolsaCompra.Text = Variables.TrasladarCMVTA.PorcentajeBolsaACC End If End If End Sub Function ExisteInversion() Dim Codigo As String = Variables.Codigo Dim TablaINV As String = "INV0" Dim TablaPINV As String = "PIN0" Dim General As New DAOGeneral Dim InvPro = Variables.InvPro If InvPro = "I" Then Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV) If INV0 Then navNuevo.Visible = True Return True Else navNuevo.Visible = False Return False End If End If If InvPro = "P" Then Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV) If PINV0 Then navNuevo.Visible = True Return True Else navNuevo.Visible = False Return False End If End If Return False End Function Sub ModificarDividendo() Dim Cantidad As Integer = dgvDividendos.Rows.Count - 2 For i As Integer = 0 To Cantidad If rdbPorcentaje.Checked Then dgvDividendos.Rows(i).Cells("Dividendo").Value *= 100 End If Next End Sub Private Sub chkAccionPreferente_CheckedChanged(sender As Object, e As EventArgs) End Sub Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click Dim codigo As String = Variables.Codigo Dim Accion As Collection = NuevaAccion() Dim ElementosAccion As Dictionary(Of String, Collection) = ColeccionNuevo(codigo) If (Estado = "N") Then oAccionesDAO.ProcesoDatos(Accion, codigo, ElementosAccion, "Nuevo") ElseIf Not ExisteValidacion() Then Variables.ColeccionACC = NuevaAccion() Me.Close() End If If Estado = "M" Then oAccionesDAO.ProcesoDatos(Accion, codigo, ElementosAccion, "Modificar") End If If Estado = "B" Then Eliminar() End If ValidarExistencia() End Sub Sub ValidarExistencia() Dim General As New DAOGeneral Dim Codigo As String = Variables.Codigo Dim Tabla As String = String.Empty Tabla = "ACC0" Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla) If (Existe) Then navNuevo.Enabled = False TbDividendos.Enabled = True navModificar.Enabled = True navEliminar.Enabled = True Else navNuevo.Enabled = True TbDividendos.Enabled = False navModificar.Enabled = False navEliminar.Enabled = False DatosCargados = True End If TipoTransaccion = String.Empty btnAceptar.Text = "Aceptar" End Sub Function ExisteValidacion() Dim General As New DAOGeneral Dim Codigo As String = Variables.Codigo Dim Tabla As String = String.Empty Tabla = "ACC0" Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla) Return Existe End Function Public Function RetornarObjeto() Return oAccionesCE End Function Private Sub CargarRegistroBD() oAccionesCE = Nothing CodigoInversion = Variables.Codigo oAccionesCE = oAccionesDAO.CargarRegistro(Me.CodigoInversion) TipoTransaccion = "C" RefrescarValorControlesInicial() End Sub Public Sub CargarRegistro(vId As Integer, vTipo As String) TipoTransaccion = "C" IdDocumento = vId TipoDocumento = vTipo End Sub Public Sub CargarRegistro(ByRef vCodigoInversion As String) TipoTransaccion = "C" Me.CodigoInversion = vCodigoInversion End Sub Private Sub txtDiasDeTenencia_Compra_TextChanged(sender As Object, e As EventArgs) Handles txtDiasDeTenenciaCompra.TextChanged End Sub Private Sub txtGananciaCapitalTotal_Compra_TextChanged(sender As Object, e As EventArgs) Handles txtGananciaCapitalTotalCompra.TextChanged End Sub Private Sub txtGananciaCapitalUnitario_Compra_TextChanged(sender As Object, e As EventArgs) Handles txtGananciaCapitalUnitarioCompra.TextChanged End Sub Private Sub txtRetornoAnualBruto_Compra_TextChanged(sender As Object, e As EventArgs) Handles txtRetornoAnualBrutoCompra.TextChanged If (txtRetornoAnualBrutoCompra.ToString.IndexOf("%") = -1) Then txtRetornoAnualBrutoCompra.Text += "%" End If If (String.IsNullOrEmpty(txtRetornoAnualBrutoCompra.Text.ToString.Trim("%"))) Then txtRetornoAnualBrutoCompra.Text = "0.0%" End If End Sub Private Sub txtRetornoAnualNeto_Compra_TextChanged(sender As Object, e As EventArgs) Handles txtRetornoAnualNetoCompra.TextChanged End Sub Private Sub cboCasa_C_SelectedIndexChanged(sender As Object, e As EventArgs) End Sub Private Sub txtPrecioSucio_Compra_TextChanged(sender As Object, e As EventArgs) Handles txtPrecioSucioCompra.TextChanged End Sub Private Sub txtGananciaCapitalUnitario_Venta_TextChanged(sender As Object, e As EventArgs) Handles txtGananciaCapitalUnitarioVenta.TextChanged End Sub Private Sub txtRetornoAnualBruto_Venta_TextChanged(sender As Object, e As EventArgs) Handles txtRetornoAnualBrutoVenta.TextChanged End Sub Private Sub txtRetornoAnualNeto_Venta_TextChanged(sender As Object, e As EventArgs) Handles txtRetornoAnualNetoVenta.TextChanged End Sub Private Sub cboCasa_V_SelectedIndexChanged(sender As Object, e As EventArgs) End Sub '********** CONTROL DE VALORES ********** 'COMPRA Private Sub ControlPrecioLimpioCompra() If DatosCargados Then Dim valor As Double = 0 If Not Double.TryParse(Me.txtPrecioLimpioCompra.Text, valor) Then oAccionesCE.PrecioLimpioVenta = "0.0" Else oAccionesCE.PrecioLimpioCompra = valor Me.txtPrecioLimpioCompra.BackColor = Color.White If (Me.TipoTransaccion = "N") Then oAccionesCE.PrecioLimpioVenta = oAccionesCE.PrecioLimpioCompra End If RefrescarValorControles() End If End If End Sub Private Sub ControlFechaOperacionCompra() oAccionesCE.FechaOperacionCompra = Me.dtpFechaOperacionCompra.Value.Date RefrescarValorControles() End Sub Private Sub ControlFechaLiquidacionCompra() oAccionesCE.FechaVencimientoCompra = Me.dtpFechaVencimientoCompra.Value.Date RefrescarValorControles() End Sub Private Sub ControlCantidadCompra() Dim valor As Integer = 0 If Not Integer.TryParse(Me.txtUnidadesCompra.Text, valor) Then oAccionesCE.CantidadCompra = "0" Else Me.txtUnidadesCompra.BackColor = Color.White oAccionesCE.CantidadCompra = valor If (Me.TipoTransaccion = "N" Or TipoTransaccion = "A") Then oAccionesCE.CantidadVenta = oAccionesCE.CantidadCompra End If RefrescarValorControles() End If End Sub 'VENTA Private Sub ControlPrecioLimpioVenta() If DatosCargados Then Dim valor As Double If Not Double.TryParse(Me.txtPrecioLimpioVenta.Text, valor) Then oAccionesCE.PrecioLimpioVenta = "0.0" Else Me.txtPrecioLimpioVenta.BackColor = Color.White oAccionesCE.PrecioLimpioVenta = valor End If RefrescarValorControles() End If End Sub Private Sub ControlFechaOperacionVenta() oAccionesCE.FechaOperacionVenta = dtpFechaOperacionVenta.Value.Date RefrescarValorControles() End Sub Private Sub ControlFechaLiquidacionVenta() oAccionesCE.FechaVencimientoVenta = dtpFechaVencimientoVenta.Value.Date RefrescarValorControles() End Sub Private Sub ControlCantidadVenta() Dim valor As Integer If Not Integer.TryParse(Me.txtUnidadesVenta.Text, valor) Then Me.txtUnidadesVenta.Text = "0" oAccionesCE.CantidadVenta = "0" Else Me.txtUnidadesVenta.BackColor = Color.White oAccionesCE.CantidadVenta = valor End If RefrescarValorControles() End Sub '********** FIN CONTROL DE VALORES ********** '********** EVENTOS DE CONTROLES ********** 'COMPRA Private Sub txtPrecioLimpioCompra_TextChanged(sender As Object, e As EventArgs) Handles txtPrecioLimpioCompra.TextChanged ControlPrecioLimpioCompra() End Sub Private Sub txtPrecioLimpioCompra_LostFocus(sender As Object, e As EventArgs) Handles txtPrecioLimpioCompra.LostFocus ControlPrecioLimpioCompra() End Sub Private Sub dtpFechaOperacionCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacionCompra.ValueChanged If DatosCargados Then ControlFechaOperacionCompra() RefrescarValorControles() Formato() End If End Sub Private Sub dtpFechaLiquidacionCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimientoCompra.ValueChanged If DatosCargados Then ControlFechaLiquidacionCompra() RefrescarValorControles() Formato() End If End Sub Private Sub txtUnidadesCompra_TextChanged(sender As Object, e As EventArgs) Handles txtUnidadesCompra.TextChanged If DatosCargados Then ControlCantidadCompra() CopiarDatos() End If End Sub Sub CopiarDatos() txtUnidadesVenta.Text = txtUnidadesCompra.Text End Sub Private Sub txtUnidadesCompra_LostFocus(sender As Object, e As EventArgs) Handles txtUnidadesCompra.LostFocus ControlCantidadCompra() End Sub 'VENTA Private Sub txtPrecioLimpioVenta_TextChanged(sender As Object, e As EventArgs) Handles txtPrecioLimpioVenta.TextChanged ControlPrecioLimpioVenta() End Sub Private Sub txtPrecioLimpioVenta_LostFocus(sender As Object, e As EventArgs) Handles txtPrecioLimpioVenta.LostFocus ControlPrecioLimpioVenta() End Sub Private Sub dtpFechaOperacionVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacionVenta.ValueChanged If DatosCargados Then ControlFechaOperacionVenta() RefrescarValorControles() End If End Sub Private Sub dtpFechaLiquidacionVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimientoVenta.ValueChanged If DatosCargados Then ControlFechaLiquidacionVenta() RefrescarValorControles() End If End Sub Private Sub txtUnidadesVenta_TextChanged(sender As Object, e As EventArgs) Handles txtUnidadesVenta.TextChanged If DatosCargados Then ControlCantidadVenta() MensajeAlerta() MostrarMensaje = True End If End Sub Sub MensajeAlerta() If (MostrarMensaje) Then Dim UnidadesVenta As Integer = 0 Dim UnidadesCompra As Integer = 0 If Not String.IsNullOrEmpty(txtUnidadesVenta.Text) Then UnidadesVenta = txtUnidadesVenta.Text End If If Not String.IsNullOrEmpty(txtUnidadesCompra.Text) Then UnidadesCompra = txtUnidadesCompra.Text End If If (CDec(UnidadesVenta) > CDec(UnidadesCompra)) Then MsgBox("Esta Tratando de Ingresar más acciones de las compradas, verifique los datos si ha cometido algún error.") End If End If End Sub Private Sub txtUnidadesVenta_LostFocus(sender As Object, e As EventArgs) Handles txtUnidadesVenta.LostFocus ControlCantidadVenta() End Sub Private Sub chkBolsa_CheckedChanged(sender As Object, e As EventArgs) End Sub '********** FIN EVENTOS DE CONTROLES ********** '********** FUNCIONES ********** Private Sub RefrescarClaseEntidad() ControlPrecioLimpioCompra() ControlFechaOperacionCompra() ControlFechaLiquidacionCompra() ControlCantidadCompra() ControlPrecioLimpioVenta() ControlFechaOperacionVenta() ControlFechaLiquidacionVenta() ControlCantidadVenta() End Sub Private Sub Formato() If DatosCargados Then If (String.IsNullOrEmpty(Me.txtRetornoAnualBrutoCompra.Text.ToString.Trim("%"))) Then Me.txtRetornoAnualBrutoCompra.Text = "0.0" End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeCasaCompra.Text.Trim("%"))) Then Me.txtComisionPorcentajeCasaCompra.Text = "0.0%" End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeBolsaCompra.Text.Trim("%"))) Then Me.txtComisionPorcentajeBolsaCompra.Text = "0.0%" End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeCasaVenta.Text.Trim("%"))) Then Me.txtComisionPorcentajeCasaVenta.Text = "0.0%" End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeBolsaVenta.Text.Trim("%"))) Then Me.txtComisionPorcentajeBolsaVenta.Text = "0.0%" End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeBolsaCompra.Text.Trim("%"))) Then Me.txtComisionPorcentajeBolsaCompra.Text = "0.0%" End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeBolsaVenta.Text.Trim("%"))) Then Me.txtComisionPorcentajeBolsaVenta.Text = "0.0%" End If If String.IsNullOrEmpty(txtRetornoAnualBrutoVenta.Text.ToString) Then txtRetornoAnualBrutoVenta.Text = 0 End If If String.IsNullOrEmpty(txtPrecioLimpioCompra.Text.ToString) Then txtPrecioLimpioCompra.Text = 0 End If If String.IsNullOrEmpty(txtPrecioLimpioVenta.Text.ToString) Then txtPrecioLimpioVenta.Text = 0 End If If String.IsNullOrEmpty(txtUnidadesCompra.Text.ToString) Then txtUnidadesCompra.Text = 0 End If If String.IsNullOrEmpty(txtUnidadesVenta.Text.ToString) Then txtUnidadesVenta.Text = 0 End If If (txtComisionPorcentajeCasaVenta.ToString.IndexOf("%") = -1) Then txtComisionPorcentajeCasaVenta.Text += "%" End If If (txtComisionPorcentajeBolsaVenta.ToString.IndexOf("%") = -1) Then txtComisionPorcentajeBolsaVenta.Text += "%" End If If String.IsNullOrEmpty(txtGananciaCapitalUnitarioVenta.Text) Then txtGananciaCapitalUnitarioVenta.Text = 0 End If If String.IsNullOrEmpty(txtRetornoAnualNetoVenta.Text) Then txtRetornoAnualNetoVenta.Text = 0 End If End If End Sub Sub RefrescarValorControlesInicial() Me.txtRetornoAnualBrutoCompra.Text = oAccionesCE.RetornoBruto * 100 Dim IOF = oAccionesCE.IOF Dim Renta = oAccionesCE.Renta If (IOF) Then ChkIOF.Checked = True Else ChkIOF.Checked = False End If If (Renta) Then ChkRenta.Checked = True Else ChkRenta.Checked = False End If Me.txtComisionPorcentajeCasaCompra.Text = CStr(oAccionesCE.ComisionPorcentajeCompraCasa * 100) + "%" Me.txtComisionPorcentajeBolsaCompra.Text = CStr(oAccionesCE.ComisionPorcentajeCompraBolsa * 100) + "%" Me.txtComisionPorcentajeCasaVenta.Text = CStr(oAccionesCE.ComisionPorcentajeVentaCasa * 100) + "%" Me.txtComisionPorcentajeBolsaVenta.Text = CStr(oAccionesCE.ComisionPorcentajeVentaBolsa * 100) + "%" Me.txtComisionCasaCompra.Text = oAccionesCE.ComisionCompraCasa Me.txtComisionBolsaCompra.Text = oAccionesCE.ComisionCompraBolsa Me.txtComisionCasaVenta.Text = oAccionesCE.ComisionVentaCasa Me.txtComisionBolsaVenta.Text = oAccionesCE.ComisionVentaBolsa If (oAccionesCE.Tipo = "Porcentaje") Then rdbPorcentaje.Checked = True ElseIf (oAccionesCE.Tipo = "Efectivo") Then rdbEfectivo.Checked = True End If 'COMPRA Me.txtPrecioLimpioCompra.Text = oAccionesCE.PrecioLimpioCompra.ToString() dtpFechaOperacionCompra.Value = CDate(oAccionesCE.FechaOperacionCompra) dtpFechaVencimientoCompra.Value = CDate(oAccionesCE.FechaVencimientoCompra) Me.txtDiasDeTenenciaCompra.Text = oAccionesCE.DiasDeTenenciaCompra.ToString Me.txtGananciaCapitalTotalCompra.Text = oAccionesCE.GananciaDeCapitalTotalCompra.ToString Me.txtGananciaCapitalUnitarioCompra.Text = oAccionesCE.GananciaDeCapitalUnitarioCompra.ToString Me.txtRetornoAnualNetoCompra.Text = oAccionesCE.RetornoAnualizadoNetoCompra.ToString() Me.txtUnidadesCompra.Text = oAccionesCE.CantidadCompra.ToString Me.txtValorTransadoCompra.Text = oAccionesCE.ValorTransadoCompra.ToString() Dim ValorIOFCompra = 0.0, ValorRentaCompra = 0.0 Me.txtMontoNetoCompra.Text = oAccionesCE.MontoNetoComprasus Me.txtPrecioSucioCompra.Text = oAccionesCE.PrecioSucioCompra.ToString() 'VENTA Me.txtPrecioLimpioVenta.Text = oAccionesCE.PrecioLimpioVenta.ToString() Me.dtpFechaOperacionVenta.Value = oAccionesCE.FechaOperacionVenta Me.dtpFechaVencimientoVenta.Value = oAccionesCE.FechaVencimientoVenta Me.txtDiasDeTenenciaVenta.Text = oAccionesCE.DiasDeTenenciaVenta.ToString Me.txtGananciaCapitalTotalVenta.Text = oAccionesCE.GananciaDeCapitalTotalVentasus.ToString() Me.txtGananciaCapitalUnitarioVenta.Text = oAccionesCE.GananciaDeCapitalUnitarioVenta.ToString txtRetornoAnualBrutoVenta.Text = oAccionesCE.RetornoAnualizadoBrutoVentasus.ToString Me.txtRetornoAnualNetoVenta.Text = oAccionesCE.RetornoAnualizadoNetoVenta.ToString() Me.txtUnidadesVenta.Text = oAccionesCE.CantidadVenta.ToString Me.txtValorTransadoVenta.Text = oAccionesCE.ValorTransadoVenta.ToString() Me.txtImpuestosYComisionesVenta.Text = oAccionesCE.SumaImpuestosYComisionesVenta.ToString() Dim ComisionCasaVenta As Double = 0 Dim ComisionBolsaVenta As Double = 0 Dim ValorTransadoVenta As Double = 0 Dim ValorIOFVenta = 0.0, ValorRentaVenta = 0.0 Me.txtMontoNetoVenta.Text = oAccionesCE.MontoNetoVentasus.ToString Me.txtPrecioSucioVenta.Text = oAccionesCE.PrecioSucioVentasus.ToString() End Sub Sub RefrescarValorControles() If DatosCargados Then If (Cargar) Then If (String.IsNullOrEmpty(oAccionesCE.RetornoBruto.ToString())) Then Else Me.txtRetornoAnualBrutoCompra.Text = oAccionesCE.RetornoBruto * 100 End If If String.IsNullOrEmpty(txtGananciaCapitalUnitarioVenta.Text) Then txtGananciaCapitalUnitarioVenta.Text = 0 End If If String.IsNullOrEmpty(txtRetornoAnualNetoVenta.Text) Then txtRetornoAnualNetoVenta.Text = 0 End If Dim IOF = oAccionesCE.IOF Dim Renta = oAccionesCE.Renta If (IOF) Then ChkIOF.Checked = True Else ChkIOF.Checked = False End If If (Renta) Then ChkRenta.Checked = True Else ChkRenta.Checked = False End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeCasaCompra.Text.TrimEnd("%"))) Then If (String.IsNullOrEmpty(oAccionesCE.ComisionCompraCasa)) Then Else If Not oAccionesCE.ComisionCompraCasa = "0" Then Me.txtComisionPorcentajeCasaCompra.Text = CStr(oAccionesCE.ComisionCompraCasa * 100) + "%" End If End If End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeBolsaCompra.Text.TrimEnd("%"))) Then If (String.IsNullOrEmpty(oAccionesCE.ComisionCompraBolsa)) Then Else If Not oAccionesCE.ComisionCompraBolsa = "0" Then Me.txtComisionPorcentajeBolsaCompra.Text = CStr(oAccionesCE.ComisionCompraBolsa * 100) + "%" End If End If End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeCasaVenta.Text.TrimEnd("%"))) Then If (String.IsNullOrEmpty(oAccionesCE.ComisionVentaCasa)) Then End If If Not oAccionesCE.ComisionVentaCasa = "0" Then Me.txtComisionPorcentajeCasaVenta.Text = CStr(oAccionesCE.ComisionVentaCasa * 100) + "%" End If End If If (String.IsNullOrEmpty(Me.txtComisionPorcentajeBolsaVenta.Text.TrimEnd("%"))) Then If (String.IsNullOrEmpty(oAccionesCE.ComisionVentaBolsa)) Then Else If Not oAccionesCE.ComisionVentaBolsa = "0" Then Me.txtComisionPorcentajeBolsaVenta.Text = CStr(oAccionesCE.ComisionVentaBolsa * 100) + "%" End If End If End If Else If (oAccionesCE.Tipo = "Porcentaje") Then rdbPorcentaje.Checked = True ElseIf (oAccionesCE.Tipo = "Efectivo") Then rdbEfectivo.Checked = True End If End If 'COMPRA If (String.IsNullOrEmpty(oAccionesCE.PrecioLimpioCompra.ToString())) Then Else If Not oAccionesCE.PrecioLimpioCompra.ToString() = "0" Then Me.txtPrecioLimpioCompra.Text = oAccionesCE.PrecioLimpioCompra.ToString() End If End If If (String.IsNullOrEmpty(oAccionesCE.FechaOperacionCompra)) Then Me.dtpFechaOperacionCompra.Value = Date.Now.Date Else Me.dtpFechaOperacionCompra.Value = oAccionesCE.FechaOperacionCompra End If If (String.IsNullOrEmpty(oAccionesCE.FechaVencimientoCompra)) Then Me.dtpFechaVencimientoCompra.Value = Date.Now.Date Else Me.dtpFechaVencimientoCompra.Value = oAccionesCE.FechaVencimientoCompra End If If (String.IsNullOrEmpty(oAccionesCE.DiasDeTenenciaCompra.ToString)) Then Else Me.txtDiasDeTenenciaCompra.Text = oAccionesCE.DiasDeTenenciaCompra.ToString End If If (String.IsNullOrEmpty(oAccionesCE.GananciaDeCapitalTotalCompra.ToString)) Then Else Me.txtGananciaCapitalTotalCompra.Text = oAccionesCE.GananciaDeCapitalTotalCompra.ToString End If If (String.IsNullOrEmpty(oAccionesCE.GananciaDeCapitalUnitarioCompra.ToString)) Then Else Me.txtGananciaCapitalUnitarioCompra.Text = oAccionesCE.GananciaDeCapitalUnitarioCompra.ToString End If If (String.IsNullOrEmpty(oAccionesCE.RetornoAnualizadoNetoCompra.ToString(Configuraciones.CodigoTXTPorcentaje))) Then Else Me.txtRetornoAnualNetoCompra.Text = oAccionesCE.RetornoAnualizadoNetoCompra.ToString() End If If (String.IsNullOrEmpty(oAccionesCE.CantidadCompra.ToString)) Then Else If Not oAccionesCE.CantidadCompra.ToString = "0" Then Me.txtUnidadesCompra.Text = oAccionesCE.CantidadCompra.ToString End If End If If (String.IsNullOrEmpty(oAccionesCE.ValorTransadoCompra.ToString(Configuraciones.CodigoTXTMontos))) Then Else Me.txtValorTransadoCompra.Text = oAccionesCE.ValorTransadoCompra.ToString() End If Dim ComisionCasaCompra As Double = 0 Dim ComisionBolsaCompra As Double = 0 Dim ValorTransadoCompra As Double = 0 If String.IsNullOrEmpty(txtComisionPorcentajeCasaCompra.Text.TrimEnd("%")) Then ComisionCasaCompra = 0 Else ComisionCasaCompra = txtComisionPorcentajeCasaCompra.Text.TrimEnd("%") / 100 End If If String.IsNullOrEmpty(txtComisionPorcentajeBolsaCompra.Text.TrimEnd("%")) Then ComisionBolsaCompra = 0 Else ComisionBolsaCompra = txtComisionPorcentajeBolsaCompra.Text.TrimEnd("%") / 100 End If If Not String.IsNullOrEmpty(txtValorTransadoCompra.Text) Then ValorTransadoCompra = txtValorTransadoCompra.Text End If Me.txtComisionCasaCompra.Text = CalcularComisionImpuestos(ComisionCasaCompra, txtValorTransadoCompra.Text) Me.txtComisionBolsaCompra.Text = CalcularComisionImpuestos(ComisionBolsaCompra, txtValorTransadoCompra.Text) If (String.IsNullOrEmpty(oAccionesCE.SumaImpuestosYComisionesCompra.ToString(Configuraciones.CodigoTXTMontos))) Then Else Me.txtImpuestosYComisionesCompra.Text = oAccionesCE.SumaImpuestosYComisionesCompra.ToString() End If Dim ValorIOFCompra = 0.0, ValorRentaCompra = 0.0 If (Not String.IsNullOrEmpty(txtIOFCompra.Text.ToString)) Then ValorIOFCompra = txtIOFCompra.Text End If If (Not String.IsNullOrEmpty(txtRentaCompra.Text.ToString)) Then ValorRentaCompra = txtRentaCompra.Text End If If (String.IsNullOrEmpty(oAccionesCE.PrecioSucioCompra.ToString(Configuraciones.CodigoTXTMontos))) Then Else Me.txtPrecioSucioCompra.Text = oAccionesCE.PrecioSucioCompra.ToString() End If 'VENTA If (String.IsNullOrEmpty(oAccionesCE.PrecioLimpioVenta.ToString())) Then Else If Not oAccionesCE.PrecioLimpioVenta = 0 Then Me.txtPrecioLimpioVenta.Text = oAccionesCE.PrecioLimpioVenta.ToString() End If End If If (String.IsNullOrEmpty(oAccionesCE.FechaOperacionVenta)) Then Me.dtpFechaOperacionVenta.Value = Date.Now.Date Else Me.dtpFechaOperacionVenta.Value = oAccionesCE.FechaOperacionVenta End If If (String.IsNullOrEmpty(oAccionesCE.FechaVencimientoVenta)) Then Me.dtpFechaVencimientoVenta.Value = Date.Now.Date Else Me.dtpFechaVencimientoVenta.Value = oAccionesCE.FechaVencimientoVenta End If If (String.IsNullOrEmpty(oAccionesCE.DiasDeTenenciaVenta.ToString)) Then Else Me.txtDiasDeTenenciaVenta.Text = oAccionesCE.DiasDeTenenciaVenta.ToString End If If (String.IsNullOrEmpty(oAccionesCE.GananciaDeCapitalTotalVenta.ToString(Configuraciones.CodigoTXTMontos))) Then Else Me.txtGananciaCapitalTotalVenta.Text = oAccionesCE.GananciaDeCapitalTotalVenta.ToString() End If If (String.IsNullOrEmpty(oAccionesCE.GananciaDeCapitalUnitarioVenta.ToString)) Then Else If Double.IsNaN(oAccionesCE.GananciaDeCapitalUnitarioVenta.ToString) Then Else Me.txtGananciaCapitalUnitarioVenta.Text = oAccionesCE.GananciaDeCapitalUnitarioVenta.ToString End If End If If String.IsNullOrEmpty(txtRetornoAnualBrutoVenta.Text.ToString) Then txtRetornoAnualBrutoVenta.Text = 0 End If Variables.IngresoBruto = CalcularIngresoBruto() Variables.IngresoNeto = CalcularIngresoNeto() If (rdbEfectivo.Checked) Then If (String.IsNullOrEmpty(oAccionesCE.RetornoAnualizadoBrutoVenta.ToString(Configuraciones.CodigoTXTPorcentaje))) Then Else Me.txtRetornoAnualBrutoVenta.Text = oAccionesCE.RetornoAnualizadoBrutoVenta.ToString() End If Else Dim Existe = dgvDividendos.Rows.Count If (Existe >= 1) Then If (Not dgvDividendos.Rows(0).Cells("Dividendo").Value Is Nothing) Then Dim Valor = dgvDividendos.Rows(0).Cells("Dividendo").Value.ToString.Trim("%") If (String.IsNullOrEmpty(Valor)) Then Else Me.txtRetornoAnualBrutoVenta.Text = CStr((CDec(Valor.ToString.Trim("%")) * 100)) + "%" End If End If End If End If If (rdbEfectivo.Checked) Then If (String.IsNullOrEmpty(oAccionesCE.RetornoAnualizadoNetoVenta.ToString(Configuraciones.CodigoTXTPorcentaje))) Then Else Me.txtRetornoAnualNetoVenta.Text = oAccionesCE.RetornoAnualizadoNetoVenta.ToString() End If Else Dim Existe = dgvDividendos.Rows.Count If (Existe >= 1) Then Dim Valor = dgvDividendos.Rows(0).Cells("PorcISR").Value If (String.IsNullOrEmpty(Valor)) Then Else Me.txtRetornoAnualNetoVenta.Text = CStr(CDec(txtRetornoAnualBrutoVenta.Text.Trim("%")) * (1 - Valor)) + "%" End If End If End If If (String.IsNullOrEmpty(oAccionesCE.CantidadVenta.ToString)) Then Else If Not oAccionesCE.CantidadVenta = 0 Then Me.txtUnidadesVenta.Text = oAccionesCE.CantidadVenta.ToString End If End If If (String.IsNullOrEmpty(oAccionesCE.ValorTransadoVenta.ToString())) Then Else Me.txtValorTransadoVenta.Text = oAccionesCE.ValorTransadoVenta.ToString() End If If (String.IsNullOrEmpty(oAccionesCE.SumaImpuestosYComisionesVenta.ToString())) Then Else Me.txtImpuestosYComisionesVenta.Text = oAccionesCE.SumaImpuestosYComisionesVenta.ToString() End If Dim ComisionCasaVenta As Double = 0 Dim ComisionBolsaVenta As Double = 0 Dim ValorTransadoVenta As Double = 0 If Not String.IsNullOrEmpty(txtComisionPorcentajeCasaVenta.Text.TrimEnd("%")) Then ComisionCasaVenta = txtComisionPorcentajeCasaVenta.Text.TrimEnd("%") / 100 End If If Not String.IsNullOrEmpty(txtComisionPorcentajeBolsaVenta.Text.TrimEnd("%")) Then ComisionBolsaVenta = txtComisionPorcentajeBolsaVenta.Text.TrimEnd("%") / 100 End If If Not String.IsNullOrEmpty(txtValorTransadoVenta.Text) Then ValorTransadoVenta = txtValorTransadoVenta.Text End If Me.txtComisionCasaVenta.Text = CalcularComisionImpuestos(ComisionCasaVenta, ValorTransadoVenta) Me.txtComisionBolsaVenta.Text = CalcularComisionImpuestos(ComisionBolsaVenta, ValorTransadoVenta) txtGananciaCapitalTotalVenta.Text += SumaComisiones() Dim ValorIOFVenta = 0.0, ValorRentaVenta = 0.0 If (Not String.IsNullOrEmpty(txtIOFVenta.Text.ToString)) Then ValorIOFVenta = txtIOFVenta.Text End If If (Not String.IsNullOrEmpty(txtRentaVenta.Text.ToString)) Then ValorRentaVenta = txtRentaVenta.Text End If If (String.IsNullOrEmpty(oAccionesCE.MontoNetoVenta.ToString())) Then Else Me.txtMontoNetoVenta.Text = CDec(oAccionesCE.MontoNetoVenta.ToString()) - CDec(txtComisionBolsaVenta.Text) - CDec(txtComisionCasaVenta.Text) - ValorIOFVenta - ValorRentaVenta End If If (String.IsNullOrEmpty(CDec(oAccionesCE.MontoNetoCompra.ToString(Configuraciones.CodigoTXTMontos)))) Or String.IsNullOrEmpty((CDec(txtComisionBolsaCompra.Text)) Or String.IsNullOrEmpty(CDec(txtComisionCasaCompra.Text)) Or String.IsNullOrEmpty(ValorIOFCompra) Or String.IsNullOrEmpty(ValorRentaCompra)) Then Else Me.txtMontoNetoCompra.Text = (CDec(oAccionesCE.MontoNetoCompra.ToString())) + (CDec(txtComisionBolsaCompra.Text) + CDec(txtComisionCasaCompra.Text) + ValorIOFCompra + ValorRentaCompra) End If If (String.IsNullOrEmpty(oAccionesCE.PrecioSucioVenta.ToString())) Then Me.txtPrecioSucioVenta.Text = "0.0" Else If Double.IsNaN(oAccionesCE.PrecioSucioVenta.ToString()) Then Me.txtPrecioSucioVenta.Text = "0.0" Else Me.txtPrecioSucioVenta.Text = oAccionesCE.PrecioSucioVenta.ToString() End If End If End If End Sub Function CalcularIngresoBruto() Dim Cantidad = dgvDividendos.Rows.Count - 1 Dim FechaActual = Date.Now.Date Dim ContadorIngreso As Double = 0.0 For i As Integer = 0 To Cantidad Try If (Not String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("Fecha").Value.ToString)) Then Dim FechaPrograma As Date = CDate(dgvDividendos.Rows(i).Cells("Fecha").Value.ToString) If (FechaActual >= FechaPrograma) Then If (Not String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("IngresoBruto").Value.ToString)) Then ContadorIngreso += CDec(dgvDividendos.Rows(i).Cells("IngresoBruto").Value.ToString) End If End If End If Catch ex As Exception End Try Next Return ContadorIngreso End Function Function CalcularIngresoNeto() Dim Cantidad = dgvDividendos.Rows.Count - 1 Dim FechaActual = Date.Now.Date Dim ContadorIngreso As Double = 0.0 For i As Integer = 0 To Cantidad Try If (Not String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("Fecha").Value.ToString)) Then Dim FechaPrograma As Date = CDate(dgvDividendos.Rows(i).Cells("Fecha").Value.ToString) If (FechaActual >= FechaPrograma) Then If (Not String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("IngresoNeto").Value.ToString)) Then ContadorIngreso += CDec(dgvDividendos.Rows(i).Cells("IngresoNeto").Value.ToString) End If End If End If Catch ex As Exception End Try Next Return ContadorIngreso End Function Function SumaComisiones() Dim ComisionCasaVenta As Double = txtComisionCasaVenta.Text Dim ComisionBolsaVenta As Double = txtComisionBolsaVenta.Text Dim Total As Double = 0.0 Total = ComisionCasaVenta + ComisionBolsaVenta Return Total End Function Function CalcularComisionImpuestos(ByVal Comision As Double, ByVal ValorTransado As Double) Return Comision * ValorTransado End Function Private Sub PrepararTablaDividendos() Dim oDataGridViewTextBoxColumn As DataGridViewTextBoxColumn oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "CodInv" oDataGridViewTextBoxColumn.DataPropertyName = "CodInv" oDataGridViewTextBoxColumn.HeaderText = "Código Inversión" oDataGridViewTextBoxColumn.ValueType = GetType(String) oDataGridViewTextBoxColumn.Visible = False Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "Correlativo" oDataGridViewTextBoxColumn.DataPropertyName = "Correlativo" oDataGridViewTextBoxColumn.HeaderText = "Correlativo" oDataGridViewTextBoxColumn.ValueType = GetType(String) oDataGridViewTextBoxColumn.Visible = True Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "Fecha" oDataGridViewTextBoxColumn.DataPropertyName = "Fecha" oDataGridViewTextBoxColumn.HeaderText = "Fecha" oDataGridViewTextBoxColumn.Name = "Fecha" oDataGridViewTextBoxColumn.ValueType = GetType(Date) Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.ValueType = GetType(String) oDataGridViewTextBoxColumn.Name = "Dividendo" oDataGridViewTextBoxColumn.DataPropertyName = "Dividendo" oDataGridViewTextBoxColumn.HeaderText = "Dividendo" Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "CantidadBase" oDataGridViewTextBoxColumn.DataPropertyName = "CantidadBase" oDataGridViewTextBoxColumn.HeaderText = "Cantidad Base" oDataGridViewTextBoxColumn.ValueType = GetType(Double) oDataGridViewTextBoxColumn.DefaultCellStyle.Format = Configuraciones.CodigoTXTMontos Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "IngresoBruto" oDataGridViewTextBoxColumn.DataPropertyName = "IngresoBruto" oDataGridViewTextBoxColumn.HeaderText = "Ingreso Bruto" oDataGridViewTextBoxColumn.ValueType = GetType(Double) oDataGridViewTextBoxColumn.DefaultCellStyle.Format = Configuraciones.CodigoTXTMontos oDataGridViewTextBoxColumn.ReadOnly = True Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "PorcISR" oDataGridViewTextBoxColumn.DataPropertyName = "PorcISR" oDataGridViewTextBoxColumn.HeaderText = "% ISR" oDataGridViewTextBoxColumn.DefaultCellStyle.Format = Configuraciones.CodigoTXTPorcentaje oDataGridViewTextBoxColumn.ValueType = GetType(Double) Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "ISR" oDataGridViewTextBoxColumn.DataPropertyName = "ISR" oDataGridViewTextBoxColumn.HeaderText = "ISR" oDataGridViewTextBoxColumn.ValueType = GetType(Double) oDataGridViewTextBoxColumn.DefaultCellStyle.Format = Configuraciones.CodigoTXTMontos oDataGridViewTextBoxColumn.ReadOnly = True Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "IngresoNeto" oDataGridViewTextBoxColumn.DataPropertyName = "IngresoNeto" oDataGridViewTextBoxColumn.HeaderText = "Ingreso Neto" oDataGridViewTextBoxColumn.ValueType = GetType(Double) oDataGridViewTextBoxColumn.DefaultCellStyle.Format = Configuraciones.CodigoTXTMontos oDataGridViewTextBoxColumn.ReadOnly = True Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "Estado" oDataGridViewTextBoxColumn.DataPropertyName = "Estado" oDataGridViewTextBoxColumn.HeaderText = "Estado" oDataGridViewTextBoxColumn.ValueType = GetType(String) oDataGridViewTextBoxColumn.Visible = False Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "FechaInicio" oDataGridViewTextBoxColumn.DataPropertyName = "FechaInicio" oDataGridViewTextBoxColumn.HeaderText = "FechaInicio" oDataGridViewTextBoxColumn.ValueType = GetType(String) oDataGridViewTextBoxColumn.Visible = False Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "FechaCorte" oDataGridViewTextBoxColumn.DataPropertyName = "FechaCorte" oDataGridViewTextBoxColumn.HeaderText = "FechaCorte" oDataGridViewTextBoxColumn.ValueType = GetType(String) oDataGridViewTextBoxColumn.Visible = False Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) oDataGridViewTextBoxColumn = New DataGridViewTextBoxColumn oDataGridViewTextBoxColumn.Name = "NumDiv" oDataGridViewTextBoxColumn.DataPropertyName = "NumDiv" oDataGridViewTextBoxColumn.HeaderText = "NuvDiv" oDataGridViewTextBoxColumn.ValueType = GetType(String) oDataGridViewTextBoxColumn.Visible = False Me.dgvDividendos.Columns.Add(oDataGridViewTextBoxColumn) End Sub Private Function FechaDividendo() Dim Index = dgvDividendos.CurrentRow.Index Dim IndexAnterior = Index - 1 Dim FechaInicial = dtpFechaOperacionCompra.Value Dim FechaActual = dgvDividendos.Rows(Index).Cells("Fecha").Value Dim FechaCalcul As Date = Date.Now.Date If (String.IsNullOrEmpty(FechaActual)) Then If (Index = 0) Then FechaCalcul = Operaciones.Meses(12, FechaInicial, FechaInicial) Else Dim Fecha = dgvDividendos.Rows(IndexAnterior).Cells("Fecha").Value FechaCalcul = Operaciones.Meses(12, Fecha, FechaInicial) End If Else FechaCalcul = FechaActual End If Return FechaCalcul End Function Private Sub PrepararCalculoDividendos(ByVal IdFila As Integer) Dim vFila As DataGridViewRow = dgvDividendos.Rows(IdFila) If (rdbEfectivo.Checked) Then If vFila.IsNewRow Then vFila.Cells("Fecha").Value = FechaDividendo() vFila.Cells("Dividendo").Value = oAccionesCE.FactorDeDividendo End If If rdbEfectivo.Checked Then If (String.IsNullOrEmpty(txtUnidadesCompra.Text)) Then vFila.Cells("CantidadBase").Value = 0.0 Else vFila.Cells("CantidadBase").Value = CDec(txtUnidadesCompra.Text) End If Else If (String.IsNullOrEmpty(txtValorTransadoCompra.Text)) Then vFila.Cells("CantidadBase").Value = 0.0 Else vFila.Cells("CantidadBase").Value = CDec(txtValorTransadoCompra.Text) End If End If vFila.Cells("IngresoBruto").Value = 0.00 vFila.Cells("PorcISR").Value = 0.05 vFila.Cells("ISR").Value = 0.00 vFila.Cells("IngresoNeto").Value = 0.00 If dgvDividendos.Rows(IdFila).Cells("NumDiv").Value Is DBNull.Value Then dgvDividendos.Rows(IdFila).Cells("NumDiv").Value = Correlativo() Else If String.IsNullOrEmpty(dgvDividendos.Rows(IdFila).Cells("NumDiv").Value) Then dgvDividendos.Rows(IdFila).Cells("NumDiv").Value = Correlativo() End If End If Else If vFila.IsNewRow Then vFila.Cells("Fecha").Value = FechaDividendo() vFila.Cells("Dividendo").Value = oAccionesCE.FactorDeDividendo.ToString + "%" If (vFila.Cells("Dividendo").Value.ToString.IndexOf("%") = -1) Then vFila.Cells("Dividendo").Value += "%" End If If rdbEfectivo.Checked Then If (String.IsNullOrEmpty(txtUnidadesCompra.Text)) Then vFila.Cells("CantidadBase").Value = 0.0 Else vFila.Cells("CantidadBase").Value = CDec(txtUnidadesCompra.Text) End If Else If (String.IsNullOrEmpty(txtValorTransadoCompra.Text)) Then vFila.Cells("CantidadBase").Value = 0.0 Else vFila.Cells("CantidadBase").Value = CDec(txtValorTransadoCompra.Text) End If End If vFila.Cells("IngresoBruto").Value = 0.00 vFila.Cells("PorcISR").Value = 0.05 vFila.Cells("ISR").Value = 0.00 vFila.Cells("IngresoNeto").Value = 0.00 If dgvDividendos.Rows(IdFila).Cells("NumDiv").Value Is DBNull.Value Then dgvDividendos.Rows(IdFila).Cells("NumDiv").Value = Correlativo() Else If String.IsNullOrEmpty(dgvDividendos.Rows(IdFila).Cells("NumDiv").Value) Then dgvDividendos.Rows(IdFila).Cells("NumDiv").Value = Correlativo() End If End If End If End If If (vFila.Cells("Fecha").Value Is DBNull.Value) Then vFila.Cells("Fecha").Value = FechaDividendo() Else If String.IsNullOrEmpty(vFila.Cells("Fecha").Value) Then vFila.Cells("Fecha").Value = FechaDividendo() End If End If RefrescarValorControles() End Sub Sub AgregarFechaCO() dgvDividendos.CurrentRow.Cells("FechaInicio").Value = Variables.FechaInicialCorte dgvDividendos.CurrentRow.Cells("FechaCorte").Value = Variables.FechaCorteCorte End Sub Function CalculoIngresoBrutoEfectivo(ByVal CantidadUnidades As Double, ByVal Dividendo As Double) Dim Total = CantidadUnidades * (Dividendo) Return Total End Function Function CalculoIngresoBrutoPorcentaje(ByVal ValorTransado As Double, ByVal Dividendo As Double, ByVal Dias As Integer, ByVal Fecha As Date) Dim Total As Double = 0 If (Operaciones.AñoBisiesto(Fecha) = 364) Then Total = (ValorTransado * (Dividendo / 100) * Dias) / 365 End If If (Operaciones.AñoBisiesto(Fecha) = 365) Then Total = (ValorTransado * (Dividendo / 100) * Dias) / 366 End If Return Total End Function Private Sub dgvDividendos_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles dgvDividendos.CellBeginEdit PrepararCalculoDividendos(e.RowIndex) End Sub Private Sub dgvDividendos_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDividendos.CellEndEdit CalcularDividendos() RefrescarValorControles() End Sub Private Sub dgvDividendos_UserDeletedRow(sender As Object, e As DataGridViewRowEventArgs) Handles dgvDividendos.UserDeletedRow End Sub Private Sub dgvImpuestosYComisiones_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) End Sub Private Sub dgvImpuestosYComisiones_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) End Sub Private Sub dgvImpuestosYComisiones_UserDeletedRow(sender As Object, e As DataGridViewRowEventArgs) oAccionesCE.ImpuestosYComisiones.AcceptChanges() End Sub Private Sub dgvImpuestosYComisiones_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) End Sub Private Sub dgvDividendos_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDividendos.CellContentClick End Sub Private Sub TabPage2_Click(sender As Object, e As EventArgs) End Sub Private Sub txtImpuestosYComisionesCompra_TextChanged(sender As Object, e As EventArgs) Handles txtImpuestosYComisionesCompra.TextChanged End Sub Private Sub TOperacion(ByVal TOperacion As String) If (TOperacion = "N") Then HabilitarBotones() ElseIf (TOperacion = "B") Then DeshabilitarBotones() End If End Sub Sub HabilitarBotones() txtUnidadesCompra.Enabled = True txtUnidadesVenta.Enabled = True End Sub Sub DeshabilitarBotones() txtDiasDeTenenciaCompra.Enabled = False txtDiasDeTenenciaVenta.Enabled = False txtGananciaCapitalTotalCompra.Enabled = False txtGananciaCapitalTotalVenta.Enabled = False txtGananciaCapitalUnitarioCompra.Enabled = False txtGananciaCapitalUnitarioVenta.Enabled = False txtRetornoAnualBrutoCompra.Enabled = False txtRetornoAnualBrutoVenta.Enabled = False txtRetornoAnualNetoCompra.Enabled = False txtRetornoAnualNetoVenta.Enabled = False txtUnidadesCompra.Enabled = False txtUnidadesVenta.Enabled = False txtValorTransadoCompra.Enabled = False txtValorTransadoVenta.Enabled = False txtImpuestosYComisionesCompra.Enabled = False txtImpuestosYComisionesVenta.Enabled = False txtMontoNetoCompra.Enabled = False txtMontoNetoVenta.Enabled = False txtPrecioSucioCompra.Enabled = False txtPrecioSucioVenta.Enabled = False End Sub Private Sub dtgcomisiones_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) End Sub Private Sub TabPage4_Click(sender As Object, e As EventArgs) End Sub Private Sub dtgcomisiones_CellContentClick_1(sender As Object, e As DataGridViewCellEventArgs) End Sub Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click Estado = "N" btnAceptar.Text = "Nuevo" End Sub Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click Estado = "M" btnAceptar.Text = "Modificar" End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) If (Estado = "N") Then NuevaAccion() End If End Sub Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click Estado = "B" btnAceptar.Text = "Eliminar" End Sub Private Sub btnAgregar_Click(sender As Object, e As EventArgs) End Sub Private Sub dgvDividendos_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDividendos.CellClick ModificarFechaCorte() PrepararCalculoDividendos(e.RowIndex) End Sub Sub ModificarFechaCorte() If rdbPorcentaje.Checked Then Dim Index As Integer = dgvDividendos.CurrentRow.Index If dgvDividendos.Rows(Index).Cells("Fecha").ColumnIndex = dgvDividendos.CurrentCell.ColumnIndex Then Dim FechaReferencia = dgvDividendos.Rows(Index).Cells("Fecha").Value If (Not String.IsNullOrEmpty(FechaReferencia)) Then Dim año = FechaReferencia.Year Dim PrimeraFecha, SegundaFecha If (dgvDividendos.Rows(Index).Cells("FechaInicio").Value Is Nothing) Then PrimeraFecha = CDate("1/1/" + año.ToString) ElseIf (dgvDividendos.Rows(Index).Cells("FechaInicio").Value Is DBNull.Value) Then PrimeraFecha = CDate("1/1/" + año.ToString) Else PrimeraFecha = dgvDividendos.Rows(Index).Cells("FechaInicio").Value End If If (dgvDividendos.Rows(Index).Cells("FechaCorte").Value Is Nothing) Then SegundaFecha = CDate("31/12/" + año.ToString) ElseIf (dgvDividendos.Rows(Index).Cells("FechaCorte").Value Is DBNull.Value) Then SegundaFecha = CDate("31/12/" + año.ToString) Else SegundaFecha = dgvDividendos.Rows(Index).Cells("FechaCorte").Value End If Variables.FechaInicial = PrimeraFecha Variables.FechaCorte = SegundaFecha Variables.CorrelativoACC = dgvDividendos.Rows(Index).Cells("NumDiv").Value frmFechasAcciones.Show() End If Cierre = True End If End If End Sub Private Sub txtComisionPorcentajeCasaCompra_TextChanged(sender As Object, e As EventArgs) Handles txtComisionPorcentajeCasaCompra.TextChanged RefrescarValorControles() End Sub Private Sub txtComisionPorcentajeBolsaCompra_TextChanged(sender As Object, e As EventArgs) Handles txtComisionPorcentajeBolsaCompra.TextChanged RefrescarValorControles() End Sub Private Sub txtComisionPorcentajeCasaVenta_TextChanged(sender As Object, e As EventArgs) Handles txtComisionPorcentajeCasaVenta.TextChanged RefrescarValorControles() End Sub Private Sub txtComisionPorcentajeBolsaVenta_TextChanged(sender As Object, e As EventArgs) Handles txtComisionPorcentajeBolsaVenta.TextChanged RefrescarValorControles() End Sub Private Sub txtMontoNetoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtMontoNetoCompra.TextChanged End Sub Private Sub btnAgregarImpuesto_Click(sender As Object, e As EventArgs) End Sub Private Sub dgvImpuestoAgregado_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) End Sub Private Sub btnQuitar_Click(sender As Object, e As EventArgs) End Sub Private Sub dgvImpuestoAgregado_CellClick(sender As Object, e As DataGridViewCellEventArgs) End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) End Sub Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems End Sub Sub ValidarRentaIOF() If (ChkIOF.Checked) Then CalculosIOF() Else BloquearIOF() End If RefrescarValorControles() If (ChkRenta.Checked) Then CalculosRenta() Else BloquearRenta() End If RefrescarValorControles() End Sub Private Sub ChkIOF_CheckedChanged(sender As Object, e As EventArgs) Handles ChkIOF.CheckedChanged If (ChkIOF.Checked) Then oAccionesCE.IOF = 1 CalculosIOF() Else oAccionesCE.IOF = 0 BloquearIOF() End If RefrescarValorControles() End Sub Sub BloquearIOF() lblCompra1.Visible = False lblVenta1.Visible = False txtIOFCompra.Text = String.Empty txtIOFCompra.Visible = False txtIOFVenta.Text = String.Empty txtIOFVenta.Visible = False End Sub Sub CalculosIOF() If (Not String.IsNullOrEmpty(txtValorTransadoCompra.Text) And Not String.IsNullOrEmpty(txtValorTransadoVenta.Text)) Then lblCompra1.Visible = True lblVenta1.Visible = True txtIOFCompra.Visible = True txtIOFVenta.Visible = True Dim ValorTransadoCompra = txtValorTransadoCompra.Text Dim ValorTransadoVenta = txtValorTransadoVenta.Text txtIOFCompra.Text = CalculoImpuestos(ValorTransadoCompra, 0.0025) txtIOFVenta.Text = CalculoImpuestos(ValorTransadoVenta, 0.0025) End If End Sub Private Sub ChkRenta_CheckedChanged(sender As Object, e As EventArgs) Handles ChkRenta.CheckedChanged If (ChkRenta.Checked) Then oAccionesCE.Renta = 1 CalculosRenta() Else oAccionesCE.Renta = 0 BloquearRenta() End If RefrescarValorControles() End Sub Sub CalculosRenta() If (Not String.IsNullOrEmpty(txtValorTransadoCompra.Text) And Not String.IsNullOrEmpty(txtValorTransadoVenta.Text)) Then lblCompra2.Visible = True lblVenta2.Visible = True txtRentaVenta.Visible = True txtRentaCompra.Visible = True Dim ValorTransadoCompra = txtValorTransadoCompra.Text Dim ValorTransadoVenta = txtValorTransadoVenta.Text txtRentaCompra.Text = CalculoImpuestos(ValorTransadoCompra, 0.1) txtRentaVenta.Text = CalculoImpuestos(ValorTransadoVenta, 0.1) End If End Sub Sub BloquearRenta() lblCompra2.Visible = False lblVenta2.Visible = False txtRentaCompra.Text = String.Empty txtRentaCompra.Visible = False txtRentaVenta.Text = String.Empty txtRentaVenta.Visible = False End Sub Function CalculoImpuestos(ByVal ValorTransado As Double, ByVal Impuesto As Double) Dim Valor = ValorTransado * Impuesto Return Valor End Function Private Sub rdbEfectivo_CheckedChanged(sender As Object, e As EventArgs) Handles rdbEfectivo.CheckedChanged If (rdbEfectivo.Checked) Then LimpiarDividendosCambios(1) Else LimpiarDividendosCambios(2) End If CambiarBase() CambioCalculo = True CambioCalculo = False If (Cargado) Then RefrescarValorControles() End If End Sub Private Sub rdbPorcentaje_CheckedChanged(sender As Object, e As EventArgs) Handles rdbPorcentaje.CheckedChanged If (rdbEfectivo.Checked) Then LimpiarDividendosCambios(1) Else LimpiarDividendosCambios(2) End If CambiarBase() CambioCalculo = True CambioCalculo = False If (Cargado) Then RefrescarValorControles() End If End Sub Sub CambiarBase() Dim Cantidad As Integer = dgvDividendos.Rows.Count - 1 For i As Integer = 0 To Cantidad If (dgvDividendos.Rows(i).Cells("NumDiv").Value Is DBNull.Value) Then Exit For Else If String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("NumDiv").Value) Then Exit For End If End If If rdbEfectivo.Checked Then If (String.IsNullOrEmpty(txtUnidadesCompra.Text)) Then dgvDividendos.Rows(i).Cells("CantidadBase").Value = 0.0 Else dgvDividendos.Rows(i).Cells("CantidadBase").Value = CDec(txtUnidadesCompra.Text) End If Else If (String.IsNullOrEmpty(txtValorTransadoCompra.Text)) Then dgvDividendos.Rows(i).Cells("CantidadBase").Value = 0.0 Else dgvDividendos.Rows(i).Cells("CantidadBase").Value = CDec(txtValorTransadoCompra.Text) End If End If Next CalcularDividendos() End Sub Private Sub dgvDividendos_Click(sender As Object, e As EventArgs) Handles dgvDividendos.Click End Sub Sub ClonarDatos() If (String.IsNullOrEmpty(txtUnidadesVenta.Text.ToString)) Then txtUnidadesVenta.Text = txtUnidadesCompra.Text End If End Sub Private Sub txtUnidadesCompra_Leave(sender As Object, e As EventArgs) Handles txtUnidadesCompra.Leave ClonarDatos() Formato() End Sub Private Sub rdbEfectivo_Click(sender As Object, e As EventArgs) Handles rdbEfectivo.Click End Sub Private Sub dgvDividendos_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDividendos.CellDoubleClick End Sub Private Sub txtPrecioLimpioCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPrecioLimpioCompra.KeyPress If String.IsNullOrEmpty(txtPrecioLimpioCompra.Text) Then If e.KeyChar = "." Then txtPrecioLimpioCompra.Text = "0" Exit Sub End If End If If (Not txtPrecioLimpioCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtPrecioLimpioVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPrecioLimpioVenta.KeyPress If String.IsNullOrEmpty(txtPrecioLimpioVenta.Text) Then If e.KeyChar = "." Then txtPrecioLimpioVenta.Text = "0" Exit Sub End If End If If (Not txtPrecioLimpioVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtUnidadesCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUnidadesCompra.KeyPress If String.IsNullOrEmpty(txtUnidadesCompra.Text) Then If e.KeyChar = "." Then txtUnidadesCompra.Text = "0" Exit Sub End If End If If (Not txtUnidadesCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtUnidadesVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUnidadesVenta.KeyPress If String.IsNullOrEmpty(txtUnidadesVenta.Text) Then If e.KeyChar = "." Then txtUnidadesVenta.Text = "0" Exit Sub End If End If If (Not txtUnidadesVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtComisionPorcentajeCasaCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionPorcentajeCasaCompra.KeyPress If String.IsNullOrEmpty(txtComisionPorcentajeCasaCompra.Text) Then If e.KeyChar = "." Then txtComisionPorcentajeCasaCompra.Text = "0" Exit Sub End If End If If (Not txtComisionPorcentajeCasaCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtComisionPorcentajeBolsaCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionPorcentajeBolsaCompra.KeyPress If String.IsNullOrEmpty(txtComisionPorcentajeBolsaCompra.Text) Then If e.KeyChar = "." Then txtComisionPorcentajeBolsaCompra.Text = "0" Exit Sub End If End If If (Not txtComisionPorcentajeBolsaCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtComisionPorcentajeCasaVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionPorcentajeCasaVenta.KeyPress If String.IsNullOrEmpty(txtComisionPorcentajeCasaVenta.Text) Then If e.KeyChar = "." Then txtComisionPorcentajeCasaVenta.Text = "0" Exit Sub End If End If If (Not txtComisionPorcentajeCasaVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtComisionPorcentajeBolsaVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionPorcentajeBolsaVenta.KeyPress If String.IsNullOrEmpty(txtComisionPorcentajeBolsaVenta.Text) Then If e.KeyChar = "." Then txtComisionPorcentajeBolsaVenta.Text = "0" Exit Sub End If End If If (Not txtComisionPorcentajeBolsaVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click End Sub Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint End Sub Private Sub TabPage1_Click(sender As Object, e As EventArgs) Handles TbOperacion.Click End Sub Private Sub txtGananciaCapitalTotalVenta_TextChanged(sender As Object, e As EventArgs) Handles txtGananciaCapitalTotalVenta.TextChanged End Sub Private Sub txtDiasDeTenenciaVenta_TextChanged(sender As Object, e As EventArgs) Handles txtDiasDeTenenciaVenta.TextChanged End Sub Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click End Sub Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click End Sub Private Sub txtIOFCompra_TextChanged(sender As Object, e As EventArgs) Handles txtIOFCompra.TextChanged End Sub Private Sub txtRentaCompra_TextChanged(sender As Object, e As EventArgs) Handles txtRentaCompra.TextChanged End Sub Private Sub CalcularDividendos() Dim Cantidad As Integer = dgvDividendos.Rows.Count - 2 For i As Integer = 0 To Cantidad If (String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("Dividendo").Value)) Then dgvDividendos.Rows(i).Cells("Dividendo").Value = 0 End If If rdbEfectivo.Checked Then If (String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("Dividendo").Value)) Then dgvDividendos.Rows(i).Cells("Dividendo").Value = 0 End If End If Dim Dividendos As Double = dgvDividendos.Rows(i).Cells("Dividendo").Value.ToString.Trim("%") Dim Porcentaje As Double = dgvDividendos.Rows(i).Cells("PorcISR").Value Dim Valor = dgvDividendos.Rows(i).Cells("CantidadBase").Value If rdbEfectivo.Checked Then Dim CalculoIB = CalculoIngresoBrutoEfectivo(Valor, Dividendos) Dim CalculoRenta = CalculoIB * Porcentaje Dim CalculoIN = CalculoIB - CalculoRenta dgvDividendos.Rows(i).Cells("IngresoBruto").Value = CalculoIB dgvDividendos.Rows(i).Cells("ISR").Value = CalculoRenta dgvDividendos.Rows(i).Cells("IngresoNeto").Value = CalculoIN Else If (dgvDividendos.Rows(i).Cells("Dividendo").Value.ToString.IndexOf("%") = -1) Then dgvDividendos.Rows(i).Cells("Dividendo").Value = dgvDividendos.Rows(i).Cells("Dividendo").Value.ToString + "%" End If Dim Dias As Integer = 0 Dim FechaInicialCorte As Date = Date.Now.Date Dim FechaCorteCorte As Date = Date.Now.Date If (dgvDividendos.Rows(i).Cells("FechaInicio").Value IsNot DBNull.Value And dgvDividendos.Rows(i).Cells("FechaCorte").Value IsNot DBNull.Value) Then If (Not String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("FechaInicio").Value) And Not String.IsNullOrEmpty(dgvDividendos.Rows(i).Cells("FechaCorte").Value)) Then FechaInicialCorte = dgvDividendos.Rows(i).Cells("FechaInicio").Value FechaCorteCorte = dgvDividendos.Rows(i).Cells("FechaCorte").Value Dias = DateDiff(DateInterval.Day, FechaInicialCorte, FechaCorteCorte) Dias += 1 Dim CalculoIBP = CalculoIngresoBrutoPorcentaje(Valor, Dividendos, Dias, FechaInicialCorte) Dim CalculoRenta = CalculoIBP * Porcentaje Dim CalculoIN = CalculoIBP - CalculoRenta dgvDividendos.Rows(i).Cells("IngresoBruto").Value = CalculoIBP dgvDividendos.Rows(i).Cells("ISR").Value = CalculoRenta dgvDividendos.Rows(i).Cells("IngresoNeto").Value = CalculoIN End If End If End If Next CorrelativoSinBD() End Sub Public Sub btnActualizar_Click(sender As Object, e As EventArgs) Handles btnActualizar.Click AgregarFechaCO() CalcularDividendos() End Sub Private Sub TabPage3_Click(sender As Object, e As EventArgs) Handles TbDividendos.Click End Sub Sub LimpiarDividendosCambios(ByVal Calculo As Integer) Dim Cantidad As Integer = dgvDividendos.Rows.Count - 2 For i As Integer = 0 To Cantidad If (Calculo = 1) Then If (Not dgvDividendos.Rows(i).Cells("Dividendo").Value.ToString.IndexOf("%") = -1) Then dgvDividendos.Rows(i).Cells("Dividendo").Value = dgvDividendos.Rows(i).Cells("Dividendo").Value.ToString.ToString.Trim("%") End If Else If (dgvDividendos.Rows(i).Cells("Dividendo").Value.ToString.IndexOf("%") = -1) Then dgvDividendos.Rows(i).Cells("Dividendo").Value = dgvDividendos.Rows(i).Cells("Dividendo").Value.ToString + "%" End If End If dgvDividendos.Rows(i).Cells("IngresoBruto").Value = 0 dgvDividendos.Rows(i).Cells("ISR").Value = 0 dgvDividendos.Rows(i).Cells("IngresoNeto").Value = 0 Next End Sub Sub CargarDividendos() Dim Codigo As String = Variables.Codigo Dim dr = oAccionesDAO.CargarDividendo(Codigo) While dr.Read dgvDividendos.Rows.Add("", "", dr("Fecha"), dr("Dividendo"), dr("CantidadBase"), dr("IngresoBruto"), dr("PorcISR"), dr("ISR"), dr("IngresoNeto"), "", dr("FechaInicio"), dr("FechaCorte"), dr("NumDiv")) End While End Sub Private Sub btnGenerarAccion_Click(sender As Object, e As EventArgs) End Sub Private Sub dgvDividendos_CellMouseMove(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvDividendos.CellMouseMove If Cierre Then AgregarFechaCO() CalcularDividendos() Cierre = False End If End Sub Private Sub dgvDividendos_MouseMove(sender As Object, e As MouseEventArgs) Handles dgvDividendos.MouseMove If Cierre Then AgregarFechaCO() CalcularDividendos() Cierre = False End If End Sub Private Sub btnQuitar_Click_1(sender As Object, e As EventArgs) Handles btnQuitar.Click QuitarFila() CorrelativoSinBD() End Sub Sub QuitarFila() Dim result As Integer = MsgBox("¿Está seguro que desea eliminar la fila?", MsgBoxStyle.OkCancel) ' Test result. Dim codigo As String = Variables.Codigo Dim Numero As Integer = dgvDividendos.CurrentRow.Cells("NumDiv").Value If result = MsgBoxResult.Ok Then Try dgvDividendos.Rows.Remove(dgvDividendos.CurrentRow) oAccionesDAO.EliminarElemenoInd(codigo, Numero) Catch ex As Exception MsgBox("No ha seleccionado una fila") End Try End If End Sub Private Sub txtPrecioSucioVenta_TextChanged(sender As Object, e As EventArgs) Handles txtPrecioSucioVenta.TextChanged End Sub Private Sub txtPrecioLimpioCompra_Leave(sender As Object, e As EventArgs) Handles txtPrecioLimpioCompra.Leave Formato() End Sub Private Sub txtComisionPorcentajeCasaCompra_Leave(sender As Object, e As EventArgs) Handles txtComisionPorcentajeCasaCompra.Leave Formato() End Sub Private Sub txtComisionPorcentajeBolsaCompra_Leave(sender As Object, e As EventArgs) Handles txtComisionPorcentajeBolsaCompra.Leave Formato() End Sub Private Sub txtPrecioLimpioVenta_Leave(sender As Object, e As EventArgs) Handles txtPrecioLimpioVenta.Leave Formato() End Sub Private Sub txtUnidadesVenta_Leave(sender As Object, e As EventArgs) Handles txtUnidadesVenta.Leave Formato() End Sub Private Sub txtComisionPorcentajeCasaVenta_Leave(sender As Object, e As EventArgs) Handles txtComisionPorcentajeCasaVenta.Leave Formato() End Sub Private Sub txtComisionPorcentajeBolsaVenta_Leave(sender As Object, e As EventArgs) Handles txtComisionPorcentajeBolsaVenta.Leave Formato() End Sub Private Sub frmAcciones_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize Redimencionar() End Sub Private Sub txtPrecioLimpioCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPrecioLimpioCompra.KeyUp If txtPrecioLimpioCompra.Text = "." Then txtPrecioLimpioCompra.Text = ".0" End If End Sub Private Sub txtUnidadesCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtUnidadesCompra.KeyUp If txtUnidadesCompra.Text = "." Then txtUnidadesCompra.Text = ".0" End If End Sub Private Sub txtComisionPorcentajeCasaCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionPorcentajeCasaCompra.KeyUp If txtComisionPorcentajeCasaCompra.Text = "." Then txtComisionPorcentajeCasaCompra.Text = ".0" End If End Sub Private Sub txtComisionPorcentajeBolsaCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionPorcentajeBolsaCompra.KeyUp If txtComisionPorcentajeBolsaCompra.Text = "." Then txtComisionPorcentajeBolsaCompra.Text = ".0" End If End Sub Private Sub txtPrecioLimpioVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPrecioLimpioVenta.KeyUp If txtPrecioLimpioVenta.Text = "." Then txtPrecioLimpioVenta.Text = ".0" End If End Sub Private Sub txtUnidadesVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtUnidadesVenta.KeyUp If txtUnidadesVenta.Text = "." Then txtUnidadesVenta.Text = ".0" End If End Sub Private Sub txtComisionPorcentajeCasaVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionPorcentajeCasaVenta.KeyUp If txtComisionPorcentajeCasaVenta.Text = "." Then txtComisionPorcentajeCasaVenta.Text = ".0" End If End Sub Private Sub txtComisionPorcentajeBolsaVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionPorcentajeBolsaVenta.KeyUp If txtComisionPorcentajeBolsaVenta.Text = "." Then txtComisionPorcentajeBolsaVenta.Text = ".0" End If End Sub Private Sub btnVenta_Click(sender As Object, e As EventArgs) End Sub Private Sub txtValorTransadoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtValorTransadoCompra.TextChanged End Sub Sub CargarTransladoNuevo() Dim Existe As Boolean = ExisteInversion() If CantFormAbierto = False Then If Not RetCodigoInversionExiste And Not Existe Then Dim TipoTransaccionCompraVenta As String = Variables.TipoTransaccionCompraVenta If TipoTransaccionCompraVenta = "C" Then txtPrecioLimpioCompra.Text = Variables.RetPrecio txtUnidadesCompra.Text = Variables.RetUnidadesAcciones ElseIf TipoTransaccionCompraVenta = "V" Then txtPrecioLimpioVenta.Text = Variables.RetPrecio txtUnidadesVenta.Text = Variables.RetUnidadesAcciones End If End If End If End Sub Private Sub btnVenderTitulo_Click(sender As Object, e As EventArgs) Handles btnVenderTitulo.Click If Variables.InvocadorProInv = "frmINV" Then Dim TrasladarDatos As New TrasladarDatosCMVTA Dim General As New DAOGeneral Dim Codigo = Variables.Codigo Dim Tabla As String = "INV0" Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla) TrasladarDatos = RellenarDatosCMVTA() If Existe Then Dim CodigoInversion As String = Variables.Codigo Dim frmPINVCMVTA As New frmPIN("V", CodigoInversion, TrasladarDatos) frmINV.Close() Me.Close() frmPINVCMVTA.ShowDialog() End If End If End Sub Function RellenarDatosCMVTA() Dim TrasladarDatos As New TrasladarDatosCMVTA TrasladarDatos.FechaOperacionACC = Operaciones.ConvertirFecha(dtpFechaOperacionCompra.Value.ToString) TrasladarDatos.FechaVencimientoACC = Operaciones.ConvertirFecha(dtpFechaVencimientoCompra.Value.ToString) TrasladarDatos.PrecioLimpioACC = Operaciones.ConvertirDecimal(txtPrecioLimpioCompra.Text.ToString) TrasladarDatos.UnidadesACC = Operaciones.ConvertirEntero(txtUnidadesCompra.Text.ToString) TrasladarDatos.PorcentajeBolsaACC = Operaciones.ConvertirDecimal(txtComisionPorcentajeBolsaCompra.Text.ToString) TrasladarDatos.PorcentajeCasaACC = Operaciones.ConvertirDecimal(txtComisionPorcentajeCasaCompra.Text.ToString) TrasladarDatos.NombreInstrumento = "ACC" TrasladarDatos.AgregarCMVTA = True Return TrasladarDatos End Function Private Sub txtValorTransadoVenta_TextChanged(sender As Object, e As EventArgs) Handles txtValorTransadoVenta.TextChanged End Sub Private Sub txtMontoNetoVenta_TextChanged(sender As Object, e As EventArgs) Handles txtMontoNetoVenta.TextChanged End Sub Private Sub txtComisionCasaCompra_TextChanged(sender As Object, e As EventArgs) Handles txtComisionCasaCompra.TextChanged End Sub Private Sub txtComisionCasaVenta_TextChanged(sender As Object, e As EventArgs) Handles txtComisionCasaVenta.TextChanged End Sub End Class