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 MySql.Data.MySqlClient;

namespace sport_invent_modul_14._05
{
    public partial class Client_Form : Form
    {
        string connectionString = "Server=85.239.57.125; Database=Primakov_Natalya_modul; Uid=Primakov_Natalya; Pwd=TempPass123!; SslMode=none;";
        public Client_Form()
        {
            InitializeComponent();
            LoadProducts();

        }

        void LoadProducts()
        {
            using (var conn = new MySqlConnection(connectionString))
            {
                conn.Open();
                var adapter = new MySqlDataAdapter(@"SELECT p.idProduct, p.Article, p.Name, c.Category, p.Description, 
                     m.Manufacturer, s.Supplier, p.Price, p.Discount, p.Quantity, u.Unit, p.Photo
                     FROM Product p
                     LEFT JOIN Category c ON p.CategoryID = c.idCategory
                     LEFT JOIN Manufacturer m ON p.ManufacturerID = m.idManufacturer
                     LEFT JOIN Supplier s ON p.SupplierID = s.idSupplier
                     LEFT JOIN Unit u ON p.EdinicaID = u.idUnit", conn);

                var dt = new DataTable();
                adapter.Fill(dt);
                dataGridView1.DataSource = dt;
                if (dataGridView1.Columns["idProduct"] != null)
                    dataGridView1.Columns["idProduct"].Visible = false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            Form1 form = new Form1();
            form.Show();
        }

        private void Client_Form_Load(object sender, EventArgs e)
        {

        }
    }
}
