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

namespace SanSystem
{
    /// <summary>
    /// 
    /// </summary>
    public partial class UCLinerGrundlagen : UserControl
    {
        InlinerSanierung inliner = null;
        /// <summary>
        /// 
        /// </summary>
        public List<Inspektionsobjekt> inspektionsobjekts = null;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inliner"></param>
        public UCLinerGrundlagen(InlinerSanierung inliner)
        {
            InitializeComponent();
            this.inliner = inliner;
        }
        /// <summary>
        /// 
        /// </summary>
        public UCLinerGrundlagen()
        {
            InitializeComponent();
        }



        private void UCLinerGrundlagen_Load(object sender, EventArgs e)
        {
            if(inliner != null)
            {
                btn_save_for_liners.Visible = btn_save_for_liners.Enabled = false;
                txt_walze_distance.DataBindings.Clear();
                txt_vakuum.DataBindings.Clear();
                txt_temp_harz.DataBindings.Clear();
                txt_charge_harz.DataBindings.Clear();
                txt_charge_liner.DataBindings.Clear();
                dt_kalibrierdatum.DataBindings.Clear();
                txt_liner.DataBindings.Clear();
                txt_harz.DataBindings.Clear();

                txt_harz.DataBindings.Add(new Binding("Text", inliner, "HarzTyp"));
                txt_liner.DataBindings.Add(new Binding("Text", inliner, "LinerTyp"));
                txt_walze_distance.DataBindings.Add(new Binding("Text", inliner, "KalibierWalzenAbstand"));
                txt_vakuum.DataBindings.Add(new Binding("Text", inliner, "KalibrierUnterdruck"));
                txt_temp_harz.DataBindings.Add(new Binding("Text", inliner, "HarzKalibrierTemperatur"));
                txt_charge_harz.DataBindings.Add(new Binding("Text", inliner, "HarzChargenummer"));
                txt_charge_liner.DataBindings.Add(new Binding("Text", inliner, "LinerChargenummer"));
                dt_kalibrierdatum.DataBindings.Add(new Binding("Value", inliner, "DatumKalibrierung"));
            }

        }

        private void btn_save_for_liners_Click(object sender, EventArgs e)
        {
            if (inliner != null) return;
            if (inspektionsobjekts == null) throw new Exception("Inspektionsobjekte sind null");

            double walzenabstand = double.Parse(txt_walze_distance.Text);
            double vakuum = double.Parse(txt_vakuum.Text);
            double temp_harz = double.Parse(txt_temp_harz.Text);
            string charge_harz = txt_charge_harz.Text;
            string charge_liner = txt_charge_liner.Text;
            DateTime kalidatum = dt_kalibrierdatum.Value;
            string harztyp = txt_harz.Text;
            string linertyp = txt_liner.Text;

            foreach(Inspektionsobjekt iObj in inspektionsobjekts)
            {
                bool hasAllInliner = false;
                for(int i = 0; i < iObj.Sanierung.Count; i++)
                {
                    if (iObj.Sanierung[i] is InlinerSanierung)
                    {
                        hasAllInliner = true;
                        break;
                    }
                }
                if (hasAllInliner) continue;
                InlinerSanierung inlinerSanierung = new InlinerSanierung();
                inlinerSanierung.DatumKalibrierung = kalidatum;
                inlinerSanierung.HarzChargenummer = charge_harz;
                inlinerSanierung.HarzKalibrierTemperatur = temp_harz;
                inlinerSanierung.HarzTyp = harztyp;
                inlinerSanierung.LinerTyp = linertyp;
                inlinerSanierung.LinerChargenummer = charge_liner;
                inlinerSanierung.KalibierWalzenAbstand = walzenabstand;
                inlinerSanierung.KalibrierUnterdruck = vakuum;
                inlinerSanierung.Inspektionsobjekt = iObj;
                iObj.Sanierung.Add(inlinerSanierung);
            }
            
        }
    }
}
