偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

C# CreateEmployee()函數(shù)

開發(fā) 后端
這里我們來修改C# CreateEmployee()函數(shù),以讓它可以接收名字、薪水、部門和職位并返回創(chuàng)建的雇員塊索引的ObjectId。

C#語言有很多值得學習的地方,這里我們主要介紹C# CreateEmployee()函數(shù),包括介紹 測試C# CreateEmployee()函數(shù)。加入一個Test命令來測試CreateEmployee等方面。

修改C# CreateEmployee()函數(shù)以重用

1)讓我們來修改C# CreateEmployee()函數(shù),以讓它可以接收名字、薪水、部門和職位并返回創(chuàng)建的雇員塊索引的ObjectId。函數(shù)的形式如下(你可以改變參數(shù)順序)

  1. public ObjectId CreateEmployee
    (string name, string division, double salary, Point3d pos) 

2) 移除上面函數(shù)中的CommandMethod屬性”CREATE”,這樣它就不再是用來創(chuàng)建雇員的命令。

3) 修改函數(shù)的代碼,這樣就可以正確地設置塊索引的名字、職位、部門和薪水和它的擴展字典。

  1. //替換  
  2. BlockReference br = new BlockReference
    (new Point3d(10, 10, 0), CreateEmployeeDefinition());  
  3. //為  
  4. BlockReference br = new BlockReference
    (pos, CreateEmployeeDefinition());  
  1. //替換  
  2.  
  3. xRec.Data = new ResultBuffer(  
  4. new TypedValue((int)DxfCode.Text, "Earnest Shackleton"),  
  5. new TypedValue((int)DxfCode.Real, 72000),  
  6. new TypedValue((int)DxfCode.Text, "Sales"));  
  7.  
  8. //為  
  9.  
  10. xRec.Data = new ResultBuffer(  
  11. new TypedValue((int)DxfCode.Text, name),  
  12. new TypedValue((int)DxfCode.Real, salary),  
  13. new TypedValue((int)DxfCode.Text, division));  

4) 因為我們把雇員的名字從MText替換成塊的屬性定義,因此我們要創(chuàng)建一個相應的屬性索引來顯示雇員的名字。屬性索引將使用屬性定義的屬性。

  1. //替換:  
  2.  
  3. btr.AppendEntity(br);//加入索引到模型空間  
  4. trans.AddNewlyCreatedDBObject(br,true);//讓事務處理知道  
  5.  
  6. //為  
  7.  
  8. AttributeReferenceattRef=newAttributeReference();  
  9. //遍歷雇員塊來查找屬性定義  
  10. BlockTableRecordempBtr=(BlockTableRecord)trans.
    GetObject(bt["EmployeeBlock"],OpenMode.ForRead);  
  11. foreach(ObjectIdidinempBtr)  
  12. {  
  13. Entityent=(Entity)trans.GetObject(id,OpenMode.ForRead,false);  
  14. //打開當前的對象!  
  15. if(entisAttributeDefinition)  
  16. {  
  17. //設置屬性為屬性索引中的屬性定義  
  18. AttributeDefinitionattDef=((AttributeDefinition)(ent));  
  19. attRef.SetPropertiesFrom(attDef);  
  20. attRef.Position=newPoint3d(attDef.Position.X+br.Position.X,
    attDef.Position.Y+br.Position.Y,attDef.Position.Z+br.Position.Z);  
  21. attRef.Height=attDef.Height;  
  22. attRef.Rotation=attDef.Rotation;  
  23. attRef.Tag=attDef.Tag;  
  24. attRef.TextString=name;  
  25. }  
  26. }  
  27. //把索引加入模型空間  
  28. btr.AppendEntity(br);  
  29. //把屬性索引加入到塊索引  
  30. br.AttributeCollection.AppendAttribute(attRef);  
  31. //讓事務處理知道  
  32. trans.AddNewlyCreatedDBObject(attRef,true);  
  33. trans.AddNewlyCreatedDBObject(br,true); 

5)不要忘記返回雇員塊索引的ObjectId,但要在提交事務處理之后才能返回:

  1. trans.Commit();  
  2. return br.ObjectId;  

6) 測試C# CreateEmployee()函數(shù)。加入一個Test命令來測試CreateEmployee:

  1. [CommandMethod("Test")]  
  2. public void Test()  
  3. {  
  4. CreateEmployee("Earnest Shackleton", "Sales", 10000, new Point3d(10, 10, 0));  
  5. }  

【編輯推薦】

  1. C#創(chuàng)建快捷方式簡單描述
  2. C#壓縮Access數(shù)據(jù)庫詳細介紹
  3. C#實現(xiàn)加載動態(tài)庫概述
  4. C#日期型數(shù)據(jù)簡單剖析
  5. C#裝箱和拆箱簡單描述
責任編輯:佚名 來源: 博客園
相關(guān)推薦

2009-08-31 09:59:13

C# CreateEm

2009-08-31 10:14:49

C# CreateEm

2009-07-31 14:26:38

JavaScript函C#函數(shù)

2009-07-30 15:24:13

C#析構(gòu)函數(shù)C#構(gòu)造函數(shù)

2009-08-10 14:43:03

C#函數(shù)Convert

2009-08-19 14:26:58

C# JavaScri

2009-07-31 16:00:30

C#函數(shù)重載

2009-07-31 14:08:54

C# 匿名函數(shù)

2009-07-31 14:54:48

dll函數(shù)C#導出

2009-07-31 14:15:38

C# 構(gòu)造函數(shù)

2009-08-24 18:09:13

C#構(gòu)造函數(shù)

2009-07-31 14:03:21

C# Format函數(shù)

2009-08-14 17:24:28

C#構(gòu)造函數(shù)和析構(gòu)函數(shù)

2009-07-31 15:22:56

C#判等函數(shù)

2009-07-31 16:12:10

Windows APIC#

2009-08-25 10:59:00

C#調(diào)用函數(shù)顯示值

2009-09-04 11:15:07

選擇C#構(gòu)造函數(shù)

2009-08-20 14:28:00

C#靜態(tài)構(gòu)造函數(shù)

2009-07-31 15:37:45

C#靜態(tài)構(gòu)造函數(shù)

2009-07-31 15:10:21

C#函數(shù)指針數(shù)組C#數(shù)組
點贊
收藏

51CTO技術(shù)棧公眾號