private async void MNUGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DiagNasos record = MNUGrid.SelectedItem as DiagNasos;

            winMNU = new ReportResultWindow();
            winMNU.chart.initControl();
            winMNU.chart.AllYAxisIsVisible = true;
            winMNU.chart.CurrentFormatY    = "0";

            winMNU.chart.init(true, "dd.MM HH");
            winMNU.chart.setY2AxisCount(winMNU.chart.CurrentGraphPane, 3);
            winMNU.chart.AddSerie("RUN", record.GetSerieData(record.DateStart, record.DateEnd, record.DataGG["GG_RUN"]),
                                  System.Drawing.Color.Red, true, false, true, -1, true);
            winMNU.chart.AddSerie("Ust", record.GetSerieData(record.DateStart, record.DateEnd, record.DataGG["GG_UST"]),
                                  System.Drawing.Color.LightBlue, true, false, true, -1, false);
            winMNU.chart.AddSerie("L", record.GetSerieDataAdd(record.DateStart, record.DateEnd),
                                  System.Drawing.Color.Orange, true, false, true, 1, true);

            winMNU.chart.init(true, "dd.MM HH");
            winMNU.chart.setY2AxisCount(winMNU.chart.CurrentGraphPane, 3);

            winMNU.chart.AddSerie("VRun", record.GetSerieDataAvg(record.DateStart, record.DateEnd, record.NasosRunGG["SVOD"].VInfo),
                                  System.Drawing.Color.Yellow, true, false, true, -1, true);
            winMNU.chart.AddSerie("VStay", record.GetSerieDataAvg(record.DateStart, record.DateEnd, record.NasosStopGG["SVOD"].VInfo),
                                  System.Drawing.Color.Yellow, true, false, true, -1, true);

            winMNU.chart.AddSerie("SRun", record.GetSerieDataAvg(record.DateStart, record.DateEnd, record.NasosRunGG["SVOD"].StayInfo),
                                  System.Drawing.Color.Red, true, false, true, 0, true);
            winMNU.chart.AddSerie("SStay", record.GetSerieDataAvg(record.DateStart, record.DateEnd, record.NasosStopGG["SVOD"].StayInfo),
                                  System.Drawing.Color.Red, true, false, true, 0, true);

            winMNU.chart.AddSerie("RRun", record.GetSerieDataAvg(record.DateStart, record.DateEnd, record.NasosRunGG["SVOD"].RunInfo),
                                  System.Drawing.Color.Green, true, false, true, 1, true);
            winMNU.chart.AddSerie("RStay", record.GetSerieDataAvg(record.DateStart, record.DateEnd, record.NasosStopGG["SVOD"].RunInfo),
                                  System.Drawing.Color.Green, true, false, true, 1, true);


            winMNU.chart.init(true, "dd.MM HH");
            winMNU.chart.setY2AxisCount(winMNU.chart.CurrentGraphPane, 3);

            winMNU.chart.AddSerie("Насос1", record.GetSerieData(record.DateStart, record.DateEnd, record.DataNasos[record.NasosType + "_1"]),
                                  System.Drawing.Color.Red, true, false, true, -1, true, 0, 3);
            winMNU.chart.AddSerie("Насос2", record.GetSerieData(record.DateStart, record.DateEnd, record.DataNasos[record.NasosType + "_2"]),
                                  System.Drawing.Color.Green, true, false, true, 0, true, -1, 2);
            if (record.NasosType == "MNU")
            {
                winMNU.chart.AddSerie("Насос3", record.GetSerieData(record.DateStart, record.DateEnd, record.DataNasos["MNU_3"]),
                                      System.Drawing.Color.Yellow, true, false, true, 1, true, -2, 1);
            }



            winMNU.Show();
        }
        private void reCalcRegul()
        {
            string caption = String.Format("Объем масла");

            CurrentDiagOilRegul.recalcData();

            try
            //if (winRegul!=null)
            {
                winRegul.Show();
                winRegul.chart.UpdateSerieData("V СБ", CurrentDiagOilRegul.serieV_SB);
                winRegul.chart.UpdateSerieData("V ОГА", CurrentDiagOilRegul.serieV_OGA);
                winRegul.chart.UpdateSerieData("V АГА", CurrentDiagOilRegul.serieV_AGA);
                winRegul.chart.UpdateSerieData("V РК", CurrentDiagOilRegul.serieV_RK);
                winRegul.chart.UpdateSerieData("V НА", CurrentDiagOilRegul.serieV_NA);
                winRegul.chart.UpdateSerieData("V ЛБ", CurrentDiagOilRegul.serieV_LB);


                winRegul.chart.UpdateSerieData("МНУ", CurrentDiagOilRegul.serieD_MNU);
                winRegul.chart.UpdateSerieData("ЛА", CurrentDiagOilRegul.serieD_LA);
                winRegul.chart.UpdateSerieData("T", CurrentDiagOilRegul.serieT_SB);


                winRegul.chart.UpdateSerieData("F", CurrentDiagOilRegul.serieF);
                winRegul.chart.UpdateSerieData("НА", CurrentDiagOilRegul.serieL_NA);
                winRegul.chart.UpdateSerieData("РК", CurrentDiagOilRegul.serieL_RK);
                winRegul.chart.UpdateSerieData("V", CurrentDiagOilRegul.serieV);
                winRegul.chart.updateSeries();
            }
            //else
            catch
            {
                winRegul = new ReportResultWindow();
                winRegul.chart.initControl();
                winRegul.chart.init(true, "dd.MM HH");
                winRegul.chart.AllYAxisIsVisible = true;
                winRegul.chart.CurrentFormatY    = "0";
                winRegul.chart.setY2AxisCount(winRegul.chart.CurrentGraphPane, 2);
                winRegul.chart.AddSerie("V СБ", CurrentDiagOilRegul.serieV_SB, System.Drawing.Color.LightBlue, true, false, true, -1, true);
                winRegul.chart.AddSerie("V ОГА", CurrentDiagOilRegul.serieV_OGA, System.Drawing.Color.LightGreen, true, false, true, -1, true);
                winRegul.chart.AddSerie("V АГА", CurrentDiagOilRegul.serieV_AGA, System.Drawing.Color.LightCoral, true, false, true, 0, false);
                winRegul.chart.AddSerie("V РК", CurrentDiagOilRegul.serieV_RK, System.Drawing.Color.Pink, true, false, true, 0, true);
                winRegul.chart.AddSerie("V НА", CurrentDiagOilRegul.serieV_NA, System.Drawing.Color.Red, true, false, true, 0, true);
                winRegul.chart.AddSerie("V ЛБ", CurrentDiagOilRegul.serieV_LB, System.Drawing.Color.Orange, true, false, true, 1, false);
                //winRegul.chart.CurrentGraphPane.LineType = ZedGraph.LineType.Stack;

                winRegul.chart.init(true, "dd.MM HH");
                winRegul.chart.setY2AxisCount(winRegul.chart.CurrentGraphPane, 2);
                winRegul.chart.AddSerie("МНУ", CurrentDiagOilRegul.serieD_MNU, System.Drawing.Color.Orange, true, false, true, 0, true, -1, 5);
                winRegul.chart.AddSerie("ЛА", CurrentDiagOilRegul.serieD_LA, System.Drawing.Color.DeepPink, true, false, true, 1, true, -2, 4);
                winRegul.chart.AddSerie("T", CurrentDiagOilRegul.serieT_SB, System.Drawing.Color.LightGreen, true, false, true, -1, true);

                winRegul.chart.init(true, "dd.MM HH");
                winRegul.chart.setY2AxisCount(winRegul.chart.CurrentGraphPane, 2);
                winRegul.chart.AddSerie("F", CurrentDiagOilRegul.serieF, System.Drawing.Color.Red, true, false, true, 0, true, 0, 200);
                winRegul.chart.AddSerie("НА", CurrentDiagOilRegul.serieL_NA, System.Drawing.Color.Yellow, true, false, true, 1, true);
                winRegul.chart.AddSerie("РК", CurrentDiagOilRegul.serieL_RK, System.Drawing.Color.Gray, true, false, true, 1, true);
                winRegul.chart.AddSerie("V", CurrentDiagOilRegul.serieV, System.Drawing.Color.LightBlue, true, false, false, -1, true);

                winRegul.Title = caption;
                winRegul.Show();
            }

            //if (winRun!=null)
            try
            {
                winRunRegul.Show();
                winRunRegul.chart.UpdatePointSerieData("V", CurrentDiagOilRegul.serieVFull);
                winRunRegul.chart.UpdatePointSerieData("V run", CurrentDiagOilRegul.serieVRun);
                winRunRegul.chart.UpdatePointSerieData("V stop", CurrentDiagOilRegul.serieVStop);
                winRunRegul.chart.updateSeries();
            }
            //else
            catch
            {
                winRunRegul = new ReportResultWindow();
                winRunRegul.chart.initControl();
                winRunRegul.chart.init(true, "0.00", true);
                winRunRegul.chart.CurrentFormatY = "0";
                winRunRegul.chart.AddPointSerie("V", CurrentDiagOilRegul.serieVFull, System.Drawing.Color.Orange, true, false);
                winRunRegul.chart.AddPointSerie("V run", CurrentDiagOilRegul.serieVRun, System.Drawing.Color.LightGreen, true, false);
                winRunRegul.chart.AddPointSerie("V stop", CurrentDiagOilRegul.serieVStop, System.Drawing.Color.LightBlue, true, false);
                winRunRegul.Title = "объем на ГГ (убрать пустые поля)";
                winRunRegul.Show();
            }
            if (chbCreateReport.IsChecked.Value)
            {
                CurrentDiagOilRegul.createText();
            }
        }
        private async void  btnCreate_Click(object sender, RoutedEventArgs e)
        {
            if (!EDSClass.Single.Ready)
            {
                MessageBox.Show("ЕДС сервер не готов");
                return;
            }
            if (!clndFrom.SelectedDate.HasValue)
            {
                MessageBox.Show("Выберите дату начала");
                return;
            }
            if (!clndFrom.SelectedDate.HasValue)
            {
                MessageBox.Show("Выберите дату конца");
                return;
            }

            /*if (cmbFunction.SelectedItem == null) {
             *      MessageBox.Show("Выберите функцию");
             *      return;
             * }*/
            if (cmbPeriod.SelectedItem == null)
            {
                MessageBox.Show("Выберите период");
                return;
            }

            if (cntrlSelectPoints.SelectedPoints.Count() == 0)
            {
                MessageBox.Show("Выберите точки");
                return;
            }


            DateTime dtStart = clndFrom.SelectedDate.Value;
            DateTime dtEnd   = clndTo.SelectedDate.Value;
            //EDSRdeportFunction func = (EDSReportFunction)cmbFunction.SelectedValue;

            EDSReportPeriod period = (EDSReportPeriod)cmbPeriod.SelectedValue;

            EDSReport report = new EDSReport(dtStart, dtEnd, period, chbMsk.IsChecked.Value);

            foreach (EDSReportRequestRecord rec in cntrlSelectPoints.SelectedPoints)
            {
                report.addRequestField(rec.Point, rec.Function);
            }

            //System.Windows.Application.Current.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Background, new System.Action(delegate { report.ReadData(); }));


            EDSClass.Disconnect();
            EDSClass.Connect();

            bool ready = await report.ReadData();

            String header = "";

            foreach (EDSReportRequestRecord rec in report.RequestData.Values)
            {
                header += String.Format("<th width='100'>{0}</th>", rec.Desc);
            }

            TextWriter tW = new StreamWriter("out.html");

            String txt = string.Format(@"<html>
				<head>
					<meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"" />
            </head>
				<table border='1'><tr><th>точка</th>{0}</tr>"                , header);

            tW.WriteLine(txt);

            foreach (KeyValuePair <DateTime, Dictionary <string, double> > de in report.ResultData)
            {
                DateTime dt        = de.Key;
                string   ValuesStr = "";
                foreach (double val in de.Value.Values)
                {
                    ValuesStr += String.Format("<td align='right'>{0:0.00}</td>", val);
                }
                tW.WriteLine(String.Format("<tr><th >{0}</th>{1}</tr>", dt.ToString("dd.MM.yyyy HH:mm:ss"), ValuesStr));
            }
            tW.WriteLine("</table></html>");
            tW.Close();

            Process.Start("out.html");


            ReportResultWindow win = new ReportResultWindow();

            win.chart.init();
            SortedList <DateTime, double> data = new SortedList <DateTime, double>();
            int index = -1;

            foreach (KeyValuePair <string, EDSReportRequestRecord> de in report.RequestData)
            {
                string id = de.Key;
                EDSReportRequestRecord request = de.Value;
                data.Clear();
                foreach (DateTime dt in report.ResultData.Keys)
                {
                    data.Add(dt, report.ResultData[dt][id]);
                }
                win.chart.AddSerie(request.Desc, data, ChartZedSerie.NextColor(), true, true, index++);
            }
            win.Show();
        }
        public void reCreateCharts(string caption, DiadOilClass diag)
        {
            try
            //if (win!=null)
            {
                win.Show();
                win.Title = caption;
                win.chart.UpdateSerieData("L1", diag.serieLvl1);
                win.chart.UpdateSerieData("L2", diag.serieLvl2);
                win.chart.UpdateSerieData("T up", diag.serieTUP);
                win.chart.UpdateSerieData("T dn", diag.serieTDn);
                win.chart.UpdateSerieData("F", diag.serieF);


                win.chart.UpdateSerieData("T avg", diag.serieTAvg);
                win.chart.UpdateSerieData("V расч", diag.serieV);
                //win.chart.UpdateSerieData("V ovation", diag.serieVOv);
                win.chart.UpdateSerieData("L коррекция", diag.serieLvlCor);
                win.chart.updateSeries();
            }
            //else
            catch
            {
                win = new ReportResultWindow();
                win.chart.initControl();
                win.chart.init(true, "dd.MM HH");
                win.chart.CurrentFormatY    = "0";
                win.chart.AllYAxisIsVisible = true;


                win.chart.AddSerie("L1", diag.serieLvl1, System.Drawing.Color.LightGreen, true, false, true, -1);
                win.chart.AddSerie("L2", diag.serieLvl2, System.Drawing.Color.LightSeaGreen, true, false, true, -1);
                win.chart.AddSerie("T up", diag.serieTUP, System.Drawing.Color.LightBlue, true, false, true, 0);
                win.chart.AddSerie("T dn", diag.serieTDn, System.Drawing.Color.LightBlue, true, false, true, 0);
                win.chart.AddSerie("F", diag.serieF, System.Drawing.Color.Red, true, false, true, 1, true, 0, 200);



                win.chart.init(true, "dd.MM HH");
                win.chart.AddSerie("T avg", diag.serieTAvg, System.Drawing.Color.LightBlue, true, false, true, 0);
                win.chart.AddSerie("V расч", diag.serieV, System.Drawing.Color.Orange, true, false, true, 1);
                //win.chart.AddSerie("V ovation", diag.serieVOv, System.Drawing.Color.OrangeRed, true, false, true, 1);
                win.chart.AddSerie("L коррекция", diag.serieLvlCor, System.Drawing.Color.Green, true, false, true, -1);
                win.Title = caption;
                win.Show();
            }

            //if (winRun!=null)
            try
            {
                winRun.Show();
                winRun.chart.UpdatePointSerieData("V", diag.serieVFull);
                winRun.chart.UpdatePointSerieData("V run", diag.serieVRun);
                winRun.chart.UpdatePointSerieData("V stop", diag.serieVStop);
                winRun.chart.updateSeries();
            }
            //else
            catch
            {
                winRun = new ReportResultWindow();
                winRun.chart.initControl();
                winRun.chart.init(true, "0", true);
                winRun.chart.CurrentFormatY = "0";
                winRun.chart.AddPointSerie("V", diag.serieVFull, System.Drawing.Color.Orange, true, false);
                winRun.chart.AddPointSerie("V run", diag.serieVRun, System.Drawing.Color.LightGreen, true, false);
                winRun.chart.AddPointSerie("V stop", diag.serieVStop, System.Drawing.Color.LightBlue, true, false);
                winRun.Title = "объем на ГГ (убрать пустые поля)";
                winRun.Show();
            }

            if (chbCreateReport.IsChecked.Value)
            {
                diag.createText();
            }
        }
        private async void grdEvents_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (!EDSClass.Single.Ready)
            {
                MessageBox.Show("ЕДС сервер не готов");
                return;
            }
            try
            {
                EDSClass.Disconnect();
                EDSClass.Connect();

                AVRCHMReportRecord ev = grdEvents.SelectedItem as AVRCHMReportRecord;

                ReportResultWindow win = new ReportResultWindow();
                win.Title = ev.Date;
                win.chart.initControl();
                win.chart.init(true, "HH:mm:ss");
                win.chart.AllYAxisIsVisible = true;
                DateTime ds = ev.DateStart;
                DateTime de = ev.DateEnd;

                SortedList <String, SortedList <DateTime, double> > errors = report.getSeriesErrorsData("ErrorLimits15", ds, de);
                foreach (KeyValuePair <String, SortedList <DateTime, double> > rec in errors)
                {
                    win.chart.AddSerie("План " + rec.Key, rec.Value, System.Drawing.Color.Red, true, false, false, 0, true);
                }

                bool HasErrorReserv = false;
                errors = report.getSeriesErrorsData("ErrorRezervGraph", ds, de);
                foreach (KeyValuePair <String, SortedList <DateTime, double> > rec in errors)
                {
                    HasErrorReserv = true;
                    win.chart.AddSerie("Резерв " + rec.Key, rec.Value, System.Drawing.Color.OrangeRed, true, false, false, 3, true);
                }


                win.chart.AddSerie("P план", report.getSerieData("PPlan", ds, de), System.Drawing.Color.Pink, true, false, true, 0, false);
                win.chart.AddSerie("P факт", report.getSerieData("PFakt", ds, de), System.Drawing.Color.Blue, true, false, false, 0, true);
                win.chart.AddSerie("P зад сум", report.getSerieData("PPlanFull", ds, de), System.Drawing.Color.Coral, true, false, false, 0, true);
                win.chart.AddSerie("P зад ГРАРМ", report.getSerieData("SumGroupZad", ds, de), System.Drawing.Color.Green, true, false, true, 0, false);
                win.chart.AddSerie("P нг", report.getSerieData("PMin", ds, de), System.Drawing.Color.Gray, true, false, false, 0, true);
                win.chart.AddSerie("P вг", report.getSerieData("PMax", ds, de), System.Drawing.Color.Gray, true, false, false, 0, true);
                win.chart.AddSerie("ГГ кол", report.getSerieData("GGCount", ds, de), System.Drawing.Color.LightBlue, true, false, false, 1, true, 0, 20);
                //win.chart.AddSerie("нарушение", report.getSerieData("ErrorLimits15", ds, de, false), System.Drawing.Color.Red, false, true, false, 0, true);

                win.chart.AddSerie("P перв", report.getSerieData("PPerv", ds, de), System.Drawing.Color.Purple, true, false, false, 2, false);
                win.chart.AddSerie("P звн", report.getSerieData("PZVN", ds, de), System.Drawing.Color.Orange, true, false, false, 2, false);
                win.chart.AddSerie("ресурс+", report.getSerieData("ResursZagr", ds, de), System.Drawing.Color.GreenYellow, true, false, false, 3, HasErrorReserv);
                win.chart.AddSerie("ресурс-", report.getSerieData("ResursRazgr", ds, de), System.Drawing.Color.YellowGreen, true, false, false, 3, HasErrorReserv);
                //win.chart.AddSerie("Нарушение рез", report.getSerieData("ErrorRezervGraph", ds, de, false), System.Drawing.Color.Red, false, true, false, 3, false);



                if (!ev.Date.ToLower().Contains("сутки"))
                {
                    /*win.chart2.Visibility = Visibility.Visible;
                     * win.mainGrid.RowDefinitions.Last().Height = new GridLength(1, GridUnitType.Star);*/
                    win.chart.init(true, "HH:mm:ss");

                    Dictionary <string, SortedList <DateTime, double> > series = await report.getGaData(ds, de);

                    System.Drawing.Color color = ChartZedSerie.NextColor();
                    foreach (string key in series.Keys)
                    {
                        bool isVG = key.Contains("ВГ");
                        SortedList <DateTime, double> data = series[key];
                        if (!isVG && data.Values.Max() > 10 || isVG && data.Values.Min() != data.Values.Max())
                        {
                            win.chart.AddSerie(key, data, color, true, false, key.Contains("Задание"), isVG ? 0 : 3, !isVG, isVG ? 0 : double.MinValue, isVG ? 20 : double.MaxValue);
                        }

                        color = isVG ? ChartZedSerie.NextColor() : color;
                    }
                }


                win.Show();
            }
            catch {
                Logger.Info(e.ToString());
            }
        }