Advertisement
Hazem3529

Untitled

Dec 20th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1.  public void CancelTicket()
  2.         {
  3.            
  4.             int num = 0;
  5.             do
  6.             {
  7.                 try
  8.                 {
  9.                     Console.Write("Write the Flight Number : ");
  10.                     num = int.Parse(Console.ReadLine());
  11.                     if (num > 10 || num < 0)
  12.                     {
  13.                         Console.Write("Write the Flight Number : ");
  14.                         num = int.Parse(Console.ReadLine());
  15.                     }
  16.  
  17.                 }
  18.                 catch (FormatException e)
  19.                 {
  20.                     Console.WriteLine(e.Message);
  21.                     Console.Write("Write the Flight Number : ");
  22.                     num = int.Parse(Console.ReadLine());
  23.                 }
  24.             } while (num > 10 || num < 0);      
  25.            
  26.            
  27.             Console.Write("Write the seat number : ");
  28.             string seat = Console.ReadLine().ToUpper();
  29.             Console.Write("Are you sure you want to cancel this ticket?[yes/no] : ");
  30.            
  31.             string conf = Console.ReadLine().ToLower();
  32.             if (conf =="yes")
  33.             {
  34.                 string[,] seats = new string[6, 5];
  35.                 string[] ch = { "A", "B", "C", "D", "E", "F" };
  36.                 for (int i = 0; i < 6; i++)
  37.                 {
  38.                     for (int y = 0; y < 5; y++)
  39.                     {
  40.                         int n = y + 1;
  41.                         seats[i, y] = (ch[i] + n.ToString());
  42.                     }
  43.                 }
  44.                 TextReader tr = new StreamReader("Plane" + num + ".txt");
  45.                 string[] seatLines = new string[6];
  46.                 for (int i = 0; i < 6; i++)
  47.                 {
  48.                     seatLines[i] = tr.ReadLine();
  49.                 }
  50.                 for (int i = 0; i < 6; i++)
  51.                 {
  52.                     string[] temp = seatLines[i].Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
  53.                     for (int y = 0; y < 5; y++)
  54.                     {
  55.                         if (seat == seats[i, y])
  56.                             seats[i, y] = seat;
  57.                         else
  58.                             seats[i, y] = temp[y];
  59.                     }
  60.                 }
  61.                 tr.Dispose();
  62.                 tr.Close();
  63.                 TextWriter tw = new StreamWriter("Plane" + num + ".txt");
  64.                 StringBuilder sb = new StringBuilder();
  65.                 for (int i = 0; i < 6; i++)
  66.                 {
  67.                     for (int y = 0; y < 5; y++)
  68.                     {
  69.                         sb.Append(seats[i, y] + " ");
  70.                     }
  71.                     tw.WriteLine(sb.ToString());
  72.                     sb.Clear();
  73.                 }
  74.  
  75.                 tw.Dispose();
  76.                 tw.Close();
  77.                 File.Delete(User.temp + "Ticket" + num + seat + ".txt");
  78.             }
  79.             else { return; }
  80.             Console.Clear();
  81.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement