private async void MNUBUtttonCreate_Click(object sender, RoutedEventArgs e) { DateTime dt = _DateStart; ObservableCollection <DiagNasos> CurrentMNU = new ObservableCollection <DiagNasos>(); while (dt < _DateEnd) { DiagNasos diag = new DiagNasos(dt, dt.AddDays(7), Int32.Parse(txtGG.Text)); //bool ok = diag.ReadData("DN",2,"GG_RUN"); //bool ok = diag.ReadData("MNU", 3, "GG_UST"); bool ok = diag.ReadData("DN", 2, "GG_RUN"); CurrentMNU.Add(diag); dt = dt.AddDays(7); } MNUGrid.ItemsSource = CurrentMNU; }
public static async void CreateReport(DateTime dateStart, DateTime dateEnd, string type, string Header) { int nasosCount = type == "MNU" ? 3 : 2; string typeRunGG = "GG_RUN"; string FileNameFull = String.Format("c:/wrk/test{0}.xlsx", type); XLWorkbook wbFull = new XLWorkbook(); IXLWorksheet sheetSvodGG = null; int stepDays = 7; int[] GGArr = new int[] { 1, 3, 4, 5, 7, 2, 6, 9, 10 }; for (int ggInd = 1; ggInd <= 9; ggInd++) { int ggNum = GGArr[ggInd - 1]; string FileNameTem = String.Format("c:/wrk/template3.xlsx", nasosCount); string FileName = String.Format("c:/wrk/test{0}_GG{1}.xlsx", type, ggNum); try { File.Delete(FileName); File.Copy(FileNameTem, FileName); } catch { } XLWorkbook wb = new XLWorkbook(FileName); IXLWorksheet sheetTemp = null; bool ok = wb.TryGetWorksheet("GGTemplate", out sheetTemp); if (nasosCount == 2) { sheetTemp.Range(1, 18, 20, 30).Clear(); sheetTemp.Range(1, 4, 1, 17).Merge(); } IXLWorksheet sheet = sheetTemp.CopyTo(String.Format("GG {0}", ggNum)); if (ggInd == 1) { sheetSvodGG = sheetTemp.CopyTo(wbFull, "Свод"); sheetSvodGG.Cell(1, 1).Value = "ГГ"; sheetSvodGG.Cell(1, 4).Value = "ГГ в работе или простое"; sheetSvodGG.Range(sheetSvodGG.Cell(1, 1), sheetSvodGG.Cell(4, 100)).CopyTo(sheetSvodGG.Cell(4 + 13, 1)); sheetSvodGG.Range(sheetSvodGG.Cell(1, 1), sheetSvodGG.Cell(4, 100)).CopyTo(sheetSvodGG.Cell(8 + 25, 1)); sheetSvodGG.Cell(4 + 13, 4).Value = "ГГ в работе"; sheetSvodGG.Cell(8 + 25, 4).Value = "ГГ в простое"; } sheetTemp.Delete(); IXLWorksheet sheetSvod = wb.AddWorksheet("GG SVOD"); int RowCount = (int)((dateEnd - dateStart).TotalDays / stepDays + 7); sheet.Range(sheet.Cell(1, 1), sheet.Cell(4, 100)).CopyTo(sheet.Cell(RowCount + 1, 1)); sheet.Range(sheet.Cell(1, 1), sheet.Cell(4, 100)).CopyTo(sheet.Cell(RowCount * 2 + 1, 1)); sheet.Cell(1, 4).Value = "ГГ в работе или простое"; sheet.Cell(RowCount + 1, 4).Value = "ГГ в работе"; sheet.Cell(RowCount * 2 + 1, 4).Value = "ГГ в простое"; DateTime ds = dateStart.AddSeconds(0); int rowIndex = 0; int weekNumber = 0; while (ds < dateEnd) { DateTime de = ds.AddDays(7); if (type == "MNU" && ds.Year >= 2020) { typeRunGG = "GG_UST"; } else { typeRunGG = "GG_RUN"; } Logger.Info(String.Format("{0}: {1}", ggNum, de)); DiagNasos diag = new DiagNasos(ds, de, ggNum); diag.ReadData(type, nasosCount, typeRunGG); Logger.Info("read"); ok = wb.TryGetWorksheet("GGFullData", out sheetTemp); IXLWorksheet shFull = sheetTemp.CopyTo(String.Format("GG{0}_{1}", ggNum, ds.ToString("ddMM"))); int row = 2; foreach (PuskStopData pd in diag.FullNasosData) { row++; shFull.Cell(row, 1).Value = pd.TimeOn; shFull.Cell(row, 2).Value = pd.TimeOff; shFull.Cell(row, 3).Value = pd.TypeData; shFull.Cell(row, 4).Value = pd.ValueStart; shFull.Cell(row, 5).Value = pd.ValueEnd; if (pd.PrevRecord != null) { shFull.Cell(row, 6).Value = pd.PrevRecord.TimeOff; } /*if (pd.NextRecord != null) * shFull.Cell(row, 7).Value = pd.NextRecord.TimeOn;*/ shFull.Cell(row, 8).Value = pd.Comment; shFull.Cell(row, 9).Value = (pd.TimeOff - pd.TimeOn).TotalSeconds / 60; if (pd.PrevRecord != null) { shFull.Cell(row, 10).Value = -(pd.PrevRecord.TimeOff - pd.TimeOn).TotalSeconds / 60; } } sheetSvod.Cell(RowCount * 1 - 1, 1).Value = "ГГ в работе. время простоя насосов"; fillHorDouble(sheetSvod, RowCount * 1 + weekNumber, "неделя " + ds.ToString(), diag.NasosRunGG["SVOD"].StayInfo.sorted, 60); sheetSvod.Cell(RowCount * 2 - 1, 1).Value = "ГГ в работе. время работы насосов"; fillHorDouble(sheetSvod, RowCount * 2 + weekNumber, "неделя " + ds.ToString(), diag.NasosRunGG["SVOD"].RunInfo.sorted, 60); sheetSvod.Cell(RowCount * 3 - 1, 1).Value = "ГГ в работе. скорость набора уровня (потери давления)"; fillHorDouble(sheetSvod, RowCount * 3 + weekNumber, "неделя " + ds.ToString(), diag.NasosRunGG["SVOD"].VInfo.sorted); sheetSvod.Cell(RowCount * 4 - 1, 1).Value = "ГГ в простое. время простоя насосов"; fillHorDouble(sheetSvod, RowCount * 4 + weekNumber, "неделя " + ds.ToString(), diag.NasosStopGG["SVOD"].StayInfo.sorted, 60); sheetSvod.Cell(RowCount * 5 - 1, 1).Value = "ГГ в простое. время работы насосов"; fillHorDouble(sheetSvod, RowCount * 5 + weekNumber, "неделя " + ds.ToString(), diag.NasosStopGG["SVOD"].RunInfo.sorted, 60); sheetSvod.Cell(RowCount * 6 - 1, 1).Value = "ГГ в простое. скорость набора уровня (потери давления)"; fillHorDouble(sheetSvod, RowCount * 6 + weekNumber, "неделя " + ds.ToString(), diag.NasosStopGG["SVOD"].VInfo.sorted); for (int i = 0; i < 3; i++) { Dictionary <string, AnalizeNasosData> data = i == 0 ? diag.NasosGG : i == 1 ? diag.NasosRunGG : diag.NasosStopGG; row = 5 + RowCount * i + rowIndex; sheet.Cell(row, 1).Value = ds; sheet.Cell(row, 2).Value = diag.timeGGRun / 3600; sheet.Cell(row, 2).Style.NumberFormat.Format = "0.0"; sheet.Cell(row, 3).Value = diag.timeGGStop / 3600; sheet.Cell(row, 3).Style.NumberFormat.Format = "0.0"; sheet.Cell(row, 4).Value = getVal(data["SVOD"].RunInfo.Count); sheet.Cell(row, 4).Style.NumberFormat.Format = "0"; sheet.Cell(row, 5).Value = getVal(data["SVOD"].RunInfo.Count / data["SVOD"].sumTime * 3600); sheet.Cell(row, 5).Style.NumberFormat.Format = "0.0"; sheet.Cell(row, 6).Value = getVal(data["SVOD"].RunInfo.MathO / 60); sheet.Cell(row, 6).Style.NumberFormat.Format = "0.0"; sheet.Cell(row, 7).Value = getVal(data["SVOD"].StayInfo.MathO / 60); sheet.Cell(row, 7).Style.NumberFormat.Format = "0.0"; double sumRun = data["SVOD"].RunInfo.filtered.Sum(); double sumStay = data["SVOD"].StayInfo.filtered.Sum(); if (sumStay > 0) { sheet.Cell(row, 8).Value = getVal(sumRun / sumStay); sheet.Cell(row, 8).Style.NumberFormat.Format = "0.00"; } sheet.Cell(row, 9).Value = getVal(data["SVOD"].VInfo.MathO * 3600); sheet.Cell(row, 9).Style.NumberFormat.Format = "0.00"; int col = 9; for (int nasos = 1; nasos <= nasosCount; nasos++) { AnalizeNasosData nd = data[String.Format("{0}_{1}", type, nasos)]; sheet.Cell(row, col + 1).Value = getVal(nd.RunInfo.Count); sheet.Cell(row, col + 1).Style.NumberFormat.Format = "0"; if (data["SVOD"].RunInfo.Count > 0) { sheet.Cell(row, col + 2).Value = getVal(nd.RunInfo.Count * 100.0 / data["SVOD"].RunInfo.Count); } sheet.Cell(row, col + 2).Style.NumberFormat.Format = "0.0"; sheet.Cell(row, col + 3).Value = getVal(nd.RunInfo.MathO / 60.0); sheet.Cell(row, col + 3).Style.NumberFormat.Format = "0.0"; sumRun = nd.RunInfo.filtered.Sum(); sumStay = data["SVOD"].StayInfo.filtered.Sum() - sumRun; if (sumStay > 0) { sheet.Cell(row, col + 4).Value = getVal(sumRun / sumStay); sheet.Cell(row, col + 4).Style.NumberFormat.Format = "0.00"; } col += 4; } if (de >= dateEnd) { int rowdesc = (i + 1) * 4 + i * 12 + ggInd; sheet.Range(row, 2, row, 100).CopyTo(sheetSvodGG.Cell(rowdesc, 2)); sheetSvodGG.Cell(rowdesc, 1).Value = String.Format("ГГ-{0}", ggNum); } } ds = de.AddSeconds(0); rowIndex++; weekNumber++; } sheetTemp.Delete(); sheet.CopyTo(wbFull, sheet.Name); wb.SaveAs(FileName); } wbFull.SaveAs(FileNameFull); sendDiagData(FileNameFull, Header); }