dw_1.setfocus()
IF DW_1.GETROW()=0 THEN
MESSAGEBOX("提示","当前没有记录,不允许选择图片!")
RETURN
END IF
if FileExists("bmp/picture.jpg")=false or FileExists("bmp/notpict.jpg")=false then
messagebox("提示","对不起, 找不到系统默认图片, 无法操作!")
return
end if
string pathname, named,ls_image,ls_curdir
integer value
long li_ph
string is_lnifile
is_lnifile = uf_getapp()+"\rsgl.ini"
ls_curdir = profilestring(is_lnifile,"照片默认路径","path",'')
//指向照片的默认路径:
if ls_curdir<>'' then
SetCurrentDirectoryA(ls_curdir)
end if
//如果图片大于32K X 5 时, 拒绝存入到数据库中:
if flen > 32765 * 2 then
messagebox("提示","系统限制文件大小为64kb,当前文件大小为:"+string(round(flen/1024,0))+"Kb, 拒绝存入数据库!")
/*回到原来路径*/
SetCurrentDirectoryA(gs_curdir)
setredraw(true)
return
end if
if flen = -1 then
messagebox("提示","存入图片出错, 按确定返回!")
/*回到原来路径*/
SetCurrentDirectoryA(gs_curdir)
setredraw(true)
return
end if
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
new_pos = 1
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
tot_b = tot_b + b
NEXT
FileClose(li_FileNum)
UPDATEBLOB rsgl SET fimage = :tot_b WHERE ph=:li_ph ;
update rsgl set fimage_b = 1 where ph = :li_ph;
dw_1.setitem(dw_1.getrow(),'rsgl_fimage_b',1)
commit;
end if
string li_default
long li_row
Blob Emp_id_pic
long ll_row,ll_row1
blob lb_image,lb_image1
if dw_1.getrow()>0 then
li_ph=dw_1.getitemnumber(dw_1.getrow(),"rsgl_ph")
end if
/*回到原来路径*/
SetCurrentDirectoryA(gs_curdir)
setredraw(true)
// 显示加载图片:
li_default = "bmp\rms_image.jpg"
gs_image='bmp\picture.jpg'
if FileExists(li_default)=false or FileExists(gs_image)=false then
messagebox("提示","对不起, 找不到系统默认图片, 无法操作!")
return
end if
ll_row1=dw_1.rowcount()
if ll_row1>0 then
selectblob fimage into :lb_image from rsgl where ph = :li_ph;
li_FileNum = FileOpen( &
"bmp\picture.jpg", &
StreamMode!, Write!, LockWrite!, Replace!)
SetPointer(HourGlass!)
flen = Len(lb_image)
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
new_pos = 1
FOR i = 1 to loops
b = blobmid(lb_image, (i -1)*32765,32765)
FileWrite(li_FileNum, b)
NEXT
FileClose(li_FileNum)
if flen = 0 or flen = 1 then
dw_2.object.p_1.filename=li_default
else
dw_2.object.p_1.filename=gs_image
end if
end if
在数据库应用的开发过程中,经常要在数据库中存储一些备注信息,而这些备注信息的内容一般较大,格式多样,有可能是图像、语音文件、视频文件等,在PB中可以使用OLE的方法,也可以直接用脚本处理。
本文介绍用脚本来处理,数据库是ASA8的,附件里有表的设计,文中省略。
1、建立一个工作空间(workspace),取名为:blob。
2、建立一个应用(application),取名为:blob。
3、设计一个表blobtest,其字段定义如下:
Column Name Data Type Width Null Comment
No Integer No 号码
Name Varchar 10 No 姓名
Photo Long Binary Null 照片
2)、cb_save的clicked事件:(本文只处理了新增记录,有兴趣的朋友可以完善他)
long ll_no
string ls_name
string ls_photofile
integer li_filenum
integer li_loops
integer li_counter
long ll_filelen
blob lb_read
blob lb_picture
If sle_no.text = '' or sle_name.text = '' or sle_photo.text = '' then return
ll_no = long(sle_no.text) //号码
ls_name = sle_name.text //姓名
ls_photofile = sle_photo.text //照片文件
//插入记录,先写no,name字段
Insert into blobtest (no,name)
values (:ll_no, :ls_name);
If sqlca.sqlcode = -1 then
Rollback;
Messagebox('插入记录出错',Sqlca.Sqlerrtext)
Return
Else
Commit;
End if
// 获 取 文 件 的 大 小
ll_filelen = FileLength(ls_photofile)
//打开文件
li_filenum = FileOpen(ls_photofile,STREAMMODE!, READ!,LOCKREAD!)
/*FileRead() 函 数 不 支 持 读 取 大 于32K 的 文 本,
计 算 将 使 用 FileRead 函 数 的 次 数*/
IF ll_filelen > 32765 THEN
li_loops = ( (ll_filelen - 1) / 32765 ) + 1
ELSE
li_loops = 1
END IF
//读文件
FOR li_counter = 1 to li_loops
FileRead(li_filenum, lb_read )
lb_picture = lb_picture + lb_read
NEXT
FileClose(li_filenum)
//显示图片
p_1.SetPicture(lb_picture)
//写入数据库
UPDATEBLOB blobtest
SET photo = :lb_picture
WHERE no = :ll_no;
IF Sqlca.SQLNRows > 0 THEN
COMMIT;
Messagebox('提示信息','记录保存成功!')
Else
Rollback;
Messagebox('提示信息','记录保存成功,照片文件保存失败!' + sqlca.sqlerrtext)
END IF
3)、cb_exit的clicked事件:
close(parent)
4)、cb_query的clicked事件:
blob lb_picture
long ll_No
if sle_no.text = '' then return
ll_no = long(sle_no.text) //号码
SelectBlob photo
Into :lb_picture
From blobtest
where no = :ll_no;
//显示图片
p_1.SetPicture(lb_picture)