$PBExportHeader$uo_v2_dw_filter.sru
forward
global type uo_v2_dw_filter from userobject
end type
type dw_2 from datawindow within uo_v2_dw_filter
end type
type pb_2 from uo_v2_button within uo_v2_dw_filter
end type
type pb_1 from uo_v2_button within uo_v2_dw_filter
end type
type shl_3 from uo_v2_sthl within uo_v2_dw_filter
end type
type shl_2 from uo_v2_sthl within uo_v2_dw_filter
end type
type shl_1 from uo_v2_sthl within uo_v2_dw_filter
end type
type cbx_1 from uo_v2_ckb within uo_v2_dw_filter
end type
type sle_1 from uo_v2_sle within uo_v2_dw_filter
end type
type gb_1 from groupbox within uo_v2_dw_filter
end type
end forward

global type uo_v2_dw_filter from userobject
integer width = 1339
integer height = 1212
long backcolor = 134217739
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
event ue_close ( )
dw_2 dw_2
pb_2 pb_2
pb_1 pb_1
shl_3 shl_3
shl_2 shl_2
shl_1 shl_1
cbx_1 cbx_1
sle_1 sle_1
gb_1 gb_1
end type
global uo_v2_dw_filter uo_v2_dw_filter

type variables
datawindow dw_1 // 操作的DW
string ins_colname // 操作的
long ins_row // 操作的行; 0-代表操作的是标题

private:
string coltype
uo_string lo_str
end variables

forward prototypes
public subroutine uof_set_dw_col (datawindow arg_dw, string arg_colname, long arg_row)
private subroutine pf_face ()
private function string pf_getfilter_str ()
end prototypes

event ue_close();// 关闭窗口
end event

public subroutine uof_set_dw_col (datawindow arg_dw, string arg_colname, long arg_row);// 初始化当前操作的DW/列/行

dw_1 = arg_dw
ins_colname = arg_colname
ins_row = arg_row

// 1. 统计dw_1 列ins_colname的选项

coltype = Lower(dw_1.Describe(ins_colname + ".ColType"))

Long i, row
String ls_value, ls_findstr
FOR i = 1 To dw_1.RowCount()
	ls_value = lo_str.uof_getitemformattedstring(dw_1, i, ins_colname)
	
	ls_findstr = ls_value
	ls_findstr = lo_str.uof_replace(ls_findstr, "'", "~~~'")
	
	ls_findstr = "itemvalue = '"+ls_findstr+"'"
	
	row = dw_2.Find(ls_findstr, 1, dw_2.RowCount())
	IF row <= 0 THEN
		row = dw_2.InsertRow(0)
		dw_2.Object.itemvalue[row] = ls_value
	END IF
	dw_2.Object.itemcnt[row] = dw_2.Object.itemcnt[row] + 1
NEXT
dw_2.Sort()


IF ins_row > 0 THEN
	ls_value = lo_str.uof_getitemformattedstring(dw_1, ins_row, ins_colname)
	sle_1.Text = ls_value
	sle_1.TriggerEvent('modified')
END IF

IF sle_1.Text <> '' THEN
	sle_1.SelectText(1, Len(sle_1.Text))
END IF
sle_1.SetFocus()
end subroutine

private subroutine pf_face ();long row

row = dw_2.Find("ch = 1", 1 , dw_2.RowCount())

pb_1.Enabled = (row > 0)
pb_2.Enabled = (row > 0)
end subroutine

private function string pf_getfilter_str ();string ls_filter
string ls_itemvalue
Long i
ls_filter = ''

FOR i = 1 To dw_2.RowCount()
	IF dw_2.Object.ch[i] <> 1 THEN CONTINUE
	
	ls_itemvalue = dw_2.Object.itemvalue[i]
	IF ls_itemvalue = "(空白)" THEN ls_itemvalue = ''
	ls_itemvalue = "'"+lo_str.uof_replace(ls_itemvalue, "'", "~~~'")+"'"
	ls_filter += ","+ls_itemvalue
NEXT

IF ls_filter = '' THEN
	ls_filter += ",''"
END IF
ls_filter = "LookUpDisplay(" + ins_colname + ") IN (" + Mid(ls_filter, 2) + ")"

return ls_filter
end function

on uo_v2_dw_filter.create
this.dw_2=create dw_2
this.pb_2=create pb_2
this.pb_1=create pb_1
this.shl_3=create shl_3
this.shl_2=create shl_2
this.shl_1=create shl_1
this.cbx_1=create cbx_1
this.sle_1=create sle_1
this.gb_1=create gb_1
this.Control[]={this.dw_2,&
this.pb_2,&
this.pb_1,&
this.shl_3,&
this.shl_2,&
this.shl_1,&
this.cbx_1,&
this.sle_1,&
this.gb_1}
end on

on uo_v2_dw_filter.destroy
destroy(this.dw_2)
destroy(this.pb_2)
destroy(this.pb_1)
destroy(this.shl_3)
destroy(this.shl_2)
destroy(this.shl_1)
destroy(this.cbx_1)
destroy(this.sle_1)
destroy(this.gb_1)
end on

event destructor;destroy lo_str
end event

event constructor;lo_str = create uo_string
end event

type dw_2 from datawindow within uo_v2_dw_filter
integer x = 37
integer y = 244
integer width = 1262
integer height = 788
integer taborder = 30
string title = "none"
string dataobject = "dw_v2_filter_ctrl_base"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event itemchanged;post pf_face()
end event

type pb_2 from uo_v2_button within uo_v2_dw_filter
integer x = 987
integer y = 1044
integer width = 311
integer taborder = 50
string text = "定位"
end type

event clicked;call super::clicked;String ls_filter

ls_filter = pf_getfilter_str()

Long ll_row, ll_next
ll_row = dw_1.GetRow()
ll_next = 0

IF ll_row <= 0 THEN
	ll_next = dw_1.Find(ls_filter, 1, dw_1.RowCount())
	GOTO ext
END IF

ll_next = dw_1.Find(ls_filter, ll_row, dw_1.RowCount())
IF ll_next <= 0 Or ll_row = dw_1.RowCount() THEN
	ll_next = dw_1.Find(ls_filter, 1, ll_row)
	GOTO ext
END IF

IF ll_next = ll_row THEN
	ll_next = dw_1.Find(ls_filter, ll_row + 1, dw_1.RowCount())
	IF ll_next <= 0 THEN
		ll_next = dw_1.Find(ls_filter, 1, ll_row)
	END IF
END IF

ext:
IF ll_next > 0 THEN
	dw_1.ScrollToRow(ll_next)
END IF

Parent.Trigger Event ue_close()



end event

type pb_1 from uo_v2_button within uo_v2_dw_filter
integer x = 37
integer y = 1044
integer width = 498
integer taborder = 40
end type

event clicked;call super::clicked;String ls_filter

ls_filter = pf_getfilter_str()

lo_str.uof_dw_append_filter(dw_1, ref ls_filter)
dw_1.Filter()

u_dw_rbtnfilter ldw // 同dw_1，如果类型兼容就有值
try 
	ldw = dw_1
catch ( Throwable ex )
	/*statementBlock*/
end try
IF IsValid(ldw) THEN ldw.curdw_filterstr = ls_filter

Parent.Trigger Event ue_close()

end event

type shl_3 from uo_v2_sthl within uo_v2_dw_filter
boolean visible = false
integer x = 1038
integer y = 172
integer width = 261
integer height = 56
string text = "查询方案>"
end type

event clicked;call super::clicked;// TODO: 列出方案菜单及保存

String menustr
menustr = ''
string ls_dwname, ls_stylename, ls_parm
long ll_empid, ll_ifshare
ls_dwname = dw_1.DataObject

DECLARE cur1 cursor FOR
SELECT empid,
	stylename,
	ifshare
	FROM u_user_report_style
 where (dwname = :ls_dwname)
 and (empid = :sys_empid or ifshare = 1 or :sys_empid = 0  )
 ORDER BY ifshare, stylename;

OPEN CUR1;

FETCH CUR1 INTO :ll_empid, :ls_stylename, :ll_ifshare;
DO WHILE sqlca.sqlcode = 0
	
	ls_parm = string(ll_empid)+":"+ls_stylename
	IF ll_ifshare = 1 THEN ls_stylename += "*"
	
	IF menustr <> "" THEN menustr += "|"
	menustr +=  "Text="+ls_stylename+"~tEvent=ue_report_style~tParm="+ls_parm
	
	FETCH CUR1 INTO :ll_empid, :ls_stylename, :ll_ifshare;
LOOP
CLOSE cur1;


IF menustr <> "" THEN menustr += "|"
menustr +=  "Text=保存~tEvent=ue_save_style"

If Len(Trim(menustr)) <> 0 Then
	m_Dfc_Control_PopupMenu dmPopupMenu
	dmPopupMenu = Create m_Dfc_Control_PopupMenu
	dmPopupMenu.mf_BuildMenu(This, menustr)
//	IF IsValid(ins_parentwindow) THEN
//		dmPopupMenu.mf_PopMenu(ins_parentwindow)
//	ELSE
		dmPopupMenu.mf_PopMenu()
//	END IF
	Destroy dmPopupMenu
End If
end event

type shl_2 from uo_v2_sthl within uo_v2_dw_filter
integer x = 713
integer y = 172
integer width = 233
integer height = 56
string text = "清空条件"
end type

event clicked;call super::clicked;dw_1.SetFilter('')
dw_1.Filter()

u_dw_rbtnfilter ldw // 同dw_1，如果类型兼容就有值
try 
	ldw = dw_1
catch ( Throwable ex )
	/*statementBlock*/
end try
IF IsValid(ldw) THEN ldw.curdw_filterstr = ''

parent.trigger event ue_close()
end event

type shl_1 from uo_v2_sthl within uo_v2_dw_filter
integer x = 242
integer y = 172
integer width = 123
integer height = 56
string text = "反选"
end type

event clicked;call super::clicked;long i

for i = 1 to dw_2.RowCount()
	dw_2.Object.ch[i] = 1 - dw_2.Object.ch[i]
next

pf_face()
end event

type cbx_1 from uo_v2_ckb within uo_v2_dw_filter
integer x = 32
integer y = 160
boolean checked = true
end type

event clicked;call super::clicked;long ll_check

if this.checked then
	ll_check = 1
else
	ll_check = 0
end if

long i

for i = 1 to dw_2.RowCount()
	dw_2.Object.ch[i] = ll_check
next

pf_face()
end event

type sle_1 from uo_v2_sle within uo_v2_dw_filter
integer x = 37
integer y = 68
integer width = 1262
integer taborder = 20
end type

event ue_textchanged;call super::ue_textchanged;string ls_filter
ls_filter = this.text

if ls_filter = '' then
	dw_2.SetFilter('')
	goto ext
end if

ls_filter = lo_str.uof_replace(ls_filter, "'", "~~~'")

ls_filter = "itemvalue like '%"+ls_filter+"%'"
dw_2.SetFilter(ls_filter)

ext:
dw_2.Filter()
pf_face()
end event

type gb_1 from groupbox within uo_v2_dw_filter
integer x = 5
integer width = 1326
integer height = 1200
integer taborder = 10
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 16711680
long backcolor = 134217739
string text = "文本筛选"
end type

