$PBExportHeader$u_dw_rbtnfilter.sru
forward
global type u_dw_rbtnfilter from datawindow
end type
type pointapi from structure within u_dw_rbtnfilter
end type
end forward

type pointapi from structure
	long		x
	long		y
end type

global type u_dw_rbtnfilter from datawindow
integer width = 1010
integer height = 316
integer taborder = 10
boolean livescroll = true
borderstyle borderstyle = stylelowered!
event ue_after_filter ( )
event ue_setlayout ( )
event dwnkey pbm_dwnkey
event rbbutton ( string arg_type,  string arg_name,  string arg_data,  long arg_row )
end type
global u_dw_rbtnfilter u_dw_rbtnfilter

type prototypes
FUNCTION long GetCursorPos(ref POINTAPI lpPoint) library 'user32.dll' 
end prototypes

type variables
boolean  RBUTTON_FILTER_USE=false
boolean  RBUTTON_SETPOSITION_USE=false
boolean  titleclick_sort_USE=false
boolean  setcolumn_visible_USE= true //false

boolean  autosave_FILTER_USE= true //false
boolean  autosave_sort_USE= true //false
boolean  autosave_setlayout_USE= true //false
boolean  autosave_columnvisible_USE= true //false

string ins_INIfile_name=''
string ins_opemp=''
long cardw_empid

string cur_DataObject = ''
string curDW_filterstr=''
string curDW_sortstr=''
string ins_mdfstr_column_visible=''
string ins_mdfstr_column_width=''
string ins_mdfstr_column_x=''
int ins_mdf_autosize = 0 
int ins_mdf_height = 0 


long arg_ins_xpos
long arg_ins_ypos
string arg_ins_dwtype
string arg_ins_dwname
string arg_ins_dwdata
long arg_ins_dwrow


boolean arg_SetPosition = false
string arg_Positionstr=''

String curDW_colfilter = ''

String Old_dwObject
end variables

forward prototypes
public function integer uf_string_deal (s_esq_tran arg_esq_tran, string column_name)
public function integer uf_decimal_deal (s_esq_tran arg_esq_tran, string column_name)
public function integer uf_datetime_deal (s_esq_tran arg_esq_tran, string column_name)
public function integer uf_read_profile_sort ()
public function integer uf_read_profile_filter ()
public function integer uf_read_profile_layout ()
public subroutine uf_getnewlayout ()
public subroutine uf_save_profile_layout ()
public subroutine uf_save_profile_filter ()
public subroutine uf_save_profile_sort ()
public subroutine uf_reset_layout ()
public function integer uf_string_deal_setp (s_esq_tran arg_esq_tran, string column_name)
end prototypes

event ue_after_filter();IF THIS.RowCount() > 0 THEN
	This.SelectRow(0,False)
	This.SelectRow(1,True)
	This.SetRow(1)
	THIS.TriggerEvent(RowFocusChanged!)
END IF






end event

event ue_setlayout();IF setcolumn_visible_USE = False THEN RETURN
IF This.DataObject = '' THEN RETURN

datastore ls_ds
ls_ds = Create datastore
ls_ds.DataObject = 'dw_rbtnfilter_setlayout'

datastore  ls_ds_ori
ls_ds_ori = Create datastore
ls_ds_ori.DataObject = This.DataObject


String ls_mdfstr //存放modify string
String des_1,des_2,szColumn,ls_dbname
Long nColumnIndex,nColumnCount,lRow,ls_i
s_dw_rbtnfilter_setlayout_rt ls_s_rt

//nColumnCount = Integer( this.Object.DataWindow.Column.Count)
//
//For nColumnIndex = 1 To nColumnCount
//	des_1= this.Describe( "#" + String(nColumnIndex) + ".Name") 
//	des_2= this.describe(des_1+ "_t.Text")
//	
//	szColumn = f_strip( des_2)
//	If szColumn <> "!" Then
//		lRow = ls_ds.InsertRow( 0)
//		ls_ds.SetItem( lRow, "ctitle", szColumn)
//		ls_ds.SetItem( lRow, "cname", des_1)
//		ls_ds.SetItem( lRow, "cshow_flag", long(this.describe(des_1+ ".Visible")))
//		
//		ls_ds.SetItem( lRow, "cwidth", long(this.describe(des_1+ ".width")))
//		ls_ds.SetItem( lRow, "nColumnIndex", nColumnIndex)
//	End If
//Next
///*
String ls_dwobjectstr,ls_object,ls_type
Long li_start,li_tab_pos

ls_dwobjectstr = This.Describe("Datawindow.Objects") + "~t"

li_start = 1
li_tab_pos = Pos(ls_dwobjectstr,   "~t",   li_start)

DO WHILE   li_tab_pos   >   0
	ls_object   =   Mid(ls_dwobjectstr,   li_start,   (li_tab_pos   -   li_start) )
	IF Pos(ls_object,'_t') > 0 THEN
		ls_object   =   Mid(ls_dwobjectstr,   li_start,   (li_tab_pos   -   li_start) - 2)
		ls_type = Lower(Left(This.Describe(ls_object+".Type"),4))
		
		IF ls_type = 'comp' Or ls_type = 'colu' THEN
			
			des_1 = This.Describe( ls_object + ".Name")
			des_2 = This.Describe(des_1+ "_t.Text")
			ls_dbname = This.Describe( ls_object + ".dbname")
			
			szColumn = f_strip( des_2)
			IF szColumn <> "!" THEN
				lRow = ls_ds.InsertRow( 0)
				ls_ds.SetItem( lRow, "ctitle", szColumn)
				ls_ds.SetItem( lRow, "cname", ls_dbname)
				ls_ds.SetItem( lRow, "name", des_1)
				ls_ds.SetItem( lRow, "cshow_flag", Long(This.Describe(des_1+ ".Visible")))
				
				ls_ds.SetItem( lRow, "cwidth", Long(This.Describe(des_1+ ".width")))
				ls_ds.SetItem( lRow, "nColumnIndex", nColumnIndex)
				
			END IF
		END IF
	END IF
	
	li_start = li_tab_pos   +   1
	li_tab_pos = Pos(ls_dwobjectstr,   "~t",   li_start)
LOOP
//*/

s_dw_rbtn_tran s_rb_tran
Long ll_height
Boolean lb_autosize

ll_height = Long(This.Describe("DataWindow.Detail.Height"))

IF This.Describe("DataWindow.Detail.Height.AutoSize") = 'yes' THEN
	lb_autosize = True
ELSE
	lb_autosize = False
END IF

s_rb_tran.dwr_ds = ls_ds
s_rb_tran.dwr_autosize = lb_autosize
s_rb_tran.dwr_height = ll_height

//---打开设置窗口
OpenWithParm(w_dw_rbtnfilter_setlayout,s_rb_tran)

ls_s_rt = Message.PowerObjectParm
//---处理设置
IF ls_s_rt.flag = 1 THEN //要保存修改
	ls_ds.SetFullState( ls_s_rt.b_changes )
	FOR ls_i = 1 To ls_ds.RowCount()
		ls_mdfstr = ls_mdfstr+ls_ds.Object.name[ls_i]+'.visible='+String(ls_ds.Object.cshow_flag[ls_i])+'~t'
	NEXT
	ins_mdfstr_column_visible = ls_mdfstr
	This.Modify( ins_mdfstr_column_visible)
	
	lb_autosize = ls_s_rt.b_autosize
	ll_height = ls_s_rt.l_height
	
	
	
	IF lb_autosize THEN
		This.Modify("DataWindow.Detail.Height.AutoSize = Yes")
		ll_height = Long(ls_ds_ori.Describe("DataWindow.Detail.Height"))
		This.Modify("DataWindow.Detail.Height = "+String(ll_height))
	ELSE
		This.Modify("DataWindow.Detail.Height.AutoSize = No")
		This.Modify("DataWindow.Detail.Height = "+String(ll_height))
	END IF
	
ELSEIF ls_s_rt.flag = 2 THEN //reset
	uf_reset_layout()
	uf_save_profile_layout()
END IF

Destroy ls_ds
destroy ls_ds_ori





end event

event dwnkey;if keydown(KeyF4!)  then //read layout
	uf_read_profile_filter()
	uf_read_profile_sort()
	//uf_read_profile_layout()
elseif keydown(KeyF5!)  then //save layout 不含列显示
	uf_save_profile_filter()
	uf_save_profile_sort()
	//uf_save_profile_layout()
elseif keydown(KeyF9!)  then //reset layout 不含列显示
	uf_reset_layout()
elseif keydown(KeyF2!)  then //save layout 不含列显示
	sys_dw_f2_win_name = parent.ClassName()
	this.triggerevent('ue_setlayout')
elseIF  KeyDown(KeyControl!)  And KeyDown(KeyC!) THEN //涂选 ctrl + C 复制
	//	messagebox('','ssss')
	//sys_DataWindowselected = This.Object.DataWindow.Selected.Data
	::Clipboard(This.Object.DataWindow.Selected.Data)
end if
	

end event

event rbbutton(string arg_type, string arg_name, string arg_data, long arg_row);String str_clickedobjecttype
String column_name,column_text_name
if arg_row<1 then return
IF rbutton_filter_use THEN
	String cur_data,ls_title
	
		str_clickedobjecttype = Lower(Left(arg_type,4))
	IF str_clickedobjecttype <> 'colu' THEN
		IF str_clickedobjecttype = 'data' THEN
			curdw_filterstr = ''
			THIS.SetFilter('')
			THIS.SetRedraw (FALSE)
			THIS.Filter()
			THIS.SetRedraw (TRUE)
		END IF
		GOTO csort
	END IF
	
	s_esq_tran ls_esq_tran
	pointapi lppoint1
	column_name = arg_name
	
	IF getcursorpos(lppoint1) <> 0  THEN
		ls_esq_tran.X = PixelsToUnits(lppoint1.X, xpixelstounits!)
		ls_esq_tran.Y = PixelsToUnits(lppoint1.Y, ypixelstounits!)
	ELSE
		environment   exerun_env
		GetEnvironment(exerun_env )
		ls_esq_tran.X = arg_ins_xpos +THIS.X + ( PixelsToUnits(exerun_env.ScreenWidth, xpixelstounits!) - THIS.Width ) / 2
		ls_esq_tran.Y = arg_ins_ypos +THIS.Y + ( PixelsToUnits(exerun_env.ScreenHeight, xpixelstounits!) - THIS.Height) / 2.5
	END IF
	
	ls_esq_tran.cur_filter_expr = curdw_filterstr
	ls_title = THIS.Describe(column_name+ "_t.text")
	
	IF ls_title = "!" THEN ls_title = ''
	column_name = arg_name
	ls_esq_tran.Title = ls_title
	
	IF arg_row > 0 THEN
		cur_data = String(arg_data)
	END IF	
	
	//分别处理不同类型
	CHOOSE CASE Left( THIS.Describe( arg_name+ ".coltype"),4)
		CASE "char"
			ls_esq_tran.cur_data = cur_data
			If (uf_string_deal(ls_esq_tran,column_name)) = 0 THEN RETURN
		CASE "date","time"
			ls_esq_tran.dt_data = DateTime(Date(Left(cur_data,10)),Time(Right(cur_data,8)))
			If (uf_datetime_deal(ls_esq_tran,column_name)) = 0 THEN RETURN
		CASE ELSE
			ls_esq_tran.num_data = dec(cur_data)
			If (uf_decimal_deal(ls_esq_tran,column_name)) = 0 THEN RETURN
	END CHOOSE
	
	THIS.SetFilter(curdw_filterstr)
	
	THIS.SetRedraw (FALSE)
	THIS.Filter()
	THIS.TriggerEvent("ue_after_filter")
	THIS.SetRedraw (TRUE)
END IF

csort:

IF titleclick_sort_use THEN
	str_clickedobjecttype = Left(arg_type,4)
	
	IF str_clickedobjecttype = 'text' THEN
		column_text_name = arg_name
		
		IF Len(column_text_name) >= 3 AND Right(column_text_name,2) = '_t' THEN
			column_name = Left(column_text_name,Len(column_text_name) - 2)
		ELSE
			GOTO cend
		END IF
		
		IF Left(Describe(column_name+'.type'),4) <> 'colu' AND &
			Left(Describe(column_name+'.type'),4) <> 'comp' THEN
			RETURN
		END IF
		IF curDW_sortstr = column_name+' A ' THEN
			curDW_sortstr = column_name+' D '
		ELSE
			curDW_sortstr = column_name+' A '
		END IF
		
	ELSE
		curDW_sortstr = ''
	END IF
	
	IF curDW_sortstr <> '' THEN
		THIS.SetSort(curDW_sortstr)
		THIS.SetRedraw (FALSE)
		THIS.Sort()
		THIS.SetRedraw (TRUE)
	END IF
END IF

cend:
//IF THIS.RowCount() > 0 THEN
//	THIS.SetRow(1)
//	THIS.ScrollToRow(1)
//	THIS.SelectRow(0,FALSE)
//	THIS.SelectRow(1,TRUE)
//END IF




end event

public function integer uf_string_deal (s_esq_tran arg_esq_tran, string column_name);////uf_string_deal
//OpenWithParm(w_publ_inputexpr,arg_esq_tran)
//arg_esq_tran = Message.PowerObjectParm
//
//CHOOSE CASE arg_esq_tran.comp_op
//	CASE '包含'
//		arg_esq_tran.comp_op = ' LIKE '
//	CASE '不包含'
//		arg_esq_tran.comp_op = ' NOT LIKE '
//	CASE '等于'
//		arg_esq_tran.comp_op = ' = '
//	CASE '不等于'
//		arg_esq_tran.comp_op = ' <> '
//	CASE '大于'
//		arg_esq_tran.comp_op = ' > '
//	CASE '小于'
//		arg_esq_tran.comp_op = ' < '
//	CASE '大于等于'
//		arg_esq_tran.comp_op = ' >= '
//	CASE '小于等于'
//		arg_esq_tran.comp_op = ' <= '
//END CHOOSE
//
//IF arg_esq_tran.return_flag = 4 THEN
//	IF NOT arg_esq_tran.DIST_BOOLEAN THEN
//		arg_Positionstr = "pos(upper("+column_name+"), '"+Upper(arg_esq_tran.cur_data)+"') > 0 "
//	ELSE
//		arg_Positionstr = "pos("+column_name+", '"+arg_esq_tran.cur_data+"') > 0 "
//	END IF
//	arg_SetPosition = TRUE
//ELSE
//	
//	IF arg_esq_tran.comp_op = ' LIKE ' OR arg_esq_tran.comp_op = ' NOT LIKE ' THEN
//		IF Pos(arg_esq_tran.cur_data,'%') = 0 THEN
//			IF Trim(arg_esq_tran.cur_data) = '' THEN
//				arg_esq_tran.cur_data = '%'
//			ELSE
//				arg_esq_tran.cur_data = '%'+arg_esq_tran.cur_data+'%'
//			END IF
//		END IF
//	END IF
//	
//	arg_SetPosition = FALSE
////	IF Pos(arg_esq_tran.cur_data,'%') = 0 THEN
////		IF Trim(arg_esq_tran.cur_data) = '' THEN
////			arg_esq_tran.cur_data = '%'
////		ELSE
////			arg_esq_tran.cur_data = '%'+arg_esq_tran.cur_data+'%'
////		END IF
////	END IF
//	
//	CHOOSE CASE arg_esq_tran.return_flag
//		CASE 0
//			RETURN 0
//		CASE 1
////			IF arg_esq_tran.cur_data = '' THEN
////				IF Trim(curDW_filterstr) = '' THENx RETURN 1
////				IF NOT arg_esq_tran.DIST_BOOLEAN THEN
////					curDW_filterstr = "( UPPER("+column_name+" ) " + arg_esq_tran.comp_op +  " UPPER('"+arg_esq_tran.cur_data+"')) "
////				ELSE
////					curDW_filterstr = "( "+column_name + arg_esq_tran.comp_op + " '"+arg_esq_tran.cur_data+"') "
////				END IF
////				
////			ELSE
//				IF Trim(curDW_filterstr) = '' THEN
//					IF NOT arg_esq_tran.DIST_BOOLEAN THEN
//						curDW_filterstr = "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+arg_esq_tran.cur_data+"')) "
//					ELSE
//						curDW_filterstr = "( "+column_name + arg_esq_tran.comp_op + " '"+arg_esq_tran.cur_data+"' )"
//					END IF
//				ELSE
//					
//					IF NOT arg_esq_tran.DIST_BOOLEAN THEN
//						curDW_filterstr = curDW_filterstr+" and ( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+arg_esq_tran.cur_data+"')) "
//					ELSE
//						curDW_filterstr = curDW_filterstr+" and ( "+column_name + arg_esq_tran.comp_op + " '"+arg_esq_tran.cur_data+"' )"
//					END IF
//					
//				END IF
////			END IF
//		CASE 2
////			IF arg_esq_tran.cur_data = '' THEN
////				IF Trim(curDW_filterstr) = '' THEN RETURN 1
////				curDW_filterstr = ''
////			ELSE
//				IF NOT arg_esq_tran.DIST_BOOLEAN THEN
//					curDW_filterstr = "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+arg_esq_tran.cur_data+"')) "
//				ELSE
//					curDW_filterstr = "("+column_name + arg_esq_tran.comp_op + " '"+arg_esq_tran.cur_data+"') "
//				END IF
////			END IF
//			
//		CASE ELSE
//			RETURN 0
//	END CHOOSE
//END IF
//RETURN 1
//
//uf_string_deal
OpenWithParm(w_publ_inputexpr,arg_esq_tran)
arg_esq_tran = Message.PowerObjectParm

string ls_comp_op
ls_comp_op = arg_esq_tran.comp_op

Choose Case arg_esq_tran.comp_op
	Case '包含'
		arg_esq_tran.comp_op = ' LIKE '
	Case '不包含'
		arg_esq_tran.comp_op = ' NOT LIKE '
	Case '等于'
		arg_esq_tran.comp_op = ' = '
	Case '不等于'
		arg_esq_tran.comp_op = ' <> '
	Case '大于'
		arg_esq_tran.comp_op = ' > '
	Case '小于'
		arg_esq_tran.comp_op = ' < '
	Case '大于等于'
		arg_esq_tran.comp_op = ' >= '
	Case '小于等于'
		arg_esq_tran.comp_op = ' <= '
End Choose

String ls_enter
Long ll_pos
String ls_filter,ls_filterstr,ls_cur_data,ls_filter_1,ls_filterstr_1
ls_enter = '~r~n'
ls_cur_data = arg_esq_tran.cur_data

If arg_esq_tran.return_flag = 4 Then
	If Not arg_esq_tran.DIST_BOOLEAN Then
		arg_Positionstr = "pos(upper("+column_name+"), '"+Upper(arg_esq_tran.cur_data)+"') > 0 "
	Else
		arg_Positionstr = "pos("+column_name+", '"+arg_esq_tran.cur_data+"') > 0 "
	End If
	arg_SetPosition = True
Else
	
	ll_pos = Pos(arg_esq_tran.cur_data,ls_enter)
	
	If ll_pos = 0 Then
		If arg_esq_tran.comp_op = ' LIKE ' Or arg_esq_tran.comp_op = ' NOT LIKE ' Then
			If Pos(arg_esq_tran.cur_data,'%') = 0 Then
				If Trim(arg_esq_tran.cur_data) = '' Then
					arg_esq_tran.cur_data = '%'
				Else
					arg_esq_tran.cur_data = '%'+arg_esq_tran.cur_data+'%'
				End If
			End If
		End If
	End If
	
	arg_SetPosition = False
	//	IF Pos(arg_esq_tran.cur_data,'%') = 0 THEN
	//		IF Trim(arg_esq_tran.cur_data) = '' THEN
	//			arg_esq_tran.cur_data = '%'
	//		ELSE
	//			arg_esq_tran.cur_data = '%'+arg_esq_tran.cur_data+'%'
	//		END IF
	//	END IF
	
	
	IF Old_dwObject <> THIS.DATAOBJECT THEN
		IF arg_esq_tran.return_flag <> 0 THEN arg_esq_tran.return_flag = 2
	END IF
	
	Old_dwObject = THIS.DATAOBJECT

	
	
	
	Choose Case arg_esq_tran.return_flag
		Case 0
			Return 0
		Case 1
			
			If ll_pos = 0 Then
				If Trim(curDW_filterstr) = '' Then
					If Not arg_esq_tran.DIST_BOOLEAN Then
						curDW_filterstr = "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+arg_esq_tran.cur_data+"')) "
						curDW_colfilter = '['+UPPER(arg_esq_tran.title)+']'+' '+ls_comp_op+' “'+UPPER(ls_cur_data)+'”'+ls_enter
						
					Else
						curDW_filterstr = "( "+column_name + arg_esq_tran.comp_op + " '"+arg_esq_tran.cur_data+"' )"
						curDW_colfilter = '['+arg_esq_tran.title+']'+' '+ls_comp_op+' “'+ls_cur_data+'”'+ls_enter
					End If
				Else
					
					If Not arg_esq_tran.DIST_BOOLEAN Then
						curDW_filterstr = curDW_filterstr+" and ( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+arg_esq_tran.cur_data+"')) "
						curDW_colfilter = curDW_colfilter+ '['+UPPER(arg_esq_tran.title)+']'+' '+ls_comp_op+' “'+UPPER(ls_cur_data)+'”'+ls_enter
						
					Else
						curDW_filterstr = curDW_filterstr+" and ( "+column_name + arg_esq_tran.comp_op + " '"+arg_esq_tran.cur_data+"' )"
						curDW_colfilter = curDW_colfilter+ '['+arg_esq_tran.title+']'+' '+ls_comp_op+' “'+ls_cur_data+'”'+ls_enter
					End If
					
				End If
			Else
				Do While ll_pos > 0
					
					If arg_esq_tran.comp_op = ' LIKE ' Or arg_esq_tran.comp_op = ' NOT LIKE ' Then
						If Pos(Left(arg_esq_tran.cur_data,ll_pos - 1),'%') = 0 Then
							If Trim(Left(arg_esq_tran.cur_data,ll_pos - 1)) = '' Then
								ls_filter = '%'
								ls_filter_1 = ''
							Else
								ls_filter = '%'+trim(Left(arg_esq_tran.cur_data,ll_pos - 1))+'%'
								ls_filter_1 = trim(Left(arg_esq_tran.cur_data,ll_pos - 1))
							End If
						End If
					Else
						ls_filter = trim(Left(arg_esq_tran.cur_data,ll_pos - 1))
						ls_filter_1 = trim(Left(arg_esq_tran.cur_data,ll_pos - 1))
					End If
					
					
					If Not arg_esq_tran.DIST_BOOLEAN Then
						ls_filterstr_1 = ls_filterstr_1 + '['+UPPER(arg_esq_tran.title)+']'+' '+ls_comp_op+' “'+UPPER(ls_filter_1)+'”'+ls_enter
						If Trim(ls_filterstr) = '' Then
							ls_filterstr = ls_filterstr + "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+ls_filter+"')) "
						Else
							ls_filterstr = ls_filterstr + " or ( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+ls_filter+"')) "
						End If
					Else
						ls_filterstr_1 = ls_filterstr_1 + '['+arg_esq_tran.title+']'+' '+ls_comp_op+' “'+ls_filter_1+'”'+ls_enter
						If Trim(ls_filterstr) = '' Then
							ls_filterstr = ls_filterstr + "("+column_name + arg_esq_tran.comp_op + " '"+ls_filter+"') "
						Else
							ls_filterstr = ls_filterstr + "or ("+column_name + arg_esq_tran.comp_op + " '"+ls_filter+"') "
						End If
					End If
					
					
					arg_esq_tran.cur_data = Mid(arg_esq_tran.cur_data, ll_pos + Len(ls_enter))
					ll_pos = Pos(arg_esq_tran.cur_data,ls_enter)
				Loop
				
				If Trim(arg_esq_tran.cur_data) <> '' Then
					
					If arg_esq_tran.comp_op = ' LIKE ' Or arg_esq_tran.comp_op = ' NOT LIKE ' Then
						If Pos(arg_esq_tran.cur_data,'%') = 0 Then
							ls_filter = '%'+arg_esq_tran.cur_data+'%'
							ls_filter_1 = arg_esq_tran.cur_data
						End If
					Else
						ls_filter = arg_esq_tran.cur_data
						ls_filter_1 = arg_esq_tran.cur_data
					End If
					
					If Trim(ls_filterstr) <> '' Then
						ls_filterstr = ls_filterstr + ' or '
					End If
					
					If Not arg_esq_tran.DIST_BOOLEAN Then
						ls_filterstr = ls_filterstr + "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+ls_filter+"')) "
						ls_filterstr_1 = ls_filterstr_1 + '['+UPPER(arg_esq_tran.title)+']'+' '+ls_comp_op+' “'+UPPER(ls_filter_1)+'”'+ls_enter
					Else
						ls_filterstr = ls_filterstr + "("+column_name + arg_esq_tran.comp_op + " '"+ls_filter+"') "
						ls_filterstr_1 = ls_filterstr_1 + '['+arg_esq_tran.title+']'+' '+ls_comp_op+' “'+ls_filter_1+'”'+ls_enter
					End If
					
				End If
				
				ls_filterstr = "(" + ls_filterstr + ")"
				
				
				If Trim(curDW_filterstr) = '' Then
					curDW_filterstr = ls_filterstr
					curDW_colfilter = ls_filterstr_1
					
				else
					curDW_filterstr = curDW_filterstr + " and "+ls_filterstr
					curDW_colfilter = ls_filterstr_1
					
				end if
				
			End If
			
			
		Case 2
			If ll_pos = 0 Then
				If Not arg_esq_tran.DIST_BOOLEAN Then
					curDW_filterstr = "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+arg_esq_tran.cur_data+"')) "
					curDW_colfilter = '['+UPPER(arg_esq_tran.title)+']'+' '+ls_comp_op+' “'+UPPER(ls_cur_data)+'”'+ls_enter
				Else
					curDW_filterstr = "("+column_name + arg_esq_tran.comp_op + " '"+arg_esq_tran.cur_data+"') "
					curDW_colfilter = '['+arg_esq_tran.title+']'+' '+ls_comp_op+' “'+ls_cur_data+'”'+ls_enter
				End If
			Else
				
				curDW_filterstr = ''
				curDW_colfilter = ''
				Do While ll_pos > 0
					
					If arg_esq_tran.comp_op = ' LIKE ' Or arg_esq_tran.comp_op = ' NOT LIKE ' Then
						If Pos(Left(arg_esq_tran.cur_data,ll_pos - 1),'%') = 0 Then
							If Trim(Left(arg_esq_tran.cur_data,ll_pos - 1)) = '' Then
								ls_filter = '%'
								ls_filter_1 = ''
							Else
								ls_filter = '%'+trim(Left(arg_esq_tran.cur_data,ll_pos - 1))+'%'
								ls_filter_1 = trim(Left(arg_esq_tran.cur_data,ll_pos - 1))
							End If
						End If
					Else
						ls_filter = trim(Left(arg_esq_tran.cur_data,ll_pos - 1))
						ls_filter_1 = trim(Left(arg_esq_tran.cur_data,ll_pos - 1))
					End If
					
					
					If Not arg_esq_tran.DIST_BOOLEAN Then
						curDW_colfilter = curDW_colfilter+ '['+UPPER(arg_esq_tran.title)+']'+' '+ls_comp_op+' “'+UPPER(ls_filter_1)+'”'+ls_enter
						If Trim(curDW_filterstr) = '' Then							
							curDW_filterstr = curDW_filterstr + "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+ls_filter+"')) "
							
						Else
							IF arg_esq_tran.comp_op = ' NOT LIKE ' THEN
								curDW_filterstr = curDW_filterstr + " and ( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+ls_filter+"')) "
							ELSE
								curDW_filterstr = curDW_filterstr + " or ( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+ls_filter+"')) "
							END IF
						End If
					Else
						curDW_colfilter = ls_filterstr_1 + '['+arg_esq_tran.title+']'+' '+ls_comp_op+' “'+ls_filter_1+'”'+ls_enter
						If Trim(curDW_filterstr) = '' Then
							curDW_filterstr = curDW_filterstr + "("+column_name + arg_esq_tran.comp_op + " '"+ls_filter+"') "
						Else
							IF arg_esq_tran.comp_op = ' NOT LIKE ' THEN
								curDW_filterstr = curDW_filterstr + "AND ("+column_name + arg_esq_tran.comp_op + " '"+ls_filter+"') "
							ELSE
								curDW_filterstr = curDW_filterstr + "or ("+column_name + arg_esq_tran.comp_op + " '"+ls_filter+"') "						
							END IF
						End If
					End If
					
					
					arg_esq_tran.cur_data = Mid(arg_esq_tran.cur_data, ll_pos + Len(ls_enter))
					ll_pos = Pos(arg_esq_tran.cur_data,ls_enter)
				Loop
				
				If Trim(arg_esq_tran.cur_data) <> '' Then
					
					If arg_esq_tran.comp_op = ' LIKE ' Or arg_esq_tran.comp_op = ' NOT LIKE ' Then
						If Pos(arg_esq_tran.cur_data,'%') = 0 Then
							ls_filter = '%'+arg_esq_tran.cur_data+'%'
							ls_filter_1 = arg_esq_tran.cur_data
						End If
					Else
						ls_filter = arg_esq_tran.cur_data
						ls_filter_1 = arg_esq_tran.cur_data
					End If
					
					If Trim(curDW_filterstr) <> '' Then
						IF arg_esq_tran.comp_op = ' NOT LIKE ' THEN
							curDW_filterstr = curDW_filterstr + ' and '
						ELSE
							curDW_filterstr = curDW_filterstr + ' or '
						END IF
						
					End If
					
					If Not arg_esq_tran.DIST_BOOLEAN Then
						curDW_filterstr = curDW_filterstr + "( UPPER("+column_name+" ) "  + arg_esq_tran.comp_op + " UPPER('"+ls_filter+"')) "
						curDW_colfilter = curDW_colfilter+ '['+UPPER(arg_esq_tran.title)+']'+' '+ls_comp_op+' “'+UPPER(ls_filter_1)+'”'+ls_enter
					Else
						curDW_filterstr = curDW_filterstr + "("+column_name + arg_esq_tran.comp_op + " '"+ls_filter+"') "
						curDW_colfilter = curDW_colfilter+ '['+arg_esq_tran.title+']'+' '+ls_comp_op+' “'+ls_filter_1+'”'+ls_enter
					End If
					
				End If
				
				curDW_filterstr = "(" + curDW_filterstr + ")"
				
			End If
			
			
		Case Else
			Return 0
	End Choose
End If
Return 1













end function

public function integer uf_decimal_deal (s_esq_tran arg_esq_tran, string column_name);//uf_decimal_deal
OpenWithParm(w_publ_input_num,arg_esq_tran)
arg_esq_tran = Message.PowerObjectParm

Boolean lb_ifarea
lb_ifarea = arg_esq_tran.if_area //---是否按范围选择

IF lb_ifarea = FALSE THEN
	CHOOSE CASE arg_esq_tran.return_flag
		CASE 0
			RETURN 0
		CASE 1 //补充
			IF Trim(curDW_filterstr) = '' THEN
				curDW_filterstr = '('+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+")"
				IF arg_esq_tran.ELSE_BOOLEAN THEN curDW_filterstr = ' ( NOT '+curDW_filterstr +') '
			ELSE
				IF arg_esq_tran.ELSE_BOOLEAN THEN
					curDW_filterstr = curDW_filterstr+" and ( NOT "+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+") "
				ELSE
					curDW_filterstr = curDW_filterstr+" and ( "+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+") "
				END IF
				
			END IF
		CASE 2 //新查询
			curDW_filterstr = '('+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+")"
			IF arg_esq_tran.ELSE_BOOLEAN THEN curDW_filterstr = '( NOT '+curDW_filterstr +')'
			
		CASE ELSE
			
	END CHOOSE
ELSE
	CHOOSE CASE arg_esq_tran.return_flag
		CASE 0
			RETURN 0
		CASE 1 //补充
			IF Trim(curDW_filterstr) = '' THEN
				curDW_filterstr = '('+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+' and '+ column_name+arg_esq_tran.comp_opb+String(arg_esq_tran.num_datab)+")"
				IF arg_esq_tran.ELSE_BOOLEAN THEN curDW_filterstr = ' ( NOT '+curDW_filterstr +') '
			ELSE
				IF arg_esq_tran.ELSE_BOOLEAN THEN
					curDW_filterstr = curDW_filterstr+" and ( NOT "+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+' and '+ column_name+arg_esq_tran.comp_opb+String(arg_esq_tran.num_datab)+") "
				ELSE
					curDW_filterstr = curDW_filterstr+" and ( "+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+' and '+ column_name+arg_esq_tran.comp_opb+String(arg_esq_tran.num_datab)+") "
				END IF
				
			END IF
		CASE 2 //新查询
			curDW_filterstr = '('+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.num_data)+' and '+ column_name+arg_esq_tran.comp_opb+String(arg_esq_tran.num_datab)+")"
			IF arg_esq_tran.ELSE_BOOLEAN THEN curDW_filterstr = '( NOT '+curDW_filterstr +')'
			
		CASE ELSE
			
	END CHOOSE	
END IF

RETURN 1
end function

public function integer uf_datetime_deal (s_esq_tran arg_esq_tran, string column_name);//////////////////////////////////////////////////////////////////////////// //
//uf_datetime_deal(arg_esq_tran,column_name)
//右键查询 - 时间
//修改人：谢莫锋
//时间：2003-06-11
//参数：arg_esq_tran：结构参数，column_name：列名
///////////////////////////////////////////////////////////////////////////////

String ls_enddate
String ls_firstdate
String ls_enddate_end
String ls_firstdate_end
String ls_firstdate_area
String ls_enddate_area
Long ls_timeinuse,ls_timeinuse_end
Boolean lb_ifarea = FALSE

OpenWithParm(w_publ_input_datetime,arg_esq_tran)
arg_esq_tran = Message.PowerObjectParm

ls_timeinuse = arg_esq_tran.b_timeinuse //---时间有效标记
ls_timeinuse_end = arg_esq_tran.b_timeinuse_end //---时间有效标记

lb_ifarea = arg_esq_tran.if_area //---是否按范围选择

IF lb_ifarea = FALSE THEN
	IF ls_timeinuse = 1 THEN //1.如果时间有效的时候
		CHOOSE CASE arg_esq_tran.return_flag
			CASE 0
				RETURN 0
			CASE 1 //补充
				IF Trim(curdw_filterstr) = '' THEN
					curdw_filterstr = '('+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.dt_data,'yyyy-mm-dd hh:mm:ss')+")"
					IF arg_esq_tran.else_boolean THEN
						curdw_filterstr = ' ( not '+curdw_filterstr +') '
					END IF
				ELSE
					IF arg_esq_tran.else_boolean THEN
						curdw_filterstr = curdw_filterstr+" and ( not "+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.dt_data,'yyyy-mm-dd hh:mm:ss')+") "
					ELSE
						curdw_filterstr = curdw_filterstr+" and ( "+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.dt_data,'yyyy-mm-dd hh:mm:ss')+") "
					END IF
				END IF
			CASE 2 //新查询
				curdw_filterstr = '('+column_name+arg_esq_tran.comp_op+String(arg_esq_tran.dt_data,'yyyy-mm-dd hh:mm:ss')+")"
				IF arg_esq_tran.else_boolean THEN
					curdw_filterstr = '( not '+curdw_filterstr +')'
				END IF
			CASE ELSE
		END CHOOSE
	ELSE //--------2.如果时间无效的时候	
		ls_firstdate = String(arg_esq_tran.dt_data,'yyyy-mm-dd hh:mm:ss') //一天的开始时间
		ls_enddate = String(DateTime(Date(arg_esq_tran.dt_data),Time('23:59:59')),'yyyy-mm-dd hh:mm:ss') //一天的结束时间
		
		
		
		CHOOSE CASE arg_esq_tran.return_flag
			CASE 0
				RETURN 0
			CASE 1 //补充
				IF Trim(curdw_filterstr) = '' THEN
					IF arg_esq_tran.comp_op = '=' THEN
						curdw_filterstr = '('+column_name+'>='+ls_firstdate+' and '+column_name+'<='+ls_enddate+')'
					ELSEIF arg_esq_tran.comp_op = '>' THEN
						curdw_filterstr = '('+column_name+'>'+ls_enddate+')'
					ELSEIF arg_esq_tran.comp_op = '>=' THEN
						curdw_filterstr = '('+column_name+'>'+ls_firstdate+')'
					ELSEIF arg_esq_tran.comp_op = '<' THEN
						curdw_filterstr = '('+column_name+'<'+ls_firstdate+')'
					ELSEIF arg_esq_tran.comp_op = '<=' THEN
						curdw_filterstr = '('+column_name+'<='+ls_enddate+')'
					END IF
					IF arg_esq_tran.else_boolean THEN curdw_filterstr = '( not '+curdw_filterstr +')'
				ELSE //不为空的时候
					IF arg_esq_tran.comp_op = '=' THEN
						IF arg_esq_tran.else_boolean THEN
							curdw_filterstr = curdw_filterstr+' and not ('+column_name+'>='+ls_firstdate+' and '+column_name+'<='+ls_enddate+')'
						ELSE
							curdw_filterstr = curdw_filterstr+' and ('+column_name+'>='+ls_firstdate+' and '+column_name+'<='+ls_enddate+')'
						END IF
					ELSEIF arg_esq_tran.comp_op = '>' THEN
						IF arg_esq_tran.else_boolean THEN
							curdw_filterstr = curdw_filterstr+' and not ('+column_name+'>'+ls_enddate+')'
						ELSE
							curdw_filterstr = curdw_filterstr+' and ('+column_name+'>'+ls_enddate+')'
						END IF
					ELSEIF arg_esq_tran.comp_op = '>=' THEN
						IF arg_esq_tran.else_boolean THEN
							curdw_filterstr = curdw_filterstr+' and not ('+column_name+'>'+ls_firstdate+')'
						ELSE
							curdw_filterstr = curdw_filterstr+' and ('+column_name+'>'+ls_firstdate+')'
						END IF
					ELSEIF arg_esq_tran.comp_op = '<' THEN
						IF arg_esq_tran.else_boolean THEN
							curdw_filterstr = curdw_filterstr+' and not ('+column_name+'<'+ls_firstdate+')'
						ELSE
							curdw_filterstr = curdw_filterstr+' and ('+column_name+'<'+ls_firstdate+')'
						END IF
					ELSEIF arg_esq_tran.comp_op = '<=' THEN
						IF arg_esq_tran.else_boolean THEN
							curdw_filterstr = curdw_filterstr+' and not ('+column_name+'<='+ls_enddate+')'
						ELSE
							curdw_filterstr = curdw_filterstr+' and ('+column_name+'<='+ls_enddate+')'
						END IF
					END IF

				END IF
			CASE 2 //新查询
				IF arg_esq_tran.comp_op = '=' THEN
					curdw_filterstr = '('+column_name+'>='+ls_firstdate+' and '+column_name+'<='+ls_enddate+')'
				ELSEIF arg_esq_tran.comp_op = '>' THEN
					curdw_filterstr = '('+column_name+'>'+ls_enddate+')'
				ELSEIF arg_esq_tran.comp_op = '>=' THEN
					curdw_filterstr = '('+column_name+'>'+ls_firstdate+')'
				ELSEIF arg_esq_tran.comp_op = '<' THEN
					curdw_filterstr = '('+column_name+'<'+ls_firstdate+')'
				ELSEIF arg_esq_tran.comp_op = '<=' THEN
					curdw_filterstr = '('+column_name+'<='+ls_enddate+')'
				END IF
				IF arg_esq_tran.else_boolean THEN curdw_filterstr = '( not '+curdw_filterstr +')'
			CASE ELSE
		END CHOOSE
	END IF
ELSE
	ls_firstdate = String(arg_esq_tran.dt_data,'yyyy-mm-dd hh:mm:ss') //一天的开始时间
	
	ls_firstdate_end = String(arg_esq_tran.dt_date_end,'yyyy-mm-dd hh:mm:ss') //一天的开始时间
	ls_enddate_end = String(DateTime(Date(arg_esq_tran.dt_date_end),Time('23:59:59')),'yyyy-mm-dd hh:mm:ss') //一天的结束时间
	
	ls_firstdate_area = 	ls_firstdate
	
	IF ls_timeinuse_end = 1 THEN
		ls_enddate_area = 	ls_firstdate_end
	ELSE
		ls_enddate_area = 	ls_enddate_end
	END IF
	
	CHOOSE CASE arg_esq_tran.return_flag
		CASE 0
			RETURN 0
		CASE 1 //补充
			IF Trim(curdw_filterstr) = '' THEN
				curdw_filterstr = '('+column_name+'>='+ls_firstdate_area+' and '+column_name+'<='+ls_enddate_area+")"
				IF arg_esq_tran.else_boolean THEN
					curdw_filterstr = ' ( not '+curdw_filterstr +') '
				END IF
			ELSE
				IF arg_esq_tran.else_boolean THEN
					curdw_filterstr = curdw_filterstr+" and not ( "+column_name+'>='+ls_firstdate_area+' and '+column_name+'<='+ls_enddate_area+")"
				ELSE
					curdw_filterstr = curdw_filterstr+" and ( "+column_name+'>='+ls_firstdate_area+' and '+column_name+'<='+ls_enddate_area+")"
				END IF
			END IF
		CASE 2 //新查询
			curdw_filterstr = '('+column_name+'>='+ls_firstdate_area+' and '+column_name+'<='+ls_enddate_area+")"
			IF arg_esq_tran.else_boolean THEN
				curdw_filterstr = '( not '+curdw_filterstr +')'
			END IF
		CASE ELSE
	END CHOOSE
END IF

RETURN 1
end function

public function integer uf_read_profile_sort ();//
//从INI读取用户的默认习惯  sort
//

IF cur_DataObject = '' THEN RETURN 0

THIS.SetRedraw(FALSE)

IF titleclick_sort_USE AND autosave_sort_use THEN
	SELECT dwnSyntax_sort INTO :curDW_sortstr
		FROM sys_user_dwnSyntax
		WHERE empid = :cardw_empid
		AND dwname = :cur_DataObject;
	IF sqlca.SQLCode <> 0 THEN
		curDW_sortstr = ''
	END IF
	//	curDW_sortstr=ProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'curDW_sortstr', '')
	THIS.SetSort(curDW_sortstr)
	THIS.Sort()
END IF

THIS.SetRedraw(TRUE)



RETURN 0




end function

public function integer uf_read_profile_filter ();//
//从INI读取用户的默认习惯
//

IF cur_DataObject = '' THEN RETURN 0

THIS.SetRedraw(FALSE)
IF RBUTTON_FILTER_USE AND autosave_filter_use THEN
	SELECT dwnSyntax_filter INTO :curdw_filterstr
		FROM sys_user_dwnSyntax
		WHERE empid = :cardw_empid
		AND dwname = :cur_DataObject;
	IF sqlca.SQLCode <> 0 THEN
		curdw_filterstr = ''
	END IF
	
	//	curDW_filterstr=ProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'curDW_filterstr', '')
	
	THIS.SetFilter(curdw_filterstr)
	THIS.Filter()
	
END IF

THIS.SetRedraw(TRUE)


RETURN 0






end function

public function integer uf_read_profile_layout ();//
//读取用户的默认习惯-布局
//

IF cur_dataobject = '' THEN RETURN 0

string arg_msg, tmp
oleobject obj, parm
if (setcolumn_visible_USE or autosave_setlayout_USE) then
	parm = FXAppCom.CreatePbDictionary()
	parm.SetString('token', app_token_fx)
	parm.SetString('dwname', cur_dataobject)
	obj = FXAppCom.GetDwLayout(parm, ref arg_msg)
	if (arg_msg = '') then
		ins_mdfstr_column_visible = obj.GetString('column_visible')
		ins_mdfstr_column_width = obj.GetString('column_width')
		ins_mdfstr_column_x = obj.GetString('column_x')
		ins_mdf_autosize = obj.GetInt('column_autosize')
		ins_mdf_height = obj.GetInt('column_detail_height')
		
		tmp = This.Modify(ins_mdfstr_column_visible)
		tmp = This.Modify(ins_mdfstr_column_width)
		tmp = This.Modify(ins_mdfstr_column_x)
	else
		ins_mdfstr_column_visible = ''
		ins_mdfstr_column_width = ''
		ins_mdfstr_column_x = ''
		ins_mdf_autosize = - 1
		ins_mdf_height = 0
		return 0
	end if

	This.SetRedraw(False)
	
	//IF setcolumn_visible_USE And autosave_columnvisible_USE THEN
	//	SELECT dwnSyntax_layout_column_visible
	//		INTO :ins_mdfstr_column_visible
	//		FROM sys_user_dwnSyntax
	//		WHERE empid = :cardw_empid
	//		And dwname = :cur_dataobject;
	//	IF sqlca.SQLCode <> 0 THEN
	//		ins_mdfstr_column_visible = ''
	//	END IF
	//	
	//	//	ins_mdfstr_column_visible=ProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'ins_mdfstr_column_visible', '')
	//	This.Modify(ins_mdfstr_column_visible)
	//END IF
	
	//IF  autosave_setlayout_USE THEN
	//	SELECT dwnSyntax_layout_column_width,dwnSyntax_layout_column_x
	//		INTO :ins_mdfstr_column_width,:ins_mdfstr_column_x
	//		FROM sys_user_dwnSyntax
	//		WHERE empid = :cardw_empid
	//		And dwname = :cur_dataobject;
	//	IF sqlca.SQLCode <> 0 THEN
	//		ins_mdfstr_column_width = ''
	//		ins_mdfstr_column_x = ''
	//	END IF
	//	
	//	
	//	//	ins_mdfstr_column_width=ProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'ins_mdfstr_column_width', '')
	//	//	ins_mdfstr_column_x=ProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'ins_mdfstr_column_x', '')
	//	This.Modify(ins_mdfstr_column_width)
	//	This.Modify(ins_mdfstr_column_x)
	//END IF
	
	//SELECT dwnSyntax_layout_column_autosize,dwnSyntax_layout_column_detail_height
	//	INTO :ins_mdf_autosize,:ins_mdf_height
	//	FROM sys_user_dwnSyntax
	//	WHERE empid = :cardw_empid
	//	And dwname = :cur_dataobject;
	//IF sqlca.SQLCode <> 0 THEN
	//	ins_mdf_height = 0
	//	ins_mdf_autosize = -1
	//END IF
	
	datastore  ls_ds_ori
	ls_ds_ori = Create datastore
	ls_ds_ori.DataObject = This.DataObject
	
	IF ins_mdf_autosize = 1 THEN
		This.Modify("DataWindow.Detail.Height.AutoSize = Yes")
	ELSEIF ins_mdf_autosize = 0 THEN
		This.Modify("DataWindow.Detail.Height.AutoSize = No")
	ELSE
		IF ls_ds_ori.Describe("DataWindow.Detail.Height.AutoSize") = 'yes' THEN
			This.Modify("DataWindow.Detail.Height.AutoSize = Yes")
		ELSE
			This.Modify("DataWindow.Detail.Height.AutoSize = No")
		END IF
	END IF
	
	IF ins_mdf_height <= 0 THEN
		ins_mdf_height = Long(ls_ds_ori.Describe("DataWindow.Detail.Height"))
	END IF
	
	IF ins_mdf_height > 0 THEN
		This.Modify("DataWindow.Detail.Height = "+String(ins_mdf_height))
	END IF
	
	This.SetRedraw(True)
	
	destroy ls_ds_ori
end if

RETURN 0


end function

public subroutine uf_getnewlayout ();
IF This.DataObject = '' THEN RETURN

String des_1,des_2,szColumn
String ls_mdfstr_vis = ''
String ls_mdfstr_wi = ''
String ls_mdfstr_x = ''
Long nColumnIndex,nColumnCount,lRow,ls_i

//nColumnCount = Integer( this.Object.DataWindow.Column.Count)
//
//For nColumnIndex = 1 To nColumnCount
//	des_1= this.Describe( "#" + String(nColumnIndex) + ".Name") 
//	des_2= this.describe(des_1+ "_t.Text")
//	szColumn = f_strip( des_2)
//	
//	If szColumn <> "!" Then
//		ls_mdfstr_vis=ls_mdfstr_vis+des_1+'.visible='+this.describe(des_1+ ".Visible")+'~t'
//		ls_mdfstr_wi=ls_mdfstr_wi+des_1+'.width='+this.describe(des_1+ ".width")+'~t'
//		ls_mdfstr_x=ls_mdfstr_x+des_1+'.x='+this.describe(des_1+ ".x")+'~t'
//		ls_mdfstr_x=ls_mdfstr_x+des_1+'_t.x='+this.describe(des_1+ ".x")+'~t'
//	End If
//Next
///*
String ls_dwobjectstr,ls_object,ls_type
Long li_start,li_tab_pos,li_i

ls_dwobjectstr = This.Describe("Datawindow.Objects") + "~t"

li_start = 1
li_tab_pos = Pos(ls_dwobjectstr,   "~t",   li_start)

DO WHILE   li_tab_pos   >   0
	ls_object   =   Mid(ls_dwobjectstr,   li_start,   (li_tab_pos   -   li_start) )
	IF Pos(ls_object,'_t') > 0 THEN
		ls_object   =   Mid(ls_dwobjectstr,   li_start,   (li_tab_pos   -   li_start) - 2)
		ls_type = Lower(Left(This.Describe(ls_object+".Type"),4))
		
		IF ls_type = 'comp' Or ls_type = 'colu' THEN
			
			des_1 = This.Describe( ls_object + ".Name")
			des_2 = This.Describe(des_1+ "_t.Text")
			
			szColumn = f_strip( des_2)
			IF szColumn <> "!" THEN
				ls_mdfstr_vis = ls_mdfstr_vis+des_1+'.visible='+This.Describe(des_1+ ".Visible")+'~t'
				ls_mdfstr_wi = ls_mdfstr_wi+des_1+'.width='+This.Describe(des_1+ ".width")+'~t'
				ls_mdfstr_x = ls_mdfstr_x+des_1+'.x='+This.Describe(des_1+ ".x")+'~t'
				ls_mdfstr_x = ls_mdfstr_x+des_1+'_t.x='+This.Describe(des_1+ ".x")+'~t'
			END IF
		END IF
	END IF
	
	li_start = li_tab_pos   +   1
	li_tab_pos = Pos(ls_dwobjectstr,   "~t",   li_start)
LOOP
//*/

ins_mdf_height = Long(This.Describe("DataWindow.Detail.Height"))

IF This.Describe("DataWindow.Detail.Height.AutoSize") = 'yes' THEN
	ins_mdf_autosize = 1
ELSE
	ins_mdf_autosize = 0
END IF

ins_mdfstr_column_visible = ls_mdfstr_vis
ins_mdfstr_column_width = ls_mdfstr_wi
ins_mdfstr_column_x = ls_mdfstr_x


end subroutine

public subroutine uf_save_profile_layout ();//
//从用户的默认习惯写入-布局
//

IF cur_DataObject = '' THEN RETURN

oleobject parm
string arg_msg
if (setcolumn_visible_USE or autosave_setlayout_USE or autosave_columnvisible_USE) then
	uf_getnewlayout()
	
	parm = FXAppCom.CreatePbDictionary()
	parm.SetString('token', app_token_fx)
	parm.SetString('dwname', cur_dataobject)
	parm.SetString('column_visible', ins_mdfstr_column_visible)
	parm.SetString('column_width', ins_mdfstr_column_width)
	parm.SetString('column_x', ins_mdfstr_column_x)
	parm.SetInt('column_autosize', ins_mdf_autosize)
	parm.SetInt('column_detail_height', ins_mdf_height)
	FXAppCom.SetDwLayoutAsync(parm, ref arg_msg)
end if

//IF  setcolumn_visible_USE And autosave_columnvisible_USE THEN
//	UPDATE sys_user_dwnSyntax
//		SET dwnSyntax_layout_column_visible = :ins_mdfstr_column_visible
//		WHERE empid = :cardw_empid
//		And dwname = :cur_DataObject;
//	IF sqlca.SQLCode = 0 THEN
//		IF sqlca.SQLNRows = 0 THEN
//			INSERT INTO sys_user_dwnSyntax
//				(empid,
//				dwname,
//				dwnSyntax_filter,
//				dwnSyntax_sort,
//				dwnSyntax_layout_column_visible,
//				dwnSyntax_layout_column_width,
//				dwnSyntax_layout_column_x)
//				Values(:cardw_empid,:cur_DataObject,'','',:ins_mdfstr_column_visible,'','');
//		END IF
//	END IF
//	COMMIT;
//	
//	//	setProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'ins_mdfstr_column_visible', ins_mdfstr_column_visible)
//END IF
//
//
//IF  autosave_setlayout_USE THEN
//	UPDATE sys_user_dwnSyntax
//		SET dwnSyntax_layout_column_width = :ins_mdfstr_column_width,
//		dwnSyntax_layout_column_x = :ins_mdfstr_column_x
//		WHERE empid = :cardw_empid
//		And dwname = :cur_DataObject;
//	IF sqlca.SQLCode = 0 THEN
//		IF sqlca.SQLNRows = 0 THEN
//			INSERT INTO sys_user_dwnSyntax
//				(empid,
//				dwname,
//				dwnSyntax_filter,
//				dwnSyntax_sort,
//				dwnSyntax_layout_column_visible,
//				dwnSyntax_layout_column_width,
//				dwnSyntax_layout_column_x)
//				Values(:cardw_empid,:cur_DataObject,'','','',:ins_mdfstr_column_width,:ins_mdfstr_column_x);
//		END IF
//	END IF
//	COMMIT;
//	//	setProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'ins_mdfstr_column_width', ins_mdfstr_column_width)
//	//	setProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'ins_mdfstr_column_x', ins_mdfstr_column_x)
//END IF
//
//
//UPDATE sys_user_dwnSyntax
//	SET dwnSyntax_layout_column_autosize = :ins_mdf_autosize,
//	dwnSyntax_layout_column_detail_height = :ins_mdf_height
//	WHERE empid = :cardw_empid
//	And dwname = :cur_DataObject;
//IF sqlca.SQLCode = 0 THEN
//	IF sqlca.SQLNRows = 0 THEN
//		INSERT INTO sys_user_dwnSyntax
//			(empid,
//			dwname,
//			dwnSyntax_filter,
//			dwnSyntax_sort,
//			dwnSyntax_layout_column_visible,
//			dwnSyntax_layout_column_width,
//			dwnSyntax_layout_column_x,
//			dwnSyntax_layout_column_autosize,
//			dwnSyntax_layout_column_detail_height)
//			Values(:cardw_empid,:cur_DataObject,'','',:ins_mdfstr_column_visible,'','',:ins_mdf_autosize,:ins_mdf_height);
//	END IF
//END IF
//
//
//COMMIT;

RETURN






end subroutine

public subroutine uf_save_profile_filter ();//
//从用户的默认习惯写入ini-filter
//
IF cur_DataObject = '' THEN RETURN

IF  rbutton_filter_use AND autosave_filter_use THEN
	UPDATE sys_user_dwnSyntax
		SET dwnSyntax_filter = :curdw_filterstr
		WHERE empid = :cardw_empid
		AND dwname = :cur_DataObject;
	IF sqlca.SQLCode = 0 THEN
		IF sqlca.SQLNRows = 0 THEN
			INSERT INTO sys_user_dwnSyntax
				(empid,
				dwname,
				dwnSyntax_filter,
				dwnSyntax_sort,
				dwnSyntax_layout_column_visible,
				dwnSyntax_layout_column_width,
				dwnSyntax_layout_column_x)
				Values(:cardw_empid,:cur_DataObject,:curdw_filterstr,'','','','');
		END IF
	END IF
	COMMIT;
	//	setProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'curDW_filterstr', curdw_filterstr)
END IF

RETURN




end subroutine

public subroutine uf_save_profile_sort ();//
//从用户的默认习惯写入INI-sort
//

IF cur_DataObject = '' THEN RETURN

IF titleclick_sort_USE AND autosave_sort_use THEN
	UPDATE sys_user_dwnSyntax
		SET dwnSyntax_sort = :curDW_sortstr
		WHERE empid = :cardw_empid
		AND dwname = :cur_DataObject;
	IF sqlca.SQLCode = 0 THEN
		IF sqlca.SQLNRows = 0 THEN
			INSERT INTO sys_user_dwnSyntax
				(empid,
				dwname,
				dwnSyntax_filter,
				dwnSyntax_sort,
				dwnSyntax_layout_column_visible,
				dwnSyntax_layout_column_width,
				dwnSyntax_layout_column_x)
				Values(:cardw_empid,:cur_DataObject,'',:curDW_sortstr,'','','');
		END IF
	END IF
	COMMIT;
	//	setProfileString (ins_inifile_name,ins_opemp+'_'+THIS.DataObject, 'curDW_sortstr', curDW_sortstr)
END IF

RETURN





end subroutine

public subroutine uf_reset_layout ();
IF THIS.DataObject = '' THEN RETURN

datastore  ls_ds
ls_ds = CREATE datastore
ls_ds.DataObject = THIS.DataObject

String des_1,des_2,szColumn
String ls_mdfstr_vis = ''
String ls_mdfstr_wi = ''
String ls_mdfstr_x = ''
Long nColumnIndex,nColumnCount,lRow,ls_i

//nColumnCount = Integer( this.Object.DataWindow.Column.Count)
//
//For nColumnIndex = 1 To nColumnCount
//	des_1= this.Describe( "#" + String(nColumnIndex) + ".Name") 
//	des_2= this.describe(des_1+ "_t.Text")
//	szColumn = f_strip( des_2)
//	
//	If szColumn <> "!" Then
//		ls_mdfstr_vis=ls_mdfstr_vis+des_1+'.visible='+ls_ds.describe(des_1+ ".Visible")+'~t'
//		ls_mdfstr_wi=ls_mdfstr_wi+des_1+'.width='+ls_ds.describe(des_1+ ".width")+'~t'
//		ls_mdfstr_x=ls_mdfstr_x+des_1+'.x='+ls_ds.describe(des_1+ ".x")+'~t'
//		ls_mdfstr_x=ls_mdfstr_x+des_1+'_t.x='+ls_ds.describe(des_1+ ".x")+'~t'
//	End If
//Next
///*
String ls_dwobjectstr,ls_object,ls_type
Long li_start,li_tab_pos,li_i

ls_dwobjectstr = THIS.Describe("Datawindow.Objects") + "~t"

li_start = 1
li_tab_pos = Pos(ls_dwobjectstr,   "~t",   li_start)

DO WHILE   li_tab_pos   >   0
	ls_object   =   Mid(ls_dwobjectstr,   li_start,   (li_tab_pos   -   li_start) )
	IF Pos(ls_object,'_t') > 0 THEN
		ls_object   =   Mid(ls_dwobjectstr,   li_start,   (li_tab_pos   -   li_start) - 2)
		ls_type = Lower(Left(ls_ds.Describe(ls_object+".Type"),4))
		
		IF ls_type = 'comp' OR ls_type = 'colu' THEN
			
			des_1 = ls_ds.Describe( ls_object + ".Name")
			des_2 = ls_ds.Describe(des_1+ "_t.Text")
			
			szColumn = f_strip( des_2)
			IF szColumn <> "!" THEN
				ls_mdfstr_vis = ls_mdfstr_vis+des_1+'.visible='+ls_ds.Describe(des_1+ ".Visible")+'~t'
				ls_mdfstr_wi = ls_mdfstr_wi+des_1+'.width='+ls_ds.Describe(des_1+ ".width")+'~t'
				ls_mdfstr_x = ls_mdfstr_x+des_1+'.x='+ls_ds.Describe(des_1+ ".x")+'~t'
				ls_mdfstr_x = ls_mdfstr_x+des_1+'_t.x='+ls_ds.Describe(des_1+ ".x")+'~t'
			END IF
		END IF
	END IF
	
	li_start = li_tab_pos   +   1
	li_tab_pos = Pos(ls_dwobjectstr,   "~t",   li_start)
LOOP
//*/

ins_mdfstr_column_visible = ls_mdfstr_vis
ins_mdfstr_column_width = ls_mdfstr_wi
ins_mdfstr_column_x = ls_mdfstr_x

ins_mdf_height = Long(ls_ds.Describe("DataWindow.Detail.Height"))

IF ls_ds.Describe("DataWindow.Detail.Height.AutoSize") = 'yes' THEN
	ins_mdf_autosize = 1
ELSE
	ins_mdf_autosize = 0
END IF

THIS.SetRedraw(FALSE)

THIS.Modify(ins_mdfstr_column_visible)
THIS.Modify(ins_mdfstr_column_width)
THIS.Modify(ins_mdfstr_column_x)

IF ins_mdf_autosize = 1 THEN
	This.Modify("DataWindow.Detail.Height.AutoSize = Yes")
	This.Modify("DataWindow.Detail.Height = "+String(ins_mdf_height))
ELSE
	This.Modify("DataWindow.Detail.Height.AutoSize = No")
	This.Modify("DataWindow.Detail.Height = "+String(ins_mdf_height))
END IF

THIS.SetRedraw(TRUE)

end subroutine

public function integer uf_string_deal_setp (s_esq_tran arg_esq_tran, string column_name);//uf_string_deal_setp
OpenWithParm(w_publ_input_expr_posi,arg_esq_tran)
arg_esq_tran = Message.PowerObjectParm

IF arg_esq_tran.return_flag = 4 THEN
	IF NOT arg_esq_tran.DIST_BOOLEAN THEN
		arg_Positionstr = "pos(upper("+column_name+"), '"+Upper(arg_esq_tran.cur_data)+"') > 0 "
	ELSE
		arg_Positionstr = "pos("+column_name+", '"+arg_esq_tran.cur_data+"') > 0 "
	END IF
	arg_SetPosition = TRUE
END IF
RETURN 1




end function

event rbuttondown;string ls_dwoname, ls_dwotype

ls_dwoname = trim(lower(dwo.name))
ls_dwotype = trim(lower(dwo.type))

s_v2_dw_parms s_parms
s_parms.arg_colname = ''

if row <= 0 AND right(ls_dwoname,2) = '_t' AND (NOT KeyDown(KeyControl!)) then
	ls_dwoname = left(ls_dwoname, len(ls_dwoname) - 2)
	ls_dwotype = trim(lower(this.Describe(ls_dwoname+".type")))
	if ls_dwotype = 'column' OR ls_dwotype = 'compute' then
		s_parms.arg_dw = this
		s_parms.arg_colname = ls_dwoname
		s_parms.arg_row = 0
	end if
end if

if s_parms.arg_colname <> '' then
	openwithparm(w_v2_dw_filter_rsp, s_parms)
	return
end if




String str_clickedobjecttype
String column_name,column_text_name
Long FindRow, FindPage
IF RBUTTON_SETPOSITION_USE OR rbutton_filter_use THEN
	String cur_data,ls_title
	
	str_clickedobjecttype = Lower(Left(dwo.TYPE,4))
	IF str_clickedobjecttype <> 'colu' THEN
		IF str_clickedobjecttype = 'data' THEN
			IF rbutton_filter_use THEN
				curdw_filterstr = ''
				THIS.SetFilter('')
				THIS.SetRedraw (FALSE)
				THIS.Filter()
				THIS.TriggerEvent("ue_after_filter")
				THIS.SetRedraw (TRUE)
			END IF
		END IF
		GOTO csort
	END IF
	
	s_esq_tran ls_esq_tran
	pointapi lppoint1
	column_name = dwo.Name
	
	IF getcursorpos(lppoint1) <> 0  THEN
		ls_esq_tran.X = PixelsToUnits(lppoint1.X, xpixelstounits!)
		ls_esq_tran.Y = PixelsToUnits(lppoint1.Y, ypixelstounits!)
	ELSE
		environment   exerun_env
		GetEnvironment(exerun_env )
		ls_esq_tran.X = xpos +THIS.X + ( PixelsToUnits(exerun_env.ScreenWidth, xpixelstounits!) - THIS.Width ) / 2
		ls_esq_tran.Y = ypos +THIS.Y + ( PixelsToUnits(exerun_env.ScreenHeight, xpixelstounits!) - THIS.Height) / 2.5
	END IF
	
	ls_esq_tran.cur_filter_expr = curdw_filterstr
	ls_title = THIS.Describe(column_name+ "_t.text")
	
	IF ls_title = "!" THEN ls_title = ''
	column_name = dwo.Name
	ls_esq_tran.Title = ls_title
	
	IF rbutton_filter_use THEN
		//分别处理不同类型
		CHOOSE CASE Left( THIS.Describe( dwo.Name+ ".coltype"),4)
			CASE "char"
				ls_esq_tran.cur_data = dwo.primary[row]
				If (uf_string_deal(ls_esq_tran,column_name)) = 0 THEN RETURN
			CASE "date","time"
				ls_esq_tran.dt_data = dwo.primary[row]
				If (uf_datetime_deal(ls_esq_tran,column_name)) = 0 THEN RETURN
			CASE ELSE
				ls_esq_tran.num_data = dwo.primary[row]
				If (uf_decimal_deal(ls_esq_tran,column_name)) = 0 THEN RETURN
		END CHOOSE
	ELSE
		//分别处理不同类型
		CHOOSE CASE Left( THIS.Describe( dwo.Name+ ".coltype"),4)
			CASE "char"
				ls_esq_tran.cur_data = dwo.primary[row]
				If (uf_string_deal_setp(ls_esq_tran,column_name)) = 0 THEN RETURN
		END CHOOSE
	END IF
	
	IF arg_SetPosition THEN
		
		FindRow = THIS.Find(arg_Positionstr, 1, THIS.RowCount())
		//		if FindRow = row and this.rowcount( ) > row then
		//			FindRow = THIS.Find(arg_Positionstr, row + 1, THIS.RowCount())
		//		end if
		arg_SetPosition = FALSE
		
		IF FindRow <= 0 THEN GOTO csort
		THIS.SelectRow(0,FALSE)
		THIS.SelectRow(FindRow,TRUE)
		THIS.ScrollToRow( FindRow)
	ELSE
		THIS.SetFilter(curdw_filterstr)
		THIS.SetRedraw (FALSE)
		THIS.Filter()
		THIS.TriggerEvent("ue_after_filter")
		THIS.SetRedraw (TRUE)
	END IF
	
END IF
csort:

IF titleclick_sort_use THEN
	IF KeyDown(KeyControl!) THEN
		OpenWithParm(w_sortrow,this)
		curDW_sortstr = Message.StringParm
	ELSE
		str_clickedobjecttype = Left(dwo.TYPE,4)
		
		IF str_clickedobjecttype = 'text' THEN
			column_text_name = dwo.Name
			
			IF Len(column_text_name) >= 3 AND Right(column_text_name,2) = '_t' THEN
				column_name = Left(column_text_name,Len(column_text_name) - 2)
			ELSE
				GOTO cend
			END IF
			
			IF Left(Describe(column_name+'.type'),4) <> 'colu' AND &
				Left(Describe(column_name+'.type'),4) <> 'comp' THEN
				RETURN
			END IF
			IF curDW_sortstr = column_name+' A ' THEN
				curDW_sortstr = column_name+' D '
			ELSE
				curDW_sortstr = column_name+' A '
			END IF
			
		ELSE
//			curDW_sortstr = ''
		END IF
	END IF
	
	IF curDW_sortstr <> '' THEN
		THIS.SetSort(curDW_sortstr)
		THIS.SetRedraw (FALSE)
		THIS.Sort()
		THIS.SetRedraw (TRUE)
	END IF
END IF

cend:
//IF THIS.RowCount() > 0 THEN
//	THIS.SetRow(1)
//	THIS.ScrollToRow(1)
//	THIS.SelectRow(0,FALSE)
//	THIS.SelectRow(1,TRUE)
//END IF







end event

event constructor;
// titleclick_sort_use=true  //单击标题排序-功能开关
// RBUTTON_FILTER_USE=true  //右键查询-功能开关
// setcolumn_visible_USE= true //自动保存显示列-功能开关
// autosave_setlayout_USE= true //自动保存列位置及宽度-功能开关
// RBUTTON_SETPOSITION_USE=false //右键定位功能开关

ins_INIfile_name = sys_inifilename
ins_opemp = publ_operator
cardw_empid = sys_empid
cur_DataObject = THIS.DataObject

uf_read_profile_layout()
//
f_title_change(this)
end event

on u_dw_rbtnfilter.create
end on

on u_dw_rbtnfilter.destroy
end on

event destructor;uf_save_profile_layout()
end event

event clicked;//if titleclick_sort_use  then //and keydown(KeyControl!)
//	string str_clickedobjecttype
//	string column_name,column_text_name
//	str_clickedobjecttype=LEFT(dwo.type,4)
//
//	IF str_clickedobjecttype='text' then
//		column_text_name=dwo.name
//		if len(column_text_name)>=3 and right(column_text_name,2)='_t' then
//			column_name=left(column_text_name,len(column_text_name) - 2)
//		else
//			return
//		end if
//		if LEFT(describe(column_name+'.type'),4)<>'colu' then return
//		if curDW_sortstr=column_name+' A ' then
//			curDW_sortstr=column_name+' D '
//		else
//			curDW_sortstr=column_name+' A '
//		end if
//	
//	else
//		curDW_sortstr=''
//	END IF
//
//	if curDW_sortstr<>'' then
//		THIS.setsort(curDW_sortstr)
//		THIS.SetRedraw (false)
//		THIS.sort()
//		THIS.SetRedraw (true)
//	end if
//END IF
end event

