global type gf_dw_colcopy from function_object
end type
forward prototypes
global function long gf_dw_colcopy (powerobject dataobj_sur, powerobject dataobj_tar, string as_cols)
end prototypes
global function long gf_dw_colcopy (powerobject dataobj_sur, powerobject dataobj_tar, string as_cols);//====================================================================
// Declare: gf_dw_colcopy.
//--------------------------------------------------------------------
// 描述: dw 批量复制某几列
//--------------------------------------------------------------------
// 参数:
// dataobj_sur :原 dw/ds
// dataobj_tar :目标 dw/ds
// as_cols :列名多个用逗号分开 如 col1,col2
//--------------------------------------------------------------------
// 返回:
//--------------------------------------------------------------------
// 作者: tom (QQ88954322) 日期: 2019/10/09 13:31:45
//--------------------------------------------------------------------
// CopyRight(c)
//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================
Long i = 0, llPos, llBegin = 1,ll_arrcnt,ll_rowcnt
string ls_colarry[],asTag=',',ls_Ret,ls_Ret2
datawindow ldw_sur,ldw_tar
datastore lds_sur,lds_tar
dwobject dwo_sur,dwo_tar
//拆分列
as_cols=trim(as_cols)
if right(as_cols,1)=',' then as_cols=mid(as_cols,1,len(as_cols) - 1)
llPos = Pos(as_cols, asTag, llBegin)
Do While llPos > 0
i ++
ls_colarry[i] = Mid(as_cols, llBegin, llPos - llBegin)
llBegin = llPos + Len(asTag)
llPos = Pos(as_cols, asTag, llBegin)
Loop
If llBegin <= Len(as_cols) Or i > 0 Then
i ++
ls_colarry[i] = Mid(as_cols, llBegin, Len(as_cols) - llBegin + 1)
End If
ll_arrcnt=i
//取窗口数据类型
Choose Case dataobj_tar.TypeOf()
Case datastore!
lds_sur = dataobj_sur
lds_tar = dataobj_tar
ll_rowcnt=lds_sur.rowcount()
Case datawindow!
ldw_sur = dataobj_sur
ldw_tar = dataobj_tar
ll_rowcnt=ldw_sur.rowcount()
Case Else
SignalError(221,"Parameter DataObj type error")
return -1
End Choose
if dataobj_sur.TypeOf()=datawindow! then ldw_tar.setredraw(false)
//复制数据
for i=1 to ll_rowcnt
if dataobj_sur.TypeOf()=datastore! then
lds_tar.insertrow(0)
else
ldw_tar.insertrow(0)
end if
next
for i=1 to ll_arrcnt
if dataobj_sur.TypeOf()=datawindow! then
ls_Ret =ldw_sur.Describe(ls_colarry[i]+".width")
ls_Ret2=ldw_tar.Describe(ls_colarry[i]+".width")
else
ls_Ret =lds_sur.Describe(ls_colarry[i]+".width")
ls_Ret2=lds_tar.Describe(ls_colarry[i]+".width")
end if
if ls_Ret="!" then
messagebox('提示1','源窗口没有列'+ls_colarry[i])
return -1
end if
if ls_Ret2="!" then
messagebox('提示2','目标窗口没有列'+ls_colarry[i])
return -1
end if
if dataobj_sur.TypeOf()=datawindow! then
dwo_sur=ldw_sur.Object.__get_attribute(ls_colarry[i],False)
dwo_tar=ldw_tar.Object.__get_attribute(ls_colarry[i],False)
else
dwo_sur=lds_sur.Object.__get_attribute(ls_colarry[i],False)
dwo_tar=lds_tar.Object.__get_attribute(ls_colarry[i],False)
end if
dwo_tar.Current=dwo_sur.Current
next
if dataobj_sur.TypeOf()=datawindow! then ldw_tar.setredraw(true)
return 1
end function