$PBExportHeader$w_mtrl_ch_by_comid_fx.srw
$PBExportComments$根据企业ID获取其物料
forward
global type w_mtrl_ch_by_comid_fx from w_publ_base
end type
type tv_1 from uo_tv_fx_mtrltype within w_mtrl_ch_by_comid_fx
end type
type dw_show from u_dw_rbtnfilter within w_mtrl_ch_by_comid_fx
end type
type dw_select from u_dw_rbtnfilter within w_mtrl_ch_by_comid_fx
end type
type cb_select from uo_imflatbutton within w_mtrl_ch_by_comid_fx
end type
type cb_del from uo_imflatbutton within w_mtrl_ch_by_comid_fx
end type
type cb_ok from uo_imflatbutton within w_mtrl_ch_by_comid_fx
end type
type cb_select_all from uo_imflatbutton within w_mtrl_ch_by_comid_fx
end type
type r_1 from rectangle within w_mtrl_ch_by_comid_fx
end type
end forward

global type w_mtrl_ch_by_comid_fx from w_publ_base
integer width = 4686
integer height = 2300
string title = "物料选择"
boolean minbox = false
windowtype windowtype = response!
long backcolor = 16777215
string icon = "graphics\chain_link_128px.ico"
boolean center = true
tv_1 tv_1
dw_show dw_show
dw_select dw_select
cb_select cb_select
cb_del cb_del
cb_ok cb_ok
cb_select_all cb_select_all
r_1 r_1
end type
global w_mtrl_ch_by_comid_fx w_mtrl_ch_by_comid_fx

type variables
long ins_comid

s_fx_mtrldef ins_ret, ins_parm

datastore ins_mtrltypes
end variables

forward prototypes
public subroutine wf_retrieve ()
public subroutine wf_retrieve_mtrltype (readonly oleobject arg_mtrltypes)
public subroutine wf_retrieve_mtrl (readonly long arg_mtrltypeid, readonly long arg_sonflag)
end prototypes

public subroutine wf_retrieve ();string arg_msg
oleobject obj, parm, list
parm = FXAppCom.CreatePbDictionary()
parm.SetString('token', app_token_fx)
parm.SetInt('comid', ins_parm.partner_comid)
obj = FXAppCom.GetMtrltypeByComid(parm, ref arg_msg)
IF (arg_msg <> '') THEN
	MessageBox('提示', '获取物料类别失败:' + arg_msg)
	RETURN
END IF

list = obj.GetPBArray('list')
dw_show.ReSet( )
wf_retrieve_mtrltype(list)
end subroutine

public subroutine wf_retrieve_mtrltype (readonly oleobject arg_mtrltypes);long i, cnt, row
cnt = arg_mtrltypes.Count

if cnt <= 0 then return

//datastore ds
//ds = create datastore
//ds.DataObject = 'ds_fx_mtrltype'

ins_mtrltypes.Reset()

oleobject mtrltype
for i = 1 to cnt
	mtrltype = arg_mtrltypes.GetPBDictionary(i - 1)
	
	row = ins_mtrltypes.InsertRow(0)
	ins_mtrltypes.Object.comid[row] = mtrltype.GetInt('comid')
	ins_mtrltypes.Object.mtrltypeid[row] = mtrltype.GetInt('mtrltypeid')
	ins_mtrltypes.Object.mtrltype[row] = mtrltype.GetString('mtrltype')
	ins_mtrltypes.Object.handtype[row] = mtrltype.GetString('handtype')
	ins_mtrltypes.Object.sonflag[row] = mtrltype.GetInt('sonflag')
	ins_mtrltypes.Object.parentid[row] = mtrltype.GetInt('parentid')
	ins_mtrltypes.Object.mtrltypeid_erp[row] = mtrltype.GetInt('mtrltypeid_erp')
next

tv_1.uof_init(ins_mtrltypes)

//destroy ds
end subroutine

public subroutine wf_retrieve_mtrl (readonly long arg_mtrltypeid, readonly long arg_sonflag);string arg_msg
oleobject mtrls, mtrl, parm, obj
parm = FXAppCom.CreatePbDictionary()
parm.SetString('token', app_token_fx)
parm.SetInt('mtrltypeid', arg_mtrltypeid)
parm.SetInt('sonflag', arg_sonflag)
parm.SetInt('pagesize', 0)
parm.SetInt('pagenum', 0)
parm.SetString('likeStr', '')
if (ins_parm.myreltype = 1) then // 我是供应商
	parm.SetInt('cusComid', ins_parm.partner_comid)
	parm.SetInt('sptComid', 0)
elseif (ins_parm.myreltype = 2) then // 我是客户
	parm.SetInt('cusComid', 0)
	parm.SetInt('sptComid', ins_parm.partner_comid)
else
	parm.SetInt('cusComid', 0)
	parm.SetInt('sptComid', 0)
end if
obj = FXAppCom.GetMtrlWithRelationFilter(parm, ref arg_msg)
if (arg_msg <> '') then
	MessageBox('提示', arg_msg)
	return
end if

long i, cnt, row
mtrls = obj.GetPBArray('list')
cnt = mtrls.Count

dw_show.Reset( )
dw_show.SetRedraw(false)
for i = 1 to cnt
	mtrl = mtrls.GetPBDictionary(i - 1)
	row = dw_show.InsertRow(0)
	
	dw_show.Object.fxmtrlid[row] = mtrl.GetInt('fxmtrlid')
	dw_show.Object.comid[row] = mtrl.GetInt('comid')
	dw_show.Object.mtrlid[row] = mtrl.GetInt('mtrlid')
	dw_show.Object.mtrlcode[row] = mtrl.GetString('mtrlcode')
	dw_show.Object.mtrlname[row] = mtrl.GetString('mtrlname')
	dw_show.Object.mtrlmode[row] = mtrl.GetString('mtrlmode')
	dw_show.Object.mtrlsectype[row] = mtrl.GetString('mtrlsectype')
	dw_show.Object.zxmtrlmode[row] = mtrl.GetString('zxmtrlmode')
	dw_show.Object.usermtrlmode[row] = mtrl.GetString('usermtrlmode')
	dw_show.Object.statusflag[row] = mtrl.GetInt('statusflag')
	dw_show.Object.statustype[row] = mtrl.GetInt('statustype')
	dw_show.Object.woodcodeflag[row] = mtrl.GetInt('woodcodeflag')
	dw_show.Object.woodcodetype[row] = mtrl.GetInt('woodcodetype')
	dw_show.Object.pcodeflag[row] = mtrl.GetInt('pcodeflag')
	dw_show.Object.pcodetype[row] = mtrl.GetInt('pcodetype')
	dw_show.Object.configcodetype[row] = mtrl.GetInt('configcodetype')
	dw_show.Object.unit[row] = mtrl.GetString('unit')
next
dw_show.AcceptText()
dw_show.SetRedraw(true)

dw_show.SelectRow(0, false)


end subroutine

on w_mtrl_ch_by_comid_fx.create
int iCurrent
call super::create
this.tv_1=create tv_1
this.dw_show=create dw_show
this.dw_select=create dw_select
this.cb_select=create cb_select
this.cb_del=create cb_del
this.cb_ok=create cb_ok
this.cb_select_all=create cb_select_all
this.r_1=create r_1
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.tv_1
this.Control[iCurrent+2]=this.dw_show
this.Control[iCurrent+3]=this.dw_select
this.Control[iCurrent+4]=this.cb_select
this.Control[iCurrent+5]=this.cb_del
this.Control[iCurrent+6]=this.cb_ok
this.Control[iCurrent+7]=this.cb_select_all
this.Control[iCurrent+8]=this.r_1
end on

on w_mtrl_ch_by_comid_fx.destroy
call super::destroy
destroy(this.tv_1)
destroy(this.dw_show)
destroy(this.dw_select)
destroy(this.cb_select)
destroy(this.cb_del)
destroy(this.cb_ok)
destroy(this.cb_select_all)
destroy(this.r_1)
end on

event open;call super::open;ins_parm = Message.PowerObjectParm

ins_ret.ifselect = false

ins_mtrltypes = create datastore
ins_mtrltypes.DataObject = 'ds_fx_mtrltype'

if IsNull(ins_parm) then
	MessageBox('提示', '打开方式有误')
	Close(this)
	return
end if
if (not IsValid(ins_parm)) then
	MessageBox('提示', '打开方式有误')
	Close(this)
	return
end if
if (ins_parm.partner_comid <= 0) then
	MessageBox('提示', '打开参数有误')
	Close(this)
	return
end if

if (ins_parm.myreltype <> 0) then
	this.Title += '-(业务来往物料)'
end if

wf_retrieve( )
end event

event close;call super::close;destroy ins_mtrltypes

CloseWithReturn(this, ins_ret)
end event

event resize;call super::resize;cb_exit.X = this.workspacewidth( ) - cb_exit.Width
end event

type cb_func from w_publ_base`cb_func within w_mtrl_ch_by_comid_fx
integer width = 151
integer height = 164
string normalpicname = "setting.BMP"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

type cb_exit from w_publ_base`cb_exit within w_mtrl_ch_by_comid_fx
integer x = 3040
integer width = 151
integer height = 164
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

type tv_1 from uo_tv_fx_mtrltype within w_mtrl_ch_by_comid_fx
integer y = 176
integer width = 1015
integer height = 2052
integer taborder = 30
boolean bringtotop = true
integer textsize = -9
fontcharset fontcharset = gb2312charset!
fontfamily fontfamily = anyfont!
string facename = "宋体"
boolean disabledragdrop = false
boolean hideselection = false
boolean tooltips = false
boolean trackselect = true
string picturename[] = {"Application!","Structure5!"}
end type

event selectionchanged;call super::selectionchanged;wf_retrieve_mtrl(this.ins_cur_info.mtrltypeid[1], this.ins_cur_info.sonflag[1])
end event

type dw_show from u_dw_rbtnfilter within w_mtrl_ch_by_comid_fx
integer x = 1029
integer y = 176
integer width = 3648
integer height = 976
integer taborder = 20
boolean bringtotop = true
string dataobject = "dw_fx_mtrldef"
boolean hscrollbar = true
boolean vscrollbar = true
boolean rbutton_filter_use = true
boolean rbutton_setposition_use = true
boolean titleclick_sort_use = true
end type

event clicked;call super::clicked;if (row <= 0) then return

This.SelectRow(row, not This.IsSelected(row))
end event

event doubleclicked;call super::doubleclicked;cb_select.post event clicked()
end event

type dw_select from u_dw_rbtnfilter within w_mtrl_ch_by_comid_fx
integer x = 1029
integer y = 1260
integer width = 3657
integer height = 964
integer taborder = 20
boolean bringtotop = true
string dataobject = "dw_fx_mtrldef"
boolean hscrollbar = true
boolean vscrollbar = true
boolean rbutton_filter_use = true
boolean rbutton_setposition_use = true
boolean titleclick_sort_use = true
end type

event clicked;call super::clicked;if (row <= 0) then return

This.SelectRow(0, false)
This.SelectRow(row, true)
end event

event rowfocuschanged;call super::rowfocuschanged;IF currentrow <=0 THEN RETURN
this.selectrow(0,false)
this.selectrow(currentrow,true)
this.SetRow(currentrow)
end event

type cb_select from uo_imflatbutton within w_mtrl_ch_by_comid_fx
integer x = 3433
integer y = 1156
integer width = 608
integer height = 92
integer taborder = 30
boolean bringtotop = true
string text = "↓ 选择"
end type

event clicked;call super::clicked;long row
row = dw_show.GetRow( )
if (row <= 0) then
	MessageBox('提示', '请在上方的物料清单内选择')
	return
end if

dw_select.SetRedraw(false)
long i, findRow
for i = 1 to dw_show.RowCount( )
	if (dw_show.IsSelected(i)) then
		findRow = dw_select.Find('fxmtrlid = ' + string(dw_show.Object.fxmtrlid[i]), 1, dw_select.RowCount())
		if (findRow <= 0) then
			dw_show.RowsCopy(i, i, Primary!, dw_select, dw_select.RowCount() + 1, Primary!)
		end if
	end if
next
dw_select.SetRedraw(true)

//dw_show.SelectRow(0, false)
//dw_show.SetRow(0)

if (dw_select.RowCount( ) > 0) then
	dw_select.SelectRow(0, false)
	dw_select.SelectRow(dw_select.RowCount( ), true)
	dw_select.SetRow(dw_select.RowCount( ))
end if
end event

type cb_del from uo_imflatbutton within w_mtrl_ch_by_comid_fx
integer x = 4059
integer y = 1156
integer width = 608
integer height = 92
integer taborder = 40
boolean bringtotop = true
string text = "↑删除"
end type

event clicked;call super::clicked;if (dw_select.GetRow() <= 0) then
	MessageBox('提示', '请在下方的物料清单内选择')
	return
end if

dw_select.DeleteRow(dw_select.GetRow())
dw_show.TriggerEvent(rowfocuschanged!)
end event

type cb_ok from uo_imflatbutton within w_mtrl_ch_by_comid_fx
integer x = 1029
integer width = 165
integer height = 164
integer taborder = 20
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;if (dw_select.RowCount() <= 0) then
	MessageBox('提示', '右下角的清单内并没有内容')
	return
end if

long i
for i = 1 to dw_select.RowCount()
	ins_ret.fxmtrlid[i] = dw_select.Object.fxmtrlid[i]
	ins_ret.comid[i] = dw_select.Object.comid[i]
	ins_ret.mtrlid[i] = dw_select.Object.mtrlid[i]
	ins_ret.mtrlcode[i] = dw_select.Object.mtrlcode[i]
	ins_ret.mtrlname[i] = dw_select.Object.mtrlname[i]
	ins_ret.mtrlmode[i] = dw_select.Object.mtrlmode[i]
	ins_ret.mtrlsectype[i] = dw_select.Object.mtrlsectype[i]
	ins_ret.zxmtrlmode[i] = dw_select.Object.zxmtrlmode[i]
	ins_ret.usermtrlmode[i] = dw_select.Object.usermtrlmode[i]
	ins_ret.statusflag[i] = dw_select.Object.statusflag[i]
	ins_ret.statustype[i] = dw_select.Object.statustype[i]
	ins_ret.woodcodeflag[i] = dw_select.Object.woodcodeflag[i]
	ins_ret.woodcodetype[i] = dw_select.Object.woodcodetype[i]
	ins_ret.pcodeflag[i] = dw_select.Object.pcodeflag[i]
	ins_ret.pcodetype[i] = dw_select.Object.pcodetype[i]
	ins_ret.configcodetype[i] = dw_select.Object.configcodetype[i]
	ins_ret.unit[i] = dw_select.Object.unit[i]
next
ins_ret.ifselect = true

CloseWithReturn(parent, ins_ret)
end event

type cb_select_all from uo_imflatbutton within w_mtrl_ch_by_comid_fx
integer x = 2807
integer y = 1156
integer width = 608
integer height = 92
integer taborder = 40
boolean bringtotop = true
string text = "↓ 全选"
end type

event clicked;call super::clicked;dw_show.SelectRow(0, true)
cb_select.post event clicked()
end event

type r_1 from rectangle within w_mtrl_ch_by_comid_fx
long linecolor = 16777215
integer linethickness = 4
long fillcolor = 1073741824
integer x = 1737
integer y = 16
integer width = 105
integer height = 68
end type

event constructor;this.fillcolor = 14215660
this.linecolor = 14215660
this.x = -1
this.y = -1
this.height = dw_show.Y - 5
this.Width = parent.workspacewidth( )
end event

