$PBExportHeader$w_fj_manage.srw
forward
global type w_fj_manage from window
end type
type cb_up from uo_imflatbutton within w_fj_manage
end type
type dw_file_fj from u_dw_rbtnfilter within w_fj_manage
end type
type cb_read from uo_imflatbutton within w_fj_manage
end type
type cb_refresh from uo_imflatbutton within w_fj_manage
end type
type cb_exit from uo_imflatbutton within w_fj_manage
end type
type ln_bar from line within w_fj_manage
end type
type r_bar from rectangle within w_fj_manage
end type
end forward

global type w_fj_manage from window
integer width = 3918
integer height = 2400
boolean titlebar = true
string title = "附件查看"
boolean controlmenu = true
windowtype windowtype = response!
long backcolor = 134217739
string icon = "AppIcon!"
boolean center = true
cb_up cb_up
dw_file_fj dw_file_fj
cb_read cb_read
cb_refresh cb_refresh
cb_exit cb_exit
ln_bar ln_bar
r_bar r_bar
end type
global w_fj_manage w_fj_manage

type variables
string ins_title //标题
long ins_billtype //单据类型
long ins_relid //单据id
long ins_relid_mx = 0 //单据明细id
string ins_relcode //单据编号
end variables

forward prototypes
public subroutine wf_refresh ()
public function integer wf_get_filedata (string arg_filedir, string arg_filemd5, string arg_filetype, ref string arg_msg)
end prototypes

public subroutine wf_refresh ();string arg_msg
oleobject request,response,fx_file_fjs,item

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetInt('billtype', ins_billtype)
request.SetInt('relid', ins_relid)
request.SetInt('relid_mx', ins_relid_mx)

response = FXAppCom.DoExecute('GetFxFileFj', request)
arg_msg = response.GetString('ErrMsg')

if (arg_msg <> '') then
    messagebox('提示', '获取附件列表失败，原因：' + arg_msg)
    return
end if
fx_file_fjs = response.GetArrOfPBDictionary('FxFileFjs')

IF  isnull(fx_file_fjs) THEN
    RETURN
END IF

IF  fx_file_fjs.Count <= 0 THEN
    RETURN
END IF

dw_file_fj.Reset()
dw_file_fj.SetRedraw(false)
long i,row
for i = 1 to fx_file_fjs.Count
	 item = fx_file_fjs.GetItem(i - 1)
    
	 row = dw_file_fj.InsertRow(0)

	 dw_file_fj.Object.fileid[row] = item.GetInt('fileid')
	 dw_file_fj.Object.comname[row] = item.GetString('comname')
	 dw_file_fj.Object.displayName[row] = item.GetString('displayName')
	 dw_file_fj.Object.fileName[row] = item.GetString('fileName')
	 dw_file_fj.Object.fileType[row] = item.GetString('fileType')
	 dw_file_fj.Object.fx_file_fj_dscrp[row] = item.GetString('dscrp')
	 dw_file_fj.Object.filemd5[row] = item.GetString('filemd5')
	 dw_file_fj.Object.filesize[row] = item.GetDouble('file_size')
	 dw_file_fj.SetItem(row, 'opdate', item.GetDatetime('opdate'))	
	 dw_file_fj.SetItem(row, 'if_mtfj', item.GetInt('if_mtfj'))	
	 
next

dw_file_fj.SetRedraw(true)
end subroutine

public function integer wf_get_filedata (string arg_filedir, string arg_filemd5, string arg_filetype, ref string arg_msg);Long rslt = 1

oleobject parm
parm = FxAppCom.CreatePbDictionary()
parm.SetString('token', app_token_fx)
parm.SetString('fileDir', arg_filedir)
parm.SetString('filename', arg_filemd5)
parm.SetString('extension', arg_filetype)
parm.SetString('md5', arg_filemd5)
FXAppCom.GetFileDataByMd5(parm, ref arg_msg)
IF NOT ISNULL(arg_msg) AND Len(arg_msg) > 0 THEN
	rslt = 0
	GOTO ext
END IF

ext:
RETURN rslt

end function

on w_fj_manage.create
this.cb_up=create cb_up
this.dw_file_fj=create dw_file_fj
this.cb_read=create cb_read
this.cb_refresh=create cb_refresh
this.cb_exit=create cb_exit
this.ln_bar=create ln_bar
this.r_bar=create r_bar
this.Control[]={this.cb_up,&
this.dw_file_fj,&
this.cb_read,&
this.cb_refresh,&
this.cb_exit,&
this.ln_bar,&
this.r_bar}
end on

on w_fj_manage.destroy
destroy(this.cb_up)
destroy(this.dw_file_fj)
destroy(this.cb_read)
destroy(this.cb_refresh)
destroy(this.cb_exit)
destroy(this.ln_bar)
destroy(this.r_bar)
end on

event open;s_edit_index_tran s_tran //翻页功能窗口 传递参数使用
s_tran = Message.PowerObjectParm

//单据类型
IF NOT IsNull(s_tran.d_long ) THEN
	ins_billtype = s_tran.d_long 
ELSE
	MessageBox('系统提示','单据类型不正确或没有指定')
	Close(THIS)
	RETURN
END IF

//单据id
IF NOT IsNull(s_tran.e_long ) THEN
	ins_relid = s_tran.e_long  //标题
ELSE
	MessageBox('系统提示','单据类型不正确或没有指定')
	Close(THIS)
	RETURN
END IF

IF NOT IsNull(s_tran.f_long ) THEN
	ins_relid_mx = s_tran.f_long  //标题
ELSE
	MessageBox('系统提示','单据类型不正确或没有指定')
	Close(THIS)
	RETURN
END IF


//标题
IF NOT IsNull(s_tran.d_string ) THEN
	ins_relcode = s_tran.d_string
	ins_title = '附件管理[' + ins_relcode + ']'
ELSE
	ins_title = "附件查看"
END IF
THIS.Title = ins_title


IF s_tran.work_mode = 1 THEN
	cb_up.visible = true
ELSE
	cb_up.visible = FALSE
END IF



wf_refresh()
end event

event resize;ln_bar.EndX = THIS.Width
r_bar.Width = THIS.Width
end event

type cb_up from uo_imflatbutton within w_fj_manage
integer x = 827
integer width = 274
integer height = 164
integer taborder = 40
boolean bringtotop = true
string text = "上传文件"
string normalpicname = "preview.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;Long lrow

s_fileinfo s_file

s_file.fileid = 0
s_file.Filename = ''
s_file.dscrp = ''
s_file.FileType = ''
s_file.relid = ins_relid
s_file.relcode = ins_relcode
s_file.billtype = ins_billtype
s_file.relid_mx = ins_relid_mx

SetNull(s_file.filedata)

OpenWithParm(w_fj_fileadd_p,s_file)

s_file = Message.PowerObjectParm
wf_refresh()


end event

type dw_file_fj from u_dw_rbtnfilter within w_fj_manage
integer x = 5
integer y = 180
integer width = 3895
integer height = 2112
integer taborder = 30
string dataobject = "dw_file_fj"
boolean rbutton_filter_use = true
boolean rbutton_setposition_use = true
boolean titleclick_sort_use = true
end type

event rowfocuschanged;call super::rowfocuschanged;if IsNull(currentrow) then return
if (currentrow <= 0) then return

this.SelectRow(0, false)
this.SelectRow(currentrow, true)
end event

type cb_read from uo_imflatbutton within w_fj_manage
integer x = 197
integer width = 274
integer height = 164
integer taborder = 10
boolean bringtotop = true
string text = "查看文件"
string normalpicname = "preview.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;String Pathname,ls_filetype,ls_filemd5,ls_exePath,ls_filedir,arg_msg

Long ls_row
ls_row = dw_file_fj.GetRow()
IF ls_row <= 0 THEN
	MessageBox('系统提示','当前没有文件')
	RETURN
END IF

ls_exePath = GetCurrentDirectory()
//文件夹定义
IF ins_billtype = 401 THEN  //采购订单
	ls_filedir = ls_exePath + '\cache\fxsaletask\'
ELSE
	ls_filedir = ls_exePath + '\cache\temp\'
END IF

//取附件信息
ls_filemd5 = dw_file_fj.Object.filemd5[ls_row]
ls_filetype = Lower(Trim(dw_file_fj.Object.FileType[ls_row]))

Pathname = ls_filedir + ls_filemd5 + "." + ls_filetype

String lsNull
If (FileExists(Pathname)) THEN // 先查找本地是否存在文件
	ShellExecute32( Handle(This), lsNull, Pathname, lsNull, lsNull, 1 )
ELSE
	IF wf_get_filedata(ls_filedir, ls_filemd5, ls_filetype, arg_msg) = 0 THEN
		MessageBox('提示', '获取文件失败,原因:' + arg_msg)
		RETURN
	END IF
	
	If (FileExists(Pathname)) THEN // 查找本地是否存在文件
		ShellExecute32( Handle(This), lsNull, Pathname, lsNull, lsNull, 1 )
	END IF
END IF





end event

type cb_refresh from uo_imflatbutton within w_fj_manage
integer x = 9
integer width = 187
integer height = 164
integer taborder = 20
boolean bringtotop = true
string text = "刷新"
string normalpicname = "refresh.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;wf_refresh()
end event

type cb_exit from uo_imflatbutton within w_fj_manage
integer x = 471
integer width = 187
integer height = 164
integer taborder = 20
boolean bringtotop = true
string text = "退出"
string normalpicname = "exit.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;Close(parent)
end event

type ln_bar from line within w_fj_manage
long linecolor = 268435456
integer linethickness = 4
integer beginy = 168
integer endx = 2002
integer endy = 168
end type

type r_bar from rectangle within w_fj_manage
long linecolor = 16777215
integer linethickness = 4
long fillcolor = 1073741824
integer x = 2203
integer y = 40
integer width = 87
integer height = 52
end type

event constructor;THIS.FillColor = 14215660
THIS.LineColor = 14215660
THIS.X = -1
THIS.Y = -1
THIS.Height = ln_bar.BeginY - 5

end event

