Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any suggestions on this?

Status
Not open for further replies.

admdev

Programmer
May 17, 2006
56
US
Hi all,

I am working on a design which has two forms. One of the forms has a pageframe with three pages. Each of the pages has a button which calls the other form. Each of the pages represents a detail record. And the calling form from the pages will represent a detail record for each page. So the form will be called many times per page. In other words, I will have one header record with three main detail records and many detail records per main detail record.

My question is when should I save the entire record for the first time; in other words, when no header, no main detail, and no details of the main detail exist, when closing the calling form from the pages or from the main page? Perhaps from the main page present a message to the user. Something like "This is a new record. It is recommended to save your work before proceeding".

Once the first header record is inserted, I will be just updating the main detail with its child details or inserting another main detail with its child details. Again, only up to three main details.

I am trying to get some input from more experienced programmers as this is only my second VFP application.

Hope this is clear enough!

Thanks in advance.
 
After working with many Government employees, who get up from their computer when the time to go home comes around. They do not care what they are doing or what file is open or when screen is open, they just leave the computer on and where they are at the time. (yes this happens in the Private sector also)

I save after every record transaction.

This way if file maintenance is required at night and I have to disconnect the system (Ab)user that left the program open, it would only lose the one record they were editing when they left work.

I know this shoots the concept of record transactions and buffering in the foot, but, system (Ab)users do not live in the Perfect Programming World.




David W. Grewe (Dave)
 
DWGrewe,

Thanks for your reply! So you are suggesting to save from the form being called by the buttons on the pageframe even if no header exists?

Thanks.
 
If I understand your questions correctly, Each PAge of the page frame is a different child table to the main table.

So Yes I would save every time the user adds a record or moves from page to page.


David W. Grewe (Dave)
 
In other words, I will have one header record with three main detail records and many detail records per main detail record.

If I understand this correctly: simple example; company Acme, has 3 locations, each location has its own detail. When acme is chosen, the page frame fills the 3 pages with each location; each location then calls a form to display its details… Am I correct so far?

The way I would do this, would be to have 3 buttons, Add, Edit and Cancel. Add & Edit would change to “Save” when clicked. That’s when I would do the save for ALL records Added or Edited. This gives the user the opportunity to Cancel if they have made a mistake or are just fooling around. The Cancel button only comes on (enabled) when the Add / Edit button are in Save mode and when clicked it does a Tablerevert() for all tables involved.

This scenario, may sound complicated but is pretty easy to implement.

The problem with saving a record every time the user moves from page to page is, what do you do if the user has made an honest mistake? Delete the record? You will be surprised how fast deleted records add up.
 
Thanks for your replies!

Imaginecorp-
==========================================================
If I understand this correctly: simple example; company Acme, has 3 locations, each location has its own detail. When acme is chosen, the page frame fills the 3 pages with each location; each location then calls a form to display its details… Am I correct so far?
==========================================================

Yes, you are correct.
Pretend the company has three locations, each tab represents each location. Now I have to receive a shipment, which is supposed to be split into the three locations. The receiving number will be the same for all three locations; however, each location has its own detail record. Each detail record, obviously will have many items as many boxes will be received at each location. So my dilemma is when performing the first receiving at, say location A. Since no receiving number has been created, where should I be creating it? Save it from the form where I am entering the box detail or the main form. I want to do it right after the first box is scanned. Again, this is only when creating the receiving record for the first time. Once the receiving number has been created, I will be saving each box detail as the box is scanned per location.

The purpose of the application is not for receivings; however, the concept is exactly the same.

Thanks for your suggestions.

Ps. How do you create the "Quote:" here in the forum?
 
Ps. How do you create the "Quote:" here in the forum?

You use square-bracketed markup tags. Click the "Process TGML" link next at the bottom of the message reply box.

pamela
 
Issue I see is accidental entries and orphans. You're going to have a header/parent record and a group of chilren. You probably don't want a header/parent that doesn't have any child records and you certainly don't want any child records without a parent.

I haven't used the begin transaction end transaction function but that sounds like the concept you might need.

The problem with these things is that you have to code for goofups. What happens if somebody goes in and starts and then decides to quit and start over on another day, or the power goes off? Is it better to have a piece of the transaction or only the whole transaction?

Bill Couture
http:\\
 
We do exactly this scenario, though unfortunately much more complicated than what you need to do. We have clients that have multiple locations, but purchasing and receiving are done from one location. Only 2 tables are involved. A Parent table that contains general information and a child which contains the detail. In the child table each location is identified by its own location number and holds the Parent unique record number.
You can create unique record numbers by Substr(sys(2015),3,10) which will produce a unique 8 character number (should be done in the tables as the default value of a field) This will never be duplicated as long as there is a single server involved.
Now lets do this with your scenario;
Set all tables to Buffering = 5
Insert the “receiving” number in the “header record” (parent table) via the main form. After the insert into the parent table, scan the data and only do an insert into the detail table if there is data that needs to go into them. Insert the “receiving” number And the unique parent record identifier into them.
Do your updates etc.
No Saves until all updates are done.
Your main form should have an Add, Edit and Cancel buttons. Users start with the Add button and if he screws up cancel it. If the user needs to go for lunch, he saves then gets back in via the edit button.
I hope this will give you an idea on how to tackle your problem
Good luck
Here is a sample of an Edit button that changes into a Save
Code:
With Thisform
 If This.Caption = "\<Edit"
  .switch_on_off(.T.) &&& a method that enables all controls
  This.Enabled = .T.
  This.i_am_on = .T. &&& a property, which lets us know
                     ***that the form is in Edit mode
 Else
  Local mcheck
  mcheck = .doublecheck() &&& Key Field Validation method
  If !mcheck
    Return &&& If it fails, warn the user and dont save
  Endif
  .switch_on_off(.F.) &&& disable the controls 
  .formtables1.updatetables() &&& this is a class that
                          &&& Update all tables involved
   This.i_am_on = .F. &&& Form is out of Edit mode
  Endif
  .Refresh
Endwith
This.Caption = Iif(This.Caption = "\<Edit","\<Save","\<Edit")
This.ToolTipText = Iif(This.Caption = "\<Edit","Change this Record","Save These Changes")
 
Thanks guys for all the suggestions!

One thing though, I forgot to mention that I am using SQL 2005 as the backend.

Thanks.
 
DBF or SQL should make no difference. I work in a mixed environment and have a lot of forms that use both types of tables. I use standard dbf handling and ADO for the SQL. I'm told SQLSELECT is faster but got used to ADO.

Fox makes a great SQL front end!

Bill Couture
http:\\
 
Excuse my ignorance here...

I copied the Imaginecorp code into thje click event of a command button and got an error here...

Code:
  mcheck = .doublecheck() &&& Key Field Validation method

I presume that I have to write a piece of code called doublecheck()... If so where do I put it ?

JF

 
Sorry: should have explained better. The above code is specfic to our application:

Doublecheck is a metod in the form. All it does is checks the required fields to see if a correct entry has been made (Validation). a very simple example:
if empty(name)
=messagebox("Please enter the name...")
thisform.name.setfocus()
return .f.
endif

.switch_on_off(.T.): is another method in the form class. It loops thhrough all controls and disables them when the form starts. When Edit / Add are clicked it enables them.
Simple Example:
***Form.switch_on_of
lParameter pswitch
with thisform
.setall("enabled",pswitch,"Reg_textbox")
........
........
Endwith

i_am_on: is a property of the button class, default is .F., and when in edit/add mode it is switched on/off. Apart from other things, a Cancel button is enabled/disabled based upon this. The cancel button reverts any changes made, after asking the user. It loops through the tables using the Formtables class.

formtables1.: This is a complicated "conflict" catcher class, again in the form class, that resolves multi user conflicts and saves tables updates, Only if changes have been made.

All of the above is pretty simple to implement... But involves a lot of thought

 
Thanks for that, IC... Thats the trouble with dang learners like myself.

"There will always be more fools than wisemen because there are more questions than answers"

I now have the drift.

JF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top