using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Globalization;


namespace meteo
{
    public partial class data : Form
    {
        
        DataTable myTable = new DataTable("myTable");

        public data()
        {
            InitializeComponent();
        }
      
        private void bt_menu_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
        private void bt_nacti_Click_1(object sender, EventArgs e)
        {
            myTable.Rows.Clear();
            dg1.DataSource = myTable;
            //dg1.Rows.Clear();
            OpenFileDialog openFile = new OpenFileDialog();
            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string filePath = openFile.FileName;
                StreamReader sr = new StreamReader(filePath);
                string dataRow = ""; // Variable to store each row.

                // Object array used to store each line of data from the text file.
                object[] row;
                //headerRow = sr.ReadLine().Split(';'); // Read the first line of the text file.
                //columns = headerRow.Length;// Store the length of headerRow string array, this will tell us how many columns we need.

                while ((dataRow = sr.ReadLine()) != null)
                {
                    if (dataRow != "")
                    {
                        row = dataRow.Split(';'); // Split the dataRow string variable and store each data into an Object array.
                        myTable.Rows.Add(row);
                        //dg1.Rows.Add(row); // Add the row.
                    }
                }
            }
            int count2 = dg1.BindingContext[dg1.DataSource].Count;
            //int count2 = ((List<string>)dg1.DataSource).Count -1 ;
            //int count2 = dg1.RowCount - 1;
            label6.Text = "Total polozek: " + count2.ToString();

            if (dg1 != null)
            {

            }

            
                               
               if (dg1.BindingContext[dg1.DataSource].Count != 1)  //jen kdyz je neco v tabulce
             {
                 for (int i = 1; i < dg1.BindingContext[dg1.DataSource].Count - 1; i++)
                {
                    if ((myTable.Rows[i][0].ToString()) != (myTable.Rows[i - 1][0].ToString()))
                    {
                        //dm1.Items.Add(myTable.Rows[i][0].ToString());
                        //dm2.Items.Add(myTable.Rows[i][0].ToString());
                    }
                }

                bt_search.Enabled = true;
                
            }
            else
            {
                bt_search.Enabled = false;
            }
            
        }

        private void on_load(object sender, EventArgs e)
        {
            //Create a DataColumn and set various properties. 
            DataColumn myDatum = new DataColumn();
            myDatum.DataType = System.Type.GetType("System.String");
            myDatum.AllowDBNull = false;
            myDatum.Caption = "Datum";
            myDatum.ColumnName = "Datum";
            myDatum.DefaultValue = 25;
            myTable.Columns.Add(myDatum);

            DataColumn myCas = new DataColumn();
            myCas.DataType = System.Type.GetType("System.String");
            myCas.AllowDBNull = false;
            myCas.Caption = "Cas";
            myCas.ColumnName = "Cas";
            myCas.DefaultValue = 25;
            myTable.Columns.Add(myCas);

            DataColumn myTeplota = new DataColumn();
            myTeplota.DataType = System.Type.GetType("System.String");
            myTeplota.AllowDBNull = false;
            myTeplota.Caption = "Teplota";
            myTeplota.ColumnName = "Teplota";
            myTeplota.DefaultValue = 25;
            myTable.Columns.Add(myTeplota);

            DataColumn myRosny = new DataColumn();
            myRosny.DataType = System.Type.GetType("System.String");
            myRosny.AllowDBNull = false;
            myRosny.Caption = "Rosny bod";
            myRosny.ColumnName = "Rosny bod";
            myRosny.DefaultValue = 25;
            myTable.Columns.Add(myRosny);

            DataColumn myVlhkost = new DataColumn();
            myVlhkost.DataType = System.Type.GetType("System.String");
            myVlhkost.AllowDBNull = false;
            myVlhkost.Caption = "Vlhkost";
            myVlhkost.ColumnName = "Vlhkost";
            myVlhkost.DefaultValue = 25;
            myTable.Columns.Add(myVlhkost);

            DataColumn myTlak = new DataColumn();
            myTlak.DataType = System.Type.GetType("System.String");
            myTlak.AllowDBNull = false;
            myTlak.Caption = "Tlak";
            myTlak.ColumnName = "Tlak";
            myTlak.DefaultValue = 25;
            myTable.Columns.Add(myTlak);

            DataColumn mySrazky = new DataColumn();
            mySrazky.DataType = System.Type.GetType("System.String");
            mySrazky.AllowDBNull = false;
            mySrazky.Caption = "Srazky";
            mySrazky.ColumnName = "Srazky";
            mySrazky.DefaultValue = 25;
            myTable.Columns.Add(mySrazky);

            DataColumn myRychlost = new DataColumn();
            myRychlost.DataType = System.Type.GetType("System.String");
            myRychlost.AllowDBNull = false;
            myRychlost.Caption = "Rychlost";
            myRychlost.ColumnName = "Rychlost";
            myRychlost.DefaultValue = 25;
            myTable.Columns.Add(myRychlost);

            dg1.DataSource = myTable;           

        }

        private static int SumOfArray(int[] intArray)
        {
            int sum = 0;
            for (int i = 0; i < intArray.Length; i++)
            {

                sum += intArray[i];
            }
            return sum;
        }

        private void bt_search_Click(object sender, EventArgs e)
        {

        }
    }
}