$PBExportHeader$uo_tv_cusarea.sru
forward
global type uo_tv_cusarea from treeview
end type
end forward

global type uo_tv_cusarea 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 backcolor = 16777215
borderstyle borderstyle = stylelowered!
boolean hideselection = false
string picturename[] = {"Application!","LibraryList5!"}
long picturemaskcolor = 553648127
long statepicturemaskcolor = 536870912
end type
global uo_tv_cusarea uo_tv_cusarea

type variables
Long uo_deep = 0
s_cusarea uo_cur_info
datastore ds_area



end variables

forward prototypes
public function integer pf_treegrowth (long arg_handl, long arg_parentid)
public function integer f_maketree ()
public function integer f_getinfo (long arg_cusareaid)
end prototypes

public function integer pf_treegrowth (long arg_handl, long arg_parentid);Int rslt = 1

Long  ll_CusareaID,ll_count = 0,ll_i
String ls_Cusareaname,ls_areaname
Int li_sonflag

s_cusarea l_s_pfmx[]

Long li_handl
TreeViewItem l_tvi

uo_deep++

IF uo_deep > 10000 THEN //防止死递归
	RETURN 0
END IF

DECLARE pf_cur CURSOR FOR
	SELECT u_Cusarea.CusareaID,
	u_Cusarea.Cusareaname,
	u_Cusarea.areaname,
	u_Cusarea.sonflag
	FROM u_Cusarea
	Where ( u_Cusarea.parentid = :arg_parentid );
OPEN pf_cur;
ll_count = 1
FETCH pf_cur INTO :l_s_pfmx[ll_count].CusareaID,:l_s_pfmx[ll_count].Cusareaname,&
	:l_s_pfmx[ll_count].areaname,:l_s_pfmx[ll_count].sonflag;
	
DO WHILE sqlca.SQLCode = 0
	ll_count++
	FETCH pf_cur INTO :l_s_pfmx[ll_count].CusareaID,:l_s_pfmx[ll_count].Cusareaname,&
		:l_s_pfmx[ll_count].areaname,:l_s_pfmx[ll_count].sonflag;
LOOP
ll_count = ll_count - 1
CLOSE pf_cur;
//

// //yyx 2011-2-15
//ds_area.Retrieve(arg_parentid,sys_areaid)
//ds_area.AcceptText()
//FOR ll_i = 1 TO ds_area.rowcount()
//	ll_count++
//	l_s_pfmx[ll_count].CusareaID = ds_area.Object.CusareaID[ll_i]
//	l_s_pfmx[ll_count].Cusareaname = ds_area.Object.Cusareaname[ll_i]
//	l_s_pfmx[ll_count].areaname = ds_area.Object.areaname[ll_i]
//	l_s_pfmx[ll_count].sonflag = ds_area.Object.sonflag[ll_i]
//NEXT
////


FOR ll_i = 1 To ll_count
	IF Not (sys_power_issuper Or sys_areastr = '0') THEN
		IF Pos(sys_areastr,','+String(l_s_pfmx[ll_i].CusareaID)+',') = 0 THEN CONTINUE
	END IF
	
	li_handl = This.InsertItemSort(arg_handl,l_s_pfmx[ll_i].Cusareaname,2)
	
	IF This.GetItem ( li_handl, l_tvi) = 1 THEN
		l_tvi.Label = l_s_pfmx[ll_i].Cusareaname
		l_tvi.Data  = l_s_pfmx[ll_i].CusareaID
		This.SetItem( li_handl, l_tvi )
	END IF
	
	pf_treegrowth(li_handl,l_s_pfmx[ll_i].CusareaID)
NEXT

RETURN 1





end function

public function integer f_maketree ();//wf_maketree()
Long ll_hand
uo_deep = 1

Long tvi_hdl = 0

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

ll_hand = This.InsertItemLast(0,'全部地区',1)

pf_treegrowth(ll_hand,0)

This.ExpandItem(ll_hand)
This.SetRedraw(True)
RETURN 0

end function

public function integer f_getinfo (long arg_cusareaid);Int rslt = 1
SELECT Cusareaid,
	Cusareaname,
	areaname,
	sonflag,
	parentid
	INTO :uo_cur_info.Cusareaid,
	:uo_cur_info.Cusareaname,
	:uo_cur_info.areaname,
	:uo_cur_info.sonflag,
	:uo_cur_info.parentid
	FROM u_Cusarea
	Where Cusareaid = :arg_Cusareaid;
	
IF sqlca.SQLCode <> 0 THEN
	uo_cur_info.Cusareaid = 0
	uo_cur_info.Cusareaname = ''
	uo_cur_info.areaname = ''
	uo_cur_info.sonflag = 0
	uo_cur_info.parentid = 0
	uo_cur_info.parenthandtype = ''
	rslt = 0
	GOTO ext
END IF

String ls_parenthandtype
Long ll_parentid

ll_parentid = uo_cur_info.parentid

IF uo_cur_info.parentid = 0 THEN
	uo_cur_info.parenthandtype = ''
ELSE
	SELECT areaname
		INTO :ls_parenthandtype
		FROM u_Cusarea
		Where Cusareaid = :ll_parentid;
	IF sqlca.SQLCode <> 0 THEN
		uo_cur_info.parenthandtype = ''
	ELSE
		uo_cur_info.parenthandtype = ls_parenthandtype
	END IF
END IF

ext:

RETURN rslt


end function

on uo_tv_cusarea.create
end on

on uo_tv_cusarea.destroy
end on

event constructor;ds_area = CREATE datastore
ds_area.DataObject = 'ds_uo_tv_cusarea'
ds_area.SetTransObject(sqlca)
f_maketree()

end event

event selectionchanged;Long ll_hand
Long ll_cusareaid
TreeViewItem l_tvi
ll_hand = THIS.FindItem(CurrentTreeItem!,0)

IF THIS.GetItem(ll_hand,l_tvi) = 1 THEN
	IF ll_hand = 1 THEN
		ll_cusareaid = 0
	ELSE
		ll_cusareaid = l_tvi.Data
	END IF
	f_getinfo(ll_cusareaid)
	THIS.ExpandItem(ll_hand)
END IF



end event

event destructor;DESTROY ds_area

end event

