using Npgsql;
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 PM11
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
            LoadAll();
        }

        private void comeBack(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(Program.user_id, Program.connString);
            form2.Show();
            this.Hide();
        }

        private void dataGridView5_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Form3_Load(object sender, EventArgs e)
        {

        }

        private void LoadTable(DataGridView grid, string sql)
        {
            using (var conn = new NpgsqlConnection(Program.connString))
            {
                conn.Open();
                using (var adapter = new NpgsqlDataAdapter(sql, conn))
                {
                    var dt = new DataTable();
                    adapter.Fill(dt);
                    grid.DataSource = dt;
                    grid.Columns["id"].Visible = false;
                }
            }
        }

        private void LoadAll()
        {
            LoadTable(dataGridView1, "SELECT * FROM details");
            LoadTable(dataGridView2, "SELECT * FROM defects");
            LoadTable(dataGridView3, "SELECT * FROM masters");
            LoadTable(dataGridView4, "SELECT * FROM types_detail");
            LoadTable(dataGridView5, "SELECT * FROM users");
            LoadTable(dataGridView6, "SELECT * FROM roles");
        }
    }
}
