*!* oComDB.TipoDB = 1 VFP DB; oComDB.TipoDB = 2 MySQL DB
LOCAL i, j, h, k, ;
lcOrden,lcClaseBase, ;
lcCampos, lcValores, lnGlobales, lcAux
WITH thisform
lnGlobales = 0
lcCampos=''
lcValores=''
IF This.llApend
FOR i=1 TO .ControlCount
lcClaseBase=LOWER(.Controls[i].BaseClass)
DO CASE
CASE AT(lcClaseBase,'textbox editbox checkbox spinner optiongroup')>0 AND !EMPTY(.Controls[i].lcCampo)
lcCampos=lcCampos+[,]+LOWER(.Controls[i].lcCampo)
DO CASE
CASE AT(TYPE('.Controls[i].Value'),'C M')>0
*Cambio
IF ( ( oComDB.TipoDB = 1 ) AND ( lcClaseBase = 'editbox' ) )
* Con DB_FOX los Memos deben pasarse como variables globales
lnGlobales = lnGlobales + 1
lcAux = 'gGlobal'+ALLTRIM(STR(lnGlobales))+' = ALLTRIM(.Controls[i].Value)'
&lcAux
lcValores=lcValores+[,gGlobal]+ALLTRIM(STR(lnGlobales))
ELSE
lcValores=lcValores+[,"]+ CHRTRAN(ALLTRIM(.Controls[i].Value),'"',"'")+["]
ENDIF
CASE AT(TYPE('.Controls[i].Value'),'N Y')>0
SET POINT TO "."
IF lcClaseBase='textbox'
lcValores=lcValores+[,]+ALLTRIM(STR(.Controls[i].Value, ;
.Controls[i].p_entera, ;
.Controls[i].p_decimal))
ELSE
lcValores=lcValores+[,]+ALLTRIM(STR(.Controls[i].Value))
ENDIF
SET POINT TO ","
CASE TYPE('.Controls[i].Value')='D'
lcValores=lcValores+[,CTOD("]+DTOC(.Controls[i].Value)+[")]
CASE TYPE('.Controls[i].Value')='T'
lcValores=lcValores+[,CTOT("]+TTOC(.Controls[i].Value)+[")]
CASE TYPE('.Controls[i].Value')='L'
lcValores=lcValores+[,]+IIF(.Controls[i].Value,".T.",".F.")
ENDCASE
CASE lcClaseBase='combobox' AND !EMPTY(.Controls[i].lcCampo)
lcCampos=lcCampos+[,]+LOWER(.Controls[i].lcCampo)
IF .Controls[i].llValue
DO CASE
CASE AT(TYPE('.Controls[i].Value'),'C M')>0
* Cambio
lcValores=lcValores+[,"]+CHRTRAN(ALLTRIM(.Controls[i].Value),'"',"'")+["]
CASE AT(TYPE('.Controls[i].Value'),'N Y')>0
lcValores=lcValores+[,]+ALLTRIM(STR(.Controls[i].Value))
ENDCASE
ELSE
lcValores=lcValores+[,"]+ALLTRIM(.Controls[i].DisplayValue)+["]
ENDIF
CASE lcClaseBase='image' AND !EMPTY(.Controls[i].lcCampo)
lcCampos=lcCampos+[,]+LOWER(.Controls[i].lcCampo)
lcValores=lcValores+[,"]+ALLTRIM(.Controls[i].Picture)+["]
ENDCASE
ENDFOR
lcOrden=[INSERT INTO ]+this.lcTabla+[ ]+STUFF(lcCampos,1,1,[(])+[) VALUES ]+STUFF(lcValores,1,1,[(])+[)]
oComDB.AddRegistro(lcOrden)
ELSE
lcOrden=[UPDATE ]+this.lcTabla+[ SET ]
FOR i=1 TO .ControlCount
lcClaseBase=LOWER(.Controls[i].BaseClass)
DO CASE
CASE AT(lcClaseBase,'textbox editbox checkbox spinner optiongroup')>0 AND !EMPTY(.Controls[i].lcCampo)
lcOrden=lcOrden+LOWER(.Controls[i].lcCampo)+[=]
DO CASE
CASE AT(TYPE('.Controls[i].Value'),'C M')>0
*Cambio
IF ( ( oComDB.TipoDB = 1 ) AND ( lcClaseBase = 'editbox' ) )
* Con DB_FOX los Memos deben pasarse como variables globales
lnGlobales = lnGlobales + 1
lcAux = 'gGlobal'+ALLTRIM(STR(lnGlobales))+' = ALLTRIM(.Controls[i].Value)'
&lcAux
lcOrden=lcOrden+[gGlobal]+ALLTRIM(STR(lnGlobales))+[,]
ELSE
lcOrden=lcOrden+["]+CHRTRAN(ALLTRIM(.Controls[i].Value),'"',"'")+[",]
ENDIF
CASE AT(TYPE('.Controls[i].Value'),'N Y')>0
SET POINT TO "."
IF lcClaseBase='textbox'
lcOrden=lcOrden+ALLTRIM(STR(.Controls[i].Value, ;
.Controls[i].p_entera, ;
.Controls[i].p_decimal))+[,]
ELSE
IF lcClaseBase='checkbox'
lcOrden=lcOrden+IIF(!EMPTY(.Controls[i].Value),".T.",".F.")+[,]
ELSE
lcOrden=lcOrden+ALLTRIM(STR(.Controls[i].Value))+[,]
ENDIF
ENDIF
SET POINT TO ","
CASE TYPE('.Controls[i].Value')='D'
lcOrden=lcOrden+[CTOD("]+DTOC(.Controls[i].Value)+["),]
CASE TYPE('.Controls[i].Value')='T'
lcOrden=lcOrden+[CTOT("]+TTOC(.Controls[i].Value)+["),]
CASE TYPE('.Controls[i].Value')='L'
lcOrden=lcOrden+IIF(.Controls[i].Value,".T.",".F.")+[,]
ENDCASE
CASE lcClaseBase='combobox' AND !EMPTY(.Controls[i].lcCampo)
lcOrden=lcOrden+LOWER(.Controls[i].lcCampo)+[=]
IF .Controls[i].llValue
DO CASE
CASE AT(TYPE('.Controls[i].Value'),'C M')>0
* Cambio
lcOrden=lcOrden+["]+CHRTRAN(ALLTRIM(.Controls[i].Value),'"',"'")+[",]
CASE AT(TYPE('.Controls[i].Value'),'N Y')>0
lcOrden=lcOrden+ALLTRIM(STR(.Controls[i].Value))+[,]
ENDCASE
ELSE
lcOrden=lcOrden+["]+ALLTRIM(.Controls[i].DisplayValue)+[",]
ENDIF
CASE lcClaseBase='image' AND !EMPTY(.Controls[i].lcCampo)
lcOrden=lcOrden+LOWER(.Controls[i].lcCampo)+[="]+ALLTRIM(.Controls[i].Picture)+[",]
ENDCASE
ENDFOR
lcOrden=STUFF(lcOrden,LEN(lcOrden),1,[ ])+[WHERE ]+ALLTRIM(this.lcPriKey)+[=]+ALLTRIM(STR(this.lnPriKey))
oComDB.ModRegistro(lcOrden,1)
ENDIF
DO WHILE ( lnGlobales > 0 )
lcAux = 'RELEASE gGlobal'+ALLTRIM(STR(lnGlobales))
&lcAux
lnGlobales = lnGlobales - 1
ENDDO
ENDWITH
this.llApend=.F.