PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/V4-3-RC/Templates/CSLA40/CSharp/NVLDataPortalFetch.asp

#
ASP | 149 lines | 143 code | 6 blank | 0 comment | 31 complexity | 42fd26541ca4629ec31cb1aae44d5fb2 MD5 | raw file
Possible License(s): LGPL-2.0, CC-BY-SA-3.0, Apache-2.0, MIT, GPL-3.0
  1. <%
  2. if (!Info.UseCustomLoading && (UseNoSilverlight() ||
  3. CurrentUnit.GenerationParams.GenerateSilverlight4))
  4. {
  5. foreach (Criteria c in Info.CriteriaObjects)
  6. {
  7. if (c.GetOptions.DataPortal)
  8. {
  9. string strGetComment = string.Empty;
  10. bool getIsFirst = true;
  11. foreach (CriteriaProperty p in c.Properties)
  12. {
  13. if (!getIsFirst)
  14. {
  15. strGetComment += System.Environment.NewLine + new string(' ', 8);
  16. }
  17. else
  18. getIsFirst = false;
  19. TypeCodeEx propType = p.PropertyType;
  20. strGetComment += "/// <param name=\"" + FormatCamel(p.Name) + "\">The " + CslaGenerator.Metadata.PropertyHelper.SplitOnCaps(p.Name) + ".</param>";
  21. }
  22. if (c.Properties.Count > 1)
  23. strGetComment = "/// <param name=\"crit\">The fetch criteria.</param>";
  24. %>
  25. /// <summary>
  26. /// Loads a <see cref="<%= Info.ObjectName %>"/> collection from the database<%= (Info.SimpleCacheOptions == SimpleCacheResults.DataPortal && c.Properties.Count == 0) ? " or from the cache" : "" %><%= c.Properties.Count > 0 ? ", based on given criteria" : "" %>.
  27. /// </summary>
  28. <%
  29. if (c.Properties.Count > 0)
  30. {
  31. %><%= strGetComment %>
  32. <%
  33. }
  34. if (c.GetOptions.RunLocal)
  35. {
  36. %>[Csla.RunLocal]
  37. <%
  38. }
  39. if (c.Properties.Count > 1)
  40. {
  41. %>protected void DataPortal_Fetch(<%= c.Name %> crit)<%
  42. }
  43. else if (c.Properties.Count > 0)
  44. {
  45. %>protected void DataPortal_Fetch(<%= ReceiveSingleCriteria(c, "crit") %>)<%
  46. }
  47. else
  48. {
  49. %>protected void DataPortal_Fetch()<%
  50. }
  51. %>
  52. {
  53. <%
  54. if (Info.SimpleCacheOptions == SimpleCacheResults.DataPortal && c.Properties.Count == 0)
  55. {
  56. %>
  57. if (IsCached)
  58. {
  59. LoadCachedList();
  60. return;
  61. }
  62. <%
  63. }
  64. %>
  65. <%= GetConnection(Info, true) %>
  66. {
  67. <%= GetCommand(Info, c.GetOptions.ProcedureName) %>
  68. {
  69. <%
  70. if (Info.CommandTimeout != string.Empty)
  71. {
  72. %>cmd.CommandTimeout = <%= Info.CommandTimeout %>;
  73. <%
  74. }
  75. %>cmd.CommandType = CommandType.StoredProcedure;
  76. <%
  77. foreach (CriteriaProperty p in c.Properties)
  78. {
  79. if (c.Properties.Count > 1)
  80. {
  81. %>cmd.Parameters.AddWithValue("@<%= p.ParameterName %>", <%= GetParameterSet(p, true) %>).DbType = DbType.<%= TypeHelper.GetDbType(p.PropertyType) %>;
  82. <%
  83. }
  84. else
  85. {
  86. %>cmd.Parameters.AddWithValue("@<%= p.ParameterName %>", <%= AssignSingleCriteria(c, "crit") %>).DbType = DbType.<%= TypeHelper.GetDbType(p.PropertyType) %>;
  87. <%
  88. }
  89. }
  90. if (Info.PersistenceType == PersistenceType.SqlConnectionUnshared)
  91. {
  92. %>cn.Open();
  93. <%
  94. }
  95. string hookArgs = string.Empty;
  96. if (c.Properties.Count > 1)
  97. {
  98. hookArgs = ", crit";
  99. }
  100. else if (c.Properties.Count > 0)
  101. {
  102. hookArgs = ", " + HookSingleCriteria(c, "crit");
  103. }
  104. %>var args = new DataPortalHookArgs(cmd<%= hookArgs %>);
  105. OnFetchPre(args);
  106. LoadCollection(cmd);
  107. OnFetchPost(args);
  108. }
  109. }
  110. <%
  111. if (Info.SimpleCacheOptions == SimpleCacheResults.DataPortal && c.Properties.Count == 0)
  112. {
  113. %>
  114. _list = this;
  115. <%
  116. }
  117. %>
  118. }
  119. <!-- #include file="SimpleCacheLoadCachedList.asp" -->
  120. <%
  121. }
  122. }
  123. %>
  124. private void LoadCollection(SqlCommand cmd)
  125. {
  126. IsReadOnly = false;
  127. var rlce = RaiseListChangedEvents;
  128. RaiseListChangedEvents = false;
  129. using (var dr = new SafeDataReader(cmd.ExecuteReader()))
  130. {
  131. while (dr.Read())
  132. {
  133. Add(new NameValuePair(
  134. <%= String.Format(GetDataReaderStatement(valueProp)) %>,
  135. <%= String.Format(GetDataReaderStatement(nameProp)) %>));
  136. }
  137. }
  138. RaiseListChangedEvents = rlce;
  139. IsReadOnly = true;
  140. }
  141. <%
  142. }
  143. %>