using System;
using System.Drawing;
using System.Windows.Forms;
using Zoo;

namespace Zoo

{
    public class FormMain : Form
    {
        DataGridView dgv;
        TextBox txtSearch;
        Button btnSearch;
        Button btnAdd;
        Button btnEdit;
        Button btnDelete;

        public FormMain()
        {
            InitializeComponent();
            LoadData();
        }

        private void InitializeComponent()
        {
            Text = "Информационная система";
            StartPosition = FormStartPosition.CenterScreen;
            Size = new Size(900, 550);
            BackColor = Color.WhiteSmoke;
            Font = new Font("Segoe UI", 10);

            Label lblSearch = new Label();
            lblSearch.Text = "Поиск:";
            lblSearch.Location = new Point(20, 20);
            lblSearch.AutoSize = true;

            txtSearch = new TextBox();
            txtSearch.Location = new Point(80, 17);
            txtSearch.Size = new Size(220, 30);

            btnSearch = new Button();
            btnSearch.Text = "Поиск";
            btnSearch.Location = new Point(320, 15);
            btnSearch.Size = new Size(100, 35);
            btnSearch.BackColor = Color.DodgerBlue;
            btnSearch.ForeColor = Color.White;
            btnSearch.FlatStyle = FlatStyle.Flat;
            btnSearch.Click += BtnSearch_Click;

            dgv = new DataGridView();
            dgv.Location = new Point(20, 70);
            dgv.Size = new Size(620, 400);
            dgv.AllowUserToAddRows = false;
            dgv.ReadOnly = true;
            dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dgv.Columns.Add("id", "ID");
            dgv.Columns.Add("name", "ФИО");
            dgv.Columns.Add("phone", "Телефон");
            dgv.Columns.Add("email", "Email");

            btnAdd = new Button();
            btnAdd.Text = "Добавить";
            btnAdd.Location = new Point(680, 90);
            btnAdd.Size = new Size(170, 45);
            btnAdd.BackColor = Color.ForestGreen;
            btnAdd.ForeColor = Color.White;
            btnAdd.FlatStyle = FlatStyle.Flat;
            btnAdd.Click += BtnAdd_Click;

            btnEdit = new Button();
            btnEdit.Text = "Редактировать";
            btnEdit.Location = new Point(680, 160);
            btnEdit.Size = new Size(170, 45);
            btnEdit.BackColor = Color.Goldenrod;
            btnEdit.ForeColor = Color.White;
            btnEdit.FlatStyle = FlatStyle.Flat;
            btnEdit.Click += BtnEdit_Click;

            btnDelete = new Button();
            btnDelete.Text = "Удалить";
            btnDelete.Location = new Point(680, 230);
            btnDelete.Size = new Size(170, 45);
            btnDelete.BackColor = Color.IndianRed;
            btnDelete.ForeColor = Color.White;
            btnDelete.FlatStyle = FlatStyle.Flat;
            btnDelete.Click += BtnDelete_Click;

            Controls.Add(lblSearch);
            Controls.Add(txtSearch);
            Controls.Add(btnSearch);
            Controls.Add(dgv);
            Controls.Add(btnAdd);
            Controls.Add(btnEdit);
            Controls.Add(btnDelete);
        }

        private void LoadData()
        {
            dgv.Rows.Add("1", "Иванов Иван", "89001234567", "ivan@mail.ru");
            dgv.Rows.Add("2", "Петров Петр", "89112223344", "petr@mail.ru");
            dgv.Rows.Add("3", "Сидоров Алексей", "89223334455", "alex@mail.ru");
            dgv.Rows.Add("4", "Кузнецов Сергей", "89334445566", "sergey@mail.ru");
        }

        private void BtnSearch_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Поиск: " + txtSearch.Text);
        }

        private void BtnAdd_Click(object sender, EventArgs e)
        {
            FormEdit f = new FormEdit();
            f.ShowDialog();
        }

        private void BtnEdit_Click(object sender, EventArgs e)
        {
            if (dgv.CurrentRow == null)
            {
                MessageBox.Show("Выберите запись.");
                return;
            }

            FormEdit f = new FormEdit();
            f.ShowDialog();
        }

        private void BtnDelete_Click(object sender, EventArgs e)
        {
            if (dgv.CurrentRow == null)
            {
                MessageBox.Show("Выберите запись.");
                return;
            }

            dgv.Rows.Remove(dgv.CurrentRow);
            MessageBox.Show("Запись удалена.");
        }
    }
}