using System;
using System.Windows.Forms;
using TinyHeels.App_Code;
using System.Data.SqlClient;
namespace TinyHeels
{
    public partial class Dashboard : Form
    {
        public Dashboard()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            loadTime();
        }
        public void loadTime()
        {
            try
            {
                string time = DateTime.Now.ToString("dddd, MMMM d, yyyy hh:mm:ss:tt");
                lblTime.Text = time;
            }
            catch (Exception ex)
            {

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            slider.Height = button1.Height;
            slider.Top = button1.Top;

            //-------------------------

            if (!panelX.Controls.Contains(controlDashboard.Instance))
            {
                panelX.Controls.Add(controlDashboard.Instance);
                controlDashboard.Instance.Dock = DockStyle.Fill;
                controlDashboard.Instance.BringToFront();
            }
            else
            {
                controlDashboard.Instance.BringToFront();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            slider.Height = button2.Height;
            slider.Top = button2.Top;

            //-------------------------

            if (!panelX.Controls.Contains(controlStock.Instance))
            {
                panelX.Controls.Add(controlStock.Instance);
                controlStock.Instance.Dock = DockStyle.Fill;
                controlStock.Instance.BringToFront();
            }
            else
            {
                controlStock.Instance.BringToFront();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            slider.Height = button3.Height;
            slider.Top = button3.Top;
            if (!panelX.Controls.Contains(controlSales.Instance))
            {
                panelX.Controls.Add(controlSales.Instance);
                controlSales.Instance.Dock = DockStyle.Fill;
                controlSales.Instance.BringToFront();
            }
            else
            {
                controlSales.Instance.BringToFront();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            slider.Height = button4.Height;
            slider.Top = button4.Top;

            //-------------------------
            if (!panelX.Controls.Contains(controlExpenditure.Instance))
            {
                panelX.Controls.Add(controlExpenditure.Instance);
                controlExpenditure.Instance.Dock = DockStyle.Fill;
                controlExpenditure.Instance.BringToFront();
            }
            else
            {
                controlExpenditure.Instance.BringToFront();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            slider.Height = button5.Height;
            slider.Top = button5.Top;

            //-------------------------
            if (!panelX.Controls.Contains(controlEmployee.Instance))
            {
                panelX.Controls.Add(controlEmployee.Instance);
                controlEmployee.Instance.Dock = DockStyle.Fill;
                controlEmployee.Instance.BringToFront();
            }
            else
            {
                controlEmployee.Instance.BringToFront();
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            slider.Height = button6.Height;
            slider.Top = button6.Top;

            //-------------------------
            if (!panelX.Controls.Contains(controlManagement.Instance))
            {
                panelX.Controls.Add(controlManagement.Instance);
                controlManagement.Instance.Dock = DockStyle.Fill;
                controlManagement.Instance.BringToFront();
            }
            else
            {
                controlManagement.Instance.BringToFront();
            }
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

            YesNo obj = new YesNo("Do you want to exit?");
            obj.ShowDialog();
            if (Common.command == true)
            {
                BackupData();
                Environment.Exit(0);
            }
            else
            {
            }
        }
        public void BackupData()
        {
            string str = @"data source=(local)\SQLEXPRESS; database=TinyHeels; integrated security = SSPI";
            SqlConnection con = new SqlConnection(str);
            con.Open();
            try
            {
                string cmd = "BACKUP DATABASE [TinyHeels] TO DISK='" + "D:\\Backup" + "\\Classic" + "-" + DateTime.Now.ToString("yyyy-MM-dd-mm-ss") + ".bak'";
                using (SqlCommand command = new SqlCommand(cmd, con))
                {
                    command.ExecuteNonQuery();
                    con.Close();
                    ErrorBox d = new ErrorBox("Done");
                    d.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                con.Close();
                ErrorBox er = new ErrorBox("You should select a valid path");
                er.ShowDialog();
            }
        }
    }
}
