Exemplo n.º 1
0
 static void ImageFromFile(Document document)
 {
     #region #ImageFromFile
     DocumentPosition pos = document.Range.Start;
     document.Images.Insert(pos, DocumentImageSource.FromFile("beverages.png"));
     #endregion #ImageFromFile
 }
Exemplo n.º 2
0
    public void AppendChart(Document doc, string path, string filename)
    {
        float scaleX = 1.0f;
        float scaleY = 1.0f;

        string chartfile = String.Format("{0}{1}", path, filename);

        try
        {
            DocumentPosition pos = doc.Range.End;

            DocumentImageSource.FromFile(chartfile);


            doc.Images.Insert(pos, DocumentImageSource.FromFile(chartfile));

            var size = doc.Images[doc.Images.Count - 1].Size;


            if (size.Width > 7.5)
            {
                scaleX = 7.5f / size.Width;
                scaleY = scaleX;
            }


            doc.Images[doc.Images.Count - 1].ScaleX = scaleX;
            doc.Images[doc.Images.Count - 1].ScaleY = scaleY;
        }
        catch (Exception ex)
        {
        }
    }
Exemplo n.º 3
0
        private void FillData(Document document)
        {
            #region #DataInserting
            Table table = document.Tables[0];

            //Insert the header data
            document.InsertSingleLineText(table.Rows[0].Cells[1].Range.Start, "Active Customers");
            document.InsertSingleLineText(table[2, 0].Range.Start, "Photo");
            document.InsertSingleLineText(table[2, 1].Range.Start, "Customer Info");
            document.InsertSingleLineText(table[2, 2].Range.Start, "Rentals");

            //Insert the customer photo
            document.Images.Insert(table[3, 0].Range.Start, DocumentImageSource.FromFile("photo.png"));

            //Insert the customer info
            document.InsertText(table[3, 1].Range.Start, "Ryan Anita W");
            document.InsertText(table[3, 2].Range.Start, "Intermediate");
            document.InsertText(table[4, 1].Range.Start, "3/28/1984");
            document.InsertText(table[5, 1].Range.Start, "*****@*****.**");
            document.InsertText(table[5, 2].Range.Start, "(555)421-0059");
            document.InsertText(table[6, 1].Range.Start, "5119 Beryl Dr, San Antonio, TX 78212");

            document.InsertSingleLineText(table[3, 3].Range.Start, "18");

            #endregion #DataInserting
        }
 static void ImageFromFile(RichEditDocumentServer wordProcessor)
 {
     #region #ImageFromFile
     Document         document = wordProcessor.Document;
     DocumentPosition pos      = document.Range.Start;
     document.Images.Insert(pos, DocumentImageSource.FromFile("Documents\\beverages.png"));
     #endregion #ImageFromFile
 }
        static void Main()
        {
            #region #inlinepictures
            RichEditDocumentServer server = new RichEditDocumentServer();
            server.LoadDocument("Texts\\InlinePictures.rtf", DocumentFormat.Rtf);
            Document doc = server.Document;

            // Insert an image from a file.
            DocumentRange    rangeFound = doc.FindAll("Visual Studio Magazine", SearchOptions.CaseSensitive)[0];
            DocumentPosition pos        = doc.Paragraphs[doc.Paragraphs.Get(rangeFound.End).Index + 2].Range.Start;
            doc.Images.Insert(pos, DocumentImageSource.FromFile("Pictures\\ReadersChoice.png"));

            // Insert an image from a stream.
            pos = doc.Paragraphs[4].Range.Start;
            string   imageToInsert = "information.png";
            Assembly a             = Assembly.GetExecutingAssembly();
            Stream   imageStream   = a.GetManifestResourceStream("InlinePictures.Resources." + imageToInsert);
            doc.Images.Insert(pos, DocumentImageSource.FromStream(imageStream));

            // Insert an image using its URI.
            string      imageUri  = "http://i.gyazo.com/798a2ed48a3535c6c8add0ea7a4fc4e6.png";
            SubDocument docHeader = doc.Sections[0].BeginUpdateHeader();
            docHeader.Images.Append(DocumentImageSource.FromUri(imageUri, server));
            doc.Sections[0].EndUpdateHeader(docHeader);


            // Insert a barcode.
            DevExpress.BarCodes.BarCode barCode = new DevExpress.BarCodes.BarCode();
            barCode.Symbology      = DevExpress.BarCodes.Symbology.QRCode;
            barCode.CodeText       = "http://www.devexpress.com";
            barCode.CodeBinaryData = System.Text.Encoding.Default.GetBytes(barCode.CodeText);
            barCode.Module         = 0.5;
            SubDocument docFooter = doc.Sections[0].BeginUpdateFooter();
            docFooter.Images.Append(barCode.BarCodeImage);
            doc.Sections[0].EndUpdateFooter(docFooter);
            #endregion #inlinepictures

            #region #getimages
            // Scale down images in the document body.
            ReadOnlyDocumentImageCollection images = server.Document.Images.Get(doc.Range);
            for (int i = 0; i < images.Count; i++)
            {
                images[i].ScaleX /= 4;
                images[i].ScaleY /= 4;
            }
            #endregion #getimages
            // Save the resulting document.
            server.SaveDocument("InlinePictures.docx", DocumentFormat.OpenXml);
            Process.Start("InlinePictures.docx");
        }
Exemplo n.º 6
0
        private void btnFromFile_Click(object sender, EventArgs e)
        {
            #region #fromfile
            DocumentPosition pos = richEditControl1.Document.CaretPosition;

            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter           = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*";
            dialog.FilterIndex      = 1;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string imageToInsert = dialog.FileName;
                richEditControl1.Document.Images.Insert(pos,
                                                        DocumentImageSource.FromFile(imageToInsert));
            }
            #endregion #fromfile
        }
Exemplo n.º 7
0
        protected virtual void AppendImage(Document doc, ScriptOutputMessage output, string fileName)
        {
            doc.BeginUpdate();
            try
            {
                fileName = Project.Current.MapPath(fileName);
                doc.Images.Append(DocumentImageSource.FromFile(fileName));
                var paragraph = doc.Paragraphs.Append();

                doc.CaretPosition = paragraph.Range.End;
                ScrollToCaret();
            }
            catch (Exception ex)
            {
                ReportError(doc, ex);
            }
            finally
            {
                doc.EndUpdate();
            }
        }
Exemplo n.º 8
0
        protected void DoWriteImage(string fileName, ImageOptions options)
        {
            options ??= new ImageOptions();

            var book = options.Book?.Document ?? Document;

            using (new UsingProcessor(() => book.BeginUpdate(), () => book.EndUpdate()))
            {
                DocumentPosition rangeStart = null, rangeEnd = null;

                DocumentImage image;
                if (options.Image != null)
                {
                    image = book.Images.Append(options.Image);
                }
                else if (!string.IsNullOrWhiteSpace(fileName))
                {
                    fileName = Project.Current.MapPath(fileName);

                    var source = DocumentImageSource.FromFile(fileName);
                    image = book.Images.Append(source);
                }
                else
                {
                    throw new Exception("WriteImage - unknown input object.");
                }

                image.ScaleX = options.ScaleX;
                image.ScaleY = options.ScaleY;

                var imageRange = image.Range;
                if (rangeStart == null)
                {
                    rangeStart = imageRange.Start;
                }

                if (!options.NoLineBreaks)
                {
                    imageRange = book.AppendText(Environment.NewLine);
                }

                rangeEnd = imageRange.End;

                if (rangeStart != null && rangeEnd != null)
                {
                    var range = book.CreateRange(rangeStart, rangeEnd.ToInt() - rangeStart.ToInt());

                    if (!string.IsNullOrWhiteSpace(options.ParagraphStyle) || options.FirstLineIdent.HasValue || options.FirstLineIndentType.HasValue ||
                        options.LeftIndent.HasValue || options.RightIndent.HasValue)
                    {
                        var pp = book.BeginUpdateParagraphs(range);
                        try
                        {
                            if (!string.IsNullOrWhiteSpace(options.ParagraphStyle))
                            {
                                var style = book.ParagraphStyles[options.ParagraphStyle] ?? throw new Exception($"Paragraph style '{options.ParagraphStyle}' does not exist.");
                                pp.Style = style;
                            }

                            if (options.FirstLineIdent.HasValue)
                            {
                                pp.FirstLineIndent = options.FirstLineIdent;
                            }
                            if (options.FirstLineIndentType.HasValue)
                            {
                                pp.FirstLineIndentType = (DevExpress.XtraRichEdit.API.Native.ParagraphFirstLineIndent)options.FirstLineIndentType;
                            }

                            if (options.LeftIndent.HasValue)
                            {
                                pp.LeftIndent = options.LeftIndent;
                            }
                            if (options.RightIndent.HasValue)
                            {
                                pp.RightIndent = options.RightIndent;
                            }
                        }
                        finally
                        {
                            book.EndUpdateParagraphs(pp);
                        }
                    }

                    Script.Book.SCBook.AddComments(book, range, options);
                }

                if (rangeEnd != null)
                {
                    book.CaretPosition = rangeEnd;
                    ResetBookFormatting(book, rangeEnd);
                    ScrollToCaret();
                }
            }
        }
        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
            }
        }
Exemplo n.º 10
0
    private void AppendCharts(DocumentPosition pos, DxChartBatch batch, Document doc, float scaleX, float scaleY)
    {
        bool addHeaderRow = true;

        if (batch.layout == DxLayout.Upper)
        {
            int numcols = LayoutOutput.NCols(batch.charts.Count);
            int numrows = (addHeaderRow) ? numcols + 1 : numcols;

            //int numrows = (addHeaderRow) ? batch.maxRow + 1 : batch.maxRow;



            doc.BeginUpdate();
            DevExpress.XtraRichEdit.API.Native.Table t = doc.Tables.Create(doc.Range.End, numrows, numcols, AutoFitBehaviorType.AutoFitToContents);

            FormatTableBorders(t);


            if (addHeaderRow)
            {
                for (int h = 0; h < numcols; h++)
                {
                    doc.InsertText(t[0, h].Range.Start, batch.vars[h]);
                    doc.InsertText(t[h, 0].Range.Start, batch.vars[h - 1]);
                    //if (h > 0 & h < batch.vars.Count) doc.InsertText(t[0, h].Range.Start, batch.vars[h]);
                    //if (h > 0 & h < batch.vars.Count) doc.InsertText(t[h, 0].Range.Start, batch.vars[h - 1]);

                    t.Cell(h, 0).VerticalAlignment = TableCellVerticalAlignment.Center;
                }
            }

            //t.Rows.Add(CreateHeaderRow(batch.vars, ncols));
            int counter = 0;
            for (int r = 0; r < numrows; r++)
            {
                //for (int c = r; c < batch.maxCol; c++)
                for (int c = r; c < numcols; c++)
                {
                    if (c > r)
                    {
                        int bumprow = (addHeaderRow) ? 1 : 0;

                        int idx = LayoutOutput.GetDiagIndex(r, c, batch.maxRow);



                        string chartfile = String.Format(@"{0}{1}.png", _temppath, batch.charts[counter].guid);
                        counter++;

                        DevExpress.XtraRichEdit.API.Native.TableCell cell = t.Cell(r + bumprow, c);
                        doc.Images.Insert(cell.Range.Start, DocumentImageSource.FromFile(chartfile));

                        doc.Images[doc.Images.Count - 1].ScaleX = scaleX;
                        doc.Images[doc.Images.Count - 1].ScaleY = scaleY;
                    }
                }
            }



            doc.EndUpdate();
        }
        else
        {
            foreach (DxChart chart in batch.charts)
            {
                string chartfile = String.Format(@"{0}{1}.png", _temppath, chart.guid);
                log(chartfile);
                //MemoryStream s = new MemoryStream();
                //chart.chart.ExportToImage(s, System.Drawing.Imaging.ImageFormat.Png);

                doc.Images.Insert(pos, DocumentImageSource.FromFile(chartfile));

                doc.Images[doc.Images.Count - 1].ScaleX = 0.5f;
                doc.Images[doc.Images.Count - 1].ScaleY = 0.5f;
            }
        }
    }