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/)

hostodo:2021美国独立日7折优惠促销NVMe硬盘的VPS,低至$13/年,还送DirectAdmin授权

7月4日是美国独立日,大致就是国庆节的意思吧。hostodo今年提前搞了个VPS大促销活动,4款便宜VPS,相当于7折,续费不涨价,本次促销不定时,不知道有多少货,卖完为止。VPS基于KVM虚拟,NVMe阵列,1Gbps带宽,自带一个IPv4+/64 IPv6,solusvm管理,送收费版DirectAdmin授权,VPS在用就有效! 官方网站:https://www.hostodo.com ...

炭云188元/年,上海CN2 VPS/2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP

炭云怎么样?炭云(之前的碳云),国人商家,正规公司(哈尔滨桓林信息技术有限公司),主机之家测评介绍过多次。现在上海CN2共享IP的VPS有一款特价,上海cn2 vps,2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP/Hyper-v,188元/年,特别适合电信网络。有需要的可以关注一下。点击进入:炭云官方网站地址炭云vps套餐:套餐cpu内存硬盘流量/带宽ip价格购买上...

Advinservers:美国达拉斯便宜VPS/1核/4GB/80GB SSD/1Gbps不限流量/月付$2.5/美国10Gbps高防服务器/高达3.5TBDDos保护$149.99元/月

Advinservers,国外商家,公司位于新泽西州,似乎刚刚新成立不久,主要提供美国和欧洲地区VPS和独立服务器业务等。现在有几款产品优惠,高达7.5TB的存储VPS和高达3.5TBDDoS保护的美国纽约高防服务器,性价比非常不错,有兴趣的可以关注一下,并且支持Paypal付款。官方网站点击直达官方网站促销产品第一款VPS为预购,预计8月1日交付。CPU为英特尔至强 CPU(X 或 E5)。官方...

selectedindexchanged为你推荐
安装程序配置服务器失败sql server 2000 安装程序配置服务器失败安装程序配置服务器失败sql安装程序配置服务器失败二叉树遍历写出二叉树的先序遍历、中序遍历、后序遍历。硬盘人硬盘是指什么人小米3大概多少钱小米3现在多少钱网管工具网吧工具有什么?网站推广外链我是新手SEO,请问网站怎样做外链推广王炳坤nike男子跑步鞋42码的对应同款女子跑步鞋是多少码?手工杀毒求个强大的手动杀毒软件淘宝软文范例今天算自己能弄出来一段2500字的软文了,好不容易啊!各位大神如何写软文呢?
河南虚拟主机 西安虚拟主机 重庆服务器租用 国外免费域名网站 网易域名邮箱 拜登买域名批特朗普 dreamhost Vultr omnis 域名优惠码 web服务器架设软件 域名评估 isp服务商 shopex主机 下载速度测试 小夜博客 hdroad winserver2008 海外加速 windowsserver2012 更多