* Idea:
* Trabajar los datos en un cursor paralelo a la tabla
* y grabar después, ó cancelar
* Se supone bloqueo manual de tablas
***********************************************************
* Formulario con:
* 6 TextBox
* 2 Botones "Nuevo", "Modificar"
* 1 CheckBox "Quitar"
* 1 CommandGroup con 2 botones ("\<Aceptar","\<Cancelar")
* 1 METODO: Agregar un método al formulario llamado "GETZAP"
* --------------------------------------------------------
* -nº de turno
* -nombre y apellido
* -telefono
* -fecha y horario
* -area
* -detalle
*************************************************************
* Las referencias por parent nos permiten utilizar el mismo
* código aunque los objetos se coloque en un container
* Lo único que es necesario cambiar, es en el Init del form,
* la referencia de ControlSource e inicialización.
**************************************************************
*---------------------
*init del formulario
*---------------------
* Apertura de la tabla
if !used("AGENDA")
copen=addbs(cDir)+"agenda"
use (cOpen) IN 0 SHARED
ENDIF
* 1 Crear un cursor clon de la tabla.
* SE le agregan dos campos de control
AFIELDS(gaCampos,"AGENDA")
IF USED("FAGENDA")
SELECT FAGENDA
USE
ENDIF
CREATE CURSOR FAGENDA FROM ARRAY GACAMPOS
ALTER table fagenda ;
ADD COLUMN "Ph_rec" I;
ADD COLUMN "PH_DEL" L
WITH thisform
* Acá se supone que se toman los campos de la tabla
* en el orden en que están
*
* Alternativamente se indican en forma manual
* .TExt1.ControlSource='fagenda.idturno'
* .TExt2.ControlSource='Fagenda.nombre'
* etc
*
FOR i=1 TO 6
cText="Text"+LTRIM(STR(i))
cField=FIELD(i)
.&cText..ControlSource='fagenda.&cField.'
NEXT
.Check1.ControlSource='fagenda.ph_del'
.Text1.Enbled=.f.
.Commandgroup1.Setall("Enabled",.f.)
.Command1.Enabled=.t.
.Command2.Enabled=.t.
.Check1.Enabled=.f.
ENDWITH
*-------------------------
* UNLOAD del form
*-------------------------
* borrar el cursor
IF USED("FAGENDA")
SELECT FAGENDA
USE
ENDIF
*-------------------------
* Boton "Nuevo" (click)
*-------------------------
set order to id_turno
go bott
nTurno=id_turno+1
SELECT fagenda
APPEND BLANK
replace idturno with nTurno
WITH this.Parent
FOR i=1 TO 6
cText="text"+LTRIM(STR(i))
.&cText..refresh
NEXT
.Check1.refresh
.Command2.Enabled=.f.
.Check1.Enabled=.t.
.Commandgroup1.Setall("Enabled",.t.)
ENDWITH
this.Enabled=.f.
this.Parent.text2.SetFocus()
*-------------------------
* Boton "Modificar" (click)
*-------------------------
SELECT agenda
BROWSE
NREC=RECNO()
SCATTER memvar
SELECT fagenda
ZAP
INSERT INTO fagenda FROM memvar
REPLACE PH_REC WITH RECNO("AGENDA")
WITH this.Parent
FOR i=1 TO 6
cText="text"+LTRIM(STR(i))
.&cText..refresh
NEXT
.Check1.refresh
.Command1.Enabled=.f.
.Check1.Enabled=.t.
.Commandgroup1.Setall("Enabled",.t.)
ENDWITH
this.Enabled=.f.
this.Parent.text2.SetFocus()
*-------------------------
* CommandGroup1.Buttons(1)
*-------------------------
SELECT FAGENDA
NREG=FAGENDA.PH_REC
LDEL=FAGENDA.PH_DEL
IF LDEL
* SI LDEL=.T. Y NREG=0 no hace nada
IF !EMPTY(NREG)
* BORRA EL REGISTRO
SELECT AGENDA
GO NREG
IF RLOCK()
DELETE
UNLOCK
ENDIF
ENDIF
ELSE
SELECT FAGENDA
SCATTER MEMVAR
IF EMPTY(NREG)
* AGREGA UN REGISTRO
INSERT INTO AGENDA FROM MEMVAR
SELECT AGENDA
UNLOCK
ELSE
* MODIFICA REGISTRO
SELECT AGENDA
GO NREG
IF RLOCK()
GATHER MEMVAR
UNLOCK
ENDIF
ENDIF
ENDIF
thisform.getZap(this.parent.parent)
*-------------------------
* CommandGroup1.Buttons(2)
*-------------------------
* Cancelar
*
thisform.getZap(this.parent.parent)
*-------------------------------
* METODO GETZAP (del formulario)
*-------------------------------
lparameters xoBj
SELECT FAGENDA
ZAP
WITH xobj
FOR i=1 TO 6
cText="text"+LTRIM(STR(i))
.&cText..refresh
NEXT
.Check1.refresh
.Command1.Enabled=.t.
.Command2.Enabled=.t.
.Check1.Enabled=.f.
.Commandgroup1.Setall("Enabled",.f.)
ENDWITH
* --------------------------------------------