relationshipselectedindexchanged

selectedindexchanged  时间:2021-02-26  阅读:()
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/)

DogYun(300元/月),韩国独立服务器,E5/SSD+NVMe

DogYun(中文名称狗云)新上了一批韩国自动化上架独立服务器,使用月减200元优惠码后仅需每月300元,双E5 CPU,SSD+NVMe高性能硬盘,支持安装Linux或者Windows操作系统,下单自动化上架。这是一家成立于2019年的国人主机商,提供VPS和独立服务器租用等产品,数据中心包括中国香港、美国洛杉矶、日本、韩国、德国、荷兰等。下面分享这款自动化上架韩国独立服务器的配置和优惠码信息。...

DMIT$10.9/月,日本VPS/三网直连/1核1.5G内存/20GB存储/1Gbps端口

优惠码年付一次性5折优惠码:TYO-Lite-Open-Beta-1y-50OFF永久8折优惠码:TYO-Lite-Open-Beta-Recur-20OFF日本vpsCPU内存SSD流量带宽价格购买1核1.5G20 GB4 TB1Gbps$10.9/月购买2核2 G40 GB6 TB1Gbps$16.9/月购买2核4 G60 GB8 TB1Gbps$21.9/月购买4核4 G80 GB12 TB...

爱用云互联租用服务器租美国、日本、美国、日本、购买2天内不满意可以退换,IP可免费更换!

爱用云互联怎么样?爱用云是一家成立于2018年的老牌商家旗下的服务器销售品牌,是正规持证IDC/ISP/IRCS商家,主要销售国内、中国香港、国外服务器产品,线路有腾讯云国外线路、自营香港CN2线路等,都是中国大陆直连线路,非常适合免备案建站业务需求和各种负载较高的项目,同时国内服务器也有多个BGP以及高防节点。专注为个人开发者用户,中小型,大型企业用户提供一站式核心网络云端服务部署,促使用户云端...

selectedindexchanged为你推荐
硬盘人电脑对人有多大辐射?创维云电视功能谁能具体介绍一下创维云电视的主要功能,以及基本的使用方式,如果能分型号介绍就更好了,O(∩_∩)O谢谢iphone6上市时间苹果6什么时候在中国大陆上市srv记录SRV记录的定义qq等级表QQ级别列表聚美优品红包聚美优品红包怎么获得购买流量移动卡如何购买流量?购买流量手机买流量怎么买呀南北互通上海南北高架和中环互通吗?淘宝软文范例如何写软文
域名管理 什么是域名地址 重庆服务器托管 liquidweb bbr 视频存储服务器 12306抢票攻略 服务器日志分析 绍兴高防 91vps 东莞服务器 卡巴斯基是免费的吗 银盘服务是什么 域名dns 空间租赁 登陆空间 网通服务器 德隆中文网 工信部网站备案查询 畅行云 更多