frmFuturos.vb 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. Public Class frmFuturos
  2. Dim Estado As String = String.Empty
  3. Dim FuturosConsulta As New FuturosDAO
  4. Dim General As New DAOGeneral
  5. Dim InstrumentoFinanciero As String = General.ObtenerInstrumento(Variables.Codigo)
  6. Dim CambiarOperacionApoyo As Boolean = False
  7. Dim Numero As Integer = -1
  8. Dim Operaciones As New Operaciones
  9. Private TipoOperacion As String = String.Empty
  10. Sub New()
  11. ' Esta llamada es exigida por el diseñador.
  12. InitializeComponent()
  13. ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
  14. End Sub
  15. Sub New(TipOper As String)
  16. Me.New
  17. TipoOperacion = TipOper
  18. End Sub
  19. Private Sub btnAceptar_Click(sender As Object, e As EventArgs)
  20. End Sub
  21. Private Sub frmFuturos_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  22. Dim VExisteInversion As Boolean = False
  23. If Variables.TipoOperacionCMVTA = "C" Then
  24. GrpVenta.Enabled = False
  25. GrpCompra.Enabled = True
  26. Else
  27. GrpVenta.Enabled = True
  28. GrpCompra.Enabled = False
  29. End If
  30. If Variables.Codigo.IndexOf("OPC") > -1 Then
  31. lblTitulo.Text = "Opciones"
  32. InstrumentoFinanciero = "OPC"
  33. ElseIf Variables.Codigo.IndexOf("FUTU") > -1 Then
  34. InstrumentoFinanciero = "FUTU"
  35. End If
  36. CargarDatos()
  37. VExisteInversion = ExisteInversion()
  38. ValidarExistencia()
  39. RellenarDatos()
  40. ConfiguracionCMVTA(VExisteInversion)
  41. End Sub
  42. Sub ConfiguracionCMVTA(ByRef VExisteInversion As Boolean)
  43. Dim Codigo As String = Variables.Codigo
  44. Dim ExisteCMVTA As Boolean = General.ExisteCMVTA(Codigo)
  45. If Not ExisteCMVTA And Variables.InvocadorProInv = "frmINV" Then
  46. btnVenderTitulo.Visible = True
  47. End If
  48. If CantFormAbierto = False And Not VExisteInversion Then
  49. If Not Variables.TrasladarCMVTA Is Nothing Then
  50. txtCantidadContratosCompra.Text = Operaciones.ConvertirEntero(Variables.TrasladarCMVTA.CantidadContratosFUTU.ToString)
  51. txtComisionBrokerCompra.Text = Operaciones.ConvertirDecimal(Variables.TrasladarCMVTA.ComisionBrokerFUTU.ToString)
  52. dtpLiquidacionCompra.Value = Operaciones.ConvertirFecha(Variables.TrasladarCMVTA.FechaLiquidacionFUTU.ToString)
  53. dtpOperacionCompra.Value = Operaciones.ConvertirFecha(Variables.TrasladarCMVTA.FechaOperacionFUTU.ToString)
  54. dtpVencimientoCompra.Value = Operaciones.ConvertirFecha(Variables.TrasladarCMVTA.FechaVencimientoFUTU.ToString)
  55. txtIdentificacionContratoCompra.Text = Variables.TrasladarCMVTA.IdContratoFUTU
  56. txtValorUnidadCompra.Text = Operaciones.ConvertirDecimal(Variables.TrasladarCMVTA.PrecioUnitarioFUTU.ToString)
  57. txtUnidadesContratoCompra.Text = Operaciones.ConvertirEntero(Variables.TrasladarCMVTA.UnidadesPorContratoFUTU.ToString)
  58. End If
  59. End If
  60. End Sub
  61. Function ExisteInversion()
  62. Dim Codigo As String = Variables.Codigo
  63. Dim TablaINV As String = "INV0"
  64. Dim TablaPINV As String = "PIN0"
  65. Dim General As New DAOGeneral
  66. Dim InvPro = Variables.InvPro
  67. If InvPro = "I" Then
  68. Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV)
  69. If INV0 Then
  70. navNuevo.Visible = True
  71. Return True
  72. Else
  73. navNuevo.Visible = False
  74. Return False
  75. End If
  76. End If
  77. If InvPro = "P" Then
  78. Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV)
  79. If PINV0 Then
  80. navNuevo.Visible = True
  81. Return True
  82. Else
  83. navNuevo.Visible = False
  84. Return False
  85. End If
  86. End If
  87. Return False
  88. End Function
  89. Sub ValidarExistencia()
  90. Dim General As New DAOGeneral
  91. Dim Codigo As String = Variables.Codigo
  92. Dim Tabla As String = String.Empty
  93. If (InstrumentoFinanciero = "FUTU") Then
  94. Tabla = "FUT0"
  95. ElseIf (InstrumentoFinanciero = "OPC") Then
  96. Tabla = "OPC0"
  97. End If
  98. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  99. If (Existe) Then
  100. navNuevo.Enabled = False
  101. navModificar.Enabled = True
  102. navEliminar.Enabled = True
  103. Else
  104. navNuevo.Enabled = True
  105. navModificar.Enabled = False
  106. navEliminar.Enabled = False
  107. End If
  108. Estado = String.Empty
  109. btnAceptar.Text = "Aceptar"
  110. End Sub
  111. Function ExisteValidacion()
  112. Dim General As New DAOGeneral
  113. Dim Codigo As String = Variables.Codigo
  114. Dim Tabla As String = String.Empty
  115. If (InstrumentoFinanciero = "FUTU") Then
  116. Tabla = "FUT0"
  117. ElseIf (InstrumentoFinanciero = "OPC") Then
  118. Tabla = "OPC0"
  119. End If
  120. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  121. Return Existe
  122. End Function
  123. Sub CambiarPosicion()
  124. If (CambiarOperacionApoyo) Then
  125. Dim NuevaPosicionCompraH, NuevaPosicionVentaH, NuevaPosicionCompraV, NuevaPosicionVentaV
  126. NuevaPosicionCompraH = GrpCompra.Left
  127. NuevaPosicionCompraV = GrpCompra.Top
  128. NuevaPosicionVentaH = GrpVenta.Left
  129. NuevaPosicionVentaV = GrpVenta.Top
  130. GrpVenta.Left = NuevaPosicionCompraH
  131. GrpVenta.Top = NuevaPosicionCompraV
  132. GrpCompra.Left = NuevaPosicionVentaH
  133. GrpCompra.Top = NuevaPosicionVentaV
  134. CambiarOperacionApoyo = False
  135. Calculos()
  136. End If
  137. End Sub
  138. Sub Calculos()
  139. Dim CantContCompra, UnidadContratoCompra, ValorUnidadCompra, ComisionBrokerCompra As Double
  140. Dim CantContVenta, UnidadContratoVenta, ValorUnidadVenta, ComisionBrokerVenta As Double
  141. CantContCompra = Operaciones.ConvertirEntero(txtCantidadContratosCompra.Text.ToString)
  142. UnidadContratoCompra = Operaciones.ConvertirDecimal(txtUnidadesContratoCompra.Text.ToString)
  143. ValorUnidadCompra = Operaciones.ConvertirDecimal(txtValorUnidadCompra.Text.ToString)
  144. ComisionBrokerCompra = Operaciones.ConvertirDecimal(txtComisionBrokerCompra.Text.ToString)
  145. CantContVenta = Operaciones.ConvertirEntero(txtCantidadContratosVenta.Text.ToString)
  146. UnidadContratoVenta = Operaciones.ConvertirDecimal(txtUnidadesContratoVenta.Text.ToString)
  147. ValorUnidadVenta = Operaciones.ConvertirDecimal(txtValorUnidadVenta.Text.ToString)
  148. ComisionBrokerVenta = Operaciones.ConvertirDecimal(txtComisionBrokerVenta.Text.ToString)
  149. Dim ValorTransadoCompra = ValorTransado(CantContCompra, UnidadContratoCompra, ValorUnidadCompra)
  150. Dim ValorTransadoVenta = ValorTransado(CantContVenta, UnidadContratoVenta, ValorUnidadVenta)
  151. Dim ValorRecibidoCompra = ValorRecibido(ValorTransadoCompra, ComisionBrokerCompra)
  152. Dim ValorRecibidoVenta = ValorPagado(ValorTransadoVenta, ComisionBrokerVenta)
  153. txtValorTransadoCompra.Text = Operaciones.ConvertirDecimal(ValorTransadoCompra.ToString)
  154. txtValorTransadoVenta.Text = Operaciones.ConvertirDecimal(ValorTransadoVenta.ToString)
  155. txtValorRecibidoCompra.Text = Operaciones.ConvertirDecimal(ValorRecibidoCompra.ToString)
  156. txtValorRecibidoVenta.Text = Operaciones.ConvertirDecimal(ValorRecibidoVenta.ToString)
  157. If (cboOperacionVenta.SelectedIndex = 0) Then
  158. Dim GananciaPerdida = Format(Me.GananciaPerdida(txtValorRecibidoVenta.Text, txtValorRecibidoCompra.Text), "0.0000")
  159. txtGananciaPerdida.Text = Operaciones.ConvertirDecimal(GananciaPerdida.ToString)
  160. ElseIf (cboOperacionVenta.SelectedIndex = 1) Then
  161. Dim GananciaPerdida = Format(Me.GananciaPerdida(txtValorRecibidoCompra.Text, txtValorRecibidoVenta.Text), "0.0000")
  162. txtGananciaPerdida.Text = Operaciones.ConvertirDecimal(GananciaPerdida.ToString)
  163. Else
  164. txtGananciaPerdida.Text = "0.0"
  165. End If
  166. Dim Dias = DiasFechas(dtpLiquidacionCompra.Value, dtpLiquidacionVenta.Value)
  167. Dim Rendimientos = Format((Rendimiento(txtGananciaPerdida.Text, txtValorRecibidoVenta.Text, Dias) * 100), "0.0000")
  168. txtRendimiento.Text = Operaciones.ConvertirDecimal(Rendimientos.ToString).ToString + "%"
  169. End Sub
  170. Function ValorTransado(ByVal CantidadContratos As Double, ByVal UnidadesContrato As Double, ByVal ValorUnidad As Double)
  171. Dim ValorTrans As Double = 0
  172. ValorTrans = Operaciones.ConvertirEntero(CantidadContratos.ToString) *
  173. Operaciones.ConvertirDecimal(UnidadesContrato.ToString) *
  174. Operaciones.ConvertirDecimal(ValorUnidad.ToString)
  175. Return ValorTrans
  176. End Function
  177. Function ValorRecibido(ByVal ValorTransado As Double, ByVal ComisionBroker As Double)
  178. Dim ValorRec As Double = 0
  179. ValorRec = ValorTransado + ComisionBroker
  180. Return ValorRec
  181. End Function
  182. Function ValorPagado(ByVal ValorTransado As Double, ByVal ComisionBroker As Double)
  183. Dim ValorRec As Double = 0
  184. ValorRec = ValorTransado - ComisionBroker
  185. Return ValorRec
  186. End Function
  187. Function GananciaPerdida(ByVal ValorTraCompra As Double, ByVal ValorPagado As Double)
  188. Dim Valor As Double
  189. Valor = ValorTraCompra - ValorPagado
  190. Return Valor
  191. End Function
  192. Function Rendimiento(ByVal GananciaPerdida As Double, ByVal ValorRecibidoVenta As Double, ByVal Dias As Double)
  193. Dim Valor As Double
  194. If (ValorRecibidoVenta = 0 Or Dias = 0) Then
  195. Valor = 0
  196. Else
  197. Valor = GananciaPerdida / ValorRecibidoVenta * 365 / Dias
  198. End If
  199. Return Valor
  200. End Function
  201. Function DiasFechas(ByVal FechaLiC As Date, ByVal FechaLiV As Date)
  202. Dim Dias As Integer
  203. Dias = DateDiff(DateInterval.Day, FechaLiV, FechaLiC)
  204. Return Dias
  205. End Function
  206. Private Sub txtCantidadContratosCompra_TextChanged(sender As Object, e As EventArgs) Handles txtCantidadContratosCompra.TextChanged
  207. CopiarDatosAVenta()
  208. Calculos()
  209. End Sub
  210. Private Sub txtCantidadContratosVenta_TextChanged(sender As Object, e As EventArgs) Handles txtCantidadContratosVenta.TextChanged
  211. CopiarDatosACompra()
  212. Calculos()
  213. End Sub
  214. Private Sub txtUnidadesContratoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtUnidadesContratoCompra.TextChanged
  215. CopiarDatosAVenta()
  216. Calculos()
  217. End Sub
  218. Private Sub txtUnidadesContratoVenta_TextChanged(sender As Object, e As EventArgs) Handles txtUnidadesContratoVenta.TextChanged
  219. CopiarDatosACompra()
  220. Calculos()
  221. End Sub
  222. Private Sub txtValorUnidadCompra_TextChanged(sender As Object, e As EventArgs) Handles txtValorUnidadCompra.TextChanged
  223. Calculos()
  224. End Sub
  225. Private Sub txtValorUnidadVenta_TextChanged(sender As Object, e As EventArgs) Handles txtValorUnidadVenta.TextChanged
  226. Calculos()
  227. End Sub
  228. Private Sub txtComisionBrokerCompra_TextChanged(sender As Object, e As EventArgs) Handles txtComisionBrokerCompra.TextChanged
  229. Calculos()
  230. End Sub
  231. Private Sub txtComisionBrokerVenta_TextChanged(sender As Object, e As EventArgs) Handles txtComisionBrokerVenta.TextChanged
  232. Calculos()
  233. End Sub
  234. Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
  235. btnAceptar.Text = "Modificar"
  236. Estado = "M"
  237. End Sub
  238. Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
  239. btnAceptar.Text = "Nuevo"
  240. Estado = "N"
  241. End Sub
  242. Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
  243. btnAceptar.Text = "Eliminar"
  244. Estado = "B"
  245. End Sub
  246. Function ColeccionDatos()
  247. Dim coleccion As New Collection
  248. Dim FOperC, FLiqC, FVenC, VaUnidadC, ValorTransadoC, CoBrokerC, VaRecC, IdContratoC, CantidadContC, UnidadesContC
  249. Dim FOperV, FLiqV, FVenV, VaUnidadV, ValorTransadoV, CoBrokerV, VaRecV, IdContratoV, CantidadContV, UnidadesContV
  250. Dim TipoOperacion As String = "Corto"
  251. If (cboOperacionVenta.SelectedIndex = 1) Then
  252. TipoOperacion = "Largo"
  253. End If
  254. Dim GananciaPerdida, Rendimiento
  255. FOperC = dtpOperacionCompra.Value
  256. FLiqC = dtpLiquidacionCompra.Value
  257. FVenC = dtpVencimientoCompra.Value
  258. VaUnidadC = txtValorUnidadCompra.Text
  259. ValorTransadoC = txtValorTransadoCompra.Text
  260. CoBrokerC = txtComisionBrokerCompra.Text
  261. VaRecC = txtValorRecibidoCompra.Text
  262. IdContratoC = txtIdentificacionContratoCompra.Text
  263. CantidadContC = txtCantidadContratosCompra.Text
  264. UnidadesContC = txtUnidadesContratoCompra.Text
  265. FOperV = dtpOperacionVenta.Value
  266. FLiqV = dtpLiquidacionVenta.Value
  267. FVenV = dtpVencimientoVenta.Value
  268. VaUnidadV = txtValorUnidadVenta.Text
  269. ValorTransadoV = txtValorTransadoVenta.Text
  270. CoBrokerV = txtComisionBrokerVenta.Text
  271. VaRecV = txtValorRecibidoVenta.Text
  272. IdContratoV = txtIdentificacionContratoVenta.Text
  273. CantidadContV = txtCantidadContratosVenta.Text
  274. UnidadesContV = txtUnidadesContratoVenta.Text
  275. GananciaPerdida = txtGananciaPerdida.Text
  276. Rendimiento = txtRendimiento.Text.Trim("%") / 100
  277. coleccion.Add(FOperC)
  278. coleccion.Add(FLiqC)
  279. coleccion.Add(FVenC)
  280. coleccion.Add(VaUnidadC)
  281. coleccion.Add(ValorTransadoC)
  282. coleccion.Add(CoBrokerC)
  283. coleccion.Add(VaRecC)
  284. coleccion.Add(IdContratoC)
  285. coleccion.Add(CantidadContC)
  286. coleccion.Add(UnidadesContC)
  287. coleccion.Add(FOperV)
  288. coleccion.Add(FLiqV)
  289. coleccion.Add(FVenV)
  290. coleccion.Add(VaUnidadV)
  291. coleccion.Add(ValorTransadoV)
  292. coleccion.Add(CoBrokerV)
  293. coleccion.Add(VaRecV)
  294. coleccion.Add(IdContratoV)
  295. coleccion.Add(CantidadContV)
  296. coleccion.Add(UnidadesContV)
  297. coleccion.Add(GananciaPerdida)
  298. coleccion.Add(Rendimiento)
  299. coleccion.Add(TipoOperacion)
  300. Return coleccion
  301. End Function
  302. Sub RellenarDatos()
  303. If (cboOperacionVenta.SelectedIndex = -1) Then
  304. cboOperacionVenta.SelectedIndex = 1
  305. End If
  306. If (String.IsNullOrEmpty(txtValorUnidadCompra.Text.ToString)) Then
  307. txtValorUnidadCompra.Text = "0.0"
  308. End If
  309. If (String.IsNullOrEmpty(txtValorTransadoCompra.Text.ToString)) Then
  310. txtValorTransadoCompra.Text = "0.0"
  311. End If
  312. If (String.IsNullOrEmpty(txtComisionBrokerCompra.Text.ToString)) Then
  313. txtComisionBrokerCompra.Text = "0.0"
  314. End If
  315. If (String.IsNullOrEmpty(txtValorRecibidoCompra.Text.ToString)) Then
  316. txtValorRecibidoCompra.Text = "0.0"
  317. End If
  318. If (String.IsNullOrEmpty(txtIdentificacionContratoCompra.Text.ToString)) Then
  319. txtIdentificacionContratoCompra.Text = " "
  320. End If
  321. If (String.IsNullOrEmpty(txtCantidadContratosCompra.Text.ToString)) Then
  322. txtCantidadContratosCompra.Text = "0.0"
  323. End If
  324. If (String.IsNullOrEmpty(txtUnidadesContratoCompra.Text.ToString)) Then
  325. txtUnidadesContratoCompra.Text = "0.0"
  326. End If
  327. If (String.IsNullOrEmpty(txtValorUnidadVenta.Text.ToString)) Then
  328. txtValorUnidadVenta.Text = "0.0"
  329. End If
  330. If (String.IsNullOrEmpty(txtValorTransadoVenta.Text.ToString)) Then
  331. txtValorTransadoVenta.Text = "0.0"
  332. End If
  333. If (String.IsNullOrEmpty(txtComisionBrokerVenta.Text.ToString)) Then
  334. txtComisionBrokerVenta.Text = "0.0"
  335. End If
  336. If (String.IsNullOrEmpty(txtValorRecibidoVenta.Text.ToString)) Then
  337. txtValorRecibidoVenta.Text = "0.0"
  338. End If
  339. If (String.IsNullOrEmpty(txtIdentificacionContratoVenta.Text.ToString)) Then
  340. txtIdentificacionContratoVenta.Text = " "
  341. End If
  342. If (String.IsNullOrEmpty(txtCantidadContratosVenta.Text.ToString)) Then
  343. txtCantidadContratosVenta.Text = "0.0"
  344. End If
  345. If (String.IsNullOrEmpty(txtUnidadesContratoVenta.Text.ToString)) Then
  346. txtUnidadesContratoVenta.Text = "0.0"
  347. End If
  348. If (String.IsNullOrEmpty(txtGananciaPerdida.Text.ToString)) Then
  349. txtGananciaPerdida.Text = "0.0"
  350. End If
  351. If (String.IsNullOrEmpty(txtRendimiento.Text.Trim("%").ToString)) Then
  352. txtRendimiento.Text = "0.0%"
  353. End If
  354. End Sub
  355. Sub CargarDatos()
  356. Dim codigo = Variables.Codigo
  357. Dim coleccion As New Collection
  358. If (InstrumentoFinanciero = "FUTU") Then
  359. coleccion = FuturosConsulta.CargarDatos(codigo)
  360. ElseIf (InstrumentoFinanciero = "OPC") Then
  361. coleccion = FuturosConsulta.CargarDatosOpciones(codigo)
  362. End If
  363. If (Not coleccion.Count = 1) Then
  364. If (InstrumentoFinanciero = "FUTU" Or InstrumentoFinanciero = "OPC") Then
  365. dtpOperacionCompra.Value = Operaciones.ConvertirFecha(coleccion(1).ToString)
  366. dtpLiquidacionCompra.Value = Operaciones.ConvertirFecha(coleccion(2).ToString)
  367. dtpVencimientoCompra.Value = Operaciones.ConvertirFecha(coleccion(3).ToString)
  368. txtValorUnidadCompra.Text = Operaciones.ConvertirDecimal(coleccion(4).ToString)
  369. txtValorTransadoCompra.Text = Operaciones.ConvertirDecimal(coleccion(5).ToString)
  370. txtComisionBrokerCompra.Text = Operaciones.ConvertirDecimal(coleccion(6).ToString)
  371. txtValorRecibidoCompra.Text = Operaciones.ConvertirDecimal(coleccion(7).ToString)
  372. txtIdentificacionContratoCompra.Text = coleccion(8).ToString
  373. txtCantidadContratosCompra.Text = Operaciones.ConvertirEntero(coleccion(9).ToString)
  374. txtUnidadesContratoCompra.Text = Operaciones.ConvertirDecimal(coleccion(10).ToString)
  375. dtpOperacionVenta.Value = Operaciones.ConvertirFecha(coleccion(11).ToString)
  376. dtpLiquidacionVenta.Value = Operaciones.ConvertirFecha(coleccion(12).ToString)
  377. dtpVencimientoVenta.Value = Operaciones.ConvertirFecha(coleccion(13).ToString)
  378. txtValorUnidadVenta.Text = Operaciones.ConvertirDecimal(coleccion(14).ToString)
  379. txtValorTransadoVenta.Text = Operaciones.ConvertirDecimal(coleccion(15).ToString)
  380. txtComisionBrokerVenta.Text = Operaciones.ConvertirDecimal(coleccion(16).ToString)
  381. txtValorRecibidoVenta.Text = Operaciones.ConvertirDecimal(coleccion(17).ToString)
  382. txtIdentificacionContratoVenta.Text = coleccion(18).ToString
  383. txtCantidadContratosVenta.Text = Operaciones.ConvertirEntero(coleccion(19).ToString)
  384. txtUnidadesContratoVenta.Text = Operaciones.ConvertirDecimal(coleccion(20).ToString)
  385. txtGananciaPerdida.Text = Operaciones.ConvertirDecimal(coleccion(21).ToString)
  386. txtRendimiento.Text = Operaciones.ConvertirDecimal(coleccion(22).ToString)
  387. If (coleccion(23).ToString = "Corto") Then
  388. cboOperacionVenta.SelectedIndex = 0
  389. ElseIf (coleccion(23).ToString = "Largo") Then
  390. cboOperacionVenta.SelectedIndex = 1
  391. End If
  392. End If
  393. End If
  394. End Sub
  395. Sub Nuevo()
  396. Dim codigo = Variables.Codigo
  397. Dim Coleccion = ColeccionDatos()
  398. FuturosConsulta.Nuevo(codigo, Coleccion)
  399. End Sub
  400. Sub NuevoOpciones()
  401. Dim codigo = Variables.Codigo
  402. Dim Coleccion = ColeccionDatos()
  403. FuturosConsulta.NuevoOpciones(codigo, Coleccion)
  404. End Sub
  405. Sub Modificar()
  406. Dim codigo = Variables.Codigo
  407. Dim Coleccion = ColeccionDatos()
  408. FuturosConsulta.Modificar(codigo, Coleccion)
  409. End Sub
  410. Sub ModificarOpciones()
  411. Dim codigo = Variables.Codigo
  412. Dim Coleccion = ColeccionDatos()
  413. FuturosConsulta.ModificarOpciones(codigo, Coleccion)
  414. End Sub
  415. Sub Eliminar()
  416. Dim codigo = Variables.Codigo
  417. FuturosConsulta.Eliminar(codigo)
  418. End Sub
  419. Sub EliminarOpciones()
  420. Dim codigo = Variables.Codigo
  421. FuturosConsulta.EliminarOpciones(codigo)
  422. End Sub
  423. Private Sub btnAceptar_Click_1(sender As Object, e As EventArgs) Handles btnAceptar.Click
  424. Dim Instrumento As String = Variables.Codigo
  425. If Instrumento.IndexOf("FUTU") > -1 Then
  426. If (Estado = "N") Then
  427. Nuevo()
  428. ElseIf (Estado = "M") Then
  429. Modificar()
  430. ElseIf (Estado = "B") Then
  431. Eliminar()
  432. ElseIf Not ExisteValidacion() Then
  433. Variables.ColeccionFUTU = ColeccionDatos()
  434. Me.Close()
  435. End If
  436. End If
  437. If Instrumento.IndexOf("OPC") > -1 Then
  438. If (Estado = "N") Then
  439. NuevoOpciones()
  440. ElseIf (Estado = "M") Then
  441. ModificarOpciones()
  442. ElseIf (Estado = "B") Then
  443. EliminarOpciones()
  444. ElseIf Not ExisteValidacion() Then
  445. Variables.ColeccionFUTU = ColeccionDatos()
  446. Me.Close()
  447. End If
  448. End If
  449. ValidarExistencia()
  450. End Sub
  451. Private Sub dtpLiquidacionCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpLiquidacionCompra.ValueChanged
  452. Calculos()
  453. RellenarDatos()
  454. End Sub
  455. Private Sub dtpLiquidacionVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpLiquidacionVenta.ValueChanged
  456. RellenarDatos()
  457. Calculos()
  458. End Sub
  459. Private Sub txtGananciaPerdida_TextChanged(sender As Object, e As EventArgs) Handles txtGananciaPerdida.TextChanged
  460. Calculos()
  461. End Sub
  462. Private Sub txtRendimiento_TextChanged(sender As Object, e As EventArgs) Handles txtRendimiento.TextChanged
  463. Calculos()
  464. End Sub
  465. Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems
  466. End Sub
  467. Private Sub cboOperacionVenta_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboOperacionVenta.SelectedIndexChanged
  468. If (Not Numero = cboOperacionVenta.SelectedIndex) Then
  469. CambiarOperacionApoyo = True
  470. Numero = cboOperacionVenta.SelectedIndex
  471. End If
  472. CambiarPosicion()
  473. End Sub
  474. Private Sub txtValorUnidadCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtValorUnidadCompra.KeyPress
  475. If String.IsNullOrEmpty(txtValorUnidadCompra.Text) Then
  476. If e.KeyChar = "." Then
  477. txtValorUnidadCompra.Text = "0"
  478. Exit Sub
  479. End If
  480. End If
  481. If (Not txtValorUnidadCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  482. Operaciones.ValidarEntrada(sender, e, True)
  483. Else
  484. Operaciones.ValidarEntrada(sender, e, False)
  485. End If
  486. End Sub
  487. Private Sub txtValorUnidadVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtValorUnidadVenta.KeyPress
  488. If String.IsNullOrEmpty(txtValorUnidadVenta.Text) Then
  489. If e.KeyChar = "." Then
  490. txtValorUnidadVenta.Text = "0"
  491. Exit Sub
  492. End If
  493. End If
  494. If (Not txtValorUnidadVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  495. Operaciones.ValidarEntrada(sender, e, True)
  496. Else
  497. Operaciones.ValidarEntrada(sender, e, False)
  498. End If
  499. End Sub
  500. Private Sub txtComisionBrokerCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionBrokerCompra.KeyPress
  501. If String.IsNullOrEmpty(txtComisionBrokerCompra.Text) Then
  502. If e.KeyChar = "." Then
  503. txtComisionBrokerCompra.Text = "0"
  504. Exit Sub
  505. End If
  506. End If
  507. If (Not txtComisionBrokerCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  508. Operaciones.ValidarEntrada(sender, e, True)
  509. Else
  510. Operaciones.ValidarEntrada(sender, e, False)
  511. End If
  512. End Sub
  513. Private Sub txtComisionBrokerVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionBrokerVenta.KeyPress
  514. If String.IsNullOrEmpty(txtComisionBrokerVenta.Text) Then
  515. If e.KeyChar = "." Then
  516. txtComisionBrokerVenta.Text = "0"
  517. Exit Sub
  518. End If
  519. End If
  520. If (Not txtComisionBrokerVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  521. Operaciones.ValidarEntrada(sender, e, True)
  522. Else
  523. Operaciones.ValidarEntrada(sender, e, False)
  524. End If
  525. End Sub
  526. Private Sub txtIdentificacionContratoCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtIdentificacionContratoCompra.KeyPress
  527. End Sub
  528. Private Sub txtIdentificacionContratoVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtIdentificacionContratoVenta.KeyPress
  529. End Sub
  530. Private Sub txtCantidadContratosCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCantidadContratosCompra.KeyPress
  531. If String.IsNullOrEmpty(txtCantidadContratosCompra.Text) Then
  532. If e.KeyChar = "." Then
  533. txtCantidadContratosCompra.Text = "0"
  534. Exit Sub
  535. End If
  536. End If
  537. If (Not txtCantidadContratosCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  538. Operaciones.ValidarEntrada(sender, e, True)
  539. Else
  540. Operaciones.ValidarEntrada(sender, e, False)
  541. End If
  542. End Sub
  543. Private Sub txtCantidadContratosVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCantidadContratosVenta.KeyPress
  544. If String.IsNullOrEmpty(txtCantidadContratosVenta.Text) Then
  545. If e.KeyChar = "." Then
  546. txtCantidadContratosVenta.Text = "0"
  547. Exit Sub
  548. End If
  549. End If
  550. If (Not txtCantidadContratosVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  551. Operaciones.ValidarEntrada(sender, e, True)
  552. Else
  553. Operaciones.ValidarEntrada(sender, e, False)
  554. End If
  555. End Sub
  556. Private Sub txtUnidadesContratoCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUnidadesContratoCompra.KeyPress
  557. If String.IsNullOrEmpty(txtUnidadesContratoCompra.Text) Then
  558. If e.KeyChar = "." Then
  559. txtUnidadesContratoCompra.Text = "0"
  560. Exit Sub
  561. End If
  562. End If
  563. If (Not txtUnidadesContratoCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  564. Operaciones.ValidarEntrada(sender, e, True)
  565. Else
  566. Operaciones.ValidarEntrada(sender, e, False)
  567. End If
  568. End Sub
  569. Private Sub txtUnidadesContratoVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUnidadesContratoVenta.KeyPress
  570. If String.IsNullOrEmpty(txtUnidadesContratoVenta.Text) Then
  571. If e.KeyChar = "." Then
  572. txtUnidadesContratoVenta.Text = "0"
  573. Exit Sub
  574. End If
  575. End If
  576. If (Not txtUnidadesContratoVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  577. Operaciones.ValidarEntrada(sender, e, True)
  578. Else
  579. Operaciones.ValidarEntrada(sender, e, False)
  580. End If
  581. End Sub
  582. Sub CopiarDatosACompra()
  583. If (cboOperacionVenta.SelectedIndex = 0) Then
  584. txtCantidadContratosCompra.Text = txtCantidadContratosVenta.Text
  585. txtUnidadesContratoCompra.Text = txtUnidadesContratoVenta.Text
  586. End If
  587. End Sub
  588. Sub CopiarDatosAVenta()
  589. If (cboOperacionVenta.SelectedIndex = 1) Then
  590. txtCantidadContratosVenta.Text = txtCantidadContratosCompra.Text
  591. txtUnidadesContratoVenta.Text = txtUnidadesContratoCompra.Text
  592. End If
  593. End Sub
  594. Private Sub txtIdentificacionContratoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtIdentificacionContratoCompra.TextChanged
  595. End Sub
  596. Private Sub dtpOperacionCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpOperacionCompra.ValueChanged
  597. RellenarDatos()
  598. End Sub
  599. Private Sub dtpVencimientoCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpVencimientoCompra.ValueChanged
  600. RellenarDatos()
  601. End Sub
  602. Private Sub txtValorUnidadCompra_Leave(sender As Object, e As EventArgs) Handles txtValorUnidadCompra.Leave
  603. RellenarDatos()
  604. End Sub
  605. Private Sub txtComisionBrokerCompra_Leave(sender As Object, e As EventArgs) Handles txtComisionBrokerCompra.Leave
  606. RellenarDatos()
  607. End Sub
  608. Private Sub txtIdentificacionContratoCompra_Leave(sender As Object, e As EventArgs) Handles txtIdentificacionContratoCompra.Leave
  609. RellenarDatos()
  610. End Sub
  611. Private Sub txtCantidadContratosCompra_Leave(sender As Object, e As EventArgs) Handles txtCantidadContratosCompra.Leave
  612. RellenarDatos()
  613. End Sub
  614. Private Sub txtUnidadesContratoCompra_Leave(sender As Object, e As EventArgs) Handles txtUnidadesContratoCompra.Leave
  615. RellenarDatos()
  616. End Sub
  617. Private Sub dtpOperacionVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpOperacionVenta.ValueChanged
  618. RellenarDatos()
  619. End Sub
  620. Private Sub dtpVencimientoVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpVencimientoVenta.ValueChanged
  621. RellenarDatos()
  622. End Sub
  623. Private Sub txtValorUnidadVenta_Leave(sender As Object, e As EventArgs) Handles txtValorUnidadVenta.Leave
  624. RellenarDatos()
  625. End Sub
  626. Private Sub txtComisionBrokerVenta_Leave(sender As Object, e As EventArgs) Handles txtComisionBrokerVenta.Leave
  627. RellenarDatos()
  628. End Sub
  629. Private Sub txtIdentificacionContratoVenta_Leave(sender As Object, e As EventArgs) Handles txtIdentificacionContratoVenta.Leave
  630. RellenarDatos()
  631. End Sub
  632. Private Sub txtCantidadContratosVenta_Leave(sender As Object, e As EventArgs) Handles txtCantidadContratosVenta.Leave
  633. RellenarDatos()
  634. End Sub
  635. Private Sub txtUnidadesContratoVenta_Leave(sender As Object, e As EventArgs) Handles txtUnidadesContratoVenta.Leave
  636. RellenarDatos()
  637. End Sub
  638. Private Sub txtValorUnidadCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtValorUnidadCompra.KeyUp
  639. If txtValorUnidadCompra.Text = "." Then
  640. txtValorUnidadCompra.Text = ".0"
  641. End If
  642. End Sub
  643. Private Sub txtComisionBrokerCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionBrokerCompra.KeyUp
  644. If txtComisionBrokerCompra.Text = "." Then
  645. txtComisionBrokerCompra.Text = ".0"
  646. End If
  647. End Sub
  648. Private Sub txtCantidadContratosCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCantidadContratosCompra.KeyUp
  649. If txtCantidadContratosCompra.Text = "." Then
  650. txtCantidadContratosCompra.Text = ".0"
  651. End If
  652. End Sub
  653. Private Sub txtUnidadesContratoCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtUnidadesContratoCompra.KeyUp
  654. If txtUnidadesContratoCompra.Text = "." Then
  655. txtUnidadesContratoCompra.Text = ".0"
  656. End If
  657. End Sub
  658. Private Sub txtValorUnidadVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtValorUnidadVenta.KeyUp
  659. If txtValorUnidadVenta.Text = "." Then
  660. txtValorUnidadVenta.Text = ".0"
  661. End If
  662. End Sub
  663. Private Sub txtComisionBrokerVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionBrokerVenta.KeyUp
  664. If txtComisionBrokerVenta.Text = "." Then
  665. txtComisionBrokerVenta.Text = ".0"
  666. End If
  667. End Sub
  668. Private Sub txtIdentificacionContratoVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtIdentificacionContratoVenta.KeyUp
  669. End Sub
  670. Private Sub txtCantidadContratosVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCantidadContratosVenta.KeyUp
  671. If txtCantidadContratosVenta.Text = "." Then
  672. txtCantidadContratosVenta.Text = ".0"
  673. End If
  674. End Sub
  675. Private Sub txtUnidadesContratoVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtUnidadesContratoVenta.KeyUp
  676. If txtUnidadesContratoVenta.Text = "." Then
  677. txtUnidadesContratoVenta.Text = ".0"
  678. End If
  679. End Sub
  680. Private Sub btnVenderTitulo_Click(sender As Object, e As EventArgs) Handles btnVenderTitulo.Click
  681. If Variables.InvocadorProInv = "frmINV" Then
  682. Dim TrasladarDatos As New TrasladarDatosCMVTA
  683. Dim General As New DAOGeneral
  684. Dim Codigo = Variables.Codigo
  685. Dim Tabla As String = "INV0"
  686. TrasladarDatos = RellenarDatosCMVTA()
  687. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  688. If Existe Then
  689. Dim CodigoInversion As String = Variables.Codigo
  690. Dim frmPINVCMVTA As New frmPIN("V", CodigoInversion, TrasladarDatos)
  691. frmINV.Close()
  692. Me.Close()
  693. frmPINVCMVTA.ShowDialog()
  694. End If
  695. End If
  696. End Sub
  697. Function RellenarDatosCMVTA()
  698. Dim TrasladarDatos As New TrasladarDatosCMVTA
  699. TrasladarDatos.CantidadContratosFUTU = Operaciones.ConvertirEntero(txtCantidadContratosCompra.Text.ToString)
  700. TrasladarDatos.ComisionBrokerFUTU = Operaciones.ConvertirDecimal(txtComisionBrokerCompra.Text.ToString)
  701. TrasladarDatos.FechaLiquidacionFUTU = Operaciones.ConvertirFecha(dtpLiquidacionCompra.Value.ToString)
  702. TrasladarDatos.FechaOperacionFUTU = Operaciones.ConvertirFecha(dtpOperacionCompra.Value.ToString)
  703. TrasladarDatos.FechaVencimientoFUTU = Operaciones.ConvertirFecha(dtpVencimientoCompra.Value.ToString)
  704. TrasladarDatos.UnidadesPorContratoFUTU = Operaciones.ConvertirDecimal(txtUnidadesContratoCompra.Text.ToString)
  705. TrasladarDatos.IdContratoFUTU = Operaciones.ConvertirDecimal(txtIdentificacionContratoCompra.Text.ToString)
  706. TrasladarDatos.PrecioUnitarioFUTU = Operaciones.ConvertirDecimal(txtValorUnidadCompra.Text.ToString)
  707. TrasladarDatos.NombreInstrumento = "FUTU"
  708. TrasladarDatos.AgregarCMVTA = True
  709. Return TrasladarDatos
  710. End Function
  711. Private Sub txtValorTransadoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtValorTransadoCompra.TextChanged
  712. End Sub
  713. Private Sub txtValorRecibidoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtValorRecibidoCompra.TextChanged
  714. End Sub
  715. Private Sub txtValorTransadoVenta_TextChanged(sender As Object, e As EventArgs) Handles txtValorTransadoVenta.TextChanged
  716. End Sub
  717. Private Sub txtValorRecibidoVenta_TextChanged(sender As Object, e As EventArgs) Handles txtValorRecibidoVenta.TextChanged
  718. End Sub
  719. End Class