grouping of repetitive functions on User Archives

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Sampleprogram:groupingofrepetitivefunctionsonUserArchivesinonefunction.QUESTION:HowcanIreducetheCcodewithscriptsforaccessingUserArchive?ANSWER:IfyouprogramscriptsforaccessingUserArchive,thentherearelargevolumesofcodefortheadministrationtasks.ThiscodeisthesameforaccessingallUserArchives.Theexamplehereshowsanoptionforgroupingtheadministrationtaskstogetherinonefunction.Thescriptstructurelookslikethisforstandardprogrammingmethods:1.Generatingthesortingandfilteringconditions2.SettingupaconnectiontotheUserArchiveuaConnectuaQueryArchiveByNameiferror:return3.SettingthesortingandfilteringconditionsuaArchiveSetFilteruaArchiveSetSort4.OpeningthequeryuaArchiveOpen5.ActuallyworkingwiththequeryRead,write,delete,insertandsoon.6.ClearingdowntheconnectiontotheUserArchiveuaArchiveCloseuaReleaseArchiveuaDisconnectIfyouprogrameverythingwithfaultcheckinonefunction,thefunctionbecomestoolargeandunclear.Ifyoutakeacloselookatthelistabove,youwillbeabletoseethatonlypoints1and5changefromcasetocase.AlltheotherpointsremainthesamenomatterwhatstructuretheUserArchivehas.Youcansplittheabovestructureinto3functions.1.Thetask-relatedfunctiontakescareofpoint1.Itgeneratesthefiltersandsortingconditions.2.Ageneralfunctionthatencapsulatesalladministrationactions.ThisfunctionappliesforALLUserArchives.Thefunctionreceiveacallbackfunctionasparameter.Thiscallbackfunctioniscalledeitherforeachentryinthequeryorjustoncefortheentirearchive.3.Acallbackfunction,thisfunctionprocesspoint5.Thisdivisionmeansthatyoudon'thavetoworryabouttheadministrationactions.Youprogramjustonefunctionforquerygenerationandonearchive-relatedfunction,whichprocessesthearchiveentries.InthefollowingexampleweusethefunctionuaUtilityEnumRecords.Functiondescription:BOOLuaUtilityEnumRecords(Constchar*pszArchiveName,constchar*lpszFilter,constchar*lpszSort,BOOL(UserFunc)(UAHARCHIVE*phUA,void*pUserData),void*pUserData)Parameters:pszArchiveName:Pointertoazero-terminatedstring.ThestringcontainsthenameofthearchiveasitappearsintheUserArchiveeditor.lpszFilter:Pointertoazero-terminatedstring.Thestringcontainsthefilterconditionforthearchive.ThepointercanalsobeZERO.lpszSort:Pointertoazero-terminatedstring.Thestringcontainsthesortingconditionforthearchive.ThepointercanalsobeZERO.UserFunc:Nameofacallbackfunction.Thefunctioniscalledforeachentryifyoutransferafilter.Thefunctioniscalledoncefortheentirearchiveifyoudonottransferafilter.Thefunctionmustbeofthefollowingtype:BOOL(UserFunc)(UAHARCHIVE*phUA,void*pUserData).pUserData:Pointertouserdata.Thepointerisforwardedwithoutmodificationtothecallbackfunction.Returnvalue:ThefunctionreturnsthevalueTRUEif:nofaultshaveoccurredduringconnectionsetupandclear-down.thecallbackfunctionalwaysreturnsTRUE.OtherwisethevalueFALSEisreturned.Function:TheuaUtilityEnumRecordsfunctioncarriesoutthefollowingsteps:1.SetsupconnectiontotheUserArchive.2.Setsthefilterandsortingconditionsiftheyaretransferred.3.Opensthequery.4.Ifnofilterhasbeenset,thefunctioncallsthecallbackfunctionwiththehandletothearchive.Ifthefilterexists,thecallbackfunctioniscalledinaloopforeachentryinthequerywiththehandletoanentry.AssoonastheCBfunctionreturnsthevalueFALSE,theloopisterminated.ThefunctionuaUtilityEnumRecordsthenreturnstheFALSE.5.Afterthecallbackfunctionhasbeenprocessed,theconnectiontothearchiveissetup.YouseethecodeofthefunctioninthefollowingPDFdocument:uaUtilityEnumRecords_1.pdf(7KB)代码:#includeapdefap.hBOOLuaUtilityEnumRecords(constchar*pszArchiveName,constchar*lpszFilter,constchar*lpszSort,BOOL(UserFunc)(UAHARCHIVE*phUA,void*pUserData),void*pUserData){/*FunctioncreateaQueryforaUserArchivespecifiedbyFilterandsortcondition.FunctioncallsforeachRecordinQueryUserfunctionifFilterspecified.Ifnotfilterspezifiedfunctioncallsuserfunctiononlyonetime.ParameterhArchive:HandletoaUserArchivelpszFilter:PointertoZerroTerminatedstringwithFilterforUserArchive.IfPointeris'ntNULLfunctionmakenewQueryfromArchive,andcallsforEACHrecordUserFunction!IfPointerisNULL:FunctioncreateconectiontoUserArchivewhithoutfilter.InthisCaseuserfunctioniscalledonlyONETIME!!lpszSort:pointertozeroterminatedstringwithsortconditionlpFunc:PointertoUserFunction.pUserData:PointertoParameterStructforUserFunction.*/BOOLreturnCode=TRUE;constchar*funcName=uaUtilityEnumRecords;UAHCONNECThConnect;BOOLreturnCode=TRUE;//GetConnectiontoUserArchivesreturnCode=uaConnect(&hConnect);if(!returnCode||!hConnect){returnCode=FALSE;printf(%sfaultinuaConnect\r\n,funcName);}else{//GetHandletoActualArchive.UAHARCHIVEhArchive;if(!uaQueryArchiveByName(hConnect,pszArchiveName,&hArchive)){printf(%s:uaQueryArchiveError:%d\r\n,funcName,uaGetLastError());returnCode=FALSE;}else{if(lpszFilter)returnCode=uaArchiveSetFilter(hArchive,lpszFilter);if(lpszSort)returnCode=(returnCode&&uaArchiveSetSort(hArchive,lpszSort));if(!returnCode){printf(%s:uaArchiveSetFilter\r\n,funcName);}else{//OpenDatareturnedbyQueryif(uaArchiveOpen(hArchive)){//IfFilterspecified:GotoFirstRecordinQueryif(!lpszFilter)//ifnoneFilterspecified:calluserfunkctiononeTimeonly{if(!(returnCode=UserFunc(&hArchive,pUse

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功