public FormMonthsValuesDialogs(Dictionary <Months, double> values, string caption)
        {
            InitializeComponent();
            Text = caption;
            if (values != null)
            {
                Values = values;
            }
            else
            {
                Values = new Dictionary <Months, double>();
            }

            for (int i = 1; i <= 12; i++)
            {
                Months month = (Months)i;
                Label  label = new Label()
                {
                    Text = month.Description(), Height = 20, Margin = new Padding(0, 0, 0, 2), Font = new Font(FontFamily.GenericSansSerif, 10)
                };
                TextBox textbox = new TextBox()
                {
                    Height = 30, Margin = new Padding(0, 0, 0, 2), Text = Values.ContainsKey(month) ? Values[month].ToString() : "", Tag = month
                };
                Labels.Add(month, label);
                Textboxes.Add(month, textbox);
                flowLayoutPanelMonth.Controls.Add(label);
                flowLayoutPanelValue.Controls.Add(textbox);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// сохранение ВЭК
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="range"></param>
        public override void SaveEnergyInfo(string filename, RawRange range)
        {
            using (ExcelPackage excelPackage = new ExcelPackage())
            {
                //Set some properties of the Excel document
                excelPackage.Workbook.Properties.Author  = "Wind Energy";
                excelPackage.Workbook.Properties.Title   = range.Name;
                excelPackage.Workbook.Properties.Created = DateTime.Now;
                //Create the WorkSheet
                ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Лист 1");

                List <object> years = new List <object>();
                foreach (RawItem item in range)
                {
                    if (!years.Contains(item.Date.Year))
                    {
                        years.Add(item.Date.Year);
                    }
                }

                double totalAverageSpeed = range.Average((t) => t.Speed);

                //формирование заголовка
                List <string> cap = new List <string>()
                {
                    "Год", "Месяц", "Кол-во измерений"
                };
                foreach (GradationItem grad in Vars.Options.CurrentSpeedGradation.Items)
                {
                    cap.Add(grad.Average.ToString("0.00"));
                }
                cap.AddRange(new string[] { "Vmin, м/с", "Vmax, м/с", "Vср, м/с", "Vэкстр.50, м/с", "δ(P)", "Cv(V)", "𝜎(V)", "γ", "β", "Nвал уд., Вт/м^2", "Эвал уд., Вт*ч/м^2" });
                foreach (WindDirections16 wd in WindDirections16.Calm.GetEnumItems().GetRange(0, 17))
                {
                    cap.Add(wd.Description());
                }


                //ЗАПИСЬ ФАЙЛА
                //запись заголовка
                for (int j = 1; j <= cap.Count; j++)
                {
                    worksheet.Cells[1, j].Value = cap[j - 1];
                }
                worksheet.Cells[1, 1, 1, cap.Count].Style.Font.Bold        = true;
                worksheet.Cells[1, 1, 1, cap.Count].Style.Fill.PatternType = ExcelFillStyle.Solid;
                worksheet.Cells[1, 1, 1, cap.Count].Style.Fill.BackgroundColor.SetColor(Color.Gray);
                worksheet.View.FreezePanes(2, 3);

                //запись данных обо всём периоде
                EnergyInfo ri1 = StatisticEngine.ProcessRange(range);
                StatisticalRange <WindDirections16> sd1 = StatisticEngine.GetDirectionExpectancy(range, GradationInfo <WindDirections16> .Rhumb16Gradations);
                StatisticalRange <GradationItem>    ss1 = StatisticEngine.GetExpectancy(range, Vars.Options.CurrentSpeedGradation);
                EnergyInfo ei1   = StatisticEngine.ProcessRange(ss1);
                int        cells = saveEnergyInfoLine(worksheet, 2, ri1, ei1, sd1, ss1, "Все года", "Все месяцы", range.Count);
                worksheet.Cells[2, 1, 2, cells].Style.Font.Bold        = true;
                worksheet.Cells[2, 1, 2, cells].Style.Fill.PatternType = ExcelFillStyle.Solid;
                worksheet.Cells[2, 1, 2, cells].Style.Fill.BackgroundColor.SetColor(Color.LightGray);

                //запись данных для каждого года
                int line = 3;
                foreach (int year in years) //цикл по годам
                {
                    //для каждого месяца в году
                    for (int mt = 0; mt <= 12; mt++) //по месяцам, начиная со всех
                    {
                        Months   month = (Months)mt;
                        RawRange rn    = range.GetRange(false, true, DateTime.Now, DateTime.Now, year, month.Description());
                        if (rn == null || rn.Count == 0)
                        {
                            continue;
                        }
                        EnergyInfo ri = StatisticEngine.ProcessRange(rn, range);
                        StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations);
                        StatisticalRange <GradationItem>    ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation);
                        EnergyInfo ei = StatisticEngine.ProcessRange(ss);
                        cells = saveEnergyInfoLine(worksheet, line, ri, ei, sd, ss, year.ToString(), month.Description(), rn.Count);
                        if (Math.IEEERemainder(mt + 1, 2) == 0 || mt == 0) //на нечетных строках добавляем серый фон
                        {
                            worksheet.Cells[line, 1, line, cells].Style.Fill.PatternType = ExcelFillStyle.Solid;
                            worksheet.Cells[line, 1, line, cells].Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                        }
                        if (month == Months.All) //для суммарной информации по году выделение жирным
                        {
                            worksheet.Cells[line, 1, line, cells].Style.Font.Bold = true;
                        }
                        line++;
                    }
                }

                //запись данных для каждого месяца отдельно
                line += 3;
                //для каждого месяца в году
                for (int mt = 1; mt <= 12; mt++) //по месяцам
                {
                    Months   month = (Months)mt;
                    RawRange rn    = range.GetRange(false, true, DateTime.Now, DateTime.Now, "Все", month.Description());
                    if (rn == null || rn.Count == 0)
                    {
                        continue;
                    }
                    EnergyInfo ri = StatisticEngine.ProcessRange(rn, range);
                    StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations);
                    StatisticalRange <GradationItem>    ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation);
                    EnergyInfo ei = StatisticEngine.ProcessRange(ss);
                    cells = saveEnergyInfoLine(worksheet, line, ri, ei, sd, ss, "Все года", month.Description(), rn.Count);
                    if (Math.IEEERemainder(mt + 1, 2) == 0 || mt == 0) //на нечетных строках добавляем серый фон
                    {
                        worksheet.Cells[line, 1, line, cells].Style.Fill.PatternType = ExcelFillStyle.Solid;
                        worksheet.Cells[line, 1, line, cells].Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                    }
                    line++;
                }


                //Save your file
                FileInfo fi = new FileInfo(filename);
                excelPackage.SaveAs(fi);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Сохранение ВЭК в формате CSV
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="range"></param>
        public override void SaveEnergyInfo(string filename, RawRange range)
        {
            List <object> years = new List <object>();

            foreach (RawItem item in range)
            {
                if (!years.Contains(item.Date.Year))
                {
                    years.Add(item.Date.Year);
                }
            }

            //формирование заголовка
            string cap = "Год;Месяц;кол-во изм";

            foreach (GradationItem grad in Vars.Options.CurrentSpeedGradation.Items)
            {
                cap += ";" + grad.Average.ToString("0.00");
            }
            cap += ";Vmin, м/с;Vmax, м/с;Vср, м/с;Vэкст50,м/с;Cv(V);𝜎(V);параметр γ;параметр β;Nвал уд., Вт/м^2;Эвал уд., Вт*ч/м^2";
            foreach (WindDirections16 wd in WindDirections16.Calm.GetEnumItems().GetRange(0, 17))
            {
                cap += ";" + wd.Description();
            }

            //запись в файл
            saveEnergyInfoLine(filename, null, null, null, null, cap, "", "", 0, false); //запись заголовка

            //запись данных обо всём периоде
            EnergyInfo ri1 = StatisticEngine.ProcessRange(range);
            StatisticalRange <WindDirections16> sd1 = StatisticEngine.GetDirectionExpectancy(range, GradationInfo <WindDirections16> .Rhumb16Gradations);
            StatisticalRange <GradationItem>    ss1 = StatisticEngine.GetExpectancy(range, Vars.Options.CurrentSpeedGradation);
            EnergyInfo ei1 = StatisticEngine.ProcessRange(ss1);

            saveEnergyInfoLine(filename, ri1, ei1, sd1, ss1, null, "Все года", "Все месяцы", range.Count, true);

            //запись данных для каждого года
            foreach (int year in years) //цикл по годам
            {
                //для каждого месяца в году
                for (int mt = 0; mt <= 12; mt++)//по месяцам, начиная со всех
                {
                    Months   month = (Months)mt;
                    RawRange rn    = range.GetRange(false, true, DateTime.Now, DateTime.Now, year, month.Description());
                    if (rn == null || rn.Count == 0)
                    {
                        continue;
                    }
                    EnergyInfo ri = StatisticEngine.ProcessRange(rn, range);
                    StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations);
                    StatisticalRange <GradationItem>    ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation);
                    EnergyInfo ei = StatisticEngine.ProcessRange(ss);
                    saveEnergyInfoLine(filename, ri, ei, sd, ss, null, year.ToString(), month.Description(), rn.Count, true);
                }
            }

            //запись данных по месяцам
            saveEnergyInfoLine(filename, null, null, null, null, ";", "", "", 0, true);
            saveEnergyInfoLine(filename, null, null, null, null, ";", "", "", 0, true);
            saveEnergyInfoLine(filename, null, null, null, null, ";", "", "", 0, true);
            for (int mt = 1; mt <= 12; mt++)//по месяцам, начиная со всех
            {
                Months   month = (Months)mt;
                RawRange rn    = range.GetRange(false, true, DateTime.Now, DateTime.Now, "Все", month.Description());
                if (rn == null || rn.Count == 0)
                {
                    continue;
                }
                EnergyInfo ri = StatisticEngine.ProcessRange(rn, range);
                StatisticalRange <WindDirections16> sd = StatisticEngine.GetDirectionExpectancy(rn, GradationInfo <WindDirections16> .Rhumb16Gradations);
                StatisticalRange <GradationItem>    ss = StatisticEngine.GetExpectancy(rn, Vars.Options.CurrentSpeedGradation);
                EnergyInfo ei = StatisticEngine.ProcessRange(ss);
                saveEnergyInfoLine(filename, ri, ei, sd, ss, null, "Все года", month.Description(), rn.Count, true);
            }
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            foreach (TextBox tb in Textboxes.Values)
            {
                Months month = (Months)tb.Tag;
                if (string.IsNullOrWhiteSpace(tb.Text))
                {
                    _ = MessageBox.Show(this, $"Не удалось распознать значение месяца: {month.Description()}", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
                }
                if (!double.TryParse(tb.Text.Trim().Replace('.', Constants.DecimalSeparator), out double value))
                {
                    _ = MessageBox.Show(this, $"Не удалось распознать \"{tb.Text}\" как число", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
                }
                Values[month] = value;
            }

            Result       = Values;
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 5
0
        private string xAxis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index)
        {
            Months month = (Months)val;

            return(month.Description());
        }