$PBExportHeader$w_publ_edit_index.srw
$PBExportComments$定义窗口
forward
global type w_publ_edit_index from w_publ_base
end type
type sle_usual_query from u_sleedit within w_publ_edit_index
end type
type cb_nextpage from uo_imflatbutton within w_publ_edit_index
end type
type cb_priorpage from uo_imflatbutton within w_publ_edit_index
end type
type cb_firstpage from uo_imflatbutton within w_publ_edit_index
end type
type cb_retrieveall from uo_imflatbutton within w_publ_edit_index
end type
type em_pagerowno from editmask within w_publ_edit_index
end type
type st_pagerowno from statictext within w_publ_edit_index
end type
type st_1 from statictext within w_publ_edit_index
end type
type cb_add from uo_imflatbutton within w_publ_edit_index
end type
type cb_edit from uo_imflatbutton within w_publ_edit_index
end type
type cb_delet from uo_imflatbutton within w_publ_edit_index
end type
type cb_choice from uo_imflatbutton within w_publ_edit_index
end type
type cb_cancel from uo_imflatbutton within w_publ_edit_index
end type
type cbx_mlselect from checkbox within w_publ_edit_index
end type
type cbx_allselect from checkbox within w_publ_edit_index
end type
type cb_mode_itfchg_b from uo_imflatbutton within w_publ_edit_index
end type
type cb_mode_itfchg from uo_imflatbutton within w_publ_edit_index
end type
type gb_1 from groupbox within w_publ_edit_index
end type
type dw_uc from datawindow within w_publ_edit_index
end type
type cb_retrieve from uo_imflatbutton within w_publ_edit_index
end type
type cb_print from uo_imflatbutton within w_publ_edit_index
end type
type ln_bar from line within w_publ_edit_index
end type
type ln_bar2 from line within w_publ_edit_index
end type
type r_bar from rectangle within w_publ_edit_index
end type
type ln_1 from line within w_publ_edit_index
end type
type ln_2 from line within w_publ_edit_index
end type
type dw_index from u_dw_rbtnfilter within w_publ_edit_index
end type
end forward

global type w_publ_edit_index from w_publ_base
integer width = 2926
integer height = 1784
string title = "编缉"
boolean minbox = false
windowtype windowtype = response!
event ue_usual_query_filt ( )
event ue_usual_query_retr ( )
event user_key ( )
event retrieve_uc ( )
event ue_mode_itfchg ( )
event refresh_interface ( )
event ue_help ( )
sle_usual_query sle_usual_query
cb_nextpage cb_nextpage
cb_priorpage cb_priorpage
cb_firstpage cb_firstpage
cb_retrieveall cb_retrieveall
em_pagerowno em_pagerowno
st_pagerowno st_pagerowno
st_1 st_1
cb_add cb_add
cb_edit cb_edit
cb_delet cb_delet
cb_choice cb_choice
cb_cancel cb_cancel
cbx_mlselect cbx_mlselect
cbx_allselect cbx_allselect
cb_mode_itfchg_b cb_mode_itfchg_b
cb_mode_itfchg cb_mode_itfchg
gb_1 gb_1
dw_uc dw_uc
cb_retrieve cb_retrieve
cb_print cb_print
ln_bar ln_bar
ln_bar2 ln_bar2
r_bar r_bar
ln_1 ln_1
ln_2 ln_2
dw_index dw_index
end type
global w_publ_edit_index w_publ_edit_index

type variables
boolean  ls_update_flag=true
long modifyrow_no=0,crl_row   //当前行记录
s_edit_tran  para_obj   //环境信息用于查询
string keyword_string  //关键字 未用
date first_date //查询开始日
date end_date  //查询结束日，比表达日后一天
int child_column_int //明细dw锁定列数
string ins_sqlerrtext

boolean if_retrieveing=false


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=''
int retrmode=0 // 0 retrieve all;1 first page ;2 prior page;3 next page;4 last page

boolean if_select_all=false
boolean if_changeselect=true
int if_mlselect=0


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)
public function integer wf_index_uc ()
public function integer wf_face_change ()
end prototypes

event ue_usual_query_filt();//if dw_edit_mode or keydown(keyf4!) or keydown(keyf5!) then	return
//string obj_expr=''  
//if trim(sle_usual_query.text)<>'' then 
//	if pos(trim(sle_usual_query.text),'%')=0 then
//		obj_expr=obj_expr+'( name like "%'+trim(sle_usual_query.text)+'%" )'
//	else
//		obj_expr=obj_expr+'( name like "'+trim(sle_usual_query.text)+'" )'
//	end if 
//end if
//
//dw_uc.setfilter(obj_expr)
//
//dw_uc.setredraw(false)
//dw_index.setredraw(false)
//dw_uc.filter()
//if dw_index.rowcount()>=1 then
//	dw_index.selectrow(0,false)
//	dw_index.selectrow(1,true)
//end if
//dw_uc.setredraw(true)
//dw_index.setredraw(true)
end event

event ue_usual_query_retr();//if dw_edit_mode or keydown(keyf4!) or keydown(keyf5!) then	return
//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 + "(name like '%"+trim(sle_usual_query.text)+"%')"
//	else
//		ls_querystrpart=ls_querystrpart + "(name 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_uc,ls_newselect,1)   
//this.triggerevent('retrieve_uc') //注意必须有此句
end event

event user_key();if keydown(Keypageup!)  then
	if  cb_priorpage.enabled then	cb_priorpage.triggerevent(clicked!)
elseif keydown(Keypagedown!)  then
	if  cb_nextpage.enabled then	cb_nextpage.triggerevent(clicked!)
elseif keydown(Keyenter!) and keydown(keycontrol!) then
	if mode = 1 and not dw_edit_mode and cb_choice.enabled then	cb_choice.triggerevent(clicked!)
end if

if keydown(keyshift!)  then
	if cbx_mlselect.visible then
		cbx_mlselect.checked = not cbx_mlselect.checked
		cbx_mlselect.triggerevent(clicked!)
	end if
end if

if keydown(keycontrol!) and keydown(keya!) then
	if cbx_allselect.visible and cbx_allselect.enabled then
		cbx_allselect.checked = not cbx_allselect.checked
		cbx_allselect.triggerevent(clicked!)
	end if
end if



end event

event retrieve_uc();boolean cb_firstpage_enabled,cb_nextpage_enabled,cb_retrieveall_enabled
boolean cb_priorpage_enabled,cb_func_enabled,cb_retrieve_enabled

cb_firstpage_enabled=cb_firstpage.enabled
cb_nextpage_enabled=cb_nextpage.enabled
cb_retrieveall_enabled=cb_retrieveall.enabled
cb_priorpage_enabled=cb_priorpage.enabled
cb_func_enabled=cb_func.enabled
cb_retrieve_enabled=cb_retrieve.enabled

cb_firstpage.enabled=false
cb_nextpage.enabled=false
cb_retrieveall.enabled=false
cb_priorpage.enabled=false
cb_func.enabled=false
cb_retrieve.enabled=false



dw_UC.setredraw(false)
dw_index.ShareDataOff()
SetPointer(HourGlass!)
dw_UC.retrieve()
SetPointer(Arrow!)
dw_uc.sharedata(dw_index)
dw_UC.setredraw(true)


if dw_index.rowcount()>=1 then
dw_index.selectrow(0,false)
dw_index.selectrow(1,true)
end if

cb_firstpage.enabled=cb_firstpage_enabled
cb_nextpage.enabled=cb_nextpage_enabled
cb_retrieveall.enabled=cb_retrieveall_enabled
cb_priorpage.enabled=cb_priorpage_enabled
cb_func.enabled=cb_func_enabled
cb_retrieve.enabled=cb_retrieve_enabled

end event

event ue_mode_itfchg();//因工作模式(选择\非选择)改变界面布局
IF mode = 1 THEN
	IF cb_mode_itfchg.Text = '<<' THEN
		cb_add.Enabled = FALSE
		cb_delet.Enabled = FALSE
		cb_edit.Enabled = FALSE
		
		cb_choice.Enabled = TRUE
		
		
		IF if_select_all THEN
			cbx_mlselect.Visible = TRUE
			cbx_allselect.Visible = TRUE
		ELSE
			cbx_mlselect.Visible = FALSE
			cbx_allselect.Visible = FALSE
		END IF
	ELSE
		cb_add.Enabled = TRUE
		cb_delet.Enabled = TRUE
		cb_edit.Enabled = TRUE
		
		cb_choice.Enabled = FALSE
		
		cbx_mlselect.Visible = FALSE
		cbx_allselect.Visible = FALSE
		IF if_select_all THEN
			cbx_mlselect.Checked = FALSE
			cbx_mlselect.TriggerEvent(Clicked!)
		END IF
	END IF
END IF


end event

event ue_help();Int i
i = htmlhelpA(Handle(THIS), sys_help_chm, 0, THIS.Title+".html")

end event

public function integer wf_editindex_lockf ();//wf_editindex_lockf
if retrieve_all or dw_edit_mode then
	cb_firstpage.enabled=false
	cb_nextpage.enabled=false
	cb_priorpage.enabled=false
	cb_retrieveall.enabled=false
	em_pagerowno.enabled=false
Else
	cb_firstpage.enabled=true
	cb_nextpage.enabled=true
	cb_priorpage.enabled=true
	cb_retrieveall.enabled=TRUE

//	IF f_power_ind(3197,sys_msg_pow) THEN
		em_pagerowno.Enabled = True
//	ELSE
//		em_pagerowno.Enabled = False
//	END IF

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:(None)
//--------------------------------------------------------------------
// Returns:  string
//--------------------------------------------------------------------
// Author:	yyx		Date: 2003.10.17
//--------------------------------------------------------------------
// 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

public function integer wf_index_uc ();//WF_INDEX_UC
LONG LS_LONG 
LS_LONG=DW_UC.GETROW()
dw_index.SETROW(LS_LONG)
dw_index.ScrollToRow(LS_LONG)
dw_index.selectrow(0,false)
dw_index.selectrow(LS_LONG,true)
RETURN 0
end function

public function integer wf_face_change ();if dw_edit_mode then
	cb_func.enabled = false
	cb_retrieve.enabled = false
	cb_delet.enabled = false
	cb_print.enabled = false
	cb_choice.Enabled = FALSE
	sle_usual_query.Enabled = FALSE
	
	cb_edit.text = "放弃&E"
	cb_add.text = "保存&S"
	cb_edit.normalpicname = 'Undo.bmp'
	cb_add.normalpicname = 'Save.bmp'
else
	
	cb_retrieve.enabled = true
	cb_delet.enabled = true
	cb_print.enabled = true
	cb_func.enabled = true
	
	sle_usual_query.Enabled = TRUE
	IF mode = 1 THEN		
		cb_choice.Enabled = TRUE
	ELSE
		
		cb_choice.Enabled = FALSE
	END IF
	
	cb_edit.text = "修改&E"
	cb_add.text = "新建&S"	
	cb_edit.normalpicname = 'OPEN.bmp'
	cb_add.normalpicname = 'new.bmp'
end if

cb_edit.of_init_draw()
cb_add.of_init_draw()
cb_edit.of_paint()
cb_add.of_paint()
cb_edit.triggerevent('ue_textchange')
cb_add.triggerevent('ue_textchange')

this.triggerevent('refresh_interface')
return 1

end function

on w_publ_edit_index.create
int iCurrent
call super::create
this.sle_usual_query=create sle_usual_query
this.cb_nextpage=create cb_nextpage
this.cb_priorpage=create cb_priorpage
this.cb_firstpage=create cb_firstpage
this.cb_retrieveall=create cb_retrieveall
this.em_pagerowno=create em_pagerowno
this.st_pagerowno=create st_pagerowno
this.st_1=create st_1
this.cb_add=create cb_add
this.cb_edit=create cb_edit
this.cb_delet=create cb_delet
this.cb_choice=create cb_choice
this.cb_cancel=create cb_cancel
this.cbx_mlselect=create cbx_mlselect
this.cbx_allselect=create cbx_allselect
this.cb_mode_itfchg_b=create cb_mode_itfchg_b
this.cb_mode_itfchg=create cb_mode_itfchg
this.gb_1=create gb_1
this.dw_uc=create dw_uc
this.cb_retrieve=create cb_retrieve
this.cb_print=create cb_print
this.ln_bar=create ln_bar
this.ln_bar2=create ln_bar2
this.r_bar=create r_bar
this.ln_1=create ln_1
this.ln_2=create ln_2
this.dw_index=create dw_index
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.sle_usual_query
this.Control[iCurrent+2]=this.cb_nextpage
this.Control[iCurrent+3]=this.cb_priorpage
this.Control[iCurrent+4]=this.cb_firstpage
this.Control[iCurrent+5]=this.cb_retrieveall
this.Control[iCurrent+6]=this.em_pagerowno
this.Control[iCurrent+7]=this.st_pagerowno
this.Control[iCurrent+8]=this.st_1
this.Control[iCurrent+9]=this.cb_add
this.Control[iCurrent+10]=this.cb_edit
this.Control[iCurrent+11]=this.cb_delet
this.Control[iCurrent+12]=this.cb_choice
this.Control[iCurrent+13]=this.cb_cancel
this.Control[iCurrent+14]=this.cbx_mlselect
this.Control[iCurrent+15]=this.cbx_allselect
this.Control[iCurrent+16]=this.cb_mode_itfchg_b
this.Control[iCurrent+17]=this.cb_mode_itfchg
this.Control[iCurrent+18]=this.gb_1
this.Control[iCurrent+19]=this.dw_uc
this.Control[iCurrent+20]=this.cb_retrieve
this.Control[iCurrent+21]=this.cb_print
this.Control[iCurrent+22]=this.ln_bar
this.Control[iCurrent+23]=this.ln_bar2
this.Control[iCurrent+24]=this.r_bar
this.Control[iCurrent+25]=this.ln_1
this.Control[iCurrent+26]=this.ln_2
this.Control[iCurrent+27]=this.dw_index
end on

on w_publ_edit_index.destroy
call super::destroy
destroy(this.sle_usual_query)
destroy(this.cb_nextpage)
destroy(this.cb_priorpage)
destroy(this.cb_firstpage)
destroy(this.cb_retrieveall)
destroy(this.em_pagerowno)
destroy(this.st_pagerowno)
destroy(this.st_1)
destroy(this.cb_add)
destroy(this.cb_edit)
destroy(this.cb_delet)
destroy(this.cb_choice)
destroy(this.cb_cancel)
destroy(this.cbx_mlselect)
destroy(this.cbx_allselect)
destroy(this.cb_mode_itfchg_b)
destroy(this.cb_mode_itfchg)
destroy(this.gb_1)
destroy(this.dw_uc)
destroy(this.cb_retrieve)
destroy(this.cb_print)
destroy(this.ln_bar)
destroy(this.ln_bar2)
destroy(this.r_bar)
destroy(this.ln_1)
destroy(this.ln_2)
destroy(this.dw_index)
end on

event open;call super::open;if_ue_retr=true
if_ue_filter=true
if_ue_sort=true

old_title = this.title

s_edit_index_tran s_tran //传递参数使用
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_select_all = s_tran.if_select_all
end if

//choose case mode
//	case 0
//		this.title = old_title+'  编辑模式  [f4-新建/保存 f5-编辑/放弃]'
//	case 1
//		this.title = old_title+'  选择模式  [f4-新建/保存 f5-编辑/放弃]'
//end choose



dw_uc.settransobject (sqlca)
dw_index.settransobject (sqlca)
dw_index.rbutton_filter_use = true //右键查询功能开关

pkcolumndbtname = wf_get_pkcolumndbtname(dw_uc) //取第一列为关键字
ori_oldselect = dw_uc.describe("datawindow.table.select")
ls_newselect = ori_oldselect
ds_curquery = create datastore
ds_curquery.dataobject = 'd_extr_find'
ds_curquery.settransobject (sqlca)

cbx_mlselect.visible = false
cbx_allselect.visible = false

if mode = 1 then cb_mode_itfchg.triggerevent(clicked!)
wf_editindex_lockf()

if not retrieve_all and trim(arg_string_code) <> '' then
	sle_usual_query.text = trim(arg_string_code)
	this.triggerevent("ue_usual_query_retr") //修改ls_newselect,retrieve
else
	wf_retrieveuc(dw_uc,ls_newselect,1) //retrieve
	this.triggerevent('retrieve_uc')
end if

if retrieve_all and trim(arg_string_code) <> '' 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_UC
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_index.SetRedraw(FALSE)
wf_retrieveuc(dw_uc,ls_newselect,1)
DW_index.SetRedraw(TRUE)
end event

event close;call super::close;//CLOSEWITHRETURN(THIS,<INS_RT_STRU>)
//<INS_RT_STRU> 窗体级子定义结构变量,用于返回
end event

event closequery;call super::closequery;if dw_edit_mode then
	dw_UC.ACCEPTTEXT()
	int ls_row=0
	ls_row=dw_UC.GetNextModified(0, Primary!)+&
	dw_UC.GetNextModified(0, FILTER!)+dw_UC.DeletedCount()
	if ls_row>0 then 
		if messagebox('是否保存','数据已经改变，是否先保存？',Question!,YesNo!,1 ) = 1 THEN 
			RETURN 1
		END IF	
	end if
else
	if if_retrieveing then
		messagebox("系统提示",'系统正在查询数据,请稍后再退出！')
		return 1
	end if
end if


end event

event key;call super::key;THIS.TRIGGEREVENT('USER_KEY')
end event

event ue_filter;call super::ue_filter;OPENWITHPARM(w_filter_query,dw_uc)
STRING LS_EXPR
LS_EXPR=Message.StringParm	

if len(LS_EXPR)>2 and trim(LS_EXPR)='' then return

dw_uc.setfilter(LS_EXPR)

dw_uc.SetRedraw (false)
dw_uc.filter()
dw_uc.SetRedraw (true)
end event

event ue_sort;call super::ue_sort;OPENwithparm(w_sortrow,dw_UC)
STRING LS_EXPR
LS_EXPR=Message.StringParm	
IF ISNULL(LS_EXPR) THEN LS_EXPR='   '
if len(LS_EXPR)>2 and trim(LS_EXPR)='' then return

dw_UC.setsort(LS_EXPR)

dw_UC.SetRedraw (false)
dw_UC.sort()
dw_UC.SetRedraw (true)
end event

event ue_sentdataout;call super::ue_sentdataout;OPENWITHPARM(w_sentdataout,dw_index)
end event

event resize;call super::resize;ln_bar.endx = this.width
ln_bar2.endx = this.width
ln_1.endx = this.width
ln_2.endx = this.width
r_bar.width = this.width
end event

type cb_func from w_publ_base`cb_func within w_publ_edit_index
integer x = 686
integer width = 151
integer height = 164
integer taborder = 30
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_publ_edit_index
integer x = 1275
integer width = 151
integer height = 164
integer taborder = 20
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

type sle_usual_query from u_sleedit within w_publ_edit_index
integer x = 206
integer y = 184
integer height = 92
boolean autohscroll = true
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_INDEX.ScrollNextRow()
	End If
	If  Key = KeyUPArrow! Then //
		dw_INDEX.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_nextpage from uo_imflatbutton within w_publ_edit_index
integer x = 2181
integer width = 151
integer height = 164
integer taborder = 140
string text = "末页"
string normalpicname = "p4.ico"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;wf_retrieveuc(dw_uc,ls_newselect,4)
parent.triggerevent('retrieve_uc')
end event

type cb_priorpage from uo_imflatbutton within w_publ_edit_index
integer x = 2030
integer width = 151
integer height = 164
integer taborder = 130
string text = "下页"
string normalpicname = "p3.ico"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;wf_retrieveuc(dw_uc,ls_newselect,3)
parent.triggerevent('retrieve_uc')
end event

type cb_firstpage from uo_imflatbutton within w_publ_edit_index
integer x = 1879
integer width = 151
integer height = 164
integer taborder = 120
string text = "上页"
string normalpicname = "p2.ico"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;wf_retrieveuc(dw_uc,ls_newselect,2)
parent.triggerevent('retrieve_uc')
end event

type cb_retrieveall from uo_imflatbutton within w_publ_edit_index
integer x = 1728
integer width = 151
integer height = 164
integer taborder = 70
string text = "首页"
string normalpicname = "p1.ico"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;wf_retrieveuc(dw_uc,ls_newselect,1)
parent.triggerevent('retrieve_uc')
end event

type em_pagerowno from editmask within w_publ_edit_index
integer x = 1426
integer y = 32
integer width = 302
integer height = 96
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;//IF f_power_ind(3197,sys_msg_pow) THEN
//	This.Text = f_profilestring (sys_empid,dw_uc.DataObject, "pagerowno",'100')
//ELSE
	This.Text = String(1000)
//END IF

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_uc.dataobject, "pagerowno", this.text)


end event

type st_pagerowno from statictext within w_publ_edit_index
boolean visible = false
integer x = 434
integer y = 748
integer width = 197
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 134217739
boolean enabled = false
string text = "页行数"
boolean focusrectangle = false
end type

type st_1 from statictext within w_publ_edit_index
integer x = 14
integer y = 204
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_add from uo_imflatbutton within w_publ_edit_index
integer width = 192
integer height = 164
integer taborder = 150
boolean bringtotop = true
string text = "新建&S"
string normalpicname = "new.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;if dw_edit_mode then
	string ls_errmsg
	if dw_uc.update() = -1 then
		if pos(ins_sqlerrtext,"cannot insert duplicate key row") > 0  or pos(ins_sqlerrtext,"unique key") > 0 then
			ls_errmsg = "关键内容重复"
		else
			ls_errmsg = "因为网络或其他原因>"+ins_sqlerrtext
		end if
		rollback;
		messagebox ("系统提示",ls_errmsg+",保存操作失败!",exclamation!,ok!)
		ls_update_flag = false
		return
	else
		commit;
		ls_update_flag = true
	end if
	ins_sqlerrtext = ""
	dw_uc.enabled = false
else
	long	li_row, li_cur_row
	li_cur_row = dw_uc.getrow()
	li_row = dw_uc.insertrow (li_cur_row)
	dw_uc.scrolltorow (li_row)
	dw_uc.enabled = true
	dw_uc.setfocus()
	modifyrow_no = li_row
end if

dw_edit_mode = not dw_edit_mode
wf_face_change()

if dw_edit_mode then
	if cb_mode_itfchg.text = '<<' then
		cb_mode_itfchg.triggerevent(clicked!)
	end if
else
	wf_index_uc()
end if

dw_index.rbutton_filter_use = not dw_edit_mode
wf_editindex_lockf()

end event

type cb_edit from uo_imflatbutton within w_publ_edit_index
integer x = 192
integer width = 192
integer height = 164
integer taborder = 170
boolean bringtotop = true
string text = "修改&E"
string normalpicname = "open.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;if dw_edit_mode then
	
	IF MessageBox ("IF","是否确定要放弃保存当前资料?",Question!,YesNo! ) = 2 THEN RETURN

	
	if dw_uc.getitemstatus(dw_uc.getrow(), 0, primary!) = newmodified! or dw_uc.getitemstatus(dw_uc.getrow(), 0, primary!) = new! then
		dw_uc.deleterow(dw_uc.getrow())
	else
		dw_uc.reselectrow(dw_uc.getrow())
	end if
	dw_uc.enabled = false
	modifyrow_no = 0
else
	dw_uc.enabled = true
	dw_uc.setfocus()
	modifyrow_no = dw_uc.getrow()
end if

dw_edit_mode = not dw_edit_mode
wf_face_change()

if dw_edit_mode then
	if cb_mode_itfchg.text = '<<' then
		cb_mode_itfchg.triggerevent(clicked!)
	end if	
else
	wf_index_uc()
end if



dw_index.rbutton_filter_use = not dw_edit_mode
wf_editindex_lockf()


end event

type cb_delet from uo_imflatbutton within w_publ_edit_index
integer x = 384
integer width = 151
integer height = 164
integer taborder = 180
boolean bringtotop = true
string text = "删除"
string normalpicname = "delete.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;//IF MessageBox ("IF","是否确定要删除当前记录?(选择确定后记录将不可恢复)",Question!,YesNo! ) = 2 THEN
//RETURN
//END IF 
//dw_uc.SetRedraw (false)
//dw_UC.DeleteRow (0)
//dw_UC.TriggerEvent (rowfocuschanged!)
//
//if dw_UC.Update() = -1 then
//	rollback;
//	MessageBox ("NO","删除记录操作失败!",Exclamation!,OK!)
//else
//	commit;
//end if
//dw_uc.SetRedraw (true)
//
//WF_INDEX_UC()
end event

type cb_choice from uo_imflatbutton within w_publ_edit_index
string tag = "选定[C^+Enter]"
integer x = 1125
integer width = 151
integer height = 164
integer taborder = 190
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;////单选代码
////LONG LS_ROW
////LS_ROW=dw_uc.getrow()
////if LS_ROW<=0 then 
////	messagebox('系统提示','请先选择目标行!',StopSign!)
////	return
////end if
////
////INS_RT_STRU.scustid=dw_INDEX.OBJECT.custid[LS_ROW]
////...

////CLOSE(PARENT)

/////多选代码
//LONG ROW,ls_i,chC=0
//ROW=dw_pageretr.GETROW()
//if ROW<=0 then 
//	messagebox('系统提示','请先选择目标行!',StopSign!)
//	return
//end if
//
//for ls_i=1 to dw_pageretr.rowcount()
//	if dw_pageretr.isselected(ls_i) then 
//		chC++		
//		INS_RT_STRU.mtrlwareid[ls_i]=dw_pageretr.OBJECT.mtrlwareid[ls_i]
//		INS_RT_STRU.mtrlid[ls_i]=dw_pageretr.OBJECT.mtrlid[ls_i]
//		INS_RT_STRU.u_mtrldef_mtrlcode[ls_i]=dw_pageretr.OBJECT.u_mtrldef_mtrlcode[ls_i]
//		INS_RT_STRU.u_mtrldef_mtrlname[ls_i]=dw_pageretr.OBJECT.u_mtrldef_mtrlname[ls_i]
//		INS_RT_STRU.u_mtrldef_mtrltype[ls_i]=dw_pageretr.OBJECT.u_mtrldef_mtrltype[ls_i]
//		INS_RT_STRU.u_mtrldef_unit[ls_i]=dw_pageretr.OBJECT.u_mtrldef_unit[ls_i]
//		INS_RT_STRU.noallocqty[ls_i]=dw_pageretr.OBJECT.noallocqty[ls_i]
//		INS_RT_STRU.cost[ls_i]=dw_pageretr.OBJECT.cost[ls_i]
//		INS_RT_STRU.planprice[ls_i]=dw_pageretr.OBJECT.planprice[ls_i]
//		INS_RT_STRU.storageid[ls_i]=dw_pageretr.OBJECT.storageid[ls_i]
//		INS_RT_STRU.plancode[ls_i]=dw_pageretr.OBJECT.plancode[ls_i]
//		INS_RT_STRU.billtype[ls_i]=dw_pageretr.OBJECT.billtype[ls_i]
//		INS_RT_STRU.noauditingqty[ls_i]=dw_pageretr.OBJECT.noauditingqty[ls_i]
//		if isnull(INS_RT_STRU.noauditingqty[ls_i]) then INS_RT_STRU.noauditingqty[ls_i]=0
//	end if
//
//next
//if chC=0 then 
//	messagebox('系统提示','请至少选择一个目标行!',StopSign!)
//	return
//end if
//
//CLOSE(PARENT)
end event

type cb_cancel from uo_imflatbutton within w_publ_edit_index
string tag = "取消[&Esc]"
boolean visible = false
integer x = 270
integer y = 592
integer width = 329
integer height = 112
integer taborder = 200
boolean bringtotop = true
boolean enabled = false
string text = "取消"
end type

event clicked;call super::clicked;CLOSE(PARENT)

end event

type cbx_mlselect from checkbox within w_publ_edit_index
integer x = 1458
integer y = 204
integer width = 215
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 16711680
long backcolor = 134217739
string text = "多选"
end type

event clicked;if this.checked then
	if_mlselect=1
	cbx_allselect.enabled=true
else
	if_mlselect=0
	cbx_allselect.enabled=false
	cbx_allselect.checked=false
	cbx_allselect.triggerevent(clicked!)
end if

f_SetProfileString (sys_empid,dw_index.DATAOBJECT, "if_mlselect", string(if_mlselect))

end event

type cbx_allselect from checkbox within w_publ_edit_index
integer x = 1774
integer y = 204
integer width = 229
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 16711680
long backcolor = 134217739
string text = "全选"
end type

event clicked;If dw_index.RowCount() <= 0 Then Return
Long li

dw_index.setredraw(false)
If This.Checked Then
	For li = 1 To dw_index.RowCount()
		dw_index.SelectRow(li,True)
	Next
Else
	For li = 1 To dw_index.RowCount()
		dw_index.SelectRow(li,False)
	Next
End If
dw_index.setredraw(true)
end event

type cb_mode_itfchg_b from uo_imflatbutton within w_publ_edit_index
boolean visible = false
integer x = 709
integer y = 1004
integer width = 78
integer height = 132
integer taborder = 160
boolean bringtotop = true
boolean enabled = false
string text = ">>"
end type

event clicked;call super::clicked;cb_mode_itfchg.TRIGGEREVENT(clicked!)
this.text=cb_mode_itfchg.text
cb_mode_itfchg.triggerevent('ue_textchange')

end event

type cb_mode_itfchg from uo_imflatbutton within w_publ_edit_index
integer x = 1029
integer width = 96
integer height = 164
integer taborder = 80
boolean bringtotop = true
string text = ">>"
boolean border = false
end type

event clicked;call super::clicked;IF THIS.Text = '<<' THEN
	THIS.Text = '>>'
	dw_index.Width = dw_uc.X+1 - dw_index.X
	dw_index.Y = dw_uc.Y
ELSE
	THIS.Text = '<<'
	dw_index.Width = dw_uc.X+1+dw_uc.Width - dw_index.X
	dw_index.Y = dw_uc.Y
END IF

PARENT.TriggerEvent('ue_mode_itfchg')

cb_mode_itfchg_b.Text = THIS.Text
cb_mode_itfchg_b.TriggerEvent('ue_textchange')

end event

type gb_1 from groupbox within w_publ_edit_index
boolean visible = false
integer x = 87
integer y = 844
integer width = 1184
integer height = 148
integer taborder = 50
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 134217739
boolean enabled = false
end type

type dw_uc from datawindow within w_publ_edit_index
event key pbm_dwnkey
event ue_dw_scroll pbm_vscroll
integer x = 1362
integer y = 292
integer width = 1495
integer height = 1372
integer taborder = 90
boolean enabled = false
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event key;PARENT.TRIGGEREVENT('USER_KEY')
boolean cancel_key=false

If key = KeyEnter!  or  key = Keydownarrow! Then //
	keybd_event ( 9, 0, 0 , 0 ) // 按下tab 
	keybd_event ( 9, 0, 2, 0 ) // 释放tab 
	cancel_key=true
elseif key = Keyuparrow! then 
	keybd_event ( 16, 0, 0 , 0 )
	keybd_event ( 9, 0, 0 , 0 )
	keybd_event ( 9, 0, 2, 0 ) 
	keybd_event ( 16, 0, 2, 0 ) 
	cancel_key=true
End If

this.ScrollToRow(this.getrow())	
if cancel_key then return 1


end event

event ue_dw_scroll;return 1
end event

event dberror;ins_sqlerrtext=sqlerrtext
return 1
end event

event retrieverow;IF not (retrieve_all or retrmode=0) and row>=onepage_rowlmno THEN RETURN 1
end event

event rowfocuschanged;IF modifyrow_no >0 AND dw_edit_mode THEN
	THIS.SETROW(modifyrow_no)
	THIS.ScrollToRow(modifyrow_no)
END IF
end event

event rowfocuschanging;IF dw_edit_mode THEN RETURN 1
end event

event rbuttondown;if not dw_edit_mode then return
Long ll_row,ll_column
ll_row = THIS.GetRow()
ll_column = THIS.GetColumn()

IF ll_row <= 0 THEN RETURN
IF ll_column <= 0 THEN RETURN

IF Left( THIS.Describe( dwo.Name+ ".coltype"),4) = 'date' THEN
	s_calender_arg s_calender
	
	s_calender.PointerX = xpos
	s_calender.PointerY = ypos
	s_calender.X = THIS.X + PARENT.X
	s_calender.Y = THIS.Y + PARENT.Y
	
	OpenWithParm(w_calendar,s_calender)
	THIS.SetItem(ll_row,ll_column,id_date_selected)
	
END IF




end event

type cb_retrieve from uo_imflatbutton within w_publ_edit_index
integer x = 535
integer width = 151
integer height = 164
integer taborder = 100
boolean bringtotop = true
string text = "刷新"
string normalpicname = "refresh.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;parent.triggerevent('retrieve_uc')
wf_index_uc()
end event

type cb_print from uo_imflatbutton within w_publ_edit_index
integer x = 837
integer width = 192
integer height = 164
integer taborder = 110
boolean bringtotop = true
string text = "预览&P"
string normalpicname = "print.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;//S_print_MSG LS_PRMSG
//
//LS_PRMSG.obj_dwNAME='dwrp_zl_lsdzl'
//LS_PRMSG.SHARE_DW=DW_UC
//LS_PRMSG.TAG_TEXT='零售点资料表'
//LS_PRMSG.SETUP_FLAG=0
//LS_PRMSG.PAGECH_FLAG=1
//
//Openwithparm(w_publ_preview,LS_PRMSG)
//
end event

type ln_bar from line within w_publ_edit_index
long linecolor = 268435456
integer linethickness = 4
integer beginx = -46
integer beginy = 172
integer endx = 1961
integer endy = 172
end type

type ln_bar2 from line within w_publ_edit_index
long linecolor = 16777215
integer linethickness = 4
integer beginx = -46
integer beginy = 176
integer endx = 1993
integer endy = 176
end type

type r_bar from rectangle within w_publ_edit_index
long linecolor = 16777215
integer linethickness = 4
long fillcolor = 1073741824
integer x = 2629
integer width = 146
integer height = 68
end type

event constructor;this.fillcolor = 14215660
this.linecolor = 14215660
this.x = -1
this.y = -1
this.height = ln_bar.beginy - 5

end event

type ln_1 from line within w_publ_edit_index
long linecolor = 268435456
integer linethickness = 4
integer beginy = 284
integer endx = 2016
integer endy = 284
end type

type ln_2 from line within w_publ_edit_index
long linecolor = 16777215
integer linethickness = 4
integer beginy = 288
integer endx = 2048
integer endy = 288
end type

type dw_index from u_dw_rbtnfilter within w_publ_edit_index
integer y = 292
integer width = 1362
integer height = 1372
integer taborder = 40
boolean bringtotop = true
boolean minbox = true
boolean hscrollbar = true
boolean vscrollbar = true
boolean hsplitscroll = true
end type

event clicked;call super::clicked;if row > 0 then
	this.setrow(row)
	if if_mlselect = 1 then
		if if_changeselect then
			this.selectrow(row,not this.isselected(row))
		else
			if_changeselect = true
		end if
	else
		if dw_edit_mode then return
		this.selectrow(0,false)
		this.selectrow(row,true)
	end if
end if










end event

event rowfocuschanged;call super::rowfocuschanged;if if_mlselect=1 then
	if currentrow <=0 then return
	if keydown(keycontrol!) then 
		if this.isselected(currentrow) then
			this.selectrow(currentrow,false)
			if_changeselect=false
		else
			if_changeselect=true
		end if
	else
		if not this.isselected(currentrow) then
			this.selectrow(currentrow,true)
			if_changeselect=false
		else
			if_changeselect=true
		end if
	end if
else
	if dw_edit_mode then return
	if currentrow <=0 then return
	this.selectrow(0,false)
	this.selectrow(currentrow,true)
	dw_uc.setrow(currentrow)
	dw_uc.scrolltorow (currentrow)
end if
end event

event constructor;call super::constructor;titleclick_sort_use=true  //单击标题排序功能开关


end event

event doubleclicked;call super::doubleclicked;IF mode=1 AND NOT dw_edit_mode THEN
	cb_choice.TRIGGEREVENT(CLICKED!)
END IF
end event

event dwnkey;call super::dwnkey;if keydown(Keyenter!) and keydown(keycontrol!) then return 1
PARENT.POSTEVENT('USER_KEY')
end event

