版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
./arcgis開發(fā)常用源碼1.點上生成面的代碼if<m_pFeatureLayer.FeatureClass.ShapeType==esriGeometryType.esriGeometryPolygon>{IPointCollectionm_pPointCollection=newPolygonClass<>;objectmissing=Type.Missing;inticount=newFeature.XLIST.Count;if<icount<3>return;for<inti=0;i<icount;i++>{IPointpoint=newPointClass<>;point.PutCoords<newFeature.XLIST,newFeature.YLIST>;m_pPointCollection.AddPoint<point,refmissing,refmissing>;}IPolygonm_pPolygon=m_pPointCollectionasIPolygon;if<m_pPolygon==null>{System.Windows.Forms.MessageBox.Show<"null">;return;}else{ITopologicalOperatorpTopo=m_pPolygonasITopologicalOperator;if<pTopo!=null>{pTopo.Simplify<>;}}IWorkspaceEditm_pWorkspaceEdit=m_EngineEditor.EditWorkspaceasIWorkspaceEdit;m_pWorkspaceEdit.StartEditOperation<>;IFeaturem_pFeature=m_pFeatureLayer.FeatureClass.CreateFeature<>;m_pFeature.Shape=m_pPolygonasIGeometry;m_pFeature.Store<>;m_pWorkspaceEdit.StopEditOperation<>;}2.文件的打開保存另存的代碼usingSystem;usingSystem.Windows.Forms;usingESRI.ArcGIS.esriSystem;usingESRI.ArcGIS.SystemUI;usingESRI.ArcGIS.Carto;namespaceSaveMapDocument{///<summary>///SummarydescriptionforForm1.///</summary>{publicSystem.Windows.Forms.TextBoxtxtMapDocument;publicSystem.Windows.Forms.ButtoncmdOpen;publicSystem.Windows.Forms.ButtoncmdSave;publicSystem.Windows.Forms.ButtoncmdSaveAs;privateSystem.Windows.Forms.OpenFileDialogopenFileDialog1;privateSystem.Windows.Forms.SaveFileDialogsaveFileDialog1;privateIMapDocumentm_MapDocument;privateESRI.ArcGIS.Controls.AxToolbarControlaxToolbarControl1;privateESRI.ArcGIS.Controls.AxPageLayoutControlaxPageLayoutControl1;privateESRI.ArcGIS.Controls.AxLicenseControlaxLicenseControl1;privateESRI.ArcGIS.Controls.AxTOCControlaxTOCControl1;///<summary>///Requireddesignervariable.///</summary>privateSystem.ComponentModel.Containercomponents=null;publicSaveMapDocument<>{////RequiredforWindowsFormDesignersupport//InitializeComponent<>;////TODO:AddanyconstructorcodeafterInitializeComponentcall//}///<summary>///Cleanupanyresourcesbeingused.///</summary>protectedoverridevoidDispose<booldisposing>{//ReleaseCOMobjectsESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown<>;if<disposing>{if<components!=null>{components.Dispose<>;}}base.Dispose<disposing>;}#regionWindowsFormDesignergeneratedcode///<summary>///Themainentrypointfortheapplication.///</summary>[STAThread]staticvoidMain<>{Application.Run<newSaveMapDocument<>>;}privatevoidForm1_Load<objectsender,System.EventArgse>{//AddtoolbardefinitionstotheToolbarControlaxToolbarControl1.AddToolbarDef<"esriControls.ControlsPageLayoutToolbar",-1,false,0,esriCommandStyles.esriCommandStyleIconOnly>;axToolbarControl1.AddToolbarDef<"esriControls.ControlsGraphicElementToolbar",-1,true,0,esriCommandStyles.esriCommandStyleIconOnly>;//SetbuddycontrolaxToolbarControl1.SetBuddyControl<axPageLayoutControl1>;axTOCControl1.SetBuddyControl<axPageLayoutControl1>;cmdSave.Enabled=false;cmdSaveAs.Enabled=false;}privatevoidcmdOpen_Click<objectsender,System.EventArgse>{//OpenafiledialogforopeningmapdocumentsopenFileDialog1.Title="OpenMapDocument";openFileDialog1.Filter="MapDocuments<*.mxd>|*.mxd";openFileDialog1.ShowDialog<>;//ExitifnomapdocumentisselectedstringsFilePath=openFileDialog1.FileName;if<sFilePath=="">{return;}//OpendocumentOpenDocument<<sFilePath>>;if<cmdSave.Enabled==false>{cmdSave.Enabled=true;}if<cmdSaveAs.Enabled==false>{cmdSaveAs.Enabled=true;}}privatevoidcmdSave_Click<objectsender,System.EventArgse>{//SavechangestothecurrentdocumentSaveDocument<>;}privatevoidcmdSaveAs_Click<objectsender,System.EventArgse>另存為{//OpenafiledialogforsavingmapdocumentssaveFileDialog1.Title="SaveMapDocumentAs";saveFileDialog1.Filter="MapDocuments<*.mxd>|*.mxd";saveFileDialog1.ShowDialog<>;//ExitifnomapdocumentisselectedstringsFilePath=saveFileDialog1.FileName;if<sFilePath=="">{return;}if<sFilePath==m_MapDocument.DocumentFilename>{//SavechangestothecurrentdocumentSaveDocument<>;}else{//SaveAsanewdocumentwithrelativepathsm_MapDocument.SaveAs<sFilePath,true,true>;//OpendocumentOpenDocument<<sFilePath>>;MessageBox.Show<"Documentsavedsuccessfully!">;}}privatevoidOpenDocument<stringsFilePath>{if<m_MapDocument!=null>m_MapDocument.Close<>;//Createanewmapdocumentm_MapDocument=newMapDocumentClass<>;//Openthemapdocumentselectedm_MapDocument.Open<sFilePath,"">;//SetthePageLayoutControlpagelayouttothemapdocumentpagelayoutaxPageLayoutControl1.PageLayout=m_MapDocument.PageLayout;txtMapDocument.Text=m_MapDocument.DocumentFilename;}privatevoidSaveDocument<>{//Checkthatthedocumentisnotreadonlyif<m_MapDocument.get_IsReadOnly<m_MapDocument.DocumentFilename>==true>{MessageBox.Show<"Thismapdocumentisreadonly!">;return;}//Savewiththecurrentrelativepathsettingm_MapDocument.Save<m_MapDocument.UsesRelativePaths,true>;MessageBox.Show<"Changessavedsuccessfully!">;}}}3.訪問一個地圖staticvoidOpenMXDViaMapDocument<stringpath>{IMapDocumentpMapDocument=newMapDocumentClass<>;if<pMapDocument.get_IsMapDocument<path>>{pMapDocument.Open<path,null>;IMappMap;for<inti=0;i<=pMapDocument.MapCount-1;i++>{pMap=pMapDocument.get_Map<i>;Console.WriteLine<pMap.Name>;IEnumLayerpEnumLayer=pMap.get_Layers<null,true>;pEnumLayer.Reset<>;ILayerpLayer=pEnumLayer.Next<>;while<pLayer!=null>{Console.WriteLine<pLayer.Name>;pLayer=pEnumLayer.Next<>;}}}}4、地圖坐標privatevoidaxMapControl1_OnMouseMove<objectsender,IMapControlEvents2_OnMouseMoveEvente>{stringoutx=null;stringouty=null;IActiveViewpActiveView=axMapControl1.ActiveView;BJAEINFunction.bj54tojingweiduAo<pActiveView,e.mapX,e.mapY,refoutx,refouty>;labelItem1.Text="地理坐標:經(jīng)度:"+outx+"緯度:"+outy;//IFeatureLayerpFeatLyr;//pFeatLyr=axMapControl1.Map.get_Layer<2>asIFeatureLayer;//pFeatLyr.DisplayField="面積";//pFeatLyr.ShowTips=true;//stringpTips;//pTips=pFeatLyr.get_TipText<e.mapX,e.mapY,pActiveView.FullExtent.Width/100>;//toolTip1.SetToolTip<axMapControl1,pTips>;}5、大地轉(zhuǎn)北京54publicstaticvoidbj54tojingweiduAo<IActiveViewpActiveView,doubleinx,doubleiny,refstringoutx,refstringouty>{try{IMappMap=pActiveView.FocusMap;SpatialReferenceEnvironmentpSpRE=newSpatialReferenceEnvironment<>;IGeographicCoordinateSystempGeoCS=pSpRE.CreateGeographicCoordinateSystem<<int>esriSRGeoCSType.esriSRGeoCS_Beijing1954>;ISpatialReferencepSpr=pGeoCS;IPointpPoint=newESRI.ArcGIS.Geometry.Point<>;pPoint.X=inx;pPoint.Y=iny;IGeometrypGeo=pPoint;pGeo.SpatialReference=pMap.SpatialReference;pGeo.Project<pSpr>;//坐標轉(zhuǎn)換,由當前地圖坐標轉(zhuǎn)為北京54經(jīng)緯度坐標doublejwd_jd=pPoint.X;doublejwd_wd=pPoint.Y;//轉(zhuǎn)化成度、分、秒//經(jīng)度intJd,Wd,Jf,Wf;doubletemp;SingleJm,Wm;Jd=<int>jwd_jd;//度temp=<jwd_jd-Jd>*60;Jf=<int>temp;//分temp=<temp-Jf>*60;Jm=Convert.ToInt32<temp>;//秒//緯度Wd=<int>jwd_wd;//度temp=<jwd_wd-Wd>*60;Wf=<int>temp;//分temp=<temp-Wf>*60;Wm=Convert.ToInt32<temp>;//秒outx=Jd+"度"+Jf+"分"+Jm+"秒";outy=Wd+"度"+Wf+"分"+Wm+"秒";}catch<Exceptionex>{MessageBox.Show<ex.Message>;}6.拖動代碼privatevoidbtnClearSelction_Click<objectsender,EventArgse>{ICommandpCommand=newControlsMapIdentifyToolClass<>;IToolpTool=pCommandasITool;switch<this.tabControl.SelectedTabIndex>{case0:pCommand.OnCreate<this.mainMapControl.Object>;this.mainMapControl.CurrentTool=pTool;break;case1:pCommand.OnCreate<this.axPageLayoutControl.Object>;this.axPageLayoutControl.CurrentTool=pTool;break;}}7.axMapControl和axPagelayoutControl數(shù)據(jù)同步顯示的程序privatevoidaxMapControl1_OnMouseDown<objectsender,IMapControlEvents2_OnMouseDownEvente>{axMapControl1.MousePointer=esriControlsMousePointer.esriPointerCrosshair;IGeometrypGeom=axMapControl1.TrackRectangle<>;DrawMapShape<pGeom>;axMapControl1.CtlRefresh<esriViewDrawPhase.esriViewGeography,null,null>;}privatevoidDrawMapShape<IGeometrypGeom>{IRgbColorpColor;pColor=newRgbColorClass<>;pColor.Red=100;pColor.Green=100;pColor.Blue=100;ISimpleFillSymbolpFillsyl;pFillsyl=newSimpleFillSymbolClass<>;pFillsyl.Color=pColor;objectoFillsyl=pFillsyl;axMapControl1.DrawShape<pGeom,refoFillsyl>;}privatevoidCopyAndOverwriteMap<>{IObjectCopyobjectCopy=newObjectCopyClass<>;objecttoCopyMap=axMapControl1.Map;objectcopiedMap=objectCopy.Copy<toCopyMap>;objecttoOverwriteMap=axPageLayoutControl1.ActiveView.FocusMap;objectCopy.Overwrite<copiedMap,reftoOverwriteMap>;}privatevoidaxMapControl1_OnAfterScreenDraw<objectsender,IMapControlEvents2_OnAfterScreenDrawEvente>{IActiveViewactiveView=<IActiveView>axPageLayoutControl1.ActiveView.FocusMap;IDisplayTransformationdisplayTransformation=activeView.ScreenDisplay.DisplayTransformation;displayTransformation.VisibleBounds=axMapControl1.Extent;axPageLayoutControl1.ActiveView.Refresh<>;CopyAndOverwriteMap<>;}privatevoidaxPageLayoutControl1_OnViewRefreshed<objectsender,IPageLayoutControlEvents_OnViewRefreshedEvente>{axTOCControl1.CtlUpdate<>;CopyAndOverwriteMap<>;}8.放大縮小放大ICommandpCommand=newControlsMapZoomInToolClass<>;IToolpTool=pCommandasITool;pCommand.OnCreate<this.axMapControl1.Object>;this.axMapControl1.CurrentTool=pTool;縮小ICommandpCommand=newControlsMapZoomOutToolClass<>;IToolpTool=pCommandasITool;pCommand.OnCreate<this.axMapControl1.Object>;this.axMapControl1.CurrentTool=pTool;9.在arcsence中的各個控件的應用類似的arcmap也一樣。case"ZoomIn":{ICommandcommand=newControlsSceneZoomInTool<>;//ControlsSceneZoomInToolClass<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;}break;case"toolFly":{ICommandcommand=newControlsSceneFlyToolClass<>;//ControlsSceneZoomInToolClass<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;}break;case"toolSelectFeatures":{ICommandcommand=newControlsSceneSelectFeaturesToolClass<>;//ControlsSceneZoomInToolClass<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;}break;case"toolTargetZoom":{ICommandcommand=newControlsSceneTargetZoomToolClass<>;//ControlsSceneZoomInToolClass<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;}break;case"toolFullExtent":{ICommandcommand=newControlsSceneFullExtentCommandClass<>;//ControlsSceneZoomInToolClass<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;}break;case"ZoomOut":{ICommandcommand=newControlsSceneZoomOutTool<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;}break;case"Pan":{ICommandcommand=newControlsScenePanTool<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;}break;case"Navigate":{ICommandcommand=newControlsSceneNavigateTool<>;command.OnCreate<this.axSceneControl1.Object>;this.axSceneControl1.CurrentTool=commandasESRI.ArcGIS.SystemUI.ITool;10.在C#中如何連接ACCESS數(shù)據(jù)庫publicstringmyConnstring="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+HttpContext.Current.Server.MapPath<"data.mdb">;//data.mdb是你的數(shù)據(jù)庫名稱OleDbConnectionMyConnection;MyConnection=newOleDbConnection<myConnstring>;strInsert="";//strinsert是你的sql語句OleDbCommandMyCommand=newOleDbCommand<strInsert,MyConnection>;MyConnection.Open<>;MyCommand.ExecuteNonQuery<>;MyConnection.Close<>;11.創(chuàng)建文件〔word//創(chuàng)建文件夾System.ObjectNothing=System.Reflection.Missing.Value;Directory.CreateDirectory<"c:/CNSI">;//創(chuàng)建文件所在目錄stringname="CNSI_"+DateTime.Now.ToLongDateString<>+".doc";objectfilename="c://CNSI//"+name;//文件保存路徑//創(chuàng)建Word文檔Microsoft.Office.Interop.Word.ApplicationWordApp=newMicrosoft.Office.Interop.Word.ApplicationClass<>;Microsoft.Office.Interop.Word.DocumentWordDoc=WordApp.Documents.Add<refNothing,refNothing,refNothing,refNothing>;IQueryFilterpQueryFilter;pQueryFilter=pFeatureWorkspace;.Word.ApplicationWordApp=newMicrosoft.Office.Interop.Word.ApplicationClass<>;Microsoft.Office.Interop.Word.DocumentWordDocs=WordApp.Documents.Add<refNothing,refNothing,refNothing,refNothing>;WordDocs.Close<refNothing,refNothing,refNothing>;WordApp.Quit<refNothing,refNothing,refNothing>;WordDocs.SaveAs<reffilename,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing>;//WordApp.Quit<refNothing,refNothing,refNothing>;message=name+"文檔生成成功,以保存到C:CNSI下";hycatch{message="文件導出異常!";}stringpath="E:\\yxl\\tianjia\\database2.mdb";IWorkspaceiW=AccessWorkspaceFromPropertySet<path>;IFeatureWorkspacepFeatureWorkspace=<IFeatureWorkspace>iW;ITablepTable=pFeatureWorkspace.OpenTable<"database2">;12.C#操作Access數(shù)據(jù)庫的方法//取得連接publicOleDbConnectiongetConn<>{ConnectDatabaseconnstr=newConnectDatabase<>;stringconnStr=connstr.GetConnectionString<>;OleDbConnectionoledb=newOleDbConnection<connStr>;returnoledb;}〔1采用OleDbCommand,OleDbDataReader訪問數(shù)據(jù)庫1.查詢publicUsergetUserFromName<stringSearchname>{UsertempUser=newUser<>;try{OleDbConnectionoleconn=getConn<>;//數(shù)據(jù)庫連接stringstrSel="select*fromMyUserwhereUserName='"+Searchname+"'";//查詢語句OleDbCommandmyCommand=newOleDbCommand<strSel,oleconn>;//查詢命令oleconn.Open<>;//打開數(shù)據(jù)庫連接OleDbDataReaderreader;reader=myCommand.ExecuteReader<>;//執(zhí)行查詢命令,返回記錄集if<reader.Read<>>{tempUser.ID=<int>reader["UserID"];tempUser.Name=reader["UserName"].ToString<>;tempUser.Salary=<float>reader["UserSalary"];tempUser.Password=reader["UserPassword"].ToString<>;tempUser.Memo=reader["UserMemo"].ToString<>;tempUser.Birthday=<DateTime>reader["UserBirthday"];tempUser.Address=reader["UserAddress"].ToString<>;}else{thrownewException<"沒有記錄">;}reader.Close<>;//關閉記錄集oleconn.Close<>;//關閉連接}catch<Exceptione>{thrownewException<"打開數(shù)據(jù)庫出錯"+e.Message>;}returntempUser;}2.插入記錄publicvoidInsertUser<Userinsertuser>{try{OleDbConnectionoleconn=getConn<>;//數(shù)據(jù)庫連接oleconn.Open<>;//打開數(shù)據(jù)庫連接stringstrSel="insertinto[MyUser]<[UserName],[UserPassword],[UserSalary],[UserAddress],[UserBirthday],[UserMemo]>";//插入語句strSel+="valuesring<>;strSel+=",'"+insertuser.Address+"',#"+insertuser.Birthday.ToString<>+"#,'"+insertuser.Memo+"'>";OleDbCommandmyCommand=newOleDbCommand<strSel,oleconn>;//查詢命令myCommand.ExecuteNonQuery<>;oleconn.Close<>;//關閉連接}catch<Exceptione>{thrownewException<"打開數(shù)據(jù)庫出錯"+e.Message>;}}3.刪除記錄publicvoidDeleteUser<intm_id>{try{OleDbConnectionoleconn=getConn<>;oleconn.Open<>;stringstrSel="DeleteFrom[Myuser]whereUserID="+m_id.ToString<>;OleDbCommandmyCommand=newOleDbCommand<strSel,oleconn>;myCommand.ExecuteNonQuery<>;oleconn.Close<>;}catch<Exceptione>{thrownewException<"刪除記錄出錯"+e.Message>;}}〔2采用OleDbDataAdapter,OleDbCommandBuilder,DataSet,DataTable,DataRow訪問數(shù)據(jù)庫添加記錄如下publicvoidInsertUserA<UserinsertUser>{using<OleDbConnectionconn=getConn<>>{OleDbDataAdapteradapter=newOleDbDataAdapter<>;stringqueryString="Select*fromMyUserorderbyUserID";adapter.SelectCommand=newOleDbCommand<queryString,conn>;OleDbCommandBuilderbuilder=newOleDbCommandBuilder<adapter>;//builder.QuotePrefix="[";//builder.QuoteSuffix="]";conn.Open<>;DataSetusers=newDataSet<>;adapter.Fill<users,"MyUser">;DataTabledt=newDataTable<>;dt=users.Tables["MyUser"];DataRowr=dt.NewRow<>;r["UserName"]=insertUser.Name;r["UserPassword"]=insertUser.Password;r["UserAddress"]=insertUser.Address;r["UserSalary"]=insertUser.Salary;r["UserBirthday"]=insertUser.Birthday;r["UserMemo"]=insertUser.Memo;dt.Rows.Add<r>;adapter.Update<users,"MyUser">;}}需要注意字段不能和關鍵字相同,否則會出現(xiàn)Insertinto出錯的提示。解決辦法在前一篇<3>采用參數(shù)化查詢的方式publicclassAccessUtil{publicAccessUtil<>{}privatestringconnString;publicstringConnString{get{returnconnString;}set{connString=value;}}publicAccessUtil<stringconnstr>{this.connString=connstr;}//帶參數(shù)的插入語句,返回值為id關鍵字的值,單條插入語句publicintExecuteInsert<stringSQL,OleDbParameter[]parameters>{using<OleDbConnectionconn=newOleDbConnection<connString>>{OleDbCommandcmd=newOleDbCommand<SQL,conn>;try{conn.Open<>;if<parameters!=null>{cmd.Parameters.AddRange<parameters>;}cmd.ExecuteNonQuery<>;cmd.CommandText=@"Select@@identity";intvalue=Int32.Parse<cmd.ExecuteScalar<>.ToString<>>;returnvalue;}catch<System.Exceptione>{throwe;}}}//不帶參數(shù)的插入語句,返回值為關鍵字的值publicintExecuteInsert<stringSQL>{returnExecuteInsert<SQL,null>;}//帶參數(shù)的插入、刪除、更新語句,返回受影響的記錄的個數(shù)publicintExecuteNoQuery<stringSQL,OleDbParameter[]parameters>{using<OleDbConnectionconn=newOleDbConnection<connString>>{conn.Open<>;OleDbCommandcmd=newOleDbCommand<SQL,conn>;try{if<parameters!=null>{cmd.Parameters.AddRange<parameters>;}introws=cmd.ExecuteNonQuery<>;returnrows;}catch<System.Exceptione>{throwe;}}}//不帶參數(shù)的插入、刪除、更新語句,返回受影響的記錄的個數(shù)publicintExecuteNoQuery<stringSQL>{returnExecuteNoQuery<SQL,null>;}//帶參數(shù)的查詢語句,返回所查詢到的記錄集publicDataSetExecuteQuery<stringSQL,OleDbParameter[]parameters>{using<OleDbConnectionconn=newOleDbConnection<connString>>{DataSetds=newDataSet<>;try{conn.Open<>;OleDbDataAdapterda=newOleDbDataAdapter<SQL,conn>;if<parameters!=null>{da.SelectCommand.Parameters.AddRange<parameters>;}da.Fill<ds,"ds">;}catch<System.Exceptione>{throwe;}returnds;}}//不帶參數(shù)的查詢,返回所查詢到的記錄集publicDataSetExecuteQuery<stringSQL>{returnExecuteQuery<SQL,null>;}}classManageUser{//Access數(shù)據(jù)庫工具對象AccessUtilaccessutil=newAccessUtil<ConnectDatabase.GetConnectionString<>>;publicArrayListGetAllUserArr<>//獲得User表中的所有記錄,存儲進ArrayList。{stringSQL="select*fromMyUserorderbyID";DataSetds=accessutil.ExecuteQuery<SQL>;//返回的臨時表的名稱為"ds"/*ArrayListarr=newArrayList<>;for<inti=0;i<ds.Tables["ds"].Rows.Count;i++>{arr.Add<DataRow2User<ds.Tables["ds"].Rows>>;}*/ArrayListarr=DataTable2ArrayList<ds.Tables["ds"]>;returnarr;}publicDataSetGetAllUserDataSet<>//存儲成DataSet{stringSQL="select*fromMyUserorderbyID";DataSetds=accessutil.ExecuteQuery<SQL>;returnds;}privateUserDataRow2User<DataRowdr>//將數(shù)據(jù)表中的一條記錄轉(zhuǎn)換為一個User類的實例{Useruser=newUser<>;user.ID=Int32.Parse<dr["ID"].ToString<>>;user.Name=dr["Name"].ToString<>;user.Address=dr["Address"].ToString<>;user.Birthday=Convert.ToDateTime<dr["Birthday"].ToString<>>;user.Memo=dr["Memo"].ToString<>;user.Salary=<float>Convert.ToDouble<dr["Salary"].ToString<>>;user.Password=dr["Password"].ToString<>;returnuser;}privateArrayListDataTable2ArrayList<DataTabledt>//將一個表中的記錄轉(zhuǎn)化為ArrayList對象{ArrayListtempArr=newArrayList<>;DataTableReaderdr=newDataTableReader<dt>;while<dr.Read<>>{Useruser=newUser<>;user.ID=Int32.Parse<dr["ID"].ToString<>>;user.Name=dr["Name"].ToString<>;user.Address=dr["Address"].ToString<>;user.Birthday=Convert.ToDateTime<dr["Birthday"].ToString<>>;user.Memo=dr["Memo"].ToString<>;user.Salary=<float>Convert.ToDouble<dr["Salary"].ToString<>>;user.Password=dr["Password"].ToString<>;tempArr.Add<user>;}returntempArr;}publicDataSetGetUserByName<stringname>{StringSQL="Select*fromMyUserwhereName=?";OleDbParameter[]parameter=newOleDbParameter[1];parameter[0]=newOleDbParameter<"@Name",OleDbType.VarChar>;parameter[0].Value=name;DataSetdt=accessutil.ExecuteQuery<SQL,parameter>;returndt;}publicintInsertUser<UserinUser>{StringSQL="insertinto[MyUser]<[Name],[Password],[Salary],[Address],[Birthday],[Memo]>values<?,?,?,?,?,?>";OleDbParameter[]parameters=newOleDbParameter[6];parameters[0]=newOleDbParameter<"@Name",OleDbType.VarChar>;parameters[0].Value=inUser.Name;parameters[1]=newOleDbParameter<"@Password",OleDbType.VarChar>;parameters[1].Value=inUser.Password;parameters[2]=newOleDbParameter<"@Salary",OleDbType.Single>;parameters[2].Value=inUser.Salary;parameters[3]=newOleDbParameter<"@Address",OleDbType.VarChar>;parameters[3].Value=inUser.Address;parameters[4]=newOleDbParameter<"@Birthday",OleDbType.Date>;parameters[4].Value=inUser.Birthday;parameters[5]=newOleDbParameter<"@Memo",OleDbType.VarChar>;parameters[5].Value=inUser.Memo;returnaccessutil.ExecuteInsert<SQL,parameters>;}publicvoidDelUserById<intid>{StringSQL="DELETEFROM[MyUser]whereID=?";OleDbParameter[]parameters=newOleDbParameter[1];parameters[0]=newOleDbParameter<"@ID",OleDbType.Integer>;parameters[0].Value=id;accessutil.ExecuteNoQuery<SQL,parameters>;}publicvoidUpdateUser<Useruserupdate>{StringSQL="update[MyUser]Set[Name]=?,[Password]=?,[Salary]=?,[Address]=?,[Birthday]=?,[Memo]=?where[ID]=?";OleDbParameter[]parameters=newOleDbParameter[7];parameters[0]=newOleDbParameter<"@Name",OleDbType.VarChar>;parameters[0].Value=userupdate.Name;parameters[1]=newOleDbParameter<"@Password",OleDbType.VarChar>;parameters[1].Value=userupdate.Password;parameters[2]=newOleDbParameter<"@Salary",OleDbType.Single>;parameters[2].Value=userupdate.Salary;parameters[3]=newOleDbParameter<"@Address",OleDbType.VarChar>;parameters[3].Value=userupdate.Address;parameters[4]=newOleDbParameter<"@Birthday",OleDbType.Date>;parameters[4].Value=userupdate.Birthday;parameters[5]=newOleDbParameter<"@Memo",OleDbType.VarChar>;parameters[5].Value=userupdate.Memo;parameters[6]=newOleDbParameter<"@ID",OleDbType.Integer>;parameters[6].Value=userupdate.ID;accessutil.ExecuteNoQuery<SQL,parameters>;}}13.加載cad代碼privatevoidAddCADRasterLayer<stringsPath,stringsName>{IWorkspaceFactorypCadWorkspaceFactory=newCadWorkspaceFactoryClass<>;IWorkspacepWorkspace=pCadWorkspaceFactory.OpenFromFile<sPath,0>;ICadDrawingWorkspacepCadDrawingWorkspace=pWorkspaceasICadDrawingWorkspace;ICadDrawingDatasetpCadDataset;//'定義并獲得CAD文件的數(shù)據(jù)集pCadDataset=pCadDrawingWorkspace.OpenCadDrawingDataset<sName>;ICadLayerpCadLayer;//'加入圖層到Map對象中去pCadLayer=newCadLayerClass<>;pCadLayer.CadDrawingDataset=pCadDataset;axMapControl1.AddLayer<pCadLayer,0>;axMapControl1.Refresh<>;}privatevoidbutton1_Click<objectsender,EventArgse>{OpenFileDialogopenFileDialog1=newOpenFileDialog<>;openFileDialog1.Filter="所有文件|*.*";if<openFileDialog1.ShowDialog<>==DialogResult.OK>{AddCADRasterLayer<openFileDialog1.FileName,"11.dwg">;//}}<七>給PageLayoutControl添加彈出式菜單
與給跟綁定控件協(xié)作的ToolbarControl增加ArcGISEngine命令一樣,按照前面的步驟,你也可以從ArcGISEngine命令創(chuàng)建彈出式菜單。下面將向你的應用程序中增加與PageLayoutControl協(xié)作的彈出式菜單。當在PageLayoutControl可視區(qū)域點擊鼠標右鍵的時候,彈出式菜單將顯示。1.
向類中添加如下的成員變量〔紅色部分:
{
privateESRI.ArcGIS.MapControl.AxMapControlaxMapControl1;
privateESRI.ArcGIS.PageLayoutControl.AxPageLayoutControlaxPageLayoutControl1;
privateESRI.ArcGIS.TOCControl.AxTOCControlaxTOCControl1;
privateESRI.ArcGIS.ToolbarControl.AxToolbarControlaxToolbarControl1;
privateIToolbarMenum_ToolbarMenu=newToolbarMenuClass<>;//彈出式菜單//……2.
在Form_Load事件中向ToolbarControl增加命令代碼的后面加載文檔代碼的前面增加如下代碼。
privatevoidForm1_Load<objectsender,System.EventArgse>
{
//前面是增加地圖導航的代碼……//共享ToolbarControl的命令池
m_ToolbarMenu.CommandPool=axToolbarControl1.CommandPool;
//向ToolbarMenu增加命令
progID="esriControlToolsPageLayout.ControlsPageZoomInFixedCommand";
m_ToolbarMenu.AddItem<progID,-1,-1,false,
esriCommandStyles.esriCommandStyleIconAndText>;
progID="esriControlToolsPageLayout.ControlsPageZoomOutFixedCommand";
m_ToolbarMenu.AddItem<progID,-1,-1,false,
esriCommandStyles.esriCommandStyleIconAndText>;
progID="esriControlToolsPageLayout.ControlsPageZoomWholePageCommand";
m_ToolbarMenu.AddItem<progID,-1,-1,false,
esriCommandStyles.esriCommandStyleIconAndText>;
progID="esriControlToolsPageLayout.ControlsPageZoomPageToLastExtentBackCommand";
m_ToolbarMenu.AddItem<progID,-1,-1,true,
esriCommandStyles.esriCommandStyleIconAndText>;
progID="esriControlToolsPageLayout.ControlsPageZoomPageToLastExtentForwardCommand";
m_ToolbarMenu.AddItem<progID,-1,-1,false,
esriCommandStyles.esriCommandStyleIconAndText>;
//設置與PageLayoutControl掛接
m_ToolbarMenu.SetHook<axPageLayoutControl1>;
//后面是加載圖形文檔的代碼……
//……3.
在設計模式顯示窗體并從屬性窗口中選擇axPageLayoutControl1,顯示axPageLayoutControl事件。雙擊OnMouseDown事件,向代碼窗口中增加事件處理代碼。4.
在axPageLayoutControl1_OnMouseDown事件中增加如下代碼:
privatevoidaxPageLayoutControl1_OnMouseDown<objectsender,ESRI.ArcGIS.PageLayoutControl.IPageLayoutControlEvents_OnMouseDownEvente>
{
//彈出ToolbarMenu
if<e.button==2>
{
m_ToolbarMenu.PopupMenu<e.x,e.y,axPageLayoutControl1.hWnd>;
}}5.
生成并運行應用程序。在PageLayoutControl的顯示區(qū)域單擊右鍵以顯示彈出菜單,并為頁面布局導航。<八>在TOCControl中控制標簽編輯
TOCControl默認允許用戶自動地切換圖層的可見性并改變顯示在目錄表中的名稱。你可以增加代碼防止用戶在編輯名稱時輸入空的字符串。1.
在Form_Load事件的開始增加下列代碼。
privatevoidForm1_Load<objectsender,System.EventArgse>
{
//當縮放時禁止重繪
this.SetStyle<ControlStyles.EnableNotifyMessage,true>;
//設置標簽編輯為手動方式
axTOCControl1.LabelEdit=esriTOCControlEdit.esriTOCControlManual;
//后面是加載文檔代碼
//……2.
在設計模式顯示窗體并從屬性窗口選擇AxTOCControl1控件,顯示AxTOCControl事件。雙擊OnEndLabelEdit向代碼窗口添加事件處理函數(shù)。3.
在axTOCControl1_OnEndLabelEdit事件中添加以下代碼:
privatevoidaxTOCControl1_OnEndLabelEdit<objectsender,ESRI.ArcGIS.TOCControl.ITOCControlEvents_OnEndLabelEditEvente>
{
//禁止在編輯標簽時鍵入空字串
stringnewLabel=e.newLabel;
if<newLabel.Trim<>=="">
{
e.canEdit=false;
}
}4.
生成并生成應用程序。編輯TOCControl控件的地圖、圖層、標題或圖例類的標簽,在其上點擊一次,然后再點一次調(diào)用標簽編輯。試著用空字串替代標簽。在編輯期間,你可以隨時使用鍵盤上的ESC鍵取消編輯。<九>在MapControl上繪制圖形
你可以將MapControl作為縮略圖窗體使用,并在其上繪制顯示PageLayoutControl內(nèi)的焦點地圖的當前范圍。當你瀏覽PageLayoutControl數(shù)據(jù)框架內(nèi)的數(shù)據(jù)時,你將看到縮略圖窗口也進行了更新。注:使用地圖導航工具導航焦點圖〔活動圖將改變PageLayoutControl中焦點地圖的范圍并引起MapControl更新。使用頁面布局工具導航頁面布局將改變頁面布局的范圍〔不是PageLayoutControl中的焦點圖的范圍,而MapControl將不更新。1.
向類中增加下列成員變量:{
privateESRI.ArcGIS.MapControl.AxMapControlaxMapControl1;
privateESRI.ArcGIS.PageLayoutControl.AxPageLayoutControlaxPageLayoutControl1;
privateESRI.ArcGIS.TOCControl.AxTOCControlaxTOCControl1;
privateESRI.ArcGIS.ToolbarControl.AxToolbarControlaxToolbarControl1;
privateIToolbarMenum_ToolbarMenu=newToolbarMenuClass<>;//彈出式菜單
privateIEnvelopem_Envelope;
//MapControl繪制的范圍
privateObjectm_FillSymbol;
//在MapControl
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 網(wǎng)絡倫理與道德-第1篇-洞察分析
- 虛擬現(xiàn)實訓練成本效益分析-洞察分析
- 無人零售技術發(fā)展研究-洞察分析
- 線纜絕緣老化檢測方法-洞察分析
- 虛假新聞識別與治理-洞察分析
- 《大數(shù)據(jù)存儲技術與應用》 課件 項目一-任務二 走進大數(shù)據(jù)存儲技術
- 文化產(chǎn)品自動化生產(chǎn)線構建-洞察分析
- 醫(yī)療器械合作的意向書(5篇)
- 《建筑節(jié)能的措施》課件
- 創(chuàng)意美術教育課程設計的多維探索
- 村集體“三資”管理存在的問題分析
- 2024年江蘇蘇州幼兒師范高等??茖W校招考聘用教師及專職輔導員7人高頻考題難、易錯點模擬試題(共500題)附帶答案詳解
- 2024年7月國家開放大學本科《中國法律史》期末紙質(zhì)考試試題及答案
- 八年級生物上冊知識點總結(填空版+答案)
- 分布式光伏建設投資人投標方案(技術方案)
- 果樹嫁接合同協(xié)議書
- 2024年四川省自然資源置業(yè)集團招聘筆試沖刺題(帶答案解析)
- 幼兒園小班語言課件:《冬天到了》
- 醫(yī)院內(nèi)急診重癥快速反應小組建設專家共識1
- 2023-2024學年度九上圓與無刻度直尺作圖專題研究(劉培松)
- 2023年度四川公需科目:數(shù)字經(jīng)濟與驅(qū)動發(fā)展
評論
0/150
提交評論