private void button2_Click(object sender, EventArgs e)
        {
            StreamWriter file = new StreamWriter("base.txt", true);

            string[] temp = richTextBox1.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            try
            {
                file.WriteLine(DateTime.Parse(temp[0]).ToShortDateString());
                file.WriteLine(temp[1]);
                file.WriteLine(int.Parse(temp[2]));
                file.WriteLine(int.Parse(temp[3]));
                file.WriteLine(int.Parse(temp[4]));
            }
            catch (Exception)
            {
                Form Exception = new WrongFormatException();
                Exception.Show();
            }

            file.Close();

            new Input().Read();

            Close();
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            StreamWriter file = new StreamWriter("base.txt");

            foreach (Weather weather in Program.weather)
            {
                if (weather.Date.ToShortDateString() + " " + weather.City + " " + weather.Pressure + " " + weather.Temperature + " " + weather.WindSpeed == comboBox1.SelectedItem.ToString())
                {
                    string[] temp = richTextBox1.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    try
                    {
                        file.WriteLine(DateTime.Parse(temp[0]).ToShortDateString());
                        file.WriteLine(temp[1]);
                        file.WriteLine(int.Parse(temp[2]));
                        file.WriteLine(int.Parse(temp[3]));
                        file.WriteLine(int.Parse(temp[4]));
                    }
                    catch (Exception)
                    {
                        file.WriteLine(weather.Date.ToShortDateString());
                        file.WriteLine(weather.City);
                        file.WriteLine(weather.Pressure);
                        file.WriteLine(weather.Temperature);
                        file.WriteLine(weather.WindSpeed);

                        Form Exception = new WrongFormatException();
                        Exception.Show();
                    }
                }
                else
                {
                    file.WriteLine(weather.Date.ToShortDateString());
                    file.WriteLine(weather.City);
                    file.WriteLine(weather.Pressure);
                    file.WriteLine(weather.Temperature);
                    file.WriteLine(weather.WindSpeed);
                }
            }

            file.Close();

            new Input().Read();

            Close();
        }