using Syncfusion.Windows.Forms.Chart;
using System;
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.Tasks;
using System.Windows.Forms;

namespace SanSystem
{
    public partial class FrmLinerChart : Form
    {
        public FrmLinerChart()
        {
            InitializeComponent();
            
        }

        public void SaveChart()
        {
            Size size = new Size(800, 400);
            ChartControl chartControl = new ChartControl();
            chartControl.Size = size;

            ChartAxis axis = chartControl.PrimaryYAxis;
            ChartAxis axis0 = new ChartAxis(ChartOrientation.Vertical);
            ChartAxis axis1 = new ChartAxis(ChartOrientation.Vertical);

            ChartAxisLayout layout1 = new ChartAxisLayout();
            ChartAxisLayout layout2 = new ChartAxisLayout();

            chartControl.Axes.Add(axis0);
            chartControl.Axes.Add(axis1);

            layout1.Spacing = 12;
            layout2.Spacing = 12;
            layout1.Axes.Add(axis);
            layout2.Axes.Add(axis0);
            layout2.Axes.Add(axis1);

            chartControl.ChartArea.YLayouts.Add(layout1);
            chartControl.ChartArea.YLayouts.Add(layout2);

            ChartSeries temperaturChart = new ChartSeries("Temperatur", ChartSeriesType.Line);
            ChartSeries druckChart = new ChartSeries("Druck", ChartSeriesType.Line);

            string[] input = File.ReadAllLines(@"C:\Users\Damian\Desktop\SanVerwaltung\SanSystem\bin\Debug\projekte\18-850\SW01-SW02\UVAnlage\Trend\Trend022.csv");
            int counter = 0;
            foreach (string pars in input)
            {
                string[] parts = pars.Split(',');
                if (parts[0].Equals("Group1") || parts[1].Equals("(END)")) continue;
                double temperatur = double.Parse(parts[1].Replace('.', ','));
                double druck = double.Parse(parts[2].Replace('.', ','));

                temperaturChart.Points.Add(counter, temperatur);
                druckChart.Points.Add(counter, druck);
                counter++;

            }
            temperaturChart.YAxis = axis;
            druckChart.YAxis = axis0;

            axis.Title = "°C";
            axis.TitleFont = new Font("Segeo UI", 14F);

            axis0.Title = "[bar]";
            axis0.TitleFont = new Font("Segeo UI", 14F);

            chartControl.LegendsPlacement = ChartPlacement.Outside;
            chartControl.LegendPosition = ChartDock.Bottom;
            chartControl.LegendAlignment = ChartAlignment.Center;
            chartControl.Title.Visible = false;

            ChartAxis chartAxis = new ChartAxis();
            chartAxis.Orientation = ChartOrientation.Horizontal;
            chartAxis.Range = new MinMaxInfo(0, 6, 1);
            chartAxis.DrawGrid = false;
            chartAxis.LineType.Width = 1F;
            chartAxis.LineType.ForeColor = Color.Black;
            chartControl.Axes.Add(chartAxis);

            chartControl.Series.Add(temperaturChart);
            chartControl.Series.Add(druckChart);
            chartControl.Skins = Skins.Metro;


            axis1.OpposedPosition = true;
            axis.EdgeLabelsDrawingMode = ChartAxisEdgeLabelsDrawingMode.Shift;
            axis0.EdgeLabelsDrawingMode = ChartAxisEdgeLabelsDrawingMode.Shift;
            axis1.EdgeLabelsDrawingMode = ChartAxisEdgeLabelsDrawingMode.Shift;

            chartControl.SaveImage("./temp.jpg");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SaveChart();
        }
    }
}
