自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C# Employee對象淺談

開發(fā) 后端
本文用代碼片斷演示了怎樣獲取C# Employee對象的所有內(nèi)容,包括ACME_DIVISION字典中的部門經(jīng)理的名字。

C#語言有很多值得學(xué)習(xí)的地方,這里我們主要介紹C# Employee對象,包括介紹所有雇員數(shù)據(jù)的命令等方面。

C# Employee對象

本文用代碼片斷演示了怎樣獲取C# Employee對象的所有內(nèi)容,包括ACME_DIVISION字典中的部門經(jīng)理的名字。如果有時間的話,請閱讀一下其中的代碼來看看它是怎么使用的。它可以被直接放到你的類中并可以運行。命令的名字是PRINTOUTEMPLOYEE。ListEmployee()函數(shù)接收一個ObjectId參數(shù),它通過一個ref類型的字符串?dāng)?shù)組返回值(包含相應(yīng)的雇員數(shù)據(jù))。調(diào)用它的PrintoutEmployee()函數(shù)只是用來在命令行中輸出這些數(shù)據(jù)。

我們需要一個遍歷并顯示所有雇員數(shù)據(jù)的命令。

  1. public static void ListEmployee(ObjectId employeeId, ref string[] saEmployeeList)  
  2. {  
  3. int nEmployeeDataCount = 0;  
  4. Database db = HostApplicationServices.WorkingDatabase;  
  5. Transaction trans = db.TransactionManager.StartTransaction(); //開始事務(wù)處理。  
  6. try  
  7. {  
  8. Entity ent = (Entity)trans.GetObject(employeeId, OpenMode.ForRead, false); 
  9. //打開當(dāng)前對象!  
  10. if (ent.GetType() == typeof(BlockReference))  
  11. {  
  12. //不是所有的塊索引都有雇員數(shù)據(jù),所以我們要處理錯誤  
  13. bool bHasOurDict = true;  
  14. Xrecord EmployeeXRec = null;  
  15. try{  
  16. BlockReference br = (BlockReference)ent;  
  17. DBDictionary extDict = (DBDictionary)trans.GetObject
    (br.ExtensionDictionary, OpenMode.ForRead, false);  
  18. EmployeeXRec = (Xrecord)trans.GetObject(extDict.GetAt("EmployeeData"), 
    OpenMode.ForRead, false);  
  19. }  
  20. catch  
  21. {  
  22. bHasOurDict = false; //出現(xiàn)了錯誤……字典或擴展記錄不能訪問  
  23. }  
  24. if (bHasOurDict) //如果獲得擴展字典,而又有擴展記錄……  
  25. {  
  26. // 為雇員列表分配內(nèi)存  
  27. saEmployeeList = new String[4];  
  28. //加入雇員的名字  
  29. TypedValue resBuf = EmployeeXRec.Data.AsArray()[0];  
  30. saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), 
    nEmployeeDataCount);  
  31. nEmployeeDataCount += 1;  
  32. //加入雇員的薪水  
  33. resBuf = EmployeeXRec.Data.AsArray()[1];  
  34. saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), 
    nEmployeeDataCount);  
  35. nEmployeeDataCount += 1;  
  36. //加入雇員所在的部門  
  37. resBuf = EmployeeXRec.Data.AsArray()[2];  
  38. string str = (string)resBuf.Value;  
  39. saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), 
    nEmployeeDataCount);  
  40. nEmployeeDataCount += 1;  
  41. //現(xiàn)在,讓我們從公司字典中獲取老板的名字  
  42. //在NOD中找到.  
  43. DBDictionary NOD = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, 
    OpenMode.ForRead, false);  
  44. DBDictionary acmeDict = (DBDictionary)trans.GetObject(NOD.GetAt("ACME_DIVISION"), 
    OpenMode.ForRead);  
  45. //注意我們直接使用擴展數(shù)據(jù)...  
  46. DBDictionary salesDict = (DBDictionary)trans.GetObject(acmeDict.GetAt
    ((string)EmployeeXRec.Data.AsArray()[2].Value),OpenMode.ForRead);  
  47. Xrecord salesXRec = (Xrecord)trans.GetObject(salesDict.GetAt("Department Manager"), 
    OpenMode.ForRead);  
  48. //***,把雇員的數(shù)據(jù)輸出到命令行  
  49. resBuf = salesXRec.Data.AsArray()[0];  
  50. saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), nEmployeeDataCount);  
  51. nEmployeeDataCount += 1;  
  52. }  
  53. }  
  54. trans.Commit();  
  55. }  
  56. finally  
  57. {  
  58. trans.Dispose();  
  59. }  
  60. }  
  61.  
  62. [CommandMethod("PRINTOUTEMPLOYEE")]  
  63. public static void PrintoutEmployee()  
  64. {  
  65. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;  
  66. //聲明我們將在下面使用的工具...  
  67. Database db = HostApplicationServices.WorkingDatabase;  
  68. Transaction trans = db.TransactionManager.StartTransaction();  
  69. try  
  70. {  
  71. //首先,獲取塊表和模型空間塊表記錄  
  72. BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.
    WorkingDatabase.BlockTableId, OpenMode.ForRead);  
  73. BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], 
    OpenMode.ForRead);  
  74. //現(xiàn)在,我們需要把內(nèi)容輸出到命令行。這里可以有一個對象幫助我們:  
  75. //下面的部分,我們將遍歷模型空間:  
  76. foreach (ObjectId id in btr)  
  77. {  
  78. Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead, false); //打開當(dāng)前對象!  
  79. if (ent is BlockReference)  
  80. {  
  81. string[] saEmployeeList = null;// 這是正確的...定義新的列表。  
  82. ListEmployee(id, ref saEmployeeList);  
  83. if ((saEmployeeList.Length == 4))  
  84. {  
  85. ed.WriteMessage("Employee Name: {0}", saEmployeeList[0]);  
  86. ed.WriteMessage("Employee Salary: {0}", saEmployeeList[1]);  
  87. ed.WriteMessage("Employee Division: {0}", saEmployeeList[2]);  
  88. ed.WriteMessage("Division Manager: {0}", saEmployeeList[3]);  
  89. }  
  90. }  
  91. }  
  92. }  
  93. finally  
  94. {  
  95. }  

【編輯推薦】

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

2009-08-31 09:44:23

C# Employee

2009-08-12 11:24:25

C# String對象

2009-08-19 17:12:18

C# Connecti

2009-09-02 15:41:21

C# HTTPWebR

2009-08-18 09:06:41

C#對象和集合

2009-09-02 16:36:37

C#調(diào)用Excel對象

2009-07-31 17:51:27

C#對象初始化

2009-05-08 09:46:37

微軟C#集合對象

2009-08-26 15:28:52

C#對象集合初始化器

2009-08-03 15:06:43

C# Stack對象C# Queue對象

2009-08-20 18:30:33

C# ReaderWr

2011-09-21 10:56:31

C#結(jié)構(gòu)

2009-08-07 11:26:53

C#數(shù)組結(jié)構(gòu)

2009-08-25 16:16:43

C# oledbcon

2009-08-26 15:46:01

C#匿名類型

2009-08-06 15:30:23

C#類型系統(tǒng)

2009-08-14 17:58:05

C#接口方法

2009-08-26 13:15:38

C#選擇控制

2009-08-20 10:24:52

C#開發(fā)WinForm

2009-08-10 10:04:25

C#抽象類C#接口
點贊
收藏

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