Two questions - saving values and logging user name

I tried using the search feature but it either doesn’t seem to work well at all, or I’m trying to do something that no one has asked. I feel like I’m missing something.

Question 1) I have a screen for changing the auto start up and auto shut down times for a machine. I’d like the user to change all the necessary fields and then hit a save button. After clicking that button, then and only then will the values from all those fields actually be written to the PLC. I don’t want one to be written, then the next, then the next, as they’re filling out the screen. I want them all written at the same time.

Question 2) When the user makes those changes, I want to log his/her username, along with all the values from the fields on the screen, to a table on the SQL server so we have a history of the changes made and who made them.

I’d love to hear your ideas.

The simplest way I’ve found to do this sort of pending save is to use a extra (custom) property for the actual tag binding (bidirectional) and a one-way binding on the editable field’s normal value property to that custom property. Then your edits stay in the form, but the form still populates from the PLC’s current values.

In the actionPerformed script on your save button, you iterate through the form’s components, assigning the current field value back to the custom property. As for the logging, I would turn on tag history for the values, and have just the operator/workstation identification inserted to a log table. (Again in the actionPerformed script.)

Some notes for this design pattern:
[ul][li]When open on multiple clients, changes saved by one user will show up in all of the other clients[/li]
[li]In a propertyChange event script for the editable property, you can check if the new value is different from the custom property. When different, it must be a human entry. Use this to enable the “Save” button, so it is obvious that changes have been made to the form.[/li]
[li]Bind the background color of the field to highlight it when the editable property differs from the custom property[/li][/ul]

I would look into this in the manual:


On the actionPerformed of the save button:

[code]start = event.source.parent.getComponent(‘Start’).text
stop = event.source.parent.getComponent(‘Stop’).text
changeby = system.tag.getTagValue("[System]Client/User/OSUsername")

if start == “”:
system.gui.messageBox(“Please enter in Start Time.”)
elif stop == “”:
system.gui.messageBox(“Please enter in Stop Time.”)

query = “UPDATE table Start=?,Stop=?,ChangeBy=?, ChangeDate=GETDATE() WHERE something = ?”
system.db.runPrepUpdate(query, [start, stop, changeby, something])