$PBExportHeader$w_rp_mstpay_fx.srw
$PBExportComments$供应商对账单(协同)
forward
global type w_rp_mstpay_fx from w_publ_base_style
end type
type cb_retrieve from uo_imflatbutton within w_rp_mstpay_fx
end type
type cb_1 from uo_imflatbutton within w_rp_mstpay_fx
end type
type st_1 from statictext within w_rp_mstpay_fx
end type
type em_datea from editmask within w_rp_mstpay_fx
end type
type st_2 from statictext within w_rp_mstpay_fx
end type
type em_datez from editmask within w_rp_mstpay_fx
end type
type dw_mstpay_ff from datawindow within w_rp_mstpay_fx
end type
type dw_mstpay from u_dw_rbtnfilter within w_rp_mstpay_fx
end type
type dw_mstpay_data from datawindow within w_rp_mstpay_fx
end type
type cb_2 from commandbutton within w_rp_mstpay_fx
end type
type st_4 from statictext within w_rp_mstpay_fx
end type
type em_heightedit from editmask within w_rp_mstpay_fx
end type
type cb_read from uo_imflatbutton within w_rp_mstpay_fx
end type
end forward

global type w_rp_mstpay_fx from w_publ_base_style
integer width = 4713
integer height = 2768
string title = "供应商对账表"
boolean maxbox = true
boolean resizable = true
long backcolor = 16777215
event ue_page_next ( )
event ue_page_before ( )
event ue_page_end ( )
cb_retrieve cb_retrieve
cb_1 cb_1
st_1 st_1
em_datea em_datea
st_2 st_2
em_datez em_datez
dw_mstpay_ff dw_mstpay_ff
dw_mstpay dw_mstpay
dw_mstpay_data dw_mstpay_data
cb_2 cb_2
st_4 st_4
em_heightedit em_heightedit
cb_read cb_read
end type
global w_rp_mstpay_fx w_rp_mstpay_fx

type variables
long ins_cur_pageNum = 1 // 用于记录当前页码
long ins_totalPages = 1 // 用于记录总页数
end variables

forward prototypes
public function integer wf_retrieve ()
public function integer wf_retrieve_data (long a_row)
public function integer wf_delete_local_data (boolean a_ifsilence)
end prototypes

event ue_page_next();// 下页
if (ins_cur_pageNum = ins_totalPages) then return

ins_cur_pageNum ++
end event

event ue_page_before();// 上页
if (ins_cur_pageNum = 1) then return

ins_cur_pageNum --
end event

event ue_page_end();// 末页
if (ins_cur_pageNum = ins_totalPages) then return

ins_cur_pageNum = ins_totalPages
end event

public function integer wf_retrieve ();int rslt = 1
string arg_msg

long oriRow
oriRow = dw_mstpay.GetRow()

datetime dateA, dateZ
dateA = DateTime(Date(em_dateA.Text), Time(0))
dateZ = DateTime(Date(em_dateZ.Text), Time('23:59:59'))

oleobject obj, parm, list, item
parm = FxAppCom.CreatePbDictionary()
parm.SetString('token', app_token_fx)
parm.SetDateTime('dateA', dateA)
parm.SetDateTime('dateZ', dateZ)
obj = FXAppCom.GetRpMstpay(parm, ref arg_msg)
if (arg_msg <> '') then
	rslt = 0
	goto ext
end if

dw_mstpay.Reset()
dw_mstpay_ff.Reset()
dw_mstpay_data.Reset()

long i, row
list = obj.GetPBArray('list')
dw_mstpay.SetRedraw(false)
for i = 1 to list.Count
	item = list.GetPBDictionary(i - 1)
	row = dw_mstpay.InsertRow(0)
	
	dw_mstpay.Object.ch[row] = 0
	dw_mstpay.Object.SerialNum[row] = item.GetString('SerialNum')
	dw_mstpay.Object.SendSCcode[row] = item.GetString('SendSCcode')
	dw_mstpay.Object.AddUser[row] = item.GetString('AddUser')
	if (not IsNull(item.GetDateTime('AddTime'))) then
		dw_mstpay.Object.AddTime[row] = item.GetDateTime('AddTime')
	end if
//	dw_mstpay.Object.Summary[row] = item.GetString('Summary')
	dw_mstpay.Object.Postscript[row] = item.GetString('Postscript')
//	dw_mstpay.Object.Remark[row] = item.GetString('Remark')
	if (not IsNull(item.GetDateTime('effectDateA'))) then
		dw_mstpay.Object.effectDateA[row] = item.GetDateTime('effectDateA')
	end if
	if (not IsNull(item.GetDateTime('effectDateZ'))) then
		dw_mstpay.Object.effectDateZ[row] = item.GetDateTime('effectDateZ')
	end if
	dw_mstpay.Object.flag[row] = item.GetInt('flag')
	dw_mstpay.Object.opemp[row] = item.GetString('opemp')
	if (not IsNull(item.GetDateTime('opdate'))) then
		dw_mstpay.Object.opdate[row] = item.GetDateTime('opdate')
	end if
	dw_mstpay.Object.withdrawEmp[row] = item.GetString('withdrawEmp')
	if (not IsNull(item.GetDateTime('withdrawDate'))) then
		dw_mstpay.Object.withdrawDate[row] = item.GetDateTime('withdrawDate')
	end if
	dw_mstpay.Object.filename[row] = item.GetString('filename')
	dw_mstpay.Object.extension[row] = item.GetString('extension')
	dw_mstpay.Object.comname[row] = item.GetString('comname')
	if (item.GetInt('Status') = 5) then // [5]接收未处理
		dw_mstpay.Object.unread[row] = 1
	else
		dw_mstpay.Object.unread[row] = 0
	end if
next
dw_mstpay.AcceptText()
dw_mstpay.SetRedraw(true)

//wf_delete_local_data(true)

ext:
if (rslt = 1) then
	if (dw_mstpay.RowCount() > 0) then
		dw_mstpay.SelectRow(0, false)
		if (oriRow > 0 and oriRow <= dw_mstpay.RowCount()) then
			dw_mstpay.SelectRow(oriRow, true)
			dw_mstpay.SetRow(oriRow)
			dw_mstpay.post event RowFocusChanged(oriRow)
		else
			dw_mstpay.SelectRow(1, true)
			dw_mstpay.SetRow(1)
			dw_mstpay.post event RowFocusChanged(1)
		end if
	end if
else
	MessageBox('提示', arg_msg)
end if

return rslt





end function

public function integer wf_retrieve_data (long a_row);int rslt = 1
string arg_msg

if (IsNull(a_row)) then return 0
if (a_row <= 0) then return 0

dw_mstpay_data.Reset()
dw_mstpay.Accepttext( )
long flag // 0-不可读 1-可读 2-被撤回
flag = dw_mstpay.Object.flag[a_row]
if (flag = 0 or flag = 2) then return 0

string sn, filename, extension, exePath, fileDir
sn = dw_mstpay.Object.SerialNum[a_row]
filename = dw_mstpay.Object.filename[a_row]
extension = dw_mstpay.Object.extension[a_row]
exePath = GetCurrentDirectory()
fileDir = exePath + '\cache\mstpay\'
IF ISNULL(sn) THEN RETURN 0

long insertRow
oleobject parm
dw_mstpay_data.SetRedraw(false)
if (FileExists(fileDir + filename + extension)) then // 先查找本地是否存在文件
	insertRow = dw_mstpay_data.InsertRow(0)
	dw_mstpay_data.Object.filepath[insertRow] = fileDir + filename + extension
else
	parm = FxAppCom.CreatePbDictionary()
	parm.SetString('token', app_token_fx)
	parm.SetString('sn', sn)
//	parm.SetString('exePath', exePath)
	parm.SetString('fileDir', fileDir)
	parm.SetString('filename',filename)
	parm.SetString('extension',extension)
	FXAppCom.GetRpMstpayData(parm, ref arg_msg)
	IF NOT ISNULL(arg_msg) AND Len(arg_msg) > 0 THEN
		rslt = 0
		GOTO ext
	END IF
	// TODO
	insertRow = dw_mstpay_data.InsertRow(0)
	dw_mstpay_data.Object.filepath[insertRow] = fileDir + filename + extension
end if
dw_mstpay_data.SetRedraw(true)


ext:
IF rslt <> 1 AND NOT ISNULL(arg_msg) AND Len(arg_msg) > 0 THEN
	MessageBox('提示','获取对账单图片失败,'+arg_msg)
END IF
return rslt




end function

public function integer wf_delete_local_data (boolean a_ifsilence);// 删除本地超期/被撤回的对账表
// a_ifsilence = true不弹出错误信息

int rslt = 1

datetime ldt_now
ldt_now = datetime(today(), now())

long findRow
findRow = dw_mstpay.Find('', 1, dw_mstpay.RowCount())

// TODO

return rslt

end function

on w_rp_mstpay_fx.create
int iCurrent
call super::create
this.cb_retrieve=create cb_retrieve
this.cb_1=create cb_1
this.st_1=create st_1
this.em_datea=create em_datea
this.st_2=create st_2
this.em_datez=create em_datez
this.dw_mstpay_ff=create dw_mstpay_ff
this.dw_mstpay=create dw_mstpay
this.dw_mstpay_data=create dw_mstpay_data
this.cb_2=create cb_2
this.st_4=create st_4
this.em_heightedit=create em_heightedit
this.cb_read=create cb_read
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cb_retrieve
this.Control[iCurrent+2]=this.cb_1
this.Control[iCurrent+3]=this.st_1
this.Control[iCurrent+4]=this.em_datea
this.Control[iCurrent+5]=this.st_2
this.Control[iCurrent+6]=this.em_datez
this.Control[iCurrent+7]=this.dw_mstpay_ff
this.Control[iCurrent+8]=this.dw_mstpay
this.Control[iCurrent+9]=this.dw_mstpay_data
this.Control[iCurrent+10]=this.cb_2
this.Control[iCurrent+11]=this.st_4
this.Control[iCurrent+12]=this.em_heightedit
this.Control[iCurrent+13]=this.cb_read
end on

on w_rp_mstpay_fx.destroy
call super::destroy
destroy(this.cb_retrieve)
destroy(this.cb_1)
destroy(this.st_1)
destroy(this.em_datea)
destroy(this.st_2)
destroy(this.em_datez)
destroy(this.dw_mstpay_ff)
destroy(this.dw_mstpay)
destroy(this.dw_mstpay_data)
destroy(this.cb_2)
destroy(this.st_4)
destroy(this.em_heightedit)
destroy(this.cb_read)
end on

event open;call super::open;//
//dw_mstpay_dada.InsertRow(0)


string arg_msg // 70-供应商对账表
if (f_find_fx_user_power(70, ref arg_msg) <> 1) then
	MessageBox('权限提示', arg_msg)
	Close(this)
	return
end if

em_datea.Text = String(RelativeDate(Today(), - 120))
em_datez.Text = String(Today())

wf_retrieve()
end event

event resize;call super::resize;if (this.Width < 4100) then this.Width = 4100
if (this.Height < 2600) then this.Height = 2600

dw_mstpay_ff.Width = this.workspacewidth( ) * 0.4
dw_mstpay.X = dw_mstpay_ff.Width + 5
dw_mstpay.Width = this.workspacewidth( ) - dw_mstpay_ff.Width - 10

dw_mstpay_data.Width = this.workspacewidth( )
dw_mstpay_data.Height = this.workspaceheight( ) - dw_mstpay_data.Y

// 按钮靠右
cb_exit.X = this.workspacewidth( ) - cb_exit.Width
end event

type cb_func from w_publ_base_style`cb_func within w_rp_mstpay_fx
boolean visible = false
integer x = 3113
boolean enabled = false
end type

type cb_exit from w_publ_base_style`cb_exit within w_rp_mstpay_fx
integer x = 3607
end type

type ln_bar from w_publ_base_style`ln_bar within w_rp_mstpay_fx
end type

type ln_bar2 from w_publ_base_style`ln_bar2 within w_rp_mstpay_fx
end type

type r_bar from w_publ_base_style`r_bar within w_rp_mstpay_fx
end type

type cb_retrieve from uo_imflatbutton within w_rp_mstpay_fx
integer width = 151
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_retrieve()
end event

type cb_1 from uo_imflatbutton within w_rp_mstpay_fx
boolean visible = false
integer x = 2496
integer width = 151
integer height = 164
integer taborder = 20
boolean bringtotop = true
boolean enabled = false
string text = "打印"
end type

type st_1 from statictext within w_rp_mstpay_fx
integer x = 14
integer y = 204
integer width = 183
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "日期从"
boolean focusrectangle = false
end type

type em_datea from editmask within w_rp_mstpay_fx
integer x = 192
integer y = 188
integer width = 389
integer height = 84
integer taborder = 40
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "0000-00-00"
borderstyle borderstyle = stylelowered!
maskdatatype maskdatatype = datemask!
string mask = "yyyy-mm-dd"
boolean spin = true
end type

type st_2 from statictext within w_rp_mstpay_fx
integer x = 599
integer y = 204
integer width = 87
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "到"
boolean focusrectangle = false
end type

type em_datez from editmask within w_rp_mstpay_fx
integer x = 672
integer y = 188
integer width = 389
integer height = 84
integer taborder = 50
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "0000-00-00"
borderstyle borderstyle = stylelowered!
maskdatatype maskdatatype = datemask!
string mask = "yyyy-mm-dd"
boolean spin = true
end type

type dw_mstpay_ff from datawindow within w_rp_mstpay_fx
integer y = 284
integer width = 1856
integer height = 692
integer taborder = 50
boolean bringtotop = true
string title = "none"
string dataobject = "dw_fieb_rp_mstpay_ff"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type dw_mstpay from u_dw_rbtnfilter within w_rp_mstpay_fx
integer x = 1851
integer y = 284
integer width = 2258
integer height = 692
integer taborder = 20
boolean bringtotop = true
boolean titlebar = true
string title = "对账表列表"
string dataobject = "dw_fieb_rp_mstpay"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean hscrollbar = true
boolean vscrollbar = true
boolean resizable = true
boolean hsplitscroll = true
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
	IF THIS.rowcount() > 0 then
		THIS.SelectRow(0,FALSE)
		THIS.SelectRow(1,TRUE)
		THIS.setrow(1)
		currentrow =1
	end if
end if

if IsNull(currentrow) then
	currentrow = this.GetRow()
	if IsNull(currentrow) then return
end if
if (currentrow <= 0) then return

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

dw_mstpay_ff.Reset( )
this.RowsCopy(currentrow, currentrow, Primary!, dw_mstpay_ff, 1, Primary!)

string arg_msg // 71-供应商对账表确认
if (f_find_fx_user_power(71, ref arg_msg) = 1 and this.Object.unread[currentrow] = 1) then
	cb_read.Enabled = true
else
	cb_read.Enabled = false
end if

wf_retrieve_data(currentrow)


end event

event clicked;call super::clicked;if (row > 0) then
	this.SelectRow(0, false)
	this.SelectRow(row, true)
	THIS.SetRow(row)
end if
end event

type dw_mstpay_data from datawindow within w_rp_mstpay_fx
integer y = 972
integer width = 4105
integer height = 1236
integer taborder = 60
boolean bringtotop = true
string title = "none"
string dataobject = "dw_fieb_rp_mstpay_data"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type cb_2 from commandbutton within w_rp_mstpay_fx
integer x = 1609
integer y = 188
integer width = 247
integer height = 84
integer taborder = 70
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string pointer = "Arrow!"
string text = "调整"
end type

event clicked;//dw_mstpay_dada
//dw_mstpay_dada.Modify("DataWindow.detail.height = 1000")
Long ll_height
ll_height = Long(em_heightedit.Text)
IF ISNULL(ll_height) OR ll_height <= 0 THEN
	RETURN
END IF
 dw_mstpay_data.Modify("pic.height = '" + String(ll_height) + "'")
end event

type st_4 from statictext within w_rp_mstpay_fx
integer x = 1115
integer y = 204
integer width = 265
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "图片高度;"
boolean focusrectangle = false
end type

type em_heightedit from editmask within w_rp_mstpay_fx
integer x = 1376
integer y = 188
integer width = 201
integer height = 84
integer taborder = 90
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "600"
borderstyle borderstyle = stylelowered!
string mask = "######"
end type

type cb_read from uo_imflatbutton within w_rp_mstpay_fx
integer x = 155
integer width = 256
integer height = 164
integer taborder = 70
boolean bringtotop = true
string text = "标记已读"
string normalpicname = "ok.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;long findRow, index = 0
long rows[]
findRow = dw_mstpay.Find('ch = 1', 1, dw_mstpay.RowCount())
if (findRow > 0) then // 多选
	do while findRow > 0
		index++
		rows[index] = findRow
		
		if (findRow >= dw_mstpay.RowCount()) then exit
		findRow = dw_mstpay.Find('ch = 1', findRow + 1, dw_mstpay.RowCount())
	loop
else // 单选
	findRow = dw_mstpay.GetRow()
	if (findRow > 0) then
		if (dw_mstpay.IsSelected(findRow)) then
			index++
			rows[index] = findRow
		end if
	end if
end if

if (index <= 0) then
	MessageBox('提示', '请选中/勾选需要标记已读的项')
	return
end if

string tmp_serialnum
long ll_i
oleobject strList, parm
strList = FXAppCom.NewPBArray()
for ll_i = 1 to UpperBound(rows)
	if (dw_mstpay.Object.unread[rows[ll_i]] = 0) then continue
	
	tmp_serialnum = Trim(dw_mstpay.Object.serialnum[rows[ll_i]])
	
	strList.AddString(tmp_serialnum)
next

string arg_msg
if (strList.Count > 0) then
	parm = FxAppCom.CreatePbDictionary()
	parm.SetString('token', app_token_fx)
	parm.SetObject('list', strList)
	FxAppCom.ReadRpMstpay(parm, ref arg_msg)
	if (arg_msg <> '') then
		MessageBox('提示', arg_msg)
	end if
end if

cb_retrieve.post event clicked()


end event

