public void AddEnhancemant(Enhancement enhancement) { try { enhancement.ticketId = EnhancementTickets.Max(m => m.ticketId) + 1; StreamWriter sw = new StreamWriter(filePath, true); sw.WriteLine($"{enhancement.ticketId},{enhancement.summary},{enhancement.status},{enhancement.priority},{enhancement.submitter},{enhancement.assigned},{string.Join("|", enhancement.watching)},{enhancement.software},{enhancement.cost},{enhancement.reason},{enhancement.estimate}"); sw.Close(); EnhancementTickets.Add(enhancement); logger.Info("Ticket ID {Id} added", enhancement.ticketId); } catch (Exception ex) { logger.Error(ex.Message); } }
//Method to write to file public void AddTicket(Ticket ticket, int type) { if (type == 1) { Defect defect = (Defect)ticket; try{ StreamWriter sw = new StreamWriter(defectFile, true); sw.WriteLine($"{defect.id},{defect.summary},{defect.status},{defect.priority},{defect.submitter},{defect.assigned},{String.Join("|", defect.watching)},{defect.severity}"); sw.Close(); logger.Info($"Defect {defect.id} entered"); }catch (Exception e) { logger.Error(e.Message); } } else if (type == 2) { Enhancement en = (Enhancement)ticket; try{ StreamWriter sw = new StreamWriter(enhancementFile, true); sw.WriteLine($"{en.id},{en.summary},{en.status},{en.priority},{en.submitter},{en.assigned},{String.Join("|", en.watching)},{en.software},{en.cost},{en.reason},{en.estimate}"); sw.Close(); logger.Info($"Enhancement {en.id} entered"); }catch (Exception e) { logger.Error(e.Message); } } else if (type == 3) { Task task = (Task)ticket; try{ StreamWriter sw = new StreamWriter(taskFile, true); sw.WriteLine($"{task.id},{task.summary},{task.status},{task.priority},{task.submitter},{task.assigned},{String.Join("|", task.watching)},{task.projectName},{task.dueDate}"); sw.Close(); logger.Info($"Task {task.id} entered"); }catch (Exception e) { logger.Error(e.Message); } } //update Ticket list Tickets.Add(ticket); }
public EnhancementTicketFile(string EnhancementTicketFilePath) { filePath = EnhancementTicketFilePath; EnhancementTickets = new List <Enhancement>(); try { StreamReader sr = new StreamReader(filePath); while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] ticketDetails = line.Split(','); if (ticketDetails.Length == 11) { Enhancement enhancement = new Enhancement(); enhancement.ticketId = UInt64.Parse(ticketDetails[0]); enhancement.summary = ticketDetails[1]; enhancement.status = ticketDetails[2]; enhancement.priority = ticketDetails[3]; enhancement.submitter = ticketDetails[4]; enhancement.assigned = ticketDetails[5]; enhancement.watching = ticketDetails[6].Split('|').ToList(); enhancement.software = ticketDetails[7]; enhancement.cost = ticketDetails[8]; enhancement.reason = ticketDetails[9]; enhancement.estimate = ticketDetails[10]; EnhancementTickets.Add(enhancement); } } sr.Close(); logger.Info("Tickets in file: {Count}", EnhancementTickets.Count); } catch (Exception ex) { logger.Error(ex.Message); } }
static void Main(string[] args) { NLog.Logger logger = NLog.Web.NLogBuilder.ConfigureNLog(Directory.GetCurrentDirectory() + "\\nlog.config").GetCurrentClassLogger(); logger.Info("Program Started"); // create ticket files for each type TicketFile defects = new TicketFile("Tickets.csv", "Defect"); TicketFile enhancements = new TicketFile("Enhancements.csv", "Enhancement"); TicketFile tasks = new TicketFile("Task.csv", "Task"); string userChoice; do { Console.Write("\n1. Read data from file\n2. Add data to file\n3. Search for ticket\nEnter any key to exit\n>"); userChoice = Console.ReadLine(); // choice 1 - read data if (userChoice == "1") { //ask what file to read from Console.Write("\nWhich type of ticket do you wish to look at?\n1. Bugs/Defects\n2. Enhancements\n3. Tasks\n>"); int readFrom; while (!Int32.TryParse(Console.ReadLine(), out readFrom)) { Console.Write("\nAnswer must be an integer\n1. Bugs/Defects\n2. Enhancements\n3. Tasks\n>"); } //read from that file if (readFrom == 1) { foreach (Defect defect in defects.Tickets) { Console.WriteLine("\n" + defect.Display()); } logger.Info("Defects Displayed"); } else if (readFrom == 2) { foreach (Enhancement en in enhancements.Tickets) { Console.WriteLine("\n" + en.Display()); } logger.Info("Enhancements Displayed"); } else if (readFrom == 3) { foreach (Task task in tasks.Tickets) { Console.WriteLine("\n" + task.Display()); } logger.Info("Tasks Displayed"); } } // choice 2 - add data else if (userChoice == "2") { //ask what file to write to Console.Write("\nWhich type of ticket do you wish to write?\n1. Bug/Defect\n2. Enhancement\n3. Task\n>"); int toWrite; while (!Int32.TryParse(Console.ReadLine(), out toWrite)) { Console.Write("\nAnswer must be an integer\n1. Bugs/Defect\n2. Enhancement\n3. Task\n>"); } //collect information //summary, status, priority, submitter, assigned, watching Console.Write("Enter Summary: "); string summary = Console.ReadLine(); Console.Write("Enter Status: "); string status = Console.ReadLine(); Console.Write("Enter Priority: "); string priority = Console.ReadLine(); Console.Write("Enter Submitter: "); string submitter = Console.ReadLine(); Console.Write("Enter Assigned: "); string assigned = Console.ReadLine(); List <string> watchers = new List <string>(); string watcher; do { Console.Write("Enter Watching (or done to quit): "); watcher = Console.ReadLine(); if (!watcher.Equals("done")) { watchers.Add(watcher); } } while(!watcher.Equals("done")); //defect - id, severity, create the new ticket if (toWrite == 1) { //create ticket Defect defect = new Defect(); // add id + severity defect.id = defects.getNewID(); Console.Write("Enter Severity: "); defect.severity = Console.ReadLine(); //add everything else defect.summary = summary; defect.status = status; defect.priority = priority; defect.submitter = submitter; defect.assigned = assigned; defect.watching = watchers; defects.AddTicket(defect, toWrite); } //enhancement - id, software, cost, reason, estimate, create the new ticket else if (toWrite == 2) { //create ticket Enhancement en = new Enhancement(); //add id, software, cost, reason, estimate en.id = enhancements.getNewID(); Console.Write("Enter Software: "); en.software = Console.ReadLine(); Console.Write("Enter Cost: "); en.cost = Double.Parse(Console.ReadLine()); Console.Write("Enter Reason: "); en.reason = Console.ReadLine(); Console.Write("Enter Estimate: "); en.estimate = Double.Parse(Console.ReadLine()); //add everything else en.summary = summary; en.status = status; en.priority = priority; en.submitter = submitter; en.assigned = assigned; en.watching = watchers; enhancements.AddTicket(en, toWrite); } //task - id, project name, due date, create the new ticket else if (toWrite == 3) { //create ticket Task task = new Task(); //add id, project name, due date task.id = tasks.getNewID(); Console.Write("Enter Project Name: "); task.projectName = Console.ReadLine(); Console.Write("Enter Due Date (mm/dd/yyyy): "); DateTime dueDate; while (!DateTime.TryParse(Console.ReadLine(), out dueDate)) { logger.Info("Invalid date"); Console.Write("Plese enter date(mm/dd/yyyy): "); } task.dueDate = dueDate; //add everything else task.summary = summary; task.status = status; task.priority = priority; task.submitter = submitter; task.assigned = assigned; task.watching = watchers; tasks.AddTicket(task, toWrite); } } else if (userChoice == "3") { //status, priority, or submitter Console.Write("Search by:\n1. Status\n2. Priority\n3. Submitter\n>"); int searchBy; Int32.TryParse(Console.ReadLine(), out searchBy); //search term Console.Write("Search For\n>"); string searchTerm = Console.ReadLine(); //search List <Ticket> ticketsBySearch = new List <Ticket>(); switch (searchBy) { case 1: //status ticketsBySearch.AddRange(defects.Tickets.Where(t => t.status.Equals(searchTerm, StringComparison.OrdinalIgnoreCase)) .Concat(enhancements.Tickets.Where(t => t.status.Equals(searchTerm, StringComparison.OrdinalIgnoreCase))) .Concat(tasks.Tickets.Where(t => t.status.Equals(searchTerm, StringComparison.OrdinalIgnoreCase))).ToList()); break; case 2: //priority ticketsBySearch.AddRange(defects.Tickets.Where(t => t.priority.Equals(searchTerm, StringComparison.OrdinalIgnoreCase)) .Concat(enhancements.Tickets.Where(t => t.priority.Equals(searchTerm, StringComparison.OrdinalIgnoreCase))) .Concat(tasks.Tickets.Where(t => t.priority.Equals(searchTerm, StringComparison.OrdinalIgnoreCase))).ToList()); break; case 3: //submitter ticketsBySearch.AddRange(defects.Tickets.Where(t => t.submitter.Equals(searchTerm, StringComparison.OrdinalIgnoreCase)) .Concat(enhancements.Tickets.Where(t => t.submitter.Equals(searchTerm, StringComparison.OrdinalIgnoreCase))) .Concat(tasks.Tickets.Where(t => t.submitter.Equals(searchTerm, StringComparison.OrdinalIgnoreCase))).ToList()); break; } //result logger.Info($"{ticketsBySearch.Count()} tickets with \"{searchTerm}\" search term"); Console.Write($"The {ticketsBySearch.Count()} tickets with \"{searchTerm}\" search term:"); foreach (Ticket ticket in ticketsBySearch) { Console.WriteLine("\n" + ticket.Display()); } } } while (userChoice == "1" || userChoice == "2" || userChoice == "3"); logger.Info("Program Ended"); }
public void Add() { //create placeholder ticket Enhancement fresh = new Enhancement(); //set ticket # if (Enhancements.Count == 0) { fresh.TicketId = 1; } else { fresh.TicketId = Enhancements[Enhancements.Count - 1].TicketId + 1; } //get summary Console.Write("=Enter Bug Summary:\n" + "==="); string input = Console.ReadLine(); fresh.Summary = "\"" + input + "\""; //get status Console.Write("=Choose Bug Status:\n" + "=1) Open\n" + "=2) Closed\n" + "==="); switch (Validate.ValidateMenuSelection(Console.ReadLine(), 2)) { case "1": fresh.Status = Status.Open; break; case "2": fresh.Status = Status.Closed; break; } //get priority Console.Write("=Choose Bug Priority:\n" + "=1) High\n" + "=2) Medium\n" + "=3) Low\n" + "=4) Negligible\n" + "==="); switch (Validate.ValidateMenuSelection(Console.ReadLine(), 4)) { case "1": fresh.Priority = Priority.High; break; case "2": fresh.Priority = Priority.Medium; break; case "3": fresh.Priority = Priority.Low; break; case "4": fresh.Priority = Priority.Negligible; break; } //get name of submitter Console.Write("=Enter Name of Submitter: "); fresh.Submitter = Validate.ValidateName(Console.ReadLine()); //get name of assigned Console.Write("=Enter Name of Assigned: "); fresh.Assigned = Validate.ValidateName(Console.ReadLine()); //get number of watchers Console.Write("=Enter Number of Bug Watchers: "); var num = Validate.ValidateNumber(Console.ReadLine()); if (num == "0") { fresh.Watching = "No Watchers"; } else { //list for watchers List <string> watchers = new List <string>(); for (var i = 0; i < int.Parse(num); i++) { //get name of watchers Console.Write("=Enter the Name of the Watcher: "); watchers.Add(Validate.ValidateName(Console.ReadLine())); } //join watchers with '|' and add to fresh fresh.Watching = String.Join("|", watchers.ToArray()); } //get software Console.Write("=Enter Name of the Project: "); fresh.Software = Validate.ValidateForChars(Console.ReadLine()); //get cost Console.Write("=Enter Cost: "); fresh.Cost = Validate.ValidateDouble(Console.ReadLine()); //get reason Console.Write("=Enter Reason: "); fresh.Reason = Validate.ValidateForChars(Console.ReadLine()); //get estimate Console.Write("=Enter Estimate: "); fresh.Estimate = Validate.ValidateForChars(Console.ReadLine()); //confirm ticket Console.WriteLine("=Ticket information to be entered:"); fresh.Display(); Console.Write("=Confirm?\n" + "=1) Add\n" + "=2) Cancel\n" + "==="); switch (Validate.ValidateMenuSelection(Console.ReadLine(), 2)) { case "1": logger.Trace("Ticket added, {fresh}", fresh); Console.WriteLine("Ticket Added."); Enhancements.Add(fresh); StreamWriter sw = new StreamWriter(File); foreach (var enhancement in Enhancements) { sw.WriteLine(enhancement.ToString()); } sw.Close(); break; case "2": Console.WriteLine("Canceling ticket creation, returning to main menu."); break; } }
static void Main(string[] args) { string bugDefectTicketFilePath = Directory.GetCurrentDirectory() + "\\tickets.csv"; string enhancementTicketFilePath = Directory.GetCurrentDirectory() + "\\enhancements.csv"; string taskTicketFilePath = Directory.GetCurrentDirectory() + "\\tasks.csv"; logger.Info("Program started"); BugDefectTicketFile bugDefectTicketFile = new BugDefectTicketFile(bugDefectTicketFilePath); EnhancementTicketFile enhancementTicketFile = new EnhancementTicketFile(enhancementTicketFilePath); TaskTicketFile taskTicketFile = new TaskTicketFile(taskTicketFilePath); string choice = ""; do { Console.WriteLine("1) Add Ticket"); Console.WriteLine("2) Display All Tickets"); Console.WriteLine("Enter to quit"); choice = Console.ReadLine(); logger.Info("User choice: {Choice}", choice); if (choice == "1") { Console.WriteLine("1) Bug/Defect"); Console.WriteLine("2) Enhancement"); Console.WriteLine("3) Task"); string ticketTypeChoice = Console.ReadLine(); logger.Info("User choice: {Choice}", ticketTypeChoice); if (ticketTypeChoice == "1") { BugDefect bugDefect = new BugDefect(); Console.WriteLine("Enter Bug/Defect ticket summary"); bugDefect.summary = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket status"); bugDefect.status = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket priority"); bugDefect.priority = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket submitter"); bugDefect.submitter = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket asignee"); bugDefect.assigned = Console.ReadLine(); string input; do { Console.WriteLine("Enter Bug/Defect ticket watcher (or done to quit)"); input = Console.ReadLine(); if (input != "done" && input.Length > 0) { bugDefect.watching.Add(input); } }while (input != "done"); if (bugDefect.watching.Count == 0) { bugDefect.watching.Add("(no watchers listed)"); } Console.WriteLine("Enter Bug/Defect ticket severity"); bugDefect.severity = Console.ReadLine(); bugDefectTicketFile.AddBugDefect(bugDefect); } if (ticketTypeChoice == "2") { Enhancement enhancement = new Enhancement(); Console.WriteLine("Enter Enhancement ticket summary"); enhancement.summary = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket status"); enhancement.status = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket priority"); enhancement.priority = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket submitter"); enhancement.submitter = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket asignee"); enhancement.assigned = Console.ReadLine(); string input; do { Console.WriteLine("Enter Enhancement ticket watcher (or done to quit)"); input = Console.ReadLine(); if (input != "done" && input.Length > 0) { enhancement.watching.Add(input); } }while (input != "done"); if (enhancement.watching.Count == 0) { enhancement.watching.Add("(no watchers listed)"); } Console.WriteLine("Enter Enhancement ticket software"); enhancement.software = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket cost"); enhancement.cost = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket reason"); enhancement.reason = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket estimate"); enhancement.estimate = Console.ReadLine(); enhancementTicketFile.AddEnhancemant(enhancement); } if (ticketTypeChoice == "3") { Task task = new Task(); Console.WriteLine("Enter Task ticket summary"); task.summary = Console.ReadLine(); Console.WriteLine("Enter Task ticket status"); task.status = Console.ReadLine(); Console.WriteLine("Enter Task ticket priority"); task.priority = Console.ReadLine(); Console.WriteLine("Enter Task ticket submitter"); task.submitter = Console.ReadLine(); Console.WriteLine("Enter Task ticket asignee"); task.assigned = Console.ReadLine(); string input; do { Console.WriteLine("Enter Task ticket watcher (or done to quit)"); input = Console.ReadLine(); if (input != "done" && input.Length > 0) { task.watching.Add(input); } }while (input != "done"); if (task.watching.Count == 0) { task.watching.Add("(no watchers listed)"); } Console.WriteLine("Enter Task ticket project name"); task.projectName = Console.ReadLine(); Console.WriteLine("Enter Task ticket due date"); task.dueDate = Console.ReadLine(); taskTicketFile.AddTask(task); } } else if (choice == "2") { Console.WriteLine("1) Bug/Defect"); Console.WriteLine("2) Enhancement"); Console.WriteLine("3) Task"); string ticketTypeChoice = Console.ReadLine(); logger.Info("User choice: {Choice}", ticketTypeChoice); if (ticketTypeChoice == "1") { foreach (Ticket m in bugDefectTicketFile.BugDefectTickets) { Console.WriteLine(m.Display()); } } else if (ticketTypeChoice == "2") { foreach (Ticket m in enhancementTicketFile.EnhancementTickets) { Console.WriteLine(m.Display()); } } else if (ticketTypeChoice == "3") { foreach (Ticket m in taskTicketFile.TaskTickets) { Console.WriteLine(m.Display()); } } } } while (choice == "1" || choice == "2"); logger.Info("Program ended"); }
public void TicketEntry() { string choice; string type; List <string> baseQuestions; CSVTicketParser ticketParser = new CSVTicketParser(); do { Console.WriteLine("1) Read data from file."); Console.WriteLine("2) Create file from data."); Console.WriteLine("3) Search file from data"); Console.WriteLine("Enter any other key to exit."); // input response choice = Console.ReadLine(); if (choice == "1") { ReadDataFromFile(); } else if (choice == "2") { Console.WriteLine("Enter a ticket (Y/N)?"); response = Console.ReadLine().ToUpper(); if (response != "Y") { break; } Console.WriteLine("Enter a ticket type (1:Task, 2:Enhancement, 3:Bug/Defect, 4:Other Ticket)"); type = Console.ReadLine(); baseQuestions = BaseQuestions(); if (type == "1") { Task task = new Task(); task.ticketID = baseQuestions[0]; task.summary = baseQuestions[1]; task.status = baseQuestions[2]; task.priority = baseQuestions[3]; task.submitter = baseQuestions[4]; task.assigned = baseQuestions[5]; task.watching = baseQuestions[6]; Console.WriteLine("Enter the Project Name: "); task.projectName = Console.ReadLine(); //05/05/2005 Console.WriteLine("Enter the Due Date: (ex 05/05/2005)"); task.dueDate = Convert.ToDateTime(Console.ReadLine()); StreamWriter sw = new StreamWriter(ticketFiles[1] + ".csv", append: true); sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8}", task.ticketID, task.summary, task.status, task.priority, task.submitter, task.assigned, task.watching, task.projectName, task.dueDate); sw.Close(); } else if (type == "2") { Enhancement enhancement = new Enhancement(); enhancement.ticketID = baseQuestions[0]; enhancement.summary = baseQuestions[1]; enhancement.status = baseQuestions[2]; enhancement.priority = baseQuestions[3]; enhancement.submitter = baseQuestions[4]; enhancement.assigned = baseQuestions[5]; enhancement.watching = baseQuestions[6]; Console.WriteLine("Enter the Software: "); enhancement.software = Console.ReadLine(); Console.WriteLine("Enter the Cost: "); enhancement.cost = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Enter the Reason: "); enhancement.reason = Console.ReadLine(); Console.WriteLine("Enter the Estimate: "); enhancement.estimate = Convert.ToDouble(Console.ReadLine()); StreamWriter sw = new StreamWriter(ticketFiles[2] + ".csv", append: true); sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", enhancement.ticketID, enhancement.summary, enhancement.status, enhancement.priority, enhancement.submitter, enhancement.assigned, enhancement.watching, enhancement.software, enhancement.cost, enhancement.reason, enhancement.estimate); sw.Close(); } else if (type == "3") { BugDefect bugDefect = new BugDefect(); bugDefect.ticketID = baseQuestions[0]; bugDefect.summary = baseQuestions[1]; bugDefect.status = baseQuestions[2]; bugDefect.priority = baseQuestions[3]; bugDefect.submitter = baseQuestions[4]; bugDefect.assigned = baseQuestions[5]; bugDefect.watching = baseQuestions[6]; Console.WriteLine("Enter severity (1,2,3,4)"); bugDefect.severity = Console.ReadLine(); StreamWriter sw = new StreamWriter(ticketFiles[3] + ".csv", append: true); sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7}", bugDefect.ticketID, bugDefect.summary, bugDefect.status, bugDefect.priority, bugDefect.submitter, bugDefect.assigned, bugDefect.watching, bugDefect.severity); sw.Close(); } else if (type == "4") { Ticket ticket = new Ticket(); ticket.ticketID = baseQuestions[0]; ticket.summary = baseQuestions[1]; ticket.status = baseQuestions[2]; ticket.priority = baseQuestions[3]; ticket.submitter = baseQuestions[4]; ticket.assigned = baseQuestions[5]; ticket.watching = baseQuestions[6]; StreamWriter sw = new StreamWriter(ticketFiles[4] + ".csv", append: true); sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", ticket.ticketID, ticket.summary, ticket.status, ticket.priority, ticket.submitter, ticket.assigned, ticket.watching); sw.Close(); } else { Console.WriteLine("Please enter 1, 2, 3 or 4 to specify the ticket type"); } } else if (choice == "3") { Console.WriteLine("Please choose a type of ticket to search: "); Console.WriteLine("1) Bug Defects"); Console.WriteLine("2) Enhancements"); Console.WriteLine("3) Tasks"); Console.WriteLine("4) Other"); string userChoice = Console.ReadLine(); switch (userChoice) { case "1": { Console.WriteLine("Please choose how to search tickets:"); Console.WriteLine("1) Status"); Console.WriteLine("2) Priority"); Console.WriteLine("3) Submitter"); string response = Console.ReadLine(); switch (response) { case "1": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileBugDefect = "BugTickets.csv"; var tickets = ticketParser.BDStatusLow(fileBugDefect, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "2": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileBugDefect = "BugTickets.csv"; var tickets = ticketParser.BDPriority(fileBugDefect, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "3": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileBugDefect = "BugTickets.csv"; var tickets = ticketParser.BDSubmiter(fileBugDefect, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } default: { break; } } break; } case "2": { Console.WriteLine("Please choose how to search tickets:"); Console.WriteLine("1) Status"); Console.WriteLine("2) Priority"); Console.WriteLine("3) Submitter"); string response = Console.ReadLine(); switch (response) { case "1": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileEnhancement = "EnhancementTickets.csv"; var tickets = ticketParser.EHStatus(fileEnhancement, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "2": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileEnhancement = "EnhancementTickets.csv"; var tickets = ticketParser.EHPriority(fileEnhancement, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "3": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileEnhancement = "EnhancementTickets.csv"; var tickets = ticketParser.EHSubmitter(fileEnhancement, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } default: { break; } } break; } case "3": { Console.WriteLine("Please choose how to search tickets:"); Console.WriteLine("1) Status"); Console.WriteLine("2) Priority"); Console.WriteLine("3) Submitter"); string response = Console.ReadLine(); switch (response) { case "1": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileTask = "TaskTickets.csv"; var tickets = ticketParser.TaskStatus(fileTask, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "2": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileTask = "TaskTickets.csv"; var tickets = ticketParser.TaskPriority(fileTask, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "3": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); string fileTask = "TaskTickets.csv"; var tickets = ticketParser.TaskSubmitter(fileTask, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } default: { break; } } break; } case "4": { Console.WriteLine("Please choose how to search tickets:"); Console.WriteLine("1) Status"); Console.WriteLine("2) Priority"); Console.WriteLine("3) Submitter"); string response = Console.ReadLine(); switch (response) { case "1": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); var tickets = ticketParser.TicketStatus(file, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "2": { Console.WriteLine("Please choose you status: "); Console.WriteLine("1) Low"); Console.WriteLine("2) Medium"); Console.WriteLine("3) High"); string statusRes = Console.ReadLine(); var tickets = ticketParser.TicketPriority(file, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } case "3": { Console.WriteLine("Please type in name of submitter: "); string statusRes = Console.ReadLine(); var tickets = ticketParser.TicketSubmitter(file, statusRes); foreach (var ticket in tickets) { Console.WriteLine(ticket.ticketID + " " + ticket.status); } break; } default: { break; } } break; } } } } while (choice == "1" || choice == "2" || choice == "3"); // do while loop for option two, continue adding records }
static void Main(string[] args) { string bugDefectTicketFilePath = Directory.GetCurrentDirectory() + "\\tickets.csv"; string enhancementTicketFilePath = Directory.GetCurrentDirectory() + "\\enhancements.csv"; string taskTicketFilePath = Directory.GetCurrentDirectory() + "\\tasks.csv"; logger.Info("Program started"); BugDefectTicketFile bugDefectTicketFile = new BugDefectTicketFile(bugDefectTicketFilePath); EnhancementTicketFile enhancementTicketFile = new EnhancementTicketFile(enhancementTicketFilePath); TaskTicketFile taskTicketFile = new TaskTicketFile(taskTicketFilePath); string choice = ""; do { Console.WriteLine("1) Add Ticket"); Console.WriteLine("2) Display All Tickets"); Console.WriteLine("3) Search Tickets"); Console.WriteLine("Enter to quit"); choice = Console.ReadLine(); logger.Info("User choice: {Choice}", choice); if (choice == "1") { Console.WriteLine("1) Bug/Defect"); Console.WriteLine("2) Enhancement"); Console.WriteLine("3) Task"); string ticketTypeChoice = Console.ReadLine(); logger.Info("User choice: {Choice}", ticketTypeChoice); if (ticketTypeChoice == "1") { BugDefect bugDefect = new BugDefect(); Console.WriteLine("Enter Bug/Defect ticket summary"); bugDefect.summary = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket status"); bugDefect.status = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket priority"); bugDefect.priority = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket submitter"); bugDefect.submitter = Console.ReadLine(); Console.WriteLine("Enter Bug/Defect ticket asignee"); bugDefect.assigned = Console.ReadLine(); string input; do { Console.WriteLine("Enter Bug/Defect ticket watcher (or done to quit)"); input = Console.ReadLine(); if (input != "done" && input.Length > 0) { bugDefect.watching.Add(input); } }while (input != "done"); if (bugDefect.watching.Count == 0) { bugDefect.watching.Add("(no watchers listed)"); } Console.WriteLine("Enter Bug/Defect ticket severity"); bugDefect.severity = Console.ReadLine(); bugDefectTicketFile.AddBugDefect(bugDefect); } if (ticketTypeChoice == "2") { Enhancement enhancement = new Enhancement(); Console.WriteLine("Enter Enhancement ticket summary"); enhancement.summary = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket status"); enhancement.status = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket priority"); enhancement.priority = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket submitter"); enhancement.submitter = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket asignee"); enhancement.assigned = Console.ReadLine(); string input; do { Console.WriteLine("Enter Enhancement ticket watcher (or done to quit)"); input = Console.ReadLine(); if (input != "done" && input.Length > 0) { enhancement.watching.Add(input); } }while (input != "done"); if (enhancement.watching.Count == 0) { enhancement.watching.Add("(no watchers listed)"); } Console.WriteLine("Enter Enhancement ticket software"); enhancement.software = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket cost"); enhancement.cost = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket reason"); enhancement.reason = Console.ReadLine(); Console.WriteLine("Enter Enhancement ticket estimate"); enhancement.estimate = Console.ReadLine(); enhancementTicketFile.AddEnhancemant(enhancement); } if (ticketTypeChoice == "3") { Task task = new Task(); Console.WriteLine("Enter Task ticket summary"); task.summary = Console.ReadLine(); Console.WriteLine("Enter Task ticket status"); task.status = Console.ReadLine(); Console.WriteLine("Enter Task ticket priority"); task.priority = Console.ReadLine(); Console.WriteLine("Enter Task ticket submitter"); task.submitter = Console.ReadLine(); Console.WriteLine("Enter Task ticket asignee"); task.assigned = Console.ReadLine(); string input; do { Console.WriteLine("Enter Task ticket watcher (or done to quit)"); input = Console.ReadLine(); if (input != "done" && input.Length > 0) { task.watching.Add(input); } }while (input != "done"); if (task.watching.Count == 0) { task.watching.Add("(no watchers listed)"); } Console.WriteLine("Enter Task ticket project name"); task.projectName = Console.ReadLine(); Console.WriteLine("Enter Task ticket due date"); task.dueDate = Console.ReadLine(); taskTicketFile.AddTask(task); } } else if (choice == "2") { Console.WriteLine("1) Bug/Defect"); Console.WriteLine("2) Enhancement"); Console.WriteLine("3) Task"); string ticketTypeChoice = Console.ReadLine(); logger.Info("User choice: {Choice}", ticketTypeChoice); if (ticketTypeChoice == "1") { foreach (Ticket m in bugDefectTicketFile.BugDefectTickets) { Console.WriteLine(m.Display()); } } else if (ticketTypeChoice == "2") { foreach (Ticket m in enhancementTicketFile.EnhancementTickets) { Console.WriteLine(m.Display()); } } else if (ticketTypeChoice == "3") { foreach (Ticket m in taskTicketFile.TaskTickets) { Console.WriteLine(m.Display()); } } } else if (choice == "3") { Console.WriteLine("1) Search Status"); Console.WriteLine("2) Search Priority"); Console.WriteLine("3) Search Submitter"); string searchChoice = Console.ReadLine(); if (searchChoice == "1") { Console.WriteLine("Enter Ticket Status"); string statusInput = Console.ReadLine(); var statusBugDefectSearch = bugDefectTicketFile.BugDefectTickets.Where(m => m.status.ToLower().Contains($"{statusInput}")); var statusEnhancementSearch = enhancementTicketFile.EnhancementTickets.Where(m => m.status.ToLower().Contains($"{statusInput}")); var statusTaskSearch = taskTicketFile.TaskTickets.Where(m => m.status.ToLower().Contains($"{statusInput}")); Console.WriteLine($"There are {statusBugDefectSearch.Count()+statusTaskSearch.Count()+statusEnhancementSearch.Count()} {statusInput} status tickets:\n"); Console.WriteLine("Bug Defect Tickets:"); foreach (BugDefect m in statusBugDefectSearch) { Console.WriteLine($" {m.Display()}"); } Console.WriteLine("Enhancement Tickets:"); foreach (Enhancement m in statusEnhancementSearch) { Console.WriteLine($" {m.Display()}"); } Console.WriteLine("Task Tickets:"); foreach (Task m in statusTaskSearch) { Console.WriteLine($" {m.Display()}"); } } else if (searchChoice == "2") { Console.WriteLine("Enter Ticket Priority"); string priorityInput = Console.ReadLine(); var priorityBugDefectSearch = bugDefectTicketFile.BugDefectTickets.Where(m => m.priority.ToLower().Contains($"{priorityInput}")); var priorityEnhancementSearch = enhancementTicketFile.EnhancementTickets.Where(m => m.priority.ToLower().Contains($"{priorityInput}")); var priorityTaskSearch = taskTicketFile.TaskTickets.Where(m => m.priority.ToLower().Contains($"{priorityInput}")); Console.WriteLine($"There are {priorityBugDefectSearch.Count()+priorityEnhancementSearch.Count()+priorityTaskSearch.Count()} {priorityInput} tickets:\n"); Console.WriteLine("Bug Defect Tickets:"); foreach (BugDefect m in priorityBugDefectSearch) { Console.WriteLine($" {m.Display()}"); } Console.WriteLine("Enhancement Tickets:"); foreach (Enhancement m in priorityEnhancementSearch) { Console.WriteLine($" {m.Display()}"); } Console.WriteLine("Task Tickets:"); foreach (Task m in priorityTaskSearch) { Console.WriteLine($" {m.Display()}"); } } else if (searchChoice == "3") { Console.WriteLine("Enter Ticket Submitter"); string submitterInput = Console.ReadLine(); var submitterBugDefectSearch = bugDefectTicketFile.BugDefectTickets.Where(m => m.submitter.ToLower().Contains($"{submitterInput}")); var submitterEnhancementSearch = enhancementTicketFile.EnhancementTickets.Where(m => m.submitter.ToLower().Contains($"{submitterInput}")); var submitterTaskSearch = taskTicketFile.TaskTickets.Where(m => m.submitter.ToLower().Contains($"{submitterInput}")); Console.WriteLine($"There are {submitterBugDefectSearch.Count()+submitterEnhancementSearch.Count()+submitterTaskSearch.Count()} tickets submitted by {submitterInput}:\n"); Console.WriteLine("Bug Defect Tickets:"); foreach (BugDefect m in submitterBugDefectSearch) { Console.WriteLine($" {m.Display()}"); } Console.WriteLine("Enhancement Tickets:"); foreach (Enhancement m in submitterEnhancementSearch) { Console.WriteLine($" {m.Display()}"); } Console.WriteLine("Task Tickets:"); foreach (Task m in submitterTaskSearch) { Console.WriteLine($" {m.Display()}"); } } } } while (choice == "1" || choice == "2" || choice == "3"); logger.Info("Program ended"); }
//Constructor to reads from file public TicketFile(string file, string type) { Tickets = new List <Ticket>(); //switch for each type of ticket switch (type) { case "Defect": try{ StreamReader sr = new StreamReader(file); defectFile = file; while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] ticket = line.Split(","); Defect defect = new Defect(); defect.id = Int32.Parse(ticket[0]); defect.summary = ticket[1]; defect.status = ticket[2]; defect.priority = ticket[3]; defect.submitter = ticket[4]; defect.assigned = ticket[5]; defect.severity = ticket[7]; string[] watchers = ticket[6].Split("|"); foreach (string s in watchers) { defect.watching.Add(s); } Tickets.Add(defect); } sr.Close(); } catch (Exception e) { logger.Error(e.Message); } break; case "Enhancement": try{ StreamReader sr = new StreamReader(file); enhancementFile = file; while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] ticket = line.Split(","); Enhancement enhancement = new Enhancement(); enhancement.id = Int32.Parse(ticket[0]); enhancement.summary = ticket[1]; enhancement.status = ticket[2]; enhancement.priority = ticket[3]; enhancement.submitter = ticket[4]; enhancement.assigned = ticket[5]; enhancement.software = ticket[7]; enhancement.cost = Double.Parse(ticket[8]); enhancement.reason = ticket[9]; enhancement.estimate = Double.Parse(ticket[10]); string[] watchers = ticket[6].Split("|"); foreach (string s in watchers) { enhancement.watching.Add(s); } Tickets.Add(enhancement); } sr.Close(); } catch (Exception e) { logger.Error(e.Message); } break; case "Task": try{ StreamReader sr = new StreamReader(file); taskFile = file; while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] ticket = line.Split(","); Task task = new Task(); task.id = Int32.Parse(ticket[0]); task.summary = ticket[1]; task.status = ticket[2]; task.priority = ticket[3]; task.submitter = ticket[4]; task.assigned = ticket[5]; task.projectName = ticket[7]; DateTime dueDate; if (!DateTime.TryParse(ticket[8], out dueDate)) { Console.WriteLine("failed"); } ; task.dueDate = dueDate; string[] watchers = ticket[6].Split("|"); foreach (string s in watchers) { task.watching.Add(s); } Tickets.Add(task); } sr.Close(); } catch (Exception e) { logger.Error(e.Message); } break; } }