Dictionary.tt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <#@ template debug="false" hostspecific="false" language="C#" #>
  2. <#@ output extension=".cs" #>
  3. <#@ assembly name="System.Xml" #>
  4. <#@ assembly name="System.Data" #>
  5. <#
  6. System.Data.SqlClient.SqlConnection db = new System.Data.SqlClient.SqlConnection("Data Source=192.168.0.66\\LIOT; User Id=sa; Password=1; Initial Catalog=LIOT.Exam");
  7. System.Data.DataTable dtDictionaryItem = new System.Data.DataTable();
  8. System.Data.SqlClient.SqlDataAdapter daDictionaryItem = new System.Data.SqlClient.SqlDataAdapter("select * from Sys_Dictionary", db);
  9. db.Open();
  10. daDictionaryItem.Fill(dtDictionaryItem);
  11. #>
  12. using System;
  13. namespace EMIS.ViewModel
  14. {
  15. [Serializable]
  16. public enum DictionaryItem
  17. {
  18. <#
  19. for (int j = 0; j < dtDictionaryItem.Rows.Count; j ++)
  20. {
  21. System.Data.DataRow dr = dtDictionaryItem.Rows[j];
  22. string enumItem = "";
  23. enumItem += @"///<summary>
  24. ///" + dr["Name"] + @"
  25. ///</summary>
  26. ";
  27. enumItem += dr["DictionaryCode"];
  28. if (j != dtDictionaryItem.Rows.Count - 1)
  29. {
  30. enumItem += ",";
  31. }
  32. #>
  33. <#= enumItem#>
  34. <#}
  35. #>}
  36. <#
  37. for (int i = 0; i < dtDictionaryItem.Rows.Count; i ++)
  38. {
  39. System.Data.DataRow dr = dtDictionaryItem.Rows[i];
  40. string enumItem = "";
  41. enumItem += @" ///<summary>
  42. ///" + dr["Name"] + @"
  43. ///</summary>
  44. [Serializable]
  45. ";
  46. enumItem += "public enum " + dr["DictionaryCode"];
  47. #>
  48. <#= enumItem#>
  49. {
  50. <#
  51. System.Data.SqlClient.SqlDataAdapter daDictionaryItemElement = new System.Data.SqlClient.SqlDataAdapter(@"
  52. select di.*
  53. from Sys_DictionaryItem di
  54. inner join Sys_Dictionary d on di.DictionaryCode=d.DictionaryCode
  55. where di.DictionaryCode='" + dr["DictionaryCode"] + "' and (di.IsEditable=0 or d.IsEditable=0)", db);
  56. System.Data.DataTable dtDictionaryItemElement = new System.Data.DataTable();
  57. daDictionaryItemElement.Fill(dtDictionaryItemElement);
  58. for (int j = 0; j < dtDictionaryItemElement.Rows.Count; j ++)
  59. {
  60. System.Data.DataRow drElement = dtDictionaryItemElement.Rows[j];
  61. string elementItem = "";
  62. elementItem += @"///<summary>
  63. ///" + drElement["Name"] + " -- " + drElement["Value"] + @"
  64. ///</summary>
  65. [System.ComponentModel.Description(""" + drElement["Name"] + @""")]
  66. ";
  67. elementItem += drElement["Code"] + " = " + drElement["Value"].ToString();
  68. if (j != dtDictionaryItemElement.Rows.Count - 1)
  69. {
  70. elementItem += ",";
  71. }#>
  72. <#= elementItem#>
  73. <#}
  74. #>
  75. }
  76. <#}
  77. #>
  78. }