CopyrightIBMCorporation2006TrademarksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage1of17IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETHowtouseEnterpriseCoreObjectstocreatemodel-drivenASP.
NETapplicationswithIBMDB2UDBBobSwartJanuary26,2006UseBorlandDelphi2005andtheEnterpriseCoreObjects(ECO)toimportanIBMDB2UniversalDatabase(DB2UDB)databaseandcreateaUMLobjectmodelforit,whichisthebasisforanASP.
NETWebapplication.
FollowinguponthepreviousECOarticle(whichproducedaWinFormsapplication),thisarticleprovidesexamplesthatuseIBMDB2UDBasthebasisfortheEcoSpace,presenttheUMLmodeloftheEmployeeandDepartmentclasseswithassociations,andgenerateASP.
NETWebforms.
UsingEnterpriseCoreObjectsIILasttime,wecreatedanECOWinFormsApplicationinDelphi2005,butthistime,we'llmakeanECOASP.
NETWebApplication.
StartDelphi2005,selectFile>New>Other,andfromtheDelphifor.
NETProjects,double-clicktheECOASP.
NETWebApplicationicon,asshowninFigure1.
developerWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage2of17Figure1.
Delphi2005ObjectRepositoryThisstartstheECOASP.
NETWebApplicationwizard,whereyouonlyhavetospecifythenameoftheproject,likeECO2DB2ASPinthiscase(seeFigure2).
Optionally,youcanspecifythelocation,althoughbydefaultthenameoftheprojectwillbeusedasthenameofthenewASP.
NETvirtualdirectoryinIISaswell.
Figure2.
NewECOASP.
NETWebApplicationClickOKtocreatetheECOASP.
NETWebApplication,whichconsistsofanumberofgeneratedsourcefiles.
Beforeyoucontinue,compileandsavetheproject,closetheprojectandreopenitagain.
ThiswillensurethattheECOcomponentsthatarealreadyplacedinthedifferentformsanddesignersstartwiththecorrectvalue(thetypeoftheEcoSpaceforexample),whichisonlyknownaftercompilingtheproject.
ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage3of17Afteryou'vereopenedtheproject,youhavetoperformthreesteps:designyourUMLmodel,createandspecifythe(empty)IBMDB2UDBdatabasetostoretheUMLmodel,anddesigntheASP.
NETWebuserinterfaceforthemodel.
DesigningtheUMLmodelLikelasttime,IwillfocusontheEMPLOYEEandDEPARTMENTtablesintheIBMDB2UDBSAMPLEdatabase,andrecreatethemasEmployeeandDepartmentclassesintheECOUMLmodel.
ClicktheModelViewtabintheProjectManager,andopentheCoreClassesnode.
Thendouble-clicktheCoreClasseschildnode,whichwillstarttheUMLDesigner.
HereyoucanuseUMLdesignelementstodrawyourdesignfortheEmployeeandDepartmentclasses,likewedidlasttimefortheWinFormsexample(sothiswillbeabitshorterandquickerthaninthepreviousarticle).
TheIBMDB2UDBSAMPLEdatabasecontainsanEMPLOYEEtablewithanEMPNOfieldthatisusedasidentifyingfield,bothforitself(askeyfield,althoughit'snotspecifiedtobethekeyfield),andfortheDEPARTMENTtablewhichusesitfortheMGRNOfield.
TheEMPLOYEEtablealsohasaWORKDEPTfield,whichcanbeusedtomapwiththeDEPTNOfieldintheDEPARTMENTtable.
Andfinally,theDEPARTMENTtablehasaADMRDEPTfieldwhichisacircularlinktoitself(identifyingdepartmentsthatmanageotherdepartments).
ThesekeyandforeignkeyfieldsareuselessinUMLobjectmodels,sowewillnotaddthemtotheclassdesigns,butwillimplementtheimplicitfunctionalitythattheystandforusingexplicitassociations.
DesigningtheEmployeeclassRight-clickthedesignerareaoftheCoreClassesdesignerandusethepop-upmenutoaddanewECOClass.
NameitEmployee.
TheIBMDB2UDBSAMPLEdatabaseusedtheEMPNOfieldasuniquevaluetodeterminetheemployee,whichwasusedbytheDEPARTMENTtableaswell,butyoucanskipthisfield(justliketheWORKDEPTfield),sinceECOitselfwilladduniqueindexfieldstoidentifyclassinstances.
Right-clicktheEmployeeclassandusethepop-upmenutoaddattributes.
AddtheFirstNameattributeoftypeString,theMidInitattributeoftypeWideChar,theLastNameattributeoftypestring,thePhoneNoattributeoftypeString,theHireDateattributeoftypeDateTime,theJobattributeoftypeString,theEdLevelattributeoftypeInteger,theSexattributeoftypeWideChar,theBirthdateattributeoftypeDateTime,andtheSalary,Bonus,andCommattributesoftypeCurrency.
DesigningtheDepartmentclassRight-clickonthedesignerareaandaddanewECOClasscalledDepartment.
YoucanskiptheDEPTNOfield(justliketheEMPNOfield),sostartwiththeDeptNamefieldoftypeString.
TheMGRNOfieldisactuallyalinkbacktotheEMPLOYEEtable,andwe'lldealwiththatinaminutewhenaddingassociated,soskipthatfieldaswell.
SamewiththeADMRDEPTfield,whichdeveloperWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage4of17isactuallyalinkfromtheEMPLOYEEtablebacktoitself.
TheonlyfieldyouneedtoaddistheLOCATIONfieldoftypeString.
AddingAssociationRelationsWiththeEmployeeandDepartmentclassesdesigned,youmustnowdesigntheassociationsbetweenthem(whichwereimplicitlydefinedusingtheEMPNOandWORKDEPTfieldsoftheEMPLOYEEtable,andtheDEPTNO,MGRNO,andADMRDEPTfieldsoftheDEPARTMENTtable).
TheWORKDEPTfieldoftheEMPLOYEEtableobviouslypointedtotheDEPARTMENTtable,usingtheDEPTNOfieldtolinkto.
ThiscanbereplacedbyanassociationfromEmployeetoDepartment.
IntheToolPalette,selecttheAssociationelement,thenclickontheEmployeeclass,holddownthemousebutton,anddragtotheDepartmentclass.
ThiswilldrawanassociationbetweenEmployeeandDepartment.
UsetheObjectInspectortosetthenameofthenewassociationtoEmployment.
Anhastwoends:oneattheEmployeesideandoneattheDepartmentside,bothsetto0.
.
1multiplicitybydefault.
BasedonthefactthattheoriginalWORKDEPTfieldintheEMPLOYEEtablepointedtotheDEPTNOfieldintheDEPARTMENTtable,youcanassumethatanEmployeecanlinktoonlyoneDepartment(ornone,sinceWORKDEPTisanullablefield),sothemultiplicitycanremain0.
.
1.
FortheDepartment,itmeansthatzeroormoreEmployeescanbelinkedtoit.
SoattheEmployeeside,themultiplicitymustchangefrom0.
.
1to0.
.
*.
NowyoumustaddthelinkbackfromtheDepartmentclasstotheEmployeeclass,implementingtheMGRNOfield.
ThistimethemultiplicitymustbesetsothataDepartmentismanagedby0or1Employees(MGRNOisnullable),andanEmployeecaninfactmanagezeroofmoreDepartments.
Onlyonerelationshipleft:replacingtheADMRDEPTfield,whichisbetweentheDepartmentclassanditself(oneDepartmentismanagedbyanotherDepartment,whichinturncanmanagemultipleDepartments).
ThisisdonebyanassociationbetweenDepartmentanditself.
ThefinalUMLmodelcanbeseeninFigure3.
Figure3.
Employee-DepartmentUMLmodelAlthoughyounolongerhavetheEMPNOandWORKDEPTfields(intheEMPLOYEEtable)northeDEPTNO,MGRNO,andADMRDEPTfields(intheDEPARTMENTtable),thenewUMLmodelcanstorethesameinformationthroughtheexplicitassociationrelations.
ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage5of17CreatinganemptyIBMDB2ECODatabaseNormally,youwouldneedanemptydatabaseasacontainertostoretheEcoSpace.
Delphi2005comeswithaCD-ROMthatcontainstheIBMDB2UDBDeveloperedition.
YoucanusetheControlCenter(foundintheIBMDB2GeneralAdministratorTools),andintheControlCenterusethetreeviewtobrowseyoursystem,DB2instancesanddatabases.
Createanewdatabaseusingthewizard,whichwillgiveyoua7-stepwizardwhereyouonlyhavetospecifythenameofthenewemptydatabase(somethinglikeECO2ASP).
TheSQLDDLwhichisusedtocreatethedatabaseisasfollows:CREATEDATABASEECO2ONC:USINGCODESETIBM-1252TERRITORYUSCOLLATEUSINGSYSTEM;AftertheemptyIBMDB2UDBECO2databasehasbeencreated,youneedtogototheDataExplorerandaddanewDB2ConnectiontotheECO2database.
Makesuretospecifytherightdatabasename(ECO2)andavalidusernameandpasswordtoconnecttoit.
ConfiguringtheEcoPersistenceMapperProviderWiththeUMLmodelreadyandtheemptyIBMDB2UDBECO2databasecreated,it'stimetomakethemodelpersistent.
Lasttime,inasingle-userWinFormapplication,youcouldplacethePersistenceMapperBdpcomponentintheEcoSpaceunit.
However,thistimeyou'rebuildingamulti-userASP.
NETWebFormsapplication,whichmeanstheapplicationmustbemulti-useraware,sharingthemodelindifferentthreads.
ThisishandledbyaspecialEcoPersistenceMapperProviderunit.
IntheProjectManager,double-clicktheEcoPersistenceMapperProvider.
pasnode,andthenclickthedesigntabsoyoucanplacetherequiredcomponents.
First,placeaPersistenceMapperBdpcomponentontheEcoPersistenceMapperProviderdesignarea,andclickontheDB2SetuplinkatthebottomoftheObjectInspector.
ThendragtheBDPConnectioncomponentfromtheDataExplorer(theonepointingtotheemptyIBMDB2UDBECO2database)andplaceitnexttothePersistenceMapperBdpcomponent.
Ifyoudoitinthisorder,thenallthenecessarypropertieswillbelinkedautomatically(thatis,thePersistenceMapperpropertyoftheEcoPersistemceMapperProviderwillbepointingtothePersistenceMapperBdpcomponent,andtheConnectionpropertyofthePersistenceMapperBdpwillbepointingtotheBdpConnectioncomponent).
There'sonepropertyyoumustsetmanually,andthat'stheSyncActivepropertyofthePersistenceMapperBdpcomponent.
SetthistoTrue.
YoumustnowgeneratetherequiredtablesfortheEcoSpaceandaddthemtotheemptyIBMDB2UDBECO2database.
Todothis,clicktheleftmostbuttonatthebottomoftheEcoPersistenceMapperProviderdesigner,whichsaysGenerateSchema.
Afteryouclickthebutton,theapplicationisrecompiled,andadialogboxdisplayswhichtablescan(optionally)bedeleted,whichtablesmustbedroppedandrecreated,andwhichnewtableswillbecreatedinthedatabase,asshowninFigure4.
developerWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage6of17Figure4.
GenerateSchemaAfteryouclicktheOKbutton,thesevennewtablesareaddedtotheIBMDB2UDBECO2database.
ApartfromtheEMPLOYEEandDEPARTMENTtables,yougetfiveECOspecifictablesthatareneededfortheEcoSpacemanagementitself.
Thereisonlyonestepleft:buildingauserinterfaceontopoftheEcoSpace,thistimeusingASP.
NETWebFormsinsteadof.
NETWinForms.
BuildingtheASP.
NETuserinterfaceTheASP.
NETuserinterfaceisbuiltintheWebForm1.
aspxfile.
ToopenthisunitintheHMTLdesigner,double-clicktheWebForm1.
aspxnodeintheProjectManager.
WheretheWinForm(fromlasttime)hadfivecomponentsalreadypresentinthenon-visualcomponentareaoftheWinFormsDesigner,theASP.
NETWebFormsDesigneronlyshowsonecomponent:therhRootReferenceHandletotherootoftheEcoSpace(andallobjectinstancesinsideit).
YouneedtoaddanadditionalcomponentfromtheEnterpriseCoreObjectscategory,namelyanExpressionHandler.
AnExpressionHandleislinkedtoeitheraReferenceHandle(likerhRoot)oranotherExpressionHandle.
YoucanuseittoevaluateanOCL(ObjectConstraintLanguage)expression.
Inthiscase,theExpressionHandlewillbecalledehEmployeeandconnectedwithitsRootHandlepropertytorhRoot.
IntheExpressionproperty,youcanusetheOCLExpressionEditoragaintobuildtheEmployee.
allInstancesexpression,justlikelasttime.
What'sdifferentthistimeisthatyoualsoneedtosettheAddExternalIdpropertyoftheehEmployeeExpressionHandlertoTrue(you'llusetheExternalIdfieldinaminute).
Now,placeaDataGridcomponentontheWebForm,andassignitsDataSourcetotheehEmployeeExpressionHandler.
AlsosettheDataKeyFieldpropertyoftheDataGridcomponenttoExternalId(thisisimportant),soitwillusetheinternalECO"key"asanIDforexternaluse(sowecanidentifywhichitemintheDataGridisthecurrentone,forexample).
ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage7of17TheresultisthattheDataGridwillshowthemetadata--thenamesandtypesoftheattributesoftheEmployeeclass,includingtheExternalIdfield(aninternalfieldaddedbyECOthatyoudon'treallyneedtoshow).
InordertomakesuretheExternalIdfieldisnotshown,clickthePropertyBuilderverbatthebottomoftheObjectInspector.
ThiswillstarttheDataGridPropertiesdialogbox.
Here,youcanspecifywhichfieldsyouwanttosee,andwhichtohide.
Theleftsideofthisdialogboxshowsfivecategories.
Youneedthesecondone,forthecolumns.
Inthispage,youcanselectthecolumnsthatyouwanttosee(movethemfromthelistboxonthelefttotheright),forexampletheFirstName,MidInit,LastName,andPhoneNobutnoneoftheotherfields(seeFigure5).
Figure5.
DataGridPropertiesThere'sonemorethingyouneedtodobeforeclosingtheDataGridPropertieseditor:atthetopoftheColumnspageisthecheckboxfortheCreatecolumnsautomaticallyatruntimeoption.
Ifyoudon'tuncheckthatoption,thenyougetyourselectedcolumnsaswellasallnormalcolumns(someofthemtwice).
Souncheckthatoptiontomakesureyouonlygetthecolumnsyou'veselected.
That'safeatureofMicrosoft'sASP.
NETDataGrid,bytheway,notspecificallyincombinationwithECOorDB2.
Afteryou'veuncheckedthisoption,youcanclickOKtoclosetheDataGridPropertiesdialogbox.
developerWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage8of17Now,atthebottomoftheObjectInspectorthereisanotherverbcalledAutoFormatwhichyoucanusetogivetheDataGridaquicklook.
IfyouclicktheAutoFormatverb,youcanselectalayoutfortheDataGrid,likeColorFul3(youcanseetheresultinoneofthenextscreenshots).
ViewingthefirstresultinthebrowserYoucanalmostviewthefirstresultinabrowser.
There'sonethingmissing:theabilitytoaddnewEmployeeobjectstotheEcoSpace.
Forthis,youneedaButtoncontrol,placedsomewherenexttotheDataGrid,withtheTextpropertysettoNewEmployeeandthefollowingimplementationforitsClickeventhandler:Listing1.
NewEmployeeObjectprocedureTWebForm1.
Button1_Click(sender:System.
Object;e:System.
EventArgs);varNewEmployee:Employee;beginNewEmployee:=Employee.
Create(EcoSpace);NewEmployee.
Firstname:='Robert';NewEmployee.
MidInit:='E';NewEmployee.
Lastname:='Swart';NewEmployee.
PhoneNo:='42';UpdateDatabase;DataBind;end;ThisexamplecreatesanewinstanceofanEmployeewhilepassingtheEcoSpaceasanargumenttotheconstructor,inordertomakesurethattheEmployeeislivinginourEcoSpace.
ItalsoassignssomeinitialvaluestotheFirstName,MidInit,LastName,andPhoneNoattributes,althoughit'sgenerallyOKtoleavetheseemptyfornewobjects.
Youcaneditthemlaterandenterthecorrectvalues.
ThecalltoUpdateDatabaseensuresthattheunderlyingdatabaseisupdatedwiththecontentsofthemodifiedEcoSpace.
ThecalltoDataBindmakessurethattheASP.
NETcontrolsareupdated(specificallythattheDataGriddisplaysthenewresultoftheehEmployeeExpressionHandler).
Ifyoucompileandruntheapplication,however,you'llquicklynoticethatyoucanenternewEmployees,butthereisnowaytomodifytheminanyway,ortodeletethemforthatmatter.
AndalthoughIamahardworker,itdoesn'tseemverysensibletohaveanEcoSpacewithRobertE.
SwartastheonlyEmployeeavailable.
WorkingwiththeECODataintheBrowserSo,youneedtoaddtheabilitytoeditthecontentsoftheDataGrid.
SelecttheDataGrid,andclickthePropertyBuilderverbagaintostarttheDataGridPropertiesdialogbox(likeinFigure5).
GototheColumnspageagain.
Apartfromregularcolumns,youalsoneedtohaveButtons.
IntheAvailablecolumnslistbox,scrolldowntotheButtonColumn.
SelecttheEdit,Update,Cancel,andDeletebuttons,andclickonthearrowtoaddthemtotheSelectedcolumnslistbox.
Youcancustomizethebuttons,forexamplechangingtheirtypetoPushButtoninsteadofLinkButton.
Whenyou'refinished,closethedialogbox.
ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage9of17NowyouneedtoassigntheeventsthattheDataGridfiresfortheEdit,Update,Cancel,andDeletecommands.
GototheEventstaboftheObjectInspector,andopenupthedrop-downcomboboxfortheEditCommandeventhandler.
Itdisplaysanumberofoptions(whichweregeneratedbytheECOwizardswhenyoucreatedtheASP.
NETECOproject).
FortheEditCommand,connecttheeventhandlertotheDataGrid_EditCommandmethod.
DothesamethingfortheUpdateCommand(toDataGrid_UpdateCommand),theCancelCommand,andtheDeleteCommand.
YoucannowruntheASP.
NETECO2applicationandusethebuttonnexttotheDataGridtocreatenewEmployeeobjects,andthebuttonsintheDataGridtoedit,update,cancel,ordeletetheEmployeeobjectsagain(asshowninFigure6).
Figure6.
ECOEmployeesinASP.
NETThereisoneproblem:theDataGriddoesn'tcontainallattributesoftheEmployeeclass(otherwisetheDataGridwouldbetoowideforthescreen).
Sowecannoteditallfields.
Cometothinkofit,wouldn'titbenicertobeabletoselectanEmployeeintheDataGridandclickonaButtonorLinktogotoadetailpagewhereyoucaneditallfieldsAbitliketheAutoFormsintheWinFormsversionoftheECOproject.
Andwhileyou'reatit,youcouldaddtheabilitytoaddandlinktoDepartmentobjectsaswell.
CreatinghyperlinkdetailslinksGobacktoDelphi2005,gototheHTMLdesigner,selecttheDataGrid,clickthePropertyBuilderlinkagain,andaddanothernewcolulmn:thistimeaHyperLinkcolumn.
SettheTextpropertytoDetails,theURLfieldtotheExternalId,andtheURLformatpropertyto:EmployeeDetails.
aspxRootId={0}Thiswillmakesurethatforagivenrow,theDetailslinkwillpointtotheEmployeeDetails.
aspxpage(whichyouwillneedtocreate),passingasRootIdthevalueoftheExternalIdinternalkeyfield.
Neat,huhdeveloperWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage10of17AddinganemployeedetailspageNow,selectFile>New-Other,gototheASP.
NETFilescategoryintheObjectRepository,andaddanECOASP.
NETPagetotheproject.
Makesureyoudon'taddaregularASP.
NETPage,butanECOASP.
NETPage.
OnlythelatterhasthecodetosupportECO(hookingintotheDataGrid'sevents,andretrievingtheRootIdvalueasstartingpointfortherhRootReferenceHandle,pointingtotherightEmployeeclassinstance).
NowyouneedtosavethenewECOASP.
NETPageinEmployeeDetails.
aspx(sincethat'sthepagenamethatyouusedintheURLformatpropertyoftheDetailsHyperlink).
InthecodeeditorfortheEmployeeDetails.
pasfile,addtheCoreClassesUnittotheusesclause,sothatthenewECOASP.
NETPageknowsabouttheclasstypesintheEcoSpace.
Then,gototheDesignviewagain,andclickontherhRootandsettheEcoSpaceTypetoECO2DB2ASPEcoSpace.
TECO2DB2ASPEcoSpace(justopenupthedrop-downcomboboxfortheEcoSpaceTypepropertyandselecttheonlychoiceavailable).
SettheStaticValueTypetoEmployee(thisyouwillhavetoentermanually),toindicatethattheelementthattherhRootpointstoisanEmployee,sothatyougetvaliddesign-timesupport.
Now,placeanExpressionHandlercomponentnexttotheRhRoot,callitehEmployee,setitsRootHandlepropertytorhRoot,theAddExternalIdpropertytoTrue,andtheExpressionpropertytoself(whichwillbethecurrentEmployeeclassinstancethatwasselectedinthepreviousASP.
NETpage).
Now,insteadofaddingaDataGrid,whichwillagainbetoowideifyouaddallcolumnstoit,youshouldinsteadaddindividualASP.
NETTextBoxcontrolstobindtotheattributesoftheEmployee.
PlaceaTextBoxcontrolontheECOASP.
NETWebForm,andclickontheellipsis(.
.
.
)fortheDataBindingproperty.
ThiswillopenadialogboxthatyoucanusetoconnecttheTextpropertytotheehEmployee[0]'sFirstNamefield,asshowninFigure7.
ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage11of17Figure7.
SimpleDataBindingtoECOExpressionHandleYoucandothisforallindividualfields,andendupwithalongdetailpageshowingtheTextBoxesoneundereachother.
Inordertogetanicelayout,it'srecommendedtouseanHTMLtablethatyoucaninsertusingTable>Insert-Table.
AnHTMLtableof12rowswith2columnsisenoughfortheFirstName,MidInit,LastName,PhoneNo,HireDate,Job,EdLevel,Sex,Birthdate,Salary,Bonus,andCommattributes.
IthelpsifyougivetheTextBoxcontrolssensiblenamesliketbFirstName,tbMidInit,andsoon.
Afteryou'veaddedthe12ASP.
NETTextBoxcontrolsintherightcolumnoftheHTMLtable,youcanenterthelabelsintheleftcolumn,andaButtonundertheHTMLtablewiththecaptionSaveandReturnonit,whichyouneedtoimplementtosavethecontentsoftheTextBoxcontrolsbackinthecurrentEmployee,andreturntotheoriginalASP.
NETpage(whichisprobablystillcalledWebForm1.
aspx).
ThecodefortheButtonClickeventisasfollows,notetheuseofthesensiblenamesfortheTextBoxcontrols:Listing2.
NewEmployeeObjectprocedureTWebForm2.
Button1_Click(sender:System.
Object;e:System.
EventArgs);varEmp:Employee;begintryEmp:=(rhRoot.
Element.
AsObjectasEmployee);Emp.
FirstName:=tbFirstName.
Text;Emp.
MidInit:=tbMidInit.
Text[1];Emp.
LastName:=tbLastName.
Text;Emp.
PhoneNo:=tbPhoneNo.
Text;Emp.
HireDate:=Convert.
ToDateTime(tbHireDate.
Text);Emp.
Job:=tbJob.
Text;Emp.
EdLevel:=Convert.
ToInt32(tbEdLevel.
Text);developerWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage12of17Emp.
Sex:=tbSex.
Text[1];Emp.
Birthdate:=Convert.
ToDateTime(tbBirthdate.
Text);Emp.
Salary:=Convert.
ToDouble(tbSalary.
Text);Emp.
Bonus:=Convert.
ToDouble(tbBonus.
Text);Emp.
Comm:=Convert.
ToDouble(tbComm.
Text);UpdateDatabase;DataBind;Response.
Redirect('WebForm1.
aspx');exceptonE:ExceptiondoResponse.
Write(E.
Message);end;end;Atdesigntime,theECOASP.
NETDetailPagefortheEmployeecanbeseeninFigure8.
Figure8.
EmployeeDetailPageSaveAll,Compile,andRuntheapplication.
YoucannowaddnewEmployeeobjects,andclickontheDetailshyperlinktogototheEmployeeDetailspagewhereyoucaneditthedetails,andclickonSaveandReturntocontinue.
Obviously,ifyoudon'twanttosavethechanges,youneedabuttonthatonlydoestheResponse.
RedirectinitsClickevent(Ileavethataseasyexerciseforthereader).
AddingDepartmentsintothemixTimetothrowtheDepartmentclassintothemix.
Ontheoverviewpage,wherewehavetheDataGridshowingthefouroftheEmployeefieldswithButtonsandDetailhyperlinks,plusanAddButtontoaddnewEmployeeobjects,youcandothesamethingforDepartments.
ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage13of17PlaceanotherExpressionHandle,callitehDepartment,pointitsRootHandlepropertytorhRoot,settheAddExternalIdpropertytoTrue,andasExpressionpropertywriteDepartment.
allInstances.
PlaceaDataGridontheASP.
NETWebForm,connectitsDataSourcepropertytoehDepartment,settheDataKeyFieldtoExternalId,andmakesureonlytheDeptNameandLocationpropertiesarevisible.
Thistime,thereareonlytwocolumns,sowecanEdit,Update,Cancel,andDeletefromtheDataGridwithouttheneedforadetailpage.
ButweneedaspecialAddButton,tocreatenewDepartmentinstances,implementedasfollows:Listing3.
NewDepartmentObjectprocedureTWebForm1.
Button2_Click(sender:System.
Object;e:System.
EventArgs);varNewDept:Department;beginNewDept:=Department.
Create(EcoSpace);NewDept.
DeptName:='DeptName';NewDept.
Location:='Location';UpdateDatabase;DataBind;end;NotethattheDeptNameandLocationvaluesareonlydefaultvaluesthatneedtobechangedusingtheEditandUpdatebuttonsintheDataGrid,asyoucanseeinFigure9.
Figure9.
EmployeeandDepartmentsatruntimedeveloperWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage14of17ShowingrelateddepartmentsThere'sonefinalthinglefttodo:oncealistofvalidDepartmentsexists,youcanassigntheEmployeetooneoftheexistingDepartments(thistakescareoftheEmployeesassociationbetweenzeroormoreEmployeesandoneDepartment--seeFigure3).
Forthis,youneedtogobacktotheEmployeeDetails.
aspxpage.
BelowtheTextBoxcontrolsfortheselectedEmployee,youwanttoshowaDataGridwithallavailableDepartments,allowingyoutoassigntheEmployeetooneoftheseDepartments.
Firstofall,showthecurrentDepartmentassignedtotheEmployeeusingtheWorksAtassociation.
Forthese,youcanuseanewExpressionHandlecalledEmployeeDepartment,withitsRootHandlepointedtoehEmployee(theExpressionHandle)andasExpressionpropertyself.
WorksAt.
ThiswillensurethattheDeptNamebelongingtotheDepartmentassociatedviatheWorksAtlinkcanbeobtainedusingtheehEmployeeDepartmentExpressionHandle.
Notethatitcanhavezerooronevalues,soyoucannotusesimpledatabindingtoshowtheresult.
Instead,youcanwriteonelineofcodeinthePage_Loadtodeterminethevalue,andthenprintit:Listing4.
SelectRightEmployeeprocedureTWebForm2.
Page_Load(sender:System.
Object;e:System.
EventArgs);varId:string;beginEcoSpace.
Active:=True;Id:=Request.
Params['RootId'];ifAssigned(Id)and(Id'')thenrhRoot.
SetElement(ObjectForId(Id));ifAssigned(ehEmployeeDepartment.
Element)thenResponse.
Write('Worksfor:'+(ehEmployeeDepartment.
Element.
AsObjectasDepartment).
DeptName);ifnotIsPostBackthenDataBind;end;LinkingEmployeeswithDepartmentsThelaststepshowstheassociatedDepartment,butdoesn'tactuallymaketheassociation.
Forthat,weneedasecondReferenceHandle,calledrhDepartments.
SetitsEcoSpaceTypepropertytoECO2DB2ASPEcoSpace.
TECO2DB2ASPEcoSpace.
ThenplaceathirdExpressionHandlecomponent,setrhDepartmentasitsroot,theAddExternalIdpropertytoTrue,andsetitsExpressionpropertytoDepartment.
allInstancesinordertolistallavailableDepartmentsintheEcoSpace.
Then,placeaDataGridtodisplaytheDepartmentclasses,setitsDataSourcetoehDepartments,DataKeyFieldtoExternalId,andusetheDataGridPropertyBuildertomakesureonlytheDeptNameandLocationfieldsareshown.
Then,addaSelectbuttonwithTextpropertysettoWorkHere.
TheimplementationoftheSelectedIndexChangeeventisasfollows:ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage15of17Listing5.
LinkEmployeetoDepartmentprocedureTWebForm2.
DataGrid1_SelectedIndexChanged(sender:System.
Object;e:System.
EventArgs);varIDep:IObject;Dep:Department;beginId:=DataGrid1.
DataKeys[DataGrid1.
SelectedIndex].
ToString;IDep:=ObjectForId(Id);Dep:=(IDep.
AsObjectasDepartment);(rhRoot.
Element.
AsObjectasEmployee).
WorksAt:=Dep;UpdateDatabase;DataBind;end;Forallthistowork,youmustensurethatthenewrhDepartmentroothandleisassignedtotheEcoSpace,whichcanbedoneinthePage_Loadeventagain.
ThefinalEmployeeDetailpagecanbeseeninFigure10(whereI'vealreadyassignedRobertE.
SwarttoworkintheTrainingDepartment).
developerWorksibm.
com/developerWorks/IBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage16of17Figure10.
EmployeedetailandDepartmentpageTheotherassociations--fromDepartmenttoManagerandfromDepartmenttoDepartment--areleftasexerciseforthereader.
Withtheexamplesshowninthisarticle,I'msureyoucandesignandimplementtherestofthisprojectforyourself.
SummaryInthisarticle,you'veusedDelphi2005andEnterpriseCoreObjectsII,buildinganASP.
NETWebapplication,whilestillusingtheIBMDB2UDBdatabaseasbasisfortheEcoSpace,presentingtheUMLmodelofthedataandgeneratingASP.
NETWebforms.
I'veshownhowtocreateclassinstances,howtoedit,cancel,update,anddeleteitemsintheDataGrid,howtojumptodetailpages(foraselecteditem),andevenhowtobuildassociationrelationswithASP.
NETWebpages.
ibm.
com/developerWorks/developerWorksIBMDB2databaseswithEnterpriseCoreObjectsandASP.
NETPage17of17DownloadableresourcesDescriptionNameSizeSamplesourcecodeforthisprojectsource.
zip(HTTP|FTP)35KBCopyrightIBMCorporation2006(www.
ibm.
com/legal/copytrade.
shtml)Trademarks(www.
ibm.
com/developerworks/ibm/trademarks/)
每每进入第四季度,我们就可以看到各大云服务商的促销力度是一年中最大的。一来是年底的促销节日活动比较多,二来是商家希望最后一个季度冲刺业绩。这不还没有到第四季度,我们看到有些商家已经蠢蠢欲动的开始筹备活动。比如素有低价VPS收割机之称的Virmach商家居然还没有到黑色星期五就有发布黑五促销活动。Virmach 商家有十多个数据中心,价格是便宜的,但是机器稳定性和速度肯定我们也是有数的,要不这么低的...
如今我们还有在做个人网站吗?随着自媒体和短视频的发展和兴起,包括我们很多WEB2.0产品的延续,当然也包括个人建站市场的低迷和用户关注的不同,有些个人已经不在做网站。但是,由于我们有些朋友出于网站的爱好或者说是有些项目还是基于PC端网站的,还是有网友抱有信心的,比如我们看到有一些老牌个人网站依旧在运行,且还有新网站的出现。今天在这篇文章中谈谈有网友问关于个人网站备案的问题。这个也是前几天有他在选择...
OneTechCloud(易科云)是一家主打CN2等高端线路的VPS主机商家,成立于2019年,提供的产品包括VPS主机和独立服务器租用等,数据中心可选美国洛杉矶、中国香港、日本等,有CN2 GIA线路、AS9929、高防、原生IP等。目前商家针对全场VPS主机提供月付9折,季付8折优惠码,优惠后香港VPS最低季付64元起(≈21.3元/月),美国洛杉矶CN2 GIA线路+20Gbps防御型VPS...
selectedindexchanged为你推荐
刷网站权重提升百度权重的几个方法人人时光机求徐智勇的时光机的歌词,百度上全是周杰轮跟五月天的,我要粤语啊伪静态什么是伪静态伪静态有何作用1433端口怎么去看1433端口在线代理网站求有效的代理服务器地址?显卡温度多少正常显卡温度多少正常qq空间装扮qq空间怎么装扮vbscript教程请教一下高手们,这个VBS脚本难不难啊,我想学学这个,但是又不知道该从哪入手,希望高手指点指点??畅想中国未来的中国是什么样子的mate8价格华为mate8 128g售价多少钱
免费网站域名注册 备案域名出售 hostgator winhost 缓存服务器 新世界电讯 xen 免费ftp站点 铁通流量查询 ibox官网 架设服务器 php空间推荐 共享主机 100mbps 彩虹云 腾讯总部在哪 带宽租赁 ledlamp 卡巴斯基官网下载 卡巴斯基试用版下载 更多