using Database;
using FluentFTP;
using KlassenBIB;
using SchnittstelleImporter;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SanSystem
{
    /// <summary>
    /// 
    /// </summary>
    public partial class frmMain : Form
    {
        /// <summary>
        /// 
        /// </summary>
        public frmMain()
        {
            InitializeComponent();

            //Global.Instance.
            
            if (!Directory.Exists(Global.Instance.Projektpfad)) Directory.CreateDirectory(Global.Instance.Projektpfad);
            Datenbank.Instance.LoadProjekt(Global.Instance.ProjektNummer, Global.Instance.Projektpfad);//     Path.Combine(Global.Instance.Projektpfad,"18-850.xaml"));

           
            //Datenbank.Instance.CreateProjekt("");
            this.Width = Screen.PrimaryScreen.WorkingArea.Width;
            this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            this.WindowState = FormWindowState.Maximized;
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(0, 0);

            projektToolStripMenuItem.Text = Global.Instance.language.Labels["mainmenu_projekt"];
            neuToolStripMenuItem.Text = Global.Instance.language.Labels["mainmenu_projekt_new"];
            öffnenToolStripMenuItem.Text = Global.Instance.language.Labels["mainmenu_projekt_open"];

            toolStripStatus_projekt_Label.Text = Datenbank.Instance.projekt;
        }

        


        private void frm_main_Load(object sender, EventArgs e)
        {
            
            frmStrassenList strassenList = new frmStrassenList();
            strassenList.MdiParent = this;
            strassenList.Show();
            


            //frmObjektEdit frmObjektEdit = new frmObjektEdit();
            //frmObjektEdit.Show();
        }

        private void frm_main_FormClosing(object sender, FormClosingEventArgs e)
        {
            
            Datenbank.Instance.SaveProjekt();
        }

        private void neuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmNewProjekt frmNewProjekt = new FrmNewProjekt();
            frmNewProjekt.FormClosed += FrmProjektList_FormClosed;
            frmNewProjekt.ShowDialog();
        }

        private void öffnenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //
            frmProjektList frmProjektList = new frmProjektList();

            frmProjektList.FormClosed += FrmProjektList_FormClosed;
            frmProjektList.ShowDialog();
        }

        private void FrmProjektList_FormClosed(object sender, FormClosedEventArgs e)
        {
            toolStripStatus_projekt_Label.Text = Global.Instance.ProjektNummer;
            Form[] openedWindows = this.MdiChildren;
            foreach(Form form in openedWindows)
            {
                form.Close();
                form.Dispose();
            }
            frmStrassenList strassenList = new frmStrassenList();
            strassenList.MdiParent = this;
            strassenList.Top = 0;
            strassenList.Left = 0;
            strassenList.Location = new Point(0, 0);
            strassenList.StartPosition = FormStartPosition.Manual;
            strassenList.Show();
        }

        private void speichernToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Datenbank.Instance.SaveProjekt();
        }

        private void massenstatistikToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSelectMassenDate frmSelectMassenDate = new FrmSelectMassenDate();
            frmSelectMassenDate.ShowDialog();
        }

        private void stammdatenImportierenToolStripMenuItem_Click(object sender, EventArgs e)
        {
#if !DEBUG
            /// DELETE ME
            MessageBox.Show("Diese Funktion ist zur Zeit noch nicht implementiert");
#else
            IImportedObjekte importedObjekte = SchnittstelleImporter.ImportBuilder.Import(ImportSchnittstellen.XML2006);
            importedObjekte.XMLFile = @"C:\Users\Damian\Desktop\XML\3_Zustandsdaten\ISYBAU_XML-2006-Zustandsdaten_DIN_EN_13508-2.xml";
            importedObjekte.Projektnummer = Global.Instance.ProjektNummer;
            Datenbank.Instance.loadedProjekt.Objekte.AddRange(importedObjekte.GetInspektionsobjekte());

            Form[] openedWindows = this.MdiChildren;
            foreach (Form form in openedWindows)
            {
                form.Close();
                form.Dispose();
            }
            frmStrassenList strassenList = new frmStrassenList();
            strassenList.MdiParent = this;
            strassenList.Top = 0;
            strassenList.Left = 0;
            strassenList.Location = new Point(0, 0);
            strassenList.StartPosition = FormStartPosition.Manual;
            strassenList.Show();
#endif
        }
    }
}
