private void button2_Click(object sender, EventArgs e) { if (ProjectNameBox.TextLength == 0) { MessageBox.Show("Project name is empty or blank.", "Empty Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } ProjectNameBox.Text = ProjectNameBox.Text.Trim(); FakeProjectRepository newProjectList = new FakeProjectRepository(); existingProjects = newProjectList.GetAll(); foreach (Project projectName in existingProjects) { if (projectName.Name == ProjectNameBox.Text) { MessageBox.Show("Project name already exists.", "Duplicate Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } } Project project = new Project(); project.Id = newProjectID; project.Name = ProjectNameBox.Text; existingProjects.Add(project); newProjectID++; DialogResult = DialogResult.OK; Close(); }
private void FormProject_Load(object sender, EventArgs e) { Projects.Items.Clear(); FakeProjectRepository Project_Repo = new FakeProjectRepository(); List <Project> existing_projects = Project_Repo.GetAll(); foreach (Project p in existing_projects) { string str = p.Id.ToString() + " - " + p.Name; Projects.Items.Add(str); } }
private void buttonSelect_Click(object sender, EventArgs e) { Console.WriteLine(FormProject.selectedProjectName); Console.WriteLine(Projects.SelectedItem); Preference Selection = new Preference(); string SelectedItem = Projects.SelectedItem.ToString(); string[] ListedString = SelectedItem.Split('-'); Selection.Value = ListedString[0].Trim(); Selection.Name = ListedString[1].Trim(); if (FormProject.selectedProjectName == Selection.Name) { MessageBox.Show("Cannot remove your current session project.", "Cannot Remove Current Project", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } else { FakeProjectRepository projects = new FakeProjectRepository(); List <Project> removeProject = new List <Project>(); removeProject = projects.GetAll(); Project remove = new Project(); foreach (Project project in removeProject) { if (project.Name == Selection.Name) { remove = project; } } DialogResult confirmation; confirmation = MessageBox.Show("Are you sure you'd like to remove this project?", "Remove Project", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (confirmation == DialogResult.Yes) { removeProject.Remove(remove); } } DialogResult = DialogResult.OK; Close(); }