private static int saveOrCancelMenu(Incident incident) { Console.Clear(); bool showMenu = true; int option = 1; while (showMenu) { Console.WriteLine("Confirm incident details:\n"); Console.WriteLine("Incident description: " + incident.Description); Console.WriteLine("Incident Location: " + incident.Location); Console.WriteLine("\nUse Up arrow and Down arrow to move, enter/spacebar to select"); if (option == 1) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("* "); Console.Write("Confirm incident\n"); Console.ResetColor(); } else { Console.Write(" "); Console.Write("Confirm incident\n"); } if (option == 2) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("* "); Console.Write("Cancel incident\n"); Console.ResetColor(); } else { Console.Write(" "); Console.Write("Cancel incident\n"); } switch (Console.ReadKey().Key) { case ConsoleKey.UpArrow: if (option != 1) { option--; } Console.Clear(); break; case ConsoleKey.DownArrow: if (option != 2) { option++; } Console.Clear(); break; case ConsoleKey.Enter: case ConsoleKey.Spacebar: Console.Clear(); switch (option) { case 1: return(1); case 2: showMenu = false; return(-1); } break; default: Console.WriteLine("\nInvalid key, use Up/Down arrow to move, enter/spacebar to select"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); break; } } return(-1); }
public static void ViewAssignedIncidentMenu() { bool showMenu = true; int option = 1; while (showMenu) { Console.Clear(); if (incident == null) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\t*There isn't an incident that is assigned to you at the moment*"); Console.ResetColor(); } else { Console.WriteLine("================================================================="); Console.WriteLine("================================================================="); Console.WriteLine("\t Incident Details"); Console.WriteLine(); Console.WriteLine("Incident ID : {0}", incident.IncidentID); Console.WriteLine("Date issued : {0}", incident.Date_Logged); Console.WriteLine("Location : {0}", incident.Location); string status = ""; switch (incident.Status) { case (int)IncidentStatus.Open: status = "Open"; break; case (int)IncidentStatus.Escalated: status = "Escalated"; break; } Console.WriteLine("Status : {0}", status); Console.WriteLine("Description : {0}", incident.Description); Console.WriteLine(); Console.WriteLine("================================================================="); Console.WriteLine("================================================================="); } Console.WriteLine("\nUse Up arrow and Down arrow to move, enter/spacebar to select"); if (option == 1) { Console.ForegroundColor = ConsoleColor.Red; if (incident == null) { Console.Write("* "); Console.Write("\u21B5 Go back\n"); } else if ((incident != null) && (taskDetail == null)) { Console.Write("* "); Console.Write("Accept\n"); } else if ((incident != null) && (taskDetail != null)) { Console.Write("* "); Console.Write("Close incident\n"); } Console.ResetColor(); } else { if (incident == null) { Console.Write(" "); Console.Write("\u21B5 Go back\n"); } else if ((incident != null) && (taskDetail == null)) { Console.Write(" "); Console.Write("Accept\n"); } else if ((incident != null) && (taskDetail != null)) { Console.Write(" "); Console.Write("Close incident\n"); } } if (option == 2) { Console.ForegroundColor = ConsoleColor.Red; if ((incident != null) && (taskDetail == null)) { Console.Write("* "); Console.Write("Reject\n"); } else if ((incident != null) && (taskDetail != null)) { Console.Write("* "); Console.Write("\u21B5 Go back\n"); } Console.ResetColor(); } else { if ((incident != null) && (taskDetail == null)) { Console.Write(" "); Console.Write("Reject\n"); } else if ((incident != null) && (taskDetail != null)) { Console.Write(" "); Console.Write("\u21B5 Go back\n"); } } if (option == 3) { Console.ForegroundColor = ConsoleColor.Red; if ((incident != null) && (taskDetail == null)) { Console.Write("* "); Console.Write("\u21B5 Go back\n"); } Console.ResetColor(); } else { if ((incident != null) && (taskDetail == null)) { Console.Write(" "); Console.Write("\u21B5 Go back\n"); } } switch (Console.ReadKey().Key) { case ConsoleKey.UpArrow: if (option != 1) { option--; } break; case ConsoleKey.DownArrow: if (incident == null) { } else if ((incident != null) && (taskDetail == null)) { if (option != 3) { option++; } } else if ((incident != null) && (taskDetail != null)) { if (option != 2) { option++; } } break; case ConsoleKey.Enter: case ConsoleKey.Spacebar: Console.Clear(); switch (option) { case 1: if (incident == null) { showMenu = false; } else if ((incident != null) && (taskDetail == null)) { //Accepting a task if (Database.Instance.AcceptRejectCloseATask((int)IncidentStatus.Accepted, "", incident.IncidentID)) { incident = Database.Instance.GetAssignedIncidentToTech(); taskDetail = Database.Instance.GetTaskDetail(incident.IncidentID, Authenticate.Instance.User.User_ID); Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nTask has been accepted successfully..."); Console.WriteLine("\nPress any key to continue..."); Console.ResetColor(); Console.ReadKey(true); } else { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nTask failed to be accepted, try again later"); Console.WriteLine("\nPress any key to continue..."); Console.ResetColor(); Console.ReadKey(true); } } else if ((incident != null) && (taskDetail != null)) { //Closing a task if (Database.Instance.AcceptRejectCloseATask((int)IncidentStatus.Closed, "", incident.IncidentID)) { incident = Database.Instance.GetAssignedIncidentToTech(); if (incident == null) { taskDetail = null; } Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nTask has been closed successfully..."); Console.WriteLine("\nPress any key to continue..."); Console.ResetColor(); Console.ReadKey(true); } else { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nTask failed to close, try again later"); Console.WriteLine("\nPress any key to continue..."); Console.ResetColor(); Console.ReadKey(true); } } break; case 2: if ((incident != null) && (taskDetail == null)) { //Reject a task Console.Clear(); Console.WriteLine("Please enter your reason for rejecting the task: "); string reason = Console.ReadLine(); while (String.IsNullOrEmpty(reason) || String.IsNullOrWhiteSpace(reason)) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid reason. Reason can not be empty\n"); Console.ResetColor(); Console.WriteLine("Please enter your reason for rejecting the task: "); reason = Console.ReadLine(); } if (Database.Instance.AcceptRejectCloseATask((int)IncidentStatus.Rejected, reason, incident.IncidentID)) { incident = Database.Instance.GetAssignedIncidentToTech(); if (incident == null) { taskDetail = null; } Console.ReadKey(true); Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nTask has been rejected successfully..."); Console.WriteLine("\nPress any key to continue..."); Console.ResetColor(); Console.ReadKey(true); } else { Console.ReadKey(true); Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nTask failed to be accepted, try again later"); Console.WriteLine("\nPress any key to continue..."); Console.ResetColor(); Console.ReadKey(true); } showMenu = false; } else if ((incident != null) && (taskDetail != null)) { showMenu = false; } break; case 3: //The option to exit the tab showMenu = false; break; } break; default: Console.WriteLine("\nInvalid key, use Up/Down arrow to move, enter/spacebar to select"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); break; } } }
public static Boolean LogIncident()//A method that allows the user to Report their incidents { //The user is prompted to log the incident which requires them to enter the decrtion and the location of the incident Console.WriteLine("**********************************************\n"); Console.WriteLine("Enter incident description: "); string incidentDescription = Console.ReadLine(); while (string.IsNullOrEmpty(incidentDescription) || string.IsNullOrWhiteSpace(incidentDescription) || !Validators.isValidInputString(incidentDescription)) { Console.WriteLine("Invalid! Please enter valid description: "); incidentDescription = Console.ReadLine(); } Console.Clear(); Console.WriteLine("Enter incident location: "); Console.WriteLine("i.e. Gijima Midrand, Gazelle Close, Floor 2, room: Siyabonga"); string incidentLocation = Console.ReadLine(); while (string.IsNullOrEmpty(incidentLocation) || string.IsNullOrWhiteSpace(incidentLocation) || !Validators.isValidInputLocString(incidentDescription)) { Console.WriteLine("Invalid! Please enter valid location: "); Console.WriteLine("i.e. Gijima Midrand, Gazelle Close, Floor 2, room: Siyabonga"); incidentLocation = Console.ReadLine(); } DateTime date = DateTime.Now; //The input that will be saved in the database Incident incident = new Incident(0, incidentLocation, incidentDescription, date, 0, Authenticate.Instance.User, null); if (saveOrCancelMenu(incident) > 0) { if (Database.Instance.LogIncident(incident)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Incident Successfully\n"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); /// Set timer for escalation IncidentSystem.Instance.setTimerForEscalation(Database.Instance.GetIncidentID(incident), false); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Incident cancelled\n"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); } Console.WriteLine("Press any key to continue..."); Console.Clear(); // if (Database.Instance.LogIncident(incident)) { // Console.ForegroundColor = ConsoleColor.Green; // Console.WriteLine("Incident Successfully logged!"); // Console.WriteLine("\nPress any key to continue..."); // Console.ForegroundColor = ConsoleColor.White; // /// Set timer for escalation // IncidentSystem.Instance.setTimerForEscalation(Database.Instance.GetIncidentID(incident), false); // } else { // Console.ForegroundColor = ConsoleColor.Red; // Console.WriteLine("An error has occured! Please contact administrator"); // Console.WriteLine("\nPress any key to continue..."); // Console.ForegroundColor = ConsoleColor.White; // } Console.ReadKey(true); return(true); }