68 lines
2.5 KiB
C#
68 lines
2.5 KiB
C#
using MySql.Data.MySqlClient;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace megadem
|
|
{
|
|
public partial class MaterialForm : Form
|
|
{
|
|
private MySqlDataAdapter dataAdapter;
|
|
private DataTable prodTable;
|
|
private BindingSource bindingSource = new BindingSource();
|
|
|
|
public MaterialForm()
|
|
{
|
|
InitializeComponent();
|
|
LoadProdData();
|
|
}
|
|
|
|
private void LoadProdData() // загрузка данных в дгв
|
|
{
|
|
try
|
|
{
|
|
DB db = new DB();
|
|
using (MySqlConnection connection = db.getConnection())
|
|
{
|
|
connection.Open();
|
|
string query = "SELECT Product_name AS `Название продукта`, Material_name AS `Название материала`, Quantity_of_material AS `Количество материала` FROM ProductMaterial LEFT JOIN Product ON Product.idProduct = ProductMaterial.ProductID LEFT JOIN Material ON Material.Material_name = ProductMaterial.MaterialID";
|
|
|
|
dataAdapter = new MySqlDataAdapter(query, connection);
|
|
prodTable = new DataTable();
|
|
dataAdapter.Fill(prodTable);
|
|
dataGridViewMaterial.RowTemplate.Height = 60;
|
|
bindingSource.DataSource = prodTable;
|
|
dataGridViewMaterial.DataSource = bindingSource;
|
|
dataGridViewMaterial.AllowUserToAddRows = false;
|
|
dataGridViewMaterial.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
|
|
dataGridViewMaterial.ReadOnly = true; // настройки дгв
|
|
|
|
}
|
|
}
|
|
catch (MySqlException ex)
|
|
{
|
|
MessageBox.Show("Ошибка при подключении к базе данных или выполнении запроса: " + ex.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Произошла общая ошибка: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
this.Hide();
|
|
MainForm form = new MainForm();
|
|
form.Show();
|
|
}
|
|
}
|
|
|
|
}
|