Welcome! Log In Create A New Profile

Advanced

[WD21]TableAddLine

Posted by Ericus 
Ericus
[WD21]TableAddLine
July 30, 2018 11:38PM
Good day

When entering data into a table control what do you guys do to create a new line for every entry?

Do you just use TableAddLine on the Exit event of the last column?

What if the user tabs on the last column, it creates a new line but now he goes up to edit something in a previous line. Now Exit's the last column again and now another blank new line is created.

Is there a simple solution to all of this?

Thanks in advance.


Ericus Steyn
GuenterP
Re: [WD21]TableAddLine
July 31, 2018 07:04AM
Hi, with us here, there are two approches. (Warning: we're "procedural" guys!)

1- If new lines are to be added and the input has to be checked (range, duplicates etc.) before storing in the db, there is the method to switch off automatic saveing in the table control and do your own thing. Be warned, when switching that checkbox off, you will not be able to reach an empty new line without the code lines shown later ...

[attachment 2776 Table1.png]

Then, there is a lot of code (in one of the most simple windows I found for you) ...

First the entry into a row - you have to take care whether you're entering an empty row (=> Creation) or a row showing an existing record (=> Modif)
[attachment 2777 Table2.png]

Next, we let the user do whatever s/he wants, we are just waiting for him/her to leave the row .... now the great check of all of the values of the row will start ...

IF RowMode = "Modif" THEN
	// Validity
	IF Table.BGR_NUM < 1 OR Table.BGR_NUM > 999 THEN
		Error("Die Backzettel-Gruppen-Nummer muß im Bereich von 1 bis 999 liegen !")
		Table.BGR_NUM = OLD_BGR_NUM
		ReturnToCapture(Table.BGR_NUM)
	END
	IF NoSpace(Table.BGR_BEZ) = "" THEN
		Error("Es muß eine Bezeichnung der Backzettel-Gruppe eingetragen werden !")
		Table.BGR_BEZ = OLD_BGR_BEZ
		ReturnToCapture(Table.BGR_BEZ)
	END
	IF OLD_BGR_NUM <> Table.BGR_NUM THEN
		// check for dups
		MyPosition = HSavePosition(BACKZETTELGRUPPE)
		HReadSeekFirst(BACKZETTELGRUPPE,BGR_NUM,Table.BGR_NUM)
		IF HFound(BACKZETTELGRUPPE) AND Table.BGR_NUM = BACKZETTELGRUPPE.BGR_NUM THEN
			Error("ÄNDERUNG: Die Backzettel-Gruppe "+BACKZETTELGRUPPE.BGR_NUMBEZ+" war schon vergeben !")
			Table.BGR_NUM = OLD_BGR_NUM
			IF MyPosition > 0 THEN HRestorePosition(MyPosition)
			ReturnToCapture(Table.BGR_NUM)
		END
		IF MyPosition > 0 THEN HRestorePosition(MyPosition)
	ELSE
		// Re-Positionieren
		HReadSeekFirst(BACKZETTELGRUPPE,BGR_NUM,Table.BGR_NUM)
	END
	BACKZETTELGRUPPE.BGR_NUM = Table.BGR_NUM
	BACKZETTELGRUPPE.BGR_BEZ = Table.BGR_BEZ
	HModify(BACKZETTELGRUPPE)
	TableDisplay(Table,taCurrentSelection)
ELSE
	// RowMode = "Creation"
	IF not KeyPressed(kpEscape) THEN
		IF Table.BGR_NUM <> 0 OR NoSpace(Table.BGR_BEZ) <> "" THEN
			IF KeyPressed(kpEscape) THEN
				// ESC-taste
				Table.BGR_NUM = 0
				Table.BGR_BEZ = ""
				TableSelectMinus(Table)
				ReturnToCapture(GoToTable)
			END
			
			IF Table.BGR_NUM < 1 OR Table.BGR_NUM > 999 THEN
				Error("Die Backzettel-Gruppen-Nummer muß im Bereich von 1 bis 999 liegen !")
				Table.BGR_NUM = 0
				ReturnToCapture(Table.BGR_NUM)
			END
			IF NoSpace(Table.BGR_BEZ) = "" THEN
				Error("Es muße eine Bezeichnung der Backzettel-Gruppe eingetragen werden !")
				Table.BGR_BEZ = ""
				ReturnToCapture(Table.BGR_BEZ)
			END
			MyPosition = HSavePosition(BACKZETTELGRUPPE)
			HReadSeekFirst(BACKZETTELGRUPPE,BGR_NUM,Table.BGR_NUM)
			
			IF HFound(BACKZETTELGRUPPE) AND Table.BGR_NUM = BACKZETTELGRUPPE.BGR_NUM THEN
				Error("NEU-EINGABE: Die Backzettel-Gruppe "+BACKZETTELGRUPPE.BGR_NUMBEZ+" war schon angelegt !")
				Table.BGR_NUM = 0
				IF MyPosition > 0 THEN HRestorePosition(MyPosition)
				ReturnToCapture(Table.BGR_NUM)
			ELSE
				IF MyPosition > 0 THEN HRestorePosition(MyPosition)
				BACKZETTELGRUPPE.BGR_NUM = Table.BGR_NUM
				BACKZETTELGRUPPE.BGR_BEZ = Table.BGR_BEZ
				HAdd(BACKZETTELGRUPPE)
				TableDisplay(Table,taInit)
				TableSelectPlus(Table,TableCount(Table)+1)
				ReturnToCapture(Table.BGR_NUM)
			END
		END
	ELSE
		// ESC gedrückt!
		Table.BGR_NUM = 0
		Table.BGR_BEZ = ""
		TableSelectMinus(Table)
		ReturnToCapture(GoToTable)
	END
END

The window look like that:

[attachment 2778 Table3.png]

The code behind the button [ <= Tabelle ] looks like that

IF Table..State = Active THEN 
	Table = TableCount(Table)+1
	ReturnToCapture(Table.BGR_NUM)
END

2. - The second method is the much simpler one. We specify that no new data records may be entered. Modification of existing records, no new ones. The sensitive parts are being hid (= made read-only) from the end-user, some other fields of the record can be input. Since R/O colums are different in color (here, it is a painful pink) end users can easily see those fields which can be modified.



Edited 2 time(s). Last edit at 07/31/2018 07:12AM by GuenterP.
Attachments:
open | download - Table1.png (24.3 KB)
open | download - Table2.png (13.3 KB)
open | download - Table3.png (43.3 KB)
Ericus
Re: [WD21]TableAddLine
July 31, 2018 10:17AM
Thanks very much Guenter

I do something similar but I do all my checking and changes as the user progress through the row.

But the table..state is a good way to get what I want.

Regards


Ericus
wduser
Re: [WD21]TableAddLine
August 01, 2018 10:43PM
Hi

Simples way is not to use inline editing. ( editing in the table you are using to store the data as well.
Place a line above the table. Do you adding and modifying in that line. You can make it quite sophisticated . Maybe allowing inserting lines etc.

It results in a table with data and a line to edit the data.


If you want everything in one table. I want that . I use a memory table. While editing nothing is saved. you can add delete change lines . If you are done hit the save button and everything is saved.


How to do this . I am not going to give you a ton of code to show . I'll give you the concept.


When loading up the data is added to the table and every line has and ID as in the db. Adding new lines with table add line() these do not have an ID. This makes it you can destingwise between rows that do exist and rows that need be added. For editing the same applies .

This works great and allows for going back to the state where you began etc. But you can choose a whole other way Have done so myself es well. And that is save everything directly. And delete when removing.


As I said it is not standard . If it is a quick app and no one wants it . You can do the way easier way with an edit line .


This is is indeed the strength of Windev . It can be standard and easy and you can make your own sophisticated thing as well.

R
Ericus: [WD21]TableAddLine
September 09, 2018 09:24AM
Autor: Ericus

Link zum Beitrag: [27130.foren.mysnip.de]

Thanks very much for this tip.

I am going to give this a bash as well. Much easier to have all the
check and population of drop-downs done in that one line than to manage
every line of the table.

Regards



Ericus Steyn
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: