using SanShared;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BerichtGen
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FrmOptions : Form
    {
        Thread generateProtokollThread;
        Hashtable grundDaten;
        string firma;
        string vorlage;
        string speicherpfad;
        string source;
        string filename;
        List<BilderObject> bilderObjects;

        DataTable tableContent = null;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="firma"></param>
        /// <param name="vorlage"></param>
        /// <param name="speicherpfad"></param>
        /// <param name="filename"></param>
        /// <param name="grunddaten"></param>
        /// <param name="bilderObjects"></param>
        /// <param name="tableContent"></param>
        public FrmOptions(string firma, string vorlage, string speicherpfad,string filename, Hashtable grunddaten, List<BilderObject> bilderObjects, DataTable tableContent = null)
        {
            InitializeComponent();

            this.firma = firma;
            this.vorlage = vorlage;
            this.speicherpfad = speicherpfad;
            this.grundDaten = grunddaten;
            this.bilderObjects = bilderObjects;
            this.tableContent = tableContent;
            this.source = Path.Combine("documents", firma, vorlage);
            this.filename = filename;
        }

        void Gen()
        {
            Bericht bericht = new Bericht();
            bericht.Erzeuge(source, speicherpfad,filename, grundDaten, bilderObjects, tableContent,cb_doc.Checked,cb_pdf.Checked);
        }

        private void btn_start_Click(object sender, EventArgs e)
        {
            generateProtokollThread = new Thread(Gen);
            generateProtokollThread.IsBackground = true;
            generateProtokollThread.Start();

            while (generateProtokollThread.IsAlive)
            {

            }

            if (rb_yes.Checked && cb_pdf.Checked)
            {
                string pfad = Path.Combine(speicherpfad, string.Format("{0}.pdf", filename));
                FrmPDFViewer frmPDFViewer = new FrmPDFViewer(pfad);
                frmPDFViewer.ShowDialog();
            }

            this.Close();
        }
    }
}
