GIF演示:
选择文件按钮:
int li_flag
string ls_openpath,ls_filename
li_flag =GetFileOpenName("文件选择",ls_openpath,ls_filename)
IF li_flag <> 1 then return
sle_1.text = ls_openpath
uo_1.of_read_data(ls_openpath)
blob按钮:
blob blb_tmp
blb_tmp = uo_1.of_upload(sle_1.text)
if len(blb_tmp) > 0 then
//写SQL语句,blb_tmp内容保存到数据库
//updateblob .....
uo_1.of_show(true)
end if
创建Custom Visual 对象,命名为vo_upload_progress
forward
global type vo_upload_progress from userobject
end type
type mle_1 from multilineedit within vo_upload_progress
end type
type st_1 from statictext within vo_upload_progress
end type
type st_bar from statictext within vo_upload_progress
end type
type st_4 from statictext within vo_upload_progress
end type
type st_5 from statictext within vo_upload_progress
end type
type st_6 from statictext within vo_upload_progress
end type
type st_filename from statictext within vo_upload_progress
end type
type st_filesize from statictext within vo_upload_progress
end type
type st_filetype from statictext within vo_upload_progress
end type
type st_percentage from statictext within vo_upload_progress
end type
type st_readsize from statictext within vo_upload_progress
end type
type gb_2 from groupbox within vo_upload_progress
end type
end forward
global type vo_upload_progress from userobject
integer width = 1836
integer height = 893
long backcolor = 16777215
string text = "none"
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
mle_1 mle_1
st_1 st_1
st_bar st_bar
st_4 st_4
st_5 st_5
st_6 st_6
st_filename st_filename
st_filesize st_filesize
st_filetype st_filetype
st_percentage st_percentage
st_readsize st_readsize
gb_2 gb_2
end type
global vo_upload_progress vo_upload_progress
forward prototypes
public function blob of_upload (string as_path)
public function long of_read_data (string as_path)
public function long of_show (boolean as_bool)
public function integer of_empty ()
end prototypes
public function blob of_upload (string as_path);integer li_FileNum, loops, i
long ll_flen, ll_bytes_read,ll_percentage
blob b, tot_b
string ls_fileSize
long ll_add_bytes
long ll_width
dec ldc_positino
SetPointer(HourGlass!)
ll_width = 1500
ldc_positino = Truncate(ll_width/100,2)
ll_flen = FileLength(as_path)
li_FileNum = FileOpen(as_path,StreamMode!, Read!, LockRead!)
IF ll_flen > 32765 THEN
loops = (ll_flen/32765) + 1
ELSE
loops = 1
END IF
FOR i = 1 to loops
ll_bytes_read = FileRead(li_FileNum, b)
ll_add_bytes += ll_bytes_read
if ll_add_bytes > 1024 * 1024 then //进度
ls_fileSize = string(round(ll_add_bytes/(1024 * 1024),2)) + 'MB'
else
ls_fileSize = string(round(ll_add_bytes/1024,2)) + 'KB'
end if
ll_percentage = round(100*(ll_add_bytes/ll_flen),0) //百分百
if ll_percentage > 100 then ll_percentage = 100
st_readsize.text = ls_fileSize
st_percentage.text = string(ll_percentage) + '%'
st_bar.width = ldc_positino * ll_percentage
tot_b = tot_b + b
NEXT
FileClose(li_FileNum)
return tot_b
end function
public function long of_read_data (string as_path);int li_flag
string ls_filename,ls_fileSize
long ll_filelength,ll_pos
long ll_maxPos = 0
of_show(false)
of_empty()
ll_filelength = FileLength(as_path)
if ll_filelength > 1024 * 1024 then
ls_fileSize = string(round(ll_filelength/(1024 * 1024),2)) + 'MB'
else
ls_fileSize = string(round(ll_filelength/1024,2)) + 'KB'
end if
//最后一个\位置
ll_pos = posW(as_path, '\', 1)
do while ll_pos > 0
ll_maxPos = max(ll_maxPos,ll_pos)
ll_pos = posW(as_path, '\', ll_pos + 1)
loop
ls_filename = midW(as_path,ll_maxPos + 1,lenW(as_path))
st_filename.text = ls_filename
//最后一个.位置
ll_pos = 0
ll_maxPos = 0
ll_pos = posW(as_path, '.', 1)
do while ll_pos > 0
ll_maxPos = max(ll_maxPos,ll_pos)
ll_pos = posW(as_path, '.', ll_pos + 1)
loop
ls_filename = midW(as_path,ll_maxPos + 1,lenW(as_path))
st_filetype.text = ls_filename
st_filesize.text = ls_fileSize
return 1
end function
public function long of_show (boolean as_bool);if as_bool then
st_1.visible = true
mle_1.visible = true
gb_2.height = 883
mle_1.text = '文件名:'+st_filename.text+'~r~n上传完成。~r~n文件大小:'+st_filesize.text
else
st_1.visible = false
mle_1.visible = false
gb_2.height = 550
end if
return 1
end function
public function integer of_empty ();st_bar.width = 50
st_percentage.text = '0%'
st_filename.text = ''
st_filesize.text = ''
st_filetype.text = ''
return 1
end function
on vo_upload_progress.create
this.mle_1=create mle_1
this.st_1=create st_1
this.st_bar=create st_bar
this.st_4=create st_4
this.st_5=create st_5
this.st_6=create st_6
this.st_filename=create st_filename
this.st_filesize=create st_filesize
this.st_filetype=create st_filetype
this.st_percentage=create st_percentage
this.st_readsize=create st_readsize
this.gb_2=create gb_2
this.Control[]={this.mle_1,&
this.st_1,&
this.st_bar,&
this.st_4,&
this.st_5,&
this.st_6,&
this.st_filename,&
this.st_filesize,&
this.st_filetype,&
this.st_percentage,&
this.st_readsize,&
this.gb_2}
end on
on vo_upload_progress.destroy
destroy(this.mle_1)
destroy(this.st_1)
destroy(this.st_bar)
destroy(this.st_4)
destroy(this.st_5)
destroy(this.st_6)
destroy(this.st_filename)
destroy(this.st_filesize)
destroy(this.st_filetype)
destroy(this.st_percentage)
destroy(this.st_readsize)
destroy(this.gb_2)
end on
event constructor;st_1.backcolor = rgb(255,153,0)
mle_1.backcolor = rgb(255,153,0)
of_show(false)
end event
type mle_1 from multilineedit within vo_upload_progress
integer x = 132
integer y = 592
integer width = 1569
integer height = 208
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "微软雅黑"
long textcolor = 33554432
long backcolor = 32896
boolean border = false
boolean displayonly = true
end type
type st_1 from statictext within vo_upload_progress
integer x = 77
integer y = 557
integer width = 1693
integer height = 269
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 32896
boolean enabled = false
alignment alignment = center!
boolean focusrectangle = false
end type
type st_bar from statictext within vo_upload_progress
integer x = 77
integer y = 362
integer width = 51
integer height = 74
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 32768
alignment alignment = center!
boolean focusrectangle = false
end type
type st_4 from statictext within vo_upload_progress
integer x = 88
integer y = 67
integer width = 252
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean italic = true
long textcolor = 33554432
long backcolor = 16777215
boolean enabled = false
string text = "文件名:"
boolean focusrectangle = false
end type
type st_5 from statictext within vo_upload_progress
integer x = 88
integer y = 157
integer width = 311
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean italic = true
long textcolor = 33554432
long backcolor = 16777215
boolean enabled = false
string text = "文件大小:"
boolean focusrectangle = false
end type
type st_6 from statictext within vo_upload_progress
integer x = 77
integer y = 246
integer width = 322
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean italic = true
long textcolor = 33554432
long backcolor = 16777215
boolean enabled = false
string text = "文件类型:"
boolean focusrectangle = false
end type
type st_filename from statictext within vo_upload_progress
integer x = 344
integer y = 67
integer width = 1265
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean italic = true
long textcolor = 33554432
long backcolor = 16777215
boolean enabled = false
boolean focusrectangle = false
end type
type st_filesize from statictext within vo_upload_progress
integer x = 395
integer y = 157
integer width = 1178
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean italic = true
long textcolor = 33554432
long backcolor = 16777215
boolean enabled = false
boolean focusrectangle = false
end type
type st_filetype from statictext within vo_upload_progress
integer x = 395
integer y = 246
integer width = 1287
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean italic = true
long textcolor = 33554432
long backcolor = 16777215
boolean enabled = false
boolean focusrectangle = false
end type
type st_percentage from statictext within vo_upload_progress
integer x = 1609
integer y = 362
integer width = 172
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "微软雅黑"
long textcolor = 33554432
long backcolor = 16777215
string text = "0%"
alignment alignment = center!
boolean focusrectangle = false
end type
type st_readsize from statictext within vo_upload_progress
integer x = 1408
integer y = 448
integer width = 373
integer height = 74
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "微软雅黑"
long textcolor = 33554432
long backcolor = 16777215
alignment alignment = right!
boolean focusrectangle = false
end type
type gb_2 from groupbox within vo_upload_progress
integer width = 1825
integer height = 883
integer taborder = 20
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 16777215
end type