﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;

namespace Dresscode
{
    public partial class Splashscreen : Form
    {
        public Splashscreen()
        {
            InitializeComponent();
        }
        int time = 950;
        int count = 1;
        bool connectable = false;
        globals gl = new globals();
        private void Splashscreen_Load(object sender, EventArgs e)
        {
            try
            {
                timer1.Interval = time * 4;
                timer2.Interval = time;
                timer1.Enabled = true;
                timer2.Enabled = true;
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    if (gl.oleconnection.State == ConnectionState.Closed) gl.oleconnection.Open();
                    connectable = true;
                    if (gl.oleconnection.State == ConnectionState.Open) gl.oleconnection.Close();
                }
                else
                    MessageBox.Show("You are not connected to the internet my young padawan", "Error");
            }
            catch (Exception) {}
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            timer2.Enabled = false;
            if (connectable)
            {
                this.Hide();
                Login login = new Login();
                if (login.ShowDialog() == DialogResult.OK) Application.Run(new Login());
            }
            else
            {
                MessageBox.Show("Your connection to the Reporting system is inaccessible\nPlease relaunch the application.\nIf the problem persists, contact an administrator.", "Error");
                Application.Exit();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (count == 0) { pictureBox1.Image = Properties.Resources.markhor1; count++; }
            else
            {
                if (count == 1) { pictureBox1.Image = Properties.Resources.markhor2; count++; }
                else
                {
                    if (count == 2) { pictureBox1.Image = Properties.Resources.markhor3; count++; }
                    else
                        pictureBox1.Image = Properties.Resources.morkhorcomputerdms;
                }
            }
        }
    }
}