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 _0603NeshinaRogova
{
    public partial class Administrator : Form
    {
        private int currentUserId;
        private string connectionString = "Server=cfif31.ru; port=3306; Database=ISPr25-21_NeshinaPV_Doctor; username=ISPr25-21_NeshinaPV; password=ISPr25-21_NeshinaPV";

        public Administrator(int userId)
        {
            InitializeComponent();
            currentUserId = userId;
            LoadDataGrid();
        }

        private void LoadDataGrid()
        {
            try
            {
                using (MySqlConnection conn = new MySqlConnection(connectionString))
                {
                    conn.Open();
                    string query = @"SELECT * from Pacient
                                        ";
                    MySqlCommand cmd = new MySqlCommand(query, conn);
                    DataTable dt = new DataTable();
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    adapter.Fill(dt);
                    dataGridViewRequests.DataSource = dt;
                    dataGridViewRequests.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                    dataGridViewRequests.ReadOnly = true;
                    dataGridViewRequests.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка загрузки данных: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

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