コード例 #1
0
        public TaskDetail GetTaskDetail(int incident_id, int technician_id)
        {
            TaskDetail taskDetail = null;

            try
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(connectionString())) {
                    NpgsqlDataReader rdr = null;

                    connection.Open();

                    String SQLquery = "SELECT * FROM \"" + DatabaseNames.TABLE_TASK_DETAIL + "\" WHERE \"" +
                                      DatabaseNames.TASK_DETAIL_INCIDENT_ID + "\" = " + incident_id + " AND \"" +
                                      DatabaseNames.TASK_DETAIL_TECHNICIAN_ID + "\" = " + technician_id;

                    // Pass the connection to a command object
                    NpgsqlCommand command = new NpgsqlCommand(SQLquery, connection);

                    rdr = command.ExecuteReader();


                    while (rdr.Read())
                    {
                        string   reason     = "";
                        Incident incident   = GetIncident((int)rdr[3]);
                        User     technician = GetUserInfo((int)rdr[4]);

                        if (rdr[2] != System.DBNull.Value)
                        {
                            reason = (string)rdr[2];
                        }

                        taskDetail = new TaskDetail((int)rdr[0], (int)rdr[1], reason, incident, technician);
                    }

                    rdr.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error retrieving data: " + e);
            }

            return(taskDetail);
        }
コード例 #2
0
        public static bool TechnicianMainMenu()  //Options where the user chooses which tab they want to go to
        {
            if (incident != null)
            {
                taskDetail = Database.Instance.GetTaskDetail(incident.IncidentID, Authenticate.Instance.User.User_ID);
            }

            bool showMenu = true;
            int  option   = 1;

            while (showMenu)
            {
                Console.Clear();
                Console.WriteLine("Welcome to the GIJIMA Incident App, " + Authenticate.Instance.User.first_name + "\n");

                if (incident != null)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("*You have an incident assigned to you*\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("*You have no incident assigned yet*\n");
                    Console.ResetColor();
                }

                Console.WriteLine("Use Up arrow and Down arrow to move, enter/spacebar to select");
                if (option == 1)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.Write("View assigned incident\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.Write("View assigned incident\n");
                }
                if (option == 2)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.Write("View Incidents Logged\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.Write("View Incidents Logged\n");
                }
                if (option == 3)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.Write("Manage profile\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.Write("Manage profile\n");
                }
                if (option == 4)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.WriteLine("Exit\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.WriteLine("Exit\n");
                }

                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.UpArrow:

                    if (option != 1)
                    {
                        option--;
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (option != 4)
                    {
                        option++;
                    }
                    break;

                case ConsoleKey.Enter:
                case ConsoleKey.Spacebar:
                    Console.Clear();
                    switch (option)
                    {
                    case 1:
                        //The option to open the Incident Log Method
                        ViewAssignedIncidentMenu();
                        break;

                    case 2:

                        Console.WriteLine("List of logged incidents ");

                        //The option to View the Incidents that the user has logged
                        //ViewStatus();
                        break;

                    case 3:
                        //The option to Manage the user's Profile
                        ManageProfile();
                        break;

                    case 4:
                        //The option to exit the tab
                        Console.WriteLine("\nExiting...");
                        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;
                }
            }

            return(showMenu);
        }
コード例 #3
0
        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;
                }
            }
        }