private void submitBtn_Click(object sender, RoutedEventArgs e) { string ideaIDStr = ideaIDTxt.Text.Trim(); int ideaID; string reason = reasonTxt.Text.Trim(); bool success = int.TryParse(ideaIDStr, out ideaID); if (!success) { errorLbl.Text = "IdeaID must be a number"; } else if (responseComboBox.SelectedItem == null || ((string)((ComboBoxItem)responseComboBox.SelectedValue).Content == "Decline" && reason == "")) { errorLbl.Text = "Please input all field!"; } else { string response = (string)((ComboBoxItem)responseComboBox.SelectedValue).Content; IdeaMediator mediator = new IdeaMediator(); Idea idea = mediator.getIdea(ideaID); if (idea == null || idea.status != "Pending") { errorLbl.Text = "Idea doesn't exist!"; } else { if (response == "Accept") { response += "ed"; } else { response += "d"; } idea.status = response; if (response == "Declined") { idea.response = reason; } Idea i = mediator.updateIdea(ideaID, idea); if (i == null) { MessageBox.Show("Idea response failed"); } else { MessageBox.Show("Idea response success"); } refresh(); } } }
private void executeBtn_Click(object sender, RoutedEventArgs e) { string ideaIDStr = ideaIDTxt.Text.Trim(); string desc = descTxt.Text.Trim(); int ideaID; bool success = int.TryParse(ideaIDStr, out ideaID); if (!success) { errorLbl.Text = "IdeaID must be a number!"; } else if (desc == "") { errorLbl.Text = "Please input all field!"; } else { IdeaMediator mediator = new IdeaMediator(); Idea idea = mediator.getIdea(ideaID); if (idea.status != "Accepted") { errorLbl.Text = "Idea can't be executed"; } else { TaskMediator tmediator = new TaskMediator(); TaskFactory tfactory = new TaskFactory(); Task task = tmediator.addTask(tfactory.createNewTask(ideaID, desc)); if (task == null) { MessageBox.Show("Execute idea failed!"); } else { idea.status = "On Progress"; mediator.updateIdea(ideaID, idea); if (idea.type == "Add") { AttractionRideMediator amediator = new AttractionRideMediator(); AttractionRideFactory afactory = new AttractionRideFactory(); amediator.addAttractionOrRide(afactory.createNewAttractionOrRide(idea.name, idea.category, idea.description)); } MessageBox.Show("Execute idea success!"); } refresh(); } } }