Дипломная работа: Информационная система реализации билетов в кинотеатрах

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

}

/// <summary>

/// выбор кинотеатра афиши

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void CinemaComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

string selectedCinema = cinemaComboBox.SelectedItem.ToString();

int selectedId = 1;

foreach (var item in cinema)

{

if (selectedCinema.Equals(item.Name))

selectedId = item.CinemaId;

}

tickets = new List<Ticket>();

command = new MySqlCommand("Select tik.ticket_id, tik.cinema_id, tik.time_seans, fil.film_id, fil.name, fil.description, " +

"fil.cost, fil.length " +

"From tikets.ticket as tik INNER JOIN tikets.film as fil ON tik.film_id = fil.film_id " +

"Where tik.cinema_id = " + selectedId

, db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

foreach (var item in table.Select())

{

tickets.Add(new Ticket(

Convert.ToInt32(item.ItemArray[0]),

Convert.ToInt32(item.ItemArray[1]),

selectedCinema,

Convert.ToDateTime(item.ItemArray[2]),

Convert.ToInt32(item.ItemArray[3]),

item.ItemArray[4].ToString(),

item.ItemArray[5].ToString(),

"от " + item.ItemArray[6].ToString() + "р.",

Convert.ToInt32(item.ItemArray[7])));

}

filsGrid.ItemsSource = tickets;

}

}

}

LoginForm.xaml.cs

using MySql.Data.MySqlClient;

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;

namespace CourseWorkProject_OOP

{

/// <summary>

/// Логика взаимодействия для LoginForm.xaml

/// </summary>

public partial class LoginForm: Window

{

public int userId;

public LoginForm()

{

InitializeComponent();

}

public bool isLogin = true;

private void Button_Click_2(object sender, RoutedEventArgs e)

{

isLogin = true;

//получение данных от пользоывателя

String loginUser = loginField.Text;

String passUser = passField.Password;

DB db = new DB();

DataTable table = new DataTable();

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command = new MySqlCommand("SELECT * FROM users WHERE login = @uL AND password = @uP", db.GetConnection());

command.Parameters.Add(new MySqlParameter("@ul", loginUser));

command.Parameters.Add(new MySqlParameter("@uP", passUser));

adapter.SelectCommand = command;

adapter.Fill(table);

//проверка колличества найденных записей

if (table.Rows.Count > 0)

{

userId = Convert.ToInt32(table.Select()[0].ItemArray[0]);

User mainWindowUser = null;

Admin mainWindowAdmin = null;

if (table.Select()[0].ItemArray[5].ToString().Equals("user"))

{

mainWindowUser = new User(userId);

mainWindowUser.Show();

isLogin = false;

Close();

}

else

{

mainWindowAdmin = new Admin();

mainWindowAdmin.Show();

isLogin = false;

Close();

}

}

else

MessageBox.Show("Неверные данные");

}

private void Window_Closed(object sender, EventArgs e)

{

}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)

{

if (isLogin)

new MainWindow().Show();

}

}

}

BronTickets.xaml.cs

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;

using CourseWorkProject_OOP.Models.Entity;

using MySql.Data.MySqlClient;

namespace CourseWorkProject_OOP

{

/// <summary>

/// Логика взаимодействия для BronTickets.xaml

/// </summary>

public partial class BronTickets: Window

{

int ticketId;

int userId;

double tickPrice;

public BronTickets(int ticketId, int userId)

{

DB db = new DB();

db.openConnection();

InitializeComponent();

this.ticketId = ticketId;

this.userId = userId;

}

private void Button_Click(object sender, RoutedEventArgs e)

{

int selectedLine = comboRow.SelectedIndex;

DB db = new DB();

db.openConnection();

MySqlDataAdapter adapter = new MySqlDataAdapter();

command = new MySqlCommand("INSERT INTO tikets.sale(date_sale, ticket_id, user_id, price, line) VALUES (" +

"@date_sale,@ticket_id,@user_id,@price,@line);"

, db.GetConnection());

adapter.InsertCommand = command;

adapter.InsertCommand.Parameters.Add("@date_sale", MySqlDbType.DateTime, 4).Value = DateTime.Now;

adapter.InsertCommand.Parameters.Add("@ticket_id", MySqlDbType.Int32, 4).Value = ticketId;

adapter.InsertCommand.Parameters.Add("@user_id", MySqlDbType.Int32, 4).Value = userId;

adapter.InsertCommand.Parameters.Add("@price", MySqlDbType.Double, 4).Value = tickPrice;

adapter.InsertCommand.Parameters.Add("@line", MySqlDbType.Int32, 4).Value = selectedLine;

adapter.InsertCommand.ExecuteNonQuery();

Close();

}

DB db = new DB();

DataTable table;

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command;

/// <summary>

/// расчет цены билета исходя из сеанса и ряда

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

int selectedLine = comboRow.SelectedIndex;

command = new MySqlCommand("Select count(tikets.sale.sale_id) " +

"From tikets.sale " +

"Where tikets.sale.line = "+ selectedLine + " AND tikets.sale.ticket_id = " + ticketId

, db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

if (Convert.ToInt32(table.Select()[0].ItemArray[0]) == 10)

{

MessageBox.Show("Извините, места в этом ряду закончились, выберите другой ряд");

}

else

{

tickPrice = getPrice(selectedLine);

if (biletPrice!= null)

biletPrice.Content = "Цена билета: " + tickPrice + "р.";

}

}

/// <summary>

/// Метод расчета цены исходя из ряда, длинны сеанса и времени сеанса.

/// </summary>

/// <param name="line"></param>

/// <returns></returns>

private double getPrice(int line)

{

double price = 0;

List<LengthCategory> lengthCategory = new List<LengthCategory>();

command = new MySqlCommand("SELECT * FROM tikets.length_category", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

foreach (var item in table.Select())

{

lengthCategory.Add(new LengthCategory(Convert.ToInt32(item.ItemArray[1]), Convert.ToInt32(item.ItemArray[2]), Convert.ToDouble(item.ItemArray[4])));

}

List<PlaceCategory> placeCategory = new List<PlaceCategory>();

command = new MySqlCommand("SELECT * FROM tikets.place_category", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

foreach (var item in table.Select())

{

placeCategory.Add(new PlaceCategory(Convert.ToInt32(item.ItemArray[1]), Convert.ToInt32(item.ItemArray[2]), Convert.ToDouble(item.ItemArray[4])));

}

List<TimeCategory> timeCategory = new List<TimeCategory>();

command = new MySqlCommand("SELECT * FROM tikets.time_category", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

foreach (var item in table.Select())

{

timeCategory.Add(new TimeCategory(Convert.ToInt32(item.ItemArray[1]), Convert.ToInt32(item.ItemArray[2]), Convert.ToDouble(item.ItemArray[4])));

}

command = new MySqlCommand("Select tik.time_seans, fil.length, fil.cost " +

"From tikets.ticket as tik INNER JOIN tikets.film as fil ON tik.film_id = fil.film_id " +

"Where tik.ticket_id = " + ticketId, db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

if (table.Rows.Count == 0)

{

return price;

}

price = Convert.ToDouble(table.Select()[0].ItemArray[2]);

foreach (var item in lengthCategory)

{

price = item.calcPrice(price, Convert.ToInt32(table.Select()[0].ItemArray[1]));

}

foreach (var item in placeCategory)

{

price = item.calcPrice(price, line);

}

foreach (var item in timeCategory)

{

price = item.calcPrice(price, Convert.ToDateTime(table.Select()[0].ItemArray[0]));

}

return Math.Round(price, 2);

}

}

}

Admin.xaml.cs

using System;

using System.Collections.Generic;

using System.Data;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;

using System.Xml.Linq;

using CourseWorkProject_OOP.Models.Entity;

using Microsoft.Win32;

using MySql.Data.MySqlClient;

namespace CourseWorkProject_OOP

{

/// <summary>

/// Логика взаимодействия для Admin.xaml

/// </summary>

public partial class Admin: Window

{

public Admin()

{

InitializeComponent();

}

/// <summary>

/// добавление фильмов

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void AddFilm_Click(object sender, RoutedEventArgs e)

{

addFilmGrid.Visibility = Visibility.Visible;

addTiketGrid.Visibility = Visibility.Hidden;

otchetGrid.Visibility = Visibility.Hidden;

}

/// <summary>

/// отчеты

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void ShonOtchet_Click(object sender, RoutedEventArgs e)

{

addFilmGrid.Visibility = Visibility.Hidden;

addTiketGrid.Visibility = Visibility.Hidden;

otchetGrid.Visibility = Visibility.Visible;

}

/// <summary>

/// метод добавления фильма при нажатии на кнопку

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void addFilmBtn_Click(object sender, RoutedEventArgs e)

{

if (filmName.Text == "" || filmLength.Text == "" || filmDescription.Text == "" || filmCost.Text == "")

{

MessageBox.Show("Заполните все поля!");

return;

}

DB db = new DB();

db.openConnection();

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command = new MySqlCommand("INSERT INTO tikets.film(name, length, description, cost) VALUES (" +

"@name,@length,@description,@cost);"

, db.GetConnection());

adapter.InsertCommand = command;

adapter.InsertCommand.Parameters.Add("@name", MySqlDbType.String, 4).Value = filmName.Text.ToString();

adapter.InsertCommand.Parameters.Add("@length", MySqlDbType.Int32, 4).Value = Convert.ToInt32(filmLength.Text);

adapter.InsertCommand.Parameters.Add("@description", MySqlDbType.String, 4).Value = filmDescription.Text.ToString();

adapter.InsertCommand.Parameters.Add("@cost", MySqlDbType.Double, 4).Value = Convert.ToDouble(filmCost.Text);

adapter.InsertCommand.ExecuteNonQuery();

filmName.Text = "";

filmLength.Text = "";

filmDescription.Text = "";

filmCost.Text = "";

MessageBox.Show("Фильм успешно добавлен!");

}

List<Cinema> cinema = new List<Cinema>();

List<Film> films = new List<Film>();

/// <summary>

/// добавление билетов по кнопке

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void AddTikect_Click(object sender, RoutedEventArgs e)

{

addTiketGrid.Visibility = Visibility.Visible;

addFilmGrid.Visibility = Visibility.Hidden;

otchetGrid.Visibility = Visibility.Hidden;

ticketFilm.Items.Clear();

ticketCinema.Items.Clear();

DB db = new DB();

db.openConnection();

DataTable table;

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command;

cinema = new List<Cinema>();

films = new List<Film>();

command = new MySqlCommand("SELECT * FROM tikets.cinema", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

foreach (var item in table.Select())

{

cinema.Add(new Cinema(Convert.ToInt32(item.ItemArray[0]), item.ItemArray[1].ToString(), Convert.ToInt32(item.ItemArray[2]),

Convert.ToInt32(item.ItemArray[3]), Convert.ToInt32(item.ItemArray[4]), item.ItemArray[5].ToString()));

}

foreach (var item in cinema)

{

ticketCinema.Items.Add(item.Name);

}

command = new MySqlCommand("SELECT * FROM tikets.film", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

foreach (var item in table.Select())

{

films.Add(new Film(

Convert.ToInt32(item.ItemArray[0]),

item.ItemArray[1].ToString(),

item.ItemArray[2].ToString(),

item.ItemArray[3].ToString(),

Convert.ToInt32(item.ItemArray[4])));

}

foreach (var item in films)

{

ticketFilm.Items.Add(item.Name);

}

}

private void addTicketBtn_Click(object sender, RoutedEventArgs e)

{

int filmId = 0, cinemaId = 0;

foreach (var item in films)

{

if (item.Name.Equals(ticketFilm.SelectedItem))

filmId = item.FilmId;

}

foreach (var item in cinema)

{

if (item.Name.Equals(ticketCinema.SelectedItem))

cinemaId = item.CinemaId;

}

DateTime dateTime = Convert.ToDateTime(ticketDate.Text);

DB db = new DB();

db.openConnection();

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command = new MySqlCommand("INSERT INTO tikets.ticket(time_seans, cinema_id, film_id) VALUES (" +

"@time_seans,@cinema_id,@film_id);"

, db.GetConnection());

adapter.InsertCommand = command;

adapter.InsertCommand.Parameters.Add("@time_seans", MySqlDbType.DateTime, 4).Value = dateTime;

adapter.InsertCommand.Parameters.Add("@cinema_id", MySqlDbType.Int32, 4).Value = cinemaId;

adapter.InsertCommand.Parameters.Add("@film_id", MySqlDbType.Int32, 4).Value = filmId;

adapter.InsertCommand.ExecuteNonQuery();

ticketDate.Text = "";

MessageBox.Show("Билеты успешно добавлены!");

}

private void Button_Click(object sender, RoutedEventArgs e)

{

otchetText.Text = "";

DB db = new DB();

db.openConnection();

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command;

cinema = new List<Cinema>();

films = new List<Film>();

command = new MySqlCommand("Select films.name, count(films.film_id) " +

"From tikets.film as films " +

"INNER JOIN tikets.ticket as tickets ON films.film_id = tickets.film_id " +

"INNER JOIN tikets.sale as sales ON sales.ticket_id = tickets.ticket_id " +

"GROUP BY films.name; ", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

int count = 1;

foreach (var item in table.Select())

{

otchetText.Text += "Место номер " + count + ": " + item.ItemArray[0].ToString() + "\n";

count++;

}

}

private void Button_Click_1(object sender, RoutedEventArgs e)

{

otchetText.Text = "";

DB db = new DB();

db.openConnection();

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command;

cinema = new List<Cinema>();

films = new List<Film>();

command = new MySqlCommand("Select films.name, sum(sales.price) " +

"From tikets.film as films " +

"INNER JOIN tikets.ticket as tickets ON films.film_id = tickets.film_id " +

"INNER JOIN tikets.sale as sales ON sales.ticket_id = tickets.ticket_id " +

"GROUP BY films.name; ", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

int count = 1;

foreach (var item in table.Select())

{

otchetText.Text += item.ItemArray[0].ToString() + " собрал " + item.ItemArray[1].ToString() + "р. \n";

count++;

}

}

private void Button_Click_2(object sender, RoutedEventArgs e)

{

otchetText.Text = "";

DB db = new DB();

db.openConnection();

MySqlDataAdapter adapter = new MySqlDataAdapter();

MySqlCommand command;

cinema = new List<Cinema>();

films = new List<Film>();

command = new MySqlCommand("Select cinemas.name, count(sales.ticket_id) " +

"From tikets.cinema as cinemas " +

"INNER JOIN tikets.ticket as tickets ON cinemas.cinema_id = tickets.cinema_id " +

"INNER JOIN tikets.sale as sales ON sales.ticket_id = tickets.ticket_id " +

"GROUP BY cinemas.name;", db.GetConnection());

table = new DataTable();

adapter.SelectCommand = command;

adapter.Fill(table);

int count = 1;

foreach (var item in table.Select())

{

otchetText.Text += item.ItemArray[1].ToString() + " зрителей посетили " + item.ItemArray[0].ToString() + " \n";

count++;

}

}

DataTable table = null;

private void exit_Click(object sender, RoutedEventArgs e)

{

MainWindow mainWindow = new MainWindow();

mainWindow.Show();

Close();

}

private void Button_Click_3(object sender, RoutedEventArgs e)

{

if (table == null)

return;

XDocument xdoc = new XDocument();

XElement attributes = new XElement("attributes");

foreach (var item in table.Select())

{

XElement otchet = new XElement("otchet");

XAttribute otchetNameAttr = new XAttribute("name", item.ItemArray[0].ToString());

XElement otchetElement = new XElement("element", item.ItemArray[1].ToString());

otchet.Add(otchetNameAttr);

otchet.Add(otchetElement);

attributes.Add(otchet);

}

xdoc.Add(attributes);

SaveFileDialog saveFileDialog = new SaveFileDialog();

saveFileDialog.Filter = "Xml file (*.xml)|*.xml";

saveFileDialog.InitialDirectory = @"c:\";

if (saveFileDialog.ShowDialog() == true)

xdoc.Save(saveFileDialog.FileName);

}

}

}

Cinema.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace CourseWorkProject_OOP.Models.Entity

{

public class Cinema

{

public int CinemaId;

public string Name { get; set; }

public string Description { get; set; }

public int CountPlaceCategory1;

public int CountPlaceCategory2;

public int CountPlaceCategory3;

public Cinema(int cinema_id, string name, int place_category1, int place_category2, int place_category3, string description)

{

this.CinemaId = cinema_id;

this.Name = name;

this.CountPlaceCategory1 = place_category1;

this.CountPlaceCategory2 = place_category2;

this.CountPlaceCategory3 = place_category3;

this.Description = description;

}

}

}

Film.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace CourseWorkProject_OOP.Models.Entity

{

public class Film

{

public int FilmId;

public string Name { get; set; }

public string Description { get; set; }

public string Cost { get; set; }

public int Length { get; set; }

public Film(int filmId, string name, string description, string cost, int length)

Источник: https://otherreferats.allbest.ru/download/1203174/