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.Threading;
using System.Windows.Forms;

namespace bai2_tr46_dieukhienthangmay
{
    public partial class Form1 : Form
    {
        string a = String.Empty;
        string b = String.Empty;
 
        public Form1()
        {
            InitializeComponent();

        }
        int x;
        private void delay_ms(int delayms)
        {
            x = 0;
            do
            {
                Application.DoEvents();
            }
            while (x < (delayms / 100));
            Application.DoEvents();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button_start_Click(object sender, EventArgs e)
        {
            string a = "1";
            tang1.BackColor = Color.Blue;
            tang2.BackColor = Color.White;
            tang3.BackColor = Color.White;
            tang4.BackColor = Color.White;
            textBox1.Text = a;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                button4.BackColor = Color.Pink;

                int t = int.Parse(textBox1.Text.ToString());
                if (t == 1)
                {
                    ovalShape1.BackColor = Color.Red;
                    tang1.BackColor = Color.Blue;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "1";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.Blue;
                    textBox1.Text = "4";
                    button4.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 2)
                {
                    ovalShape1.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.Blue;
                    textBox1.Text = "4";
                    button4.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 3)
                {
                    ovalShape1.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.Blue;
                    textBox1.Text = "4";
                    button4.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 4)
                {
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.Blue;
                    textBox1.Text = "4";
                    button4.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
            }
            catch (Exception)
            {
                button1.BackColor = Color.Gray;
                button2.BackColor = Color.Gray;
                button3.BackColor = Color.Gray;
                button4.BackColor = Color.Gray;
                MessageBox.Show("Nhấn START trước để bật thang máy.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            {
                x++;
            if (x > 65000) x = 0;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                button3.BackColor = Color.Pink;
                int t = int.Parse(textBox1.Text.ToString());
                if (t == 1)
                {
                    ovalShape1.BackColor = Color.Red;
                    tang1.BackColor = Color.Blue;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "1";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    button3.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 2)
                {
                    ovalShape1.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    button3.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 3)
                {
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    button3.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 4)
                {
                    ovalShape2.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.Blue;
                    textBox1.Text = "4";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    button3.BackColor = Color.Gray;
                    ovalShape2.BackColor = Color.DarkGray;
                }
            }
            catch (Exception)
            {
                button1.BackColor = Color.Gray;
                button2.BackColor = Color.Gray;
                button3.BackColor = Color.Gray;
                button4.BackColor = Color.Gray;
                MessageBox.Show("Nhấn START trước để bật thang máy.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                button2.BackColor = Color.Pink;
                int t = int.Parse(textBox1.Text.ToString());
                if (t == 1)
                {
                    ovalShape1.BackColor = Color.Red;
                    tang1.BackColor = Color.Blue;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "1";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    button2.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 2)
                {
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    button2.BackColor = Color.Gray;
                    ovalShape1.BackColor = Color.DarkGray;
                }
                if (t == 3)
                {
                    ovalShape2.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    button2.BackColor = Color.Gray;
                    ovalShape2.BackColor = Color.DarkGray;
                }
                if (t == 4)
                {
                    ovalShape2.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.Blue;
                    textBox1.Text = "4";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    button2.BackColor = Color.Gray;
                    ovalShape2.BackColor = Color.DarkGray;
                }
            }
            catch (Exception)
            {
                button1.BackColor = Color.Gray;
                button2.BackColor = Color.Gray;
                button3.BackColor = Color.Gray;
                button4.BackColor = Color.Gray;
                MessageBox.Show("Nhấn START trước để bật thang máy.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                button1.BackColor = Color.Pink;
                int t = int.Parse(textBox1.Text.ToString());
                if (t == 1)
                {
                    tang1.BackColor = Color.Blue;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "1";
                    button1.BackColor = Color.Gray;
                }
                if (t == 2)
                {
                    ovalShape2.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    delay_ms(1000);
                    tang1.BackColor = Color.Blue;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "1";
                    button1.BackColor = Color.Gray;
                    ovalShape2.BackColor = Color.DarkGray;
                }
                if (t == 3)
                {
                    ovalShape2.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    delay_ms(1000);
                    tang1.BackColor = Color.Blue;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "1";
                    button1.BackColor = Color.Gray;
                    ovalShape2.BackColor = Color.DarkGray;
                }
                if (t == 4)
                {
                    ovalShape2.BackColor = Color.Red;
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.Blue;
                    textBox1.Text = "4";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.Blue;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "3";
                    delay_ms(1000);
                    tang1.BackColor = Color.White;
                    tang2.BackColor = Color.Blue;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "2";
                    delay_ms(1000);
                    tang1.BackColor = Color.Blue;
                    tang2.BackColor = Color.White;
                    tang3.BackColor = Color.White;
                    tang4.BackColor = Color.White;
                    textBox1.Text = "1";
                    button1.BackColor = Color.Gray;
                    ovalShape2.BackColor = Color.DarkGray;
                }
            }
            catch (Exception)
            {
                button1.BackColor = Color.Gray;
                button2.BackColor = Color.Gray;
                button3.BackColor = Color.Gray;
                button4.BackColor = Color.Gray;
             MessageBox.Show("Nhấn START trước để bật thang máy.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        
    }
}
