private void worker_DoWork(object sender, DoWorkEventArgs e) { m_Word = PrintReport(); }
private Word PrintReport() { worker.ReportProgress(5); GetCondenserData(); CondenserTest.ReportType type = CondenserTest.ReportType.Common; if (ci.listCondenserTest.Count == 0) { MyLocalizer.XtraMessageBoxShow("Для данного конденсатора не проводились испытания.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } if (ci.listCondenserTest[ci.iCondenserTestIndex].CondenserTestType == CondenserTest.CondenserTestType.Resource) { type = CondenserTest.ReportType.Resource; } if (ci.listCondenserTest[ci.iCondenserTestIndex].CondenserTestType == CondenserTest.CondenserTestType.Acceptance) { type = CondenserTest.ReportType.Acceptance; } if (ci.listCondenserTest[ci.iCondenserTestIndex].CondenserTestType == CondenserTest.CondenserTestType.Operational && m_CondenserTestID > 0) { type = CondenserTest.ReportType.Operational; } Word word = new Word(); List <KeyValuePair <string, string> > bookmarks = new List <KeyValuePair <string, string> >(); worker.ReportProgress(50); //try { switch (type) { case CondenserTest.ReportType.Resource: if (!word.Start(AppDomain.CurrentDomain.BaseDirectory + "/Reports/Ресурсные_испытания.dot")) { return(null); } break; case CondenserTest.ReportType.Acceptance: if (!word.Start(AppDomain.CurrentDomain.BaseDirectory + "/Reports/Приемо_сдаточные_испытания.dot")) { return(null); } break; case CondenserTest.ReportType.Operational: if (!word.Start(AppDomain.CurrentDomain.BaseDirectory + "/Reports/Эксплуатационные_испытания.dot")) { return(null); } break; case CondenserTest.ReportType.Common: if (!word.Start(AppDomain.CurrentDomain.BaseDirectory + "/Reports/Сводный_протокол.dot")) { return(null); } break; } bookmarks.Add(new KeyValuePair <string, string>("CondenserNumber", ci.strCondenserNumber)); bookmarks.Add(new KeyValuePair <string, string>("CondenserNumber2", ci.strCondenserNumber)); bookmarks.Add(new KeyValuePair <string, string>("CondenserNumber3", ci.strCondenserNumber)); bookmarks.Add(new KeyValuePair <string, string>("CondenserTypeName", ci.strCondenserTypeName)); bookmarks.Add(new KeyValuePair <string, string>("CondenserVolume", ci.fCondenserVolume.ToString())); bookmarks.Add(new KeyValuePair <string, string>("CondenserWeight", ci.fCondenserWeight.ToString())); if (type == CondenserTest.ReportType.Acceptance || type == CondenserTest.ReportType.Operational || type == CondenserTest.ReportType.Common) { bookmarks.Add(new KeyValuePair <string, string>("NormalizedResource", ci.iNormalizedResource.ToString())); } bookmarks.Add(new KeyValuePair <string, string>("EnergyCharge", ci.fEnergyCharge.ToString())); bookmarks.Add(new KeyValuePair <string, string>("Inductivity", ci.fInductivity.ToString())); bookmarks.Add(new KeyValuePair <string, string>("InsulatingLiquidTypeName", ci.strInsulatingLiquidTypeName)); bookmarks.Add(new KeyValuePair <string, string>("MaxDischargeCurrent", ci.fMaxDischargeCurrent.ToString())); bookmarks.Add(new KeyValuePair <string, string>("NominalCapacitance", ci.fNominalCapacitance.ToString())); bookmarks.Add(new KeyValuePair <string, string>("NominalVoltage", ci.fNominalVoltage.ToString())); if (type == CondenserTest.ReportType.Common) { if (ci.listCondenserTest[0].CondenserTestType == CondenserTest.CondenserTestType.Acceptance) { bookmarks.Add(new KeyValuePair <string, string>("PSIDate", ci.listCondenserTest[0].dtCondenserTestDate.ToShortDateString())); if (ci.listCondenserTest[0].fH2 != null) { bookmarks.Add(new KeyValuePair <string, string>("H2", ci.listCondenserTest[0].fH2.ToString())); } if (ci.listCondenserTest[0].fN2 != null) { bookmarks.Add(new KeyValuePair <string, string>("N2", ci.listCondenserTest[0].fN2.ToString())); } if (ci.listCondenserTest[0].fO2 != null) { bookmarks.Add(new KeyValuePair <string, string>("O2", ci.listCondenserTest[0].fO2.ToString())); } if (ci.listCondenserTest[0].fC2H2 != null) { bookmarks.Add(new KeyValuePair <string, string>("C2H2", ci.listCondenserTest[0].fC2H2.ToString())); } if (ci.listCondenserTest[0].fC2H4 != null) { bookmarks.Add(new KeyValuePair <string, string>("C2H4", ci.listCondenserTest[0].fC2H4.ToString())); } if (ci.listCondenserTest[0].fC2H6 != null) { bookmarks.Add(new KeyValuePair <string, string>("C2H6", ci.listCondenserTest[0].fC2H6.ToString())); } if (ci.listCondenserTest[0].fCH4 != null) { bookmarks.Add(new KeyValuePair <string, string>("CH4", ci.listCondenserTest[0].fCH4.ToString())); } if (ci.listCondenserTest[0].fCO != null) { bookmarks.Add(new KeyValuePair <string, string>("CO", ci.listCondenserTest[0].fCO.ToString())); } if (ci.listCondenserTest[0].fCO2 != null) { bookmarks.Add(new KeyValuePair <string, string>("CO2", ci.listCondenserTest[0].fCO2.ToString())); } } } if (type != CondenserTest.ReportType.Common) { if (ci.listCondenserTest[ci.iCondenserTestIndex].CondenserTestType == CondenserTest.CondenserTestType.Operational) { bookmarks.Add(new KeyValuePair <string, string>("Index", (ci.iCondenserTestIndex).ToString("00"))); // т.к. первое всегда идет приемо-сдаточное } else { bookmarks.Add(new KeyValuePair <string, string>("Index", (ci.iCondenserTestIndex + 1).ToString("00"))); } bookmarks.Add(new KeyValuePair <string, string>("CondenserTestDate", ci.listCondenserTest[ci.iCondenserTestIndex].dtCondenserTestDate.ToShortDateString())); if (type == CondenserTest.ReportType.Resource || type == CondenserTest.ReportType.Operational) { bookmarks.Add(new KeyValuePair <string, string>("CycleCount", ci.listCondenserTest[ci.iCondenserTestIndex].iCycleCount.ToString())); } if (type == CondenserTest.ReportType.Resource) { bookmarks.Add(new KeyValuePair <string, string>("Conclusion", ci.listCondenserTest[ci.iCondenserTestIndex].CondenserState == CondenserTest.CondenserTestState.Work ? "работоспособен" : "неработоспособен")); } if (type == CondenserTest.ReportType.Acceptance || type == CondenserTest.ReportType.Operational) { bookmarks.Add(new KeyValuePair <string, string>("Conclusion", ci.listCondenserTest[ci.iCondenserTestIndex].strConclusion)); bookmarks.Add(new KeyValuePair <string, string>("Recommendation", ci.listCondenserTest[ci.iCondenserTestIndex].strRecommendation)); } bookmarks.Add(new KeyValuePair <string, string>("CondenserTestEquipment", ci.listCondenserTest[ci.iCondenserTestIndex].strCondenserTestEquipment)); bookmarks.Add(new KeyValuePair <string, string>("Temperature", ci.listCondenserTest[ci.iCondenserTestIndex].strTemperature)); bookmarks.Add(new KeyValuePair <string, string>("TestVoltageAmplitude", ci.listCondenserTest[ci.iCondenserTestIndex].fTestVoltageAmplitude.ToString())); bookmarks.Add(new KeyValuePair <string, string>("TestVoltageFrequency", ci.listCondenserTest[ci.iCondenserTestIndex].fTestVoltageFrequency.ToString())); if (ci.listCondenserTest[ci.iCondenserTestIndex].dtAnalysisDateExecute != null) { bookmarks.Add(new KeyValuePair <string, string>("AnalysisDateExecute", ((DateTime)ci.listCondenserTest[ci.iCondenserTestIndex].dtAnalysisDateExecute).ToShortDateString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].dtAnalysisDateProbe != null) { bookmarks.Add(new KeyValuePair <string, string>("AnalysisDateProbe", ((DateTime)ci.listCondenserTest[ci.iCondenserTestIndex].dtAnalysisDateProbe).ToShortDateString())); } bookmarks.Add(new KeyValuePair <string, string>("AnalysisEmployeeFIO", ci.listCondenserTest[ci.iCondenserTestIndex].strAnalysisEmployeeFIO)); if (ci.listCondenserTest[ci.iCondenserTestIndex].fH2 != null) { bookmarks.Add(new KeyValuePair <string, string>("H2", ci.listCondenserTest[ci.iCondenserTestIndex].fH2.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fN2 != null) { bookmarks.Add(new KeyValuePair <string, string>("N2", ci.listCondenserTest[ci.iCondenserTestIndex].fN2.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fO2 != null) { bookmarks.Add(new KeyValuePair <string, string>("O2", ci.listCondenserTest[ci.iCondenserTestIndex].fO2.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fC2H2 != null) { bookmarks.Add(new KeyValuePair <string, string>("C2H2", ci.listCondenserTest[ci.iCondenserTestIndex].fC2H2.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fC2H4 != null) { bookmarks.Add(new KeyValuePair <string, string>("C2H4", ci.listCondenserTest[ci.iCondenserTestIndex].fC2H4.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fC2H6 != null) { bookmarks.Add(new KeyValuePair <string, string>("C2H6", ci.listCondenserTest[ci.iCondenserTestIndex].fC2H6.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fCH4 != null) { bookmarks.Add(new KeyValuePair <string, string>("CH4", ci.listCondenserTest[ci.iCondenserTestIndex].fCH4.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fCO != null) { bookmarks.Add(new KeyValuePair <string, string>("CO", ci.listCondenserTest[ci.iCondenserTestIndex].fCO.ToString())); } if (ci.listCondenserTest[ci.iCondenserTestIndex].fCO2 != null) { bookmarks.Add(new KeyValuePair <string, string>("CO2", ci.listCondenserTest[ci.iCondenserTestIndex].fCO2.ToString())); } } word.SetBookmarkText(bookmarks); worker.ReportProgress(80); if (type == CondenserTest.ReportType.Operational) { if (ci.listCondenserTest[ci.iCondenserTestIndex].listSheduler.Count > 1) { word.InsertRowsInTable(3, ci.listCondenserTest[ci.iCondenserTestIndex].listSheduler.Count - 1); } for (int i = 0; i < ci.listCondenserTest[ci.iCondenserTestIndex].listSheduler.Count; i++) { word.SetTextInCell(1, i + 1 + 1, ci.listCondenserTest[ci.iCondenserTestIndex].listSheduler[i].dtShedulerDate.ToShortDateString(), 3); word.SetTextInCell(2, i + 1 + 1, ci.listCondenserTest[ci.iCondenserTestIndex].listSheduler[i].dtShedulerDate.ToString("HH:mm"), 3); word.SetTextInCell(3, i + 1 + 1, ci.listCondenserTest[ci.iCondenserTestIndex].listSheduler[i].iShedulerCycleCount.ToString(), 3); } } if (type == CondenserTest.ReportType.Common) { word.InsertRowsInTable(2, ci.listCondenserTest.Count - 2); int iRowIndex = 4; long iCycleCount = 0; for (int i = 0; i < ci.listCondenserTest.Count; i++) { if (ci.listCondenserTest[i].CondenserTestType == CondenserTest.CondenserTestType.Operational) { word.SetTextInCell(1, iRowIndex, ci.listCondenserTest[i].dtCondenserTestDate.ToShortDateString(), 2); if (ci.listCondenserTest[i].iCycleCount != null) { iCycleCount += (long)ci.listCondenserTest[i].iCycleCount; } word.SetTextInCell(2, iRowIndex, iCycleCount.ToString(), 2); if (ci.listCondenserTest[i].fH2 != null) { word.SetTextInCell(3, iRowIndex, ci.listCondenserTest[i].fH2.ToString(), 2); } if (ci.listCondenserTest[i].fO2 != null) { word.SetTextInCell(4, iRowIndex, ci.listCondenserTest[i].fO2.ToString(), 2); } if (ci.listCondenserTest[i].fN2 != null) { word.SetTextInCell(5, iRowIndex, ci.listCondenserTest[i].fN2.ToString(), 2); } if (ci.listCondenserTest[i].fCH4 != null) { word.SetTextInCell(6, iRowIndex, ci.listCondenserTest[i].fCH4.ToString(), 2); } if (ci.listCondenserTest[i].fCO != null) { word.SetTextInCell(7, iRowIndex, ci.listCondenserTest[i].fCO.ToString(), 2); } if (ci.listCondenserTest[i].fCO2 != null) { word.SetTextInCell(8, iRowIndex, ci.listCondenserTest[i].fCO2.ToString(), 2); } if (ci.listCondenserTest[i].fC2H4 != null) { word.SetTextInCell(9, iRowIndex, ci.listCondenserTest[i].fC2H4.ToString(), 2); } if (ci.listCondenserTest[i].fC2H6 != null) { word.SetTextInCell(10, iRowIndex, ci.listCondenserTest[i].fC2H6.ToString(), 2); } if (ci.listCondenserTest[i].fC2H2 != null) { word.SetTextInCell(11, iRowIndex, ci.listCondenserTest[i].fC2H2.ToString(), 2); } iRowIndex++; } } if (ci.listCondenserTest.Count > 2) { List <Word.BorderInfo> listBorders = new List <Word.BorderInfo>(); listBorders.Add(new Word.BorderInfo(Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth075pt, Microsoft.Office.Interop.Word.WdColor.wdColorBlack)); listBorders.Add(new Word.BorderInfo(Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth075pt, Microsoft.Office.Interop.Word.WdColor.wdColorBlack)); word.SetCellsBorders(1, 11, 4, 4 + ci.listCondenserTest.Count - 1, listBorders, 2); } } else { if (ci.listCondenserTest[ci.iCondenserTestIndex].TestVoltageImageForm != null) { ci.listCondenserTest[ci.iCondenserTestIndex].TestVoltageImageForm.Save(AppDomain.CurrentDomain.BaseDirectory + "/Reports/tmp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); word.InsertPicture(AppDomain.CurrentDomain.BaseDirectory + "/Reports/tmp.jpg", Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter, "TestVoltageImageForm"); } } worker.ReportProgress(100); return(word); } }