// Search funtion ticketsalesman. Search on name, search on ticketnumber and surch on movie name and date/time public void DisplayTickets() { ShowData SD = new ShowData(); Console.OutputEncoding = Encoding.UTF8; try { Connection.Open(); string TicketInfo = @"SELECT * FROM ticket"; string MovieInfo = @"SELECT * FROM movie"; string DateInfo = @"SELECT * FROM date"; MySqlCommand oCmd = new MySqlCommand(TicketInfo, Connection); MySqlCommand oCmd2 = new MySqlCommand(MovieInfo, Connection); MySqlCommand oCmd3 = new MySqlCommand(DateInfo, Connection); // creating the strings string TicketID; string TicketCode; string Owner; string MovieID; string DateID; string MovieName; using (MySqlDataReader getTicketInfo = oCmd.ExecuteReader()) { DataTable dataTable = new DataTable(); dataTable.Load(getTicketInfo); Console.Clear(); bool k = true; // menu of the three search options Console.WriteLine("\n[1] Search on name\n[2] Search on ticket number\n[3] Search on movie, time and date\n[exit] To go back to the menu"); string SearchOption = Console.ReadLine(); while (k) { if (SearchOption == "1") { Console.Clear(); Console.WriteLine("\nPlease enter the customer full name"); string name2 = Console.ReadLine(); string name = name2.ToString().ToLower(); bool isFound = false; while (true) { // going through the data foreach (DataRow row in dataTable.Rows) { Owner = row["Owner"].ToString(); TicketCode = row["TicketCode"].ToString(); TicketID = row["TicketID"].ToString(); MovieID = row["MovieID"].ToString(); DateID = row["DateID"].ToString(); // check if there is a match if (Owner == name) { isFound = true; Connection.Close(); // going to the overview with all the details Overview(TicketID, MovieID, DateID); Console.WriteLine("\nPress enter to go back to the menu"); Console.ReadLine(); // using k to break out of the outer loop k = false; break; } } if (isFound) { // using k to break out of the outer loop k = false; break; } else { ErrorMessage("\nThe name you entered was not found. Please enter again or type [exit] to exit"); name = Console.ReadLine(); if (name == "exit") { // using k to break out of the outer loop k = false; break; } } } break; } else if (SearchOption == "2") { bool isFound = false; string line; Console.Clear(); while (true) { Console.WriteLine("\nPlease enter the ticketnumber"); string ticketnumber = Console.ReadLine(); // going through the data foreach (DataRow row in dataTable.Rows) { Owner = row["Owner"].ToString(); TicketCode = row["TicketCode"].ToString(); TicketID = row["TicketID"].ToString(); MovieID = row["MovieID"].ToString(); DateID = row["DateID"].ToString(); // check if there is a match if (TicketCode == ticketnumber) { isFound = true; Connection.Close(); // going to the overview with all the details Overview(TicketID, MovieID, DateID); Console.WriteLine("\nPress enter to go back to the menu"); Console.ReadLine(); break; } } if (isFound) { Console.Clear(); // using k to break out of the outer loop k = false; break; } else if (ticketnumber == "exit") { Console.Clear(); // using k to break out of the outer loop k = false; break; } else { Console.Clear(); Console.WriteLine("\nThere were no results found with ticketnumber: " + ticketnumber + " Please enter again or type [exit] to exit"); line = Console.ReadLine(); if (line == "exit") { Console.Clear(); // using k to break out of the outer loop k = false; break; } } } } else if (SearchOption == "3") { Console.Clear(); bool isFound = false; Console.WriteLine("\nPlease enter the movie"); string movie = Console.ReadLine(); Console.WriteLine("\nPlease enter the time (e.g. 12:00)"); string time = Console.ReadLine(); Console.WriteLine("\nPlease enter the date ( e.g. 12/04/2020)"); string date = Console.ReadLine(); string DT = date + " " + time; MySqlDataReader getMovieInfo = oCmd2.ExecuteReader(); DataTable dataTable2 = new DataTable(); dataTable2.Load(getMovieInfo); MySqlDataReader getDateInfo = oCmd3.ExecuteReader(); DataTable dataTable3 = new DataTable(); dataTable3.Load(getDateInfo); int movieID = 0; int dateID = 0; while (true) { // going through all movie data foreach (DataRow row in dataTable2.Rows) { MovieName = row["MovieName"].ToString(); if (movie == MovieName) { movieID = Convert.ToInt32(row["MovieID"]); break; } } // going through all the date data foreach (DataRow row in dataTable3.Rows) { string datetime = Convert.ToDateTime(row["DateTime"]).ToString("dd/MM/yyyy HH:mm"); if (DT == datetime) { dateID = Convert.ToInt32(row["DateID"]); break; } } // going through ticket data foreach (DataRow row in dataTable.Rows) { TicketID = row["TicketID"].ToString(); MovieID = row["MovieID"].ToString(); DateID = row["DateID"].ToString(); // going through all the ticket data to see if there is a match between all the given information if (movieID == Convert.ToInt32(row["MovieID"]) && dateID == Convert.ToInt32(row["DateID"])) { isFound = true; Connection.Close(); // going to the overview with all the details Overview(TicketID, MovieID, DateID); Console.WriteLine("\nPress enter to go back to the menu"); string exit = Console.ReadLine(); // using k to break out of the outer loop k = false; break; } } if (isFound) { // using k to break out of the outer loop k = false; break; } else { Console.Clear(); Console.WriteLine("\nThere were no results found. Press enter to go back to the menu"); string exit = Console.ReadLine(); Console.Clear(); // using k to break out of the outer loop k = false; break; } } } else if (SearchOption == "exit") { Console.Clear(); break; } } } } catch (MySqlException ex) { throw; } finally { Connection.Close(); } }
public void DeleteReservation(string ticketcode) { try { AdminData AD = new AdminData(); int seatX = 0; int seatY = 0; int hallID; int amount; Connection.Open(); string stringToDelete = @"DELETE FROM ticket WHERE TicketCode = @TicketCode"; string TicketInfo = @"SELECT * FROM ticket"; MySqlCommand command = new MySqlCommand(stringToDelete, Connection); MySqlParameter TicketCodeParam = new MySqlParameter("@TicketCode", MySqlDbType.String); MySqlCommand oCmd = new MySqlCommand(TicketInfo, Connection); using (MySqlDataReader getTicketInfo = oCmd.ExecuteReader()) { DataTable dataTable = new DataTable(); dataTable.Load(getTicketInfo); string TicketCode; string TicketID; string MovieID; string DateID; int dateid; bool isFound = false; double TotalPrice; while (true) { foreach (DataRow row in dataTable.Rows) { TicketCode = row["TicketCode"].ToString(); TicketID = row["TicketID"].ToString(); MovieID = row["MovieID"].ToString(); DateID = row["DateID"].ToString(); hallID = Convert.ToInt32(row["HallID"]); amount = Convert.ToInt32(row["amount"]); seatX = Convert.ToInt32(row["seatX"]); seatY = Convert.ToInt32(row["seatY"]); dateid = Convert.ToInt32(row["DateID"]); TotalPrice = Convert.ToDouble(row["TotalPrice"]); double pricedelete = -TotalPrice; if (TicketCode == ticketcode) { ShowData DeleteTicket = new ShowData(); // Ticket and contact information overview to check if you want to remove the right ticket. DeleteTicket.Overview(TicketID, MovieID, DateID); isFound = true; Console.WriteLine("\nDo you really want to remove this reservation?\n[1] Remove reservation\n[2] Cancel"); string CancelOrDelete = Console.ReadLine(); if (CancelOrDelete == "1") { TicketCodeParam.Value = ticketcode; command.Parameters.Add(TicketCodeParam); command.Prepare(); command.ExecuteNonQuery(); DateTime MonthYear = AD.GetDate(dateid); Connection.Close(); var MonthMM = Convert.ToDateTime(MonthYear).ToString("MM"); int Month = Convert.ToInt32(MonthMM); var Yearyyyy = Convert.ToDateTime(MonthYear).ToString("yyyy"); int Year = Convert.ToInt32(Yearyyyy); AD.UpdateRevenueYear(Year, pricedelete); AD.UpdateRevenueMonth(Month, Year, pricedelete); // This set the seats back to available AD.switchAvail((seatX - 1), (seatY - 1), hallID, amount, true); Console.WriteLine("\nReservation removed. Press enter to go back to the menu"); Console.ReadLine(); Console.Clear(); break; } else if (CancelOrDelete == "2") { Console.Clear(); break; } break; } } if (isFound) { Console.Clear(); break; } else { Console.Clear(); Console.WriteLine("\nThere were no results found with ticketnumber: " + ticketcode + "\nPress enter to go back to the menu"); Console.ReadLine(); Console.Clear(); break; } } } } catch (MySqlException) { throw; } finally { Connection.Close(); } }