- •Аннотация.
- •Оглавление
- •Введение.
- •Цель курсовой работы.
- •Задание на выполнение курсовой работы.
- •Концептуальная модель данных.
- •Логическая структура данных.
- •Этапы реализации системы.
- •6.1. Запросы.
- •6.2. Индексы.
- •6.3. Роли.
- •6.4. Процедуры.
- •6.5. Триггеры.
- •Руководство пользователя-клиента.
- •Руководство инструктора.
- •Руководство администратора.
- •Список литературы
- •Листинг программ. Интерфейс для пользователя hikingtrips. Файл Form2.Cs
- •Файл Form1.Cs
- •Файл Form4.Cs
- •Файл Form3.Cs
- •Файл Form5.Cs
- •Файл Form6.Cs
- •Листинг программ. Интерфейс для инструктора hikingtripsinstructors. Файл Form1.Cs
- •Файл Form2.Cs
Файл Form5.Cs
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using iTextSharp.text.pdf;
using iTextSharp.text;
using Microsoft.VisualBasic.Devices;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Reflection.PortableExecutable;
using MySqlX.XDevAPI;
using System.Collections;
using Microsoft.VisualBasic.ApplicationServices;
using Microsoft.VisualBasic.Logging;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace hikingtrips
{
public partial class Form5 : Form
{
private const string connectionString = "server=localhost;database=hikingtrips;uid=root;password=Fuckingpassword2;";
private DataGridViewCell clickedCell;
int selectedIndex1;
int selectedIndex2;
double days;
int x;
private static readonly Random rnd = new Random();
int cost = rnd.Next(500, 5000);
int instr = rnd.Next(1, 6);
int paidornot = 1;
string usertripid;
public Form5(int usr_ind)
{
InitializeComponent();
this.x = usr_ind;
}
private void button1_Click(object sender, EventArgs e)
{
LoadRoutes();
}
private void button3_Click(object sender, EventArgs e)
{
LoadEquipment();
}
private void button2_Click(object sender, EventArgs e)
{
DateTime dt = dateTimePicker1.Value;
DateTime new_dt = dt.Date;
ExportSelectedRouteToPdf(new_dt);
}
private void button4_Click(object sender, EventArgs e)
{
InfoAboutTrips();
}
private void button5_Click(object sender, EventArgs e)
{
InfoAboutEquipment();
}
private void LoadRoutes()
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string query = "SELECT * FROM routes";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataTable routesTable = new DataTable();
adapter.Fill(routesTable);
dataGridView1.DataSource = routesTable;
}
}
}
private void LoadEquipment()
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string query = "SELECT * FROM equipment";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataTable routesTable = new DataTable();
adapter.Fill(routesTable);
dataGridView2.DataSource = routesTable;
}
}
}
public void ExportSelectedRouteToPdf(DateTime new_dt)
{
Document document = new Document();
PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\Users\ACER\Desktop\receipt.pdf", System.IO.FileMode.Create));
string ind = x.ToString();
if (dataGridView1.SelectedRows.Count > 0)
{
if (dataGridView2.SelectedRows.Count > 0)
{
selectedIndex1 = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["route_id"].Value);
selectedIndex2 = Convert.ToInt32(dataGridView2.SelectedRows[0].Cells["equipment_id"].Value);
using (MySqlConnection connection2 = new MySqlConnection(connectionString))
{
string query2 = "SELECT last_name, first_name, middle_name FROM costumers WHERE user_id = @ind";
MySqlCommand command2 = new MySqlCommand(query2, connection2);
command2.Parameters.AddWithValue("@ind", ind);
connection2.Open();
MySqlDataReader reader2 = command2.ExecuteReader();
if (reader2.Read())
{
string f = reader2["last_name"].ToString();
string i = reader2["first_name"].ToString();
string o = reader2["middle_name"].ToString();
document.Open();
document.Add(new Paragraph("Route information"));
document.Add(new Paragraph($"Dear {f} " + $"{i} " + $"{o}, " + "we inform you that you have purchased a route and rented equipment for hiking. You will find information about your purchases in the receipt below."));
document.Add(new Paragraph(" "));
}
reader2.Close();
connection2.Close();
}
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
string query = "SELECT title, duration_in_hours, duration_in_days ,point_of_departure, price FROM routes WHERE route_id = @index";
MySqlCommand command = new MySqlCommand(query, connection);
command.Parameters.AddWithValue("@index", selectedIndex1);
connection.Open();
MySqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
string title = reader["title"].ToString();
string duration_in_hours = reader["duration_in_hours"].ToString();
string duration_in_days = reader["duration_in_days"].ToString();
string point_of_departure = reader["point_of_departure"].ToString();
string price = reader["price"].ToString();
document.Add(new Paragraph($"Information about a purchased hiking trip:"));
document.Add(new Paragraph($"Title: {title}"));
document.Add(new Paragraph($"Duration in hours: {duration_in_hours} hours"));
document.Add(new Paragraph($"Duration in days: {duration_in_days} days"));
document.Add(new Paragraph($"Point of departure: {point_of_departure}"));
document.Add(new Paragraph($"Price: {price}"));
document.Add(new Paragraph(" "));
days = Convert.ToDouble(duration_in_days);
}
reader.Close();
connection.Close();
}
using (MySqlConnection connection3 = new MySqlConnection(connectionString))
{
string query3 = "SELECT title, amount FROM equipment WHERE equipment_id = @index";
MySqlCommand command3 = new MySqlCommand(query3, connection3);
command3.Parameters.AddWithValue("@index", selectedIndex2);
connection3.Open();
MySqlDataReader reader3 = command3.ExecuteReader();
if (reader3.Read())
{
string title = reader3["title"].ToString();
document.Add(new Paragraph($"Information about a purchased equipment:"));
document.Add(new Paragraph($"Title: {title}"));
document.Add(new Paragraph(" "));
}
reader3.Close();
connection3.Close();
}
using (MySqlConnection connection6 = new MySqlConnection(connectionString))
{
string query6 = "SELECT * FROM instructors WHERE instructor_id = @index";
MySqlCommand command6 = new MySqlCommand(query6, connection6);
command6.Parameters.AddWithValue("@index", instr);
connection6.Open();
MySqlDataReader reader6 = command6.ExecuteReader();
if (reader6.Read())
{
string last_name = reader6["last_name"].ToString();
string first_name = reader6["first_name"].ToString();
string middle_name = reader6["middle_name"].ToString();
string phone_number = reader6["phone_number"].ToString();
string email = reader6["email"].ToString();
string seniority = reader6["seniority"].ToString();
document.Add(new Paragraph($"Information about your instructor:"));
document.Add(new Paragraph($"His name: {last_name} " + $"{first_name} " + $"{middle_name}"));
document.Add(new Paragraph($"His phone number: {phone_number}"));
document.Add(new Paragraph($"His e-mail: {email}"));
document.Add(new Paragraph($"His seniority: {seniority}"));
document.Add(new Paragraph(" "));
}
reader6.Close();
connection6.Close();
}
using (MySqlConnection connection4 = new MySqlConnection(connectionString))
{
connection4.Open();
string query4 = "INSERT INTO teams (trip, user, instructor, paid_or_not) VALUES (@trip, @user, @instructor, @paid_or_not)";
string query6 = "SELECT user_trip_id FROM teams WHERE user = @index";
using (MySqlCommand command = new MySqlCommand(query4, connection4))
{
command.Parameters.AddWithValue("@trip", selectedIndex1);
command.Parameters.AddWithValue("@user", ind);
command.Parameters.AddWithValue("@instructor", instr);
command.Parameters.AddWithValue("@paid_or_not", paidornot);
command.ExecuteNonQuery();
}
using (MySqlCommand command2 = new MySqlCommand(query6, connection4))
{
command2.Parameters.AddWithValue("@index", ind);
usertripid = Convert.ToInt32(command2.ExecuteScalar()).ToString();
}
connection4.Close();
}
using (MySqlConnection connection5 = new MySqlConnection(connectionString))
{
connection5.Open();
string query5 = "INSERT INTO rent (user_on_trip, equipment, price) VALUES (@user_on_trip, @equipment, @price)";
using (MySqlCommand command = new MySqlCommand(query5, connection5))
{
command.Parameters.AddWithValue("@user_on_trip", usertripid);
command.Parameters.AddWithValue("@equipment", selectedIndex2);
command.Parameters.AddWithValue("@price", cost);
command.ExecuteNonQuery();
}
connection5.Close();
}
}
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string query = "INSERT INTO trip (route, date_of_begining, date_of_ending) VALUES (@route, @date_of_begining, @date_of_ending)";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
DateTime endDate = new_dt.AddDays(days);
command.Parameters.AddWithValue("@route", selectedIndex1);
command.Parameters.AddWithValue("@date_of_begining", new_dt.ToString("yyyy-MM-dd"));
command.Parameters.AddWithValue("@date_of_ending", endDate.ToString("yyyy-MM-dd"));
command.ExecuteNonQuery();
}
}
using (MySqlConnection connection7 = new MySqlConnection(connectionString))
{
string query7 = "SELECT date_of_begining, date_of_ending FROM trip WHERE trip_id = (SELECT MAX(trip_id) FROM trip)";
MySqlCommand command7 = new MySqlCommand(query7, connection7);
connection7.Open();
MySqlDataReader reader7 = command7.ExecuteReader();
if (reader7.Read())
{
string date_of_begining = reader7["date_of_begining"].ToString();
string date_of_ending = reader7["date_of_ending"].ToString();
document.Add(new Paragraph($"Information about dates you have choosen for the trip:"));
document.Add(new Paragraph($"Date of begining: {date_of_begining}"));
document.Add(new Paragraph($"Date of ending: {date_of_ending}"));
document.Close();
}
reader7.Close();
connection7.Close();
MessageBox.Show("PDF document has been successfully saved to the desktop!", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
Form6 frm6 = new Form6(usertripid);
frm6.Show();
this.Hide();
}
private void InfoAboutTrips()
{
Document document = new Document();
PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\Users\ACER\Desktop\Trips.pdf", System.IO.FileMode.Create));
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
string query = "SELECT route_id, title, duration_in_hours, point_of_departure, price FROM routes";
MySqlCommand command = new MySqlCommand(query, connection);
MySqlDataAdapter da = new MySqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
connection.Open();
MySqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
document.Open();
foreach (DataRow row in dt.Rows)
{
foreach (var item in row.ItemArray)
{
document.Add(new Paragraph(item.ToString()));
}
document.Add(new Paragraph(Environment.NewLine));
}
document.Close();
}
reader.Close();
connection.Close();
}
}
private void InfoAboutEquipment()
{
Document document = new Document();
PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\Users\ACER\Desktop\Equipment.pdf", System.IO.FileMode.Create));
using (MySqlConnection connection3 = new MySqlConnection(connectionString))
{
string query3 = "SELECT equipment_id, title, amount FROM equipment";
MySqlCommand command3 = new MySqlCommand(query3, connection3);
MySqlDataAdapter da = new MySqlDataAdapter(command3);
DataTable dt = new DataTable();
da.Fill(dt);
connection3.Open();
MySqlDataReader reader3 = command3.ExecuteReader();
if (reader3.Read())
{
document.Open();
foreach (DataRow row in dt.Rows)
{
foreach (var item in row.ItemArray)
{
document.Add(new Paragraph(item.ToString()));
}
document.Add(new Paragraph(Environment.NewLine));
}
document.Close();
}
reader3.Close();
connection3.Close();
}
}
}
}
