T版还不如做一个这样的小程序,让用户按照你的设计去录入数据,可能还会更简单些。
活到老,学到老!http://www.(该域名已经被ISP盗卖了)E-mail:hu-jj@
#include "FoxPro.h" SET DEFAULT TO "E:\我的文檔\項目\測試\VFP\test - caolp" && 程序执行根目录,即上图的文件夹位置 SET PATH TO "数据" && 程序搜索数据的文件夹 CLEAR ALL Main() CLEAR ALL RETURN *--------------------------- * 程序主入口 *--------------------------- PROCEDURE Main() LOCAL loForm loForm = CREATEOBJECT("C_MainForm") WITH loForm .Caption = "XXX小区住户平面图" .WindowState = WINDOWSTATE_MAXIMIZED .MinWidth = 800 .MinHeight = 600 .Show ENDWITH READ EVENTS ENDPROC *--------------------------- * 主窗体 *--------------------------- DEFINE CLASS C_MainForm AS myForm DIMENSION aList1[1] && 楼栋清单 DIMENSION aList2[1] && 单元号 DIMENSION aList3[1] && 楼层号 DIMENSION aList4[1] && 户室号 cList = "" && 筛选字符串 PROCEDURE cList_Assign(tcValue) ThisForm.cList = RTRIM(tcValue) ENDPROC ADD OBJECT Selector AS C_Selector WITH Top = 5, Left = 5 ADD OBJECT cnt_Map AS Container WITH BorderWidth = 0, BackStyle = 0 PROCEDURE Load CLOSE DATABASES ALL USE "居民信息" IN 0 ENDPROC PROCEDURE Unload CLOSE DATABASES ALL ENDPROC PROCEDURE Resize ThisForm.Go ENDPROC PROCEDURE Arrange WITH Top = ThisForm.Selector.Top + ThisForm.Selector.Height + 5 .Left = 5 .Height = ThisForm.Height - .Top - 5 .Width = ThisForm.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE Init LOCAL lnIndex WITH ThisForm .Get_List1 BINDEVENT(., "Click", This, "Change_List1") BINDEVENT(., "Click", This, "Change_List2") BINDEVENT(., "Click", This, "Change_List3") BINDEVENT(., "Click", This, "Change_List4") BINDEVENT(.Selector.btn_Go, "Click", This, "Go") ENDWITH ENDPROC * 获取楼栋清单 FUNCTION Get_List1() LOCAL lcStr, lnIndex SELECT "居民信息" SET ORDER TO "Master" GOTO TOP lcStr = SPACE(LEN(楼栋号)) lnIndex = 1 DIMENSION ThisForm.aList1[lnIndex] ThisForm.aList1[lnIndex] = lcStr DO WHILE !EOF() IF 楼栋号 != lcStr lnIndex = lnIndex + 1 lcStr = 楼栋号 DIMENSION ThisForm.aList1[lnIndex] ThisForm.aList1[lnIndex] = lcStr ENDIF SKIP ENDDO WITH .FOR lnIndex = 1 TO ALEN(ThisForm.aList1, 1) .AddItem(ThisForm.aList1[lnIndex]) NEXT .ListIndex = 1 ENDWITH ENDFUNC * 获取单元清单 FUNCTION Get_List2(tcNo1) LOCAL lcStr, lnIndex SELECT "居民信息" SET ORDER TO "Master" lcStr = SPACE(LEN(单元号)) lnIndex = 1 DIMENSION ThisForm.aList2[lnIndex] ThisForm.aList2[lnIndex] = lcStr IF !EMPTY(tcNo1) .AND. SEEK(tcNo1) DO WHILE 楼栋号 == tcNo1 IF 单元号 != lcStr lnIndex = lnIndex + 1 lcStr = 单元号 DIMENSION ThisForm.aList2[lnIndex] ThisForm.aList2[lnIndex] = lcStr ENDIF SKIP ENDDO ENDIF WITH .FOR lnIndex = 1 TO ALEN(ThisForm.aList2, 1) .AddItem(ThisForm.aList2[lnIndex]) NEXT .ListIndex = 1 ENDWITH ENDFUNC * 获取楼层清单 FUNCTION Get_List3(tcNo1, tcNo2) LOCAL lcStr, lnIndex SELECT "居民信息" SET ORDER TO "Master" lcStr = SPACE(LEN(楼层号)) lnIndex = 1 DIMENSION ThisForm.aList3[lnIndex] ThisForm.aList3[lnIndex] = lcStr IF !EMPTY(tcNo1) .AND. !EMPTY(tcNo2) .AND. SEEK(ThisForm.cList) DO WHILE (楼栋号 == tcNo1) .AND. (单元号 == tcNo2) IF 楼层号 != lcStr lnIndex = lnIndex + 1 lcStr = 楼层号 DIMENSION ThisForm.aList3[lnIndex] ThisForm.aList3[lnIndex] = lcStr ENDIF SKIP ENDDO ENDIF WITH .FOR lnIndex = 1 TO ALEN(ThisForm.aList3, 1) .AddItem(ThisForm.aList3[lnIndex]) NEXT .ListIndex = 1 ENDWITH ENDFUNC * 获取户室清单 FUNCTION Get_List4(tcNo1, tcNo2, tcNo3) LOCAL lcStr, lnIndex SELECT "居民信息" SET ORDER TO "Master" lcStr = SPACE(LEN(户室号)) lnIndex = 1 DIMENSION ThisForm.aList4[lnIndex] ThisForm.aList4[lnIndex] = lcStr IF !EMPTY(tcNo1) .AND. !EMPTY(tcNo2) .AND. !EMPTY(tcNo3) .AND. SEEK(ThisForm.cList) DO WHILE (楼栋号 == tcNo1) .AND. (单元号 == tcNo2) .AND. (楼层号 == tcNo3) IF 户室号 != lcStr lnIndex = lnIndex + 1 lcStr = 户室号 DIMENSION ThisForm.aList4[lnIndex] ThisForm.aList4[lnIndex] = lcStr ENDIF SKIP ENDDO ENDIF WITH .FOR lnIndex = 1 TO ALEN(ThisForm.aList4, 1) .AddItem(ThisForm.aList4[lnIndex]) NEXT .ListIndex = 1 ENDWITH ENDFUNC * 改变楼栋 PROCEDURE Change_List1 WITH ThisForm .cList = .(.) .Get_List3(., .) .Get_List4(., ., .) ENDWITH ENDPROC * 改变单元 PROCEDURE Change_List2 WITH ThisForm .cList = . + .(., .) .Get_List4(., ., .) ENDWITH ENDPROC * 改变楼层 PROCEDURE Change_List3 WITH ThisForm .cList = . + . + .(., ., .) ENDWITH ENDPROC * 改变户室 PROCEDURE Change_List4 WITH ThisForm .cList = . + . + . + . ENDPROC PROCEDURE cnt_Map.Clear WITH This DO WHILE .ControlCount > 0 .RemoveObject(.Controls(.ControlCount).Name) ENDDO ENDWITH ENDPROC * 确定 PROCEDURE Go LOCAL lcStr, lcNumber, lcName, lnRow, lnCol SELECT "居民信息" SET ORDER TO "Master" IF SEEK(ThisForm.cList) lcStr = 楼栋号 + 单元号 + 楼层号 + 户室号 DO WHILE (ThisForm.cList $ lcStr) .AND. !EOF() IF (楼栋号 + 单元号 + 楼层号 + 户室号 == lcStr) .AND. (ALLTRIM(户主关系) == "户主") WITH = STRTRAN(楼栋号 + 单元号 + 楼层号 + 户室号, ' ', '0') lcName = "House_" + lcNumber IF VARTYPE(.&lcName) != "O" lnRow = INT(VAL(楼层号)) lnCol = INT(VAL(户室号)) .AddObject(lcName, "C_Household") WITH .&lcName .Arrange .Top = .Parent.Height - lnRow * (.Height + 5) .Left = (lnCol - 1) * (.Width + 5) ._Number = lcNumber ._Name = ALLTRIM(姓名) .Visible = .T. ENDWITH ENDIF ENDWITH ENDIF SKIP IF (楼栋号 + 单元号 + 楼层号 + 户室号) != lcStr lcStr = 楼栋号 + 单元号 + 楼层号 + 户室号 ENDIF ENDDO ENDIF ENDPROC ENDDEFINE *--------------------------- * 选择器控件 *--------------------------- DEFINE CLASS C_Selector AS Container BorderWidth = 0 BackStyle = 0 PROCEDURE Init LOCAL laItems[4], lnIndex laItems[1] = "楼栋: " laItems[2] = "单元: " laItems[3] = "楼层: " laItems[4] = "户室: " WITH This FOR lnIndex = 1 TO ALEN(laItems, 1) .AddObject("cnt_Get" + TRANSFORM(lnIndex), "myGet") WITH .Controls(lnIndex) .AddObject("Label1", "Label") WITH .Label1 .Caption = laItems[lnIndex] .Width = 40 .Height = 25 .Alignment = 1 ENDWITH .AddObject("Combo1", "ComboBox") WITH .Combo1 .Style = 2 .Width = 60 .Height = 25 ENDWITH .Arrange .Top = 0 .Left = (lnIndex - 1) * (.Width + 5) ENDWITH .Width = .Controls(lnIndex).Left + .Controls(lnIndex).Width NEXT .AddObject("btn_Go", "CommandButton") WITH .btn_Go .Caption = "确定" .Width = 40 .Height = 25 .Top = 0 .Left = This.Controls(ALEN(laItems, 1)).Left + This.Controls(ALEN(laItems, 1)).Width + 20 ENDWITH .Height = 25 .Width = .btn_Go.Left + .btn_Go.Width .SetAll("Visible", .T.) ENDWITH ENDPROC ENDDEFINE *--------------------------- * 住户信息显示控件 *--------------------------- DEFINE CLASS C_Household AS Container BorderWidth = 2 SpecialEffect = 0 _FontName = "微软雅黑" PROCEDURE _FontName_Assign(tcValue) IF VARTYPE(tcValue) != "C" tcValue = "微软雅黑" ENDIF WITH This ._FontName = tcValue .SetAll("FontName", ._FontName) ENDWITH ENDPROC _FontSize = 9 PROCEDURE _FontSize_Assign(tnValue) IF (VARTYPE(tnValue) != "N") .OR. (tnValue < 9) tnValue = 9 ENDIF WITH This ._FontSize = tnValue .Arrange ENDWITH ENDPROC _Width = 100 PROCEDURE _Width_Assign(tnValue) IF (VARTYPE(tnValue) != "N") .OR. (tnValue < 100) tnValue = 100 ENDIF WITH This ._Width = tnValue .Arrange ENDWITH ENDPROC _Height = 16 PROCEDURE _Height_Assign(tnValue) IF (VARTYPE(tnValue) != "N") .OR. (tnValue < 16) tnValue = 16 ENDIF WITH This ._Height = tnValue .Arrange ENDWITH ENDPROC * 房号 _Number = "" PROCEDURE _Number_Assign(tcValue) IF VARTYPE(tcValue) != "C" tcValue = "" ENDIF WITH This ._Number = tcValue .lbl_HouseNumber.Caption = ._Number ENDWITH ENDPROC * 户主名 _Name = "" PROCEDURE _Name_Assign(tcValue) IF VARTYPE(tcValue) != "C" tcValue = "" ENDIF WITH This ._Name = tcValue .lbl_HouseName.Caption = ._Name ENDWITH ENDPROC HIDDEN _Margin _Margin = 4 ADD OBJECT PROTECTED lbl_Title1 AS Label WITH Caption = "房号: ", Alignment = 1, Width = 50, Height = This._Height ADD OBJECT PROTECTED lbl_HouseNumber AS Label WITH Caption = This._Number, Alignment = 2, Width = This._Width, Height = This._Height ADD OBJECT PROTECTED lbl_Title2 AS Label WITH Caption = "户主名: ", Alignment = 1, Width = 50, Height = This._Height ADD OBJECT PROTECTED lbl_HouseName AS Label WITH Caption = This._Name, Alignment = 2, Width = This._Width, Height = This._Height PROCEDURE Arrange WITH This .SetAll("FontSize", ._FontSize) WITH .lbl_Title1 .Height = This._Height .Top = This._Margin .Left = This._Margin ENDWITH WITH This.lbl_HouseNumber .Width = This._Width .Height = This._Height .Top = This.lbl_Title1.Top .Left = This.lbl_Title1.Left + This.lbl_Title1.Width ENDWITH WITH This.lbl_Title2 .Height = This._Height .Top = This.lbl_Title1.Top + This.lbl_Title1.Height + This._Margin .Left = This._Margin ENDWITH WITH This.lbl_HouseName .Width = This._Width .Height = This._Height .Top = This.lbl_Title2.Top .Left = This.lbl_Title2.Left + This.lbl_Title1.Width ENDWITH .Width = .lbl_HouseNumber.Left + .lbl_HouseNumber.Width + ._Margin .Height = .lbl_HouseName.Top + .lbl_HouseName.Height + ._Margin ENDWITH ENDPROC PROCEDURE Resize This.Arrange ENDPROC ENDDEFINE *--------------------------- * 自定义窗体 *--------------------------- DEFINE CLASS myForm AS Form PROCEDURE Arrange * 虛方法 ENDPROC PROCEDURE Activate ThisForm.Arrange ENDPROC PROCEDURE Resize ThisForm.Arrange ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC ENDDEFINE *---------------------- * 仿Get容器 *---------------------- DEFINE CLASS myGet AS Container BorderWidth = 0 BackStyle = 0 PROCEDURE Arrange LOCAL lnIndex WITH This .Height = 0 .Width = 0 FOR lnIndex = 1 TO .ControlCount WITH .Controls(lnIndex) .Top = 0 IF .Height > This.Height This.Height = .Height ENDIF IF lnIndex > 1 .Left = This.Controls(lnIndex - 1).Left + This.Controls(lnIndex - 1).Width + 5 ELSE .Left = 0 ENDIF This.Width = .Left + .Width ENDWITH NEXT ENDWITH ENDPROC PROCEDURE Resize This.Arrange ENDPROC ENDDEFINE