Exemple #1
0
        public static bool AddScreening(Schedule schedule)
        {
            bool result = false;
            string formatForMySql = schedule.Date.ToString("yyyy-MM-dd HH:mm:ss");

            Query.queryToExecute = string.Format(
                        "INSERT INTO schedule (movie_id, time, price) VALUES (\"{0}\", \"{1}\", \"{2}\");",
                        schedule.MovieId, formatForMySql, schedule.Price);
            int queryResult = Query.queryExecutor.ExecuteNonQuery(Query.queryToExecute);

            if (queryResult == 1)
            {
                result = true;
            }
            else
            {
                MessageBox.Show("Error while adding screening!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return result;
        }
        private void btnAddNewScreening_Click(object sender, RoutedEventArgs e)
        {
            DateTime? date = this.txtNewDate.SelectedDate;
            int? hour = this.txtNewHour.Value;
            int? minute = this.txtNewMinute.Value;

            if (date == null)
            {
                MessageBox.Show("You must choose date!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (hour == null)
            {
                MessageBox.Show("You must choose hour!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (hour < 0 || 23 < hour)
            {
                MessageBox.Show("Hour must be between 0 and 23!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (minute == null)
            {
                MessageBox.Show("You must choose minute!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (minute < 0 || 59 < minute)
            {
                MessageBox.Show("Minute must be between 0 and 59!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            DateTime finalDateTime = date.Value.AddHours((double)hour);
            finalDateTime = finalDateTime.AddMinutes((double)minute);

            float price = 0;

            if (!float.TryParse(this.txtNewPrice.Text, out price))
            {
                MessageBox.Show("Price must be a number!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Schedule schedule = new Schedule(finalDateTime, price, int.Parse(this.txtId.Text));

            if (AdminQuery.AddScreening(schedule))
            {
                MessageBox.Show("You successfully added new screening to the movie.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                this.schedulePanel.Children.Clear();
                this.ClearInsertScheduleContainer();
                this.insertScheduleContainer.Visibility = Visibility.Hidden;
                this.btnBookPlace_Click(sender, e);
            }
        }
Exemple #3
0
        public static List<Schedule> GetMovieSchedules(int movie_id)
        {
            List<Schedule> schedules = new List<Schedule>();

            queryToExecute = string.Format("SELECT id, time, price FROM schedule WHERE movie_id = \"{0}\" ORDER BY time;", movie_id);

            MySqlDataReader reader = queryExecutor.ExecuteQuery(queryToExecute);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    var date = reader.GetMySqlDateTime(1);
                    DateTime datetime = DateTime.Parse(date.ToString());

                    Schedule schedule = new Schedule(
                       reader.GetInt32(0),
                       datetime,
                       reader.GetFloat(2)
                       );
                    schedules.Add(schedule);
                }
            }

            reader.Close();
            return schedules;
        }