using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SinosysHardware.Business;
namespace SinosysHardware.UI
{
    public partial class Splash : Form
    {
        private bool appLoaded;
        public Splash()
        {
            InitializeComponent();
        }

        private void Splash_Load(object sender, EventArgs e)
        {
            //Set this variable to false so that the Activated event
            //will perform its work since this is the first time
            //this screen has been activated
            appLoaded = false;
        }

        private void Splash_Activated(object sender, EventArgs e)
        {
            if (!appLoaded)
            {
            Application.DoEvents();
            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();
            statusBar1.Text = "Searching for local database...";
            System.Threading.Thread.Sleep(2000);
            Application.DoEvents();
             // If database doesn't exist
            Services s = new Services();
            try
            {
                if (!s.DatabaseExists())
                {
                    statusBar1.Text = "同步数据...";
                    Application.DoEvents();
                    s.SyncWithDataSource();
                    statusBar1.Text = "设备端同步数据完成";
                    Application.DoEvents();
                    Cursor.Current = Cursors.Default;
                    Application.DoEvents();
                    appLoaded = true; 
                 
                    
                  
                }
                else
                {
                    appLoaded = true;
                  
                    
                    statusBar1.Text = "设备端数据库已存在！";
                    Application.DoEvents();
                    Cursor.Current = Cursors.Default;
                    Application.DoEvents();
                   
                }

                
            }
            catch (Exception)
            {
                statusBar1.Text = "Shutting down...";
                  Application.DoEvents();
                System.Threading.Thread.Sleep(2000);
                 Application.DoEvents();
                 Cursor.Current = Cursors.Default;
                 Application.Exit();
            }

            }
           
        }

        private void btnOut_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            // Database has been created so load the Logon Screen
            Logon logon = new Logon();
            logon.ShowDialog();
            
        }

       
      

      
    }
}