I have an app where the user is being asked to enter timesheet data into a browse. He first enters the name of the employee, then the start and end times. In this app, time is applied to a particular consumer, each of whom has differing billing based on a number of factors. So when a record is newly entered or changed, it is modified by these parameters.
I couldn't do this in the dbf field rules proper, so I first placed the lookup in the OnSave of the field rules. This didn't seem to work too well, so I later changed it to the browse OnSave event. The other parameter I was asked to incorporate was a lookup for a pre-existing time and date for that particular Consumer. This was needed to ensure that no two employees were putting down time for the same consumer.
I put this all into one script detailed below. Seems to be working, however I am having problems with the Cancel event. If a duplicate entry is found, then a dialog box pops up and asks the user if this is ok. If it is, all is well, but if not entry should be cancelled and the input line wiped out. That is not happening.
Any ideas or solutions to improve what I have would be most appreciated.
I couldn't do this in the dbf field rules proper, so I first placed the lookup in the OnSave of the field rules. This didn't seem to work too well, so I later changed it to the browse OnSave event. The other parameter I was asked to incorporate was a lookup for a pre-existing time and date for that particular Consumer. This was needed to ensure that no two employees were putting down time for the same consumer.
I put this all into one script detailed below. Seems to be working, however I am having problems with the Cancel event. If a duplicate entry is found, then a dialog box pops up and asks the user if this is ok. If it is, all is well, but if not entry should be cancelled and the input line wiped out. That is not happening.
Any ideas or solutions to improve what I have would be most appreciated.
Code:
'Date Created: 09-Feb-2014 02:25:21 PM 'Last Updated: 09-Feb-2014 03:01:44 PM 'Created By : Charles Hoens 'Updated By : Charles Hoens s=table.get("timehours") 'debug(1) dim wac as l=.F. dim cons as c=alltrim(s.consumer) dim dons as d=s.edate wac=exist(cons+dons,"timehours","lmain") if wac = .T. 'Displays a message box (style:'OK, Cancel Buttons', image: 'Attention symbol', id: 'msg1'). DIM SHARED msg1_result as N DIM SHARED msg1_OK_Button as L DIM SHARED msg1_CANCEL_Button as L msg1_OK_Button = .F. msg1_CANCEL_Button = .F. title_var = "Possible Duplicate Entry" message_text_var = <<%text% A possible duplicate entry for this Consumer on this date has been found. Do you want to continue with with this entry? If so, press OK. If not, press Cancel. %text% msg1_result=ui_msg_box(title_var,message_text_var,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_ATTENTION_SYMBOL) 'Test to see which button on the message box was pressed.... SELECT CASE msg1_result = UI_OK_SELECTED msg1_OK_Button= .t. goto NEXTT CASE msg1_result = UI_CANCEL_SELECTED msg1_CANCEL_Button= .t. 'Cancel changes to record in current form at Control_browse1 level. 'topparent:Control_browse1.cancel() cancel() end END SELECT end if NEXTT: 's=table.get("timehours") dim jac as c=s.consumer t=table.open("consumers") query.filter="lastfirst=var->jac" qry=t.query_create() if s.service="Behavior Support" s.change_begin() if t.behaviorist<>0 s.serviceamt=t.behaviorist end if s.waivercode=t.wcbs s.totamount=s.serviceamt*toseconds(s.tothours)/60/60 s.change_end() end if if s.service="Respite" s.change_begin() s.serviceamt=t.respite s.waivercode=t.wcres s.totamount=s.serviceamt*toseconds(s.tothours)/60/60 s.change_end() end if if s.service="Activity" s.change_begin() if t.activity<>0 s.serviceamt=t.activity end if s.waivercode=t.wcact s.totamount=s.serviceamt*toseconds(s.tothours)/60/60 s.change_end() end if if s.service="Day Program" s.change_begin() if t.dayprog<>0 s.serviceamt=t.dayprog end if s.waivercode=t.wcdp s.totamount=s.serviceamt*toseconds(s.tothours)/60/60 s.change_end() end if if s.service="Behaviorist" s.change_begin() s.serviceamt=t.behaviorist s.waivercode=t.wcbh s.totamount=s.serviceamt*toseconds(s.tothours)/60/60 s.change_end() end if if s.service="Mileage" s.change_begin() s.serviceamt=t.mileage s.waivercode=t.wcmile s.totamount=s.serviceamt*s.mileage s.change_end() end if
Comment