1. A "DataFile" Layer that includes the actual database (Access) and the DataSets for them.
I am splitting the data sets up into Admin functions, Employee Data Access, and so on.
2. A second layer I am calling the "Data Access Layer" (DAL) which includes classes that actually pull data from the database through the datasets. For example, for the Employees.cs class, I have the following under the DAL,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BurrSOFTDesktop.DataDirectory.DataFiles.EmployeesTableAdapters;
using BurrSOFTDesktop.DataDirectory.DataFiles;
namespace BurrSOFTDesktop.DataDirectory.DAL
{
[System.ComponentModel.DataObject]
class EmployeeDataAccess
{
private EmployeesTableAdapter _employees = null;
protected EmployeesTableAdapter Adapter
{
get
{
if (_employees == null)
_employees = new EmployeesTableAdapter();
return _employees;
}
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
public Employees.EmployeesDataTable GetEmployees()
{
return Adapter.GetEmployees();
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public Employees.EmployeesDataTable GetEmployeesByEmployeeID(int employeeID)
{
return Adapter.GetEmployeesByEmployeeID(employeeID);
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public Employees.EmployeesDataTable GetEmployeesByPartialLastName(string partialName)
{
return Adapter.GetEmployeesByPartialLastName(partialName);
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public Employees.EmployeesDataTable GetEmployeesByLocation(int locationID)
{
return Adapter.GetEmployeesByLocationID(locationID);
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public Employees.EmployeesDataTable GetEmployeesByDepartment(int departmentID)
{
return Adapter.GetEmployeesByDepartment(departmentID);
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public Employees.EmployeesDataTable GetEmployeesBySuppperisor(int supervisorID)
{
return Adapter.GetEmployeesBySupervisorID(supervisorID);
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public Employees.EmployeesDataTable GetEmployeesByHireDate(DateTime startDate, DateTime? endDate)
{
if (endDate == null)
endDate = DateTime.Now;
return Adapter.GetEmployeesByHireDateRange(startDate, endDate);
}
/// <summary>
/// This method will add a new employee to the Employees Data Table.
/// It should be noted that there is NO verification in this method to ensure that an employee is not added twice.
/// The Business Layer should check for a duplicate employee by verifying full name prior to calling this method.
/// </summary>
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
public bool AddEmployee(string firstName, string middleName, string lastName, string address1, string address2,
string city, string state, string zip, string phone1, string phone2, DateTime? hireDate,
int? locationID, string title, int? departmentID, int? supervisorID, decimal? payRate,
bool wRApprover, bool pRApprover, decimal? pRLimit, string user1, string user2, string user3)
{
Employees.EmployeesDataTable employees = new Employees.EmployeesDataTable();
Employees.EmployeesRow employee = employees.NewEmployeesRow();
if (firstName == string.Empty) employee.SetFirstNameNull();
else employee.FirstName = firstName;
if (middleName == string.Empty) employee.SetMiddleNameNull();
else employee.MiddleName = middleName;
if (lastName == string.Empty) employee.SetLastNameNull();
else employee.LastName = lastName;
if (address1 == string.Empty) employee.SetAddress1Null();
else employee.Address1 = address1;
if (address2 == string.Empty) employee.SetAddress2Null();
else employee.Address2 = address2;
if (city == string.Empty) employee.SetCityNull();
else employee.City = city;
if (state == string.Empty) employee.SetStateNull();
else employee.State = state;
if (zip == string.Empty) employee.SetZipNull();
else employee.Zip = zip;
if (phone1 == string.Empty) employee.SetPhone1Null();
else employee.Phone1 = phone1;
if (phone2 == string.Empty) employee.SetPhone2Null();
else employee.Phone2 = phone2;
if (hireDate == null) employee.SetHireDateNull();
else employee.HireDate = (DateTime)hireDate;
if (locationID == null) employee.SetLocationIDNull();
else employee.LocationID = (int)locationID;
if (title == string.Empty) employee.SetTitleNull();
else employee.Title = title;
if (departmentID == null) employee.SetDepartmentIDNull();
else employee.DepartmentID = (int)departmentID;
if (supervisorID == null) employee.SetSupervisorNull();
else employee.Supervisor = (int)supervisorID;
if (payRate == null) employee.SetPayRateNull();
else employee.PayRate = (float)payRate;
employee.WRApprover = wRApprover;
employee.PRApprover = pRApprover;
if (pRLimit == null) employee.SetPRLimitNull();
else employee.PRLimit = (float)pRLimit;
if (user1 == string.Empty) employee.SetUser1Null();
else employee.User1 = user1;
if (user2 == string.Empty) employee.SetUser2Null();
else employee.User2 = user2;
if (user3 == string.Empty) employee.SetUser3Null();
else employee.User3 = user3;
employees.AddEmployeesRow(employee);
int rowsAffected = Adapter.Update(employee);
// return true if one and only one row was affected.
return rowsAffected == 1;
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool UpdateEmployee(int employeeID, string firstName, string middleName, string lastName, string address1, string address2,
string city, string state, string zip, string phone1, string phone2, DateTime? hireDate,
int? locationID, string title, int? departmentID, int? supervisorID, decimal? payRate,
bool? wRApprover, bool? pRApprover, decimal? pRLimit, string user1, string user2, string user3)
{
Employees.EmployeesDataTable employees = Adapter.GetEmployeesByEmployeeID(employeeID);
if (employees.Count == 0)
return false;
Employees.EmployeesRow employee = employees[0];
if (firstName != string.Empty) employee.FirstName = firstName;
if (middleName != string.Empty) employee.MiddleName = middleName;
if (lastName != string.Empty) employee.LastName = lastName;
if (address1 != string.Empty) employee.Address1 = address1;
if (address2 != string.Empty) employee.Address2 = address2;
if (city != string.Empty) employee.City = city;
if (state != string.Empty) employee.State = state;
if (zip != string.Empty) employee.Zip = zip;
if (phone1 != string.Empty) employee.Phone1 = phone1;
if (phone2 != string.Empty) employee.Phone2 = phone2;
if (hireDate != null) employee.HireDate = (DateTime)hireDate;
if (locationID != null) employee.LocationID = (int)locationID;
if (title != string.Empty) employee.Title = title;
if (departmentID != null) employee.DepartmentID = (int)departmentID;
if (supervisorID != null) employee.Supervisor = (int)supervisorID;
if (payRate != null) employee.PayRate = (float)payRate;
if (wRApprover != null) employee.WRApprover = (bool)wRApprover;
if (pRApprover != null) employee.PRApprover = (bool)pRApprover;
if (pRLimit != null) employee.PRLimit = (float)pRLimit;
if (user1 != string.Empty) employee.User1 = user1;
if (user2 != string.Empty) employee.User2 = user2;
if (user3 != string.Empty) employee.User3 = user3;
int rowsAffected = Adapter.Update(employee);
return rowsAffected == 1;
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
public bool DeleteEmployee(int employeeID)
{
int rowsAffected = Adapter.DeleteEmployeeByEmplyeeID(employeeID);
return rowsAffected == 1;
}
}
}
3. A Business Logic Layer (BLL) that access the DAL only to perform all the required work. Here is where my question lies...\
4. The actual UI layer that will pull form the BLL.
Now, on the the real question...
In my business logic layer, when developing my classes for accessing the data, how fractured should I make the class files?
For example, take the Employees DAL I posted above. SHould I make one big class that tries to cover all the GetEmployeesBy... methods, or should I break them up into multiple classes? For example,
Should I make the following classes for the employee structures:
1. GetAllEmployees
2. GetAnEmployee
3. GetEmployeesBySupervisor
...
and so on.
The idea of my BLL is that I will aceess the DAL and get the information dumped into datatables, and then access each item in a data row through methods in the class. So if I called GetAnEmployee class, I could get the FirstName with GetAnEmployee.FirstName. For the classes with multiple employes in the table, I would use and index variable that can be set by the calling program.
Any thoughts?
Thanks,
Ed.

New Topic/Question
Reply




MultiQuote






|