Nov2611/_3Menu.cs
2025-11-26 16:13:12 +04:00

86 lines
2.6 KiB
C#

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 NeshinaPolina07_11
{
public partial class _3Menu : Form
{
public _3Menu()
{
InitializeComponent();
this.Text = "Пользователь";
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void _3Menu_Load(object sender, EventArgs e)
{
try
{
var db = DB.GetInstance();
var connection = db.GetConnection();
string query = @"
SELECT
p.product_id,
p.product_article,
p.product_name,
p.unit,
p.price,
p.discount,
p.quantity_in_stock,
p.description,
p.photo,
c.category_name AS category,
m.manufacturer_name AS manufacturer,
s.supplier_name AS supplier
FROM products p
LEFT JOIN categories c ON p.category_id = c.category_id
LEFT JOIN manufacturers m ON p.manufacturer_id = m.manufacturer_id
LEFT JOIN suppliers s ON p.supplier_id = s.supplier_id;";
using (MySqlCommand cmd = new MySqlCommand(query, connection))
using (MySqlDataAdapter adapter = new MySqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
dgvProducts.DataSource = dt;
}
dgvProducts.AutoResizeColumns();
}
catch (Exception ex)
{
MessageBox.Show("Ошибка загрузки данных: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button1_Click(object sender, EventArgs e)
{
MainForm form = new MainForm();
form.Show();
this.Hide();
}
private void _3Menu_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
MainForm form1 = new MainForm();
form1.Show();
}
}
}