1、我想雙擊圖片框彈出選擇圖片的工具表單如何寫代碼?
2、在圖片框顯示的圖片如何存入資料庫中?
3、存入資料庫的圖片如何取出顯示在圖片框中?
4、想問問下拉資料視窗如何做?
問題多了點 拜托各位大哥了 謝謝!!!
uj5u.com熱心網友回復:
1.用 getfileopenname()函式2.用 insert 陳述句
3.blob bl
selectblob pic into :bl from table;
p_1.setpicture(bl)
4.選擇一列,Edit屬性頁中的style type 改成dropDownDW
下面datawindow中選擇下拉的資料視窗
display column 中選擇顯示的列內容
data column 中選存放的內容
uj5u.com熱心網友回復:
存取二進制大物件在資料庫應用的開發程序中,經常要在資料庫中存盤一些備注資訊,而這些備注資訊的內容一般較大,格式多樣,有可能是影像、語音檔案、視頻檔案等,在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 照片
4、建立一視窗w_input,內置如下控制元件:
控制元件名 型別 說明
sle_no SingleLineEdit 輸入號碼
sle_name SingleLineEdit 輸入姓名
cb_select_photo Command Button 選擇照片檔案
sle_photo SingleLineEdit 顯示照片檔案名
cb_save Command Button 保存記錄(本文只有插入)
cb_query Command Button 查詢
cb_exit Command Button 退出
P_1 Picture 顯示照片
界面如下:
5、撰寫腳本
1)、cb_select_photo的clicked事件:
string ls_photofile
string ls_named
integer li_value
//選擇照片檔案
li_value = GetFileOpenName("選擇圖片檔案", &
+ ls_photofile, ls_named, "圖片檔案", &
+ "BMP Files (*.BMP),*.BMP," &
+ "JPG Files (*.JPG),*.JPG")
sle_photo.text = ls_photofile
p_1.Picturename = ls_photofile
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)
6、效果圖
1)、插入:如圖輸入內容并選擇圖片,然后選擇保存按鈕。
2)、輸入幾個號碼和名稱并選擇圖片,然后逐一顯示如下(本文照片取自MY83論壇,如有侵權,請告知):
江南小生:
深圳土著:
夏芷若:
賤客無名:
北京馬桶:
uj5u.com熱心網友回復:
圖片最好用db ole object就是進入dw從哪里插計算列,那里有一個插db ole object
選好咧和對應關系等,你說的前三個功能不用寫代碼
隨著dw_1.update,retrieve一起操作
下拉資料窗就是一個資料窗,你把他的style改稱dddw,選好顯示列資料列
uj5u.com熱心網友回復:
這是我寫過的一個存入圖片并顯示的腳本,可供參考。其中gs_開頭的為全域引數,沒有在這里宣告,但可以看出的。
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
li_ph = dw_1.getitemnumber(dw_1.getrow(),"rsgl_ph")
value = GetFileopenName("(添加圖片)選擇圖片檔案", &
+ pathname, named, "picture", &
+ "JPG Files (*.JPG),*.JPG")
ls_curdir = mid(pathname,1,pos(pathname,named) - 1 )
if ls_curdir <> '' then
setprofilestring (is_lnifile,"照片默認路徑","path", ls_curdir)
end if
if value=https://bbs.csdn.net/topics/1 then
integer li_FileNum, loops, i
long flen, bytes_read, new_pos
blob b, tot_b
SetPointer(HourGlass!)
flen = FileLength(pathname)
li_FileNum = FileOpen(pathname, &
StreamMode!, Read!, LockRead!)
//如果圖片大于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
/*回到原來路徑*/
SetCurrentDirectoryA(gs_curdir)
setredraw(true)
uj5u.com熱心網友回復:
不會,幫頂uj5u.com熱心網友回復:
感謝樓上的,我先收藏了。uj5u.com熱心網友回復:
為何我在插入圖片時,老提示“插入記錄出錯”,這是為何呀??
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/100874.html
標籤:數據庫相關
