配色: 字号:
TreeView控件四层节点表单设计
2022-05-16 | 阅:  转:  |  分享 
  
TreeView控件四层节点表单设计一、运行界面:二、有关代码:1、Form1.Load事件代码PUBLICDataPath,TempP
athDataPath=SYS(5)+SYS(2003)+"\Data\"IF!DIRECTORY(DataPath)MD
(DataPath)ENDIFTempPath=SYS(5)+SYS(2003)+"\Temp\"IF!DIRECTORY(T
empPath)MD(TempPath)ENDIFCLOSEdataUSE(DataPath+"成绩汇总表.dbf")
ALIAScjhzbIN02、Form1.UnLoad事件代码CLOSEDATABASES3、Form1.In
it事件代码thisform.olecontrol1.LineStyle=1&&tvwRootLinesthisform
.olecontrol1.Style=7&&tvwTreelinesPlusMinusPictureTextthisfor
m.olecontrol1.Nodes.ClearSELECTdistinct学校FROMcjhzbINTO
CURSORtempSCAN&&添加第一层节点:学校thisform.olecontrol1.Nodes.Add(,,''
学校''+ALLTRIM(学校),学校)SELECTdistinct年级FROMcjhzbWHEREcjhz
b.学校=temp.学校INTOCURSORtemp1SELECTtemp1SCAN&&添加第二层节点:年级th
isform.olecontrol1.Nodes.Add(''学校''+ALLTRIM(temp.学校),4,''年级''+ALLTRI
M(temp.学校)+ALLTRIM(年级),年级)SELECTdistinct班级FROMcjhzbWHER
Ecjhzb.学校=temp.学校ANDcjhzb.年级=temp1.年级INTOCURSORtemp2SE
LECTtemp2SCAN&&添加第三层节点:班级thisform.olecontrol1.Nodes.Add(''年级''+
ALLTRIM(temp.学校)+ALLTRIM(temp1.年级),4,''班级''+ALLTRIM(temp.学校)+ALLTRI
M(temp1.年级)+ALLTRIM(班级),班级)SELECTdistinct性别FROMcjhzbWHER
Ecjhzb.学校=temp.学校ANDcjhzb.年级=temp1.年级ANDcjhzb.班级=temp2.
班级INTOCURSORtemp3SELECTtemp3SCAN&&添加第四层节点:性别thisform.o
lecontrol1.Nodes.Add(''班级''+ALLTRIM(temp.学校)+ALLTRIM(temp1.年级)+ALLT
RIM(temp2.班级),4,''性别''+ALLTRIM(temp.学校)+ALLTRIM(temp1.年级)+ALLTRIM(t
emp2.班级)+ALLTRIM(性别),性别)ENDSCANUSEINtemp3SELECTtemp2ENDSCANU
SEINtemp2SELECTtemp1ENDSCANUSEINtemp1SELECTtempENDSCANU
SEINtempthisform.olecontrol1.refresh4、Form1.OleControl1.NodeC
lick事件代码ActiveX控件事件LPARAMETERSnodeDOCASE
第一层节点:学校CASEISNULL(This.SelectedItem.Parent)wjm=DataPat
h+"cjtjmb2.doc"PUBLICcxx,i,k,m,soWord=CREATEOBJECT("word.ap
plication")oWord.VISIBLE=.T.SELECTcjhzbLocateFORALLTRIM(cjh
zb.学校)=ALLTRIM(this.Nodes(this.Selecteditem.key).text)IFFOUND(
)cxx=ALLTRIM(this.Nodes(this.Selecteditem.key).text)WAITWINDOW
''正在生成"''+cxx+''"成绩统计表……''NOWAITSELECTFROMcjhzbWHER
E学校=cxxINTOCURSORtemp0SELECTtemp0oTab=oWord.APPLICATIO
N.Documents.OPEN(wjm)oWord.SELECTIONoWord.SELECTION.insertafter(A
LLTRIM("&cxx"))SELECTtemp0S=RECCOUNT()-2M=IIF(MOD(s,2)<>0,IN
T(s/2+1),s/2)oWord.ActiveDocument.Tables(1).cell(2,1).selectoWord
.Selection.InsertRowsBelow(m)FORi=1TORECCOUNT()GOik=
INT((i+1)/2+1)IFMOD(i,2)=0oTab.Tables(1).Cell(k,7).Range.In
sertAfter(temp0.年级)oTab.Tables(1).Cell(k,8).Range.InsertAfter(tem
p0.班级)oTab.Tables(1).Cell(k,9).Range.InsertAfter(temp0.姓名)oTab.Ta
bles(1).Cell(k,10).Range.InsertAfter(temp0.语文)oTab.Tables(1).Cell
(k,11).Range.InsertAfter(temp0.数学)oTab.Tables(1).Cell(k,12).Range
.InsertAfter(temp0.英语)ELSEoTab.Tables(1).Cell(k,1).Range.InsertAf
ter(temp0.年级)oTab.Tables(1).Cell(k,2).Range.InsertAfter(temp0.班级)
oTab.Tables(1).Cell(k,3).Range.InsertAfter(temp0.姓名)oTab.Tables(1
).Cell(k,4).Range.InsertAfter(temp0.语文)oTab.Tables(1).Cell(k,5).R
ange.InsertAfter(temp0.数学)oTab.Tables(1).Cell(k,6).Range.InsertAf
ter(temp0.英语)ENDIFENDFORSELECTtemp0USESELECTcjhzbWAITCLEA
RFileName=TempPath+cxx+"成绩统计表.doc"oWord.Documents(1).SAVEAS(File
name)oWord.ActiveDocument.CLOSEoWord.QUIT()MESSAGEBOX("成绩统计表WORD文
档生成完毕!",64,"提示")ENDIF第二层节点:年级CASEISNULL
(This.SelectedItem.Parent.parent)wjm=DataPath+"cjtjmb2.doc"PUBLI
Ccxx,cnj,i,k,m,soWord=CREATEOBJECT("word.application")oWor
d.VISIBLE=.T.SELECTcjhzbLocateFORALLTRIM(cjhzb.学校)=ALLTRIM(
this.Nodes(this.Selecteditem.parent.key).text)ANDALLTRIM(cjh
zb.年级)=ALLTRIM(this.Nodes(this.Selecteditem.key).text)IFFOUND()
cxx=ALLTRIM(this.Nodes(this.Selecteditem.parent.key).text)cnj=AL
LTRIM(this.Nodes(this.Selecteditem.key).text)WAITWINDOW''正在生成"
''+cxx+cnj+''"成绩统计表……''NOWAITSELECTFROMcjhzbWHERE学校=
cxxAND年级=cnjINTOCURSORtemp0SELECTtemp0oTab=oWord.APPL
ICATION.Documents.OPEN(wjm)oWord.SELECTIONoWord.SELECTION.inserta
fter(ALLTRIM("&cxx&cnj"))SELECTtemp0S=RECCOUNT()-2M=IIF(MOD(s
,2)<>0,INT(s/2+1),s/2)oWord.ActiveDocument.Tables(1).cell(2,1).se
lectoWord.Selection.InsertRowsBelow(m)FORi=1TORECCOUNT()
GOik=INT((i+1)/2+1)IFMOD(i,2)=0oTab.Tables(1).Cell(k,7)
.Range.InsertAfter(temp0.年级)oTab.Tables(1).Cell(k,8).Range.Insert
After(temp0.班级)oTab.Tables(1).Cell(k,9).Range.InsertAfter(temp0.姓
名)oTab.Tables(1).Cell(k,10).Range.InsertAfter(temp0.语文)oTab.Table
s(1).Cell(k,11).Range.InsertAfter(temp0.数学)oTab.Tables(1).Cell(k,
12).Range.InsertAfter(temp0.英语)ELSEoTab.Tables(1).Cell(k,1).Rang
e.InsertAfter(temp0.年级)oTab.Tables(1).Cell(k,2).Range.InsertAfter
(temp0.班级)oTab.Tables(1).Cell(k,3).Range.InsertAfter(temp0.姓名)oTa
b.Tables(1).Cell(k,4).Range.InsertAfter(temp0.语文)oTab.Tables(1).C
ell(k,5).Range.InsertAfter(temp0.数学)oTab.Tables(1).Cell(k,6).Rang
e.InsertAfter(temp0.英语)ENDIFENDFORSELECTtemp0USESELECTcjhzb
WAITCLEARFileName=TempPath+cxx+cnj+"成绩统计表.doc"oWord.Documents
(1).SAVEAS(Filename)oWord.ActiveDocument.CLOSEoWord.QUIT()MESSAGE
BOX("成绩统计表WORD文档生成完毕!",64,"提示")ENDIF第三层节
点:班级CASEISNULL(This.SelectedItem.Parent.parent.parent)wjm=Data
Path+"cjtjmb.doc"PUBLICcxx,cnj,cbj,i,k,m,soWord=CREATEOBJE
CT("word.application")oWord.VISIBLE=.T.SELECTcjhzbLocateFORA
LLTRIM(cjhzb.学校)=ALLTRIM(this.nodes(this.Selecteditem.parent.Pare
nt.key).Text)ANDALLTRIM(cjhzb.年级)=ALLTRIM(this.nodes(this.Sele
cteditem.Parent.key).Text)ANDALLTRIM(cjhzb.班级)=ALLTRIM(this.nod
es(this.Selecteditem.key).Text)IFFOUND()cxx=ALLTRIM(this.nodes(
this.Selecteditem.parent.Parent.key).Text)cnj=ALLTRIM(this.nodes(
this.Selecteditem.Parent.key).Text)cbj=ALLTRIM(this.nodes(this.S
electeditem.key).Text)WAITWINDOW''正在生成"''+cxx+cnj+cbj+''"成绩统
计表……''NOWAITSELECTFROMcjhzbWHERE学校=cxxAND年级=cnjAND
班级=cbjINTOCURSORtemp0SELECTtemp0oTab=oWord.APPLICATION
.Documents.OPEN(wjm)oWord.SELECTIONoWord.SELECTION.insertafter(AL
LTRIM("&cxx&cnj&cbj"))SELECTtemp0FORi=1TORECCOUNT()GO
iIFi>30oTab.Tables(1).Cell(i+1-30,5).Range.InsertAfter(temp0
.姓名)oTab.Tables(1).Cell(i+1-30,6).Range.InsertAfter(temp0.语文)oT
ab.Tables(1).Cell(i+1-30,7).Range.InsertAfter(temp0.数学)oTab.Tabl
es(1).Cell(i+1-30,8).Range.InsertAfter(temp0.英语)ELSEoTab.Tables
(1).Cell(i+1,1).Range.InsertAfter(temp0.姓名)oTab.Tables(1).Cell(i
+1,2).Range.InsertAfter(temp0.语文)oTab.Tables(1).Cell(i+1,3).Rang
e.InsertAfter(temp0.数学)oTab.Tables(1).Cell(i+1,4).Range.InsertAf
ter(temp0.英语)ENDIFENDFORSELECTtemp0USESELECTcjhzbWAITCLE
ARFileName=TempPath+cxx+cnj+cbj+"成绩统计表.doc"oWord.Documents(1).SA
VEAS(Filename)oWord.ActiveDocument.CLOSEoWord.QUIT()MESSAGEBOX("成
绩统计表WORD文档生成完毕!",64,"提示")ENDIF第四层节点:性别CAS
EISNULL(This.SelectedItem.Parent.parent.parent.parent)wjm=DataP
ath+"cjtjmb.doc"PUBLICcxx,cnj,cbj,cxb,i,k,m,soWord=CREATE
OBJECT("word.application")oWord.VISIBLE=.T.SELECTcjhzbLocateF
ORALLTRIM(cjhzb.学校)=ALLTRIM(this.nodes(this.Selecteditem.parent.
Parent.parent.key).Text)ANDALLTRIM(cjhzb.年级)=ALLTRIM(this.nodes
(this.Selecteditem.Parent.parent.key).Text)ANDALLTRIM(cjhzb.班级
)=ALLTRIM(this.nodes(this.Selecteditem.parent.key).Text)ANDALL
TRIM(cjhzb.性别)=ALLTRIM(this.nodes(this.Selecteditem.key).Text)IF
FOUND()cxx=ALLTRIM(this.nodes(this.Selecteditem.parent.Parent.p
arent.key).Text)cnj=ALLTRIM(this.nodes(this.Selecteditem.Parent
.parent.key).Text)cbj=ALLTRIM(this.nodes(this.Selecteditem.pare
nt.key).Text)cxb=ALLTRIM(this.nodes(this.Selecteditem.key).Text
)WAITWINDOW''正在生成"''+cxx+cnj+cbj+cxb+''"生成绩统计表……''NOWAITSE
LECTFROMcjhzbWHERE学校=cxxAND年级=cnjAND班级=cbjand性别=
cxbINTOCURSORtemp0SELECTtemp0oTab=oWord.APPLICATION.Docum
ents.OPEN(wjm)oWord.SELECTIONoWord.SELECTION.insertafter(ALLTRIM(
"&cxx&cnj&cbj&cxb")+"生")SELECTtemp0FORi=1TORECCOUNT()GO
iIFi>30oTab.Tables(1).Cell(i+1-30,5).Range.InsertAfter(temp
0.姓名)oTab.Tables(1).Cell(i+1-30,6).Range.InsertAfter(temp0.语文)o
Tab.Tables(1).Cell(i+1-30,7).Range.InsertAfter(temp0.数学)oTab.Tab
les(1).Cell(i+1-30,8).Range.InsertAfter(temp0.英语)ELSEoTab.Table
s(1).Cell(i+1,1).Range.InsertAfter(temp0.姓名)oTab.Tables(1).Cell(i+1,2).Range.InsertAfter(temp0.语文)oTab.Tables(1).Cell(i+1,3).Range.InsertAfter(temp0.数学)oTab.Tables(1).Cell(i+1,4).Range.InsertAfter(temp0.英语)ENDIFENDFORSELECTtemp0USESELECTcjhzbWAITCLEARFileName=TempPath+cxx+cnj+cbj+cxb+"生成绩统计表.doc"oWord.Documents(1).SAVEAS(Filename)oWord.ActiveDocument.CLOSEoWord.QUIT()MESSAGEBOX("成绩统计表WORD文档生成完毕!",64,"提示")ENDIFENDCASE三、附件1、成绩汇总表.dbf2、模板文件(cjtjmb.doc)8列31行成绩统计表姓名语文数学英语姓名语文数学英语3、模板文件(cjtjmb1.doc)成绩统计表姓名语文数学英语姓名语文数学英语4、模板文件(cjtjmb2.doc)成绩统计表年级班级姓名语文数学英语年级班级姓名语文数学英语-3-
献花(0)
+1
(本文系王咸美首藏)