public bool CreateExcel(LoggerInformation loggerInformation) { var decoder = new HexFileDecoder(loggerInformation); var loggerVariables = decoder.AssignLoggerVariables(); if (loggerVariables.LoggerState != "Logging" && loggerVariables.LoggerState != "Stopped") { return(false); } var saveFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Temprecord\\TempLite\\"; var excelPath = saveFilePath + loggerInformation.SerialNumber + ".xlsx"; var excel = new ExcelPackage(); var workSheet = excel.Workbook.Worksheets.Add(loggerInformation.SerialNumber); CreateLayout(workSheet, loggerInformation, loggerVariables); excel.SaveAs(new FileInfo(excelPath)); return(true); }
public bool CreatePDF(LoggerInformation loggerInformation) { double lineCounter = 80; var decoder = new HexFileDecoder(loggerInformation); var loggerVariables = decoder.AssignLoggerVariables(); var channelOne = loggerVariables.ChannelOne; var channelTwo = loggerVariables.ChannelTwo; var channelTwoEnabled = loggerVariables.IsChannelTwoEnabled; var pen = new PDFPen(Color.Black, 1); var font = new PDFFont(FontType.Helvetica, 10, PDF.Drawing.FontStyle.Regular); var boldFont = new PDFFont(FontType.Helvetica, 10, PDF.Drawing.FontStyle.Bold); if (loggerVariables.LoggerState != "Logging" && loggerVariables.LoggerState != "Stopped") { return(false); } var pdfPage = CreateNewPage(font, loggerInformation.SerialNumber); void DrawChannelStatistics(string Label, Func <ChannelConfig, string> getString, double lineConterMultiplier = 1.0) { pdfPage.DrawString(Label, boldFont, Color.Black, PDFcoordinates.firstColumn, (float)lineCounter); pdfPage.DrawString(getString(channelOne) + channelOne.Unit, font, Color.Black, PDFcoordinates.secondColumn, (float)lineCounter); if ((channelTwoEnabled) && Label != LabelConstant.MKT) { pdfPage.DrawString(getString(channelTwo) + channelTwo.Unit, font, Color.Black, PDFcoordinates.thirdColumn, (float)lineCounter); } lineCounter += PDFcoordinates.lineInc * lineConterMultiplier; } void DrawChannelLimits(string Label, Func <ChannelConfig, string> getString, double lineConterMultiplier = 1.0) { pdfPage.DrawString(Label, boldFont, Color.Black, PDFcoordinates.firstColumn, (float)lineCounter); pdfPage.DrawString(getString(channelOne), font, Color.Black, PDFcoordinates.secondColumn, (float)lineCounter); if (channelTwoEnabled) { pdfPage.DrawString(getString(channelTwo), font, Color.Black, PDFcoordinates.thirdColumn, (float)lineCounter); } lineCounter += PDFcoordinates.lineInc * lineConterMultiplier; } void DrawSection(string firstColoumString, string secondColoumString, double lineConterMultiplier = 1.0) { pdfPage.DrawString(firstColoumString, boldFont, Color.Black, PDFcoordinates.firstColumn, (float)lineCounter); pdfPage.DrawString(secondColoumString, font, Color.Black, PDFcoordinates.secondColumn, (float)lineCounter); lineCounter += PDFcoordinates.lineInc * lineConterMultiplier; } if (channelOne.OutsideLimits == 0 && channelTwo.OutsideLimits == 0) { var greenPen = new PDFPen(Color.LimeGreen, 15); pdfPage.DrawLine(greenPen, 550, 163, 570, 180); pdfPage.DrawLine(greenPen, 570, 190, 632, 120); pdfPage.DrawString(LabelConstant.WithinLimit, font, Color.Black, PDFcoordinates.limitInfo_X, PDFcoordinates.limitInfo_Y); } else { var redPen = new PDFPen(Color.OrangeRed, 15); pdfPage.DrawLine(redPen, 550, 125, 610, 190); pdfPage.DrawLine(redPen, 550, 190, 610, 125); pdfPage.DrawString(LabelConstant.LimitsExceeded, font, Color.Black, PDFcoordinates.limitInfo_X, PDFcoordinates.limitInfo_Y); } //Draw the boxes pdfPage.DrawRectangle(pen, PDFcoordinates.box1_X1, PDFcoordinates.box1_Y1, PDFcoordinates.box1_X2 - PDFcoordinates.box1_X1, PDFcoordinates.box1_Y2 - PDFcoordinates.box1_Y1); pdfPage.DrawRectangle(pen, PDFcoordinates.box2_X1, PDFcoordinates.box2_Y1, PDFcoordinates.box2_X2 - PDFcoordinates.box2_X1, PDFcoordinates.box2_Y2 - PDFcoordinates.box2_Y1); pdfPage.DrawRectangle(pen, PDFcoordinates.box3_X1, PDFcoordinates.box3_Y1, PDFcoordinates.box3_X2 - PDFcoordinates.box3_X1, PDFcoordinates.box3_Y2 - PDFcoordinates.box3_Y1); //Draw the Text DrawSection(LabelConstant.Model, loggerInformation.LoggerName); DrawSection(LabelConstant.LoggerState, loggerVariables.LoggerState); DrawSection(LabelConstant.Battery, loggerVariables.BatteryPercentage); DrawSection(LabelConstant.SamplePeriod, loggerVariables.SameplePeriod + LabelConstant.TimeSuffix); DrawSection(LabelConstant.StartDelay, loggerVariables.StartDelay + LabelConstant.TimeSuffix); DrawSection(LabelConstant.FirstSample, loggerVariables.FirstSample); DrawSection(LabelConstant.LastSample, loggerVariables.LastSample); DrawSection(LabelConstant.RecordedSample, loggerVariables.RecordedSamples.ToString()); DrawSection(LabelConstant.TotalTrips, loggerVariables.TotalTrip.ToString()); DrawSection(LabelConstant.TagsPlaced, loggerVariables.TagsPlaced.ToString()); lineCounter -= PDFcoordinates.lineInc * 0.5; pdfPage.DrawLine(pen, 20, lineCounter, 680, lineCounter); lineCounter += PDFcoordinates.lineInc * 0.75; pdfPage.DrawString(LabelConstant.Channel, boldFont, Color.Black, PDFcoordinates.firstColumn, lineCounter); pdfPage.DrawString(LabelConstant.ChannelOneLabel, boldFont, Color.Black, PDFcoordinates.secondColumn, lineCounter); if (channelTwoEnabled) { pdfPage.DrawString(LabelConstant.ChannelTwoLabel, boldFont, Color.Black, PDFcoordinates.thirdColumn, (float)lineCounter); } lineCounter += PDFcoordinates.lineInc; if (channelOne.AboveLimits > 0) { pdfPage.DrawString(DecodeConstant.Exceeded, font, Color.Black, PDFcoordinates.secondColumn + 50, (float)lineCounter); } if (channelTwo.AboveLimits > 0) { pdfPage.DrawString(DecodeConstant.Exceeded, font, Color.Black, PDFcoordinates.thirdColumn + 50, (float)lineCounter); } DrawChannelStatistics(LabelConstant.PresentUpperLimit, c => c.PresetUpperLimit.ToString("N2")); if (channelOne.BelowLimits > 0) { pdfPage.DrawString(DecodeConstant.Exceeded, font, Color.Black, PDFcoordinates.secondColumn + 50, (float)lineCounter); } if (channelTwo.BelowLimits > 0) { pdfPage.DrawString(DecodeConstant.Exceeded, font, Color.Black, PDFcoordinates.thirdColumn + 50, (float)lineCounter); } DrawChannelStatistics(LabelConstant.PresentLowerLimit, c => c.PresetLowerLimit.ToString("N2")); DrawChannelStatistics(LabelConstant.Mean, c => c.Mean.ToString("N2")); DrawChannelStatistics(LabelConstant.MKT, c => c.MKT.ToString("N2")); DrawChannelStatistics(LabelConstant.Max, c => c.Max.ToString("N2")); DrawChannelStatistics(LabelConstant.Min, c => c.Min.ToString("N2")); lineCounter += (PDFcoordinates.lineInc * 0.5); DrawChannelLimits(LabelConstant.SampleWithinLimits, c => c.WithinLimits.ToString()); DrawChannelLimits(LabelConstant.TimeWithinLimits, c => c.TimeWithinLimits); lineCounter += (PDFcoordinates.lineInc * 0.5); DrawChannelLimits(LabelConstant.SampleOutofLimits, c => c.OutsideLimits.ToString()); DrawChannelLimits(LabelConstant.TimeOutOfLimits, c => c.TimeOutLimits); lineCounter += (PDFcoordinates.lineInc * 0.5); DrawChannelLimits(LabelConstant.SampleAboveLimit, c => c.AboveLimits.ToString()); DrawChannelLimits(LabelConstant.TimeAboveLimit, c => c.TimeAboveLimits); lineCounter += (PDFcoordinates.lineInc * 0.5); DrawChannelLimits(LabelConstant.SampleBelowLimit, c => c.BelowLimits.ToString()); DrawChannelLimits(LabelConstant.TimeBelowLimit, c => c.TimeBelowLimits); DrawSection(LabelConstant.UserComment, string.Empty); if (loggerVariables.UserData.Length > 140) { var firstLine = loggerVariables.UserData.Substring(0, loggerVariables.UserData.Length / 2); var secondLine = loggerVariables.UserData.Substring(loggerVariables.UserData.Length / 2); pdfPage.DrawString(firstLine, font, Color.Black, PDFcoordinates.firstColumn, lineCounter); lineCounter += PDFcoordinates.lineInc; pdfPage.DrawString(secondLine, font, Color.Black, PDFcoordinates.firstColumn, lineCounter); lineCounter += PDFcoordinates.lineInc * 0.5; } else { pdfPage.DrawString(loggerVariables.UserData, font, Color.Black, PDFcoordinates.firstColumn, lineCounter); lineCounter += PDFcoordinates.lineInc; } pdfPage.DrawLine(pen, 20, lineCounter, 680, lineCounter); lineCounter += PDFcoordinates.lineInc * 0.75; pdfPage.DrawString(LabelConstant.ChannelOneLabel + channelOne.Unit, font, Color.DarkOliveGreen, PDFcoordinates.secondColumn, lineCounter); if (channelTwoEnabled) { pdfPage.DrawString(LabelConstant.ChannelTwoLabel + channelTwo.Unit, font, Color.MediumPurple, PDFcoordinates.secondColumn + 120, lineCounter); } lineCounter += PDFcoordinates.lineInc; pdfPage.DrawString(LabelConstant.Comment, font, Color.Black, PDFcoordinates.commentX, PDFcoordinates.commentY); pdfPage.DrawString(LabelConstant.Signature, font, Color.Black, PDFcoordinates.sigX, PDFcoordinates.sigY); //Draw graph DrawGraph(decoder, loggerVariables, pdfPage, pen, font); FillInValues(decoder, loggerVariables, loggerInformation.SerialNumber); var saveFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Temprecord\\TempLite\\"; var filename = saveFilePath + loggerInformation.SerialNumber + ".pdf"; pdfDocument.Save(filename); return(true); }