commit 1338cb49e59ca47dd98fb453fb9ce077c7b50e9a Author: Your Name Date: Thu Mar 5 16:46:07 2026 +0400 first commit diff --git a/.vs/fsh/FileContentIndex/490348a8-48a1-4a4b-8c7a-d42fd8201f38.vsidx b/.vs/fsh/FileContentIndex/490348a8-48a1-4a4b-8c7a-d42fd8201f38.vsidx new file mode 100644 index 0000000..bb069e7 Binary files /dev/null and b/.vs/fsh/FileContentIndex/490348a8-48a1-4a4b-8c7a-d42fd8201f38.vsidx differ diff --git a/.vs/fsh/FileContentIndex/6287aa9e-d989-4b22-9df7-e8ec4704aa81.vsidx b/.vs/fsh/FileContentIndex/6287aa9e-d989-4b22-9df7-e8ec4704aa81.vsidx new file mode 100644 index 0000000..a1ba00e Binary files /dev/null and b/.vs/fsh/FileContentIndex/6287aa9e-d989-4b22-9df7-e8ec4704aa81.vsidx differ diff --git a/.vs/fsh/FileContentIndex/7faedbb1-55f3-406c-be20-8c399f268000.vsidx b/.vs/fsh/FileContentIndex/7faedbb1-55f3-406c-be20-8c399f268000.vsidx new file mode 100644 index 0000000..51fa7c7 Binary files /dev/null and b/.vs/fsh/FileContentIndex/7faedbb1-55f3-406c-be20-8c399f268000.vsidx differ diff --git a/.vs/fsh/FileContentIndex/de088768-8c97-4c78-87cc-79083657b8e8.vsidx b/.vs/fsh/FileContentIndex/de088768-8c97-4c78-87cc-79083657b8e8.vsidx new file mode 100644 index 0000000..615a247 Binary files /dev/null and b/.vs/fsh/FileContentIndex/de088768-8c97-4c78-87cc-79083657b8e8.vsidx differ diff --git a/.vs/fsh/FileContentIndex/e7daaea1-bb5a-4264-8e61-ff3ee1f17c8d.vsidx b/.vs/fsh/FileContentIndex/e7daaea1-bb5a-4264-8e61-ff3ee1f17c8d.vsidx new file mode 100644 index 0000000..4ef63cb Binary files /dev/null and b/.vs/fsh/FileContentIndex/e7daaea1-bb5a-4264-8e61-ff3ee1f17c8d.vsidx differ diff --git a/.vs/fsh/v17/.suo b/.vs/fsh/v17/.suo new file mode 100644 index 0000000..c6fc01e Binary files /dev/null and b/.vs/fsh/v17/.suo differ diff --git a/.vs/fsh/v17/TestStore/0/000.testlog b/.vs/fsh/v17/TestStore/0/000.testlog new file mode 100644 index 0000000..7ecad8e Binary files /dev/null and b/.vs/fsh/v17/TestStore/0/000.testlog differ diff --git a/.vs/fsh/v17/TestStore/0/testlog.manifest b/.vs/fsh/v17/TestStore/0/testlog.manifest new file mode 100644 index 0000000..e92ede2 Binary files /dev/null and b/.vs/fsh/v17/TestStore/0/testlog.manifest differ diff --git a/AddBooksForm.Designer.cs b/AddBooksForm.Designer.cs new file mode 100644 index 0000000..fa268c3 --- /dev/null +++ b/AddBooksForm.Designer.cs @@ -0,0 +1,141 @@ +namespace fsh +{ + partial class AddBooksForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.cbAuthor = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(196, 42); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(100, 20); + this.textBox1.TabIndex = 0; + this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(196, 161); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(100, 20); + this.textBox2.TabIndex = 1; + // + // cbAuthor + // + this.cbAuthor.FormattingEnabled = true; + this.cbAuthor.Location = new System.Drawing.Point(196, 111); + this.cbAuthor.Name = "cbAuthor"; + this.cbAuthor.Size = new System.Drawing.Size(121, 21); + this.cbAuthor.TabIndex = 2; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(115, 49); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(55, 13); + this.label1.TabIndex = 3; + this.label1.Text = "название"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(115, 161); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(31, 13); + this.label2.TabIndex = 4; + this.label2.Text = "цена"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(115, 114); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(36, 13); + this.label3.TabIndex = 5; + this.label3.Text = "автор"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(160, 249); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 6; + this.button1.Text = "сохранить"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(279, 249); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 7; + this.button2.Text = "отмена"; + this.button2.UseVisualStyleBackColor = true; + // + // AddBooksForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.cbAuthor); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.Name = "AddBooksForm"; + this.Text = "AddBooksForm"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.ComboBox cbAuthor; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + } +} \ No newline at end of file diff --git a/AddBooksForm.cs b/AddBooksForm.cs new file mode 100644 index 0000000..a203be4 --- /dev/null +++ b/AddBooksForm.cs @@ -0,0 +1,117 @@ +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 System.Xml.Linq; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace fsh +{ + public partial class AddBooksForm : Form + { + string connStr = "Server=cfif31.ru;Port=3306;Database=ISPr25-21_KorotinDV_37;Uid=ISPr25-21_KorotinDV;Pwd=ISPr25-21_KorotinDV; SslMode=none; "; + + public AddBooksForm() + { + InitializeComponent(); + LoadAuthors(); // Загружаем авторов при открытии формы + } + + // Метод загрузки авторов в ComboBox + private void LoadAuthors() + { + try + { + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + string sql = "SELECT idavtori, name_A FROM avtori ORDER BY name_A"; + + MySqlCommand cmd = new MySqlCommand(sql, conn); + MySqlDataAdapter da = new MySqlDataAdapter(cmd); + DataTable dt = new DataTable(); + da.Fill(dt); + + // Настраиваем ComboBox + cbAuthor.DataSource = dt; + cbAuthor.DisplayMember = "name_A"; + cbAuthor.ValueMember = "idavtori"; + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка загрузки авторов: " + ex.Message, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void button1_Click(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(textBox1.Text)) + { + MessageBox.Show("Введите название книги", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); + textBox1.Focus(); + return; + } + + if (cbAuthor.SelectedValue == null) + { + MessageBox.Show("Выберите автора из списка", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + if (!decimal.TryParse(textBox2.Text.Replace(",", "."), out decimal price) || price < 0) + { + MessageBox.Show("Введите корректную цену (число >= 0)", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); + textBox2.Focus(); + return; + } + + // 2. Подготовка данных + string bookName = textBox1.Text.Trim(); + int authorId = Convert.ToInt32(cbAuthor.SelectedValue); + + // 3. INSERT в базу данных + try + { + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + string sql = "INSERT INTO books (name, avtor, price) VALUES (@name, @avtor, @price)"; + MySqlCommand cmd = new MySqlCommand(sql, conn); + + cmd.Parameters.AddWithValue("@name", bookName); + cmd.Parameters.AddWithValue("@avtor", authorId); + cmd.Parameters.AddWithValue("@price", price); + + int rows = cmd.ExecuteNonQuery(); + + if (rows > 0) + { + MessageBox.Show("Книга успешно добавлена!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + this.DialogResult = DialogResult.OK; + this.Close(); + } + else + { + MessageBox.Show("Не удалось добавить книгу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка при добавлении: " + ex.Message, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + + } + } +} diff --git a/AddBooksForm.resx b/AddBooksForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AddBooksForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/App.config b/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/EditBooksForm.Designer.cs b/EditBooksForm.Designer.cs new file mode 100644 index 0000000..0782163 --- /dev/null +++ b/EditBooksForm.Designer.cs @@ -0,0 +1,93 @@ +namespace fsh +{ + partial class EditBooksForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tbName = new System.Windows.Forms.TextBox(); + this.tbPrice = new System.Windows.Forms.TextBox(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // tbName + // + this.tbName.Location = new System.Drawing.Point(226, 56); + this.tbName.Name = "tbName"; + this.tbName.Size = new System.Drawing.Size(100, 20); + this.tbName.TabIndex = 0; + this.tbName.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + // + // tbPrice + // + this.tbPrice.Location = new System.Drawing.Point(226, 164); + this.tbPrice.Name = "tbPrice"; + this.tbPrice.Size = new System.Drawing.Size(100, 20); + this.tbPrice.TabIndex = 1; + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(226, 110); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(121, 21); + this.comboBox1.TabIndex = 2; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(101, 246); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 3; + this.button1.Text = "Сохранить"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // EditBooksForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button1); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.tbPrice); + this.Controls.Add(this.tbName); + this.Name = "EditBooksForm"; + this.Text = "EditBooksForm"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox tbName; + private System.Windows.Forms.TextBox tbPrice; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/EditBooksForm.cs b/EditBooksForm.cs new file mode 100644 index 0000000..3175da3 --- /dev/null +++ b/EditBooksForm.cs @@ -0,0 +1,146 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml.Linq; + +namespace fsh +{ + public partial class EditBooksForm : Form + { + private int bookId; + string connStr = "Server=cfif31.ru;Port=3306;Database=ISPr25-21_KorotinDV_37;Uid=ISPr25-21_KorotinDV;Pwd=ISPr25-21_KorotinDV; SslMode=none"; + + public EditBooksForm(int id) + { + InitializeComponent(); + bookId = id; + LoadBookData(); + LoadAuthors(); + } + + private void LoadAuthors() + { + try + { + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + string sql = "SELECT idavtori, name_A FROM avtori ORDER BY name_A"; + + MySqlCommand cmd = new MySqlCommand(sql, conn); + MySqlDataAdapter da = new MySqlDataAdapter(cmd); + DataTable dt = new DataTable(); + da.Fill(dt); + + comboBox1.DataSource = dt; + comboBox1.DisplayMember = "name_A"; + comboBox1.ValueMember = "idavtori"; + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка загрузки авторов: " + ex.Message); + } + } + + private void LoadBookData() + { + try + { + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + string sql = "SELECT avtor, name, price FROM books WHERE idname = @id"; + + MySqlCommand cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("@id", bookId); + + MySqlDataReader reader = cmd.ExecuteReader(); + + if (reader.Read()) + { + tbName.Text = reader["name"].ToString(); + comboBox1.SelectedValue = reader["avtor"]; + tbPrice.Text = reader["price"].ToString(); + } + else + { + MessageBox.Show("Книга не найдена!"); + this.Close(); + } + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка загрузки данных книги: " + ex.Message); + } + } + + + private void button1_Click(object sender, EventArgs e) + { + //string connStr = "Server=cfif31.ru;Port=3306;Database=ISPr25-21_KorotinDV_37;Uid=ISPr25-21_KorotinDV;Pwd=ISPr25-21_KorotinDV; SslMode=none"; + //using (MySqlConnection conn = new MySqlConnection(connStr)) + //{ + // conn.Open(); + // string sql = "UPDATE books SET name = @name, avtor = @avtor, price = @price WHERE idname = @idname"; + // MySqlCommand cmd = new MySqlCommand(sql, conn); + // cmd.Parameters.AddWithValue("@idname", bookId); + // cmd.Parameters.AddWithValue("@name", tbName.Text); + // cmd.Parameters.AddWithValue("@avtor", comboBox1.Text); + // cmd.Parameters.AddWithValue("@price", decimal.Parse(tbPrice.Text)); + // cmd.ExecuteNonQuery(); + //} + //this.DialogResult = DialogResult.OK; + //this.Close(); + + + + try + { + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + + string sql = "UPDATE books SET name = @name, avtor = @avtor, price = @price WHERE idname = @id"; + MySqlCommand cmd = new MySqlCommand(sql, conn); + + cmd.Parameters.AddWithValue("@name", tbName.Text.Trim()); + cmd.Parameters.AddWithValue("@avtor", comboBox1.SelectedValue); + cmd.Parameters.AddWithValue("@price", decimal.Parse(tbPrice.Text)); + cmd.Parameters.AddWithValue("@id", bookId); // Важно: обновляем именно эту книгу + + int rows = cmd.ExecuteNonQuery(); + + if (rows > 0) + { + MessageBox.Show("Данные успешно обновлены!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + this.DialogResult = DialogResult.OK; + this.Close(); + } + else + { + MessageBox.Show("Не удалось обновить данные.", "Ошибка"); + } + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка при сохранении: " + ex.Message, "Критическая ошибка"); + } + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + + } + } +} diff --git a/EditBooksForm.resx b/EditBooksForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/EditBooksForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Form1.Designer.cs b/Form1.Designer.cs new file mode 100644 index 0000000..ab39634 --- /dev/null +++ b/Form1.Designer.cs @@ -0,0 +1,118 @@ +namespace _fsh +{ + partial class Form1 + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором форм Windows + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(395, 214); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 0; + this.button1.Text = "войти"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(380, 94); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(100, 20); + this.textBox1.TabIndex = 2; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(380, 162); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(100, 20); + this.textBox2.TabIndex = 3; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(392, 135); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(52, 13); + this.label1.TabIndex = 4; + this.label1.Text = "password"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(410, 67); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 13); + this.label2.TabIndex = 5; + this.label2.Text = "login"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(380, 271); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(75, 13); + this.label3.TabIndex = 6; + this.label3.Text = "Регистрация "; + this.label3.Click += new System.EventHandler(this.label3_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + } +} + diff --git a/Form1.cs b/Form1.cs new file mode 100644 index 0000000..835af70 --- /dev/null +++ b/Form1.cs @@ -0,0 +1,90 @@ +// ВАЖНО: Подключаем библиотеку MySQL, а не SQL Server! +using MySql.Data.MySqlClient; +using System; +using System.Windows.Forms; +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.Data.SqlClient; +using fsh; + +namespace _fsh +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + + private void btAutorization_Click(object sender, EventArgs e) + { + + } + + private void Form1_Load(object sender, EventArgs e) + { + + } + + + + private void label3_Click(object sender, EventArgs e) + { + Registration Registration = new Registration(); + Registration.Show(); + this.Hide(); + } + + private void button1_Click(object sender, EventArgs e) + { + string login = textBox1.Text; + string password = textBox2.Text; + + if (string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(password)) + { + MessageBox.Show("Введите логин и пароль"); + return; + } + string connectionString = "Server=cfif31.ru; port=3306; Database=ISPr25-21_KorotinDV_37; username=ISPr25-21_KorotinDV; password=ISPr25-21_KorotinDV; Sslmode=none"; + string query = "SELECT * FROM librarians WHERE login = @login AND pass = @pass"; + try + { + using (MySqlConnection conn = new MySqlConnection(connectionString)) + { + conn.Open(); + using (MySqlCommand cmd = new MySqlCommand(query, conn)) + { + cmd.Parameters.AddWithValue("@login", login); + cmd.Parameters.AddWithValue("@pass", password); + object result = cmd.ExecuteScalar(); + + if (result != null && Convert.ToInt32(result) > 0) + { + MessageBox.Show("Успешно!", "Победа", MessageBoxButtons.OK, MessageBoxIcon.Information); + MainForm mainForm = new MainForm(); + mainForm.Show(); + this.Hide(); + } + else + { + MessageBox.Show("Неверный логин или пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка: " + ex.Message, "Критическая ошибка"); + } + } + } +} + + + \ No newline at end of file diff --git a/Form1.resx b/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs new file mode 100644 index 0000000..6126221 --- /dev/null +++ b/MainForm.Designer.cs @@ -0,0 +1,99 @@ +namespace fsh +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(202, 21); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.Size = new System.Drawing.Size(480, 284); + this.dataGridView1.TabIndex = 0; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(202, 374); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 1; + this.button1.Text = "Добавить"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(413, 374); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(94, 23); + this.button2.TabIndex = 2; + this.button2.Text = "Редактировать"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(607, 374); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 3; + this.button3.Text = "Удалить"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.dataGridView1); + this.Name = "MainForm"; + this.Text = "MainForm"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + } +} \ No newline at end of file diff --git a/MainForm.cs b/MainForm.cs new file mode 100644 index 0000000..fab8734 --- /dev/null +++ b/MainForm.cs @@ -0,0 +1,151 @@ +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; + +namespace fsh +{ + public partial class MainForm : Form + { + string connStr = "Server=cfif31.ru;Port=3306;Database=ISPr25-21_KorotinDV_37;Uid=ISPr25-21_KorotinDV;Pwd=ISPr25-21_KorotinDV;SslMode=none;"; + + public MainForm() + { + InitializeComponent(); + this.Load += MainForm_Load; + + + dataGridView1.AllowUserToAddRows = false; + dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView1.MultiSelect = false; + dataGridView1.ReadOnly = true; + } + + private void MainForm_Load(object sender, EventArgs e) + { + try + { + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + + string sql = @" + SELECT b.idname, b.name AS book_name, a.name_A AS author_name, b.price + FROM books b + INNER JOIN avtori a ON b.avtor = a.idavtori + ORDER BY b.idname"; + + MySqlCommand cmd = new MySqlCommand(sql, conn); + MySqlDataAdapter da = new MySqlDataAdapter(cmd); + DataTable dt = new DataTable(); + + int count = da.Fill(dt); + + if (count == 0) + { + MessageBox.Show("В таблице нет данных!"); + return; + } + + dataGridView1.DataSource = dt; + + dataGridView1.Columns[0].Visible = false; // Скрыть ID + + + dataGridView1.Columns[1].HeaderText = "Название книги"; + dataGridView1.Columns[2].HeaderText = "Автор"; + dataGridView1.Columns[3].HeaderText = "Цена (руб.)"; + dataGridView1.Columns[3].DefaultCellStyle.Format = "N2"; + dataGridView1.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка: " + ex.Message, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void button1_Click(object sender, EventArgs e) + { + + AddBooksForm add = new AddBooksForm(); + if (add.ShowDialog() == DialogResult.OK) + { + MainForm_Load(sender, e); + } + } + + private void button2_Click(object sender, EventArgs e) + { + if (dataGridView1.CurrentRow == null) + { + MessageBox.Show("Выберите строку для редактирования", "Внимание"); + return; + } + + int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); + EditBooksForm edit = new EditBooksForm(id); + if (edit.ShowDialog() == DialogResult.OK) + { + MainForm_Load(sender, e); + } + } + + private void button3_Click(object sender, EventArgs e) + { + if (dataGridView1.CurrentRow == null) + { + MessageBox.Show("Выберите книгу для удаления", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + // 2. Подтверждение действия + string name = dataGridView1.CurrentRow.Cells[1].Value.ToString(); + DialogResult res = MessageBox.Show( + $"Вы действительно хотите удалить книгу \"{name}\"?\nЭто действие нельзя отменить.", + "Подтверждение удаления", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question); + + if (res == DialogResult.Yes) + { + try + { + int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); + + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + string sql = "DELETE FROM books WHERE idname = @id"; + MySqlCommand cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("@id", id); + + int rows = cmd.ExecuteNonQuery(); + + if (rows > 0) + { + MessageBox.Show($"Книга \"{name}\" успешно удалена!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + MainForm_Load(sender, e); // Обновить таблицу + } + else + { + MessageBox.Show("Ошибка: книга не найдена в базе.", "Ошибка"); + } + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка при удалении: " + ex.Message, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} + diff --git a/MainForm.resx b/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..abc2356 --- /dev/null +++ b/Program.cs @@ -0,0 +1,23 @@ +using _fsh; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace fsh +{ + internal static class Program + { + /// + /// Главная точка входа для приложения. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..afc64bb --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанных со сборкой. +[assembly: AssemblyTitle("fsh")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("fsh")] +[assembly: AssemblyCopyright("Copyright © 2026")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// COM, следует установить атрибут ComVisible в TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("85db4694-a199-442e-a92f-e5eae1c40e03")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Редакция +// +// Можно задать все значения или принять номера сборки и редакции по умолчанию +// используя "*", как показано ниже: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..39d4bea --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программным средством. +// Версия среды выполнения: 4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если +// код создан повторно. +// +//------------------------------------------------------------------------------ + +namespace fsh.Properties +{ + + + /// + /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. + /// + // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder + // класс с помощью таких средств, как ResGen или Visual Studio. + // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen + // с параметром /str или заново постройте свой VS-проект. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("fsh.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Переопределяет свойство CurrentUICulture текущего потока для всех + /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..4f4ed07 --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace fsh.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Registration.Designer.cs b/Registration.Designer.cs new file mode 100644 index 0000000..925ee44 --- /dev/null +++ b/Registration.Designer.cs @@ -0,0 +1,183 @@ +namespace fsh +{ + partial class Registration + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.textBox4 = new System.Windows.Forms.TextBox(); + this.textBox5 = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(303, 343); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(170, 23); + this.button1.TabIndex = 0; + this.button1.Text = "зарегистрироваться"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(370, 30); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(27, 13); + this.label1.TabIndex = 1; + this.label1.Text = "имя"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(370, 277); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(43, 13); + this.label2.TabIndex = 2; + this.label2.Text = "пароль"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(370, 220); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(36, 13); + this.label3.TabIndex = 3; + this.label3.Text = "логин"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(370, 162); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(52, 13); + this.label4.TabIndex = 4; + this.label4.Text = "отчество"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(370, 99); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(53, 13); + this.label5.TabIndex = 5; + this.label5.Text = "фамилия"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(370, 392); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(37, 13); + this.label6.TabIndex = 6; + this.label6.Text = "назад"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(347, 62); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(100, 20); + this.textBox1.TabIndex = 7; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(347, 124); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(100, 20); + this.textBox2.TabIndex = 8; + // + // textBox3 + // + this.textBox3.Location = new System.Drawing.Point(347, 191); + this.textBox3.Name = "textBox3"; + this.textBox3.Size = new System.Drawing.Size(100, 20); + this.textBox3.TabIndex = 9; + // + // textBox4 + // + this.textBox4.Location = new System.Drawing.Point(347, 253); + this.textBox4.Name = "textBox4"; + this.textBox4.Size = new System.Drawing.Size(100, 20); + this.textBox4.TabIndex = 10; + // + // textBox5 + // + this.textBox5.Location = new System.Drawing.Point(347, 300); + this.textBox5.Name = "textBox5"; + this.textBox5.Size = new System.Drawing.Size(100, 20); + this.textBox5.TabIndex = 11; + // + // Registration + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBox5); + this.Controls.Add(this.textBox4); + this.Controls.Add(this.textBox3); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label6); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Name = "Registration"; + this.Text = "Registration"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.TextBox textBox4; + private System.Windows.Forms.TextBox textBox5; + } +} \ No newline at end of file diff --git a/Registration.cs b/Registration.cs new file mode 100644 index 0000000..0ce3e7f --- /dev/null +++ b/Registration.cs @@ -0,0 +1,77 @@ +using _fsh; +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; + +namespace fsh +{ + public partial class Registration : Form + { + public Registration() + { + InitializeComponent(); + } + + string connStr = "Server=cfif31.ru;Port=3306;Database=ISPr25-21_NeshinaPV_0303;Uid=ISPr25-21_NeshinaPV;Pwd=ISPr25-21_NeshinaPV; SslMode=none;"; + + private void lblBack_Click(object sender, EventArgs e) + { + Form1 form1 = new Form1(); + form1.Show(); + this.Hide(); + } + + private void button1_Click(object sender, EventArgs e) + { + string firstname = textBox1.Text.Trim(); + string lastname = textBox2.Text.Trim(); + string surname = textBox3.Text.Trim(); + string login = textBox4.Text.Trim(); + string password = textBox5.Text; + + if (string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + MessageBox.Show("Заполните Фамилию, Имя, Логин и Пароль!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + + string query = "INSERT INTO librarians (firstName, lastName, surName, login, password) VALUES (@f, @l, @s, @log, @pass)"; + + try + { + using (MySqlConnection conn = new MySqlConnection(connStr)) + { + conn.Open(); + using (MySqlCommand cmd = new MySqlCommand(query, conn)) + { + // Сопоставляем параметры с данными + cmd.Parameters.AddWithValue("@f", firstname); // В столбец firstName + cmd.Parameters.AddWithValue("@l", lastname); // В столбец lastName + cmd.Parameters.AddWithValue("@s", surname); // В столбец surName (Отчество) + cmd.Parameters.AddWithValue("@log", login); // В столбец login + cmd.Parameters.AddWithValue("@pass", password); // В столбец password + + cmd.ExecuteNonQuery(); + } + } + + MessageBox.Show("Регистрация успешна! Теперь войдите.", "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information); + + } + catch (Exception ex) + { + MessageBox.Show("Ошибка регистрации: " + ex.Message, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + +} + diff --git a/Registration.resx b/Registration.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Registration.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/bin/Debug/MySql.Data.dll b/bin/Debug/MySql.Data.dll new file mode 100644 index 0000000..a851892 Binary files /dev/null and b/bin/Debug/MySql.Data.dll differ diff --git a/bin/Debug/fsh.exe b/bin/Debug/fsh.exe new file mode 100644 index 0000000..a4a892b Binary files /dev/null and b/bin/Debug/fsh.exe differ diff --git a/bin/Debug/fsh.exe.config b/bin/Debug/fsh.exe.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/bin/Debug/fsh.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/bin/Debug/fsh.pdb b/bin/Debug/fsh.pdb new file mode 100644 index 0000000..5784bdf Binary files /dev/null and b/bin/Debug/fsh.pdb differ diff --git a/fsh.csproj b/fsh.csproj new file mode 100644 index 0000000..4f562fe --- /dev/null +++ b/fsh.csproj @@ -0,0 +1,122 @@ + + + + + Debug + AnyCPU + {85DB4694-A199-442E-A92F-E5EAE1C40E03} + WinExe + fsh + fsh + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + D:\DEM_Rogova\mysql.data\MySql.Data.dll + + + + + + + + + + + + + + + + Form + + + AddBooksForm.cs + + + Form + + + EditBooksForm.cs + + + Form + + + Form1.cs + + + Form + + + MainForm.cs + + + + + Form + + + Registration.cs + + + AddBooksForm.cs + + + EditBooksForm.cs + + + Form1.cs + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + Registration.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/fsh.sln b/fsh.sln new file mode 100644 index 0000000..90c03ba --- /dev/null +++ b/fsh.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34511.84 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fsh", "fsh.csproj", "{85DB4694-A199-442E-A92F-E5EAE1C40E03}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85DB4694-A199-442E-A92F-E5EAE1C40E03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85DB4694-A199-442E-A92F-E5EAE1C40E03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85DB4694-A199-442E-A92F-E5EAE1C40E03}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85DB4694-A199-442E-A92F-E5EAE1C40E03}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {16DACC7E-8980-4502-A232-2E4A74A7AE83} + EndGlobalSection +EndGlobal diff --git a/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs new file mode 100644 index 0000000..3871b18 --- /dev/null +++ b/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/obj/Debug/DesignTimeResolveAssemblyReferences.cache new file mode 100644 index 0000000..8b9b776 Binary files /dev/null and b/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..dd364a2 Binary files /dev/null and b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/obj/Debug/_fsh.Form1.resources b/obj/Debug/_fsh.Form1.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/obj/Debug/_fsh.Form1.resources differ diff --git a/obj/Debug/fsh.AddBooksForm.resources b/obj/Debug/fsh.AddBooksForm.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/obj/Debug/fsh.AddBooksForm.resources differ diff --git a/obj/Debug/fsh.EditBooksForm.resources b/obj/Debug/fsh.EditBooksForm.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/obj/Debug/fsh.EditBooksForm.resources differ diff --git a/obj/Debug/fsh.MainForm.resources b/obj/Debug/fsh.MainForm.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/obj/Debug/fsh.MainForm.resources differ diff --git a/obj/Debug/fsh.Properties.Resources.resources b/obj/Debug/fsh.Properties.Resources.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/obj/Debug/fsh.Properties.Resources.resources differ diff --git a/obj/Debug/fsh.Registration.resources b/obj/Debug/fsh.Registration.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/obj/Debug/fsh.Registration.resources differ diff --git a/obj/Debug/fsh.csproj.AssemblyReference.cache b/obj/Debug/fsh.csproj.AssemblyReference.cache new file mode 100644 index 0000000..233f882 Binary files /dev/null and b/obj/Debug/fsh.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/fsh.csproj.CopyComplete b/obj/Debug/fsh.csproj.CopyComplete new file mode 100644 index 0000000..e69de29 diff --git a/obj/Debug/fsh.csproj.CoreCompileInputs.cache b/obj/Debug/fsh.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..702f213 --- /dev/null +++ b/obj/Debug/fsh.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +1e1a3b6a97eed210e5764b1fe8eab3634c6f85ea3898099c6328193537c47989 diff --git a/obj/Debug/fsh.csproj.FileListAbsolute.txt b/obj/Debug/fsh.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..2c48952 --- /dev/null +++ b/obj/Debug/fsh.csproj.FileListAbsolute.txt @@ -0,0 +1,16 @@ +C:\Users\Student\fsh\obj\Debug\fsh.csproj.AssemblyReference.cache +C:\Users\Student\fsh\obj\Debug\fsh.AddBooksForm.resources +C:\Users\Student\fsh\obj\Debug\_fsh.Form1.resources +C:\Users\Student\fsh\obj\Debug\fsh.MainForm.resources +C:\Users\Student\fsh\obj\Debug\fsh.Properties.Resources.resources +C:\Users\Student\fsh\obj\Debug\fsh.Registration.resources +C:\Users\Student\fsh\obj\Debug\fsh.csproj.GenerateResource.cache +C:\Users\Student\fsh\obj\Debug\fsh.csproj.CoreCompileInputs.cache +C:\Users\Student\fsh\obj\Debug\fsh.EditBooksForm.resources +C:\Users\Student\fsh\bin\Debug\fsh.exe.config +C:\Users\Student\fsh\bin\Debug\fsh.exe +C:\Users\Student\fsh\bin\Debug\fsh.pdb +C:\Users\Student\fsh\bin\Debug\MySql.Data.dll +C:\Users\Student\fsh\obj\Debug\fsh.csproj.CopyComplete +C:\Users\Student\fsh\obj\Debug\fsh.exe +C:\Users\Student\fsh\obj\Debug\fsh.pdb diff --git a/obj/Debug/fsh.csproj.GenerateResource.cache b/obj/Debug/fsh.csproj.GenerateResource.cache new file mode 100644 index 0000000..d73f092 Binary files /dev/null and b/obj/Debug/fsh.csproj.GenerateResource.cache differ diff --git a/obj/Debug/fsh.exe b/obj/Debug/fsh.exe new file mode 100644 index 0000000..a4a892b Binary files /dev/null and b/obj/Debug/fsh.exe differ diff --git a/obj/Debug/fsh.pdb b/obj/Debug/fsh.pdb new file mode 100644 index 0000000..5784bdf Binary files /dev/null and b/obj/Debug/fsh.pdb differ