arielgatti444

Ejercicio Regalos 2do Parcial

Jun 28th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Ejercicio Regalos Empresariales (con metodologia de 2do parcial)
  2.  
  3.  
  4. private Sub btnGrabar_Click ()
  5.  
  6. 'se agrega un nuevo regalo se lo asocia al cliente'
  7.  
  8. 'validaciones'
  9.  
  10. dim validador as Boolean
  11.  
  12. validador = noEsStringVacio(txtRegalo.text)
  13.  
  14. If validador = false Then
  15.     end Sub
  16. End If
  17.  
  18. validador = isDate(txtFecha.text)
  19.  
  20. If validador = false Then
  21.     end Sub
  22. End If
  23.  
  24. If isNumeric(txtPrecio.text) = true Then
  25.     validador = esPositivo(txtPrecio.text)
  26.     else
  27.     validador = false  
  28. End If
  29.  
  30. If validador = false Then
  31.     end Sub
  32. End If
  33.  
  34. If cboCliente.itemData(cboCliente.listIndex) = -1 Then
  35.     msgBox "No hay ningun cliente seleccionado para asociar un regalo"
  36.     exit sub
  37. End If
  38.  
  39. Dim rsRegalos as Recordset
  40.  
  41. set rsRegalos = abrirRs("Regalo")
  42.  
  43. 'agrego el nuevo regalo en la base de datos'
  44. rsRegalos.addNew
  45. rsRegalos("codigo_cliente") = Cint(cboCliente.itemData(cboCliente.listIndex))
  46. rsRegalos("detalle") = txtRegalo.text
  47. rsRegalos("fecha") = date.now
  48. rsRegalos("precio") = format(txtPrecio.text,"$0,00")
  49. rsRegalos.update
  50.  
  51. 'vuelvo a setear con valores inciales el formulario'
  52.  
  53. txtRegalo.text = ""
  54. txtFecha.text = ""
  55. txtPrecio.text = ""
  56.  
  57. cerrarRs(rsRegalos)
  58.  
  59. call cargarClientes
  60.  
  61. End Sub
  62.  
  63. ----------------------------------------------------------------------------------------------------------------------------------
  64.  
  65. private Sub lstCliente_Click()
  66.  
  67. call cargarClientes
  68.  
  69. call cargarRegalos
  70.  
  71. End Sub
  72.  
  73. private Sub cargarClientes()
  74.  
  75. lstCliente.clear
  76.  
  77. Dim rsCliente as Recordset
  78. Dim strCriterio as String
  79.  
  80. set rsCliente = abrirRs("Cliente")
  81.  
  82. Do while not rsCliente.EOF
  83.     lstCliente.AddItem rsCliente("nombre") & " - " & format(sumaPreciosRegalos(rsCliente("codigo"),"$0,00"))
  84.     lstCliente.itemData(lstCliente.newIndex) = rsCliente("codigo")
  85.     rsCliente.movenext
  86. loop
  87.  
  88. cerrarRs(rsCliente)
  89.    
  90. End Sub
  91.  
  92.  
  93. private Function sumaPreciosRegalos(codCliente as Integer) as Single
  94.     Dim result as Single
  95.     Dim rsRegalo as Recordset
  96.     Dim strCriterio as String
  97.  
  98.     result = 0
  99.  
  100.     strCriterio = "codigo_cliente = " & codCliente
  101.  
  102.     set rsRegalo = abrirRs("Regalo")
  103.  
  104.     rsRegalo.findFirst strCriterio
  105.  
  106.     Do While not rsRegalo.noMatch
  107.         result = result + rsRegalo("precio")
  108.         rsRegalo.findNext strCriterio
  109.     Loop
  110.  
  111.     sumaPreciosRegalos = result
  112.  
  113. End Function
  114.  
  115. private Sub cargarRegalos()
  116.     lstRegalo.clear
  117.     dim rsRegalos as Recordset
  118.     dim strCriterio as String
  119.  
  120.     If cboCliente.itemData(cboCliente.listIndex) <> -1 Then
  121.  
  122.         set rsRegalos = abrirRs("regalo")
  123.  
  124.         strCriterio = "codigo_cliente =" & cboCliente.itemData(cboCliente.listIndex)
  125.  
  126.         rsRegalos.findFirst strCriterio
  127.  
  128.         Do While not rsRegalos.noMatch
  129.            
  130.             lstRegalo.AddItem rsRegalos("detalle")
  131.             lstRegalo.itemData(lstRegalo.newIndex) = rsRegalos("codigo")
  132.  
  133.             rsRegalos.findNext strCriterio
  134.  
  135.          Loop  
  136.        
  137.     End If
  138.    
  139.     cerrarRs(rsRegalos)
  140.  
  141. End Sub
  142.  
  143.  
  144. ------------------------------------------------------------------------------------------------------------------
  145.  
  146. private Sub btnBorrar_Click ()
  147.  
  148. 'el boton eliminar va a estar habilitado solamente si hay algun elemento para borrar'
  149. Dim rsRegalo as Recordset
  150. Dim strCriterio as String
  151.  
  152. if lstRegalo.itemData(lstRegalo.listIndex) = -1 then
  153.     msgBox "Debe seleccionar algun elemento para borrar"
  154.     exit sub
  155.  
  156.     else
  157.  
  158.     strCriterio = "codigo = " & lstRegalo.itemData(lstRegalo.listIndex)
  159.  
  160.     rsRegalo.findFirst strCriterio
  161.  
  162.     if not rsRegalo.noMatch then
  163.  
  164.         rsRegalo.delete
  165.         rsRegalo.update
  166.  
  167.     end if
  168.  
  169.     cerrarRs(rsRegalo)
  170.  
  171.     call cargarClientes
  172.     call cargarRegalos
  173.  
  174. End Sub
Advertisement
Add Comment
Please, Sign In to add comment