Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void CancelTicket()
- {
- int num = 0;
- do
- {
- try
- {
- Console.Write("Write the Flight Number : ");
- num = int.Parse(Console.ReadLine());
- if (num > 10 || num < 0)
- {
- Console.Write("Write the Flight Number : ");
- num = int.Parse(Console.ReadLine());
- }
- }
- catch (FormatException e)
- {
- Console.WriteLine(e.Message);
- Console.Write("Write the Flight Number : ");
- num = int.Parse(Console.ReadLine());
- }
- } while (num > 10 || num < 0);
- Console.Write("Write the seat number : ");
- string seat = Console.ReadLine().ToUpper();
- Console.Write("Are you sure you want to cancel this ticket?[yes/no] : ");
- string conf = Console.ReadLine().ToLower();
- if (conf =="yes")
- {
- string[,] seats = new string[6, 5];
- string[] ch = { "A", "B", "C", "D", "E", "F" };
- for (int i = 0; i < 6; i++)
- {
- for (int y = 0; y < 5; y++)
- {
- int n = y + 1;
- seats[i, y] = (ch[i] + n.ToString());
- }
- }
- TextReader tr = new StreamReader("Plane" + num + ".txt");
- string[] seatLines = new string[6];
- for (int i = 0; i < 6; i++)
- {
- seatLines[i] = tr.ReadLine();
- }
- for (int i = 0; i < 6; i++)
- {
- string[] temp = seatLines[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
- for (int y = 0; y < 5; y++)
- {
- if (seat == seats[i, y])
- seats[i, y] = seat;
- else
- seats[i, y] = temp[y];
- }
- }
- tr.Dispose();
- tr.Close();
- TextWriter tw = new StreamWriter("Plane" + num + ".txt");
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 6; i++)
- {
- for (int y = 0; y < 5; y++)
- {
- sb.Append(seats[i, y] + " ");
- }
- tw.WriteLine(sb.ToString());
- sb.Clear();
- }
- tw.Dispose();
- tw.Close();
- File.Delete(User.temp + "Ticket" + num + seat + ".txt");
- }
- else { return; }
- Console.Clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement