I have a submit button that is dumping a selection of tag values from our SQDCME screen based on selections made by our coordinators. the problem we are having is…if a coordinator puts in his information for his department and then forgets he entered it for the day, he goes and enters it again, which causes 2 rows of data to exist within the table in the database. So when we go to run a report from that data, both those rows are being calculated in with the daily numbers we are looking for. Is there a way to write the query so that it looks to see if there already is a row for that day and department and overwrites the information there if the coordinator double enters it? Here is the script for what the sumbit button currently does:
if system.gui.confirm(“Have you selected and entered all the appropriate information?”, “Are you sure?”, 0):
AreaSelected = event.source.parent.getComponent(‘AreaSelected’).text
ShiftSelected = event.source.parent.getComponent(‘ShiftSelected’).text
Stextfield = event.source.parent.getComponent(‘Stextfield’).text
Qtextfield = event.source.parent.getComponent(‘Qtextfield’).text
Dtextfield = event.source.parent.getComponent(‘Dtextfield’).text
Ctextfield = event.source.parent.getComponent(‘Ctextfield’).text
Mtextfield = event.source.parent.getComponent(‘Mtextfield’).text
Etextfield = event.source.parent.getComponent(‘Etextfield’).text
ProductionDate = event.source.parent.getComponent(‘ProductionDate’).text
Loggedin = event.source.parent.getComponent(‘LoginLabel’).text
query = "INSERT INTO SQDCME.dbo.SQDCME (t_stamp, Shift, Area, Safety, Quality, Delivery, Cost, Moral, Environment, Coordinator) VALUES (?,?,?,?,?,?,?,?,?,?)"
args = [ProductionDate, ShiftSelected, AreaSelected, Stextfield, Qtextfield, Dtextfield, Ctextfield, Mtextfield, Etextfield, Loggedin]
system.db.runPrepUpdate(query,args)
else:
system.gui.messageBox(“User canceled the update.”, “Update Canceled”)
tags = ["[Client]SQDCME/Stacker_1", “[Client]SQDCME/Stacker_2”, “[Client]SQDCME/GreenLine”, “[Client]SQDCME/BlueLine”, “[Client]SQDCME/RoughMill”, “[Client]SQDCME/Janitorial”, “[Client]SQDCME/LumberDrying”, “[Client]SQDCME/ForkLifts”, “[Client]SQDCME/Maintenance”, “[Client]SQDCME/PX”, “[Client]SQDCME/Finish”, “[Client]SQDCME/Boilers”, “[Client]SQDCME/Autodefecting”, “[Client]SQDCME/Offline”, “[Client]SQDCME/Training”, “[Client]SQDCME/AreaSelected”, “[Client]SQDCME/ShiftSelected”, “[Client]SQDCME/Shift_1”, “[Client]SQDCME/Shift_2”, “[Client]SQDCME/Shift_3”]
values = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
system.tag.writeAll(tags,values)
event.source.parent.getComponent(‘Stextfield’).intValue = 0
event.source.parent.getComponent(‘Qtextfield’).intValue = 0
event.source.parent.getComponent(‘Dtextfield’).intValue = 0
event.source.parent.getComponent(‘Ctextfield’).intValue = 0
event.source.parent.getComponent(‘Mtextfield’).intValue = 0
event.source.parent.getComponent(‘Etextfield’).intValue = 0
event.source.parent.getComponent(‘Dtextfield’).visible = 1
event.source.parent.getComponent(‘Container’).getComponent(‘Dtank’).visible = 1
event.source.parent.getComponent(‘Dgoaltextfield’).visible = 1