PDA

View Full Version : Refresh Active Link


ABC123

andymeer@yahoo.co.uk
03-03-2008, 02:05 AM
Hi All

I must say that V9 is yet another great step forward some great new features.

I have taken one of V8 apps and tried to recreate it in V9.

I exported dbf's to mysql,
reimported from mysql to active links with sql_ prefix,
copied my forms to new sql active links
amended a few scripts

all took just a couple of hours.

One small problem I have is:

How do I refresh a active link table within a script.

my script works fine but additions to the table do not get reflected in the form until I close the from and reopen it.

Andy
script below


DIM tbl AS P
DIM vImageFilename AS C
DIM vOld_Path AS C
DIM vPath AS C
DIM vFiles AS P
Dim Shared vExt as C
Dim prod as c

tbl = table.open("sql_webproducts2")

vOld_Path = dir_get()
vPath = UI_GET_PATH ("Enter Path","c: ", "c:\\")


If vPath = ""
End
End if

DIR_put(vPath)

vFiles = filefind.first(vExt,FILE_FIND_READONLY)


while .not. vFiles.eof()
vImageFilename =vFiles.name()
tbl.enter_begin()
myimage = rtrim(vImageFilename,vExt)
'myimage = file.filename_parse(vImageFilename,"N")
tbl.image_name = left(myimage,15)
tbl.Full_address = vpath+vImageFilename
tbl.Cd_number = CDno
'tbl.Picture = image_filename_encode(vpath+vImageFilename)
tbl.enter_end(.t.)

xbasic_wait_for_idle()

StatusBar.robot()
vFiles.next()
end while

DIR_put(vOld_Path)

tbl.close()
Parentform.resynch()

end

Selwyn Rabins
03-04-2008, 08:40 PM
Hi All

I must say that V9 is yet another great step forward some great new features.

I have taken one of V8 apps and tried to recreate it in V9.

I exported dbf's to mysql,
reimported from mysql to active links with sql_ prefix,
copied my forms to new sql active links
amended a few scripts

all took just a couple of hours.

One small problem I have is:

How do I refresh a active link table within a script.

my script works fine but additions to the table do not get reflected in the form until I close the from and reopen it.

Andy
script below


DIM tbl AS P
DIM vImageFilename AS C
DIM vOld_Path AS C
DIM vPath AS C
DIM vFiles AS P
Dim Shared vExt as C
Dim prod as c

tbl = table.open("sql_webproducts2")

vOld_Path = dir_get()
vPath = UI_GET_PATH ("Enter Path","c: ", "c:\\")


If vPath = ""
End
End if

DIR_put(vPath)

vFiles = filefind.first(vExt,FILE_FIND_READONLY)


while .not. vFiles.eof()
vImageFilename =vFiles.name()
tbl.enter_begin()
myimage = rtrim(vImageFilename,vExt)
'myimage = file.filename_parse(vImageFilename,"N")
tbl.image_name = left(myimage,15)
tbl.Full_address = vpath+vImageFilename
tbl.Cd_number = CDno
'tbl.Picture = image_filename_encode(vpath+vImageFilename)
tbl.enter_end(.t.)

xbasic_wait_for_idle()

StatusBar.robot()
vFiles.next()
end while

DIR_put(vOld_Path)

tbl.close()
Parentform.resynch()

end


you should never really have to refresh active links. the 'refresh active link' command on the menu is only meant to be used if you want to refresh the definition of the active link table should the schema of the backend table change, or should the connection string change (i.e. you have an active link table that came from mysql, but now it comes from oracle).

every time you open an active link table it gets the current data in the server.

Anis
03-07-2008, 10:47 AM
Selwyn;

The question still applies, how to reflect those additions in an open form without closing it?

I wish to see a new Form (Browse) propertiy that has an AUTOMATIC REFRESH TIMER.
Just set the timer and as long as the form is viewed and the data is being added to MySQL table it's refreshed in A5.

Raymond Lyons
03-07-2008, 01:18 PM
Selwyn;

The question still applies, how to reflect those additions in an open form without closing it?

I wish to see a new Form (Browse) propertiy that has an AUTOMATIC REFRESH TIMER.
Just set the timer and as long as the form is viewed and the data is being added to MySQL table it's refreshed in A5.

You can hit the good old F5 key to refresh whenever you wish.

Your suggestion of a timer would present a problem: Suppose you are in the process of editing a record (have not saved anything but have changed possibly a bunch of fields). While you were doing that, someone else made a change to the same record in the backend database and your timer automatically updates your form. Unless something new is added to what is currently in the beta, your changes would be history. Alpha would need to add something like what is there now when you try to save your changes and the record had already been changed by someone else, i.e., a warning and a way for you to reconcile your changes with those made by someone else. Or maybe the timer triggers a warning just that someone else has changed the record you are working on. Or something...?

Ray

Anis
03-07-2008, 01:32 PM
well, interactively yes you can hit F5, but you want that to be automatic.

If we add something like this it should be optional, if you do changes in A5 then you might not want to use it.
In my case (and as I understand from many users) all the changes and additions are coming thru MySql not Alpha, so in this case there's no problem and could be used, like you said if they are changing a record thru A5 and used that automatic refresh, it should come up with a screen of warning.

mmaisterrena
03-07-2008, 02:51 PM
what i do is put a "Refresh" button on the form

Anis
03-07-2008, 02:54 PM
How do you link that to a timer ?

Raymond Lyons
03-07-2008, 03:08 PM
well, interactively yes you can hit F5, but you want that to be automatic.

If we add something like this it should be optional, if you do changes in A5 then you might not want to use it.
In my case (and as I understand from many users) all the changes and additions are coming thru MySql not Alpha, so in this case there's no problem and could be used, like you said if they are changing a record thru A5 and used that automatic refresh, it should come up with a screen of warning.

I am not sure I made it clear: It does not matter whether the changes to a record are made "thru A5" or or through some other interaction with the backend DB, the issue is the same in both cases.

I am sure one could build a form timer for F5 refreshing that would do pretty much what Alpha has built into saves, but this would not deal with browse changes and assuming it makes sense in the first place we should not have to build this kind of thing ourselves anyway.

Ray

Peter.Greulich
03-07-2008, 04:46 PM
How do you link that to a timer ?


Put this in the OnTimer event:


sys_send_keys("{F5}")

Set the form's OnTimer interval to whatever you want.

Anis
03-07-2008, 04:57 PM
Thanks Peter

Raymond Lyons
03-08-2008, 01:49 AM
Put this in the OnTimer event:


sys_send_keys("{F5}")
Set the form's OnTimer interval to whatever you want.

To make sure no one misses what I said above in regard to this, I am going to repeat it:

"Suppose you are in the process of editing a record (have not saved anything but have changed possibly a bunch of fields). While you were doing that, [suppose] someone else made a change to the same record in the backend database and your timer automatically updates your form. Unless something new is added to what is currently in the beta, your changes would be history."

Meaning, if still desired, the user would have to make the changes all over again. Maybe this would be OK for your users, but mine would scream bloody murder. What is needed, I think, is the same kind of warning that occurs now in v9 when saving changes to a record that someone else has changed since you started your edits, i.e., rather than just automatically and irretrievably wiping out all your changes on the refresh, upon attempting to refresh we need a warning that someone else has changed the record you are still working on and showing what that other user changed and giving you some options as to how to proceed. Does anyone see what I am getting at here--or am I missing something?

Ray

andymeer@yahoo.co.uk
03-08-2008, 03:06 AM
Hi All

What I did to get around this problem, I ran my script above as a sperate operation from my Menu, Then when the user wants to view the images they open the form. So all links are available. No images can be added from the form.

PS. As anybody had a look at V9 HTML forms the advanced example is fantastic. I for one will be trying to learn this method

Andy

Jim Coltz
03-08-2008, 09:35 AM
You can also add a little more testing code to Peter's timer event to ensure the table(s) are not in change or enter mode using table.mode_get(). I use this method on our appointment form that needs refreshed to show the latest and greatest changes. It's tough to convince the users to refresh the form themselves before creating a new appointment. This seems to work well in our case. As long as no one is in the process of entering or editing a record the form refreshes. This is a form based on a three table set.


if parentform.Mode_Get()="VIEW" .and. tbl.mode_get() = 0 .and. tbl1.mode_get()\
= 0 .and. tbl2.mode_get()=0 then
topparent.Command("REFRESH")
end if

Anis
03-08-2008, 11:57 AM
Thanks for everyone. I will test all this before I put it in production.

Raymond Lyons
03-08-2008, 02:33 PM
You can also add a little more testing code to Peter's timer event to ensure the table(s) are not in change or enter mode using table.mode_get(). I use this method on our appointment form that needs refreshed to show the latest and greatest changes. It's tough to convince the users to refresh the form themselves before creating a new appointment. This seems to work well in our case. As long as no one is in the process of entering or editing a record the form refreshes. This is a form based on a three table set.


if parentform.Mode_Get()="VIEW" .and. tbl.mode_get() = 0 .and. tbl1.mode_get()\
= 0 .and. tbl2.mode_get()=0 then
topparent.Command("REFRESH")
end if

OK, after this, I give up. You can do this to "show the latest and greatest changes" via your Alpha app before you start making changes. But what if you begin making changes and either at the same time or a bit later someone else also begins making changes and they are done (save them) before you? If the timer refresh then happens, all the changes you made will be wiped out before your very eyes (unless you are looking elsewhere and don't notice them!) and you will have to start all over. Plus, if your SQL DB is open to being changed by means other than Alpha Five (mine is subject to being updated by non-Alpha programs all the time), all the Alpha based .mode_get() stuff in the world is not going to accomplish what you are looking for here. I think you need to look at what has gone on at the SQL DB level, not the active link table level, and that would be best left to the programmers at Alpha Software, especially since they already have the basics of what, I think, would be needed in code that fires when an active link record is saved (see the video on "Optimistic Record Locking" in What's New in Alpha Five Version 9). If what needs to be done can in fact be done at the active link table level, it certainly would take more than mere .mode_get() code.

There. I am done with this thread unless someone can show me where I am wrong (always possible!), in which case I will apologize for being so dense.

Ray

Anis
03-08-2008, 03:54 PM
I hope Selwyn can shed some light on this.

Thanks

mmaisterrena
03-09-2008, 03:49 PM
I will insist that a simple Save/Refresh button will do the job.
Make a button thats submits the changes first and then refreshes the display.

gagsoft
04-04-2008, 11:33 AM
I am sure this has been discussed a million times on this message board. I am trying to find a proper way to resync / refresh a browse on a form that shows info from a detail table on a set after adding new items. I am using active link tables on a MySQL database. The following code does not do it.


'save record
topparent.commit()
'refresh browse on order main form
'Activate object 'Browse1' in Form 'Bookings' .
DIM window_name as C
window_name = ":"+"Bookings"
DIM varP_Object as p
'Get a pointer to the specified window
varP_Object = obj(window_name)
'Check if the specified window exists
if .not. is_object(varP_Object) then
ui_msg_box("Error","The window '"+window_name+"' does not exist.",ui_stop_symbol)
else
varP_Object:Browse1.activate()
varP_Object:Browse1.commit()
varP_Object:Browse1.refresh()
varP_Object:Browse1.resynch()
varP_Object:Browse1.fetch_last()

end if

Or what is wrong with this code?

Selwyn Rabins
04-04-2008, 12:08 PM
I am sure this has been discussed a million times on this message board. I am trying to find a proper way to resync / refresh a browse on a form that shows info from a detail table on a set after adding new items. I am using active link tables on a MySQL database. The following code does not do it.


'save record
topparent.commit()
'refresh browse on order main form
'Activate object 'Browse1' in Form 'Bookings' .
DIM window_name as C
window_name = ":"+"Bookings"
DIM varP_Object as p
'Get a pointer to the specified window
varP_Object = obj(window_name)
'Check if the specified window exists
if .not. is_object(varP_Object) then
ui_msg_box("Error","The window '"+window_name+"' does not exist.",ui_stop_symbol)
else
varP_Object:Browse1.activate()
varP_Object:Browse1.commit()
varP_Object:Browse1.refresh()
varP_Object:Browse1.resynch()
varP_Object:Browse1.fetch_last()

end if

Or what is wrong with this code?


I think that what has been discussed on the message board in the past would not apply to this case because you have an active-link table and all previous discussions would have been about native a5 tables.

What happens if you put this code in your script:

varP_Object:browse1.ServerSideRefreshAll()


You need to force the active link table to refetch the data from the server.
Sorting on a column in active-link would cause a refresh as well.

Please let me know if this works.

Selwyn Rabins
04-04-2008, 12:31 PM
I actaually just tested it, and it works perfectly.

I have a form called 'Invoices' and my code does this:



INVOICES:browse1.ServerSideRefreshAll()

Anis
04-04-2008, 12:35 PM
I have this on a timer to refresh the form, at the same time it refreshes an embedded browse on the form,

topparent.ServerSideRefreshAll()

gagsoft
04-04-2008, 12:55 PM
Hi Selwyn

Thank you for your prompt reply. It works like a charm. And Anis, thanks for you input as well. It is appreciated. I am going to put this on a timer event. This is what makes this a great message board.
This has been a long week for me and I am going to sit back, relax and start enjoying the weekend.


Thanks


Peter Gagiano

gagsoft
04-04-2008, 01:10 PM
Anis

As a matter of interest, are you using this timer event on a remote SQL server? I am just wondering how much of your bandwidth it will be eating away.


Thanks
Peter

Anis
04-04-2008, 01:20 PM
Yes I'm using this on a remote SQL in the same location, it doesn't really use much bandwidth. This is yet being tested, once I finish this, it will be moved to the same server of the sql itself, so it should be much faster and easier since SQL and A5 are on the same machine.

gagsoft
04-04-2008, 01:25 PM
The client's database is located on a remote server and I am thinking of just putting a refresh button which the user has to click. Here in SA where I am, bandwidth is an expensive commodity. Any thoughts in this?

Anis
04-04-2008, 01:42 PM
As a matter of fact, I have a button to do a refresh as well in case the user wants to see updates in shorter than 10 seconds which I have on the timer.

If the information is not critical to reflect within a short period of time, I think it's a better idea to leave it to the user with a button on the form to refresh when they see fit.

gagsoft
04-05-2008, 11:06 AM
Anis

Thank you for the advice. Much appreciated.


Peter