public static void AddorUpdate(Employee employee) { using (var _context = new DBLabManagementEntities()) { bool isAdd = false; if (SelectID == -1) { isAdd = true; var Ids = (from e in _context.Employees select e.IDEmployee).ToList(); for (int i = 1; i <= _context.Employees.Count() + 1; i++) { if (!Ids.Contains(i)) { employee.IDEmployee = i; break; } } } else { if (urcEmployee != null) { urcEmployee.Employee = employee; } } _context.Employees.AddOrUpdate(employee); _context.SaveChanges(); if (isAdd) { frmEmployees.AddEmployee(employee.IDEmployee); } } }
private static List <Task> ListTask(Project project) { using (var _context = new DBLabManagementEntities()) { return(_context.Tasks.Where(x => x.IDProject == project.IDProject).ToList()); } }
public static Employee GetManager(Project project) { using (var _context = new DBLabManagementEntities()) { return(_context.Employees.FirstOrDefault(x => x.IDEmployee == project.IDManager)); } }
public static List <Employee> ListEmployee() { using (var _context = new DBLabManagementEntities()) { return(_context.Employees.Where(x => x.IDLAB == mainController.Lab.IDLab).ToList()); } }
public static Employee GetEmployee(int ID) { using (var _context = new DBLabManagementEntities()) { return(_context.Employees.FirstOrDefault(x => x.IDEmployee == ID)); } }
public static List <Employee> ListEmployee(string t) { using (var _context = new DBLabManagementEntities()) { return(_context.Employees.Where(x => x.IDLAB == mainController.Lab.IDLab && (x.FirstName + " " + x.LastName).Contains(t)).ToList()); } }
public static void AddNewTask(Task task, Employee em, frmListTask frmListTask) { using (var _context = new DBLabManagementEntities()) { var Ids = (from t in _context.Tasks select t.IDTask).ToList(); for (int i = 1; i <= _context.Tasks.Count() + 1; i++) { if (!Ids.Contains(i)) { task.IDTask = i; break; } } var employee = _context.Employees.FirstOrDefault(x => x.IDEmployee == em.IDEmployee); if (employee == null) { return; } employee.Tasks.Add(task); _context.Employees.AddOrUpdate(employee); _context.Tasks.Add(task); _context.SaveChanges(); AddTask(task, frmListTask); } }
public static List <Project> GetListProject() { using (var _context = new DBLabManagementEntities()) { var ListProject = _context.Projects.Where(x => x.IDLab == mainController.Lab.IDLab); return(ListProject.ToList()); } }
public static Project GetProject(Task task) { using (var _context = new DBLabManagementEntities()) { var project = _context.Projects.FirstOrDefault(x => x.IDProject == task.IDProject); return(project); } }
public static void AddOrUpdateTask(Task task) { using (var _context = new DBLabManagementEntities()) { _context.Tasks.AddOrUpdate(task); _context.SaveChanges(); } }
public static List <Employee> GetListEmployee(Task task) { using (var _context = new DBLabManagementEntities()) { var _task = _context.Tasks.FirstOrDefault(x => x.IDTask == task.IDTask); return(_task.Employees.ToList()); } }
public static void UpdateWorkTime(TimeWork timeWork) { using (var _context = new DBLabManagementEntities()) { _context.TimeWorks.AddOrUpdate(timeWork); _context.SaveChanges(); } }
public static void Delete(TimeWork timeWork) { using (var _context = new DBLabManagementEntities()) { var dele = _context.TimeWorks.FirstOrDefault(x => x.IDTimeWork == timeWork.IDTimeWork); _context.TimeWorks.Remove(dele); _context.SaveChanges(); } }
public static void LoadList(frmListProjects frmListProjects) { using (var _context = new DBLabManagementEntities()) { var project = _context.Projects.Where(x => x.IDLab == mainController.Lab.IDLab).OrderBy(x => x.StartDate); foreach (Project p in project) { AddurcProject(p, frmListProjects); } } }
public static bool DeleteSalary(Salary salary) { using (var _context = new DBLabManagementEntities()) { var dbSalary = (from u in _context.Salaries where u.IDEmployee == salary.IDEmployee && u.Month == salary.Month select u).SingleOrDefault(); _context.Salaries.Remove(dbSalary); _context.SaveChanges(); return(true); } }
public static void LoadListTime(frmSetTime frmSetTime) { using (var _context = new DBLabManagementEntities()) { foreach (var time in _context.TimeWorks.Where(x => x.IDEmployee == frmSetTime.Employee.IDEmployee).OrderBy(x => x.StartDate)) { if (time.StartDate.Value.Date == frmSetTime.Day.Date) { frmSetTime.AddTime(time); } } } }
public static void Delete() { using (var _context = new DBLabManagementEntities()) { var EmployeeDelete = _context.Employees.FirstOrDefault(x => x.IDEmployee == SelectID); if (EmployeeDelete != null) { _context.Employees.Remove(EmployeeDelete); _context.SaveChanges(); urcEmployee.Dispose(); } } }
public static void LoadList(frmTime frmTime) { using (var _context = new DBLabManagementEntities()) { foreach (var employee in _context.Employees) { if (employee.IDLAB == mainController.Lab.IDLab) { frmTime.AddTime(employee); } } } }
public static float intComplete(Project project) { using (var _context = new DBLabManagementEntities()) { int t = _context.Tasks.Where(x => x.IDProject == project.IDProject && x.Status == "True").Count(); int m = _context.Tasks.Where(x => x.IDProject == project.IDProject).Count(); if (m == 0) { return(0); } return((float)t / m); } }
public static void Update(Project project, frmListProjects frm, urcProject urc) { using (var _context = new DBLabManagementEntities()) { _context.Projects.AddOrUpdate(project); _context.SaveChanges(); if (urc != null) { urc.Dispose(); } AddurcProject(project, frm); } }
public static void Delete(Project project) { using (var _context = new DBLabManagementEntities()) { var del = _context.Projects.FirstOrDefault(x => x.IDProject == project.IDProject); foreach (var task in ListTask(del)) { TaskController.Delete(task); } _context.Projects.Remove(del); _context.SaveChanges(); } }
public static void LoadListTask(Employee e, frmListTask frmListTask) { using (var _context = new DBLabManagementEntities()) { var employee = _context.Employees.FirstOrDefault(x => x.IDEmployee == e.IDEmployee); if (employee == null) { return; } foreach (Task task in employee.Tasks) { AddTask(task, frmListTask); } } }
public static TimeSpan WeekTime(Employee employee, DateTime time) { using (var _context = new DBLabManagementEntities()) { TimeSpan t = new TimeSpan(); foreach (var w in _context.TimeWorks.Where(x => x.IDEmployee == employee.IDEmployee)) { if (w.StartDate > time && w.StartDate < time.AddDays(6)) { t += w.EndDate.Value - w.StartDate.Value; } } return(t); } }
public static List <TimeWork> Work(Employee employee, DateTime time) { using (var _context = new DBLabManagementEntities()) { List <TimeWork> list = new List <TimeWork>(); foreach (var w in _context.TimeWorks.Where(x => x.IDEmployee == employee.IDEmployee)) { if (w.StartDate.Value.Date == time.Date) { list.Add(w); } } return(list); } }
public static void AddNewLab(Lab lab, Employee employee) { using (var _context = new DBLabManagementEntities()) { lab.IDLab = _context.Labs.Count(); employee.IDEmployee = _context.Employees.Count(); lab.IDMangager = employee.IDEmployee; employee.IDLAB = lab.IDLab; employee.Lab = lab; lab.Employees.Add(employee); _context.Labs.Add(lab); _context.Employees.Add(employee); _context.SaveChanges(); } }
public static bool Login(string UserName, string password) { using (var _context = new DBLabManagementEntities()) { IsLogin = false; var employee = _context.Employees.FirstOrDefault(x => x.UserName.Trim() == UserName && x.EPassword.Trim() == password); if (employee != null) { IsLogin = true; mainController.EmployeeLogin = employee; return(true); } } return(false); }
public static bool UpdateSalary(Salary salary) { try { using (var _context = new DBLabManagementEntities()) { _context.Salaries.AddOrUpdate(salary); _context.SaveChanges(); return(true); } } catch { return(false); } }
//public static bool GetID(int IDEmployee) //{ // using(var _context=new DBLabManagementEntities()) // { // var query = (from u in _context.Employees // where u.IDEmployee == IDEmployee // select u).Any(); // return query; // } //} public static List <Employee> GetIDEmployee(int IDEmployee) { using (var _context = new DBLabManagementEntities()) { var Employee = (from u in _context.Employees where u.IDEmployee == IDEmployee select u).ToList(); if (Employee.Count > 0) { return(Employee); } else { return(null); } } }
public static void Delete(Task t) { using (var _context = new DBLabManagementEntities()) { var task = _context.Tasks.FirstOrDefault(x => x.IDTask == t.IDTask); foreach (var employee in task.Employees) { var e = _context.Employees.FirstOrDefault(x => x.IDEmployee == employee.IDEmployee); if (e != null) { e.Tasks.Remove(task); } } _context.Tasks.Remove(task); _context.SaveChanges(); } }
public static Salary getSalary(int IDEmployee, DateTime Month) { using (var _context = new DBLabManagementEntities()) { var salary = (from u in _context.Salaries where u.IDEmployee == IDEmployee && u.Month == Month select u).ToList(); if (salary.Count > 0) { return(salary[0]); } else { return(null); } } }