131 lines
4.8 KiB
C#
131 lines
4.8 KiB
C#
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;
|
||
using MySql.Data.MySqlClient;
|
||
|
||
namespace megadem
|
||
{
|
||
public partial class MainForm : Form
|
||
{
|
||
private MySqlDataAdapter dataAdapter;
|
||
private DataTable prodTable;
|
||
private BindingSource bindingSource = new BindingSource();
|
||
|
||
public MainForm()
|
||
{
|
||
InitializeComponent();
|
||
LoadProdData();
|
||
LoadImageFromResources();
|
||
}
|
||
|
||
|
||
|
||
private void LoadProdData() // загрузка данных в дгв
|
||
{
|
||
try
|
||
{
|
||
DB db = new DB();
|
||
using (MySqlConnection connection = db.getConnection())
|
||
{
|
||
connection.Open();
|
||
string query = "SELECT Article AS `Артикул`, Product_name AS `Наименование продукта`, ProductType AS `Тип продукта`, Min_price_partner AS `Минимальная цена для партнера`, Width AS `Ширина` FROM Product LEFT JOIN Product_type ON Product.Product_type_id = idProduct_type";
|
||
|
||
dataAdapter = new MySqlDataAdapter(query, connection);
|
||
prodTable = new DataTable();
|
||
dataAdapter.Fill(prodTable);
|
||
DataGridViewProduct.RowTemplate.Height = 60;
|
||
bindingSource.DataSource = prodTable;
|
||
DataGridViewProduct.DataSource = bindingSource;
|
||
DataGridViewProduct.AllowUserToAddRows = false;
|
||
DataGridViewProduct.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
|
||
DataGridViewProduct.ReadOnly = true; // настройки дгв
|
||
|
||
}
|
||
}
|
||
catch (MySqlException ex)
|
||
{
|
||
MessageBox.Show("Ошибка при подключении к базе данных или выполнении запроса: " + ex.Message);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("Произошла общая ошибка: " + ex.Message);
|
||
}
|
||
|
||
}
|
||
private void dataGridViewProd_Click(object sender, EventArgs e)
|
||
{
|
||
textBoxName.Text = DataGridViewProduct.CurrentRow.Cells[1].Value.ToString();
|
||
textBoxWidth.Text = DataGridViewProduct.CurrentRow.Cells[4].Value.ToString() +" (М)";
|
||
textBoxArticle.Text = DataGridViewProduct.CurrentRow.Cells[0].Value.ToString();
|
||
textBoxMinPrice.Text = DataGridViewProduct.CurrentRow.Cells[3].Value.ToString() + " (Р)";
|
||
textBoxType.Text = DataGridViewProduct.CurrentRow.Cells[2].Value.ToString();
|
||
}
|
||
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
this.Hide();
|
||
AddProductForm form = new AddProductForm();
|
||
form.ShowDialog();
|
||
LoadProdData();
|
||
}
|
||
|
||
private void button2_Click(object sender, EventArgs e)
|
||
{
|
||
if (DataGridViewProduct.SelectedRows.Count > 0)
|
||
{
|
||
string articleToEdit = Convert.ToString(DataGridViewProduct.SelectedRows[0].Cells["Артикул"].Value);
|
||
|
||
|
||
EditProductForm editProductForm = new EditProductForm(articleToEdit);
|
||
|
||
this.Hide();
|
||
|
||
DialogResult result = editProductForm.ShowDialog();
|
||
|
||
|
||
if (result == DialogResult.OK)
|
||
{
|
||
LoadProdData();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Пожалуйста, выберите строку для редактирования.");
|
||
}
|
||
}
|
||
|
||
private void button3_Click(object sender, EventArgs e)
|
||
{
|
||
Application.Exit();
|
||
}
|
||
|
||
private void MainForm_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
private void LoadImageFromResources()
|
||
{
|
||
// Предполагаем, что вы назвали изображение в ресурсах "MyImage"
|
||
// (замените "MyImage" на фактическое имя вашего ресурса изображения)
|
||
pictureBox1.Image = Properties.Resources.decor;
|
||
|
||
// Опционально: настроить режим отображения изображения
|
||
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; // Или StretchImage, Normal, CenterImage
|
||
}
|
||
|
||
private void button4_Click(object sender, EventArgs e)
|
||
{
|
||
this.Hide();
|
||
MaterialForm materialForm = new MaterialForm();
|
||
materialForm.Show();
|
||
}
|
||
}
|
||
}
|