Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
8
Erster Beitrag:
vor 8 Jahren, 1 Monat
Letzter Beitrag:
vor 8 Jahren, 1 Monat
Beteiligte Autoren:
DarrenF, Al, DerekT, Stefan Bentvelsen

[WD12] Processing data with a Header and Lines...

Startbeitrag von DarrenF am 04.07.2010 22:51

Hi guys,

I have a design/processing issue - I have a "standard" file structure of an Order header with Order Lines...

My dilema is how to process the Header and Lines?

I'm trying to handle it by entering the Header details and not write them immediately, then allow the user to add, modify and delete the order lines, again without writing them immediately. When the user presses a Save button I want to write the Header and then all the lines.

How or what is the best way to acheive this type of processing with WD... as I'm struggling trying to use a Table control on a window defined as "Memory" to handle the order lines...

I'm struggling in that the structure of how I want to display the details in my Table control don't (and can't) match the fields on my order lines file, so how would I use MemoryToFile or is there a different technique?

I hope you understand my descriptions - any suggestions welcome.

Thanks in advance as always...

Antworten:

Hello Darren

In most of those cases we take a simplistic approach and save the header record in a separate operation before creating the body lines because we use the header primary key as the foreign key in the child table. To do it all in one operation, the save routine can do a screentofile() for the header, pick up the key from the header file to use in the body records and then cycle through the body line memory table in a For loop and create new records as required in the order line files and assign values to the fields from the table.

To use the same screen for editing, include the order line primary key as a column in the table when you build it, and on save, seek records where you have an order line key value and create new records where you don't, because they will be new lines.

Regards
Al

von Al - am 05.07.2010 03:11
Hi Al,

Thanks...

If you create the header on the DB then move onto processing lines, what do you do if the user decides to cancel the operation? You must have to go back and delete them?

In the case of processing the header & lines all at once, I'm presuming from your description that when it comes to saving the lines, you move (in a for loop) each field from memory to the desired field individually?

Thanks again...

von DarrenF - am 05.07.2010 07:34
Hi Darren,

we save the orderhead and use the id as link in the orderline-records. In case of a user-cancel, we delete the lines and the header.


von Stefan Bentvelsen - am 05.07.2010 07:50
Hello Darren

You are correct on both counts.
There is a problem with deleting the order header record if the user cancels, but we get away with it because of the nature of that app. On the very rare occassions this happens, the user can delete the order header or because it has no body lines, they can re-assign it to another creditor.
The For loop through the table assigns the table cell data individually to the data file fields for each row as File.Field = Table.ColumnName

Regards
Al




von Al - am 05.07.2010 07:53
Thanks for the comments guys - it's much appreciated... some food for thought :cheers:

I've written most of the code to handle this as a memory table and all seems to work great except for the actual Add/Modify processing, so I think I'll stick with it and as I've already coded a For loop in my Save processing, I'll use Al's method of assigning the fields individually from the Table control - that should do the trick :spos:

Thanks again...

von DarrenF - am 05.07.2010 08:45
Darren
For this type of operation I always use simple arrays.
The first array for the header and a second array for the lines.
On completion of input I write the content of the header to get the relevant ID and the write the lines.

For the occasions where I am editing an existing record set I have and additional element in the array where I set a flag to indicate whether the line is new, modified or to be deleted.

The table display is always achieved by reading the values in array 2.
Another advantage, which I need in one of my prgs, is that I can re-order the display order of the lines table.

I guess it depends on exactly how you want to implement your process but this does avoid having to write uneeded records - especially important if you want to have sequential numbers (order\invoice) assigned to the header.

I also wrap the the write processes in a transaction so that I only have to monitor a single point of failure.

Regards

DerekT

von DerekT - am 05.07.2010 08:58
Derek,

Thanks for taking the time to respond...

Yes, I treat my memory table like an array, and for me I like the way I can use the functions TableADDLine and TableModifyLine to add and modify the table rows.

With my memory table I use the ID of each order line to indicate that it's a new or existing line, so; ID = 0 = New order line and ID 0 = Existing order line, but I see what you are saying - I could also flag if a line has been amended, thus avoiding unecessary modifications.

Thanks...



von DarrenF - am 05.07.2010 09:59
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.