getfileopenname('选择照片文件',ls_path_filename,ls_filename,"JPG","JPG Files(*.JPG),*.JPG")
if ls_filename='' then return
fp=fileopen(ls_path_name,streammode!) //打开JPG照片文件
fileread(fp,i_photo) //照片数据存入blob类型I_photo变量中
fileclose(fp) //照片的JPG文件容量很小,只读取最多64KB的数据
//照片数据存入职工照片表中
updateblob emp_photo set photo=:i_photo where emp_ID=:g_emp_ID ;
if sqlca.sqlcode= -1 then
ROLLBACK;
messagebox('出错信息','照片存储失败!')
else
commit;
end if
⑷ 图像显示
职工照片要求和职工信息一起显示、打印。在窗口中建立一数据窗口控件dw_1,然后利用数据窗口画笔以freeform风格新建一数据窗口dw_emp_info,它以职工号为参数检索emp_info(职工信息表)的数据:职工号和姓名。为处理照片显示和打印,在数据窗口中建立一个OLE对象,在出现的“inert object”(插入对象)对话框中,选中“insert control”单选钮,在“control type”控件选择列表框中找到“Microsoft Web浏览器”,选中它,然后按确定按钮,在该对象name属性中输入ole_photo,然后按确定。这时在数据窗口中增加了一个矩形对象,这就是显示照片的对象。调整该对象的大小,使能容纳实际照片大小。如图1所示:
图 1
设置dw_1的Datawindow Object Name 属性为dw_emp_info。在窗口open事件中编写如下程序:
dw_1.settransobject(sqlca)
dw_1.retrieve(g_emp_ID)
在窗口中建立一按钮cb_display,实现图像显示,click事件程序如下:
//从照片表中取出照片数据
selectblob photo into :i_photo from emp_photo
where emp_ID = :g_emp_ID;
//建立临时文件
fp=fileopen('c:\~~temp_photo.jpg',streammode!,write!,lockreadwrite!,replace!)
if fp= - 1 then
messagebox('出错信息','JPG临时文件建立失败')
return
end if
//建立JPG 照片文件
filewrite(fp,i_photo)
fileclose(fp)
//在数据窗口中显示照片
dw_1.object.ole_photo.object.navigate('c:\~~temp_photo.jpg')