PageRenderTime 69ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/App_Code/BLL/CourseComponent.cs

#
C# | 292 lines | 198 code | 31 blank | 63 comment | 7 complexity | 1b93d7dfd876693004a057d78a788382 MD5 | raw file
  1. /*
  2. '===============================================================================
  3. ' Generated From - BLL_Component_Partial_Core.vbgen
  4. '
  5. ' This object is partial class component representing a table in a database. It
  6. ' contains core data access methods. Other partial classes should be used for
  7. ' implementing custom business logic. This class can be regenerated many times.
  8. '
  9. ' Do not write custom business logic in this class as it will be overwritten
  10. ' next time the class is generated.
  11. '
  12. ' Version: 1.0
  13. ' Date: 30/01/06
  14. ' Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
  15. ' DeleteAllWForeignKey, class for sorting.
  16. '===============================================================================
  17. */
  18. using System;
  19. using System.ComponentModel;
  20. using System.Data;
  21. using System.Collections.Generic;
  22. namespace PlacementManager
  23. {
  24. [DataObjectAttribute]
  25. public partial class CourseComponent
  26. {
  27. /// <summary>
  28. /// Default constructor.
  29. /// </summary>
  30. public CourseComponent()
  31. {
  32. }
  33. /// <summary>
  34. /// Selects one record from the database table using the primary key.
  35. /// </summary>
  36. /// <returns>An object of a type representing a row in the database table.</returns>
  37. [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
  38. public Course SelectOne(int CourseId)
  39. {
  40. PlacementManager.DAL.Course_DAL o = new PlacementManager.DAL.Course_DAL();
  41. o.CourseId = CourseId;
  42. DataTable dt = o.SelectOne().Tables[0];
  43. if (dt.Rows.Count > 0)
  44. {
  45. DataRow row = dt.Rows[0];
  46. PlacementManager.Course CourseToReturn = new PlacementManager.Course((int)row["CourseId"], (int)row["DivisionId"], (string)row["CourseCode"], (string)row["CourseName"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
  47. return CourseToReturn;
  48. }
  49. else
  50. {
  51. PlacementManager.Course CourseToReturnEmpty = new PlacementManager.Course();
  52. return CourseToReturnEmpty;
  53. }
  54. }
  55. /// <summary>
  56. /// Selects all records from the database table.
  57. /// </summary>
  58. /// <returns>A collection of objects of a type representing a row in the database table.</returns>
  59. [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
  60. public List<Course> SelectAll(string sortExpression)
  61. {
  62. List<Course> listCourse = new List<Course>();
  63. PlacementManager.DAL.Course_DAL o = new PlacementManager.DAL.Course_DAL();
  64. DataSet ds = o.SelectAll();
  65. foreach (DataRow row in ds.Tables[0].Rows)
  66. {
  67. listCourse.Add(new Course((int)row["CourseId"], (int)row["DivisionId"], (string)row["CourseCode"], (string)row["CourseName"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
  68. }
  69. if (sortExpression == string.Empty)
  70. {
  71. sortExpression = "DateCreated desc";
  72. }
  73. listCourse.Sort(new CourseComparer(sortExpression));
  74. return listCourse;
  75. }
  76. /// <summary>
  77. /// Selects all records from the database table based on a foreign key.
  78. /// </summary>
  79. /// <returns>A collection of objects of a type representing a row in the database table.</returns>
  80. [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
  81. public List<Course> SelectAllWDivisionId(int DivisionId, string sortExpression)
  82. {
  83. List<Course> listCourse = new List<Course>();
  84. PlacementManager.DAL.Course_DAL o = new PlacementManager.DAL.Course_DAL();
  85. o.DivisionId = DivisionId;
  86. DataSet ds = o.SelectAllWDivisionId();
  87. foreach (DataRow row in ds.Tables[0].Rows)
  88. {
  89. listCourse.Add(new Course((int)row["CourseId"], (int)row["DivisionId"], (string)row["CourseCode"], (string)row["CourseName"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
  90. }
  91. if (sortExpression == string.Empty)
  92. {
  93. sortExpression = "DateCreated desc";
  94. }
  95. listCourse.Sort(new CourseComparer(sortExpression));
  96. return listCourse;
  97. }
  98. /// <summary>
  99. /// Inserts a new row into the datatable.
  100. /// </summary>
  101. /// <param name="o">An object of a datatype representing a row in the database table.</param>
  102. /// <returns>Boolean</returns>
  103. [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
  104. public int Insert(Course o)
  105. {
  106. PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
  107. oCourse.DivisionId = o.DivisionId;
  108. oCourse.CourseCode = o.CourseCode;
  109. oCourse.CourseName = o.CourseName;
  110. oCourse.IsActive = o.IsActive;
  111. oCourse.DateCreated = o.DateCreated;
  112. oCourse.CreatedBy = o.CreatedBy;
  113. oCourse.DateUpdated = o.DateUpdated;
  114. oCourse.UpdatedBy = o.UpdatedBy;
  115. return oCourse.Insert();
  116. }
  117. /// <summary>
  118. /// Inserts a new row into the datatable by passing parameters represneting each column.
  119. /// </summary>
  120. /// <returns>Boolean</returns>
  121. [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
  122. public int Insert(int DivisionId, string CourseCode, string CourseName, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
  123. {
  124. PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
  125. oCourse.DivisionId = DivisionId;
  126. oCourse.CourseCode = CourseCode;
  127. oCourse.CourseName = CourseName;
  128. oCourse.IsActive = IsActive;
  129. oCourse.DateCreated = DateCreated;
  130. oCourse.CreatedBy = CreatedBy;
  131. oCourse.DateUpdated = DateUpdated;
  132. oCourse.UpdatedBy = UpdatedBy;
  133. return oCourse.Insert();
  134. }
  135. /// <summary>
  136. /// Updates a row in the database table based on the primary key.
  137. /// </summary>
  138. /// <param name="o">An object of a datatype representing a row in the database table.</param>
  139. /// <returns>Boolean</returns>
  140. [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
  141. public bool Update(Course o)
  142. {
  143. PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
  144. oCourse.CourseId = o.CourseId;
  145. oCourse.DivisionId = o.DivisionId;
  146. oCourse.CourseCode = o.CourseCode;
  147. oCourse.CourseName = o.CourseName;
  148. oCourse.IsActive = o.IsActive;
  149. oCourse.DateCreated = o.DateCreated;
  150. oCourse.CreatedBy = o.CreatedBy;
  151. oCourse.DateUpdated = o.DateUpdated;
  152. oCourse.UpdatedBy = o.UpdatedBy;
  153. return oCourse.Update();
  154. }
  155. /// <summary>
  156. /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
  157. /// </summary>
  158. /// <returns>Boolean</returns>
  159. [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
  160. public bool Update(int CourseId, int DivisionId, string CourseCode, string CourseName, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
  161. {
  162. PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
  163. oCourse.CourseId = CourseId;
  164. oCourse.DivisionId = DivisionId;
  165. oCourse.CourseCode = CourseCode;
  166. oCourse.CourseName = CourseName;
  167. oCourse.IsActive = IsActive;
  168. oCourse.DateCreated = DateCreated;
  169. oCourse.CreatedBy = CreatedBy;
  170. oCourse.DateUpdated = DateUpdated;
  171. oCourse.UpdatedBy = UpdatedBy;
  172. return oCourse.Update();
  173. }
  174. /// <summary>
  175. /// Deletes one row in the database table.
  176. /// </summary>
  177. /// <param name="o">An object of a datatype representing a row in the database table.</param>
  178. /// <returns>Boolean</returns>
  179. [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
  180. public bool Delete(Course o)
  181. {
  182. PlacementManager.DAL.Course_DAL oCourse_DAL = new PlacementManager.DAL.Course_DAL();
  183. oCourse_DAL.CourseId = o.CourseId;
  184. return oCourse_DAL.Delete();
  185. }
  186. /// <summary>
  187. /// Deletes one row in the database table by passing the primary key.
  188. /// </summary>
  189. /// <returns>Boolean</returns>
  190. [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
  191. public bool Delete(int CourseId)
  192. {
  193. PlacementManager.DAL.Course_DAL oCourse_DAL = new PlacementManager.DAL.Course_DAL();
  194. oCourse_DAL.CourseId = CourseId;
  195. return oCourse_DAL.Delete();
  196. }
  197. /// <summary>
  198. /// Deletes all rows in a table based on a foreign key.
  199. /// </summary>
  200. /// <returns>Boolean</returns>
  201. [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
  202. public bool DeleteAllWDivisionId(int DivisionId)
  203. {
  204. PlacementManager.DAL.Course_DAL oCourse_DAL = new PlacementManager.DAL.Course_DAL();
  205. oCourse_DAL.DivisionId = DivisionId;
  206. return oCourse_DAL.DeleteAllWDivisionId();
  207. }
  208. }
  209. public class CourseComparer : IComparer<Course>
  210. {
  211. private string _sortColumn;
  212. private bool _reverse;
  213. public CourseComparer(string sortExpression)
  214. {
  215. _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
  216. if (_reverse)
  217. {
  218. _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
  219. }
  220. else
  221. {
  222. _sortColumn = sortExpression;
  223. }
  224. }
  225. public int Compare(Course a, Course b)
  226. {
  227. int retVal = 0;
  228. switch (_sortColumn)
  229. {
  230. case "CourseId":
  231. retVal = String.Compare(a.CourseId.ToString(), b.CourseId.ToString(), StringComparison.InvariantCultureIgnoreCase);
  232. break;
  233. case "DivisionId":
  234. retVal = String.Compare(a.DivisionId.ToString(), b.DivisionId.ToString(), StringComparison.InvariantCultureIgnoreCase);
  235. break;
  236. case "CourseCode":
  237. retVal = String.Compare(a.CourseCode.ToString(), b.CourseCode.ToString(), StringComparison.InvariantCultureIgnoreCase);
  238. break;
  239. case "CourseName":
  240. retVal = String.Compare(a.CourseName.ToString(), b.CourseName.ToString(), StringComparison.InvariantCultureIgnoreCase);
  241. break;
  242. case "IsActive":
  243. retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
  244. break;
  245. case "DateCreated":
  246. retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
  247. break;
  248. case "CreatedBy":
  249. retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
  250. break;
  251. case "DateUpdated":
  252. retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
  253. break;
  254. case "UpdatedBy":
  255. retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
  256. break;
  257. }
  258. return (retVal * (_reverse ? -1 : 1));
  259. }
  260. }
  261. }