JustPaste.it

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;

namespace idojaras
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // 10 percenként beolvassa az adatokat
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMinutes(1);
            timer.Tick += timer_Tick;
            timer.Start();
            void timer_Tick(object sender, EventArgs e) {
                Read(); 
            }
            // A program indulásakor beolvassa a táblázatot
            Read();
            // Title = "Időjós: " + weatherMan;
            var version = typeof(MainWindow ).Assembly.GetName().Version ;
            Title = "Időjárás v"+version.Major + "." + version.Minor;
        }

        // Változók

        string fileName;
        string tableName;
        string weatherMan;

        bool error;
        DateTime tableDate;

        int nightMinimum;
        int nightMaximum;
        int nightIcon;
        int nightWindDirection;
        int nightWindForce;
        int dayMinimum;
        int dayMaximum;
        int dayIcon;
        int dayWindDirection;
        int dayWindForce;
        int day1Minimum;
        int day1Maximum;
        int day1Icon;
        int day1WindDirection;
        int day1WindForce;
        int day2Minimum;
        int day2Maximum;
        int day2Icon;
        int day2WindDirection;
        int day2WindForce;
        int day3Minimum;
        int day3Maximum;
        int day3Icon;
        int day3WindDirection;
        int day3WindForce;

        // A fokokat felkerekíti
        public static int DegreeRoundind(int degree)
        {
            // Ha 360, vagy nagyobb a degreeérték, akkor marad 360
            int value = 360;
            switch (degree)
            {
                // 0 - 44
                case int n when (n >= 0 && n < 45):
                    value = 360;
                    break;
                // 45 - 89
                case int n when (n >= 45 && n < 90):
                    value = 45;
                    break;
                // 90 - 134
                case int n when (n >= 90 && n < 135):
                    value = 90;
                    break;
                // 135 - 179
                case int n when (n >= 135 && n < 180):
                    value = 135;
                    break;
                // 180 - 224
                case int n when (n >= 180 && n < 225):
                    value = 180;
                    break;
                // 225 - 269
                case int n when (n >= 225 && n < 270):
                    value = 225;
                    break;
                // 270 - 359
                case int n when (n >= 270 && n < 315):
                    value = 270;
                    break;
                case int n when (n >= 315 && n < 360):
                    value = 315;
                    break;
            }
            return value;
        }

        // Megjeleníti az adatokat
        public void DataVisualisation()
        {
            label_nightMinimum_ertek.Content = nightMinimum;
            label_nightMaximum_ertek.Content = nightMaximum;
            label_nightIcon.Content = nightIcon;
            label_nightWindDirection.Content = nightWindDirection;
            label_nightWindForce.Content = nightWindForce;
            if (nightWindForce < 0 || nightWindForce > 3) label_nightWindForce.Foreground = Brushes.Red;
            label_dayMinimum_ertek.Content = dayMinimum;
            label_dayMaximum_ertek.Content = dayMaximum;
            label_dayIcon.Content = dayIcon;
            label_dayWindDirection.Content = dayWindDirection;
            label_dayWindForce.Content = dayWindForce;
            if (dayWindForce < 0 || dayWindForce > 3) label_dayWindForce.Foreground = Brushes.Red;
            label_day1Minimum_ertek.Content = day1Minimum;
            label_day1Maximum_ertek.Content = day1Maximum;
            label_day1Icon.Content = day1Icon;
            label_day1WindDirection.Content = day1WindDirection;
            label_day1WindForce.Content = day1WindForce;
            if (day1WindForce < 0 || day1WindForce > 3) label_day1WindForce.Foreground = Brushes.Red;
            label_day2Minimum_ertek.Content = day2Minimum;
            label_day2Maximum_ertek.Content = day2Maximum;
            label_day2Icon.Content = day2Icon;
            label_day2WindDirection.Content = day2WindDirection;
            label_day2WindForce.Content = day2WindForce;
            if (day2WindForce < 0 || day2WindForce > 3) label_day2WindForce.Foreground = Brushes.Red;
            label_day3Minimum_ertek.Content = day3Minimum;
            label_day3Maximum_ertek.Content = day3Maximum;
            label_day3Icon.Content = day3Icon;
            label_day3WindDirection.Content = day3WindDirection;
            label_day3WindForce.Content = day3WindForce;
            if (day3WindForce < 0 || dayWindForce > 3) label_day3WindForce.Foreground = Brushes.Red;
            label_tableDate.Content = tableDate.ToShortDateString();
            label_weatherManName.Content  = weatherMan;
        }

        // Törli a változókat
        public void DeleteVariables()
        {
            nightMinimum = 0;
            nightMaximum = 0;
            nightIcon = 0;
            nightWindDirection = 0;
            nightWindForce = 0;
            dayMinimum = 0;
            dayMaximum = 0;
            dayIcon = 0;
            dayWindDirection = 0;
            dayWindForce = 0;
            day1Minimum = 0;
            day1Maximum = 0;
            day1Icon = 0;
            day1WindDirection = 0;
            day1WindForce = 0;
            day2Minimum = 0;
            day2Maximum = 0;
            day2Icon = 0;
            day2WindDirection = 0;
            day2WindForce = 0;
            day3Minimum = 0;
            day3Maximum = 0;
            day3Icon = 0;
            day3WindDirection = 0;
            day3WindForce = 0;
            weatherMan = "";
        }

        // Retrieve the value of a cell, given a file name, sheet name, 
        // and address name.
        public void GetCellValues(string fileName, string sheetName)
        {
            string addressName = null;
            string data = null;
            // Open the spreadsheet document for read-only access.
            using (SpreadsheetDocument document =
                SpreadsheetDocument.Open(fileName, false))
            {
                // Retrieve a reference to the workbook part.
                WorkbookPart wbPart = document.WorkbookPart;

                // Find the sheet with the supplied name, and then use that 
                // Sheet object to retrieve a reference to the first worksheet.
                Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().
                  Where(s => s.Name == sheetName).FirstOrDefault();

                // Throw an exception if there is no sheet.
                if (theSheet == null)
                {
                    throw new ArgumentException("sheetName");
                }

                // Retrieve a reference to the worksheet part.
                WorksheetPart wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id));

                // Éjjel
                addressName = "B4";
                Cell theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                // If the cell does not exist, return an empty string.
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") nightMinimum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az éjszakai minimum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "C4";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") nightMaximum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az éjszakai maximum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "D4";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") nightIcon = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az éjszakai ikon nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "E4";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") nightWindDirection = DegreeRoundind(int.Parse(data));
                    else
                    {
                        MessageBox.Show("Az éjszakai szélirány nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "F4";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") nightWindForce = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az éjszakai szélerő nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                // Nappal
                addressName = "B5";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") dayMinimum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A nappali minimum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "C5";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") dayMaximum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A nappali maximum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "D5";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") dayIcon = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A nappali ikon nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "E5";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") dayWindDirection = DegreeRoundind(int.Parse(data));
                    else
                    {
                        MessageBox.Show("A nappali szélirány nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "F5";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") dayWindForce = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A nappali szélerő nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                // day1 
                addressName = "B7";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day1Minimum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az 1.nap minimum hőmérséklete nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "C7";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day1Maximum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az 1.nap maximum hőmérséklete nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "D7";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day1Icon = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az 1.nap ikonja nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "E7";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day1WindDirection = DegreeRoundind(int.Parse(data));
                    else
                    {
                        MessageBox.Show("Az 1.napi széleirány nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "F7";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day1WindForce = int.Parse(data);
                    else
                    {
                        MessageBox.Show("Az 1.napi szélerő nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                // day2 
                addressName = "B8";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day2Minimum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 2.napi minimum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "C8";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day2Maximum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 2.napi maximum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "D8";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day2Icon = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 2.napi ikon nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "E8";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day2WindDirection = DegreeRoundind(int.Parse(data));
                    else
                    {
                        MessageBox.Show("A 2.napi szélirány nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "F8";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day2WindForce = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 2.napi szélerő nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                // day3 
                addressName = "B9";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day3Minimum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 3.napi minimum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "C9";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day3Maximum = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 3.napi maximum hőmérséklet nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "D9";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day3Icon = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 3.napi ikon nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "E9";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day3WindDirection = DegreeRoundind(int.Parse(data));
                    else
                    {
                        MessageBox.Show("A 3.napi szélirány nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "F9";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "") day3WindForce = int.Parse(data);
                    else
                    {
                        MessageBox.Show("A 3.napi szélerő nincs kitöltve");
                        error = true;
                        return;
                    }
                }
                addressName = "B1";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    if (data != "")
                    {
                        tableDate = DateTime.FromOADate(double.Parse(data, CultureInfo.InvariantCulture));
                        if (tableDate.ToShortDateString().Equals(DateTime.Now.ToShortDateString()))
                        {
                            label_tableDate.Foreground = Brushes.Green;
                        }
                        else
                        {
                            label_tableDate.Foreground = Brushes.Red;
                            error = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show("A dátum nincs kitöltve");
                        error = true;
                        return;
                    }
                    addressName = "B1";
                    theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                    if (theCell != null)
                    {
                        data = theCell.InnerText;
                        if (data != "")
                        {
                            tableDate = DateTime.FromOADate(double.Parse(data, CultureInfo.InvariantCulture));
                            if (tableDate.ToShortDateString().Equals(DateTime.Now.ToShortDateString()))
                            {
                                label_tableDate.Foreground = Brushes.Green;
                            }
                            else
                            {
                                label_tableDate.Foreground = Brushes.Red;
                                error = true;
                            }
                        }
                        else
                        {
                            MessageBox.Show("A dátum nincs kitöltve");
                            error = true;
                            return;
                        }
                    }
                }

                // Az időjelző neve
                addressName = "E1";
                theCell = wsPart.Worksheet.Descendants<Cell>().Where(c => c.CellReference == addressName).FirstOrDefault();
                if (theCell != null)
                {
                    data = theCell.InnerText;
                    var stringTable = wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
                    if (stringTable != null)
                    {
                        data = stringTable.SharedStringTable.ElementAt(int.Parse(data)).InnerText;
                    }
                    if (data != "") weatherMan = data;
                }
            }
        }

        // Az adatok elmentése
        public void Save()
        {
            int tomorrow;
            // tomorrow, vagyis +1
            tomorrow = (int)tableDate.DayOfWeek + 1;
            // lista elkészítése
            string[] list = new string[46];
            list[0] = "HOLNAP = \"" + tomorrow + "\";";
            list[1] = "N1 = \"" + dayMinimum + "\";";
            list[2] = "N2 = \"" + dayMaximum + "\";";
            list[3] = "N3 = \"" + dayIcon + "\";";
            list[4] = "N4 = \"" + dayWindDirection + "\";";
            list[5] = "N5 = \"" + dayWindForce + "\";";
            list[6] = "E1 = \"" + nightMinimum + "\";";
            list[7] = "E2 = \"" + nightMaximum + "\";";
            list[8] = "E3 = \"" + nightIcon + "\";";
            list[9] = "E4 = \"" + nightWindDirection + "\";";
            list[10] = "E5 = \"" + nightWindForce + "\";";
            list[11] = "A1 = \"" + day1Minimum + "\";";
            list[12] = "A2 = \"" + day1Maximum + "\";";
            list[13] = "A3 = \"" + day1Icon + "\";";
            list[14] = "A4 = \"" + day1WindDirection + "\";";
            list[15] = "A5 = \"" + day1WindForce + "\";";
            list[16] = "B1 = \"" + day2Minimum + "\";";
            list[17] = "B2 = \"" + day2Maximum + "\";";
            list[18] = "B3 = \"" + day2Icon + "\";";
            list[19] = "B4 = \"" + day2WindDirection + "\";";
            list[20] = "B5 = \"" + day2WindForce + "\";";
            list[21] = "C1 = \"" + day3Minimum + "\";";
            list[22] = "C2 = \"" + day3Maximum + "\";";
            list[23] = "C3 = \"" + day3Icon + "\";";
            list[24] = "C4 = \"" + day3WindDirection + "\";";
            list[25] = "C5 = \"" + day3WindForce + "\";";
            //// Hétfő
            //switch (DayHelper.DaysToMonday(tableDate))
            //{
            //    case 2:
            //        list[11] = "H1 = \"" + day1Minimum + "\";";
            //        list[12] = "H2 = \"" + day1Maximum + "\";";
            //        list[13] = "H3 = \"" + day1Icon + "\";";
            //        list[14] = "H4 = \"" + day1WindDirection + "\";";
            //        list[15] = "H5 = \"" + day1WindForce + "\";";
            //        break;
            //    case 3:
            //        list[11] = "H1 = \"" + day2Minimum + "\";";
            //        list[12] = "H2 = \"" + day2Maximum + "\";";
            //        list[13] = "H3 = \"" + day2Icon + "\";";
            //        list[14] = "H4 = \"" + day2WindDirection + "\";";
            //        list[15] = "H5 = \"" + day2WindForce + "\";";
            //        break;
            //    case 4:
            //        list[11] = "H1 = \"" + day3Minimum + "\";";
            //        list[12] = "H2 = \"" + day3Maximum + "\";";
            //        list[13] = "H3 = \"" + day3Icon + "\";";
            //        list[14] = "H4 = \"" + day3WindDirection + "\";";
            //        list[15] = "H5 = \"" + day3WindForce + "\";";
            //        break;
            //    default:
            //        list[11] = "H1 = \"\";";
            //        list[12] = "H2 = \"\";";
            //        list[13] = "H3 = \"\";";
            //        list[14] = "H4 = \"\";";
            //        list[15] = "H5 = \"\";";
            //        break;
            //}
            //// Kedd
            //switch (DayHelper.DaysToTuesday(tableDate))
            //{
            //    case 2:
            //        list[16] = "K1 = \"" + day1Minimum + "\";";
            //        list[17] = "K2 = \"" + day1Maximum + "\";";
            //        list[18] = "K3 = \"" + day1Icon + "\";";
            //        list[19] = "K4 = \"" + day1WindDirection + "\";";
            //        list[20] = "K5 = \"" + day1WindForce + "\";";
            //        break;
            //    case 3:
            //        list[16] = "K1 = \"" + day2Minimum + "\";";
            //        list[17] = "K2 = \"" + day2Maximum + "\";";
            //        list[18] = "K3 = \"" + day2Icon + "\";";
            //        list[19] = "K4 = \"" + day2WindDirection + "\";";
            //        list[20] = "K5 = \"" + day2WindForce + "\";";
            //        break;
            //    case 4:
            //        list[16] = "K1 = \"" + day3Minimum + "\";";
            //        list[17] = "K2 = \"" + day3Maximum + "\";";
            //        list[18] = "K3 = \"" + day3Icon + "\";";
            //        list[19] = "K4 = \"" + day3WindDirection + "\";";
            //        list[20] = "K5 = \"" + day3WindForce + "\";";
            //        break;
            //    default:
            //        list[16] = "K1 = \"\";";
            //        list[17] = "K2 = \"\";";
            //        list[18] = "K3 = \"\";";
            //        list[19] = "K4 = \"\";";
            //        list[20] = "K5 = \"\";";
            //        break;
            //}
            //// Szerda
            //switch (DayHelper.DaysToWednesday(tableDate))
            //{
            //    case 2:
            //        list[21] = "SZE1 = \"" + day1Minimum + "\";";
            //        list[22] = "SZE2 = \"" + day1Maximum + "\";";
            //        list[23] = "SZE3 = \"" + day1Icon + "\";";
            //        list[24] = "SZE4 = \"" + day1WindDirection + "\";";
            //        list[25] = "SZE5 = \"" + day1WindForce + "\";";
            //        break;
            //    case 3:
            //        list[21] = "SZE1 = \"" + day2Minimum + "\";";
            //        list[22] = "SZE2 = \"" + day2Maximum + "\";";
            //        list[23] = "SZE3 = \"" + day2Icon + "\";";
            //        list[24] = "SZE4 = \"" + day2WindDirection + "\";";
            //        list[25] = "SZE5 = \"" + day2WindForce + "\";";
            //        break;
            //    case 4:
            //        list[21] = "SZE1 = \"" + day3Minimum + "\";";
            //        list[22] = "SZE2 = \"" + day3Maximum + "\";";
            //        list[23] = "SZE3 = \"" + day3Icon + "\";";
            //        list[24] = "SZE4 = \"" + day3WindDirection + "\";";
            //        list[25] = "SZE5 = \"" + day3WindForce + "\";";
            //        break;
            //    default:
            //        list[21] = "SZE1 = \"\";";
            //        list[22] = "SZE2 = \"\";";
            //        list[23] = "SZE3 = \"\";";
            //        list[24] = "SZE4 = \"\";";
            //        list[25] = "SZE5 = \"\";";
            //        break;
            //}
            //// Csütörtök
            //switch (DayHelper.DaysToThursday(tableDate))
            //{
            //    case 2:
            //        list[26] = "CS1 = \"" + day1Minimum + "\";";
            //        list[27] = "CS2 = \"" + day1Maximum + "\";";
            //        list[28] = "CS3 = \"" + day1Icon + "\";";
            //        list[29] = "CS4 = \"" + day1WindDirection + "\";";
            //        list[30] = "CS5 = \"" + day1WindForce + "\";";
            //        break;
            //    case 3:
            //        list[26] = "CS1 = \"" + day2Minimum + "\";";
            //        list[27] = "CS2 = \"" + day2Maximum + "\";";
            //        list[28] = "CS3 = \"" + day2Icon + "\";";
            //        list[29] = "CS4 = \"" + day2WindDirection + "\";";
            //        list[30] = "CS5 = \"" + day2WindForce + "\";";
            //        break;
            //    case 4:
            //        list[26] = "CS1 = \"" + day3Minimum + "\";";
            //        list[27] = "CS2 = \"" + day3Maximum + "\";";
            //        list[28] = "CS3 = \"" + day3Icon + "\";";
            //        list[29] = "CS4 = \"" + day3WindDirection + "\";";
            //        list[30] = "CS5 = \"" + day3WindForce + "\";";
            //        break;
            //    default:
            //        list[26] = "CS1 = \"\";";
            //        list[27] = "CS2 = \"\";";
            //        list[28] = "CS3 = \"\";";
            //        list[29] = "CS4 = \"\";";
            //        list[30] = "CS5 = \"\";";
            //        break;
            //}
            //// Péntek
            //switch (DayHelper.DaysToFriday(tableDate))
            //{
            //    case 2:
            //        list[31] = "P1 = \"" + day1Minimum + "\";";
            //        list[32] = "P2 = \"" + day1Maximum + "\";";
            //        list[33] = "P3 = \"" + day1Icon + "\";";
            //        list[34] = "P4 = \"" + day1WindDirection + "\";";
            //        list[35] = "P5 = \"" + day1WindForce + "\";";
            //        break;
            //    case 3:
            //        list[31] = "P1 = \"" + day2Minimum + "\";";
            //        list[32] = "P2 = \"" + day2Maximum + "\";";
            //        list[33] = "P3 = \"" + day2Icon + "\";";
            //        list[34] = "P4 = \"" + day2WindDirection + "\";";
            //        list[35] = "P5 = \"" + day2WindForce + "\";";
            //        break;
            //    case 4:
            //        list[31] = "P1 = \"" + day3Minimum + "\";";
            //        list[32] = "P2 = \"" + day3Maximum + "\";";
            //        list[33] = "P3 = \"" + day3Icon + "\";";
            //        list[34] = "P4 = \"" + day3WindDirection + "\";";
            //        list[35] = "P5 = \"" + day3WindForce + "\";";
            //        break;
            //    default:
            //        list[31] = "P1 = \"\";";
            //        list[32] = "P2 = \"\";";
            //        list[33] = "P3 = \"\";";
            //        list[34] = "P4 = \"\";";
            //        list[35] = "P5 = \"\";";
            //        break;
            //}
            //// Szombat
            //switch (DayHelper.DaysToSaturday(tableDate))
            //{
            //    case 2:
            //        list[36] = "SZO1 = \"" + day1Minimum + "\";";
            //        list[37] = "SZO2 = \"" + day1Maximum + "\";";
            //        list[38] = "SZO3 = \"" + day1Icon + "\";";
            //        list[39] = "SZO4 = \"" + day1WindDirection + "\";";
            //        list[40] = "SZO5 = \"" + day1WindForce + "\";";
            //        break;
            //    case 3:
            //        list[36] = "SZO1 = \"" + day2Minimum + "\";";
            //        list[37] = "SZO2 = \"" + day2Maximum + "\";";
            //        list[38] = "SZO3 = \"" + day2Icon + "\";";
            //        list[39] = "SZO4 = \"" + day2WindDirection + "\";";
            //        list[40] = "SZO5 = \"" + day2WindForce + "\";";
            //        break;
            //    case 4:
            //        list[36] = "SZO1 = \"" + day3Minimum + "\";";
            //        list[37] = "SZO2 = \"" + day3Maximum + "\";";
            //        list[38] = "SZO3 = \"" + day3Icon + "\";";
            //        list[39] = "SZO4 = \"" + day3WindDirection + "\";";
            //        list[40] = "SZO5 = \"" + day3WindForce + "\";";
            //        break;
            //    default:
            //        list[36] = "SZO1 = \"\";";
            //        list[37] = "SZO2 = \"\";";
            //        list[38] = "SZO3 = \"\";";
            //        list[39] = "SZO4 = \"\";";
            //        list[40] = "SZO5 = \"\";";
            //        break;
            //}
            //// Vasárnap
            //switch (DayHelper.DaysToSunday(tableDate))
            //{
            //    case 2:
            //        list[41] = "V1 = \"" + day1Minimum + "\";";
            //        list[42] = "V2 = \"" + day1Maximum + "\";";
            //        list[43] = "V3 = \"" + day1Icon + "\";";
            //        list[44] = "V4 = \"" + day1WindDirection + "\";";
            //        list[45] = "V5 = \"" + day1WindForce + "\";";
            //        break;
            //    case 3:
            //        list[41] = "V1 = \"" + day2Minimum + "\";";
            //        list[42] = "V2 = \"" + day2Maximum + "\";";
            //        list[43] = "V3 = \"" + day2Icon + "\";";
            //        list[44] = "V4 = \"" + day2WindDirection + "\";";
            //        list[45] = "V5 = \"" + day2WindForce + "\";";
            //        break;
            //    case 4:
            //        list[41] = "V1 = \"" + day3Minimum + "\";";
            //        list[42] = "V2 = \"" + day3Maximum + "\";";
            //        list[43] = "V3 = \"" + day3Icon + "\";";
            //        list[44] = "V4 = \"" + day3WindDirection + "\";";
            //        list[45] = "V5 = \"" + day3WindForce + "\";";
            //        break;
            //    default:
            //        list[41] = "V1 = \"\";";
            //        list[42] = "V2 = \"\";";
            //        list[43] = "V3 = \"\";";
            //        list[44] = "V4 = \"\";";
            //        list[45] = "V5 = \"\";";
            //        break;
            //}
            // adatok kiírása
            fileName = Environment.CurrentDirectory + "\\adatok.txt";
            System.IO.StreamWriter objWriter;
            objWriter = new System.IO.StreamWriter(fileName);
            for (int i = 0; i < 26; i++)
            {
                objWriter.WriteLine(list[i]);
            }
            objWriter.Close();
            button.IsEnabled = false;
            button.Content = "Kész";
        }

        // A táblázat beolvasása
        public void Read()
        {
            DeleteVariables();
            fileName = Environment.CurrentDirectory + "\\időjárás.xlsx";
            WebClient webClient = new WebClient();
            webClient.DownloadFile("https://onedrive.live.com/download?resid=titok1&authkey=titok2&em=3", @fileName);
            tableName = "Időjárás";
            label_lastRead.Content = "Az utolsó beolvasás ideje: " + DateTime.Now.ToString("HH:mm:ss");
            error = false;
            GetCellValues(fileName, tableName);
            // Az adatok kiírása
            DataVisualisation();
            if (error)
            {

                button.Content = "Adatok beolvasása";
                button.IsEnabled = true;
            }
            else
            {
                Save();
                button.Content = "Kész";
                button.IsEnabled = true;
            }

        }

        // A nyomógom feliatától függő funkciók végrehajtása
        private void Processor(object sender, RoutedEventArgs e)
        {
            switch (button.Content)
            {
                case "Adatok beolvasása":
                    button.IsEnabled = false;
                    // A táblázat letöltése
                    Read();
                    break;

                case "Kész":
                    System.Environment.Exit(0);
                    break;
            }
        }
    }
    public static class DayHelper
    {
        public static int DaysToMonday(this DateTime date)
        {
            var today = date.DayOfWeek;
            var offset = DayOfWeek.Monday - today;
            return offset >= 0 ? offset : 7 + offset;
        }
        public static int DaysToTuesday(this DateTime date)
        {
            var today = date.DayOfWeek;
            var offset = DayOfWeek.Tuesday - today;
            return offset >= 0 ? offset : 7 + offset;
        }
        public static int DaysToWednesday(this DateTime date)
        {
            var today = date.DayOfWeek;
            var offset = DayOfWeek.Wednesday - today;
            return offset >= 0 ? offset : 7 + offset;
        }
        public static int DaysToThursday(this DateTime date)
        {
            var today = date.DayOfWeek;
            var offset = DayOfWeek.Thursday - today;
            return offset >= 0 ? offset : 7 + offset;
        }
        public static int DaysToFriday(this DateTime date)
        {
            var today = date.DayOfWeek;
            var offset = DayOfWeek.Friday - today;
            return offset >= 0 ? offset : 7 + offset;
        }
        public static int DaysToSaturday(this DateTime date)
        {
            var today = date.DayOfWeek;
            var offset = DayOfWeek.Saturday - today;
            return offset >= 0 ? offset : 7 + offset;
        }
        public static int DaysToSunday(this DateTime date)
        {
            var today = date.DayOfWeek;
            var offset = DayOfWeek.Sunday - today;
            return offset >= 0 ? offset : 7 + offset;
        }
    }
}