PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Change record number in database
Change record number in database
Iniciado por guest, 27,ago. 2015 18:42 - 10 respuestas
Publicado el 27,agosto 2015 - 18:42
Hello,

Is it possible to change the record numbers in a database file? It is a table with invoice lines and i need a function to change the order of lines. It is a table with direct acces.

Thanks!
Publicado el 27,agosto 2015 - 19:38
Hi Sammy

What are your record numbers? Automatic IDs? Something else?
When you are saying "it is a table...", are you talking about a file, or about a table control in a window?

Best regards
Publicado el 28,agosto 2015 - 10:36
Fabrice,

First thanks for your reply!
It is a data file with automatic rec numbers.
Publicado el 28,agosto 2015 - 11:52
Hi Sammy

I see

First I have to say that I would NOT use automatic identifier as line numbers for invoices, but I would have lines values set independant for each invoice.

Now, if you really want to change automatic IDs, you can by doing a hmodify on the record with the hforceautoID parameter .or hfixautoID, I can't remember which one to use in your case. So just lok for details in the help.

Best regards
Publicado el 28,agosto 2015 - 13:38
It is a temp file that i use. What is then the best way to move the order of the lines?
Miembro registrado
68 mensajes
Publicado el 28,agosto 2015 - 13:40
Usually an invoice line item record will have the Id of the parent invoice, and a auto-incremented id for the line itself,
You can use modify(file, hForceIdAuto) to alter auto-numbered Ids.
This is not recommended especially if the line item id is referenced by any other record.

if the order of the lines on the invoice is important then you should have a sequence number field to manage that.
Make it a part of a multi-part key InvoiceId-Sequence
Then you can renumber the sequences as much as you like without destroying your data.

HTH,
Chris

--
Sometimes waiting is the best way forward...
Publicado el 28,agosto 2015 - 14:08
Hi Sammy,

for the orderlines i use an own field which holds an index: If you add the first orderline it gets value 1, second orderline gets value 2 and so on.
If an orderline has to move up or down (i have two buttons for the reordering) then i switch the values.
But i don't use a table with direct access, i use a query and the orderlines are sorted by the index-field.

Greetings
Markus
Publicado el 28,agosto 2015 - 14:53
Hi again

personnaly, for all sort orders, I use a high precision numeric..

This allows me to add after or before a line by calculating the median value between the two lines (by example, adding a line between value 2 and 3 is line 2.5)

Mowing a line up can be done by switching values, of course but also by simply chaning one line value to an intermediate one. By example, if we have line 1 2 3 and 4 and want to move line 4 up 2 line, I just change sort order 4 by sort order 1.5...

Best regards
Publicado el 28,agosto 2015 - 15:02
I also use a process similar to what Markus mentioned. I just have a field on OrderLine called "Sequence" so that when you bring back the order lines (usually via a query), just ORDER BY Sequence :spos: ...and when you move the line up/down, you do as Markus says and swap the sequence number.
Publicado el 28,agosto 2015 - 15:16
Sammy

If it is a temp file then just load the contents to a memory table control recording the current desired positions in an int column ("Sequence") as Markus K advised, add some controls (buttons) to move the lines in the memory table similar to:

iTotCnt is int = MemTable..Occurrence
iCurPos is int = TableSelect(MemTable)
IF iTotCnt > 1 _AND_ iCurPos <> 1 THEN
MemTable.colSequence[iCurPos] = iCurPos-1
MemTable.colSequence[iCurPos-1] = iCurPos
END
TableSort(MemTable,"colSequence")
ChkPosition() // Procedure to disable button controls depending upon position in MemTable

When the user is done/save just delete the temp file and do a HAdd to the temp file again

I'm sure there are a number of ways to solve this and every problem this is just one that came to mind.

Eric W
Publicado el 28,agosto 2015 - 16:24
Sammy
Depends whether you need a permanent or temporary change to the order.

If permanent then does as already suggested with a sequence number in your file.

If temporary load your query result into an array and bind your table to this array.
You can then move the rows about using the 'ArrayMoveLine' function with buttons or DragnDrop foloowed by TableDisplay()