示例#1
0
        static void EditEndnote(Document document)
        {
            #region #EditEndnote
            document.LoadDocument("Documents//Grimm.docx");

            //Access the first endnote's content:
            SubDocument endnote = document.Endnotes[0].BeginUpdate();

            //Exclude the reference mark and the space after it from the range to be edited:
            DocumentRange noteTextRange = endnote.CreateRange(endnote.Range.Start.ToInt() + 2, endnote.Range.Length
                                                              - 2);

            //Access the range's character properties:
            CharacterProperties characterProperties = endnote.BeginUpdateCharacters(noteTextRange);

            characterProperties.ForeColor = System.Drawing.Color.Red;
            characterProperties.Italic    = true;

            //Finalize the character options update:
            endnote.EndUpdateCharacters(characterProperties);

            //Finalize the endnote update:
            document.Endnotes[0].EndUpdate(endnote);
            #endregion #EditEndnote
        }
示例#2
0
        static void EditSeparator(Document document)
        {
            #region #EditSeparator
            document.LoadDocument("Documents//Grimm.docx");

            //Check whether the footnotes already have a separator:
            if (document.Footnotes.HasSeparator(NoteSeparatorType.Separator))
            {
                //Initiate the update session:
                SubDocument noteSeparator = document.Footnotes.BeginUpdateSeparator(NoteSeparatorType.Separator);

                //Clear the separator range:
                noteSeparator.Delete(noteSeparator.Range);

                //Append a new text:
                noteSeparator.AppendText("***");

                CharacterProperties characterProperties = noteSeparator.BeginUpdateCharacters(noteSeparator.Range);
                characterProperties.ForeColor = System.Drawing.Color.Blue;
                noteSeparator.EndUpdateCharacters(characterProperties);

                //Finalize the update:
                document.Footnotes.EndUpdateSeparator(noteSeparator);
            }
            #endregion #EditSeparator
        }
        void ResetRange(DocumentRange r)
        {
            SubDocument         d  = r.BeginUpdateDocument();
            CharacterProperties cp = d.BeginUpdateCharacters(r);

            cp.BackColor = System.Drawing.Color.White;
            d.EndUpdateCharacters(cp);
            r.EndUpdateDocument(d);
        }
示例#4
0
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DocumentPosition    caretPosition = richEditControl1.Document.CaretPosition;
            SubDocument         document      = caretPosition.BeginUpdateDocument();
            DocumentRange       checkBox      = document.InsertText(caretPosition, uncheckedCheckBox);
            CharacterProperties cp            = document.BeginUpdateCharacters(checkBox);

            cp.FontName = "MS Gothic";
            document.EndUpdateCharacters(cp);
            caretPosition.EndUpdateDocument(document);
        }
        private void EditTextBoxContent(Document document)
        {
            #region #editcontent
            //Access the text box content
            SubDocument textBoxDocument = document.Shapes[0].TextBox.Document;

            //Insert text to the text box
            textBoxDocument.AppendText("Multimodal, Stochastic Symmetries for E-Commerce");

            //Apply formatting to the text box content
            CharacterProperties cp = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range);
            cp.ForeColor = Color.DarkSlateGray;
            cp.FontName  = "Times New Roman";
            cp.FontSize  = 18;
            textBoxDocument.EndUpdateCharacters(cp);
            #endregion #editcontent
        }
        void biClickMe_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            #region #formatting
            DocumentRange range = richEditControl1.Document.Selection;

            SubDocument doc = range.BeginUpdateDocument();

            CharacterProperties charprop = doc.BeginUpdateCharacters(range);
            charprop.BackColor = Colors.Yellow;
            charprop.AllCaps   = true;
            doc.EndUpdateCharacters(charprop);

            ParagraphProperties parprop = doc.BeginUpdateParagraphs(range);
            parprop.Alignment = ParagraphAlignment.Center;
            doc.EndUpdateParagraphs(parprop);

            range.EndUpdateDocument(doc);
            #endregion #formatting
        }
 static void AddTextBox(Document document)
 {
     #region #AddTextBox
     document.AppendText("Line One\nLine Two\nLine Three");
     Shape myTextBox = document.Shapes.InsertTextBox(document.CreatePosition(15));
     myTextBox.HorizontalAlignment = ShapeHorizontalAlignment.Center;
     // Specify the text box background color.
     myTextBox.Fill.Color = System.Drawing.Color.WhiteSmoke;
     // Draw a border around the text box.
     myTextBox.Line.Color     = System.Drawing.Color.Black;
     myTextBox.Line.Thickness = 1;
     // Modify text box content.
     SubDocument textBoxDocument = myTextBox.TextBox.Document;
     textBoxDocument.AppendText("TextBox Text");
     CharacterProperties cp = textBoxDocument.BeginUpdateCharacters(textBoxDocument.Range.Start, 7);
     cp.ForeColor = System.Drawing.Color.Orange;
     cp.FontSize  = 24;
     textBoxDocument.EndUpdateCharacters(cp);
     #endregion #AddTextBox
 }
 void InsertColumnNumbers(TableRow row)
 {
     foreach (TableCell _cell in row.Cells)
     {
         if (_cell.Index == 0)
         {
             continue;
         }
         _cell.BackgroundColor = Colors.Transparent;
         SubDocument         doc   = _cell.Range.BeginUpdateDocument();
         DocumentRange       range = doc.InsertSingleLineText(_cell.Range.Start, String.Format("{0}", _cell.Index + 1));
         CharacterProperties cp    = doc.BeginUpdateCharacters(range);
         cp.Bold      = true;
         cp.FontName  = "Comic Sans";
         cp.FontSize  = 12;
         cp.ForeColor = Colors.Red;
         doc.EndUpdateCharacters(cp);
         range.EndUpdateDocument(doc);
     }
 }
        private void btnSetRange_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (coloredRange != null)
            {
                ResetRange(coloredRange);
            }

            coloredRange = richEditControl1.Document.Selection;
            if (coloredRange.Length == 0)
            {
                return;
            }

            // Highlight selected range.
            SubDocument         d  = coloredRange.BeginUpdateDocument();
            CharacterProperties cp = d.BeginUpdateCharacters(coloredRange);

            cp.BackColor = System.Drawing.Color.Yellow;
            d.EndUpdateCharacters(cp);
            coloredRange.EndUpdateDocument(d);

            // Create a new iterator limited to the specified range.
            layoutIterator = new LayoutIterator(richEditControl1.DocumentLayout, coloredRange);

            doc = coloredRange.BeginUpdateDocument();
            richEditControl1.Document.ChangeActiveDocument(doc);
            coloredRange.EndUpdateDocument(doc);

            // Select the first element in the highlighted range.
            RangedLayoutElement el = richEditControl1.DocumentLayout.GetElement(coloredRange.Start, LayoutType.PlainTextBox);

            while (layoutIterator.MoveNext())
            {
                RangedLayoutElement element = layoutIterator.Current as RangedLayoutElement;
                if ((element != null) && (element.Equals(el)))
                {
                    UpdateInfoAndSelection();
                    return;
                }
            }
        }
        protected internal MemoryStream ExaminationPlanTemplate()
        {
            Document doc = reds.Document;

            doc.Sections[0].Page.PaperKind          = System.Drawing.Printing.PaperKind.A4;
            doc.DefaultCharacterProperties.FontSize = 12;
            doc.Unit = DevExpress.Office.DocumentUnit.Centimeter;
            doc.Sections[0].Margins.Bottom       = 2;
            doc.Sections[0].Margins.Top          = 2;
            doc.Sections[0].Margins.Left         = 2;
            doc.Sections[0].Margins.Right        = 2;
            doc.Sections[0].Margins.FooterOffset = 0.8F;

            doc.Unit = DevExpress.Office.DocumentUnit.Point;

            Section             firstSection = doc.Sections[0];
            SubDocument         subdoc       = firstSection.BeginUpdateHeader(HeaderFooterType.Primary);
            DocumentRange       textRange    = subdoc.AppendText("Kezelési Terv");
            CharacterProperties cp1          = subdoc.BeginUpdateCharacters(textRange);

            cp1.Bold     = true;
            cp1.Italic   = true;
            cp1.FontSize = 18;
            subdoc.EndUpdateCharacters(cp1);
            subdoc.Paragraphs[0].Alignment       = ParagraphAlignment.Center;
            subdoc.Paragraphs[0].LineSpacingType = ParagraphLineSpacing.Sesquialteral;
            doc.Sections[0].EndUpdateHeader(subdoc);

            doc.Protect("admin");

            using (MemoryStream ms = new MemoryStream())
            {
                reds.SaveDocument(ms, DocumentFormat.OpenXml);
                return(ms);
            }
        }
        private void ApplyFormatToSelectedText()
        {
            DocumentRange targetSelectedRange = richEditControl.Document.Selection;

            richEditControl.BeginUpdate();
            SubDocument targetSubDocument = targetSelectedRange.BeginUpdateDocument();
            SubDocument subDocument       = sourceSelectedRange.BeginUpdateDocument();

            DevExpress.XtraRichEdit.API.Native.CharacterProperties targetCharactersProperties = targetSubDocument.BeginUpdateCharacters(targetSelectedRange);
            DevExpress.XtraRichEdit.API.Native.CharacterProperties sourceCharactersProperties = subDocument.BeginUpdateCharacters(sourceSelectedRange);
            targetCharactersProperties.Assign(sourceCharactersProperties);
            subDocument.EndUpdateCharacters(sourceCharactersProperties);
            targetSubDocument.EndUpdateCharacters(targetCharactersProperties);

            DevExpress.XtraRichEdit.API.Native.ParagraphProperties targetParagraphProperties = targetSubDocument.BeginUpdateParagraphs(targetSelectedRange);
            DevExpress.XtraRichEdit.API.Native.ParagraphProperties sourceParagraphProperties = subDocument.BeginUpdateParagraphs(sourceSelectedRange);
            targetParagraphProperties.Assign(sourceParagraphProperties);
            subDocument.EndUpdateParagraphs(sourceParagraphProperties);
            targetSubDocument.EndUpdateParagraphs(targetParagraphProperties);

            sourceSelectedRange.EndUpdateDocument(subDocument);
            targetSelectedRange.EndUpdateDocument(targetSubDocument);
            richEditControl.EndUpdate();
        }
        protected internal MemoryStream Billing(string Code, CreateBillM.CompanyData from, CreateBillM.CompanyData to,
                                                ObservableCollection <CreateBillM.PrintItem> PrintList, int PriceWithoutVat, int Vat, int PriceWithVat)
        {
            Document doc = reds.Document;

            doc.Sections[0].Page.PaperKind          = System.Drawing.Printing.PaperKind.A4;
            doc.DefaultCharacterProperties.FontSize = 11;
            doc.Unit = DevExpress.Office.DocumentUnit.Centimeter;
            doc.Sections[0].Margins.Bottom       = 2;
            doc.Sections[0].Margins.Top          = 2;
            doc.Sections[0].Margins.Left         = 2;
            doc.Sections[0].Margins.Right        = 2;
            doc.Sections[0].Margins.FooterOffset = 0.8F;

            doc.Unit = DevExpress.Office.DocumentUnit.Point;

            Section             firstSection = doc.Sections[0];
            SubDocument         subdoc       = firstSection.BeginUpdateHeader(HeaderFooterType.Primary);
            DocumentRange       textRange    = subdoc.AppendText("Számla");
            CharacterProperties cp1          = subdoc.BeginUpdateCharacters(textRange);

            cp1.Bold     = true;
            cp1.Italic   = true;
            cp1.FontSize = 20;
            subdoc.EndUpdateCharacters(cp1);
            subdoc.Paragraphs[0].Alignment       = ParagraphAlignment.Center;
            subdoc.Paragraphs[0].LineSpacingType = ParagraphLineSpacing.Sesquialteral;
            doc.Sections[0].EndUpdateHeader(subdoc);

            Section     section = doc.Sections[0];
            SubDocument subdoc2 = firstSection.BeginUpdateFooter(HeaderFooterType.Primary);
            Table       table2  = subdoc2.Tables.Create(subdoc2.Range.Start, 1, 2);

            table2.TableLayout        = TableLayoutType.Fixed;
            table2.PreferredWidth     = 5000;
            table2.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table2.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table2.Borders.Left.LineStyle   = TableBorderLineStyle.None;
            table2.Borders.Right.LineStyle  = TableBorderLineStyle.None;
            table2.Borders.Bottom.LineStyle = TableBorderLineStyle.None;

            subdoc2.InsertText(table2[0, 0].Range.Start, DateTime.Now.ToString("yyyy. MMMM d.", new CultureInfo("hu-HU")));
            DocumentRange       range = subdoc2.InsertText(table2[0, 0].Range.Start, "Kiállítás dátuma: ");
            CharacterProperties cp    = subdoc2.BeginUpdateCharacters(range);

            cp.Bold = true;
            subdoc2.Paragraphs[0].SpacingBefore = 3;

            subdoc2.InsertText(table2[0, 1].Range.Start, Code);
            DocumentRange       r = subdoc2.InsertText(table2[0, 1].Range.Start, "Számla azonosító: ");
            CharacterProperties c = subdoc2.BeginUpdateCharacters(r);

            c.Bold = true;
            subdoc2.Paragraphs[1].Alignment     = ParagraphAlignment.Right;
            subdoc2.Paragraphs[1].SpacingBefore = 3;
            doc.Sections[0].EndUpdateFooter(subdoc2);

            Table table = doc.Tables.Create(doc.Range.Start, 2, 2);

            table.TableLayout        = TableLayoutType.Fixed;
            table.PreferredWidth     = 5000;
            table.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table.Borders.Left.LineStyle  = TableBorderLineStyle.None;
            table.Borders.Right.LineStyle = TableBorderLineStyle.None;
            table.Borders.Top.LineStyle   = TableBorderLineStyle.None;

            DocumentRange       range2 = reds.Document.InsertText(table[0, 0].Range.Start, "Számla kiállító adatai");
            CharacterProperties cp2    = reds.Document.BeginUpdateCharacters(range2);

            cp2.FontSize = 16;
            cp2.Bold     = true;

            DocumentRange       range3 = reds.Document.InsertText(table[0, 1].Range.Start, "Vevő adatai");
            CharacterProperties cp3    = reds.Document.BeginUpdateCharacters(range3);

            cp3.FontSize = 16;
            cp3.Bold     = true;

            ParagraphProperties props = reds.Document.BeginUpdateParagraphs(table[0, 0].Range);

            props.SpacingAfter = 2;

            Table left = doc.Tables.Create(table[1, 0].Range.Start, 1, 1);

            left.TableLayout              = TableLayoutType.Fixed;
            left.PreferredWidth           = 5000;
            left.PreferredWidthType       = WidthType.FiftiethsOfPercent;
            left.Borders.Left.LineStyle   = TableBorderLineStyle.None;
            left.Borders.Right.LineStyle  = TableBorderLineStyle.None;
            left.Borders.Top.LineStyle    = TableBorderLineStyle.None;
            left.Borders.Bottom.LineStyle = TableBorderLineStyle.None;

            Table right = doc.Tables.Create(table[1, 1].Range.Start, 1, 1);

            right.TableLayout              = TableLayoutType.Fixed;
            right.PreferredWidth           = 5000;
            right.PreferredWidthType       = WidthType.FiftiethsOfPercent;
            right.Borders.Left.LineStyle   = TableBorderLineStyle.None;
            right.Borders.Right.LineStyle  = TableBorderLineStyle.None;
            right.Borders.Top.LineStyle    = TableBorderLineStyle.None;
            right.Borders.Bottom.LineStyle = TableBorderLineStyle.None;

            bool exist1 = false;
            bool exist2 = false;

            if (from.WebPage != null)
            {
                if (!exist1)
                {
                    range6 = doc.InsertText(left[0, 0].Range.Start, "WEB: " + from.WebPage);
                    exist1 = true;
                }
                else
                {
                    doc.InsertText(left[0, 0].Range.Start, "WEB: " + from.WebPage);
                }
            }
            if (to.WebPage != null)
            {
                if (!exist2)
                {
                    range7 = doc.InsertText(right[0, 0].Range.Start, "WEB: " + to.WebPage);
                    exist2 = true;
                }
                else
                {
                    doc.InsertText(right[0, 0].Range.Start, "WEB: " + to.WebPage);
                }
            }
            if (from.Email != null)
            {
                if (!exist1)
                {
                    range6 = doc.InsertText(left[0, 0].Range.Start, "Email: " + from.Email);
                    exist1 = true;
                }
                else
                {
                    doc.InsertText(left[0, 0].Range.Start, "Email: " + from.Email + "\n");
                }
            }
            if (to.Email != null)
            {
                if (!exist2)
                {
                    range7 = doc.InsertText(right[0, 0].Range.Start, "Email: " + to.Email);
                    exist2 = true;
                }
                else
                {
                    doc.InsertText(right[0, 0].Range.Start, "Email: " + to.Email + "\n");
                }
            }
            if (from.Phone != null)
            {
                if (!exist1)
                {
                    range6 = doc.InsertText(left[0, 0].Range.Start, "Telefon: " + from.Phone);
                    exist1 = true;
                }
                else
                {
                    doc.InsertText(left[0, 0].Range.Start, "Telefon: " + from.Phone + "\n");
                }
            }
            if (to.Phone != null)
            {
                if (!exist2)
                {
                    range7 = doc.InsertText(right[0, 0].Range.Start, "Telefon: " + to.Phone);
                    exist2 = true;
                }
                else
                {
                    doc.InsertText(right[0, 0].Range.Start, "Telefon: " + to.Phone + "\n");
                }
            }

            if (from.InvoiceNumber != null)
            {
                if (!exist1)
                {
                    range6 = doc.InsertText(left[0, 0].Range.Start, "Bankszámlaszám: " + from.InvoiceNumber);
                    exist1 = true;
                }
                else
                {
                    doc.InsertText(left[0, 0].Range.Start, "Bankszámlaszám: " + from.InvoiceNumber + "\n");
                }
            }
            if (to.InvoiceNumber != null)
            {
                if (!exist2)
                {
                    range7 = doc.InsertText(right[0, 0].Range.Start, "Bankszámlaszám: " + to.InvoiceNumber);
                    exist2 = true;
                }
                else
                {
                    doc.InsertText(right[0, 0].Range.Start, "Bankszámlaszám: " + to.InvoiceNumber + "\n");
                }
            }
            if (from.RegistrationNumber != null)
            {
                if (!exist1)
                {
                    range6 = doc.InsertText(left[0, 0].Range.Start, "Cégjegyzékszám: " + from.RegistrationNumber);
                    exist1 = true;
                }
                else
                {
                    doc.InsertText(left[0, 0].Range.Start, "Cégjegyzékszám: " + from.RegistrationNumber + "\n");
                }
            }
            if (to.RegistrationNumber != null)
            {
                if (!exist2)
                {
                    range7 = doc.InsertText(right[0, 0].Range.Start, "Cégjegyzékszám: " + to.RegistrationNumber);
                    exist2 = true;
                }
                else
                {
                    doc.InsertText(right[0, 0].Range.Start, "Cégjegyzékszám: " + to.RegistrationNumber + "\n");
                }
            }
            if (!exist1)
            {
                range6 = doc.InsertText(left[0, 0].Range.Start, "Adószám: " + from.TaxNumber);
                exist1 = true;
            }
            else
            {
                doc.InsertText(left[0, 0].Range.Start, "Adószám: " + from.TaxNumber + "\n");
            }
            if (to.TaxNumber != null)
            {
                if (!exist2)
                {
                    range7 = doc.InsertText(right[0, 0].Range.Start, "Adószám: " + to.TaxNumber);
                    exist2 = true;
                }
                else
                {
                    doc.InsertText(right[0, 0].Range.Start, "Adószám: " + to.TaxNumber + "\n");
                }
            }


            doc.InsertText(left[0, 0].Range.Start, from.Address + "\n");
            if (!exist2)
            {
                range7 = doc.InsertText(right[0, 0].Range.Start, to.Address);
                exist2 = true;
            }
            else
            {
                doc.InsertText(right[0, 0].Range.Start, to.Address + "\n");
            }
            doc.InsertText(left[0, 0].Range.Start, from.ZipCode + " " + from.Settlement + "\n");
            doc.InsertText(right[0, 0].Range.Start, to.ZipCode + " " + to.Settlement + "\n");

            DocumentRange       range4 = doc.InsertText(left[0, 0].Range.Start, from.Name + "\n");
            ParagraphProperties props2 = reds.Document.BeginUpdateParagraphs(range4);

            props2.SpacingBefore = 5;
            props2.SpacingAfter  = 3;
            CharacterProperties cp4 = reds.Document.BeginUpdateCharacters(range4);

            cp4.Bold     = true;
            cp4.FontSize = 14;

            DocumentRange       range5 = doc.InsertText(right[0, 0].Range.Start, to.Name + "\n");
            ParagraphProperties props3 = reds.Document.BeginUpdateParagraphs(range5);

            props3.SpacingBefore = 5;
            props3.SpacingAfter  = 3;
            CharacterProperties cp5 = reds.Document.BeginUpdateCharacters(range5);

            cp5.Bold     = true;
            cp5.FontSize = 14;

            ParagraphProperties props4 = reds.Document.BeginUpdateParagraphs(range6);
            ParagraphProperties props5 = reds.Document.BeginUpdateParagraphs(range7);

            props4.SpacingAfter = 5;
            props5.SpacingAfter = 5;

            doc.AppendText("\n\n");

            Table table1 = doc.Tables.Create(doc.Range.End, 1, 7);

            table1.TableLayout        = TableLayoutType.Fixed;
            table1.PreferredWidth     = 5000;
            table1.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table1.Borders.Left.LineStyle   = TableBorderLineStyle.None;
            table1.Borders.Right.LineStyle  = TableBorderLineStyle.None;
            table1.Borders.Top.LineStyle    = TableBorderLineStyle.None;
            table1.Borders.Bottom.LineStyle = TableBorderLineStyle.None;

            table1[0, 0].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1[0, 0].PreferredWidth     = 1250;
            table1[0, 0].VerticalAlignment  = TableCellVerticalAlignment.Center;
            table1[0, 1].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1[0, 1].PreferredWidth     = 500;
            table1[0, 1].VerticalAlignment  = TableCellVerticalAlignment.Center;
            table1[0, 2].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1[0, 2].PreferredWidth     = 688;
            table1[0, 2].VerticalAlignment  = TableCellVerticalAlignment.Center;
            table1[0, 3].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1[0, 3].PreferredWidth     = 688;
            table1[0, 3].VerticalAlignment  = TableCellVerticalAlignment.Center;
            table1[0, 4].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1[0, 4].PreferredWidth     = 500;
            table1[0, 4].VerticalAlignment  = TableCellVerticalAlignment.Center;
            table1[0, 5].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1[0, 5].PreferredWidth     = 688;
            table1[0, 5].VerticalAlignment  = TableCellVerticalAlignment.Center;
            table1[0, 6].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table1[0, 6].PreferredWidth     = 688;
            table1[0, 6].VerticalAlignment  = TableCellVerticalAlignment.Center;

            DocumentRange       r0 = doc.InsertText(table1[0, 0].Range.Start, "Megnevezés");
            CharacterProperties c0 = reds.Document.BeginUpdateCharacters(r0);

            c0.Bold     = true;
            c0.FontSize = 10;
            DocumentRange       r1 = doc.InsertText(table1[0, 1].Range.Start, "Menny.");
            CharacterProperties c1 = reds.Document.BeginUpdateCharacters(r1);

            c1.Bold     = true;
            c1.FontSize = 10;
            ParagraphProperties p1 = doc.BeginUpdateParagraphs(r1);

            p1.Alignment = ParagraphAlignment.Right;
            DocumentRange       r2 = doc.InsertText(table1[0, 2].Range.Start, "Egységár");
            CharacterProperties c2 = reds.Document.BeginUpdateCharacters(r2);

            c2.Bold     = true;
            c2.FontSize = 10;
            ParagraphProperties p2 = doc.BeginUpdateParagraphs(r2);

            p2.Alignment = ParagraphAlignment.Right;
            DocumentRange       r3 = doc.InsertText(table1[0, 3].Range.Start, "Nettó ár");
            CharacterProperties c3 = reds.Document.BeginUpdateCharacters(r3);

            c3.Bold     = true;
            c3.FontSize = 10;
            ParagraphProperties p3 = doc.BeginUpdateParagraphs(r3);

            p3.Alignment = ParagraphAlignment.Right;
            DocumentRange       r4 = doc.InsertText(table1[0, 4].Range.Start, "ÁFA");
            CharacterProperties c4 = reds.Document.BeginUpdateCharacters(r4);

            c4.Bold     = true;
            c4.FontSize = 10;
            ParagraphProperties p4 = doc.BeginUpdateParagraphs(r4);

            p4.Alignment = ParagraphAlignment.Right;
            DocumentRange       r5 = doc.InsertText(table1[0, 5].Range.Start, "Áfa érték");
            CharacterProperties c5 = reds.Document.BeginUpdateCharacters(r5);

            c5.Bold     = true;
            c5.FontSize = 10;
            ParagraphProperties p5 = doc.BeginUpdateParagraphs(r5);

            p5.Alignment = ParagraphAlignment.Right;
            DocumentRange       r6 = doc.InsertText(table1[0, 6].Range.Start, "Bruttó ár");
            CharacterProperties c6 = reds.Document.BeginUpdateCharacters(r6);

            c6.Bold     = true;
            c6.FontSize = 10;
            ParagraphProperties p6 = doc.BeginUpdateParagraphs(r6);

            p6.Alignment = ParagraphAlignment.Right;

            Table table3 = doc.Tables.Create(doc.Range.End, PrintList.Count, 7);

            table3.TableLayout        = TableLayoutType.Fixed;
            table3.PreferredWidth     = 5000;
            table3.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3.Borders.InsideVerticalBorder.LineStyle   = TableBorderLineStyle.None;
            table3.Borders.InsideHorizontalBorder.LineStyle = TableBorderLineStyle.None;
            table3.Borders.Left.LineStyle  = TableBorderLineStyle.None;
            table3.Borders.Right.LineStyle = TableBorderLineStyle.None;

            table3[0, 0].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3[0, 0].PreferredWidth     = 1250;
            table3[0, 1].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3[0, 1].PreferredWidth     = 500;
            table3[0, 2].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3[0, 2].PreferredWidth     = 688;
            table3[0, 3].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3[0, 3].PreferredWidth     = 688;
            table3[0, 4].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3[0, 4].PreferredWidth     = 500;
            table3[0, 5].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3[0, 5].PreferredWidth     = 688;
            table3[0, 6].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table3[0, 6].PreferredWidth     = 688;

            List <DocumentRange>       dr  = new List <DocumentRange>();
            List <ParagraphProperties> ppr = new List <ParagraphProperties>();
            List <CharacterProperties> cpr = new List <CharacterProperties>();

            for (int i = 0; i < PrintList.Count; i++)
            {
                if (i % 2 == 0)
                {
                    for (int column = 0; column < 7; column++)
                    {
                        table3[i, column].BackgroundColor = ColorTranslator.FromHtml("#E6E6E6");
                    }
                }
                dr.Add(doc.InsertText(table3[i, 0].Range.Start, PrintList[i].Name));
                ppr.Add(doc.BeginUpdateParagraphs(dr[dr.Count - 1]));
                cpr.Add(doc.BeginUpdateCharacters(dr[dr.Count - 1]));
                cpr[cpr.Count - 1].FontSize    = 10;
                table3[i, 0].VerticalAlignment = TableCellVerticalAlignment.Center;

                dr.Add(doc.InsertText(table3[i, 1].Range.Start, PrintList[i].Quantity.ToString()));
                ppr.Add(doc.BeginUpdateParagraphs(dr[dr.Count - 1]));
                ppr[ppr.Count - 1].Alignment = ParagraphAlignment.Right;
                cpr.Add(doc.BeginUpdateCharacters(dr[dr.Count - 1]));
                cpr[cpr.Count - 1].FontSize    = 10;
                table3[i, 1].VerticalAlignment = TableCellVerticalAlignment.Center;

                dr.Add(doc.InsertText(table3[i, 2].Range.Start, Grouping(PrintList[i].QuantityPrice)));
                ppr.Add(doc.BeginUpdateParagraphs(dr[dr.Count - 1]));
                ppr[ppr.Count - 1].Alignment = ParagraphAlignment.Right;
                cpr.Add(doc.BeginUpdateCharacters(dr[dr.Count - 1]));
                cpr[cpr.Count - 1].FontSize    = 10;
                table3[i, 2].VerticalAlignment = TableCellVerticalAlignment.Center;

                dr.Add(doc.InsertText(table3[i, 3].Range.Start, Grouping(PrintList[i].PriceWithoutVat)));
                ppr.Add(doc.BeginUpdateParagraphs(dr[dr.Count - 1]));
                ppr[ppr.Count - 1].Alignment = ParagraphAlignment.Right;
                cpr.Add(doc.BeginUpdateCharacters(dr[dr.Count - 1]));
                cpr[cpr.Count - 1].FontSize    = 10;
                table3[i, 3].VerticalAlignment = TableCellVerticalAlignment.Center;

                dr.Add(doc.InsertText(table3[i, 4].Range.Start, PrintList[i].Vat.ToString() + " %"));
                ppr.Add(doc.BeginUpdateParagraphs(dr[dr.Count - 1]));
                ppr[ppr.Count - 1].Alignment = ParagraphAlignment.Right;
                cpr.Add(doc.BeginUpdateCharacters(dr[dr.Count - 1]));
                cpr[cpr.Count - 1].FontSize    = 10;
                table3[i, 4].VerticalAlignment = TableCellVerticalAlignment.Center;

                dr.Add(doc.InsertText(table3[i, 5].Range.Start, Grouping(PrintList[i].VatPrice)));
                ppr.Add(doc.BeginUpdateParagraphs(dr[dr.Count - 1]));
                ppr[ppr.Count - 1].Alignment = ParagraphAlignment.Right;
                cpr.Add(doc.BeginUpdateCharacters(dr[dr.Count - 1]));
                cpr[cpr.Count - 1].FontSize    = 10;
                table3[i, 5].VerticalAlignment = TableCellVerticalAlignment.Center;

                dr.Add(doc.InsertText(table3[i, 6].Range.Start, Grouping(PrintList[i].PriceWithVat)));
                ppr.Add(doc.BeginUpdateParagraphs(dr[dr.Count - 1]));
                ppr[ppr.Count - 1].Alignment = ParagraphAlignment.Right;
                cpr.Add(doc.BeginUpdateCharacters(dr[dr.Count - 1]));
                cpr[cpr.Count - 1].FontSize    = 10;
                table3[i, 6].VerticalAlignment = TableCellVerticalAlignment.Center;

                dr.Clear();
                ppr.Clear();
                cpr.Clear();
            }

            Table table4 = doc.Tables.Create(doc.Range.End, 1, 7);

            table4.TableLayout        = TableLayoutType.Fixed;
            table4.PreferredWidth     = 5000;
            table4.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table4.Borders.Left.LineStyle   = TableBorderLineStyle.None;
            table4.Borders.Right.LineStyle  = TableBorderLineStyle.None;
            table4.Borders.Bottom.LineStyle = TableBorderLineStyle.None;
            table4.Borders.Top.LineStyle    = TableBorderLineStyle.None;

            table4[0, 0].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4[0, 0].PreferredWidth     = 1250;
            table4[0, 0].VerticalAlignment  = TableCellVerticalAlignment.Bottom;
            table4[0, 1].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4[0, 1].PreferredWidth     = 500;
            table4[0, 1].VerticalAlignment  = TableCellVerticalAlignment.Bottom;
            table4[0, 2].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4[0, 2].PreferredWidth     = 688;
            table4[0, 2].VerticalAlignment  = TableCellVerticalAlignment.Bottom;
            table4[0, 3].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4[0, 3].PreferredWidth     = 688;
            table4[0, 3].VerticalAlignment  = TableCellVerticalAlignment.Bottom;
            table4[0, 4].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4[0, 4].PreferredWidth     = 500;
            table4[0, 4].VerticalAlignment  = TableCellVerticalAlignment.Bottom;
            table4[0, 5].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4[0, 5].PreferredWidth     = 688;
            table4[0, 5].VerticalAlignment  = TableCellVerticalAlignment.Bottom;
            table4[0, 6].PreferredWidthType = WidthType.FiftiethsOfPercent;
            table4[0, 6].PreferredWidth     = 688;
            table4[0, 6].VerticalAlignment  = TableCellVerticalAlignment.Bottom;

            DocumentRange       rq0 = doc.InsertText(table4[0, 0].Range.Start, "Összesen:");
            CharacterProperties cq0 = reds.Document.BeginUpdateCharacters(rq0);

            cq0.Bold     = true;
            cq0.FontSize = 10;
            DocumentRange       rq3 = doc.InsertText(table4[0, 3].Range.Start, Grouping(PriceWithoutVat));
            CharacterProperties cq3 = reds.Document.BeginUpdateCharacters(rq3);

            cq3.Bold     = true;
            cq3.FontSize = 10;
            ParagraphProperties pq3 = doc.BeginUpdateParagraphs(rq3);

            pq3.Alignment     = ParagraphAlignment.Right;
            pq3.SpacingBefore = 4;
            DocumentRange       rq5 = doc.InsertText(table4[0, 5].Range.Start, Grouping(Vat));
            CharacterProperties cq5 = reds.Document.BeginUpdateCharacters(rq5);

            cq5.Bold     = true;
            cq5.FontSize = 10;
            ParagraphProperties pq5 = doc.BeginUpdateParagraphs(rq5);

            pq5.Alignment = ParagraphAlignment.Right;
            DocumentRange       rq6 = doc.InsertText(table4[0, 6].Range.Start, Grouping(PriceWithVat));
            CharacterProperties cq6 = reds.Document.BeginUpdateCharacters(rq6);

            cq6.Bold     = true;
            cq6.FontSize = 10;
            ParagraphProperties pq6 = doc.BeginUpdateParagraphs(rq6);

            pq6.Alignment = ParagraphAlignment.Right;

            doc.AppendText("\n\n");

            DocumentRange       last   = doc.AppendText("Fizetendő: " + Grouping(PriceWithVat) + " Ft");
            CharacterProperties lastcp = doc.BeginUpdateCharacters(last);

            lastcp.Bold     = true;
            lastcp.FontSize = 16;
            ParagraphProperties lastpp = doc.BeginUpdateParagraphs(last);

            lastpp.Alignment = ParagraphAlignment.Right;

            using (MemoryStream ms = new MemoryStream())
            {
                reds.ExportToPdf(ms);
                return(ms);
            }
        }
        protected internal MemoryStream Template(bool Type,
                                                 string companyName,
                                                 string companyZip,
                                                 string companySettlement,
                                                 string companyAddress,
                                                 string doctorName,
                                                 int doctorSealNumber,
                                                 string patientName,
                                                 string motherName,
                                                 DateTime birthDate,
                                                 string TAJ,
                                                 string patientZip,
                                                 string patientSettlement,
                                                 string patientAddress,
                                                 string examination,
                                                 string examinationCode)
        {
            Document doc = reds.Document;

            doc.Sections[0].Page.PaperKind          = System.Drawing.Printing.PaperKind.A4;
            doc.DefaultCharacterProperties.FontSize = 12;
            doc.Unit = DevExpress.Office.DocumentUnit.Centimeter;
            doc.Sections[0].Margins.Bottom       = 2;
            doc.Sections[0].Margins.Top          = 2;
            doc.Sections[0].Margins.Left         = 2;
            doc.Sections[0].Margins.Right        = 2;
            doc.Sections[0].Margins.FooterOffset = 0.8F;

            doc.Unit = DevExpress.Office.DocumentUnit.Point;

            SubDocument   subdoc = doc.Sections[0].BeginUpdateHeader(HeaderFooterType.Primary);
            DocumentRange textRange;

            if (Type)
            {
                textRange = subdoc.AppendText("Vizsgálati Lap");
            }
            else
            {
                textRange = subdoc.AppendText("Státusz");
            }
            CharacterProperties cp1 = subdoc.BeginUpdateCharacters(textRange);

            cp1.Bold     = true;
            cp1.Italic   = true;
            cp1.FontSize = 18;
            subdoc.EndUpdateCharacters(cp1);
            subdoc.Paragraphs[0].Alignment       = ParagraphAlignment.Center;
            subdoc.Paragraphs[0].LineSpacingType = ParagraphLineSpacing.Sesquialteral;
            doc.Sections[0].EndUpdateHeader(subdoc);

            SubDocument subdoc2 = doc.Sections[0].BeginUpdateFooter(HeaderFooterType.Primary);
            Table       table2  = subdoc2.Tables.Create(subdoc2.Range.Start, 1, 2);

            table2.TableLayout        = TableLayoutType.Fixed;
            table2.PreferredWidth     = 5000;
            table2.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table2.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table2.Borders.Left.LineStyle   = TableBorderLineStyle.None;
            table2.Borders.Right.LineStyle  = TableBorderLineStyle.None;
            table2.Borders.Bottom.LineStyle = TableBorderLineStyle.None;

            subdoc2.InsertText(table2[0, 0].Range.Start, DateTime.Now.ToString("yyyy. MMMM d.", new CultureInfo("hu-HU")));
            DocumentRange       range = subdoc2.InsertText(table2[0, 0].Range.Start, "Dátum: ");
            CharacterProperties cp    = subdoc2.BeginUpdateCharacters(range);

            cp.Bold = true;
            subdoc2.Paragraphs[0].SpacingBefore = 3;

            subdoc2.InsertText(table2[0, 1].Range.Start, examinationCode);
            DocumentRange       r = subdoc2.InsertText(table2[0, 1].Range.Start, "Azonosító: ");
            CharacterProperties c = subdoc2.BeginUpdateCharacters(r);

            c.Bold = true;
            subdoc2.Paragraphs[1].Alignment     = ParagraphAlignment.Right;
            subdoc2.Paragraphs[1].SpacingBefore = 3;
            doc.Sections[0].EndUpdateFooter(subdoc2);

            Table table = doc.Tables.Create(doc.CaretPosition, 2, 2);

            table.TableLayout        = TableLayoutType.Fixed;
            table.PreferredWidth     = 5000;
            table.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table.Borders.Left.LineStyle  = TableBorderLineStyle.None;
            table.Borders.Right.LineStyle = TableBorderLineStyle.None;

            doc.InsertText(table[0, 0].Range.Start, "\t" + companyAddress);
            doc.InsertText(table[0, 0].Range.Start, "  Címe: " + companyZip + " " + companySettlement + "\n");
            doc.InsertText(table[0, 0].Range.Start, "  Neve: " + companyName + "\n");
            DocumentRange       range1 = doc.InsertText(table[0, 0].Range.Start, "Intézmény\n");
            CharacterProperties cp2    = doc.BeginUpdateCharacters(range1);

            cp2.Bold     = true;
            cp2.FontSize = 16;
            doc.EndUpdateCharacters(cp2);
            doc.Paragraphs[0].SpacingBefore   = 6;
            doc.Paragraphs[3].LineSpacingType = ParagraphLineSpacing.Sesquialteral;

            doc.InsertText(table[0, 1].Range.Start, "  Pecsétszáma: " + doctorSealNumber);
            doc.InsertText(table[0, 1].Range.Start, "  Neve: " + doctorName + "\n");
            DocumentRange       range2 = doc.InsertText(table[0, 1].Range.Start, "Orvos\n");
            CharacterProperties cp3    = doc.BeginUpdateCharacters(range2);

            cp3.Bold     = true;
            cp3.FontSize = 16;
            doc.EndUpdateCharacters(cp3);
            doc.Paragraphs[4].SpacingBefore = 6;

            doc.InsertText(table[1, 0].Range.Start, "  Születési ideje: " + birthDate.ToString("yyyy. MMMM d.", new CultureInfo("hu-HU")));
            doc.InsertText(table[1, 0].Range.Start, "  Anyja neve: " + motherName + "\n");
            doc.InsertText(table[1, 0].Range.Start, "  Neve: " + patientName + "\n");
            DocumentRange       range3 = doc.InsertText(table[1, 0].Range.Start, "Páciens\n");
            CharacterProperties cp4    = doc.BeginUpdateCharacters(range3);

            cp4.Bold     = true;
            cp4.FontSize = 16;
            doc.EndUpdateCharacters(cp4);
            doc.Paragraphs[7].SpacingBefore    = 6;
            doc.Paragraphs[10].LineSpacingType = ParagraphLineSpacing.Sesquialteral;

            doc.InsertText(table[1, 1].Range.Start, "\t" + patientAddress);
            doc.InsertText(table[1, 1].Range.Start, "  Lakcíme: " + patientZip + " " + patientSettlement + "\n");
            doc.InsertText(table[1, 1].Range.Start, "  TAJ száma: " + TAJ + "\n");
            DocumentRange       range4 = doc.InsertText(table[1, 1].Range.Start, "\n");
            CharacterProperties cp5    = doc.BeginUpdateCharacters(range4);

            cp5.Bold     = true;
            cp5.FontSize = 16;
            doc.EndUpdateCharacters(cp5);
            doc.Paragraphs[11].SpacingBefore = 6;

            if (Type)
            {
                DocumentRange       range5 = doc.AppendText("  Vizsgálat: ");
                CharacterProperties cp6    = doc.BeginUpdateCharacters(range5);
                cp6.Bold     = true;
                cp6.FontSize = 16;
                doc.Paragraphs[15].SpacingBefore   = 6;
                doc.Paragraphs[15].LineSpacingType = ParagraphLineSpacing.Sesquialteral;

                DocumentRange       range6 = doc.AppendText(examination);
                CharacterProperties cp7    = doc.BeginUpdateCharacters(range6);
                cp7.Bold     = false;
                cp7.FontSize = 12;
            }
            doc.Paragraphs.Append();
            doc.Paragraphs[Type ? 16 : 15].SpacingBefore   = 0;
            doc.Paragraphs[Type ? 16 : 15].LineSpacingType = ParagraphLineSpacing.Single;
            doc.AppendText("          ");

            RangePermissionCollection rpc             = doc.BeginUpdateRangePermissions();
            RangePermission           rangePermission = new RangePermission(doc.Paragraphs[16].Range);

            rangePermission.UserName = "******";
            rpc.Add(rangePermission);

            doc.EndUpdateRangePermissions(rpc);

            doc.Protect("admin");

            using (MemoryStream ms = new MemoryStream())
            {
                reds.SaveDocument(ms, DocumentFormat.OpenXml);
                return(ms);
            }
        }
        public void SendEmail()
        {
            DataTable zamok = Zamowienia_DoWyslaniaOK().Result;

            foreach (DataRow r in zamok.Rows)
            {
                #region Pobieranie danych i tworzenie ciała maila.
                rec1.CreateNewDocument();
                rec1.LoadDocument("Zamowienie_OK.docx");
                string Status_Zam = "";
                string Producent;
                string PH_Producent;
                string Numer_Zam;
                string FileDate;
                string ZamDate;
                string Uwagi;
                string Rodzaj_zam;
                string XL_Akronim;
                string Prod_Akronim;
                string Prod_Adres;
                if (bool.TryParse(r["Zpn_Alert"].ToString(), out bool al))
                {
                    if (al)
                    {
                        Status_Zam = "Błędy mapowania towarów. Obsługa CallCenter";
                    }
                    else
                    {
                        Status_Zam = "OK. Wysłane do Mobiusa.";
                    }
                }
                else
                {
                    Status_Zam = "OK. Wysłane do Mobiusa.";
                }
                if (r["Zpn_Producent"].ToString().Length > 1)
                {
                    Producent = r["Zpn_Producent"].ToString();
                }
                else
                {
                    Producent = "BŁĄD";
                }
                if (r["Zpn_NAZWISKO"].ToString().Length > 1)
                {
                    PH_Producent = r["Zpn_NAZWISKO"].ToString() + " " + r["Zpn_IMIE"].ToString();
                }
                else
                {
                    PH_Producent = "BŁĄD";
                }
                if (r["Zpn_NR_ZAM"].ToString().Length > 1)
                {
                    Numer_Zam = r["Zpn_NR_ZAM"].ToString();
                }
                else
                {
                    Numer_Zam = "BŁĄD";
                }
                if (DateTime.TryParse(r["Zpn_DataPliku"].ToString(), out DateTime Data_Otrz))
                {
                    FileDate = Data_Otrz.ToShortDateString() + " " + Data_Otrz.ToShortTimeString();
                }
                else
                {
                    FileDate = "BŁĄD";
                }
                if (DateTime.TryParse(r["Zpn_DATA_ZAM"].ToString(), out DateTime Data_Zam))
                {
                    ZamDate = Data_Zam.ToShortDateString() + " " + Data_Zam.ToShortTimeString();
                }
                else
                {
                    ZamDate = "BŁĄD";
                }
                if (r["Zpn_UWAGI"].ToString().Length > 1)
                {
                    Uwagi = r["Zpn_UWAGI"].ToString();
                }
                else
                {
                    Uwagi = "BŁĄD";
                }
                if (r["Zpn_TYP_ZAM"].ToString().Length > 1)
                {
                    if (r["Zpn_TYP_ZAM"].ToString() == "ZG")
                    {
                        Rodzaj_zam = "Gratisowe";
                    }
                    else
                    {
                        Rodzaj_zam = "Standard";
                    }
                }
                else
                {
                    Rodzaj_zam = "BŁĄD";
                }
                if (r["Knt_Akronim"].ToString().Length > 1)
                {
                    XL_Akronim = r["Knt_Akronim"].ToString();
                }
                else
                {
                    XL_Akronim = "BŁĄD";
                }
                if (r["Zpn_NAZWA"].ToString().Length > 1)
                {
                    Prod_Akronim = r["Zpn_NAZWA"].ToString();
                }
                else
                {
                    Prod_Akronim = "BŁĄD";
                }
                if ((r["Zpn_MIASTO"].ToString() + r["Zpn_ULICA"].ToString()).Length > 1)
                {
                    Prod_Adres = r["Zpn_MIASTO"].ToString() + ", " + r["Zpn_ULICA"].ToString();
                }
                else
                {
                    Prod_Adres = "BŁĄD";
                }
                if (Int32.TryParse(r["Zpn_Id"].ToString(), out int Zpn_id))
                {
                }
                else
                {
                    Zpn_id = 0;
                }

                rec1.Document.ReplaceAll("<@Status_Zam>", Status_Zam, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Producent>", Producent, SearchOptions.None);
                rec1.Document.ReplaceAll("<@PH_Producent>", PH_Producent, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Numer_Zam>", Numer_Zam, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Data_Otrz>", FileDate, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Data_Zam>", ZamDate, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Uwagi>", Uwagi, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Rodzaj_Zam>", Rodzaj_zam, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Knt_XLAkr>", XL_Akronim, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Knt_ZamProd>", Prod_Akronim, SearchOptions.None);
                rec1.Document.ReplaceAll("<@Knt_Adres>", Prod_Adres, SearchOptions.None);

                DocumentRange[] wyniki = rec1.Document.FindAll("<@TABELA>", SearchOptions.None);
                if (wyniki.Length > 0)
                {
                    // Paragraph par = rec1.Document.Paragraphs.Get(wyniki[0].Start);
                    DocumentPosition pos = wyniki[0].Start;
                    SubDocument      doc = pos.BeginUpdateDocument();


                    // Add the table
                    rec1.Document.Tables.Create(pos, 1, 9, AutoFitBehaviorType.AutoFitToContents);
                    // Format the table
                    Table tbl = rec1.Document.Tables[0];

                    pos.EndUpdateDocument(doc);
                    try
                    {
                        tbl.BeginUpdate();

                        CharacterProperties cp_Tbl = doc.BeginUpdateCharacters(tbl.Range);
                        cp_Tbl.FontSize = 10;
                        cp_Tbl.FontName = "Calibri";
                        doc.EndUpdateCharacters(cp_Tbl);
                        //tbl.BeginUpdate();

                        // Insert header caption and format the columns
                        tbl.Rows[0].HeightType = HeightType.Exact;
                        tbl.Rows[0].Height     = 80f;
                        doc.InsertSingleLineText(tbl[0, 0].Range.Start, "Lp.");
                        doc.InsertSingleLineText(tbl[0, 1].Range.Start, "Alert");
                        doc.InsertSingleLineText(tbl[0, 2].Range.Start, "Kod");
                        doc.InsertSingleLineText(tbl[0, 3].Range.Start, "Towar");
                        doc.InsertSingleLineText(tbl[0, 4].Range.Start, "il. szt.");
                        doc.InsertSingleLineText(tbl[0, 5].Range.Start, "Ilość");
                        doc.InsertSingleLineText(tbl[0, 6].Range.Start, "JM");
                        doc.InsertSingleLineText(tbl[0, 7].Range.Start, "Cena");
                        doc.InsertSingleLineText(tbl[0, 8].Range.Start, "Gratis");
                        tbl[0, 0].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 0].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.2f);
                        tbl[0, 0].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 1].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 1].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.4f);
                        tbl[0, 1].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 2].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 2].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.8f);
                        tbl[0, 2].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 3].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 3].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(2.6f);
                        tbl[0, 3].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 4].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 4].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.5f);
                        tbl[0, 4].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 5].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 5].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.6f);
                        tbl[0, 5].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 6].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 6].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.3f);
                        tbl[0, 6].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 7].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 7].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.6f);
                        tbl[0, 7].VerticalAlignment  = TableCellVerticalAlignment.Center;
                        tbl[0, 8].PreferredWidthType = WidthType.Fixed;
                        tbl[0, 8].PreferredWidth     = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.4f);
                        tbl[0, 8].VerticalAlignment  = TableCellVerticalAlignment.Center;

                        /*
                         * //Apply formatting to the "Active Customers" cell
                         * CharacterProperties properties = rec1.Document.BeginUpdateCharacters(tbl[0, 1].ContentRange);
                         * properties.FontName = "Segoe UI";
                         * properties.FontSize = 16;
                         * document.EndUpdateCharacters(properties);
                         * ParagraphProperties alignment = document.BeginUpdateParagraphs(table[0, 1].ContentRange);
                         * alignment.Alignment = ParagraphAlignment.Center;
                         * document.EndUpdateParagraphs(alignment);
                         * table[0, 1].VerticalAlignment = TableCellVerticalAlignment.Center;
                         */

                        int       wiersz = 0;
                        DataTable dt_poz = ZamowieniaPozycje_DoWyslaniaOK(Zpn_id).Result;
                        foreach (DataRow r_poz in dt_poz.Rows)
                        {
                            wiersz++;
                            tbl.Rows.InsertAfter(wiersz - 1);
                            tbl.Rows[wiersz].HeightType = HeightType.Auto;
                            if (bool.TryParse(r_poz["Alert"].ToString(), out bool ale))
                            {
                                if (ale)
                                {
                                    doc.Images.Insert(tbl[wiersz, 1].Range.Start, DocumentImageSource.FromFile("alert.png"));
                                }
                            }
                            else
                            {
                                ale = false;
                            }
                            doc.InsertSingleLineText(tbl[wiersz, 0].Range.Start, r_poz["Poz"].ToString());
                            doc.InsertSingleLineText(tbl[wiersz, 2].Range.Start, r_poz["Kod"].ToString());
                            doc.InsertSingleLineText(tbl[wiersz, 3].Range.Start, r_poz["Towar_MAG"].ToString());
                            doc.InsertSingleLineText(tbl[wiersz, 4].Range.Start, r_poz["Ilosc_szt"].ToString());
                            doc.InsertSingleLineText(tbl[wiersz, 5].Range.Start, r_poz["Ilosc_JM"].ToString());
                            doc.InsertSingleLineText(tbl[wiersz, 6].Range.Start, r_poz["JM"].ToString().ToUpper());
                            doc.InsertSingleLineText(tbl[wiersz, 7].Range.Start, r_poz["Cena_Netto"].ToString());
                            if (bool.TryParse(r_poz["Gratis"].ToString(), out bool gratt))
                            {
                            }
                            else
                            {
                                gratt = false;
                            }
                            if (bool.TryParse(r_poz["Promocja"].ToString(), out bool dol))
                            {
                            }
                            else
                            {
                                ale = false;
                            }

                            if (gratt || dol || r["Zpn_TYP_ZAM"].ToString() == "ZG")
                            {
                                doc.Images.Insert(tbl[wiersz, 8].Range.Start, DocumentImageSource.FromFile("gift.png"));
                            }
                        }
                        //Apply formatting to the header cells
                        CharacterProperties headerRowProperties = rec1.Document.BeginUpdateCharacters(tbl.Rows[0].Range);
                        headerRowProperties.FontName = "Calibri";
                        headerRowProperties.FontSize = 10;
                        headerRowProperties.Bold     = true;
                        //headerRowProperties.ForeColor = Color.FromArgb(212, 236, 183);
                        rec1.Document.EndUpdateCharacters(headerRowProperties);

                        ParagraphProperties headerRowParagraphProperties = rec1.Document.BeginUpdateParagraphs(tbl.Rows[0].Range);
                        headerRowParagraphProperties.Alignment = ParagraphAlignment.Center;
                        float f = 0.4f;
                        headerRowParagraphProperties.LeftIndent    = f;
                        headerRowParagraphProperties.SpacingBefore = 2;
                        headerRowParagraphProperties.SpacingAfter  = 2;
                        rec1.Document.EndUpdateParagraphs(headerRowParagraphProperties);
                        //Apply formatting to Row cells
                        if (tbl.Rows.Count > 1)
                        {
                            DocumentRange       targetRange            = rec1.Document.CreateRange(tbl[1, 0].Range.Start, tbl[tbl.Rows.Count - 1, 8].Range.End.ToInt());
                            ParagraphProperties RowParagraphProperties = rec1.Document.BeginUpdateParagraphs(targetRange);

                            RowParagraphProperties.LeftIndent    = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.1f);;
                            RowParagraphProperties.SpacingBefore = 8;
                            RowParagraphProperties.SpacingAfter  = 8;
                            rec1.Document.EndUpdateParagraphs(RowParagraphProperties);
                            CharacterProperties infoProperties = rec1.Document.BeginUpdateCharacters(targetRange);
                            infoProperties.FontSize = 10;
                            infoProperties.FontName = "Calibri";

                            rec1.Document.EndUpdateCharacters(infoProperties);
                        }
                        //Apply formatting to Number cells
                        for (int i = 1; i < tbl.Rows.Count; i++)
                        {
                            ParagraphProperties RrParagraphProperties = rec1.Document.BeginUpdateParagraphs(tbl[i, 4].Range);
                            RrParagraphProperties.Alignment = ParagraphAlignment.Right;
                            rec1.Document.EndUpdateParagraphs(RrParagraphProperties);
                            RrParagraphProperties           = rec1.Document.BeginUpdateParagraphs(tbl[i, 5].Range);
                            RrParagraphProperties.Alignment = ParagraphAlignment.Right;
                            rec1.Document.EndUpdateParagraphs(RrParagraphProperties);
                            RrParagraphProperties           = rec1.Document.BeginUpdateParagraphs(tbl[i, 7].Range);
                            RrParagraphProperties.Alignment = ParagraphAlignment.Right;
                            rec1.Document.EndUpdateParagraphs(RrParagraphProperties);
                            RrParagraphProperties           = rec1.Document.BeginUpdateParagraphs(tbl[i, 0].Range);
                            RrParagraphProperties.Alignment = ParagraphAlignment.Right;
                            rec1.Document.EndUpdateParagraphs(RrParagraphProperties);
                        }
                    }
                    finally
                    {
                        tbl.EndUpdate();
                        doc.BeginUpdate();
                        TableStyle tStyleMain = rec1.Document.TableStyles.CreateNew();

                        //Specify style options
                        tStyleMain.TableBorders.InsideHorizontalBorder.LineStyle = TableBorderLineStyle.Single;
                        tStyleMain.TableBorders.InsideHorizontalBorder.LineColor = Color.White;

                        tStyleMain.TableBorders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.Single;
                        tStyleMain.TableBorders.InsideVerticalBorder.LineColor = Color.White;
                        tStyleMain.CellBackgroundColor = Color.FromArgb(227, 238, 220);
                        tStyleMain.Name = "MyTableStyle";

                        //Add the style to the document collection
                        rec1.Document.TableStyles.Add(tStyleMain);

                        //Create conditional styles (styles for specific table elements)
                        TableConditionalStyle myNewStyleForOddRows = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddRowBanding);
                        myNewStyleForOddRows.CellBackgroundColor = Color.FromArgb(196, 220, 182);

                        TableConditionalStyle myNewStyleForBottomRightCell = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.BottomRightCell);
                        myNewStyleForBottomRightCell.CellBackgroundColor = Color.FromArgb(188, 214, 201);
                        doc.EndUpdate();

                        doc.BeginUpdate();

                        // Apply a previously defined style to the table
                        tbl.Style = tStyleMain;
                        doc.EndUpdate();
                        rec1.Document.ReplaceAll("<@TABELA>", "", SearchOptions.None);
                    }
                }
                #endregion
                #region Wysyłanie Maila i update statusów
                if (r["prc_email"].ToString().Length > 0)
                {
                    string Temat = "Nowe zamówienie producenckie.";
                    try
                    {
                        MailMessage mailMessage = new MailMessage("*****@*****.**", r["prc_email"].ToString());
                        mailMessage.Subject = Temat;

                        RichEditMailMessageExporter exporter = new RichEditMailMessageExporter(rec1, mailMessage);
                        exporter.Export();

                        SmtpClient mailSender = new SmtpClient();
                        mailSender.Port                  = 587;
                        mailSender.Host                  = "mag-ol.home.pl";
                        mailSender.Timeout               = 10000;
                        mailSender.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        mailSender.UseDefaultCredentials = false;
                        mailSender.Credentials           = new NetworkCredential("*****@*****.**", "!Raporty123");
                        mailSender.EnableSsl             = true;
                        mailMessage.From                 = new MailAddress("*****@*****.**");
                        //specify your login/password to log on to the SMTP server, if required
                        //mailSender.Credentials = new NetworkCredential("login", "password");
                        mailSender.Send(mailMessage);
                        int.TryParse(r["Zpn_ID"].ToString(), out int id);
                        if (id > 0)
                        {
                            SQL.UpdateDocumentMailStatus(id);
                        }
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                }
                #endregion
            }
        }
        protected virtual void SetHeaderFooterOptions(Document book, HeaderFooterKind headerFooterKind, string text, HeaderFooterOptions options)
        {
            options ??= new HeaderFooterOptions();

            Section section;
            int     sectionNum = options.SectionNum ?? -1;

            if (sectionNum > 0 && sectionNum <= book.Sections.Count)
            {
                section = book.Sections[sectionNum - 1];
            }
            else if (sectionNum < 0 && -sectionNum <= book.Sections.Count)
            {
                section = book.Sections[book.Sections.Count - (-sectionNum)];
            }
            else
            {
                throw new Exception("Invalid SectionNum.");
            }

            SubDocument   document = null;
            DocumentRange range;

            var type = options.Type;

            try
            {
                switch (headerFooterKind)
                {
                case HeaderFooterKind.Header:
                    if (options.LinkToNext)
                    {
                        section.LinkHeaderToNext((DevExpress.XtraRichEdit.API.Native.HeaderFooterType)type);
                    }
                    if (options.LinkToPrevious)
                    {
                        section.LinkHeaderToPrevious((DevExpress.XtraRichEdit.API.Native.HeaderFooterType)type);
                    }

                    document = section.BeginUpdateHeader((DevExpress.XtraRichEdit.API.Native.HeaderFooterType)type);
                    break;

                case HeaderFooterKind.Footer:
                    if (options.LinkToNext)
                    {
                        section.LinkFooterToNext((DevExpress.XtraRichEdit.API.Native.HeaderFooterType)type);
                    }
                    if (options.LinkToPrevious)
                    {
                        section.LinkFooterToPrevious((DevExpress.XtraRichEdit.API.Native.HeaderFooterType)type);
                    }

                    document = section.BeginUpdateFooter((DevExpress.XtraRichEdit.API.Native.HeaderFooterType)type);
                    break;

                default:
                    throw new Exception("Invalid DocumentType.");
                }

                document.Delete(document.Range);
                if (options.Html)
                {
                    //var insertOptions = string.IsNullOrWhiteSpace(ParagraphStyle) ? InsertOptions.KeepSourceFormatting : InsertOptions.UseDestinationStyles;
                    var insertOptions = InsertOptions.KeepSourceFormatting;
                    if (options.UseDestinationStyles)
                    {
                        insertOptions = InsertOptions.UseDestinationStyles;
                    }
                    if (options.KeepSourceFormatting)
                    {
                        insertOptions = InsertOptions.KeepSourceFormatting;
                    }
                    range = document.AppendHtmlText(text, insertOptions);
                }
                else
                {
                    range = document.AppendText(text);
                }

                if (!string.IsNullOrWhiteSpace(options.CharacterStyle))
                {
                    var style = book.CharacterStyles[options.CharacterStyle] ?? throw new Exception($"Character style '{options.CharacterStyle}' does not exist.");

                    var cp = document.BeginUpdateCharacters(range);
                    try
                    {
                        cp.Style = style;
                    }
                    finally
                    {
                        document.EndUpdateCharacters(cp);
                    }
                }

                if (!string.IsNullOrWhiteSpace(options.ParagraphStyle))
                {
                    var style = book.ParagraphStyles[options.ParagraphStyle] ?? throw new Exception($"Paragraph style '{options.ParagraphStyle}' does not exist.");

                    var pp = document.BeginUpdateParagraphs(range);
                    try
                    {
                        pp.Style = style;
                    }
                    finally
                    {
                        document.EndUpdateParagraphs(pp);
                    }
                }

                if (options.ExpandFields)
                {
                    ExpandFieldsInBookRange(range, Host?.Spreadsheet?.Workbook);
                }
            }
            finally
            {
                if (document != null)
                {
                    switch (headerFooterKind)
                    {
                    case HeaderFooterKind.Header:
                        section.EndUpdateHeader(document);
                        break;

                    case HeaderFooterKind.Footer:
                        section.EndUpdateFooter(document);
                        break;
                    }
                }
            }
        }
示例#16
0
        protected virtual void SetupHeaderFooter(Document book)
        {
            Section section;
            int     sectionNum = SectionNum ?? -1;

            if (sectionNum > 0 && sectionNum <= book.Sections.Count)
            {
                section = book.Sections[sectionNum - 1];
            }
            else if (sectionNum < 0 && -sectionNum <= book.Sections.Count)
            {
                section = book.Sections[book.Sections.Count - (-sectionNum)];
            }
            else
            {
                throw new Exception("Invalid SectionNum.");
            }

            SubDocument   document = null;
            DocumentRange range;

            var type = Type;

            try
            {
                switch (HeaderFooter)
                {
                case DocumentType.Header:
                    if (LinkToNext)
                    {
                        section.LinkHeaderToNext(type);
                    }
                    if (LinkToPrevious)
                    {
                        section.LinkHeaderToPrevious(type);
                    }

                    document = section.BeginUpdateHeader(type);
                    break;

                case DocumentType.Footer:
                    if (LinkToNext)
                    {
                        section.LinkFooterToNext(type);
                    }
                    if (LinkToPrevious)
                    {
                        section.LinkFooterToPrevious(type);
                    }

                    document = section.BeginUpdateFooter(type);
                    break;

                default:
                    throw new Exception("Invalid DocumentType.");
                }

                document.Delete(document.Range);
                if (Html)
                {
                    //var insertOptions = string.IsNullOrWhiteSpace(ParagraphStyle) ? InsertOptions.KeepSourceFormatting : InsertOptions.UseDestinationStyles;
                    var insertOptions = InsertOptions.KeepSourceFormatting;
                    if (UseDestinationStyles)
                    {
                        insertOptions = InsertOptions.UseDestinationStyles;
                    }
                    if (KeepSourceFormatting)
                    {
                        insertOptions = InsertOptions.KeepSourceFormatting;
                    }
                    range = document.AppendHtmlText(Text, insertOptions);
                }
                else
                {
                    range = document.AppendText(Text);
                }

                if (!string.IsNullOrWhiteSpace(CharacterStyle))
                {
                    var style = book.CharacterStyles[CharacterStyle] ?? throw new Exception($"Character style '{CharacterStyle}' does not exist.");

                    var cp = document.BeginUpdateCharacters(range);
                    try
                    {
                        cp.Style = style;
                    }
                    finally
                    {
                        document.EndUpdateCharacters(cp);
                    }
                }

                if (!string.IsNullOrWhiteSpace(ParagraphStyle))
                {
                    var style = book.ParagraphStyles[ParagraphStyle] ?? throw new Exception($"Paragraph style '{ParagraphStyle}' does not exist.");

                    var pp = document.BeginUpdateParagraphs(range);
                    try
                    {
                        pp.Style = style;
                    }
                    finally
                    {
                        document.EndUpdateParagraphs(pp);
                    }
                }

                if (ExpandFields)
                {
                    ExpandFieldsInBookRange(range, HostSpreadsheet);
                }
            }
            finally
            {
                if (document != null)
                {
                    switch (HeaderFooter)
                    {
                    case DocumentType.Header:
                        section.EndUpdateHeader(document);
                        break;

                    case DocumentType.Footer:
                        section.EndUpdateFooter(document);
                        break;
                    }
                }
            }
        }