using MySql.Data.MySqlClient;
using System;
using System.Windows.Forms;

namespace programming_ii__lesson_2_
{
    public partial class Form2 : Form
    {
        public Form RefToForm1 { get; set; }
        public Form2()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.RefToForm1.Show();



        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            string surname=textBox2.Text;
            string afm=textBox3.Text;
            string birthdate=dateTimePicker1.Value.ToString("yyyy-MM-dd");
            string payroll= textBox5.Text;

            var myConnection = dbconnect.myConnection;
            myConnection.Open();
            string query = $"insert into employees (name,surname,afm,birth_date,payroll) values ('{name}','{surname}','{afm}','{birthdate}','{payroll}');";
            MySqlCommand cmd = new MySqlCommand(query, myConnection);
            cmd.ExecuteNonQuery();
            myConnection.Close();

            this.Dispose();
            this.RefToForm1.Show();

        }
    }
}
