コード例 #1
0
        public bool AddRecord(Employee employee)
        {
            if (employee != null)
            {
                //get the last employee's id and increase by 1 and assign it to the employee id
                //if no employee exists, then start assign from 100
                try
                {
                    employeeDao = new EmployeeDao();
                    int id = employeeDao.GetLastEmployeeId();
                    if (id == 0)
                    {
                        employee.EmployeeId = 100;
                    }
                    else
                    {
                        employee.EmployeeId = id + 1;
                    }

                    //calculate salary
                    employee.CalculateSalary();

                    return(employeeDao.Insert(employee));
                }
                catch (NullReferenceException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(false);
            }
        }