Beispiel #1
0
        public void addCinemaHall(String name, String capacity, String location)
        {
            if (name == "")
            {
                throw new Exception("name can't be empty ");
            }
            if (capacity == "")
            {
                throw new Exception("capacity can't be empty ");
            }
            if (location == "")
            {
                throw new Exception("location can't be empty ");
            }

            int cap;

            if (!int.TryParse(capacity, out cap))
            {
                throw new Exception("capacity must be a number");
            }



            Models.CinemaHall cinemaHall = new Models.CinemaHall(name, cap, location);
            try
            {
                dbC.addCinemaHall(cinemaHall);
            }
            catch (Exception err)
            {
                throw err;
            }
        }
        public void updateCinemaHall(Models.CinemaHall cinemaHall)
        {
            String          query = "UPDATE `cinema_hall` SET `name` = '" + cinemaHall.name + "', `capacity` = '" + cinemaHall.capacity + " ', `location` = '" + cinemaHall.location + "' WHERE `cinema_hall`.`id` = " + cinemaHall.id + "";
            MySqlConnection databaseConnection = new MySqlConnection(MysqlConnetionString);
            MySqlCommand    comandDatabase     = new MySqlCommand(query, databaseConnection);

            comandDatabase.CommandTimeout = 60;
            try
            {
                databaseConnection.Open();
                MySqlDataReader myReader = comandDatabase.ExecuteReader();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void addCinemaHall(Models.CinemaHall cinemaHall)
        {
            String query = "INSERT INTO `cinema_hall` (`id`, `name`, `capacity`, `location`) VALUES (NULL, '" + cinemaHall.name + "', '" + cinemaHall.capacity + "', '" + cinemaHall.location + "')";

            MySqlConnection databaseConnection = new MySqlConnection(MysqlConnetionString);
            MySqlCommand    comandDatabase     = new MySqlCommand(query, databaseConnection);

            comandDatabase.CommandTimeout = 60;
            try
            {
                databaseConnection.Open();
                MySqlDataReader myReader = comandDatabase.ExecuteReader();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public Models.CinemaHall findCinemaHall(int id)
        {
            String query = "SELECT * FROM `cinema_hall` WHERE id = " + id;

            MySqlConnection databaseConnection = new MySqlConnection(MysqlConnetionString);
            MySqlCommand    comandDatabase     = new MySqlCommand(query, databaseConnection);

            comandDatabase.CommandTimeout = 60;
            try
            {
                databaseConnection.Open();
                MySqlDataReader myReader = comandDatabase.ExecuteReader();
                if (myReader.HasRows)
                {
                    if (myReader.Read())
                    {
                        Console.WriteLine("found");

                        Models.CinemaHall cinemaHall = new Models.CinemaHall(int.Parse(myReader[0].ToString()), myReader[1].ToString(), int.Parse(myReader[2].ToString()), myReader[3].ToString());

                        cinemaHall.showCinemaHall();
                        return(cinemaHall);
                    }

                    throw new Exception("Reader can't read");
                }
                else
                {
                    throw new Exception("CinemaHall not found ");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        //cinema hall
        //cinema hall
        //cinema hall
        //cinema hall
        public List <Models.CinemaHall> getCinemaHall()
        {
            List <Models.CinemaHall> cinemaHalls = new List <Models.CinemaHall>();

            String query = "SELECT * FROM cinema_hall";

            MySqlConnection databaseConnection = new MySqlConnection(MysqlConnetionString);
            MySqlCommand    comandDatabase     = new MySqlCommand(query, databaseConnection);

            comandDatabase.CommandTimeout = 60;
            try
            {
                databaseConnection.Open();
                MySqlDataReader myReader = comandDatabase.ExecuteReader();
                if (myReader.HasRows)
                {
                    while (myReader.Read())
                    {
                        Models.CinemaHall cinemaHall = new Models.CinemaHall(int.Parse(myReader[0].ToString()), myReader[1].ToString(), int.Parse(myReader[2].ToString()), myReader[3].ToString());

                        // cinemaHall.showCinemaHall();
                        cinemaHalls.Add(cinemaHall);
                    }

                    return(cinemaHalls);
                }
                else
                {
                    return(cinemaHalls);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }