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 saytan
{
    public partial class adminMain : Form
    {
        public adminMain()
        {
            InitializeComponent();
        }

        private void adminMain_Load(object sender, EventArgs e)
        {
            label1.BackColor = System.Drawing.Color.Transparent;
            label2.BackColor = System.Drawing.Color.Transparent;
            label3.BackColor = System.Drawing.Color.Transparent;
            label4.BackColor = System.Drawing.Color.Transparent;
            label5.BackColor = System.Drawing.Color.Transparent;
            label6.BackColor = System.Drawing.Color.Transparent;
            label8.BackColor = System.Drawing.Color.Transparent;
            label9.BackColor = System.Drawing.Color.Transparent;
            AcceptButton = button1;
        }

        private void label7_Click(object sender, EventArgs e)
        {
        }
        public void insert()
        {
            GetAllItems2();
        }
        DataTable GetAllItems2()
        {
            try
            {
                MySqlConnection conn = new MySqlConnection("Server=localhost; database=saytan; UID=root; CHARSET=utf8;");
                conn.Open();
                string max;
                string query1 = "select max(asuultNo) from asuult";
                MySqlCommand cmd = new MySqlCommand(query1, conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                max = reader.GetString(0);
                reader.Close();
                max = Convert.ToString(Convert.ToInt32(max)+1);
                string query = "INSERT INTO asuult VALUES('"+max+"','"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"','"+textBox6.Text+"','"+textBox7.Text+"')";
                MySqlDataAdapter adapter = new MySqlDataAdapter(query, "Server=localhost; database=saytan; UID=root;CHARSET=utf8;");
                DataSet DS = new DataSet();
                DS.Clear();
                adapter.Fill(DS);
                adminMain a = new adminMain();
                this.Hide();
                a.ShowDialog();
                this.Close();
                return null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "" && textBox6.Text != "" && textBox7.Text != "")
            insert();
        }

        private void label3_Click(object sender, EventArgs e)
        {
            
        }

        private void label1_Click(object sender, EventArgs e)
        {
            admin1 a = new admin1();
            this.Hide();
            a.ShowDialog();
            this.Close();
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            //admin1 a = new admin1();
            this.Hide();
            // a.ShowDialog();
            this.Close();
        }
    }
}
