int result
choose case upper(ls_type)
case '.XLS'
result = lo_open.ConnectToNewObject("excel.application")
if result = 0 then
lo_open.application.visible = 1
lo_open.Workbooks.open(ls_file);
end if
case '.DOC'
result = lo_open.ConnectToNewObject("word.application")
if result = 0 then
lo_open.documents.open(ls_file);
lo_open.application.visible = 1
//insert the audi to the file
else
destroy lo_open
messagebox('提示', '文件已经下载到:' + ls_file)
return
end if
case else
result = lo_open.ConnectToObject(ls_file)
if result = 0 then
lo_open.application.visible = 1
lo_open.application.open()
else
destroy lo_open
messagebox('提示', '文件已经下载到:' + ls_file)
return
end if
end choose
//下载
//down load the file form the sever and open it
integer li_FileNum
blob lb_file, b
long ll_row
double ll_id
string ls_direct, ls_type, ls_file
// Set a wait cursor
SetPointer(HourGlass!)
//select the bolb
ll_row = dw_main.getrow()
ls_type = dw_main.object.file_type[ll_row]
if POS(ls_type, '.') <= 0 then
messagebox('提示', '此记录没有上载文件!')
return
end if
ll_id = dw_main.object.oid_file[ll_row]
SELECTBLOB blob字段
INTO :lb_file
FROM 表
USING sqlca;
//get the file's fullname, create it at the process's current directory and //named 'temp'
ls_direct = space(100)
GetCurrentDirectory(len(ls_direct), ls_direct)
ls_file = ls_direct + '\temp' + ls_type
//open it and write
li_FileNum = FileOpen( &
ls_file, &
StreamMode!, Write!, Shared!, Replace!)
long flen
int loops,i
flen = len(lb_file)
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
// Read the file
FOR i = 1 to loops
if i = loops then
b = lb_file
else
b = blobmid(lb_file,1,32765)
lb_file = blobmid(lb_file, 32766, len(lb_file) - 32765)
end if
Filewrite(li_FileNum, b) //tot_b = tot_b + b
NEXT
//FileWrite(li_FileNum, lb_file)
fileclose(li_filenum)
//get the currentrow
long ll_row
ll_row = dw_main.getrow()
if ll_row <= 0 then
messagebox('提示','请选择上载文件的记录')
return
end if
//if new row the update it
if dw_main.GetItemStatus(ll_row, 0, Primary!) = New! or dw_main.GetItemStatus(ll_row, 0, Primary!) = NewModified! then
//dw_main.object.file_type[ll_row] = ' '
dw_main.accepttext()
if dw_main.update() = 1 then
commit;
//dw_main.resetupdate()
else
rollback;
return
end if
end if
//get the file name
string ls_file, named, ls_olddirect
integer value
//save the old directory
ls_olddirect = space(100)
GetCurrentDirectory(len(ls_olddirect), ls_olddirect)
value = GetFileOpenName("Select File", ls_file, named, "DOC", &
+ "Excle Files (*.XLS),*.XLS," &
+ "Doc Files (*.DOC),*.DOC," &
+ "All Files (*.*), *.*")
if value <> 1 then return
//reset the process's directory
SetCurrentDirectory(ls_olddirect)
integer li_FileNum, loops, i
long flen, bytes_read, new_pos
blob b, tot_b
// Set a wait cursor
SetPointer(HourGlass!)
// Get the file length, and open the file
flen = FileLength(ls_file)
li_FileNum = FileOpen(ls_file, &
StreamMode!, Read!, LockRead!)
// Determine how many times to call FileRead
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
// Read the file
new_pos = 1
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
tot_b = tot_b + b
NEXT
FileClose(li_FileNum)
// Update the Blob
double ll_id
ll_id = dw_main.object.oid_file[ll_row]
sqlca.AutoCommit = true
UPDATEBLOB table SET blob字段 = :tot_b
USING sqlca;
IF sqlca.SQLNRows > 0 THEN
COMMIT USING sqlca ;
//set the file type
dw_main.object.file_type[ll_row] = right(ls_file, 4)
dw_main.update()
commit;
END IF
sqlca.AutoCommit = false