Beispiel #1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            DateTime time = monthCalendar.SelectionStart.Date;

            int day         = time.Date.Day;
            int temperature = (int)tempField.Value;

            Month month = Helper.Deserialize(DBpath);                //

            if (month[day] != null)                                  //если в списке уже есть запись о введенном дне
            {
                DialogResult dialogResult = MessageBox.Show($"Запись о {day} января уже существует. Хотите перезаписать информацию?", "!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (dialogResult == DialogResult.No)
                {
                    return;
                }

                month[day].Temperature = temperature;
            }
            else
            {
                month.Days.Add(new Day(day, temperature));
            }

            month.Sort();
            Helper.Serialize(DBpath, month);

            if (parentForm.isShowButtonPressed)
            {
                Helper.PrintDataBase(DBpath, parentForm.Controls["bodyPanel"].Controls["outputField"] as RichTextBox);
            }

            MessageBox.Show($"Запись о {day} января успешно обновлена.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #2
0
        public static void AddTempToComboBox(string DBpath, ComboBox comboBox)
        {
            comboBox.Items.Clear();

            Month month = Deserialize(DBpath);

            month.Sort();

            if (month.Days.Count == 0)
            {
                return;
            }

            List <int> temps = new List <int>();

            foreach (Day day in month.Days)
            {
                if (temps.IndexOf(day.Temperature) < 0)
                {
                    temps.Add(day.Temperature);
                }
            }

            temps.Sort();

            foreach (int temp in temps)
            {
                comboBox.Items.Add(temp);
            }
        }
Beispiel #3
0
        public static void PrintDataBase(string DBpath, RichTextBox textField)
        {
            textField.Clear();

            string result      = "";
            double averageTemp = 0;

            Month month = Deserialize(DBpath);

            month.Sort();

            if (month.Days.Count == 0)
            {
                return;
            }

            foreach (Day day in month.Days)
            {
                if (day.Temperature >= 0)
                {
                    result += $"{day.Number}\t\t\t\t {day.Temperature}\n";
                }
                else
                {
                    result += $"{day.Number}\t\t\t\t{day.Temperature}\n";
                }

                averageTemp += day.Temperature;
            }
            averageTemp /= month.Days.Count;

            result         = result.Trim();
            textField.Text = result;

            string[] resultRows = textField.Text.Split('\n');

            foreach (string row in resultRows)
            {
                Match match       = Regex.Match(row, @"\t(.*)$");
                int   temperature = int.Parse(match.Groups[1].Value);

                if (temperature > averageTemp)
                {
                    textField.SelectionStart  = textField.Text.IndexOf(row);
                    textField.SelectionLength = row.Length;
                    textField.SelectionColor  = System.Drawing.Color.FromArgb(179, 57, 57);
                }
            }
        }
Beispiel #4
0
        public static void AddDaysToComboBox(string DBpath, ComboBox comboBox)
        {
            comboBox.Items.Clear();

            Month month = Deserialize(DBpath);

            month.Sort();

            if (month.Days.Count == 0)
            {
                return;
            }

            foreach (Day day in month.Days)
            {
                comboBox.Items.Add(day.Number);
            }
        }