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;

namespace Baza_Reklam
{
    public partial class MDIBazaReklam : Form
    {
        public MDIBazaReklam()
        {
            InitializeComponent();

            if (ConnString.getConnString().Value.Contains("truck"))
            {
                this.Text = "Baza reklam EXPO " + Application.ProductVersion;
                this.toolStrip1.BackColor = Color.MistyRose;
                    //Baza_Reklam.Classes.Version.nrWersji;
            }
            else
            {
                this.Text = "Baza reklam " + Application.ProductVersion;
                //Baza_Reklam.Classes.Version.nrWersji;
            }

           
        }
        
        private void MDIBazaReklam_Load(object sender, EventArgs e)
        {

          
            uprawnienia();
            
            //MessageBox.Show(span.ToString());
        }

        private void uprawnienia()
        {
            startToolStripButton.Enabled = false;
            zamowieniaToolStripButton.Enabled = false;
            klienciToolStripButton.Enabled = false;
            fakturyToolStripButton.Enabled = false;
            raportyToolStripButton.Enabled = false;
            prowizjeToolStripButton.Enabled = false;
            infoToolStripButton.Enabled = false;
            produkcjaToolStripButton.Enabled = false;
            listaReklamToolStripButton.Enabled = false;


            if (User.getUser().St_handlowiec || User.getUser().St_kierownik || User.getUser().St_sekretarka || User.getUser().St_subhandlowiec || User.getUser().St_produkcja)
            {
                zamowieniaToolStripButton.Enabled = true;
                klienciToolStripButton.Enabled = true;
                fakturyToolStripButton.Enabled = true;
                listaReklamToolStripButton.Enabled = true;
            }

            if (User.getUser().St_dtp || User.getUser().St_handlowiec || User.getUser().St_kierownik || User.getUser().St_sekretarka || User.getUser().St_subhandlowiec || User.getUser().St_produkcja)
            {
                raportyToolStripButton.Enabled = true;
                infoToolStripButton.Enabled = true;
            }

            if (User.getUser().St_admin || User.getUser().St_handlowiec || User.getUser().St_kierownik || User.getUser().St_sekretarka || User.getUser().St_subhandlowiec)
            {
                prowizjeToolStripButton.Enabled = true;
            }

            if (User.getUser().St_admin)
            {
                adminToolStripButton.Visible = true;
            }

            produkcjaToolStripButton.Enabled = true;


            if (User.getUser().St_handlowiec || User.getUser().St_kierownik || User.getUser().St_sekretarka || User.getUser().St_subhandlowiec || User.getUser().St_produkcja)
            {
                startToolStripButton.Enabled = true;
                StartForm.getStartForm(this).WindowState = FormWindowState.Maximized;
                StartForm.getStartForm(this).Show();
            }
        }

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

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

            ClientsForm.getClientsForm(this).WindowState = FormWindowState.Maximized;
            ClientsForm.getClientsForm(this).Show();

            this.Cursor = Cursors.Default;

        }

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

            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }
            OrdersForm.getOrderForm(this).WindowState = FormWindowState.Maximized;
            OrdersForm.getOrderForm(this).Show();

            this.Cursor = Cursors.Default;

        }

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

            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }
            FacturesForm.getFacturesForm(this).WindowState = FormWindowState.Maximized;
            FacturesForm.getFacturesForm(this).Show();

            this.Cursor = Cursors.Default;

        }

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

            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }
            ProductionForm.getProductionForm(this).WindowState = FormWindowState.Maximized;
            ProductionForm.getProductionForm(this).Show();

            this.Cursor = Cursors.Default;
        }

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

            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }
            InfoForm.getInfoForm(this).WindowState = FormWindowState.Maximized;
            InfoForm.getInfoForm(this).Show();

            this.Cursor = Cursors.Default;
        }

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

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

            ReportsForm.getReportsForm(this).WindowState = FormWindowState.Maximized;
            ReportsForm.getReportsForm(this).Show();

            this.Cursor = Cursors.Default;
        }

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

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

            ProvisionForm.getProvisionForm(this).WindowState = FormWindowState.Maximized;
            ProvisionForm.getProvisionForm(this).Show();

            this.Cursor = Cursors.Default;
        }

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

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

            StartForm.getStartForm(this).WindowState = FormWindowState.Maximized;
            StartForm.getStartForm(this).Show();

            this.Cursor = Cursors.Default;
        }

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

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

            ListaReklamNaWydanieForm.getListaReklamNaWydanieForm(this).WindowState = FormWindowState.Maximized;
            ListaReklamNaWydanieForm.getListaReklamNaWydanieForm(this).Show();
            
            this.Cursor = Cursors.Default;
        }

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

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

            AdminForm.getAdminForm(this).WindowState = FormWindowState.Maximized;
            AdminForm.getAdminForm(this).Show();

            this.Cursor = Cursors.Default;
        }

        private void koniecToolStripButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MDIBazaReklam_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Czy na pewno chcesz wyjść z programu?", "", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }
            else
                e.Cancel = false;

            string s1 = "";

            try
            {
                foreach (Form childForm in MdiChildren)
                {
                    s1 = childForm.GetType().ToString();
                    childForm.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Formularz: " + s1 + "\n" + ex.ToString());
            }


        }

        private void MDIBazaReklam_FormClosed(object sender, FormClosedEventArgs e)
        {
            //Application.Exit();
            int i = 0;
        }

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

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

            ZestawienieZamowienForm.getZestawienieZamowienForm(this).WindowState = FormWindowState.Maximized;
            ZestawienieZamowienForm.getZestawienieZamowienForm(this).Show();

            this.Cursor = Cursors.Default;

        }

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

            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }
            FacturesFormNEW.getFacturesForm(this).WindowState = FormWindowState.Maximized;
            FacturesFormNEW.getFacturesForm(this).Show();

            this.Cursor = Cursors.Default;
        }

        private void korektaToolStripButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            
            foreach (Form childForm in MdiChildren)
            {
                childForm.Hide();
            }
            KorektyForm.getFacturesForm(this).WindowState = FormWindowState.Maximized;
            KorektyForm.getFacturesForm(this).Show();

            this.Cursor = Cursors.Default;
        }

        private void tsbtnAbout_Click(object sender, EventArgs e)
        {
            //About.getAbout().WindowState = FormWindowState.Maximized;
            About about = new About();
            about.ShowDialog();
        }


                      
    }
}
