private void AppendToSheetsTable( WordprocessingDocument document, List <Doc> sheets) { Body body = document.MainDocumentPart.Document.Body; var t = body.Descendants <Table>().ToList()[0]; var firstTr = t.Descendants <TableRow>().ToList()[2]; var clonedFirstTr = firstTr.CloneNode(true); var trCells = firstTr.Descendants <TableCell>().ToList(); OpenXmlElement newTr = null; for (int i = 0; i < sheets.Count(); i++) { if (i != 0) { newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); } trCells[0].GetFirstChild <Paragraph>().Append( Word.GetTextElement((i + 1).ToString(), 22)); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement(sheets[i].Name, 22)); trCells[2].GetFirstChild <Paragraph>().Append( Word.GetTextElement(sheets[i].Note, 22)); var p = trCells[3].GetFirstChild <Paragraph>(); if (sheets[i].Creator != null) { var run = Word.GetTextElement(sheets[i].Creator.Name, 22); if (sheets[i].NormContr != null) { run.AppendChild(new Break()); } p.Append(run); } if (sheets[i].NormContr != null) { p.Append(Word.GetTextElement(sheets[i].NormContr.Name, 22)); } trCells[4].GetFirstChild <Paragraph>().Append( Word.GetTextElement(sheets[i].Form.ToStringWithComma(), 22)); if (i != 0) { t.Append(newTr); } if (i != sheets.Count() - 1) { RemoveBorders(trCells); } } }
public static void AppendToMainSmallFooterTable(WordprocessingDocument document, string markName) { var columnIndexToFill = 6; MainDocumentPart mainPart = document.MainDocumentPart; var commonFooter = mainPart.FooterParts.LastOrDefault(); var t = commonFooter.RootElement.Descendants <Table>().FirstOrDefault(); var firstTr = t.Descendants <TableRow>().FirstOrDefault(); var firstTrCells = firstTr.Descendants <TableCell>().ToList(); var tc = firstTrCells[columnIndexToFill]; var p = tc.GetFirstChild <Paragraph>(); p.Append(Word.GetTextElement(markName, 28)); }
private void AppendToTable( WordprocessingDocument document, List <ConstructionBolt> bolts, List <BoltLength> boltLengths) { if (bolts.Count() > 0) { Body body = document.MainDocumentPart.Document.Body; var t = body.Descendants <Table>().FirstOrDefault(); var firstTr = t.Descendants <TableRow>().ToList()[0]; var clonedFirstTr = firstTr.CloneNode(true); var trCells = firstTr.Descendants <TableCell>().ToList(); for (int i = 0; i < bolts.Count(); i++) { InsertThreeRows(trCells, clonedFirstTr, t, i + 1, bolts[i], boltLengths[i]); } var newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement("Всего", 24)); double sum = 0.0; for (var i = 0; i < bolts.Count(); i++) { sum += Math.Ceiling(bolts[i].Num * boltLengths[i].Weight * 10) / 10; } trCells[7].GetFirstChild <Paragraph>().Append( Word.GetTextElement(Math.Round(sum, 1).ToStringWithComma(), 24)); sum = 0.0; for (var i = 0; i < bolts.Count(); i++) { sum += Math.Ceiling(bolts[i].NutNum * bolts[i].Diameter.NutWeight * 10) / 10; } trCells[8].GetFirstChild <Paragraph>().Append( Word.GetTextElement(Math.Round(sum, 1).ToStringWithComma(), 24)); sum = 0.0; for (var i = 0; i < bolts.Count(); i++) { sum += Math.Ceiling(bolts[i].WasherNum * bolts[i].Diameter.WasherWeight * 10) / 10; } trCells[9].GetFirstChild <Paragraph>().Append( Word.GetTextElement(Math.Round(sum, 1).ToStringWithComma(), 24)); t.Append(newTr); } }
private void AppendToAttachedDocsTable( WordprocessingDocument document, List <AttachedDoc> attachedDocs) { Body body = document.MainDocumentPart.Document.Body; var t = body.Descendants <Table>().ToList()[2]; var firstTr = t.Descendants <TableRow>().ToList()[2]; var clonedFirstTr = firstTr.CloneNode(true); var trCells = firstTr.Descendants <TableCell>().ToList(); OpenXmlElement newTr = null; for (int i = 0; i < attachedDocs.Count(); i++) { if (i != 0) { newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); } trCells[0].GetFirstChild <Paragraph>().Append( Word.GetTextElement(attachedDocs[i].Designation, 22)); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement(attachedDocs[i].Name, 22)); trCells[2].GetFirstChild <Paragraph>().Append( Word.GetTextElement(attachedDocs[i].Note, 22)); if (i != 0) { t.Append(newTr); } if (i != attachedDocs.Count() - 1) { RemoveBorders(trCells); } } }
private void InsertThreeRows( List <TableCell> trCells, OpenXmlElement clonedFirstTr, Table t, int num, ConstructionBolt bolt, BoltLength boltLength) { // Болт OpenXmlElement newTr = null; if (num != 1) { newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); } trCells[0].GetFirstChild <Paragraph>().Append( Word.GetTextElement(num.ToString(), 24)); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement($"Высокопрочные болты по {bolt.Diameter.BoltTechSpec}", 24)); trCells[2].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Diameter.Diameter.ToString(), 24)); trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Diameter.StrengthClass.ToStringWithComma(), 24)); trCells[4].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Packet.ToString(), 24)); trCells[5].GetFirstChild <Paragraph>().Append( Word.GetTextElement(boltLength.Length.ToString(), 24)); trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Num.ToString(), 24)); trCells[7].GetFirstChild <Paragraph>().Append( Word.GetTextElement( (Math.Ceiling(bolt.Num * boltLength.Weight * 10) / 10).ToStringWithComma(), 24)); Word.MakeBordersThin(trCells, true, false); if (num != 1) { t.Append(newTr); } // Гайка newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement($"Гайки по {bolt.Diameter.NutTechSpec}", 24)); trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement("?", 24)); trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.NutNum.ToString(), 24)); trCells[8].GetFirstChild <Paragraph>().Append( Word.GetTextElement( (Math.Ceiling(bolt.NutNum * bolt.Diameter.NutWeight * 10) / 10).ToStringWithComma(), 24)); Word.MakeBordersThin(trCells); t.Append(newTr); // Шайба newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement($"Шайбы по {bolt.Diameter.WasherTechSpec}", 24)); trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Diameter.WasherSteel, 24)); trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.WasherNum.ToString(), 24)); trCells[9].GetFirstChild <Paragraph>().Append( Word.GetTextElement( (Math.Ceiling(bolt.WasherNum * bolt.Diameter.WasherWeight * 10) / 10).ToStringWithComma(), 24)); Word.MakeBordersThin(trCells, false); t.Append(newTr); }
private void AppendToAdditionalWorkTable( WordprocessingDocument document, List <Dtos.AdditionalWorkResponse> additionalWork) { const double valuationCoeff = 0.05; const double orderCoeff = 0.004; Body body = document.MainDocumentPart.Document.Body; var t = body.Descendants <Table>().ToList()[3]; var firstTr = t.Descendants <TableRow>().ToList()[3]; var clonedFirstTr = firstTr.CloneNode(true); var trCells = firstTr.Descendants <TableCell>().ToList(); OpenXmlElement newTr = null; double sum; for (int i = 0; i < additionalWork.Count(); i++) { if (i != 0) { newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); } sum = 0.0; trCells[0].GetFirstChild <Paragraph>().Append( Word.GetTextElement(additionalWork[i].Employee.Fullname, 22)); if (Math.Abs(additionalWork[i].DrawingsCompleted) > 0.0000001) { sum += additionalWork[i].DrawingsCompleted; trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement(additionalWork[i].DrawingsCompleted.ToStringWithComma(), 22)); } if (Math.Abs(additionalWork[i].DrawingsCheck) > 0.0000001) { trCells[2].GetFirstChild <Paragraph>().Append( Word.GetTextElement(additionalWork[i].DrawingsCheck.ToStringWithComma(), 22)); } if (Math.Abs(additionalWork[i].DrawingsCheck) > 0.0000001) { var v = Math.Round(additionalWork[i].DrawingsCheck * valuationCoeff, 3); sum += v; trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement(v.ToStringWithComma(), 22)); } if (additionalWork[i].Valuation != 0) { trCells[4].GetFirstChild <Paragraph>().Append( Word.GetTextElement(additionalWork[i].Valuation.ToString(), 22)); } if (additionalWork[i].Valuation != 0) { var v = Math.Round(additionalWork[i].Valuation * valuationCoeff, 3); sum += v; trCells[5].GetFirstChild <Paragraph>().Append( Word.GetTextElement(v.ToStringWithComma(), 22)); } if (additionalWork[i].MetalOrder != 0) { trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(additionalWork[i].MetalOrder.ToString(), 22)); } if (additionalWork[i].MetalOrder != 0) { var v = Math.Round(additionalWork[i].MetalOrder * orderCoeff, 3); sum += v; trCells[7].GetFirstChild <Paragraph>().Append( Word.GetTextElement(v.ToStringWithComma(), 22)); } trCells[8].GetFirstChild <Paragraph>().Append( Word.GetTextElement(Math.Round(sum, 3).ToStringWithComma(), 22)); if (i != 0) { t.Append(newTr); } if (i != additionalWork.Count() - 1) { RemoveBorders(trCells); } } newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); sum = 0.0; var p = trCells[0].GetFirstChild <Paragraph>(); p.ParagraphProperties.Append(new Justification { Val = JustificationValues.Center, }); p.Append(Word.GetTextElement("Итого:", 22)); var sum2 = additionalWork.Sum(v => v.DrawingsCompleted); if (Math.Abs(sum2) > 0.0000001) { sum += sum2; trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement(sum2.ToStringWithComma(), 22)); } sum2 = additionalWork.Sum(v => v.DrawingsCheck); if (Math.Abs(sum2) > 0.0000001) { trCells[2].GetFirstChild <Paragraph>().Append( Word.GetTextElement(sum2.ToStringWithComma(), 22)); } if (Math.Abs(sum2) > 0.0000001) { var v = Math.Round(sum2 * valuationCoeff, 3); sum += v; trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement(v.ToStringWithComma(), 22)); } sum2 = additionalWork.Sum(v => v.Valuation); if (sum2 != 0) { trCells[4].GetFirstChild <Paragraph>().Append( Word.GetTextElement(sum2.ToString(), 22)); } if (sum2 != 0) { var v = Math.Round(sum2 * valuationCoeff, 3); sum += v; trCells[5].GetFirstChild <Paragraph>().Append( Word.GetTextElement(v.ToStringWithComma(), 22)); } sum2 = additionalWork.Sum(v => v.MetalOrder); if (sum2 != 0) { trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(sum2.ToString(), 22)); } if (sum2 != 0) { var v = Math.Round(sum2 * orderCoeff, 3); sum += v; trCells[7].GetFirstChild <Paragraph>().Append( Word.GetTextElement(v.ToStringWithComma(), 22)); } trCells[8].GetFirstChild <Paragraph>().Append( Word.GetTextElement(Math.Round(sum, 3).ToStringWithComma(), 22)); t.Append(newTr); }