/App_Code/BLL/CourseComponent.cs
# · C# · 292 lines · 198 code · 31 blank · 63 comment · 7 complexity · 1b93d7dfd876693004a057d78a788382 MD5 · raw file
- /*
- '===============================================================================
- ' Generated From - BLL_Component_Partial_Core.vbgen
- '
- ' This object is partial class component representing a table in a database. It
- ' contains core data access methods. Other partial classes should be used for
- ' implementing custom business logic. This class can be regenerated many times.
- '
- ' Do not write custom business logic in this class as it will be overwritten
- ' next time the class is generated.
- '
- ' Version: 1.0
- ' Date: 30/01/06
- ' Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
- ' DeleteAllWForeignKey, class for sorting.
- '===============================================================================
- */
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Collections.Generic;
-
- namespace PlacementManager
- {
- [DataObjectAttribute]
- public partial class CourseComponent
- {
-
- /// <summary>
- /// Default constructor.
- /// </summary>
- public CourseComponent()
- {
-
- }
-
- /// <summary>
- /// Selects one record from the database table using the primary key.
- /// </summary>
- /// <returns>An object of a type representing a row in the database table.</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
- public Course SelectOne(int CourseId)
- {
- PlacementManager.DAL.Course_DAL o = new PlacementManager.DAL.Course_DAL();
- o.CourseId = CourseId;
- DataTable dt = o.SelectOne().Tables[0];
-
- if (dt.Rows.Count > 0)
- {
- DataRow row = dt.Rows[0];
- 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"]);
- return CourseToReturn;
- }
- else
- {
- PlacementManager.Course CourseToReturnEmpty = new PlacementManager.Course();
- return CourseToReturnEmpty;
- }
- }
-
- /// <summary>
- /// Selects all records from the database table.
- /// </summary>
- /// <returns>A collection of objects of a type representing a row in the database table.</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
- public List<Course> SelectAll(string sortExpression)
- {
- List<Course> listCourse = new List<Course>();
- PlacementManager.DAL.Course_DAL o = new PlacementManager.DAL.Course_DAL();
-
- DataSet ds = o.SelectAll();
-
- foreach (DataRow row in ds.Tables[0].Rows)
- {
- 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"]));
- }
-
- if (sortExpression == string.Empty)
- {
- sortExpression = "DateCreated desc";
- }
-
- listCourse.Sort(new CourseComparer(sortExpression));
- return listCourse;
- }
-
- /// <summary>
- /// Selects all records from the database table based on a foreign key.
- /// </summary>
- /// <returns>A collection of objects of a type representing a row in the database table.</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
- public List<Course> SelectAllWDivisionId(int DivisionId, string sortExpression)
- {
- List<Course> listCourse = new List<Course>();
- PlacementManager.DAL.Course_DAL o = new PlacementManager.DAL.Course_DAL();
- o.DivisionId = DivisionId;
- DataSet ds = o.SelectAllWDivisionId();
- foreach (DataRow row in ds.Tables[0].Rows)
- {
- 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"]));
- }
- if (sortExpression == string.Empty)
- {
- sortExpression = "DateCreated desc";
- }
- listCourse.Sort(new CourseComparer(sortExpression));
- return listCourse;
- }
-
-
- /// <summary>
- /// Inserts a new row into the datatable.
- /// </summary>
- /// <param name="o">An object of a datatype representing a row in the database table.</param>
- /// <returns>Boolean</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
- public int Insert(Course o)
- {
- PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
- oCourse.DivisionId = o.DivisionId;
- oCourse.CourseCode = o.CourseCode;
- oCourse.CourseName = o.CourseName;
- oCourse.IsActive = o.IsActive;
- oCourse.DateCreated = o.DateCreated;
- oCourse.CreatedBy = o.CreatedBy;
- oCourse.DateUpdated = o.DateUpdated;
- oCourse.UpdatedBy = o.UpdatedBy;
-
- return oCourse.Insert();
- }
-
- /// <summary>
- /// Inserts a new row into the datatable by passing parameters represneting each column.
- /// </summary>
- /// <returns>Boolean</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
- public int Insert(int DivisionId, string CourseCode, string CourseName, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
- {
- PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
-
- oCourse.DivisionId = DivisionId;
- oCourse.CourseCode = CourseCode;
- oCourse.CourseName = CourseName;
- oCourse.IsActive = IsActive;
- oCourse.DateCreated = DateCreated;
- oCourse.CreatedBy = CreatedBy;
- oCourse.DateUpdated = DateUpdated;
- oCourse.UpdatedBy = UpdatedBy;
-
- return oCourse.Insert();
- }
-
- /// <summary>
- /// Updates a row in the database table based on the primary key.
- /// </summary>
- /// <param name="o">An object of a datatype representing a row in the database table.</param>
- /// <returns>Boolean</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
- public bool Update(Course o)
- {
- PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
- oCourse.CourseId = o.CourseId;
- oCourse.DivisionId = o.DivisionId;
- oCourse.CourseCode = o.CourseCode;
- oCourse.CourseName = o.CourseName;
- oCourse.IsActive = o.IsActive;
- oCourse.DateCreated = o.DateCreated;
- oCourse.CreatedBy = o.CreatedBy;
- oCourse.DateUpdated = o.DateUpdated;
- oCourse.UpdatedBy = o.UpdatedBy;
-
- return oCourse.Update();
- }
-
- /// <summary>
- /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
- /// </summary>
- /// <returns>Boolean</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
- public bool Update(int CourseId, int DivisionId, string CourseCode, string CourseName, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
- {
- PlacementManager.DAL.Course_DAL oCourse = new PlacementManager.DAL.Course_DAL();
-
- oCourse.CourseId = CourseId;
- oCourse.DivisionId = DivisionId;
- oCourse.CourseCode = CourseCode;
- oCourse.CourseName = CourseName;
- oCourse.IsActive = IsActive;
- oCourse.DateCreated = DateCreated;
- oCourse.CreatedBy = CreatedBy;
- oCourse.DateUpdated = DateUpdated;
- oCourse.UpdatedBy = UpdatedBy;
-
- return oCourse.Update();
- }
-
- /// <summary>
- /// Deletes one row in the database table.
- /// </summary>
- /// <param name="o">An object of a datatype representing a row in the database table.</param>
- /// <returns>Boolean</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
- public bool Delete(Course o)
- {
- PlacementManager.DAL.Course_DAL oCourse_DAL = new PlacementManager.DAL.Course_DAL();
- oCourse_DAL.CourseId = o.CourseId;
- return oCourse_DAL.Delete();
- }
-
- /// <summary>
- /// Deletes one row in the database table by passing the primary key.
- /// </summary>
- /// <returns>Boolean</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
- public bool Delete(int CourseId)
- {
- PlacementManager.DAL.Course_DAL oCourse_DAL = new PlacementManager.DAL.Course_DAL();
- oCourse_DAL.CourseId = CourseId;
- return oCourse_DAL.Delete();
- }
-
- /// <summary>
- /// Deletes all rows in a table based on a foreign key.
- /// </summary>
- /// <returns>Boolean</returns>
- [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
- public bool DeleteAllWDivisionId(int DivisionId)
- {
- PlacementManager.DAL.Course_DAL oCourse_DAL = new PlacementManager.DAL.Course_DAL();
- oCourse_DAL.DivisionId = DivisionId;
- return oCourse_DAL.DeleteAllWDivisionId();
- }
-
- }
-
- public class CourseComparer : IComparer<Course>
- {
- private string _sortColumn;
- private bool _reverse;
-
- public CourseComparer(string sortExpression)
- {
- _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
- if (_reverse)
- {
- _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
- }
- else
- {
- _sortColumn = sortExpression;
- }
- }
-
- public int Compare(Course a, Course b)
- {
- int retVal = 0;
- switch (_sortColumn)
- {
- case "CourseId":
- retVal = String.Compare(a.CourseId.ToString(), b.CourseId.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "DivisionId":
- retVal = String.Compare(a.DivisionId.ToString(), b.DivisionId.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "CourseCode":
- retVal = String.Compare(a.CourseCode.ToString(), b.CourseCode.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "CourseName":
- retVal = String.Compare(a.CourseName.ToString(), b.CourseName.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "IsActive":
- retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "DateCreated":
- retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "CreatedBy":
- retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "DateUpdated":
- retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
- case "UpdatedBy":
- retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
- break;
-
- }
- return (retVal * (_reverse ? -1 : 1));
- }
- }
- }