
I am working on a project about making reservations. I have a reservation table that holds the enum field Status. And reservation lines table that holds the NoYes - Paid field.
The task is I have to iterate through all lines in res lines table and see if the NoYes Paid field is yes. If this field is yes on all lines in a given reservation, the field Status in res table has to change its status to Paid.
Any suggestions how should I implement this?
This is the code I tried, but nothing changes
public void modifiedField(FieldId _fieldId)
{
axmResLines_SJ reslines;
super(_fieldId);
switch (_fieldId)
{
case fieldNum(axmReservation_SJ, ReservationStatus):
while select* from reslines
where reslines.ReservationId == this.ResId
{
if (reslines.Paid == NoYes::Yes)
{
this.ReservationStatus = AXMReservationStatus_SJ::Paid;
}
}
break;
}
}
Using a while select loop is unncessary and it's bad for performance. Also, your code wouldn't even work correctly - it sets Status to Paid if any of the lines is Paid, not if all are paid.
What you really want to do is checking if there isn't any line with Paid == No:
select firstOnly RecId from unpaidResLine
where unpaidResLine.ReservationId == this.ResId
&& !unpaidResLine.Paid;
if (!unpaidResLine.RecId)
{
this.ReservationStatus = AXMReservationStatus_SJ::Paid;
}