You are on page 1of 3

public bool Add( out string error)

{
bool status = this.Validate(out error);
if(status)
{
var row = new DataSet.HRM.Employee();
this.CopyTo(row);
try
{
using (var context = new DataSet.HRM.HRMContext())
{
context.Employees.Add(row);
status = context.SaveChanges() > 0;
}
}
catch (Exception ex)
{

status = false;
error = ex.Message;
}

if (status)
{
this.Id = row.Id;
}
}

return status;
}

Trường hợp 1:nhập các thông tin vào hàm add bấm chạy chuong trình sẽ thêm dữ liệu vào cơ sở dữ liệu,có dữ liệu trong
cơ sở dữ liệu, thông báo pass

Trường hợp 2: nhập các thông tin vào hàm add mà nhập sai kiểu giữ liệu, bấm chạy chương trình sẽ thông báo faild, và
thông báo lỗi.

public decimal Allowance(int employeeId)


{
decimal allowance = 0;
bool status = true;
DataSet.HRM.Employee row;
//load by Id
using (var context = new DataSet.HRM.HRMContext())
{
row = context.Employees.FirstOrDefault(x => x.Id == Id);
status = row != null;
}
if(status)
{
this.CopyFrom(row);
allowance = this.WorkType switch
{
CommonTypes.WorkType.Normal => 0,
CommonTypes.WorkType.Hard => 500,
_ => 0
};

if ((this.PositionType & CommonTypes.PositionType.GD) > 0)


allowance += 7000000;
if ((this.PositionType & CommonTypes.PositionType.PGD) > 0)
allowance += 5000000;
if ((this.PositionType & CommonTypes.PositionType.TP) > 0)
allowance += 3000000;
if ((this.PositionType & CommonTypes.PositionType.PP) > 0)
allowance += 1000000;
if ((this.PositionType & CommonTypes.PositionType.NV) > 0)
allowance += 0;
if (allowance > 10000000)
allowance = 10000000;
}

return allowance;
}

Trường hợp 1: Gọi phương thức Allowance với thông tin đúng. Nếu Allowance trả về giá trị không âm,
hiển thị thông báo "pass" và giá trị phụ cấp.

Trường hợp 2: Gọi phương thức Allowance với thông tin không đúng hoặc không tồn tại. Nếu Allowance
trả về giá trị âm, hiển thị thông báo "fail" và thông báo lỗi.
public decimal WorkSalary(int employeeId, byte month, short year)
{
decimal salary = 0;
bool status = true;
DataSet.HRM.Employee row;
//load by Id
using (var context = new DataSet.HRM.HRMContext())
{
row = context.Employees.FirstOrDefault(x => x.Id == Id);
status = row != null;
}
if(status)
{
this.CopyFrom(row);
switch (this.SalaryType)
{
case CommonTypes.SalaryType.FullTime:
salary = this.Salary/(WorkTimes.WorkDays * 8 * 60) * WorkMinutes(employeeId, month, year)
+ Allowance(employeeId) + WorkTimes.Holidays * this.Salary / WorkTimes.WorkDays;
break;
case CommonTypes.SalaryType.Partime:
salary = this.Salary / 60 * WorkMinutes(employeeId, month, year);
break;
default:
salary = 0;
break;
}
}

return salary;
}
}

Trường hợp 1: Gọi phương thức WorkSalary với thông tin đúng. Nếu WorkSalary trả về giá trị không âm,
hiển thị thông báo "pass" và giá trị lương.
Trường hợp 2: Gọi phương thức WorkSalary với thông tin không đúng hoặc không tồn tại. Nếu
WorkSalary trả về giá trị âm, hiển thị thông báo "fail" và thông báo lỗi.

You might also like