Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ejercicio Regalos Empresariales (con metodologia de 2do parcial)
- private Sub btnGrabar_Click ()
- 'se agrega un nuevo regalo se lo asocia al cliente'
- 'validaciones'
- dim validador as Boolean
- validador = noEsStringVacio(txtRegalo.text)
- If validador = false Then
- end Sub
- End If
- validador = isDate(txtFecha.text)
- If validador = false Then
- end Sub
- End If
- If isNumeric(txtPrecio.text) = true Then
- validador = esPositivo(txtPrecio.text)
- else
- validador = false
- End If
- If validador = false Then
- end Sub
- End If
- If cboCliente.itemData(cboCliente.listIndex) = -1 Then
- msgBox "No hay ningun cliente seleccionado para asociar un regalo"
- exit sub
- End If
- Dim rsRegalos as Recordset
- set rsRegalos = abrirRs("Regalo")
- 'agrego el nuevo regalo en la base de datos'
- rsRegalos.addNew
- rsRegalos("codigo_cliente") = Cint(cboCliente.itemData(cboCliente.listIndex))
- rsRegalos("detalle") = txtRegalo.text
- rsRegalos("fecha") = date.now
- rsRegalos("precio") = format(txtPrecio.text,"$0,00")
- rsRegalos.update
- 'vuelvo a setear con valores inciales el formulario'
- txtRegalo.text = ""
- txtFecha.text = ""
- txtPrecio.text = ""
- cerrarRs(rsRegalos)
- call cargarClientes
- End Sub
- ----------------------------------------------------------------------------------------------------------------------------------
- private Sub lstCliente_Click()
- call cargarClientes
- call cargarRegalos
- End Sub
- private Sub cargarClientes()
- lstCliente.clear
- Dim rsCliente as Recordset
- Dim strCriterio as String
- set rsCliente = abrirRs("Cliente")
- Do while not rsCliente.EOF
- lstCliente.AddItem rsCliente("nombre") & " - " & format(sumaPreciosRegalos(rsCliente("codigo"),"$0,00"))
- lstCliente.itemData(lstCliente.newIndex) = rsCliente("codigo")
- rsCliente.movenext
- loop
- cerrarRs(rsCliente)
- End Sub
- private Function sumaPreciosRegalos(codCliente as Integer) as Single
- Dim result as Single
- Dim rsRegalo as Recordset
- Dim strCriterio as String
- result = 0
- strCriterio = "codigo_cliente = " & codCliente
- set rsRegalo = abrirRs("Regalo")
- rsRegalo.findFirst strCriterio
- Do While not rsRegalo.noMatch
- result = result + rsRegalo("precio")
- rsRegalo.findNext strCriterio
- Loop
- sumaPreciosRegalos = result
- End Function
- private Sub cargarRegalos()
- lstRegalo.clear
- dim rsRegalos as Recordset
- dim strCriterio as String
- If cboCliente.itemData(cboCliente.listIndex) <> -1 Then
- set rsRegalos = abrirRs("regalo")
- strCriterio = "codigo_cliente =" & cboCliente.itemData(cboCliente.listIndex)
- rsRegalos.findFirst strCriterio
- Do While not rsRegalos.noMatch
- lstRegalo.AddItem rsRegalos("detalle")
- lstRegalo.itemData(lstRegalo.newIndex) = rsRegalos("codigo")
- rsRegalos.findNext strCriterio
- Loop
- End If
- cerrarRs(rsRegalos)
- End Sub
- ------------------------------------------------------------------------------------------------------------------
- private Sub btnBorrar_Click ()
- 'el boton eliminar va a estar habilitado solamente si hay algun elemento para borrar'
- Dim rsRegalo as Recordset
- Dim strCriterio as String
- if lstRegalo.itemData(lstRegalo.listIndex) = -1 then
- msgBox "Debe seleccionar algun elemento para borrar"
- exit sub
- else
- strCriterio = "codigo = " & lstRegalo.itemData(lstRegalo.listIndex)
- rsRegalo.findFirst strCriterio
- if not rsRegalo.noMatch then
- rsRegalo.delete
- rsRegalo.update
- end if
- cerrarRs(rsRegalo)
- call cargarClientes
- call cargarRegalos
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment