public bool IsClearPort(NE.Port port) { bool M=true; foreach (var st in port.Stat) { if (st.BBE!=0||st.ES!=0||st.FEBBE!=0||st.FEES!=0||st.FESES!=0||st.FEUAS!=0||st.NEUAS!=0||st.SES!=0) return false; } return M; }
/// <summary> /// clear current chart and draw new from port /// </summary> /// <param name="port"></param> /// <param name="pm24"></param> private void DrawPortToChart(NE.Port port, bool pm24, bool ClearPrevSerias) { try { Chart chart = pm24 ? chart1 : chart2; ComboBox cb_line = pm24 ? comboBox1 : comboBox2; ComboBox cb_ports = pm24 ? comboBox3 : comboBox4; if (ClearPrevSerias) chart.Series.Clear(); #region series s1 Series s1 = new Series(); s1.ChartArea = "ChartArea1"; if (cb_line.SelectedItem != null) s1.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), cb_line.SelectedItem.ToString()); else s1.ChartType = SeriesChartType.SplineRange; s1.Color = System.Drawing.Color.Red; s1.CustomProperties = "EmptyPointValue=Zero"; s1.Legend = "Legend1"; s1.LegendText = "BBE"; s1.Name = port.PortName; s1.IsVisibleInLegend = true; s1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Date; s1.YValuesPerPoint = 2; s1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32; #endregion List<int> bbeList = new List<int>(); List<DateTime> dates = new List<DateTime>(); if(port.Stat_Have_BBE()) //Добавление данных для графика foreach (var stat in port.Stat) { if (!pm24 && !stat.HaveError()) continue;//пропустим пустые дни для pm15 bbeList.Add(stat.BBE); dates.Add(stat.Date); s1.Points.AddXY(stat.Date, stat.BBE); }else if(port.Stat_Have_FEBBE()) { foreach (var stat in port.Stat) { if (!pm24 && !stat.HaveError()) continue;//пропустим пустые дни для pm15 bbeList.Add(stat.FEBBE); dates.Add(stat.Date); s1.Points.AddXY(stat.Date, stat.FEBBE); } s1.LegendText = "FEBBE"; } //s1.LegendText = port.PortName; chart.Series.Add(s1); chart.ChartAreas[0].RecalculateAxesScale(); } catch (Exception ex) { MessageBox.Show(ex.Message, "DrawPortToChart Method"); } }
public ReadPM(string FileDir, string Filename) { try { int a; this.FileDir = FileDir; this.Filename = Filename; StreamReader f; string Line; NE.Port newPort = new NE.Port(1); NE.Statistics currentStat = new NE.Statistics(1); Ports = new List <NE.Port>(); string filepath = FileDir + "/" + Filename; string PortName; if (File.Exists(filepath)) { currentStat.FilePath = filepath; var tFile = File.ReadAllText(filepath); if (tFile.Contains("15 minutes")) //read pm15 file { return; } f = new StreamReader(filepath); Line = f.ReadLine(); var ListLine = Line.Split(':'); NE_Name = ListLine[1].Trim().TrimStart('"').TrimEnd('"'); Line = f.ReadLine(); ListLine = Line.Split(); Date = DateTime.ParseExact(ListLine[2].TrimStart('"').TrimEnd('"'), "dd:MM:yyyy", CultureInfo.InvariantCulture); while (!f.EndOfStream) //повторять до конца файла { if (Line.Split()[0] == "PP:") { PortName = Line.Split()[1].TrimStart('"').TrimEnd('"'); //PortName } else { Line = f.ReadLine(); // порт continue; } int ind = Ports.FindIndex(p => p.PortName == PortName); //index of port in Ports if (ind == -1) { currentStat = new NE.Statistics(1); currentStat.Date = Date.Date; //Date currentStat.FilePath = filepath; } f.ReadLine(); // next f.ReadLine(); //next Line = f.ReadLine(); if (String.IsNullOrEmpty(Line)) { continue; } while (Line.Split()[0].Trim() == "ME:") { switch (Line.Split()[1].Trim()) { case "FEBBE": int.TryParse(Line.Split()[2].Trim(), out currentStat.FEBBE); break; case "BBE": int.TryParse(Line.Split()[2].Trim(), out currentStat.BBE); break; case "FEES": int.TryParse(Line.Split()[2].Trim(), out currentStat.FEES); break; case "ES": int.TryParse(Line.Split()[2].Trim(), out currentStat.ES); break; case "SES": int.TryParse(Line.Split()[2].Trim(), out currentStat.SES); break; case "FESES": int.TryParse(Line.Split()[2].Trim(), out currentStat.FESES); break; case "FEUAS": int.TryParse(Line.Split()[2].Trim(), out currentStat.FEUAS); break; case "NEUAS": int.TryParse(Line.Split()[2].Trim(), out currentStat.NEUAS); break; } Line = f.ReadLine(); if (String.IsNullOrEmpty(Line)) { break; } } //if (Line.Split()[1].Trim() == "FEBBE") // int.TryParse(Line.Split()[2].Trim(), out newStat.FEBBE); //else int.TryParse(Line.Split()[2].Trim(),out newStat.BBE); //Line = f.ReadLine(); //ES FEES //if (Line.Split()[1].Trim() == "FEES") int.TryParse(Line.Split()[2].Trim(),out newStat.FESES); //else int.TryParse(Line.Split()[2].Trim(),out newStat.ES); //Line = f.ReadLine(); //SES FESES //if (Line.Split()[1].Trim() == "FESES") int.TryParse(Line.Split()[2].Trim(), out newStat.FESES); //else int.TryParse(Line.Split()[2].Trim(), out newStat.SES); //Line = f.ReadLine(); //UAS //if (Line.Split()[1].Trim() == "FEUAS") int.TryParse(Line.Split()[2].Trim(),out newStat.FEUAS); //else int.TryParse(Line.Split()[2].Trim(), out newStat.NEUAS); if (ind == -1) { //порт не найден newPort = new NE.Port(1); newPort.PortName = PortName; newPort.Stat.Add(currentStat); Ports.Add(newPort); //добавление нового порта } else //порт найден. добавляем stat в существующий { var removeStat = Ports[ind].Stat.FindIndex(s => s.Date.Date == currentStat.Date.Date); if (removeStat == -1) { Ports[ind].Stat.Add(currentStat); //нету такой статы } else //удаляем существующую стату чтобы добавить новую { Ports[ind].Stat.Remove(Ports[ind].Stat[removeStat]); Ports[ind].Stat.Add(currentStat); } } } //конец чтения файла f.Close(); } else { MessageBox.Show("Ошибка открытия файла" + filepath, "ReadPM Class"); } } catch (Exception) { throw; } }
public PM15(string FilePath) { try { Filename = FilePath.Split('\\').Last(); Ports = new List <NE.Port>(); NE.Port currentPort = new NE.Port(); NE.Statistics currentStat = new NE.Statistics(1); int currentInteral = 0; bool firstPort = true; string nS; // text of NumberInterval if (!File.Exists(FilePath)) { //Ports.Add(new NE.Port("fileNotFound")); NE_Name = FilePath; return; } currentStat.FilePath = FilePath; //all lines in file var Lines = File.ReadAllLines(FilePath); for (int i = 0; i < Lines.Length; i++) //проход по всем строкам { var segments = Lines[i].Split('\t'); switch (segments[0]) { case "NE:": NE_Name = segments[1].Trim().TrimStart('"').TrimEnd('"'); break; case "PO:": //get all intervals into Intervals[] nS = segments[1]; //Номер интервала int N = int.Parse(nS); //Номер интервала string dt = segments[2].TrimStart('"').TrimEnd('"'); //дата интервала DateTime datetime = DateTime.ParseExact(dt, "dd:MM:yyyy HH:mm:ss", CultureInfo.InvariantCulture); //дата интервала Intervals[N] = datetime; break; case "PP:": //port name var port_Name = segments[1].Trim('"'); //save prev port if (!firstPort) { currentPort.Stat.Add(currentStat); Ports.Add(currentPort); currentPort = new NE.Port(port_Name); } else { currentPort = new NE.Port(port_Name); firstPort = false; } break; case "BL:": //errors interval nS = segments[1]; //Номер интервала currentInteral = int.Parse(nS); if (currentInteral != 0) { currentPort.Stat.Add(currentStat); } currentStat = new NE.Statistics(1); currentStat.FilePath = FilePath; currentStat.Date = Intervals[currentInteral]; break; case "ME:": //ERRORS var erType = segments[1]; int erCount = int.Parse(segments[2].Trim()); switch (erType) { case "NEUAS": currentStat.NEUAS = erCount; break; case "SES": currentStat.SES = erCount; break; case "ES": currentStat.ES = erCount; break; case "BBE": currentStat.BBE = erCount; break; case "FEBBE": currentStat.FEBBE = erCount; break; case "FEES": currentStat.FEES = erCount; break; case "FESES": currentStat.FESES = erCount; break; case "FEUAS": currentStat.FEUAS = erCount; break; } break; } if (i == Lines.Length - 1) { currentPort.Stat.Add(currentStat); Ports.Add(currentPort); } } } catch (Exception Ex) { throw new Exception("PM15", Ex); } }