Quantcast
Channel: SCN : Discussion List - PowerBuilder Developer Center
Viewing all articles
Browse latest Browse all 2881

Trigger Changed Event on Datawindow

$
0
0

Greetings All,

 

I have a window with a datawindow that presents a grid to a user.  When they enter a base rate, it triggers the change event  which does a lot of calculations and does setitem on a bunch of other columns as shown here:

 

BASE   GRATUITY    DISCOUNT   TAX   TOTAL

100       20                  10                  6        116

50         10                  5                    3        58

ETC...

 

So the value of gratuity, discount, tax and total comes from the user entering or changing the base rate.  The value of gratuity percent, discount percent and tax percent are handled in a different window and stored in a different table.

 

And here is the problem.  The user might create a few hundred rates.  And a week later the tax rate changes in their state and instead of the tax being 6% it is now 7%.  So I need to pull all of the rates in either a hidden window or a datastore effect the original calculations on every single row using the new tax percent (or new gratuity percent or new discount percent) and have all of the values recalculated and saved to the database.

 

Just as a note, if I made the user redo the calculations it would not work because they can only enter the base rate and in this case it is not changing so the changed event would never fire.

 

So I am looking for a way to pull up all of these rows in a window/datawindow and fire the changed event so that every row is automatically recalculated using the same value for base rate and the current values for gratuity, discount and tax.

 

Can someone kindly suggest how best to do this?  BELOW IS THE CODE IN THE CURRENT ITEMCHANGED EVENT...

 

Thank you!!

 

Paul

 

CODE IN ITEM CHANGED EVENT

 

rates_have_changed = true //throw the flag to indicate that at least one rate has changed.

decimal i_base
decimal i_discount
decimal i_gratuity
decimal i_tolls
decimal i_parking
decimal i_stc
decimal i_fuel
decimal i_emln
decimal i_meet_greet
decimal i_holiday
decimal i_airport_pu_fee
decimal i_airport_do_fee
decimal compute_total_to_airport
decimal compute_total_from_airport
decimal compute_tax_to_airport
decimal compute_tax_from_airport

decimal nowNull

setnull(nowNull)

dw_1.accepttext()

 

i_base = dw_1.getitemnumber(row,"ft_affiliate_rate_staged_ar_base_rate")

 

if abs(i_base) = 0 or isNull(i_base) then

dw_1.setitem(row, "ft_affiliate_rate_staged_ar_base_rate", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_tolls", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_gratuity", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_parking", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_STC", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_fuel", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_emln", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_meet_greet", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_holiday", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_discount", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_airportfeepu", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_airportfeedo", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_tax_to_airport", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_tax_from_airport", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_total_to_airport", nowNull)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_total_from_airport", nowNull)

RETURN  //CHANGED FROM GOTO DONE FOR APPEON

end if

 

i_tolls = dw_1.getitemnumber(row,"ft_affiliate_rate_staged_ar_tolls")


if isnull(i_tolls) then
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_tolls", 0.00)
end if
i_gratuity = i_base * default_gratuity_percent
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_gratuity", i_gratuity)
i_parking = default_parking_amount
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_parking", i_parking)
i_stc = i_base * default_stc_percent
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_STC", i_stc)
if default_fuel_amount_percent_flag = "P" then
i_fuel = i_base * default_fuel_percent
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_fuel", i_fuel)
end if
if default_fuel_amount_percent_flag = "A" then
i_fuel = default_fuel_amount
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_fuel", i_fuel)
end if

i_emln = default_emln_amount
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_emln", i_emln)
i_meet_greet = default_meet_greet_amount
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_meet_greet", i_meet_greet)
i_holiday = default_holiday_amount
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_holiday", i_holiday)
i_discount = i_base * default_discount_percent
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_discount", i_discount)
i_airport_pu_fee = default_airport_fee_pu_amount
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_airportfeepu", i_airport_pu_fee)
i_airport_do_fee = default_airport_fee_do_amount
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_airportfeedo", i_airport_do_fee)

compute_tax_to_airport =  round(uf_calc_tax_to_airport(i_base, i_gratuity, i_tolls, i_fuel, i_stc, i_emln, i_holiday, i_airport_do_fee, i_discount),2)
compute_tax_from_airport = round(uf_calc_tax_from_airport(i_base, i_gratuity, i_parking, i_tolls, i_fuel, i_stc, i_emln, i_meet_greet, i_holiday, i_airport_pu_fee, i_discount),2)


dw_1.setitem(row, "ft_affiliate_rate_staged_ar_tax_to_airport", compute_tax_to_airport)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_tax_from_airport", compute_tax_from_airport)

 

compute_total_to_airport = uf_calc_total_to_airport(i_base, i_gratuity, i_parking, i_tolls, i_fuel, i_stc, i_emln, i_meet_greet, i_holiday, i_airport_pu_fee, i_discount, compute_tax_from_airport) //both functions use same arguments -- parking & meet_greet zeroed in function
compute_total_from_airport = uf_calc_total_from_airport(i_base, i_gratuity, i_parking, i_tolls, i_fuel, i_stc, i_emln, i_meet_greet, i_holiday, i_airport_pu_fee, i_discount, compute_tax_from_airport) //both functions use same arguments

dw_1.setitem(row, "ft_affiliate_rate_staged_ar_total_to_airport", compute_total_to_airport)
dw_1.setitem(row, "ft_affiliate_rate_staged_ar_total_from_airport", compute_total_from_airport)

dw_1.setitem(row, "ft_affiliate_rate_staged_ar_rate_type", train_flight_address) //In City to City this is just 'P' for Point to Point rate

dw_1.setitem(row, "ft_affiliate_rate_staged_user_id", rate_userid)


Viewing all articles
Browse latest Browse all 2881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>