$PBExportHeader$w_publ_pageretr.srw
$PBExportComments$翻页窗口
forward
global type w_publ_pageretr from w_publ_base
end type
type sle_usual_query from u_sleedit within w_publ_pageretr
end type
type cb_retrieveall from uo_imflatbutton within w_publ_pageretr
end type
type em_pagerowno from editmask within w_publ_pageretr
end type
type dw_pageretr from u_dw_rbtnfilter within w_publ_pageretr
end type
type st_1 from statictext within w_publ_pageretr
end type
type cb_nextpage from uo_imflatbutton within w_publ_pageretr
end type
end forward

global type w_publ_pageretr from w_publ_base
integer width = 3675
integer height = 2892
string title = "分页"
event ue_usual_query_filt ( )
event ue_usual_query_retr ( )
event user_key ( )
event retrieve_pageretr ( )
event ue_page1 ( )
event ue_page2 ( )
event ue_page3 ( )
event ue_page4 ( )
sle_usual_query sle_usual_query
cb_retrieveall cb_retrieveall
em_pagerowno em_pagerowno
dw_pageretr dw_pageretr
st_1 st_1
cb_nextpage cb_nextpage
end type
global w_publ_pageretr w_publ_pageretr

type variables
datastore ds_curquery //缓存查询条件
String ori_oldselect //保存原始SELECT
String ls_newselect //保存加入查询条件后的SELECT
String pkcolumndbtname //PK列数据库中列名
Long onepage_rowlmno = 100 //页行最大行数
Boolean retrieve_all = FALSE //是否全部RETRIEVE（不分页）
Int mode = 0
//工作模式：0-编辑 1-带字符串参数预选择的选择/编辑 
Long arg_pkid //目标定位id  //备用
String arg_string_code //默认常用查询内容
String OLD_TITLE = ''
s_edit_index_tran s_tran //传递参数使用
Int retrmode = 0 // 0 retrieve all;1 first page ;2 prior page;3 next page;4 last page

Boolean if_sharedata = FALSE //是否接受share
datastore ds_share //用于存放share的数据

Boolean if_power_sendout = TRUE
Boolean if_power_print = TRUE


end variables

forward prototypes
public function integer wf_editindex_lockf ()
public function integer wf_retrieveuc (datawindow arg_dw, string arg_newselect, integer arg_retrmode)
public function string wf_get_pkcolumndbtname (datawindow arg_dw)
end prototypes

event ue_usual_query_filt();//string obj_expr=''  
//if trim(sle_usual_query.text)<>'' then 
//	if pos(trim(sle_usual_query.text),'%')=0 then
//		obj_expr=obj_expr+'( inwarecode like "%'+trim(sle_usual_query.text)+'%" )'
//	else
//		obj_expr=obj_expr+'( inwarecode like "'+trim(sle_usual_query.text)+'" )'
//	end if 
//end if
//
//dw_pageretr.setfilter(obj_expr)
//
//dw_pageretr.setredraw(false)
//dw_pageretr.filter()
//if dw_pageretr.rowcount()>=1 then
//	dw_pageretr.selectrow(0,false)
//	dw_pageretr.selectrow(1,true)
//end if
//dw_pageretr.setredraw(true)
end event

event ue_usual_query_retr();//string ls_querystrpart=''
//ls_newselect=lower(ori_oldselect)
//if trim(sle_usual_query.text)<>'' then
//	if pos(trim(sle_usual_query.text),'%')=0 then
//		ls_querystrpart= ls_querystrpart + "(u_inware.inwarecode like '%"+trim(sle_usual_query.text)+"%')"
//	else
//		ls_querystrpart=ls_querystrpart + "(u_inware.inwarecode like '"+trim(sle_usual_query.text)+"')"
//	end if
//
//	if pos(ls_newselect," where ") <> 0 then
//	   ls_newselect=ls_newselect+" and ("+ls_querystrpart+')'
//	else
//		ls_newselect=ls_newselect+" where ("+ls_querystrpart+')'
//	end if
//end if
//wf_retrieveuc(dw_pageretr,ls_newselect,1)  
//this.triggerevent('retrieve_pageretr')
//
end event

event user_key();IF	KeyDown(KeyPageUp!)  THEN
	IF NOT dw_edit_mode THEN THIS.TriggerEvent('ue_page3')
ELSEIF KeyDown(KeyPageDown!)  THEN
	IF NOT dw_edit_mode THEN THIS.TriggerEvent('ue_page2')
END IF


end event

event retrieve_pageretr();Boolean cb_retrieveall_enabled,cb_nextpage_enabled
Boolean cb_func_enabled,cb_retrieve_enabled

cb_retrieveall_enabled = cb_retrieveall.Enabled
cb_nextpage_enabled = cb_nextpage.Enabled
cb_func_enabled = cb_func.Enabled

cb_retrieveall.Enabled = FALSE
cb_nextpage.Enabled = FALSE
cb_func.Enabled = FALSE


SetPointer(HourGlass!)
dw_pageretr.Retrieve()
IF dw_pageretr.RowCount() > 0 AND dw_pageretr.GetRow() = 0 THEN dw_pageretr.SetRow(1)
SetPointer(Arrow!)

cb_nextpage.Enabled = cb_nextpage_enabled
cb_retrieveall.Enabled = cb_retrieveall_enabled
cb_func.Enabled = cb_func_enabled


end event

event ue_page1();wf_retrieveuc(dw_pageretr,ls_newselect,1)
THIS.TriggerEvent('RETRIEVE_pageretr')

end event

event ue_page2();wf_retrieveuc(dw_pageretr,ls_newselect,2)
THIS.TriggerEvent('RETRIEVE_pageretr')
end event

event ue_page3();wf_retrieveuc(dw_pageretr,ls_newselect,3)
THIS.TriggerEvent('RETRIEVE_pageretr')
end event

event ue_page4();wf_retrieveuc(dw_pageretr,ls_newselect,4)
THIS.TriggerEvent('RETRIEVE_pageretr')
end event

public function integer wf_editindex_lockf ();//wf_editindex_lockf
IF retrieve_all OR dw_edit_mode THEN
	cb_nextpage.Enabled = FALSE
	cb_retrieveall.Enabled = FALSE
	em_pagerowno.Enabled = FALSE
ELSE
	cb_nextpage.Enabled = TRUE
	cb_retrieveall.Enabled = TRUE
	em_pagerowno.Enabled = TRUE
END IF

IF dw_edit_mode THEN
	sle_usual_query.Enabled = FALSE
	cb_func.Enabled = FALSE
ELSE
	sle_usual_query.Enabled = TRUE
	cb_func.Enabled = TRUE
END IF
RETURN 1

end function

public function integer wf_retrieveuc (datawindow arg_dw, string arg_newselect, integer arg_retrmode);//====================================================================
// Function: wf_retrieveuc()
//--------------------------------------------------------------------
// Description: 分页拼retr语句
//--------------------------------------------------------------------
// Arguments: 
//		integer	arg_retrmode: 0 retrieve all;1 first page ;2 prior page;3 next page;4 last page	
//--------------------------------------------------------------------
// Returns:  integer
//--------------------------------------------------------------------
// Author:	yyx		Date: 2003.10.17
//--------------------------------------------------------------------
// Modify History: 
//	
//====================================================================
//取得当前的最大\最小ID
//按上下翻页命令,拼接最新SELECT语句

retrmode=arg_retrmode
IF arg_retrmode=0  or retrieve_all THEN 
	arg_dw.Modify("datawindow.table.select = ~"" + arg_newselect+ "~"")
	GOTO EXT
END IF

string cur_page_newselect,ls_pkcolname,LS_PAGE_ter=''
cur_page_newselect=lower(trim(arg_newselect))
LONG MAX_ID=0,MIN_ID=0,LS_I,ls_id
ls_pkcolname=arg_dw.Describe("#1.name") //取得ID列名称


if arg_retrmode<>1 then
MAX_ID=0
Min_ID=0
FOR LS_I=1 TO arg_dw.ROWCOUNT()
 ls_id=arg_dw.GetItemNumber(ls_i, ls_pkcolname)
 if LS_I=1 then 
	MAX_ID=ls_id
	Min_ID=ls_id
 end if
 if not isnull(ls_id) then
	if MAX_ID<ls_id then MAX_ID=ls_id
   if Min_ID>ls_id then Min_ID=ls_id
 end if
NEXT
FOR LS_I=1 TO arg_dw.FilteredCount()
 ls_id=arg_dw.GetItemNumber(ls_i, ls_pkcolname,filter!,true)
 if LS_I=1 and MAX_ID=0 and Min_ID=0 then 
	MAX_ID=ls_id
	Min_ID=ls_id
 end if
 if not isnull(ls_id) then
	if MAX_ID<ls_id then MAX_ID=ls_id
   if Min_ID>ls_id then Min_ID=ls_id
 end if
NEXT

end if

cur_page_newselect=trim(cur_page_newselect)

IF not (retrieve_all or retrmode=0) then
	cur_page_newselect='select top '+string(onepage_rowlmno)+' '+mid( cur_page_newselect , 8)
end if

CHOOSE CASE arg_retrmode
	CASE 1 //第一页
		LS_PAGE_ter=''
	CASE 2 //上一页
		LS_PAGE_ter=pkcolumndbtname+'>'+STRING(MAX_ID)
	CASE 3 //下一页
		LS_PAGE_ter=pkcolumndbtname+'<'+STRING(Min_ID)
	CASE 4 //末页
		LS_PAGE_ter=''

END CHOOSE

IF TRIM(LS_PAGE_ter)<>'' THEN
if Pos(cur_page_newselect," where ") <> 0 then
   cur_page_newselect=cur_page_newselect+" AND ("+LS_PAGE_ter+')'
else
	cur_page_newselect=cur_page_newselect+" WHERE ("+LS_PAGE_ter+')'
end if
END IF

IF arg_retrmode=2 or arg_retrmode=4 THEN 
	cur_page_newselect=cur_page_newselect+' ORDER BY '+pkcolumndbtname
ELSE
	cur_page_newselect=cur_page_newselect+' ORDER BY '+pkcolumndbtname+' DESC'
END IF

arg_dw.Modify("datawindow.table.select = ~"" + cur_page_newselect+ "~"")

EXT:
RETURN 1
end function

public function string wf_get_pkcolumndbtname (datawindow arg_dw);//====================================================================
// Function: wf_get_pkcolumndbtname()
//--------------------------------------------------------------------
// Description: 取第一列为关键字
//--------------------------------------------------------------------
// Arguments: 
//		value	datawindow	arg_dw		
//--------------------------------------------------------------------
// Returns:  string
//--------------------------------------------------------------------
// Author:	yyx		Date: 2003.10.22
//--------------------------------------------------------------------
// Modify History: 
//	
//====================================================================
string ls_pkcolumndbtname,ls_str,tmp_oldselect
long l_pos

ls_pkcolumndbtname=arg_dw.Describe("#1.dbname") 
if pos(ls_pkcolumndbtname,'.')<=0 then
	tmp_oldselect=trim(arg_dw.Describe("DataWindow.Table.Select"))
	ls_str=mid(tmp_oldselect,8)
	if pos(ls_str,'.')>pos(ls_str,',') then 
		goto ext
	else
		ls_pkcolumndbtname=left(ls_str,pos(ls_str,',') - 1)
	end if
end if
		
ext:
return ls_pkcolumndbtname
end function

on w_publ_pageretr.create
int iCurrent
call super::create
this.sle_usual_query=create sle_usual_query
this.cb_retrieveall=create cb_retrieveall
this.em_pagerowno=create em_pagerowno
this.dw_pageretr=create dw_pageretr
this.st_1=create st_1
this.cb_nextpage=create cb_nextpage
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.sle_usual_query
this.Control[iCurrent+2]=this.cb_retrieveall
this.Control[iCurrent+3]=this.em_pagerowno
this.Control[iCurrent+4]=this.dw_pageretr
this.Control[iCurrent+5]=this.st_1
this.Control[iCurrent+6]=this.cb_nextpage
end on

on w_publ_pageretr.destroy
call super::destroy
destroy(this.sle_usual_query)
destroy(this.cb_retrieveall)
destroy(this.em_pagerowno)
destroy(this.dw_pageretr)
destroy(this.st_1)
destroy(this.cb_nextpage)
end on

event open;call super::open;OLD_TITLE = THIS.Title

s_tran = Message.PowerObjectParm
IF NOT IsNull(s_tran) THEN
	retrieve_all = s_tran.if_retrieve_all
	mode = s_tran.work_mode
	arg_pkid = s_tran.arg_pkid
	arg_string_code = s_tran.arg_string_code
	if_sharedata = s_tran.if_sharedata //是否应用sharedata，当retrieve_all＝true是生效
	ds_share = s_tran.ds_share
	if_power_sendout = s_tran.if_sendout
	if_power_print = s_tran.if_print
END IF

dw_pageretr.RBUTTON_FILTER_USE = TRUE //右键查询功能开关
dw_pageretr.titleclick_sort_use = TRUE //单击标题排序功能开关

dw_pageretr.SetTransObject (sqlca)
pkcolumndbtname = wf_get_pkcolumndbtname(dw_pageretr) //取第一列为关键字

ori_oldselect = dw_pageretr.Describe("DataWindow.Table.Select")
ls_newselect = ori_oldselect
ds_curquery = CREATE DATASTORE
ds_curquery.DataObject = 'd_extr_find'
ds_curquery.SetTransObject (sqlca)

wf_editindex_lockf()

sle_usual_query.Text = Trim(arg_string_code)
IF NOT retrieve_all THEN
	THIS.TriggerEvent("ue_usual_query_RETR") //修改ls_newselect,retrieve
ELSE
	IF  if_sharedata THEN
		ds_share.ShareData(dw_pageretr)
	ELSE
		wf_retrieveuc(dw_pageretr,ls_newselect,1)
		THIS.TriggerEvent('RETRIEVE_pageretr')
	END IF
END IF

IF retrieve_all THEN
	THIS.TriggerEvent("ue_usual_query_filt")
END IF


end event

event ue_retr;call super::ue_retr;s_extrtriequery_tran s_dbdw
s_dbdw.query_dw=dw_pageretr
s_dbdw.ptn_ds=ds_curquery
s_dbdw.query_oldselect=ori_oldselect

string ls_select=''
openwithparm(w_extr_query,s_dbdw)
ls_select = message.stringparm

if trim(ls_select)="" or isnull(ls_select) then
	return 
else
	ls_newselect=ls_select	
end if

dw_pageretr.setredraw(false)
wf_retrieveuc(dw_pageretr,ls_newselect,1)
this.triggerevent('retrieve_pageretr')
dw_pageretr.setredraw(true)
end event

type cb_func from w_publ_base`cb_func within w_publ_pageretr
integer x = 731
integer y = 4
integer width = 165
integer height = 84
integer taborder = 30
string text = "查询"
end type

type cb_exit from w_publ_base`cb_exit within w_publ_pageretr
integer x = 3255
integer y = 2144
integer height = 92
integer taborder = 20
end type

type sle_usual_query from u_sleedit within w_publ_pageretr
integer x = 219
integer y = 4
integer height = 92
end type

event inputchanged;call super::inputchanged;IF retrieve_all THEN
	PARENT.TRIGGEREVENT("ue_usual_query_filt")
END IF
end event

event keyup;call super::keyup;IF NOT dw_edit_mode THEN
	If  Key = KeyDownArrow! Then //
		dw_pageretr.ScrollNextRow()
	End If
	If  Key = KeyUPArrow! Then //
		dw_pageretr.ScrollPriorRow()
	End If
END IF
end event

event modified;call super::modified;IF retrieve_all or retrmode=0 THEN
	PARENT.TRIGGEREVENT("ue_usual_query_filt")
ELSE
	PARENT.TRIGGEREVENT("ue_usual_query_RETR")
END IF
end event

type cb_retrieveall from uo_imflatbutton within w_publ_pageretr
integer x = 1202
integer width = 165
integer height = 84
integer taborder = 70
string text = "首页"
end type

event clicked;call super::clicked;PARENT.TriggerEvent('ue_page1')


end event

type em_pagerowno from editmask within w_publ_pageretr
integer x = 901
integer width = 293
integer height = 84
integer taborder = 60
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "1000"
borderstyle borderstyle = stylelowered!
string mask = "#####0"
boolean spin = true
end type

event constructor;this.text=f_ProfileString (sys_empid,dw_pageretr.DATAOBJECT, "pagerowno",'100')
onepage_rowlmno=long(this.text)
end event

event modified;IF LONG(THIS.TEXT)>0 THEN 
else
THIS.TEXT='1'
end if
onepage_rowlmno=LONG(THIS.TEXT)
f_SetProfileString (sys_empid,dw_pageretr.DATAOBJECT, "pagerowno", THIS.TEXT)

end event

type dw_pageretr from u_dw_rbtnfilter within w_publ_pageretr
integer y = 104
integer width = 1184
integer height = 1984
integer taborder = 40
boolean titlebar = true
boolean maxbox = true
boolean hscrollbar = true
boolean vscrollbar = true
boolean resizable = true
boolean border = false
boolean hsplitscroll = true
borderstyle borderstyle = styleraised!
end type

event clicked;call super::clicked;IF Not( dw_edit_mode OR row <= 0 ) THEN  THIS.SetRow(row)


end event

event rowfocuschanged;call super::rowfocuschanged;IF dw_edit_mode THEN RETURN
IF currentrow > 0 THEN
	THIS.SelectRow(0,FALSE)
	THIS.SelectRow(currentrow,TRUE)
END IF

end event

event dwnkey;call super::dwnkey;parent.postevent('user_key')
end event

type st_1 from statictext within w_publ_pageretr
integer x = 27
integer y = 24
integer width = 219
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 134217739
string text = "编码含:"
boolean focusrectangle = false
end type

type cb_nextpage from uo_imflatbutton within w_publ_pageretr
integer x = 1367
integer width = 110
integer height = 84
integer taborder = 80
boolean bringtotop = true
string text = "▼"
end type

event clicked;call super::clicked;m_Dfc_Control_PopupMenu dmPopupMenu
string menustr


menustr="Text=下页~tEvent=ue_page3"
menustr = menustr + "|" + "Text=上页~tEvent=ue_page2"
menustr = menustr + "|" + "Text=末页~tEvent=ue_page4"
	
if len(trim(menustr))<>0 then
	dmPopupMenu = Create m_Dfc_Control_PopupMenu
	dmPopupMenu.mf_BuildMenu(This, menustr)
	dmPopupMenu.mf_PopMenu()
	Destroy dmPopupMenu
end if
end event

