Yes, you're right! Now it works!
Well ... As usually ( bad practice but.. ) I tried a series of things at a time that solved the basic problem. Here's what I identified:
1) The function that saves from the temp file to the table would be trying to lock after appending blank... and the record was already locked. Worst, I had no message there. So it failed anonymously.
2) That same function would fill the master key with the temptable's master key... which was empty.
3) So, by now I dropped the "Save-from-temp-to-dbf" function... Usually they'll be few fields, so, no gain.
4) Grid.Save works allright of course!! Saves all pending stuff to the underlying table. Nice.
Now I'm up and running. I know I'm a pain in the neck, but I'm not satisfied with the Grid's navigation... I want a "permanent" edit state and I'll need also validation in some fields.. So I need to see if all that is possible.
EDIT: ColumnValid seems to be good for validation! I'll research on it
But we're good!
Some piece of code..
Code: Select all
/* Save master detail*/
FUNCTION JournalSave()
LOCAL nOrder, nJournal
frmJournal.GridMaster.Save()
IF (cEditMode == 'New')
nJournal := VAL(DTOS(DATE()) + STRTRAN(TIME(),":",""))
gltr_mst->(DbAppend())
REPLACE gltr_mst->trans_no WITH nJournal
ELSE
IF .NOT. gltr_mst->(RLOCK())
msginfo("Error, registro no se puede bloquear.")
RETURN
ENDIF
ENDIF
REPLACE gltr_mst->period_mm WITH frmJournal.txtMM.Value,;
gltr_mst->period_yy WITH frmJournal.txtYYYY.Value,;
gltr_mst->trans_name WITH frmJournal.txtName.Value,;
gltr_mst->trans_date WITH frmJournal.dtpDate.Value
/* Temptable */
SET DELETED OFF
SELECT TempDetail
dbGoTop()
DO WHILE .NOT. EOF()
SELECT gltr_det
SEEK STR(gltr_mst->trans_no,14) + TempDetail->acc_nbr
IF FOUND()
/* record found in temp detail but deleted */
/* delete in final table */
IF gltr_det->(rlock())
IF TempDetail->(DELETED())
gltr_det->(dbDelete())
ELSE
REPLACE gltr_det->acc_nbr WITH TempDetail->acc_nbr
REPLACE gltr_det->line_amt WITH TempDetail->line_amt
REPLACE gltr_det->trans_no WITH gltr_mst->trans_no
ENDIF
ELSE
msginfo("Error, registro no se puede bloquear.")
ENDIF
gltr_det->(dbUnlock())
ELSE
gltr_det->(dbAppend())
/*save buffer to final*/
REPLACE gltr_det->acc_nbr WITH TempDetail->acc_nbr
REPLACE gltr_det->line_amt WITH TempDetail->line_amt
REPLACE gltr_det->trans_no WITH gltr_mst->trans_no
gltr_det->(dbUnlock())
ENDIF
SELECT TempDetail
dbSkip()
ENDDO
SET DELETED ON
gltr_mst->( DbCommit() )
gltr_det->( DbCommit() )
// msginfo("Record was edited with success.")
frmJournal.Release
RETURN