示例#1
0
        /// <summary>
        /// delete a ticket with an name
        /// </summary>
        /// <param name="full">given full name</param>
        public void DeleteReservationWithName(string FullName)
        {
            try
            {
                AdminData AD = new AdminData();
                ShowData  SD = new ShowData();

                int seatX = 0;
                int seatY = 0;
                int hallID;
                int amount;

                Connection.Open();

                string stringToDelete = @"DELETE FROM ticket WHERE TicketID = @TicketID";
                string TicketInfo     = @"SELECT * FROM ticket";

                MySqlCommand   command       = new MySqlCommand(stringToDelete, Connection);
                MySqlParameter TicketIDParam = new MySqlParameter("@TicketID", MySqlDbType.String);
                MySqlCommand   oCmd          = new MySqlCommand(TicketInfo, Connection);

                using (MySqlDataReader getTicketInfo = oCmd.ExecuteReader())
                {
                    DataTable dataTable = new DataTable();

                    dataTable.Load(getTicketInfo);
                    string Owner;
                    string TicketID;
                    string MovieID;
                    string DateID;
                    int    dateid;
                    bool   isFound;
                    int    deletedAmount;
                    int    foundAmount;
                    double TotalPrice;
                    int    amountofticketscounted;
                    int    amountoftickets;

                    while (true)
                    {
                        isFound                = false;
                        deletedAmount          = 0;
                        foundAmount            = 0;
                        amountofticketscounted = 0;
                        amountoftickets        = dataTable.Rows.Count;

                        foreach (DataRow row in dataTable.Rows)
                        {
                            amountofticketscounted += 1;
                            Owner      = row["Owner"].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 (Owner == FullName)
                            {
                                // Ticket and contact information overview to check if you want to remove the right ticket.
                                Console.Clear();
                                SD.Overview(TicketID, MovieID, DateID);
                                isFound      = true;
                                foundAmount += 1;

                                Console.WriteLine("\nDo you want to remove this reservation?\n[1] Yes, remove reservation\n[2] No");
                                string CancelOrDelete = Console.ReadLine();

                                if (CancelOrDelete == "1")
                                {
                                    TicketIDParam.Value = TicketID;
                                    command.Parameters.Add(TicketIDParam);
                                    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);
                                    deletedAmount += 1;
                                }

                                else if (CancelOrDelete == "2")
                                {
                                    Console.Clear();
                                }
                            }
                        }

                        // check if all tickets were checked
                        if (amountoftickets == amountofticketscounted)
                        {
                            if (isFound)
                            {
                                if (deletedAmount > 0)
                                {
                                    Console.WriteLine(deletedAmount.ToString() + " reservation(s) out of " + foundAmount.ToString() + " removed. Press enter to continue");
                                }
                                else
                                {
                                    Console.WriteLine("\nReservation(s) not removed. Press enter to continue");
                                }
                            }

                            else
                            {
                                Console.Clear();
                                Console.WriteLine("\nThere were no results found with name: " + FullName + "\nPress enter to go back to the menu");
                            }
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }
                    }
                }
            }
            catch (MySqlException)
            {
                throw;
            }
            finally
            {
                Connection.Close();
            }
        }
示例#2
0
        /// <summary>
        /// Search funtion ticketsalesman. Search on name, search on ticketnumber and surch on movie name and date/time
        /// </summary>
        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 Email;
                string MovieID;
                string DateID;

                bool isFound;
                int  amountofticketscounted;
                int  amountoftickets;

                using (MySqlDataReader getTicketInfo = oCmd.ExecuteReader())
                {
                    DataTable dataTable = new DataTable();

                    dataTable.Load(getTicketInfo);
                    Console.Clear();
                    bool k = true;

                    // menu of the three search options
                    while (k)
                    {
                        isFound = false;
                        amountofticketscounted = 0;
                        amountoftickets        = dataTable.Rows.Count;
                        Console.WriteLine("\n[1] Search on name\n[2] Search on ticket number\n[3] Search using customer's emailaddress\n[4] Search on movie, time and date\n[exit] To go back to the menu");
                        string SearchOption = Console.ReadLine();
                        if (SearchOption.Length > 5)
                        {
                            ClearAndErrorMessage("Your input is to big");
                        }
                        else if (SearchOption == "1")
                        {
                            Console.Clear();
                            Console.WriteLine("\nPlease enter the customer full name or enter [exit] to exit");

                            string name2 = Console.ReadLine();
                            string name  = name2.ToString().ToLower();

                            while (true)
                            {
                                Console.Clear();
                                if (name2 == "exit")
                                {
                                    // using k to break out of the outer loop
                                    k = false;
                                    break;
                                }

                                // going through the data
                                foreach (DataRow row in dataTable.Rows)
                                {
                                    amountofticketscounted += 1;
                                    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
                                        Console.WriteLine("\nTicket [" + TicketID + "]");
                                        Overview(TicketID, MovieID, DateID);
                                    }
                                }

                                // check if all tickets were checked
                                if (amountoftickets == amountofticketscounted)
                                {
                                    if (isFound)
                                    {
                                        Console.WriteLine("\nPress enter to continue");
                                        k = false;
                                    }
                                    else
                                    {
                                        Console.WriteLine("\nThere were no results found with the name: " + name + "\nPress enter to go back to the menu");
                                    }
                                    Console.ReadLine();
                                    Console.Clear();
                                    break;
                                }
                            }
                        }

                        else if (SearchOption == "2")
                        {
                            Console.Clear();

                            while (true)
                            {
                                Console.WriteLine("\nPlease enter the ticketnumber or enter [exit] to go back to the menu");
                                string ticketnumber = Console.ReadLine();
                                if (ticketnumber == "exit")
                                {
                                    Console.Clear();
                                    // using k to break out of the outer loop
                                    k = false;
                                    break;
                                }

                                // going through the data
                                foreach (DataRow row in dataTable.Rows)
                                {
                                    amountofticketscounted += 1;
                                    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
                                        Console.Clear();
                                        Overview(TicketID, MovieID, DateID);
                                        Console.WriteLine("\nPress enter to continue");
                                        Console.ReadLine();
                                        break;
                                    }
                                }

                                // check if all tickets were checked
                                if (amountoftickets == amountofticketscounted)
                                {
                                    if (isFound)
                                    {
                                        Console.WriteLine("\nPress enter to continue");
                                        k = false;
                                    }
                                    else
                                    {
                                        Console.Clear();
                                        Console.WriteLine("\nThere were no results found with ticketnumber: " + ticketnumber + " Please enter to continue");
                                    }
                                    Console.ReadLine();
                                    Console.Clear();
                                    break;
                                }
                            }
                        }
                        else if (SearchOption == "3")
                        {
                            while (true)
                            {
                                Console.Clear();
                                Console.WriteLine("\nPlease enter the customer's emailaddress or enter [exit] to go back");
                                string emailaddress = Console.ReadLine();
                                Console.Clear();
                                if (emailaddress == "exit")
                                {
                                    // using k to break out of the outer loop
                                    k = false;
                                    break;
                                }

                                foreach (DataRow row in dataTable.Rows)
                                {
                                    amountofticketscounted += 1;
                                    Email    = row["Email"].ToString();
                                    TicketID = row["TicketID"].ToString();
                                    MovieID  = row["MovieID"].ToString();
                                    DateID   = row["DateID"].ToString();
                                    if (Email == emailaddress)
                                    {
                                        Connection.Close();
                                        // Ticket and contact information overview
                                        Console.WriteLine("\nTicket [" + TicketID + "]");
                                        Overview(TicketID, MovieID, DateID);
                                        isFound = true;
                                    }
                                }

                                // check if all tickets were checked
                                if (amountoftickets == amountofticketscounted)
                                {
                                    if (isFound)
                                    {
                                        Console.WriteLine("\nPress enter to continue");
                                        k = false;
                                    }
                                    else
                                    {
                                        Console.WriteLine("\nThere were no results found with email: " + emailaddress + "\nPress enter to go back to the menu");
                                    }
                                    Console.ReadLine();
                                    Console.Clear();
                                    break;
                                }
                            }
                        }

                        else if (SearchOption == "4")
                        {
                            Console.Clear();
                            isFound = false;
                            Connection.Close();
                            ShowMovies();
                            string movie = "";

                            Connection.Open();

                            using (MySqlDataReader getMovieInfo = oCmd2.ExecuteReader())
                            {
                                DataTable dataTable2 = new DataTable();
                                dataTable2.Load(getMovieInfo);

                                string MovieName;
                                isFound = true;

                                while (isFound)
                                {
                                    Console.WriteLine("\nPlease enter the movie");
                                    movie = Console.ReadLine();
                                    foreach (DataRow row in dataTable2.Rows)
                                    {
                                        MovieName = row["MovieID"].ToString();

                                        if (movie == MovieName)
                                        {
                                            isFound = false;
                                            break;
                                        }
                                    }
                                    if (isFound == true)
                                    {
                                        ErrorMessage("Your input was too big");
                                    }
                                }
                            }

                            Connection.Close();

                            Console.Clear();

                            Tuple <List <DateTime>, List <int>, List <int> > dates = Customer.showTime(movie);
                            string SelectedTime = Customer.selectTime(dates, movie);
                            if (SelectedTime == "exit")
                            {
                                break;
                            }

                            int movieid = Convert.ToInt32(movie);

                            AdminData AD = new AdminData();

                            Tuple <List <DateTime>, List <int>, List <int> > times = AD.GetTime(Convert.ToInt32(movie));

                            int GetDateID = times.Item2[0];

                            Connection.Open();

                            MySqlDataReader getDateInfo = oCmd3.ExecuteReader();
                            DataTable       dataTable3  = new DataTable();

                            dataTable3.Load(getDateInfo);

                            Console.Clear();
                            while (true)
                            {
                                // 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"]) && GetDateID == Convert.ToInt32(row["DateID"]))
                                    {
                                        isFound = true;
                                        Connection.Close();

                                        // going to the overview with all the details
                                        Overview(TicketID, MovieID, DateID);

                                        // using k to break out of the outer loop
                                        k = false;
                                    }
                                }

                                if (isFound)
                                {
                                    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;
                                }

                                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;
                        }
                        else
                        {
                            SD.ClearAndErrorMessage("Your input is too big");
                        }
                    }
                }
            }

            catch (MySqlException ex)
            {
                ErrorMessage("Your input was too big");
            }
            finally
            {
                Connection.Close();
            }
        }