using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BazaZamowien.Classes;

namespace BazaZamowien
{
    public partial class MDImainForm : Form
    {
        private int childFormNumber = 0;

        public MDImainForm()
        {
            InitializeComponent();
            zamowieniaToolStripButton.Enabled = User.getUser().UprZamowienia;
            premieToolStripButton.Enabled = User.getUser().UprPremie;
        }

        private void zamowieniaToolStripButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }

            ZamowieniaForm.getZamowieniaForm(this).WindowState = FormWindowState.Maximized;
            ZamowieniaForm.getZamowieniaForm(this).Show();

            this.Cursor = Cursors.Default;
        }

        private void premieToolStripButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }

            premieForm.getPremieForm(this).WindowState = FormWindowState.Maximized;
            premieForm.getPremieForm(this).Show();

            this.Cursor = Cursors.Default;
        }

        private void MDImainForm_Load(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("SELECT TOP 1 current_version FROM Config");
            cmd.Connection = new SqlConnection(ConnString.getConnString().ZamowieniaConnStr);

            string ver;

            cmd.Connection.Open();
            ver = (string)cmd.ExecuteScalar();
            cmd.Connection.Close();
            
            if (ver.Trim() != Application.ProductVersion.Trim())
            {
                FormBadVer frm = new FormBadVer();
                frm.labelVer.Text += Application.ProductVersion;
                frm.labelSrvVer.Text += ver;
                frm.ShowDialog();
                Close();
               // return;
            }

        }

       
    }
}
