- •Аннотация.
- •Оглавление
- •Введение.
- •Цель курсовой работы.
- •Задание на выполнение курсовой работы.
- •Концептуальная модель данных.
- •Логическая структура данных.
- •Этапы реализации системы.
- •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
Файл Form4.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 static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace hikingtrips
{
public partial class Form4 : Form
{
private const string connectionString = "server=localhost;database=hikingtrips;uid=root;password=Fuckingpassword2;";
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string last_name = textBox1.Text;
string first_name = textBox2.Text;
string middle_name = textBox3.Text;
string phone_number = textBox4.Text;
string email = textBox5.Text;
string date_of_birth = textBox6.Text;
AddUserData(last_name, first_name, middle_name, phone_number, email, date_of_birth);
}
private void AddUserData(string last_name, string first_name, string middle_name, string phone_number, string email, string date_of_birth)
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string registerUserQuery = "INSERT INTO costumers (last_name, first_name, middle_name, phone_number, email, date_of_birth) VALUES (@last_name, @first_name, @middle_name, @phone_number, @email, @date_of_birth)";
using (MySqlCommand registerUserCommand = new MySqlCommand(registerUserQuery, connection))
{
registerUserCommand.Parameters.AddWithValue("@last_name", last_name);
registerUserCommand.Parameters.AddWithValue("@first_name", first_name);
registerUserCommand.Parameters.AddWithValue("@middle_name", middle_name);
registerUserCommand.Parameters.AddWithValue("@phone_number", phone_number);
registerUserCommand.Parameters.AddWithValue("@email", email);
registerUserCommand.Parameters.AddWithValue("@date_of_birth", date_of_birth);
registerUserCommand.ExecuteNonQuery();
MessageBox.Show("User data has been successfully added!", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
Form3 frm3 = new Form3();
frm3.Show();
this.Hide();
}
}
}
Файл Form3.Cs
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.VisualBasic.Logging;
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 static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace hikingtrips
{
public partial class Form3 : Form
{
private const string connectionString = "server=localhost;database=hikingtrips;uid=root;password=Fuckingpassword2;";
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string username = textBox1.Text;
string password = textBox2.Text;
int userId = GetLastInsertedUserId();
if (userId != -1)
{
RegistrateUser(username, password, userId);
}
else
{
MessageBox.Show("Error getting the user ID.", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private int GetLastInsertedUserId()
{
int lastUserId = -1;
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string query = "SELECT LAST_INSERT_ID()";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
lastUserId = Convert.ToInt32(command.ExecuteScalar());
}
}
return lastUserId;
}
private void RegistrateUser(string login, string password, int userId)
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string query = "INSERT INTO login_password (login, password, user) VALUES (@Login, @Password, @User)";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
command.Parameters.AddWithValue("@Login", login);
command.Parameters.AddWithValue("@Password", password);
command.Parameters.AddWithValue("@User", userId);
command.ExecuteNonQuery();
}
connection.Close();
}
MessageBox.Show("The username and password were added successfully.", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form1 frm3 = new Form1();
frm3.Show();
this.Close();
}
}
}
