mfc_odbc.cmt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <#@ template language="c#" HostSpecific="True" #>
  2. <#@ output extension= ".cs" #>
  3. <#
  4. TableHost host = (TableHost)(Host);
  5. host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
  6. #>
  7. #pragma once
  8. // header.h
  9. #ifndef __TBL_<#= host.GetModelClass(host.TableName).ToString().ToUpper() #>__
  10. #define __TBL_<#= host.GetModelClass(host.TableName).ToString().ToUpper() #>__
  11. class CTbl_<#= host.GetModelClass(host.TableName) #> : public CRecordset
  12. {
  13. public:
  14. CTbl_<#= host.GetModelClass(host.TableName) #>(CDatabase *pDatabase = NULL);
  15. DECLARE_DYNAMIC(CTbl_<#= host.GetModelClass(host.TableName) #>)
  16. public:
  17. <# foreach (ColumnInfo c in host.Fieldlist) { #>
  18. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="long"||
  19. CodeCommon.DbTypeToCS(c.TypeName)=="decimal")
  20. {#>
  21. LONG m_n<#= c.ColumnName.ToString() #>;
  22. <# } #>
  23. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="string" || CodeCommon.DbTypeToCS(c.TypeName)=="DateTime")
  24. {#>
  25. CString m_str<#= c.ColumnName.ToString() #>;
  26. <# } #>
  27. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="bool" )
  28. {#>
  29. BOOL m_b<#= c.ColumnName.ToString() #>;
  30. <# } #>
  31. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="float" )
  32. {#>
  33. FLOAT m_f<#= c.ColumnName.ToString() #>;
  34. <# } #>
  35. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="int" )
  36. {#>
  37. INT m_n<#= c.ColumnName.ToString() #>;
  38. <# } #>
  39. <# } #>
  40. public:
  41. virtual CString GetDefaultConnect();
  42. virtual CString GetDefaultSQL();
  43. virtual void DoFieldExchange(CFieldExchange* pFX);
  44. #ifdef _DEBUG
  45. virtual void AssertValid() const;
  46. virtual void Dump(CDumpContext& dc) const;
  47. #endif
  48. };
  49. #endif
  50. //////////////////////////////////////////////////////////////////////////////////////////////////////
  51. // .cpp
  52. #include "stdafx.h"
  53. #include "Tbl<#= host.GetModelClass(host.TableName) #>.h"
  54. #ifdef _DEBUG
  55. #define new DEBUG_NEW
  56. #undef THIS_FILE
  57. static char THIS_FILE[] = __FILE__;
  58. #endif
  59. IMPLEMENT_DYNAMIC(CTbl_<#= host.GetModelClass(host.TableName) #>, CRecordset)
  60. CTbl_<#= host.GetModelClass(host.TableName) #>::CTbl_<#= host.GetModelClass(host.TableName) #>(CDatabase* pdb): CRecordset(pdb)
  61. {
  62. <# foreach (ColumnInfo c in host.Fieldlist) { #>
  63. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="long"||
  64. CodeCommon.DbTypeToCS(c.TypeName)=="decimal")
  65. {#>
  66. m_dw<#= c.ColumnName.ToString() #> = 0;
  67. <# } #>
  68. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="string" || CodeCommon.DbTypeToCS(c.TypeName)=="DateTime")
  69. {#>
  70. m_str<#= c.ColumnName.ToString() #> = _T("");
  71. <# } #>
  72. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="bool" )
  73. {#>
  74. m_b<#= c.ColumnName.ToString() #> = FALSE;
  75. <# } #>
  76. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="float" )
  77. {#>
  78. m_f<#= c.ColumnName.ToString() #> = 0.0;
  79. <# } #>
  80. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="int" )
  81. {#>
  82. m_n<#= c.ColumnName.ToString() #> = 0;
  83. <# } #>
  84. <# } #>
  85. m_nFields = <#=host.Fieldlist.Count#>;
  86. m_nDefaultType = forwardOnly;
  87. }
  88. CString CTbl_<#= host.GetModelClass(host.TableName) #>::GetDefaultConnect()
  89. {
  90. return _T("ODBC;DSN=");
  91. }
  92. CString CTbl_<#= host.GetModelClass(host.TableName) #>::GetDefaultSQL()
  93. {
  94. return _T("[<#= host.GetModelClass(host.TableName) #>]");
  95. }
  96. void CTbl_<#= host.GetModelClass(host.TableName) #>::DoFieldExchange(CFieldExchange* pFX)
  97. {
  98. pFX->SetFieldType(CFieldExchange::outputColumn);
  99. <# foreach (ColumnInfo c in host.Fieldlist) { #>
  100. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="long"||
  101. CodeCommon.DbTypeToCS(c.TypeName)=="decimal")
  102. {#>
  103. RFX_Long(pFX, _T("[<#= c.ColumnName.ToString()#>]"), m_dw<#= c.ColumnName.ToString() #> );
  104. <# } #>
  105. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="string" || CodeCommon.DbTypeToCS(c.TypeName)=="DateTime")
  106. {#>
  107. RFX_Text(pFX, _T("[<#= c.ColumnName.ToString()#>]"), m_str<#= c.ColumnName.ToString() #> );
  108. <# } #>
  109. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="bool" )
  110. {#>
  111. RFX_Bool(pFX, _T("[<#= c.ColumnName.ToString()#>]"), m_b<#= c.ColumnName.ToString() #> );
  112. <# } #>
  113. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="float" )
  114. {#>
  115. RFX_Single(pFX, _T("[<#= c.ColumnName.ToString()#>]"), m_f<#= c.ColumnName.ToString() #> );
  116. <# } #>
  117. <# if ( CodeCommon.DbTypeToCS(c.TypeName)=="int" )
  118. {#>
  119. RFX_Int(pFX, _T("[<#= c.ColumnName.ToString()#>]"), m_n<#= c.ColumnName.ToString() #> );
  120. <# } #>
  121. <# } #>
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CTbl_<#= host.GetModelClass(host.TableName) #> diagnostics
  125. #ifdef _DEBUG
  126. void CTbl_<#= host.GetModelClass(host.TableName) #>::AssertValid() const
  127. {
  128. CRecordset::AssertValid();
  129. }
  130. void CTbl_<#= host.GetModelClass(host.TableName) #>::Dump(CDumpContext& dc) const
  131. {
  132. CRecordset::Dump(dc);
  133. }
  134. #endif //_DEBUG