$PBExportHeader$uo_tv_fx_mtrltype.sru
$PBExportComments$分销系统物料类别的treeview
forward
global type uo_tv_fx_mtrltype from treeview
end type
end forward

global type uo_tv_fx_mtrltype from treeview
integer width = 549
integer height = 452
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
long picturemaskcolor = 536870912
long statepicturemaskcolor = 536870912
end type
global uo_tv_fx_mtrltype uo_tv_fx_mtrltype

type variables
datastore ins_ds

// 用于记录当前选中的物料类别信息，只使用数组第一位
s_fx_mtrltype ins_cur_info
end variables

forward prototypes
public subroutine uof_init (readonly datastore arg_ds)
public subroutine uof_treegrowth (long arg_handl, long arg_parentid)
end prototypes

public subroutine uof_init (readonly datastore arg_ds);if arg_ds.DataObject <> 'ds_fx_mtrltype' then
	MessageBox('提示', '使用的arg_ds参数有误')
	return
end if

ins_ds = arg_ds

this.SetRedraw(false)

DO UNTIL This.FindItem(RootTreeItem!, 0) = -1
	This.DeleteItem(0)
LOOP

long ll_hand
ll_hand = This.InsertItemLast(0,'全部类别',1)
uof_treegrowth(ll_hand, 0)
This.ExpandItem(ll_hand)

this.SetRedraw(true)
end subroutine

public subroutine uof_treegrowth (long arg_handl, long arg_parentid);Long ll_mtrltypeid, ll_count = 0, ll_i
String ls_mtrltype, ls_handtype
long li_sonflag

s_fx_mtrltype s_type

Long li_handl
TreeViewItem l_tvi

Long ll_row
ll_row = ins_ds.Find("parentid = " + String(arg_parentid), 1, ins_ds.RowCount())

ll_count = 0
DO WHILE ll_row > 0
	ll_count++
	s_type.mtrltypeid[ll_count] = ins_ds.Object.mtrltypeid[ll_row]
	s_type.mtrltype[ll_count]  = ins_ds.Object.mtrltype[ll_row]
	s_type.handtype[ll_count] = ins_ds.Object.handtype[ll_row]
	s_type.sonflag[ll_count] = ins_ds.Object.sonflag[ll_row]
	s_type.parentid[ll_count] = ins_ds.Object.parentid[ll_row]
	s_type.mtrltypeid_erp[ll_count] = ins_ds.Object.mtrltypeid_erp[ll_row]
	
	IF ll_row >= ins_ds.RowCount() THEN EXIT
	ll_row = ins_ds.Find("parentid = " + String(arg_parentid), ll_row + 1, ins_ds.RowCount())
LOOP

FOR ll_i = 1 To ll_count
	li_handl = This.InsertItemSort(arg_handl, s_type.mtrltype[ll_i], 2)
	
	ll_row = ins_ds.Find("parentid = " + String(s_type.mtrltypeid[ll_i]), 1, ins_ds.RowCount())
	
	IF This.GetItem(li_handl, l_tvi) = 1 THEN
		l_tvi.Label = s_type.mtrltype[ll_i]
		l_tvi.Data  = s_type.mtrltypeid[ll_i]
		IF ll_row > 0 THEN
			l_tvi.Children = True
		END IF
		This.SetItem(li_handl, l_tvi)
	END IF
	
	uof_treegrowth(li_handl, s_type.mtrltypeid[ll_i])
NEXT
end subroutine

on uo_tv_fx_mtrltype.create
end on

on uo_tv_fx_mtrltype.destroy
end on

event selectionchanged;Long ll_mtrltypeid
TreeViewItem l_tvi

IF This.GetItem(NewHandle, l_tvi) = 1 THEN
	IF NewHandle = 1 THEN
		ll_mtrltypeid = 0
	ELSE
		ll_mtrltypeid = l_tvi.Data
	END IF
	
	Long ll_row
	ll_row = ins_ds.Find("mtrltypeid = " + String(ll_mtrltypeid), 1, ins_ds.RowCount())
	
	IF ll_row > 0 THEN
		ins_cur_info.mtrltypeid[1] = ins_ds.Object.mtrltypeid[ll_row]
		ins_cur_info.mtrltype[1] = ins_ds.Object.mtrltype[ll_row]
		ins_cur_info.handtype[1] = ins_ds.Object.handtype[ll_row]
		ins_cur_info.sonflag[1] = ins_ds.Object.sonflag[ll_row]
		ins_cur_info.parentid[1] = ins_ds.Object.parentid[ll_row]
		ins_cur_info.mtrltypeid_erp[1] = ins_ds.Object.mtrltypeid_erp[ll_row]
	ELSE
		ins_cur_info.mtrltypeid[1] = 0
		ins_cur_info.mtrltype[1] = ''
		ins_cur_info.handtype[1] = ''
		ins_cur_info.sonflag[1] = 0
		ins_cur_info.parentid[1] = 0
		ins_cur_info.mtrltypeid_erp[1] = 0
	END IF

END IF
end event

