Home > Archive > Programming with dBASE > March 2006 > Sharing data over Network









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Sharing data over Network
Tim Ward

2006-02-28, 8:25 pm

I am not very experieced at programming but am writing a program that shares a database containing 2 tables over a small network with 3 users using my application. How do I update the display of a grid on the other workstations when a one user alters the
data. I have put a button that requeries the database when a user clicks it but I would like it to be automatic when another user alters data?
Todd Kreuter

2006-02-28, 8:25 pm

Tim Ward wrote:
>
> I am not very experieced at programming but am writing a program that shares a database containing 2 tables over a small network with 3 users using my application. How do I update the display of a grid on the other workstations when a one user alters th

e data. I have put a button that requeries the database when a user clicks it but I would like it to be automatic when another user alters data?

I think you would at least need a timer object to periodically check the
table for changes. I put together the following demo form which does
that. Not sure how to distinquish your changes form some other user's
changes, though maybe it does not matter.

Run the demo on two different computers or in two different instances of
dbase. Make a change in one instance and watch other get updated. I did
very limited testing, but seems to work well. Probably needs a bit more
work.


--
Todd Kreuter [dBVIPS]


*** Copy and paste to NetForm.wfm ***
set database to
if NOT _app.databases.current.tableExists("NetTable")
create table "NetTable" (;
Field1 Char(1),;
Field2 Char(1),;
Field3 Char(1))

insert into "NetTable" Values("A", "1", "a")
insert into "NetTable" Values("B", "2", "b")
insert into "NetTable" Values("C", "3", "c")
insert into "NetTable" Values("D", "4", "d")

endif
** END HEADER -- do not remove this line
//
// Generated on 02/28/2006
//
parameter bModal
local f
f = new NetChangeForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class NetChangeForm of FORM
with (this)
metric = 6 // Pixels
height = 352.0
left = 246.0
top = 0.0
width = 405.0
text = ""
endwith

this.Query1 = new QUERY()
this.Query1.parent = this
with (this.Query1)
left = 1.0
top = 0.5
sql = 'select * from "NetTable.dbf"'
active = true
endwith

this.GRID1 = new GRID(this)
with (this.GRID1)
fontSize = 8.0
dataLink = form.query1.rowset
cellHeight = 22.0
anchor = 6 // Container
height = 352.0
left = 0.0
top = 0.0
width = 405.0
endwith

this.rowset = this.query1.rowset

function onOpen
***************
this.netTable = new NetTable()
this.netTable.grid = this.grid1

this.netTable.fileName = this.rowset.tableName
this.netTable.enable(true)

return

function canClose
*****************
this.netTable.enable(false)

return true


endclass

Class NetTable
this.file = new file()

this.timer = new timer()
this.timer.parent = this
this.timer.interval = 2.0
this.timer.onTimer = class::onTimer

this.fileName = null
this.fileMark = null

function enable(bEnable)
***************
this.timer.enabled = bEnable

return

function onTimer
****************
this.parent.refresh()

function refresh
****************

local cMark
cMark = DTOS(this.file.date(this.fileName))
cMark += this.file.time(this.fileName)
cMark += STR(this.file.size(this.fileName), 10,0, "0")

if this.fileMark = null
// initial value, do nothing

elseif this.fileMark # cMark
if this.grid.datalink.state = 1
this.grid.refresh()
endif

endif

this.fileMark = cMark

return

endclass
Tim Ward

2006-03-05, 8:27 pm

Thanks for your help. It's nice to see the data appearing on the grid all by itself!
Todd Kreuter

2006-03-05, 8:27 pm

Tim Ward wrote:
>
> Thanks for your help. It's nice to see the data appearing on the grid all by itself!


You're welcome, Tim.

I previously tested by placing the table on a novell network file server
where file caching is turned off. I wonder how it works when file
caching is turned on or under other netwoking situations? Some day when
I have time I may play around with it a bit more

--
Todd Kreuter [dBVIPS]
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com