FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse new line for DBF ...
Posts: 437
Joined: Fri Oct 07, 2005 12:56 PM
xBrowse new line for DBF ...
Posted: Thu Oct 15, 2009 11:57 AM

Hi ,

I'm searching a solution , how to add a new blank line in the xBrowse , then fill this line with needful data and then validate ( for mandatory fields for sample ... ) and append a new record in DBF . Maybe you have a sample how to do something like that ? It seems that I can add a new record to dbf and then add something like ::lNew data and then must validate for a new record for adding fully . But this way don't meet for me , because if user refuse of this new record , then this record must be deleted , so this isn't a good . I'm thinking that in this place the best solution will be something like a la buffer . But I don't know how to do that with xBrowse and DBF . Maybe I can add buffer in DBF ?

With best regards !

Rimantas U.
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: xBrowse new line for DBF ...
Posted: Thu Oct 15, 2009 12:32 PM
Hi Rimintas,

Again a database object is going to be a good answer. It is automatically buffered.

However, it is difficult to do spreadsheet style editing with cell level validation and control. Also, how does one trigger the save? On a cell by cell basis or only when they are done with the entire record? And how is the implimented in the interface, i.e. how does the user know how it works?

For these reasons I rarely use in-browse editing. It is much easier to edit a record using a popup dialog when the record is double-clicked.

I am attaching a sample program that does cell by cell editing using a database object. Each cell's edit is saved by the user pressing the Return key (most users won't like this since it does not work like a standard spreadsheet). With some work you may be able to adapt it to your desires. I did not write the code, nor do I know who the author is.

James Bott

Code (fw): Select all Collapse
/*
Purpose: XBrowse example with spreadsheet style editing
Note   : Any alpha-numeric key triggers the edit, and up and down arrows exit the edit
         Tested with FWH 8.08

Update: If you use lFastEdit, then exiting with the Return key doesn't work anymore.
*/

#include "FiveWin.ch"
#include "XBrowse.ch"

function Main()

   local oWnd, oDbf, oBrw, oCol

   USE Customer
   DATABASE oDbf

   DEFINE WINDOW oWnd

   @ 0, 0 XBROWSE oBrw OF oWnd OBJECT oDbf

   oBrw:lFastEdit:=.t.  // any alpha-numeric key triggers the edit

   oCol = oBrw:AddCol()
   oCol:cHeader                = "First"
   oCol:bStrData               = { || oDbf:First }
   oBrw:aCols[ 1 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 1 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:First := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save()) ) }

   oCol = oBrw:AddCol()
   oCol:cHeader                = "Last"
   oCol:bStrData               = { || oDbf:Last }
   oBrw:aCols[ 2 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 2 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:Last := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save()) ) }

   oBrw:CreateFromCode()

   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 437
Joined: Fri Oct 07, 2005 12:56 PM
Re: xBrowse new line for DBF ...
Posted: Thu Oct 15, 2009 01:13 PM
James Bott wrote:Hi Rimintas,

Again a database object is going to be a good answer. It is automatically buffered.

However, it is difficult to do spreadsheet style editing with cell level validation and control. Also, how does one trigger the save? On a cell by cell basis or only when they are done with the entire record? And how is the implimented in the interface, i.e. how does the user know how it works?

For these reasons I rarely use in-browse editing. It is much easier to edit a record using a popup dialog when the record is double-clicked.

I am attaching a sample program that does cell by cell editing using a database object. Each cell's edit is saved by the user pressing the Return key (most users won't like this since it does not work like a standard spreadsheet). With some work you may be able to adapt it to your desires. I did not write the code, nor do I know who the author is.

James Bott

Code (fw): Select all Collapse
/*
  
Purpose: XBrowse example with spreadsheet style editing
Note   : Any alpha-numeric key triggers the edit, and up and down arrows exit the edit
         Tested with FWH 8.08

Update: If you use lFastEdit, then exiting with the Return key doesn't work anymore.
*/

#include "FiveWin.ch"
#include "XBrowse.ch"

function Main()

   local oWnd, oDbf, oBrw, oCol

   USE Customer
   DATABASE oDbf

   DEFINE WINDOW oWnd

   @ 0, 0 XBROWSE oBrw OF oWnd OBJECT oDbf

   oBrw:lFastEdit:=.t.  // any alpha-numeric key triggers the edit

   oCol = oBrw:AddCol()
   oCol:cHeader                = "First"
   oCol:bStrData               = { || oDbf:First }
   oBrw:aCols[ 1 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 1 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:First := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save()) ) }

   oCol = oBrw:AddCol()
   oCol:cHeader                = "Last"
   oCol:bStrData               = { || oDbf:Last }
   oBrw:aCols[ 2 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 2 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:Last := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save()) ) }

   oBrw:CreateFromCode()

   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil


Hi James ,

Thanks for the answer . I was working with an old Hernan TwBrowse . At this time I begin a new project and want to do all with xBrowse . With Hernan's browse I was using dialogs for a new records input . But that isn't comfortable . xBrowse is very poverfull thing and , in mine opinion , better avoid such solutions like dialog for inputs .
It's very easy to do validation for a new record - lets say that xBrowse class extends with some features - lNewRecord - logical ( or bMarkNew for sample ) and bValidNewRecord - codeblock . So adding a new record we can mark that with lNewRecord and let to stay here until to press button "Save" or keystroke "Ctr-S" and then validate - it's OK with a new record or not ? That isn't dicifult to do . In mine opinion all management can be done with xBrowse ...
I reviewed TDatabase class . It seems that this is a solution . Here is aBuffer and I can manage that . It seems that leaves to solve problem , how to fill related data for others alias in xBrowse ...

Regards !
Rimantas U.
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: xBrowse new line for DBF ...
Posted: Thu Oct 15, 2009 04:24 PM
Rimintas,

It's very easy to do validation for a new record - lets say that xBrowse class extends with some features - lNewRecord - logical ( or bMarkNew for sample ) and bValidNewRecord - codeblock . So adding a new record we can mark that with lNewRecord and let to stay here until to press button "Save" or keystroke "Ctr-S" and then validate - it's OK with a new record or not ? That isn't dicifult to do . In mine opinion all management can be done with xBrowse ...


You still have the design issues that I mentioned. Plus you have to add a new record to the DBF before you can edit it. Then if the user doesn't want it, then you have to delete it. This gets messy--you end up with a bunch of deleted records. Also it gets very complex validating and each cell--you can't use bounded controls like radios etc.

I'm not saying it is not possible, it is just not easy to implement and I have not found a compelling reason to do so.

I think you can do what you want with lNewRecord and bValidateNewRecord by putting them in a subclass of TDatabase. You can add a new Save() method something like:

Code (fw): Select all Collapse
Method Save() Class MyData
    if ::lNewRecord
        if eval( ::bValidateNewRecord )
              super:save()
        endif
    endif
Return nil


Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 437
Joined: Fri Oct 07, 2005 12:56 PM
Re: xBrowse new line for DBF ...
Posted: Fri Oct 16, 2009 04:57 AM
James Bott wrote:Rimintas,

You still have the design issues that I mentioned. Plus you have to add a new record to the DBF before you can edit it. Then if the user doesn't want it, then you have to delete it. This gets messy--you end up with a bunch of deleted records. Also it gets very complex validating and each cell--you can't use bounded controls like radios etc.

I'm not saying it is not possible, it is just not easy to implement and I have not found a compelling reason to do so.

I think you can do what you want with lNewRecord and bValidateNewRecord by putting them in a subclass of TDatabase. You can add a new Save() method something like:

Code (fw): Select all Collapse
Method Save() Class MyData
    if ::lNewRecord
        if eval( ::bValidateNewRecord )
              super:save()
        endif
    endif
Return nil


Regards,
James


James ,
I agree with you , with natural DBF it's complicated to do what I want . I mentioned that if user will refuse for new record , then it must be deleted and that is not a way . So I asked this question - maybe exist other solutions ? You directed me to a true way - now I'm trying TDatabase class and it seems that this will do the job ! :-) Alreday tried something and can to say , that extends aren't needful - with alreday existing codeblocks of column object we can do all . Simply in edits and postedit codeblock it's needful to direct it's buffer or not . So it's all right ! :-)

With best regards !
Rimantas U.

Continue the discussion