<% =SYS(3101,1256) olddate=SET("Date") oldmark=SET("Mark") ajaxresponse=CREATEOBJECT('empty') oJSON=NEWOBJECT('json','json.prg') thepassword=orequest.form('txtpassword') IF NOT ALLTRIM(thepassword)==ALLTRIM(onlinepassword) RETURN '{"terror":"Password not correct '+onlinepassword+'"}' endif SET DATe YMD SET MARK TO [-] SET CENTURY ON fref=ALLTRIM(TRANSFORM(NVL(orequest.form('txtreffid'),''))) *We should check for transid. If it exists, then we will update *If no record exists, or if empty fref we will insert *if fref is empty, we will insert, but we IF EMPTY(fref) select top 1 val(transid) as vref,* from (dbclocation+[payment.dbf]) order by vref desc into cursor savefile newref=ALLTRIM(TRANSFORM(vref+1)) theaction=[Insert] ELSE select val(transid) as vref, * from (dbclocation+[payment.dbf]) where allt(transid)==allt(fref) into cursor savefile newref=fref IF RECCOUNT()=0 theaction=[Insert] ELSE theaction=[Update] endif ENDIF backstring=[ &]+[& ] if theaction='Insert' fieldstring='insert into (dbclocation+[payment.dbf]) (transid, ' valstring=[(']+allt(transform(newref))+[', ] for i=1 to fcount() FLD=Lower(Field(I)) FLDVAL=Evaluate('&fld') formfld=[txt]+lower(field(i)) formfldval=orequest.form(formfld) if isnull(formfldval) or fld=[transid] loop endif fieldstring=fieldstring+fld+[,] do case case type([&fld])=[D] if empty(getwordnum(formfldval,1,[-])) valstring=valstring+[{}, ] else valstring=valstring+[date(]+getwordnum(formfldval,1,[-])+[,]+getwordnum(formfldval,2,[-])+[,]+getwordnum(formfldval,3,[-])+[), ] endif case type([&fld])=[N] if empty(val(transform(formfldval))) valstring=valstring+[0, ] else valstring=valstring+transform(formfldval)+[, ] endif case type([&fld])=[C] valstring=valstring+'['+allt(transform(formfldval))+'], ' other backstring=backstring+formfld+[: ]+type([&fld])+[, ] endcase endfor valstring=subst(valstring,1,len(valstring)-2)+[)] fieldstring=subst(fieldstring,1,len(fieldstring)-2)+[)] oresponse.write(fieldstring+' value '+valstring+backstring) thecommand=fieldstring+' value '+valstring+backstring else fieldstring='Update (dbclocation+[payment.dbf]) set ' for i=1 to fcount() FLD=Lower(Field(I)) FLDVAL=Evaluate('&fld') formfld=[txt]+lower(field(i)) formfldval=orequest.form(formfld) if isnull(formfldval) or fld=[transid] loop endif do case case type([&fld])=[D] if empty(getwordnum(formfldval,1,[-])) fieldstring=fieldstring+fld+[={}, ] else fieldstring=fieldstring+fld+[=date(]+getwordnum(formfldval,1,[-])+[,]+getwordnum(formfldval,2,[-])+[,]+getwordnum(formfldval,3,[-])+[), ] endif case type([&fld])=[N] if empty(val(transform(formfldval))) fieldstring=fieldstring+fld+[=0, ] else fieldstring=fieldstring+fld+[=]+transform(formfldval)+[, ] endif case type([&fld])=[C] fieldstring=fieldstring+fld+'=['+UPPER(allt(transform(formfldval)))+'], ' other backstring=backstring+formfld+[: ]+type([&fld])+[, ] endcase endfor fieldstring=subst(fieldstring,1,len(fieldstring)-2)+[ where allt(transid)==']+ALLTRIM(TRANSFORM(newref))+[' ] *oresponse.write(fieldstring+backstring) thecommand=fieldstring+backstring ENDIF terror=[] try &thecommand *oresponse.write([Success]) SELECT * FROM (dbclocation+[payment]) WHERE ALLTRIM(transid)==newref INTO CURSOR xfile thebackupdbf=DBF() IF NOT EMPTY(bk1loc) AND DIRECTORY(bk1loc,1) DELETE FROM (bk1loc+[payment]) WHERE ALLTRIM(transid)=newref INSERT INTO (bk1loc+[payment]) SELECT * FROM (thebackupdbf) ENDIF IF NOT EMPTY(bk2loc) AND DIRECTORY(bk2loc,1) DELETE FROM (bk2loc+[payment]) WHERE ALLTRIM(transid)=newref INSERT INTO (bk2loc+[payment]) SELECT * FROM (thebackupdbf) ENDIF CATCH terror='Error while saving' ENDTRY oResponse.ContentType = "text/plain" ojson.keyforcursors='xfile' freffs=oJSON.stringify('xfile') ADDPROPERTY(ajaxresponse,'terror',terror) oResponse.Write(oJSON.AddJSONProps(ojson.stringify(ajaxresponse),freffs)) oresponse.flush SET DATE &olddate SET MARK TO &oldmark CLOSE TABLES CLOSE DATABASES %>