private void AddProject() { List <Project> projectList = ProjectDB.GetData(); project.ProjectName = txtProjectname.Text; if (txtProjectManager.Text != "") { project.ProjectManager = FindManager(); } else { project.ProjectManager = null; } if (ProjectStatus.Text != "") { project.ProjectStatus = ProjectStatus.Text; } else { ProjectStatus.SelectedIndex = 0; project.ProjectStatus = ProjectStatus.Text; } projectList.Add(project); ProjectDB.SaveData(projectList); MessageBox.Show("Project with Id " + txtId.Text + " Added Successfully", "Success Message", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void Delete(Object obj) { if (obj.GetType() == typeof(Manager)) { manager = (Manager)obj; if (manager.ProjectList.Count == 0) { managerList = ManagerDB.GetData(); managerList.Remove(manager); ManagerDB.SaveData(managerList); } else { throw new CustomMadeException("Failed to delete manager " + txtId.Text + " as it has projects."); } } else if (obj.GetType() == typeof(Reportee)) { reportee = (Reportee)obj; if (reportee.Project == null) { reporteeList = ReporteeDB.GetData(); reporteeList.Remove(reportee); ReporteeDB.SaveData(reporteeList); } else { throw new CustomMadeException("Failed to delete reportee " + txtId.Text + " as it has project assigned."); } } else if (obj.GetType() == typeof(Project)) { project = (Project)obj; manager = Validator.SearchManagerByProject(project.ProjectID); reporteeList = Validator.SearchReporteeByProject(project.ProjectID); projectList = ProjectDB.GetData(); projectList.Remove(project); ProjectDB.SaveData(projectList); foreach (Project proj in manager.ProjectList) { if (proj.ProjectID.Equals(project.ProjectID)) { manager.ProjectList.Remove(proj); break; } } foreach (Reportee rep in reporteeList) { rep.Project = null; } } }