82 lines
2.5 KiB
C#
82 lines
2.5 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 _4Menu : Form
|
|
{
|
|
public _4Menu()
|
|
{
|
|
InitializeComponent();
|
|
this.Text = "Гость";
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
MainForm form = new MainForm();
|
|
form.Show();
|
|
this.Hide();
|
|
}
|
|
|
|
private void _4Menu_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
e.Cancel = true;
|
|
this.Hide();
|
|
MainForm form1 = new MainForm();
|
|
form1.Show();
|
|
}
|
|
|
|
private void _4Menu_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);
|
|
}
|
|
}
|
|
}
|
|
}
|