Exemplo n.º 1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Create a new document.
                WordDocument document = new WordDocument();
                // Adding a new section to the document.
                IWSection section = document.AddSection();
                section.PageSetup.Margins.All        = 50;
                section.PageSetup.DifferentFirstPage = true;
                IWTextRange textRange;
                IWParagraph paragraph = section.AddParagraph();


                #region Table Cell Spacing.
                // --------------------------------------------
                // Table Cell Spacing.
                // --------------------------------------------
                paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14;

                section.AddParagraph();
                paragraph = section.AddParagraph();
                WTextBody textBody = section.Body;

                // Adding a new Table to the textbody.
                IWTable table = textBody.AddTable();
                table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                table.TableFormat.Paddings.All       = 5.4f;
                RowFormat format = new RowFormat();

                format.Paddings.All       = 5;
                format.CellSpacing        = 2;
                format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
                format.IsBreakAcrossPages = true;
                table.ResetCells(25, 5, format, 90);
                IWTextRange text;
                table.Rows[0].IsHeader = true;

                for (int i = 0; i < table.Rows[0].Cells.Count; i++)
                {
                    paragraph = table[0, i].AddParagraph() as WParagraph;
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    text = paragraph.AppendText(string.Format("Header {0}", i + 1));
                    text.CharacterFormat.Font        = new Font("Bitstream Vera Serif", 10);
                    text.CharacterFormat.Bold        = true;
                    text.CharacterFormat.TextColor   = Color.FromArgb(0, 21, 84);
                    table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226);
                }

                for (int i = 1; i < table.Rows.Count; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        paragraph = table[i, j].AddParagraph() as WParagraph;
                        paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                        text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                        text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50);
                        text.CharacterFormat.Bold      = true;
                        if (i % 2 != 1)
                        {
                            table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245);
                        }
                        else
                        {
                            table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255);
                        }
                    }
                }
                (table as WTable).AutoFit(AutoFitType.FitToContent);
                #endregion Table Cell Spacing.

                #region Nested Table
                // --------------------------------------------
                // Nested Table.
                // --------------------------------------------

                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.PageBreakBefore = true;
                paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14;

                section.AddParagraph();
                paragraph = section.AddParagraph();
                textBody  = section.Body;

                // Adding a new Table to the textbody.
                table = textBody.AddTable();

                format = new RowFormat();
                format.Paddings.All       = 5;
                format.CellSpacing        = 2.5f;
                format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
                table.ResetCells(5, 3, format, 100);


                for (int i = 0; i < table.Rows[0].Cells.Count; i++)
                {
                    paragraph = table[0, i].AddParagraph() as WParagraph;
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    text = paragraph.AppendText(string.Format("Header {0}", i + 1));
                    text.CharacterFormat.Font        = new Font("Bitstream Vera Serif", 10);
                    text.CharacterFormat.Bold        = true;
                    text.CharacterFormat.TextColor   = Color.FromArgb(0, 21, 84);
                    table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50);
                }
                table[0, 2].Width = 200;
                for (int i = 1; i < table.Rows.Count; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        paragraph = table[i, j].AddParagraph() as WParagraph;
                        paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                        if ((i == 2) && (j == 2))
                        {
                            text = paragraph.AppendText("Nested Table");
                        }

                        else
                        {
                            text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                        }

                        if ((j == 2))
                        {
                            table[i, j].Width = 200;
                        }

                        text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50);
                        text.CharacterFormat.Bold      = true;
                    }
                }

                // Adding a nested Table.
                IWTable nestTable = table[2, 2].AddTable();

                format = new RowFormat();

                format.Borders.BorderType  = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
                format.HorizontalAlignment = RowAlignment.Center;
                nestTable.ResetCells(3, 3, format, 45);

                for (int i = 0; i < nestTable.Rows.Count; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        paragraph = nestTable[i, j].AddParagraph() as WParagraph;
                        paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                        nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245);
                        text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                        text.CharacterFormat.TextColor = Color.Black;
                        text.CharacterFormat.Bold      = true;
                    }
                }
                (nestTable as WTable).AutoFit(AutoFitType.FitToContent);
                (table as WTable).AutoFit(AutoFitType.FitToWindow);
                #endregion Nested Table

                #region Table with Images
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\";

                //Add a new section to the document.
                section = document.AddSection();
                //Add paragraph to the section.
                paragraph = section.AddParagraph();
                //Writing text.
                textRange = paragraph.AppendText("Table with Images");
                textRange.CharacterFormat.FontSize  = 13f;
                textRange.CharacterFormat.TextColor = Color.DarkBlue;
                textRange.CharacterFormat.Bold      = true;

                //Add paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();

                text = null;

                //Adding a new Table to the paragraph.
                table = section.Body.AddTable();
                table.ResetCells(1, 3);

                //Adding rows to the table.
                WTableRow row = table.Rows[0];
                //Set heading row height
                row.Height = 25f;
                //set heading values to the Table.
                for (int i = 0; i < 3; i++)
                {
                    //Add paragraph for writing Text to the cells.
                    paragraph = (IWParagraph)row.Cells[i].AddParagraph();
                    //Set Horizontal Alignment as Center.
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    //Writing Row Heading
                    switch (i)
                    {
                    case 0:
                        text = paragraph.AppendText("SNO");
                        row.Cells[i].Width = 50f; break;

                    case 1: text = paragraph.AppendText("Drinks"); break;

                    case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break;
                    }
                    //Set row Heading formatting
                    text.CharacterFormat.Bold      = true;
                    text.CharacterFormat.FontName  = "Cambria";
                    text.CharacterFormat.FontSize  = 11f;
                    text.CharacterFormat.TextColor = Color.White;

                    //Set row cells formatting
                    row.Cells[i].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                    row.Cells[i].CellFormat.BackColor         = Color.FromArgb(157, 161, 190);

                    row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                }

                int sno = 1;
                //Writing Sno, Product name and Product Images to the Table.

                WTableRow row1 = table.AddRow(false);

                //Writing SNO to the table with formatting text.
                paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(sno.ToString());
                text.CharacterFormat.Bold     = true;
                text.CharacterFormat.FontSize = 10f;
                row1.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
                //Writing Product Name to the table with Formatting.
                paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText("Apple Juice");
                text.CharacterFormat.Bold                   = true;
                text.CharacterFormat.FontSize               = 10f;
                text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
                row1.Cells[1].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

                //Writing Product Images to the Table.
                paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
                paragraph.AppendPicture(Image.FromFile(dataPath + "Apple Juice.png"));
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                row1.Cells[2].CellFormat.VerticalAlignment    = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
                sno++;
                row1 = table.AddRow(false);

                //Writing SNO to the table with formatting text.
                paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(sno.ToString());
                text.CharacterFormat.Bold     = true;
                text.CharacterFormat.FontSize = 10f;
                row1.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
                //Writing Product Name to the table with Formatting.
                paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText("Grape Juice");
                text.CharacterFormat.Bold                   = true;
                text.CharacterFormat.FontSize               = 10f;
                text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
                row1.Cells[1].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

                //Writing Product Images to the Table.
                paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
                paragraph.AppendPicture(Image.FromFile(dataPath + "Grape Juice.png"));
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                row1.Cells[2].CellFormat.VerticalAlignment    = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
                sno++;
                row1 = table.AddRow(false);

                //Writing SNO to the table with formatting text.
                paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(sno.ToString());
                text.CharacterFormat.Bold     = true;
                text.CharacterFormat.FontSize = 10f;
                row1.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
                //Writing Product Name to the table with Formatting.
                paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText("Hot Soup");
                text.CharacterFormat.Bold                   = true;
                text.CharacterFormat.FontSize               = 10f;
                text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
                row1.Cells[1].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

                //Writing Product Images to the Table.
                paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
                paragraph.AppendPicture(Image.FromFile(dataPath + "Hot Soup.png"));
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                row1.Cells[2].CellFormat.VerticalAlignment    = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
                sno++;
                (table as WTable).AutoFit(AutoFitType.FixedColumnWidth);
                #endregion Table with Images
                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        private void btnFill_Click(object sender, EventArgs e)
        {
            try
            {
                // Create a new document.
                WordDocument       document = new WordDocument("Sample.doc");
                IWSection          sec      = document.LastSection;
                WTextFormField     textFF;
                WDropDownFormField dropFF;

                //Access the text field
                textFF = sec.Body.FormFields[0] as WTextFormField;

                //Fill value for the textfield
                textFF.TextRange.Text = "John";

                //Access the form field with feild name
                textFF = sec.Body.FormFields["BirthDayField"] as WTextFormField;
                textFF.TextRange.Text = "5.13.1980";

                textFF = sec.Body.FormFields[2] as WTextFormField;
                textFF.TextRange.Text = "221b Baker Street";

                textFF = sec.Body.FormFields[3] as WTextFormField;
                textFF.TextRange.Text = "(206)555-3412";

                textFF = sec.Body.FormFields[4] as WTextFormField;
                textFF.TextRange.Text = "*****@*****.**";

                dropFF = sec.Body.FormFields[5] as WDropDownFormField;

                //Set the value
                dropFF.DropDownSelectedIndex = 1;

                textFF = sec.Body.FormFields[6] as WTextFormField;
                textFF.TextRange.Text = "Michigan University";

                dropFF = sec.Body.FormFields[7] as WDropDownFormField;
                dropFF.DropDownSelectedIndex = 1;

                dropFF = sec.Body.FormFields[8] as WDropDownFormField;
                dropFF.DropDownSelectedIndex = 2;

                //Allow only to fill the form.
                document.ProtectionType = ProtectionType.AllowOnlyFormFields;

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Creating a new document.
                WordDocument doc = new WordDocument();

                // Add a new section to the document.
                IWSection section1 = doc.AddSection();


                #region Header Footer
                //Add different Header Footer for first and other pages
                if (checkBox1.Checked && checkBox2.Checked)
                {
                    // Set the header/footer setup.
                    section1.PageSetup.DifferentFirstPage = true;
                    // Inserting Header Footer to first page
                    InsertFirstPageHeaderFooter(doc, section1);
                    // Inserting Header Footer to all pages
                    InsertPageHeaderFooter(doc, section1);
                }
                //Add Header Footer only for first page
                if (checkBox1.Checked && !checkBox2.Checked)
                {
                    // Set the header/footer setup.
                    section1.PageSetup.DifferentFirstPage = true;
                    // Inserting Header Footer to first page
                    InsertFirstPageHeaderFooter(doc, section1);
                }
                //Add same Header Footer for all the pages
                if (checkBox2.Checked && !checkBox1.Checked)
                {
                    // Inserting Header Footer to all pages
                    InsertPageHeaderFooter(doc, section1);
                }
                #endregion

                // Add text to the document body section.
                IWParagraph par;
                par = section1.AddParagraph();
                //Insert Text into the word Document.
                StreamReader reader = new StreamReader(@"..\..\..\..\..\..\..\Common\Data\DocIO\WinFAQ.txt", System.Text.Encoding.ASCII);
                string       text   = reader.ReadToEnd();
                par.AppendText(text);

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    doc.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    doc.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(doc);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 4
0
        private void buttonReplace_Click(object sender, System.EventArgs e)
        {
            // Checking whether the find and replacement text boxes are filled.
            if (textBoxFind.Text.Trim() == "" || textBoxReplace.Text.Trim() == "")
            {
                MessageBoxAdv.Show("Please fill the find and replacement text in appropriate textboxes...", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                //Open an existing word document.
                doc = new WordDocument(docFileName);
                // Replace the text.
                doc.Replace(textBoxFind.Text, textBoxReplace.Text, matchCase, wholeWord);
                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    doc.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    doc.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(doc);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBoxAdv.Show(Ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates word document with built - in table styles
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Open the template document.
                WordDocument document = new WordDocument(fileName + "TemplateTableStyle.doc");

                // Get Data from the Database.
                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dataBase);
                conn.Open();
                DataSet          ds      = new DataSet();
                OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from Suppliers", conn);
                adapter.Fill(ds);
                ds.Tables[0].TableName = "Suppliers";
                adapter.Dispose();
                conn.Close();

                // Execute Mail Merge with groups.
                document.MailMerge.ExecuteGroup(ds.Tables[0]);

                #region Built-in table styles
                //Get table to apply style.
                WTable table = (WTable)document.LastSection.Tables[0];

                //Apply built-in table style to the table.
                table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent5);
                #endregion

                # region Save Document

                //Save as docx format
                if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
                # endregion
            }
Exemplo n.º 6
0
        private void cmdModificar_Click(object sender, EventArgs e)
        {
            DataSet   DSDevuelveID = new DataSet();
            DataTable DTDevuelveID = new DataTable();
            String    Spendiente   = "";

            if (txtRuc.Text.ToString().Replace(" ", "") == "")
            {
                MessageBoxAdv.Show("El Ruc debe de tener 11 digitos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRuc.Focus();
                return;
            }

            if (txtRuc.Text.ToString().Length != 11)
            {
                MessageBoxAdv.Show("Debe de registrar el número de Ruc de la empresa", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRuc.Focus();
                return;
            }

            if (ValidarSoloNumeros(txtRuc.Text.ToString()) == false)
            {
                MessageBoxAdv.Show("El Número de documento solo debe de contener números", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRuc.Focus();
                return;
            }


            if (txtNRP.Text.ToString().Replace(" ", "") == "")
            {
                MessageBoxAdv.Show("Debe de registrar el número de NRP", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtNRP.Focus();
                return;
            }
            if (txtRazonSocial.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar la Razón Social de la empresa", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRazonSocial.Focus();
                return;
            }

            if (MayorACero(txtCapacidad.Text.ToString()) == false)
            {
                MessageBoxAdv.Show("La capacidad debe de ser un valor númerico mayor a 0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCapacidad.Focus();
                return;
            }
            if (chkPendiente.Checked == true)
            {
                if (txtObservaciones.Text == "")
                {
                    MessageBoxAdv.Show("Debe de registrar en observaciones que es lo que tiene pendiente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtDireccion.Focus();
                    return;
                }
                Spendiente = "1";
            }
            else
            {
                Spendiente = "0";
            }

            WSLicitaciones.WSLicitaciones WSLic = new WSLicitaciones.WSLicitaciones();
            WSLic.Url    = mdlGenerales.DireccionWS + "FazServices/WSLicitaciones.asmx";
            DSDevuelveID = WSLic.ActualizaEmpresaLic(mdlGenerales.Conexion,
                                                     txtRuc.Text.ToString().Replace(" ", ""), txtNRP.Text.ToString().Replace(" ", ""),
                                                     txtRazonSocial.Text.ToString(), txtCapacidad.Text.ToString(), dptFechaCreacion.Value.ToString("yyyy/MM/dd"),
                                                     txtDireccion.Text.ToString(), txtTelefono1.Text.ToString(), txtTelefono2.Text.ToString(),
                                                     txtEmail.Text.ToString(), txtObservaciones.Text, Spendiente, txtRepresentante.Text.ToString(), mdlGenerales.STRUsuario);
            DTDevuelveID = DSDevuelveID.Tables[0];
            Limpiar();
            MessageBoxAdv.Show("Se actualizo el personal", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
            CargaGrid();
        }
Exemplo n.º 7
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Get Template document and database path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Data\DocIO\";

                //Loads the template document.
                WordDocument document = new WordDocument(Path.Combine(dataPath, @"TemplateUpdateFields.docx"));

                //Initialize DataSet object.
                DataSet ds = new DataSet();

                //Load data from the xml document.
                ds.ReadXml(Path.Combine(dataPath, @"StockDetails.xml"));

                // Execute Mail Merge with groups.
                document.MailMerge.ExecuteGroup(ds.Tables["StockDetails"]);

                //Update fields in the document.
                document.UpdateDocumentFields();

                //Unlink the fields in Word document when UnlinkFields is enable.
                if (UnlinkCheckBox.Checked)
                {
                    UnlinkFieldsInDocument(document);
                }

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Update Fields.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Update Fields.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Update Fields.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Update Fields.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Update Fields.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Update Fields.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Update Fields.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Update Fields.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Update Fields.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 8
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Load the template.
                document = new WordDocument(@"..\..\..\..\..\..\..\Common\Data\DocIO\Template.doc");

                // Get the tables from Data Set.
                GetDataTable();

                // Using Merge events to do conditional formatting during runtime.
                document.MailMerge.MergeField      += new MergeFieldEventHandler(AlternateRows_MergeField);
                document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_ProductImage);

                // Execute Mail Merge with groups.
                document.MailMerge.ExecuteGroup(ds.Tables["Products"]);
                document.MailMerge.ExecuteGroup(ds.Tables["Product_PriceList"]);

                ds = null;
                ds = new DataSet();

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }

            catch (Exception Ex)
            {
                MessageBoxAdv.Show(Ex.Message + "\n\n\n" + Ex.StackTrace);
            }
        }
Exemplo n.º 9
0
        private void txtNroDocumento_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            ArrayList InfoSunat = new ArrayList();

            lblDireccion.Text = "";
            lblEstado.Text    = "";
            if ((Convert.ToInt32(e.KeyChar) == 9) || (Convert.ToInt32(e.KeyChar) == 13))
            {
                if (txtNroDocumento.Text.ToString() == "")
                {
                    txtProveedor.Text = "";
                    txtDenominacion.Focus();
                    return;
                }
                if (txtNroDocumento.Text.ToString().Length != 11)
                {
                    MessageBoxAdv.Show("El ruc debe de tener 11 digitos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    clsConsultaSunat clsConsulta = new clsConsultaSunat();
                    InfoSunat = clsConsulta.GetDataSunat(txtNroDocumento.Text.ToString());
                    if (InfoSunat.Count > 0)
                    {
                        txtProveedor.Text = InfoSunat[1].ToString();
                        if (InfoSunat[4].ToString().Contains("BAJA"))
                        {
                            lblEstado.ForeColor = Color.Red;
                        }
                        else
                        {
                            lblEstado.ForeColor = Color.Black;
                        }
                        lblEstado.Text    = InfoSunat[4].ToString();
                        lblDireccion.Text = InfoSunat[6].ToString();
                    }
                    else
                    {
                        InfoSunat = clsConsulta.GetDataSunat(txtNroDocumento.Text.ToString());
                        if (InfoSunat.Count > 0)
                        {
                            txtProveedor.Text = InfoSunat[1].ToString();
                            if (InfoSunat[4].ToString().Contains("BAJA"))
                            {
                                lblEstado.ForeColor = Color.Red;
                            }
                            else
                            {
                                lblEstado.ForeColor = Color.Black;
                            }
                            lblEstado.Text    = InfoSunat[4].ToString();
                            lblDireccion.Text = InfoSunat[6].ToString();
                        }
                        else
                        {
                            InfoSunat = clsConsulta.GetDataSunat(txtNroDocumento.Text.ToString());
                            if (InfoSunat.Count > 0)
                            {
                                txtProveedor.Text = InfoSunat[1].ToString();
                                if (InfoSunat[4].ToString().Contains("BAJA"))
                                {
                                    lblEstado.ForeColor = Color.Red;
                                }
                                else
                                {
                                    lblEstado.ForeColor = Color.Black;
                                }
                                lblEstado.Text    = InfoSunat[4].ToString();
                                lblDireccion.Text = InfoSunat[6].ToString();
                            }
                        }
                    }
                }
                if (txtProveedor.Text == "")
                {
                    MessageBoxAdv.Show("Revise el Nª de RUC", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtNroDocumento.Focus();
                    return;
                }
                txtDenominacion.Focus();
                return;
            }
        }
Exemplo n.º 10
0
        private void PBLogo_DoubleClick(object sender, EventArgs e)
        {
            String    strResultado = "";
            Int32     intResultado = 0;
            String    LRuc         = "";
            DataSet   DSDevuelveID = new DataSet();
            DataTable DTDevuelveID = new DataTable();

            WSMantenimientos.WSMantenimientos WSMant = new WSMantenimientos.WSMantenimientos();
            WSMant.Url = mdlGenerales.DireccionWS + "FazServices/WSMantenimientos.asmx";
            Element el = GGCVista.TableControl.Table.CurrentElement;

            if (el != null)
            {
                if (el is GridRecord)
                {
                    DataRowView drv = (el as Record).GetData() as DataRowView;
                    LRuc = drv[2].ToString(); //show column 2
                }
            }

            if (LRuc == "")
            {
                MessageBoxAdv.Show("Debe de seleccionar la empresa", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string NombreArchivo = string.Concat("LOGOEMP_" + LRuc);

            NombreArchivo = NombreArchivo.Replace(" ", "");
            string extension = "";

            /*************************
            * Subiendo foto
            *************************/
            var dlg = new OpenFileDialog
            {
                Filter          = @"JPEG files (*.jpg)|*.jpg",
                CheckFileExists = true,
                Title           = @"Seleccione la foto",
                Multiselect     = false
            };

            ;
            if (dlg.ShowDialog() == DialogResult.OK) // Test result.
            {
                FileInfo fi = new FileInfo(dlg.FileName);
                if (fi.Exists)
                {
                    extension = fi.Extension.ToString();
                    fi.CopyTo(dlg.FileName.Replace(dlg.SafeFileName, "") + NombreArchivo + extension);
                }

                //aqui me quedo

                UploadFoto(dlg.FileName.Replace(dlg.SafeFileName, "") + NombreArchivo + extension, "");
                File.Delete(dlg.FileName.Replace(dlg.SafeFileName, "") + NombreArchivo + extension);
            }
            else
            {
                MessageBoxAdv.Show("Se cancelo el registro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            /************************************
            * Registrando logo en BD
            ************************************/
            DSDevuelveID = WSMant.ActualizaLogoEmpresa(mdlGenerales.Conexion,
                                                       LRuc, NombreArchivo + extension, mdlGenerales.STRUsuario);
            DTDevuelveID = DSDevuelveID.Tables[0];
            foreach (DataRow Row in DTDevuelveID.Rows)
            {
                intResultado = Convert.ToInt32(Row[0].ToString());
                strResultado = Row[1].ToString();
            }

            if (intResultado == 0)
            {
                MessageBoxAdv.Show(strResultado, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Limpiar();
                CargaGrid();
            }
            else
            {
                MessageBoxAdv.Show(strResultado, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 11
0
        private void button1_Click_1(object sender, System.EventArgs e)
        {
            // Get Template document and database path.
            string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\common\Data\";

            try
            {
                //SDF the database and get the NorthWind
                AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
                DataTable       table = new DataTable();
                SqlCeConnection conn  = new SqlCeConnection();
                if (conn.ServerVersion.StartsWith("3.5"))
                {
                    conn.ConnectionString = "Data Source = " + dataPath + "NorthwindIO_3.5.sdf";
                }
                else
                {
                    conn.ConnectionString = "Data Source = " + dataPath + "NorthwindIO.sdf";
                }
                conn.Open();
                SqlCeDataAdapter adapter = new SqlCeDataAdapter("Select CustomerID,CompanyName,ContactName,Address,Country,Phone from Customers", conn);
                adapter.Fill(table);
                adapter.Dispose();
                conn.Close();

                // Creating a new document.
                WordDocument document = new WordDocument();
                // Adding a new section to the document.
                IWSection section = document.AddSection();

                IWParagraph paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.BeforeSpacing = 20f;
                //Format the heading.
                IWTextRange text = paragraph.AppendText("Northwind Report");
                text.CharacterFormat.Bold      = true;
                text.CharacterFormat.FontName  = "Cambria";
                text.CharacterFormat.FontSize  = 14.0f;
                text.CharacterFormat.TextColor = Color.DarkBlue;
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.BeforeSpacing = 18f;

                //Create a new table
                WTextBody textBody = section.Body;
                IWTable   docTable = textBody.AddTable();

                //Set the format for rows
                RowFormat format = new RowFormat();
                format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                format.Borders.LineWidth  = 1.0F;
                format.Borders.Color      = Color.Black;

                //Initialize number of rows and cloumns.
                docTable.ResetCells(table.Rows.Count + 1, table.Columns.Count, format, 84);

                //Repeat the header.
                docTable.Rows[0].IsHeader = true;

                string colName;

                //Format the header rows
                for (int c = 0; c <= table.Columns.Count - 1; c++)
                {
                    string[] Cols = table.Columns[c].ColumnName.Split('|');
                    colName = Cols[Cols.Length - 1];
                    IWTextRange theadertext = docTable.Rows[0].Cells[c].AddParagraph().AppendText(colName);
                    theadertext.CharacterFormat.FontSize                    = 12f;
                    theadertext.CharacterFormat.Bold                        = true;
                    theadertext.CharacterFormat.TextColor                   = Color.White;
                    docTable.Rows[0].Cells[c].CellFormat.BackColor          = Color.FromArgb(33, 67, 126);
                    docTable.Rows[0].Cells[c].CellFormat.Borders.Color      = Color.Black;
                    docTable.Rows[0].Cells[c].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                    docTable.Rows[0].Cells[c].CellFormat.Borders.LineWidth  = 1.0f;

                    docTable.Rows[0].Cells[c].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                }

                //Format the table body rows
                for (int r = 0; r <= table.Rows.Count - 1; r++)
                {
                    for (int c = 0; c <= table.Columns.Count - 1; c++)
                    {
                        string      Value       = table.Rows[r][c].ToString();
                        IWTextRange theadertext = docTable.Rows[r + 1].Cells[c].AddParagraph().AppendText(Value);
                        theadertext.CharacterFormat.FontSize = 10;

                        docTable.Rows[r + 1].Cells[c].CellFormat.BackColor = ((r & 1) == 0) ? Color.FromArgb(237, 240, 246) : Color.FromArgb(192, 201, 219);

                        docTable.Rows[r + 1].Cells[c].CellFormat.Borders.Color      = Color.Black;
                        docTable.Rows[r + 1].Cells[c].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                        docTable.Rows[r + 1].Cells[c].CellFormat.Borders.LineWidth  = 0.5f;
                        docTable.Rows[r + 1].Cells[c].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                    }
                }

                // Add a footer paragraph text to the document.
                WParagraph footerPar = new WParagraph(document);
                // Add text.
                footerPar.AppendText("Copyright Syncfusion Inc. 2001 - 2017");
                // Add page and Number of pages field to the document.
                footerPar.AppendText("			Page ");
                footerPar.AppendField("Page", Syncfusion.DocIO.FieldType.FieldPage);

                section.HeadersFooters.Footer.Paragraphs.Add(footerPar);

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                // Shows the Message box with Exception message, if an exception throws.
                MessageBoxAdv.Show(Ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
            }
        }
Exemplo n.º 12
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Getting Image files Path.
                string dataPath = Application.StartupPath + @"\..\..\..\..\..\..\..\Common\Images\DocIO\";

                //Getting text files Path.
                string dataPath1 = Application.StartupPath + @"\..\..\..\..\..\..\..\Common\Data\";

                //Creating a new document
                WordDocument document = new WordDocument();
                //Adding a new section.
                IWSection   section   = document.AddSection();
                IWParagraph paragraph = section.AddParagraph();
                paragraph = section.AddParagraph();
                section.PageSetup.Margins.All = 72f;
                IWTextRange text = paragraph.AppendText("Adventure products");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group ");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                #region Line break
                paragraph.AppendBreak(BreakType.LineBreak);
                paragraph.AppendBreak(BreakType.LineBreak);
                #endregion

                section = document.AddSection();

                section.BreakCode             = SectionBreakCode.NoBreak;
                section.PageSetup.Margins.All = 72f;
                //Adding three columns to section.
                section.AddColumn(100, 15);
                section.AddColumn(100, 15);
                section.AddColumn(100, 15);
                //Set the columns to be of equal width.
                section.MakeColumnsEqual();

                //Adding a new paragraph to the section.
                paragraph = section.AddParagraph();
                //Adding text.
                text = paragraph.AppendText("Mountain-200");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;
                //Adding a new paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();
                //Inserting an Image.
                WPicture picture = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Mountain-200.jpg"))) as WPicture;
                picture.Width  = 120f;
                picture.Height = 90f;
                //Adding a new paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                //Adding text.
                paragraph.AppendText(@"Product No:BK-M68B-38" + "\n" + "Size: 38" + "\n" + "Weight: 25\n" + "Price: $2,294.99");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                // Set column break as true. It navigates the cursor position to the next Column.
                paragraph.ParagraphFormat.ColumnBreakAfter = true;

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("Mountain-300");
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;

                section.AddParagraph();
                paragraph      = section.AddParagraph();
                picture        = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Mountain-300.jpg"))) as WPicture;
                picture.Width  = 120f;
                picture.Height = 90f;
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText(@"Product No:BK-M4-38" + "\n" + "Size: 35\n" + "Weight: 22" + "\n" + " Price: $1,079.99");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                paragraph.ParagraphFormat.ColumnBreakAfter = true;

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("Road-150");
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;

                section.AddParagraph();
                paragraph      = section.AddParagraph();
                picture        = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Road-550-W.jpg"))) as WPicture;
                picture.Width  = 120f;
                picture.Height = 90f;
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText(@"Product No: BK-R93R-44" + "\n" + "Size: 44" + "\n" + "Weight: 14" + "\n" + "Price: $3,578.27");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                section                       = document.AddSection();
                section.BreakCode             = SectionBreakCode.NoBreak;
                section.PageSetup.Margins.All = 72f;

                text = section.AddParagraph().AppendText("First Look\n");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;

                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText("Adventure Works Cycles, the fictitious company, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;
                paragraph.ParagraphFormat.PageBreakAfter      = true;

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("Introduction\n");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 13
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Getting Image files path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\common\images\DocIO\";

                //Create a new document
                WordDocument document = new WordDocument();

                //Adding a new section to the document.
                IWSection section = document.AddSection();
                //Set Margin of the section
                section.PageSetup.Margins.All = 72;
                //Adding a paragraph to the section
                IWParagraph paragraph = section.AddParagraph();

                //Writing text.
                paragraph.AppendText("This sample demonstrates how to insert Vector and Scalar images inside a document.");

                //Adding a new paragraph
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                //Inserting .gif .
                WPicture mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "yahoo.gif"));
                //Adding Image caption
                mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage);
                ApplyFormattingForCaption(document.LastParagraph);
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                //Inserting .bmp
                mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "Reports.bmp"));
                //Adding Image caption
                mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage);
                ApplyFormattingForCaption(document.LastParagraph);
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                //Inserting .png
                mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "google.PNG"));
                //Adding Image caption
                mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage);
                ApplyFormattingForCaption(document.LastParagraph);
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                //Inserting .tif
                mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "Square.tif"));
                //Adding Image caption
                mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage);
                ApplyFormattingForCaption(document.LastParagraph);
                //Adding a new paragraph.
                paragraph = section.AddParagraph();
                //Setting Alignment for the image.
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                //Inserting .emf Image to the document.
                mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "Ess chart.emf"));
                //Scaling Image
                mImage.HeightScale = 50f;
                mImage.WidthScale  = 50f;

                //Adding Image caption
                mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage);
                ApplyFormattingForCaption(document.LastParagraph);
                //Updates the fields in Word document
                document.UpdateDocumentFields();

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Image Insertion.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Image Insertion.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start(@"Image Insertion.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Image Insertion.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Image Insertion.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start(@"Image Insertion.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Image Insertion.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Image Insertion.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start(@"Image Insertion.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 14
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Getting Data files path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\common\Data\DocIO\";

                //A new document is created.
                WordDocument document = new WordDocument(dataPath + "PieChart.docx");
                //Get chart data from xml file
                DataSet ds = new DataSet();
                ds.ReadXml(dataPath + "Products.xml");
                //Merge the product table in the Word document
                document.MailMerge.ExecuteGroup(ds.Tables["Product"]);
                //Find the Placeholder of Pie chart to insert
                TextSelection selection = document.Find("<Pie Chart>", false, false);
                WParagraph    paragraph = selection.GetAsOneRange().OwnerParagraph;
                paragraph.ChildEntities.Clear();
                //Create and Append chart to the paragraph
                WChart pieChart = paragraph.AppendChart(446, 270);
                //Set chart data
                pieChart.ChartType  = OfficeChartType.Pie;
                pieChart.ChartTitle = "Best Selling Products";
                pieChart.ChartTitleArea.FontName = "Calibri (Body)";
                pieChart.ChartTitleArea.Size     = 14;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    pieChart.ChartData.SetValue(i + 2, 1, ds.Tables[0].Rows[i].ItemArray[1]);
                    pieChart.ChartData.SetValue(i + 2, 2, ds.Tables[0].Rows[i].ItemArray[2]);
                }
                //Create a new chart series with the name “Sales”
                IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales");
                pieSeries.Values = pieChart.ChartData[2, 2, 11, 2];
                //Setting data label
                pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true;
                pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position     = OfficeDataLabelPosition.Outside;
                //Setting background color
                pieChart.ChartArea.Fill.ForeColor           = Color.FromArgb(242, 242, 242);
                pieChart.PlotArea.Fill.ForeColor            = Color.FromArgb(242, 242, 242);
                pieChart.ChartArea.Border.LinePattern       = OfficeChartLinePattern.None;
                pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1];
                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Docx);
                //Message box confirmation to view the created document.
                if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.docx");
#endif
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 15
0
        private void txtRuc_KeyPress(object sender, KeyPressEventArgs e)
        {
            lblEstado.Text = "";
            ArrayList InfoSunat = new ArrayList();

            if ((Convert.ToInt32(e.KeyChar) == 9) || (Convert.ToInt32(e.KeyChar) == 13))
            {
                if (txtRuc.Text.ToString().Length != 11)
                {
                    MessageBoxAdv.Show("El ruc debe de tener 11 digitos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    clsConsultaSunat clsConsulta = new clsConsultaSunat();
                    InfoSunat = clsConsulta.GetDataSunat(txtRuc.Text.ToString());
                    if (InfoSunat.Count > 0)
                    {
                        txtRazonSocial.Text = InfoSunat[1].ToString();
                        if (InfoSunat[3].ToString() != "")
                        {
                            dptFechaCreacion.Value = Convert.ToDateTime(InfoSunat[3].ToString());
                        }
                        txtDireccion.Text = InfoSunat[6].ToString();
                        if (InfoSunat[4].ToString().Contains("BAJA"))
                        {
                            lblEstado.ForeColor = Color.Red;
                        }
                        else
                        {
                            lblEstado.ForeColor = Color.Black;
                        }
                        lblEstado.Text = InfoSunat[4].ToString();
                    }
                    else
                    {
                        InfoSunat = clsConsulta.GetDataSunat(txtRuc.Text.ToString());
                        dptFechaCreacion.Value = Convert.ToDateTime(InfoSunat[3].ToString());
                        txtDireccion.Text      = InfoSunat[6].ToString();
                        if (InfoSunat.Count > 0)
                        {
                            txtRazonSocial.Text = InfoSunat[1].ToString();
                            if (InfoSunat[4].ToString().Contains("BAJA"))
                            {
                                lblEstado.ForeColor = Color.Red;
                            }
                            else
                            {
                                lblEstado.ForeColor = Color.Black;
                            }
                            lblEstado.Text = InfoSunat[4].ToString();
                        }
                        else
                        {
                            InfoSunat = clsConsulta.GetDataSunat(txtRuc.Text.ToString());
                            dptFechaCreacion.Value = Convert.ToDateTime(InfoSunat[3].ToString());
                            txtDireccion.Text      = InfoSunat[6].ToString();
                            if (InfoSunat.Count > 0)
                            {
                                txtRazonSocial.Text = InfoSunat[1].ToString();
                                if (InfoSunat[4].ToString().Contains("BAJA"))
                                {
                                    lblEstado.ForeColor = Color.Red;
                                }
                                else
                                {
                                    lblEstado.ForeColor = Color.Black;
                                }
                                lblEstado.Text = InfoSunat[4].ToString();
                            }
                        }
                    }
                }
                if (txtRazonSocial.Text == "")
                {
                    MessageBoxAdv.Show("Revise el Nª de RUC", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtRuc.Focus();
                    return;
                }
                txtNRP.Focus();
                return;
            }
        }
Exemplo n.º 16
0
        private async void startInsertionBtn_Click(object sender, EventArgs e)
        {
            switch (databaseToInject)
            {
            case DatabaseToInject.SQL:
                if (sqlConnection == null || sqlConnection.State != System.Data.ConnectionState.Open)
                {
                    Messages.ShowError("Database connection must first be established", icon: MessageBoxIcon.Warning);
                    return;
                }
                break;

            case DatabaseToInject.ORACLE:
                break;
            }

            injectionProgressBar.Value = 0;
            injectionProgressBar.BringToFront();

            string tableName    = databaseTableCB.SelectedItem as string;
            string dbColumnTSQL = "";
            var    keysList     = dataToInject.Keys.ToList();

            for (int i = 0; i < keysList.Count; i++)
            {
                dbColumnTSQL += '[' + keysList[i].Key + ']' + ((i == keysList.Count - 1) ? "" : ", ");
            }

            bool isSuccessful = true;

            int skippedCount = 0;
            await Task.Run(() =>
            {
                SqlCommand cmnd          = new SqlCommand();
                cmnd.Connection          = sqlConnection;
                cmnd.StatementCompleted += (object s, StatementCompletedEventArgs _e) =>
                {
                    synchronizationContext.Send(new SendOrPostCallback(
                                                    delegate(object state)
                    {
                        int value = (int)(((float)currentRow / DataToInject.Count) * 100);
                        injectionProgressBar.Value = value;
                    }), null);
                };

                for (int i = 0; i < DataToInject.Count; i++)
                {
                    currentRow = i + 1;

                    List <DTIKey> keyDatae = new List <DTIKey>();
                    string dbValuesTSQL    = "";
                    for (int j = 0; j < keysList.Count; j++)
                    {
                        DTIKey curDTIKey     = keysList[j];
                        DTIValue curDTIValue = dataToInject[curDTIKey];
                        dbValuesTSQL        += "'" + curDTIValue.Values[i] + ((j == keysList.Count - 1) ? "'" : "', ");

                        if (curDTIValue.IsKey)
                        {
                            keyDatae.Add(curDTIKey);
                        }
                    }

                    bool skipInjection = false;

                    if (keyDatae.Count > 0)
                    {
                        string sqlSearchCommand = $"SELECT TOP 1 [{keyDatae[0].Key}] FROM {tableName} WHERE";
                        for (int k = 0; k < keyDatae.Count; k++)
                        {
                            DTIKey dTIKey     = keyDatae[k];
                            DTIValue dTIValue = dataToInject[dTIKey];

                            sqlSearchCommand += $"{(sqlSearchCommand[sqlSearchCommand.Length - 1] == '\'' ? " AND " : " ")}[{dTIKey.Key}] LIKE \'{dTIValue.Values[i]}\'";
                            cmnd.CommandText  = sqlSearchCommand;
                        }

                        try
                        {
                            using (var reader = cmnd.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    skipInjection = true;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (MessageBoxAdv.Show($" Data Row Index: {i + 1} \n \n Error: {ex.Message} \n \n Would you like to terminate the process?", "Hold On", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                            {
                                isSuccessful = false;

                                break;
                            }
                        }
                    }

                    if (skipInjection)
                    {
                        skippedCount++;
                        continue;
                    }

                    string sqlCommand = $"INSERT INTO {tableName} ({dbColumnTSQL}) VALUES ({dbValuesTSQL})";
                    cmnd.CommandText  = sqlCommand;
                    try
                    {
                        cmnd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        if (MessageBoxAdv.Show($" Data Row Index: {i + 1} \n \n Error: {ex.Message} \n \n Would you like to terminate the process?", "Hold On", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                        {
                            isSuccessful = false;

                            break;
                        }
                    }

                    //if (TheGrader.notifyMe)
                    //{
                    //    if (gradedDatae[0].subGradedDatas.Exists(x => x.title == "Roll No" || x.title == "Roll Number" || x.title == "Roll #"))
                    //    {
                    //        Task.Run(() =>
                    //        {
                    //            List<GradedData> toNotifyDatae = gradedDatae.ToList().FindAll(x => x.subGradedDatas.Find(x1 => x1.title == "Roll No" || x1.title == "Roll Number" || x1.title == "Roll #").value == "512429" || x.subGradedDatas.Find(x1 => x1.title == "Roll No" || x1.title == "Roll Number" || x1.title == "Roll #").value == "560359");
                    //            if (toNotifyDatae.Count > 0)
                    //                Program.NotifyDataViaEmail(toNotifyDatae);
                    //        });
                    //    }
                    //}
                }
            });

            if (isSuccessful)
            {
                if (skippedCount > 0)
                {
                    MessageBoxAdv.Show($"Insertion Complete. \n \n Skipped {skippedCount} rows out of {DataToInject.Count} due to duplication.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBoxAdv.Show("All data has been successfuly inserted", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            if (sqlConnection.State != ConnectionState.Open)
            {
                connectionStatusPanel.BackColor = DisconnectedStatusColor;

                sqlConnectionStringField.Enabled = true;
                openDBConnectionBtn.Text         = "Open  Connection";
                openDBConnectionBtn.MetroColor   = Color.DodgerBlue;
            }

            injectionProgressBar.SendToBack();
            Enabled = true;
        }
Exemplo n.º 17
0
        private void cmdSubirCurriculum_Click(object sender, EventArgs e)
        {
            DataSet   DSDevuelveID = new DataSet();
            DataTable DTDevuelveID = new DataTable();
            String    Spendiente   = "";

            if (ValidarSoloNumeros(txtRuc.Text.ToString()) == false)
            {
                MessageBoxAdv.Show("El Número de documento solo debe de contener números", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRuc.Focus();
                return;
            }

            if (txtRuc.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar el número de Ruc de la empresa", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRuc.Focus();
                return;
            }
            if (txtNRP.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar el número de NRP", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtNRP.Focus();
                return;
            }
            if (txtRazonSocial.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar la Razón Social de la empresa", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRazonSocial.Focus();
                return;
            }
            if (MayorACero(txtCapacidad.Text.ToString()) == false)
            {
                MessageBoxAdv.Show("La capacidad debe de ser un valor númerico mayor a 0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCapacidad.Focus();
                return;
            }
            if (chkPendiente.Checked == true)
            {
                if (txtObservaciones.Text == "")
                {
                    MessageBoxAdv.Show("Debe de registrar en observaciones que es lo que tiene pendiente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtDireccion.Focus();
                    return;
                }
                Spendiente = "1";
            }
            else
            {
                Spendiente = "0";
            }

            WSLicitaciones.WSLicitaciones WSLic = new WSLicitaciones.WSLicitaciones();
            WSLic.Url    = mdlGenerales.DireccionWS + "FazServices/WSLicitaciones.asmx";
            DSDevuelveID = WSLic.ActualizaEmpresaLic(mdlGenerales.Conexion,
                                                     txtRuc.Text.ToString().Replace(" ", ""), txtNRP.Text.ToString().Replace(" ", ""), txtRazonSocial.Text.ToString(),
                                                     txtCapacidad.Text.ToString(), dptFechaCreacion.Value.ToString("yyyy/MM/dd"),
                                                     txtDireccion.Text.ToString(), txtTelefono1.Text.ToString(), txtTelefono2.Text.ToString(),
                                                     txtEmail.Text.ToString(), txtObservaciones.Text, Spendiente, txtRepresentante.Text.ToString(), mdlGenerales.STRUsuario);
            DTDevuelveID = DSDevuelveID.Tables[0];

            DataSet   DSDevuelveValidacion = new DataSet();
            DataTable DTDevuelveValidacion = new DataTable();
            String    strResultado         = "";
            Int32     intResultado         = 0;

            /*************************
            * Validación de  datos
            *************************/
            /*try
            *  {
            *   if (txtArchivo.Text != "")
            *       DeleteFile(txtArchivo.Text);
            *  }
            *  catch
            *  { }*/
            string NombreArchivo = string.Concat("C1V3E2_" + txtRuc.Text.ToString());

            NombreArchivo = NombreArchivo.Replace(" ", "");
            string extension = "";

            /*************************
            * Subiendo Constancia
            *************************/
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                FileInfo fi = new FileInfo(openFileDialog1.FileName);
                if (fi.Exists)
                {
                    extension = fi.Extension.ToString();
                    fi.CopyTo(openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "") + NombreArchivo + extension);
                }
                Upload(openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "") + NombreArchivo + extension, "");
                File.Delete(openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "") + NombreArchivo + extension);
            }
            else
            {
                MessageBoxAdv.Show("Se cancelo el registro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            /************************************
            * Registrando experiencia en BD
            ************************************/
            DSDevuelveID = WSLic.ActualizaEmpresaLicArchivo(mdlGenerales.Conexion,
                                                            txtRuc.Text.ToString(), NombreArchivo + extension, mdlGenerales.STRUsuario);
            DTDevuelveID = DSDevuelveID.Tables[0];
            foreach (DataRow Row in DTDevuelveID.Rows)
            {
                intResultado = Convert.ToInt32(Row[0].ToString());
                strResultado = Row[1].ToString();
            }

            if (intResultado != 0)
            {
                MessageBoxAdv.Show(strResultado, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Limpiar();
                CargaGrid();
            }
            else
            {
                MessageBoxAdv.Show(strResultado, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 18
0
        void SelectData()
        {
            dataToInject = new Dictionary <DTIKey, DTIValue>();
            for (int i = 0; i < DBFieldsPanel.Controls.Count; i++)
            {
                DBFieldsPanel.Controls[i].Dispose();
            }
            DBFieldsPanel.Controls.Clear();

            for (int i = 0; i < selectedFields.Length; i++)
            {
                string fieldTitle = selectedFields[i];
                dataToInject.Add(new DTIKey(i, fieldTitle), new DTIValue());

                DatabaseField databaseField = new DatabaseField(i, fieldTitle);

                databaseField.EditField += (object sender, int Id, string Value, bool isKey) =>
                {
                    bool isValid = true;

                    try
                    {
                        if (dataToInject.Keys.Any(x => x.Key == Value && x.uID != Id))
                        {
                            MessageBoxAdv.Show("This field already exists.", "Hold On", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            isValid = false;
                        }

                        var dictionaryList = dataToInject.ToList();
                        var dictObject     = dictionaryList.Find(x => x.Key.uID == Id);
                        var dictKey        = dictObject.Key;
                        var dictValue      = dictObject.Value.Values;

                        dataToInject.Remove(dictKey);
                        dataToInject.Add(new DTIKey(Id, Value), new DTIValue(dictValue, isKey));
                    }
                    catch (Exception ex)
                    {
                        isValid = false;
                        MessageBoxAdv.Show(ex.Message, "Hold On", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    return(isValid);
                };
                databaseField.RemoveField += (object sender, int Id, string Value, bool isKey) =>
                {
                    bool isValid = true;

                    try
                    {
                        if (!dataToInject.Keys.Any(x => x.Key == Value))
                        {
                            MessageBoxAdv.Show("Invalid field.", "Hold On", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            isValid = false;
                        }

                        dataToInject.Remove(dataToInject.Keys.First(x => x.Key == Value));

                        var toRemove = (DatabaseField)sender;
                        DBFieldsPanel.Controls.Remove(toRemove);
                        toRemove.Dispose();

                        if (dataToInject.Count == 0)
                        {
                            emptyListLabel.Visible = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        isValid = false;
                        MessageBoxAdv.Show(ex.Message, "Hold On", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    return(isValid);
                };

                emptyListLabel.Visible = false;
                Controls.Add(databaseField);
                DBFieldsPanel.Controls.Add(databaseField);
                databaseField.Dock = DockStyle.Top;
                databaseField.InitializeLayout();
            }
            for (int i = 0; i < DataToInject.Count; i++)
            {
                for (int j = 0; j < selectedFields.Length; j++)
                {
                    string value = (DataToInject[i] as IDictionary <string, object>)[selectedFields[j]].ToString();
                    dataToInject.First(x => x.Key.Key == selectedFields[j]).Value.Values.Add(value);
                }
            }
        }
Exemplo n.º 19
0
        private void cmdModificar_Click(object sender, EventArgs e)
        {
            DataSet   DSDevuelveID         = new DataSet();
            DataTable DTDevuelveID         = new DataTable();
            DataSet   DSDevuelveValidacion = new DataSet();
            DataTable DTDevuelveValidacion = new DataTable();
            String    strResultado         = "";
            Int32     intResultado         = 0;

            WSLicitaciones.WSLicitaciones WSLic = new WSLicitaciones.WSLicitaciones();
            WSLic.Url = mdlGenerales.DireccionWS + "FazServices/WSLicitaciones.asmx";

            if (txtNombres.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar el nombre del contacto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtNombres.Focus();
                return;
            }

            if (txtTelefono1.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar el telefono 1", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTelefono1.Focus();
                return;
            }


            string Item = "";

            if (lblItem.Text.ToString() == ("0"))
            {
                Item = "0";
            }
            else
            {
                Item = lblItem.Text.ToString();
            }

            DSDevuelveID = WSLic.ActualizaContactosEmpresa(mdlGenerales.Conexion,
                                                           txtNumeroRuc.Text.ToString(), lblItem.Text.ToString(),
                                                           txtNombres.Text.ToString(), txtTelefono1.Text.ToString(),
                                                           txtTelefono2.Text.ToString(), txtMail.Text.ToString(),
                                                           mdlGenerales.STRUsuario);

            DTDevuelveID = DSDevuelveID.Tables[0];

            foreach (DataRow Row in DTDevuelveID.Rows)
            {
                intResultado = Convert.ToInt32(Row[0].ToString());
                strResultado = Row[1].ToString();
            }

            if (intResultado != 0)
            {
                MessageBoxAdv.Show(strResultado, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Limpiar();
                CargaGrid(txtNumeroRuc.Text.ToString(), txtRazonSocial.Text.ToString(),
                          txtNRP.Text.ToString(), txtCapacidad.Text.ToString());
            }
            else
            {
                MessageBoxAdv.Show(strResultado, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 20
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Creating a new document.
                WordDocument document = new WordDocument();

                // Adding a section to the document.
                IWSection section = document.AddSection();
                //Set Margin of the section
                section.PageSetup.Margins.All = 72;
                // Adding a new paragraph to the section.
                IWParagraph paragraph = section.AddParagraph();

                // Writing text
                paragraph.AppendText("This document demonstrates Essential DocIO's Bookmark functionality.").CharacterFormat.FontSize = 14f;

                // Adding paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.AppendText("1. Inserting Bookmark Text").CharacterFormat.FontSize = 12f;

                // Adding paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();

                // BookmarkStart.
                paragraph.AppendBookmarkStart("Bookmark");
                // Write bookmark
                paragraph.AppendText("Bookmark Text");
                paragraph.AppendComment("This is a simple bookmark");
                // BookmarkEnd.
                paragraph.AppendBookmarkEnd("Bookmark");

                // Adding paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();
                // Indicating hidden bookmark text start.
                paragraph.AppendBookmarkStart("_HiddenText");
                // Writing bookmark text
                paragraph.AppendText("2. Hidden Bookmark Text").CharacterFormat.Font = new Font("Comic Sans MS", 10);
                // Indicating hidden bookmark text end.
                paragraph.AppendBookmarkEnd("_HiddenText");
                paragraph.AppendComment("This is hidden bookmark");

                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.AppendText("3. Nested Bookmarks").CharacterFormat.FontSize = 12f;

                // Writing nested bookmarks
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.AppendBookmarkStart("Main");
                paragraph.AppendText(" Main data ");
                paragraph.AppendBookmarkStart("Nested");
                paragraph.AppendText(" Nested data ");
                paragraph.AppendComment("This is a nested bookmark");
                paragraph.AppendBookmarkStart("NestedNested");
                paragraph.AppendText(" Nested Nested ");
                paragraph.AppendBookmarkEnd("NestedNested");
                paragraph.AppendText(" data Nested ");
                paragraph.AppendBookmarkEnd("Nested");
                paragraph.AppendText(" Data Main ");
                paragraph.AppendBookmarkEnd("Main");


                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 21
0
        private void ExecuteMail_Doc(int ID)
        {
            try
            {
                // Create a new document
                doc = new WordDocument();
                // Load the template.

                doc.Open((System.IO.Path.Combine(dataPath, @"SalesInvoiceDemo.doc")), FormatType.Doc);
                // Execute Mail Merge with groups.
                doc.MailMerge.ExecuteGroup(GetTestOrder(ID));
                doc.MailMerge.ExecuteGroup(GetTestOrderTotals(ID));

                // Using Merge events to do conditional formatting during runtime.
                doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);

                DataView orderDetails = new DataView(GetTestOrderDetails(ID));
                orderDetails.Sort = "ExtendedPrice DESC";
                doc.MailMerge.ExecuteGroup(orderDetails);

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    doc.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    doc.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(doc);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBoxAdv.Show(Ex.Message);
            }
        }
Exemplo n.º 22
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Get Template document and database path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Data\DocIO\";
                //Creates an empty Word document instance.
                WordDocument document = new WordDocument();

                //Opens template document.
                document.Open(System.IO.Path.Combine(dataPath, "ContentControlTemplate.docx"));

                IWTextRange textRange;
                //Gets table from the template document.
                IWTable   table = document.LastSection.Tables[0];
                WTableRow row   = table.Rows[1];

                #region Inserting content controls

                #region Calendar content control
                IWParagraph cellPara = row.Cells[0].Paragraphs[0];
                //Accesses the date picker content control.
                IInlineContentControl inlineControl = (cellPara.ChildEntities[2] as IInlineContentControl);
                textRange = inlineControl.ParagraphItems[0] as WTextRange;
                //Sets today's date to display.
                textRange.Text = DateTime.Now.ToShortDateString();
                textRange.CharacterFormat.FontSize = 14;
                //Protects the content control.
                inlineControl.ContentControlProperties.LockContents = true;
                #endregion

                #region Plain text content controls
                table    = document.LastSection.Tables[1];
                row      = table.Rows[0];
                cellPara = row.Cells[0].LastParagraph;
                //Accesses the plain text content control.
                inlineControl = (cellPara.ChildEntities[1] as IInlineContentControl);
                //Protects the content control.
                inlineControl.ContentControlProperties.LockContents = true;
                textRange = inlineControl.ParagraphItems[0] as WTextRange;
                //Sets text in plain text content control.
                textRange.Text = "Northwind Analytics";
                textRange.CharacterFormat.FontSize = 14;

                cellPara = row.Cells[1].LastParagraph;
                //Accesses the plain text content control.
                inlineControl = (cellPara.ChildEntities[1] as IInlineContentControl);
                //Protects the content control.
                inlineControl.ContentControlProperties.LockContents = true;
                textRange = inlineControl.ParagraphItems[0] as WTextRange;
                //Sets text in plain text content control.
                textRange.Text = "Northwind";
                textRange.CharacterFormat.FontSize = 14;

                row      = table.Rows[1];
                cellPara = row.Cells[0].LastParagraph;
                //Accesses the plain text content control.
                inlineControl = (cellPara.ChildEntities[1] as IInlineContentControl);
                //Protects the content control.
                inlineControl.ContentControlProperties.LockContents = true;
                //Sets text in plain text content control.
                textRange      = inlineControl.ParagraphItems[0] as WTextRange;
                textRange.Text = "10";
                textRange.CharacterFormat.FontSize = 14;


                cellPara = row.Cells[1].LastParagraph;
                //Accesses the plain text content control.
                inlineControl = (cellPara.ChildEntities[1] as IInlineContentControl);
                //Protects the content control.
                inlineControl.ContentControlProperties.LockContents = true;
                //Sets text in plain text content control.
                textRange      = inlineControl.ParagraphItems[0] as WTextRange;
                textRange.Text = "Nancy Davolio";
                textRange.CharacterFormat.FontSize = 14;
                #endregion

                #region CheckBox Content control
                row      = table.Rows[2];
                cellPara = row.Cells[0].LastParagraph;
                //Inserts checkbox content control.
                inlineControl = cellPara.AppendInlineContentControl(ContentControlType.CheckBox);
                inlineControl.ContentControlProperties.LockContents = true;
                //Sets checkbox as checked state.
                inlineControl.ContentControlProperties.IsChecked = true;
                textRange = cellPara.AppendText("C#, ");
                textRange.CharacterFormat.FontSize = 14;

                //Inserts checkbox content control.
                inlineControl = cellPara.AppendInlineContentControl(ContentControlType.CheckBox);
                inlineControl.ContentControlProperties.LockContents = true;
                //Sets checkbox as checked state.
                inlineControl.ContentControlProperties.IsChecked = true;
                textRange = cellPara.AppendText("VB");
                textRange.CharacterFormat.FontSize = 14;
                #endregion


                #region Drop down list content control
                cellPara = row.Cells[1].LastParagraph;
                //Accesses the dropdown list content control.
                inlineControl = (cellPara.ChildEntities[1] as IInlineContentControl);
                inlineControl.ContentControlProperties.LockContents = true;
                //Sets default option to display.
                textRange      = inlineControl.ParagraphItems[0] as WTextRange;
                textRange.Text = "ASP.NET";
                textRange.CharacterFormat.FontSize = 14;
                inlineControl.ParagraphItems.Add(textRange);

                //Adds items to the dropdown list.
                ContentControlListItem item;
                item             = new ContentControlListItem();
                item.DisplayText = "ASP.NET MVC";
                item.Value       = "2";
                inlineControl.ContentControlProperties.ContentControlListItems.Add(item);

                item             = new ContentControlListItem();
                item.DisplayText = "Windows Forms";
                item.Value       = "3";
                inlineControl.ContentControlProperties.ContentControlListItems.Add(item);

                item             = new ContentControlListItem();
                item.DisplayText = "WPF";
                item.Value       = "4";
                inlineControl.ContentControlProperties.ContentControlListItems.Add(item);

                item             = new ContentControlListItem();
                item.DisplayText = "Xamarin";
                item.Value       = "5";
                inlineControl.ContentControlProperties.ContentControlListItems.Add(item);
                #endregion

                #region Calendar content control
                row      = table.Rows[3];
                cellPara = row.Cells[0].LastParagraph;
                //Accesses the date picker content control.
                inlineControl = (cellPara.ChildEntities[1] as IInlineContentControl);
                inlineControl.ContentControlProperties.LockContents = true;
                //Sets default date to display.
                textRange      = inlineControl.ParagraphItems[0] as WTextRange;
                textRange.Text = DateTime.Now.AddDays(-5).ToShortDateString();
                textRange.CharacterFormat.FontSize = 14;

                cellPara = row.Cells[1].LastParagraph;
                //Inserts date picker content control.
                inlineControl = (cellPara.ChildEntities[1] as IInlineContentControl);
                inlineControl.ContentControlProperties.LockContents = true;
                //Sets default date to display.
                textRange      = inlineControl.ParagraphItems[0] as WTextRange;
                textRange.Text = DateTime.Now.AddDays(10).ToShortDateString();
                textRange.CharacterFormat.FontSize = 14;
                #endregion

                #endregion
                #region Block content control
                //Accesses the block content control.
                BlockContentControl blockContentControl = ((document.ChildEntities[0] as WSection).Body.ChildEntities[2] as BlockContentControl);
                //Protects the block content control
                blockContentControl.ContentControlProperties.LockContents = true;
                #endregion

                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Docx);
                //Message box confirmation to view the created document.
                if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.docx");
#endif
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }

                // Exit
                this.Close();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 23
0
        private void saveOutputForm()
        {
            DialogResult result;
            String       resultText, resultMessage;

            if (workMode == WorkMode.Search || workMode == WorkMode.Template)
            {
                result = saveFileDialog.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                if (workMode == WorkMode.Search)
                {
                    string[]      strMarkers    = { "DBN:", "MFN:" };
                    StringBuilder resultRecords = new StringBuilder();
                    resultRecords.AppendLine(strMarkers[0] + find_replaceScriptEditor.curDatabase.dbName);

                    List <int> MfnList = find_replaceScriptEditor.SearchScriptResultList.Select(x => x.mfn).Distinct().ToList();

                    foreach (int mfn in MfnList)
                    {
                        resultRecords.AppendLine(strMarkers[1] + mfn);
                    }

                    resultText    = resultRecords.ToString();
                    resultMessage = String.Format("Найденные записи сохранены в файле {0}. Хотите просмотреть?", saveFileDialog.FileName);
                }
                else
                {
                    resultText    = templateStringBuilder.ToString();
                    resultMessage = String.Format("Выходной шаблон сохранён в файле {0}. Хотите просмотреть?", saveFileDialog.FileName);
                }

                File.WriteAllText(saveFileDialog.FileName, resultText, Encoding.Default);
                result = MessageBoxAdv.Show(resultMessage, "Внимание!", MessageBoxButtons.OKCancel);

                if (result == DialogResult.OK)
                {
                    string appName;
                    if (Utils.TryGetRegisteredApplication(System.IO.Path.GetExtension(saveFileDialog.FileName), out appName))
                    {
                        if (appName == Application.ExecutablePath)
                        {
                            Process.GetCurrentProcess().WaitForExit(1000);
                        }
                    }

                    Process.Start(appName, saveFileDialog.FileName);


                    /*ProcessStartInfo pi = new ProcessStartInfo(saveFileDialog.FileName);
                     * try
                     * {
                     *  Process.Start(pi);
                     * }
                     * catch
                     * {
                     *  Process.Start(Application.ExecutablePath, saveFileDialog.FileName);
                     *  Application.Exit();
                     * }
                     *
                     *
                     * //var processes = Process.GetProcesses().Where(p => p.MainModule.FileName.StartsWith(saveFileDialog.FileName, true, CultureInfo.InvariantCulture));
                     * /*foreach (Process proc in Process.GetProcesses())
                     * {
                     *  proc.Kill();
                     * }*/

                    //Process.GetCurrentProcess().Kill();

                    /*Process[] myProcess = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
                     * foreach (Process process in myProcess)
                     * {
                     *  process.CloseMainWindow();
                     *  //all the windows messages has to be processed in the msg queue
                     *  //hence call to Application DoEvents forces the MSG
                     *  Application.DoEvents();
                     * }
                     *
                     * ProcessStartInfo pi = new ProcessStartInfo(saveFileDialog.FileName);
                     * pi.UseShellExecute = true;
                     * Process.Start(pi);
                     *
                     * /*Process newProc = new Process();
                     * newProc.StartInfo.Arguments = Path.GetFileName(saveFileDialog.FileName);
                     * //p.StartInfo.UseShellExecute = true;
                     * newProc.StartInfo.WorkingDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
                     * newProc.StartInfo.FileName = saveFileDialog.FileName;
                     * newProc.StartInfo.Verb = "OPEN";
                     * newProc.Start();*/
                }
                return;
            }
        }
Exemplo n.º 24
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Creates a new word document instance
                WordDocument document = new WordDocument();
                //Adds new section to the document
                IWSection section = document.AddSection();
                //Sets page margins
                document.LastSection.PageSetup.Margins.All = 72;
                //Adds new paragraph to the section
                IWParagraph paragraph = section.AddParagraph();

                //Appends text to paragraph
                IWTextRange textRange = paragraph.AppendText("Mathematical equations");
                textRange.CharacterFormat.FontSize            = 28;
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                paragraph.ParagraphFormat.AfterSpacing        = 12;

                #region Sum to the power of n
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n.");
                //Creates an equation with sum to the power of N
                CreateSumToThePowerOfN(paragraph);
                #endregion

                #region Fourier series
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L");
                //Creates a Fourier series equation
                CreateFourierseries(paragraph);
                #endregion

                #region Triple scalar product
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of triple scalar product");
                //Creates a triple scalar product equation
                CreateTripleScalarProduct(paragraph);
                #endregion

                #region Gamma function
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of gamma function");
                //Creates a gamma function equation
                CreateGammaFunction(paragraph);
                #endregion

                #region Vector relation
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of vector relation ");
                //Creates a vector relation equation
                CreateVectorRelation(paragraph);
                #endregion

                //Save as docx format
                if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Create Equation.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Create Equation.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Create Equation.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Create Equation.pdf");
                    converter.Dispose();
                    pdfDoc.Close();
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Create Equation.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Create Equation.pdf");
#endif

                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Create a new document.
                WordDocument document = new WordDocument();

                // Adding a new section to the document.
                IWSection section = document.AddSection();

                // Adding a new paragraph to the section.
                IWParagraph paragraph = section.AddParagraph();


                #region Document formatting
                //Set background color.
                document.Background.Gradient.Color1         = Color.FromArgb(232, 232, 232);
                document.Background.Gradient.Color2         = Color.FromArgb(255, 255, 255);
                document.Background.Type                    = BackgroundType.Gradient;
                document.Background.Gradient.ShadingStyle   = GradientShadingStyle.Horizontal;
                document.Background.Gradient.ShadingVariant = GradientShadingVariant.ShadingDown;

                section.PageSetup.Margins.All = 72f;
                section.PageSetup.PageSize    = new SizeF(612, 792);

                #endregion

                #region Title Section
                IWTable table = section.Body.AddTable();
                table.ResetCells(1, 2);

                WTableRow row = table.Rows[0];
                row.Height = 25f;

                IWParagraph cellPara = row.Cells[0].AddParagraph();
                Image       img      = Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\Image.jpg");
                IWPicture   pic      = cellPara.AppendPicture(img);
                pic.Height = 80;
                pic.Width  = 180;

                cellPara = row.Cells[1].AddParagraph();
                row.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row.Cells[1].CellFormat.BackColor         = Color.FromArgb(173, 215, 255);
                IWTextRange txt = cellPara.AppendText("Job Application Form");
                cellPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 18f;

                row.Cells[0].Width = 200;
                row.Cells[1].Width = 300;
                row.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                #endregion

                section.AddParagraph();

                #region General Information
                table = section.Body.AddTable();
                table.TableFormat.Paddings.All = 5.4f;
                table.ResetCells(2, 1);
                row                = table.Rows[0];
                row.Height         = 20;
                row.Cells[0].Width = 500;
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
                row.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                txt = cellPara.AppendText(" General Information");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontSize = 11f;

                row                = table.Rows[1];
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].Width = 500;
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

                txt = cellPara.AppendText("\n Full Name:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                WTextFormField txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Birth Date:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField("BirthDayField", DateTime.Now.ToString("M/d/yyyy"));
                txtField.StringFormat = "M/d/yyyy";
                txtField.Type         = TextFormFieldType.DateText;
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;
                txtField.CharacterFormat.TextColor           = Color.MidnightBlue;
                txtField.CharacterFormat.FontName            = "Arial";
                txtField.CharacterFormat.FontSize            = 11f;

                txt = cellPara.AppendText("\n\n Address:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField      = cellPara.AppendTextFormField(null);
                txtField.Type = TextFormFieldType.RegularText;
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Phone:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Email:\t\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;
                cellPara.AppendText("\n");
                #endregion

                section.AddParagraph();

                #region Educational Qualification
                table = section.Body.AddTable();
                table.TableFormat.Paddings.All = 5.4f;
                table.ResetCells(2, 1);
                row                = table.Rows[0];
                row.Height         = 20;
                row.Cells[0].Width = 500;
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
                row.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                txt = cellPara.AppendText(" Educational Qualification");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontSize = 11f;

                row                = table.Rows[1];
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].Width = 500;
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

                txt = cellPara.AppendText("\n Type:\t\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                WDropDownFormField dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Higher");
                dropField.DropDownItems.Add("Vocational");
                dropField.DropDownItems.Add("Universal");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Institution:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.CharacterFormat.FontSize            = 11f;

                txt = cellPara.AppendText("\n\n Programming Languages:");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txt = cellPara.AppendText("\n\n\t C#:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 9f;
                dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Perfect");
                dropField.DropDownItems.Add("Good");
                dropField.DropDownItems.Add("Excellent");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n\t VB:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 9f;
                dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Perfect");
                dropField.DropDownItems.Add("Good");
                dropField.DropDownItems.Add("Excellent");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;
                #endregion

                btnFill.Enabled = true;

                //Protect document
                document.ProtectionType = ProtectionType.AllowOnlyFormFields;
                document.Save("Sample.doc", FormatType.Doc);
                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 26
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (radioButton1.Checked)
                {
                    // Get Template files path.
                    string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Data\DocIO\";

                    // Creating new documents.
                    WordDocument docSource1 = new WordDocument();
                    WordDocument docSource2 = new WordDocument();
                    WordDocument docMaster  = new WordDocument();

                    // Load Templates.
                    docSource1.Open(Path.Combine(dataPath, "TemplateSource1.doc"), FormatType.Doc);
                    docSource2.Open(Path.Combine(dataPath, "TemplateSource2.doc"), FormatType.Doc);
                    docMaster.Open(Path.Combine(dataPath, "TemplateMaster.doc"), FormatType.Doc);

                    // Search for a string and store in TextSelection
                    //The TextSelection copies a text segment with formatting.
                    TextSelection selection1 = docSource1.Find("PlaceHolder text is replaced with this formatted animated text", false, false);

                    // Search for a string and store in TextSelection
                    TextSelection selection2 = docSource2.Find(new Regex("This is the second Sentence"));

                    // Replacing the placeholder inside Master Template with matches found while
                    //search the two template documents.
                    docMaster.Replace(new Regex("PlaceHolder1"), selection1);
                    docMaster.Replace(new Regex("PlaceHolder2"), selection2);

                    //Save as doc format
                    if (wordDocRadioBtn.Checked)
                    {
                        //Saving the document to disk.
                        docMaster.Save("Sample.doc");

                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.doc");
#endif
                            //Exit
                            this.Close();
                        }
                    }
                    //Save as docx format
                    else if (wordDocxRadioBtn.Checked)
                    {
                        //Saving the document as .docx
                        docMaster.Save("Sample.docx", FormatType.Docx);
                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            try
                            {
                                //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                                System.Diagnostics.Process process = new System.Diagnostics.Process();
                                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
#else
                                System.Diagnostics.Process.Start("Sample.docx");
#endif
                                //Exit
                                this.Close();
                            }
                            catch (Win32Exception ex)
                            {
                                MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                                Console.WriteLine(ex.ToString());
                            }
                        }
                    }
                    //Save as pdf format
                    else if (pdfRadioBtn.Checked)
                    {
                        DocToPDFConverter converter = new DocToPDFConverter();
                        //Convert word document into PDF document
                        PdfDocument pdfDoc = converter.ConvertToPDF(docMaster);
                        //Save the pdf file
                        pdfDoc.Save("Sample.pdf");
                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            try
                            {
#if NETCORE
                                System.Diagnostics.Process process = new System.Diagnostics.Process();
                                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
#else
                                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                                //Exit
                                this.Close();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.ToString());
                            }
                        }
                    }
                    else
                    {
                        // Exit
                        this.Close();
                    }
                }
                else
                {
                    //Load template document
#if NETCORE
                    WordDocument doc = new WordDocument(@"..\..\..\..\..\..\..\..\Common\Data\DocIO\original.doc");
#else
                    WordDocument doc = new WordDocument(@"..\..\..\..\..\..\..\Common\Data\DocIO\original.doc");
#endif
                    //Load the document to be replaced
#if NETCORE
                    WordDocument replaceDoc = new WordDocument(@"..\..\..\..\..\..\..\..\Common\Data\DocIO\Replace.doc");
#else
                    WordDocument replaceDoc = new WordDocument(@"..\..\..\..\..\..\..\Common\Data\DocIO\Replace.doc");
#endif
                    //Set Margin of the section
                    doc.LastSection.PageSetup.Margins.All = 72;
                    //Select a table and add it to TextBodyPart
                    TextBodyPart replacePart = new TextBodyPart(replaceDoc);
                    replacePart.BodyItems.Add(replaceDoc.Sections[0].Body.Tables[0] as WTable);

                    //Replace Text with table
                    doc.Replace("INSERT TABLE", replacePart, true, true);

                    //Select text and image
                    replacePart = new TextBodyPart(replaceDoc);
                    TextBodySelection textSel = new TextBodySelection(replaceDoc.LastSection.Body, 0, replaceDoc.LastSection.Paragraphs.Count, 0, 1);
                    replacePart.Copy(textSel);

                    //Replace Text with image and text.
                    doc.Replace("INSERT PARAGRAPH ITEMS", replacePart, false, true);

                    //Save as doc format
                    if (wordDocRadioBtn.Checked)
                    {
                        //Saving the document to disk.
                        doc.Save("Sample.doc");

                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.doc");
#endif
                            //Exit
                            this.Close();
                        }
                    }
                    //Save as docx format
                    else if (wordDocxRadioBtn.Checked)
                    {
                        //Saving the document as .docx
                        doc.Save("Sample.docx", FormatType.Docx);
                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            try
                            {
                                //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                                System.Diagnostics.Process process = new System.Diagnostics.Process();
                                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
#else
                                System.Diagnostics.Process.Start("Sample.docx");
#endif
                                //Exit
                                this.Close();
                            }
                            catch (Win32Exception ex)
                            {
                                MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                                Console.WriteLine(ex.ToString());
                            }
                        }
                    }
                    //Save as pdf format
                    else if (pdfRadioBtn.Checked)
                    {
                        DocToPDFConverter converter = new DocToPDFConverter();
                        //Convert word document into PDF document
                        PdfDocument pdfDoc = converter.ConvertToPDF(doc);
                        //Save the pdf file
                        pdfDoc.Save("Sample.pdf");
                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            try
                            {
                                //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                                System.Diagnostics.Process process = new System.Diagnostics.Process();
                                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
#else
                                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                                //Exit
                                this.Close();
                            }
                            catch (Exception ex)
                            {
                                MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                                Console.WriteLine(ex.ToString());
                            }
                        }
                    }
                    else
                    {
                        // Exit
                        this.Close();
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 27
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //A new document is created.
                WordDocument document = new WordDocument();

                //Create footnotes at the bottom of the page
                CreateFootNote(document);

                //Create endnotes at the end of the section
                CreateEndNote(document);

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        private void btnconvert_Click_1(object sender, EventArgs e)
        {
            if (this.textBox1.Text != String.Empty)
            {
                WordDocument wordDoc = new WordDocument((string)textBox1.Tag, Syncfusion.DocIO.FormatType.Automatic);
#if !(SyncfusionFramework3_5 || SyncfusionFramework2_0)
                //Initialize chart to image converter for converting charts in word to pdf conversion
                wordDoc.ChartToImageConverter = new ChartToImageConverter();
                wordDoc.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Normal;
#endif
                DocToPDFConverter converter = new DocToPDFConverter();

                //Enable Direct PDF rendering mode for faster conversion.
                converter.Settings.EnableFastRendering = checkBox1.Checked;
                converter.Settings.EmbedCompleteFonts = checkBox2.Checked;
                converter.Settings.EmbedFonts = checkBox3.Checked;
                converter.Settings.AutoTag = checkBox4.Checked;
                converter.Settings.PreserveFormFields = checkBox5.Checked;
                converter.Settings.ExportBookmarks = checkBox6.Checked
                                                     ? Syncfusion.DocIO.ExportBookmarkType.Headings
                                                     : Syncfusion.DocIO.ExportBookmarkType.Bookmarks;

                if(checkBox7.Checked)
                {
                    wordDoc.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Formatting | RevisionType.Insertions;
                    // Set revision bars color as Black.
                    wordDoc.RevisionOptions.RevisionBarsColor = RevisionColor.Black;
                    // Set revised properties (Formatting) color as Blue.
                    wordDoc.RevisionOptions.RevisedPropertiesColor = RevisionColor.Blue;
                    // Set deleted text (Deletions) color as Yellow.
                    wordDoc.RevisionOptions.DeletedTextColor = RevisionColor.Yellow;
                    // Set inserted text (Insertions) color as Pink.
                    wordDoc.RevisionOptions.InsertedTextColor = RevisionColor.Pink;
                }

                if (checkBox8.Checked)
                {
                    //Sets ShowInBalloons to render a document comments in converted PDF document.
                    wordDoc.RevisionOptions.CommentDisplayMode = CommentDisplayMode.ShowInBalloons;
                    //Sets the color to be used for Comment Balloon
                    wordDoc.RevisionOptions.CommentColor = RevisionColor.Blue;
                }
                //Convert word document into PDF document
                PdfDocument pdfDoc = converter.ConvertToPDF(wordDoc);
                //Save the pdf file
                pdfDoc.Save("DoctoPDF.pdf");
                //Message box confirmation to view the created document.
                if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    try
                    {
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("DoctoPDF.pdf") { UseShellExecute = true };
                        process.Start();
#else                       
                        System.Diagnostics.Process.Start("DoctoPDF.pdf");
#endif
                        //Exit
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else
            {
                MessageBoxAdv.Show("Browse a word document and click the button to convert as a PDF.");
            }
        }
Exemplo n.º 29
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (this.textBox1.Text != String.Empty)
            {
                // Load the Document
                WordDocument wordDoc = new WordDocument((string)textBox1.Tag, Syncfusion.DocIO.FormatType.Automatic);
                // Convert Word Document into image
                Image[] image      = wordDoc.RenderAsImages(ImageType.Metafile);
                int     pageNumber = 0;
                //Save as Bitmap image
                if (bmpRadioBtn.Checked)
                {
                    for (int i = 0; i < image.Length; i++)
                    {
                        image[i].Save(@"WordToImage_" + ++pageNumber + ".bmp", ImageFormat.Bmp);
                    }
                    if (MessageBoxAdv.Show("Do you want to view the Image file?", "File has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("WordToImage_1.bmp")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start(@"WordToImage_1.bmp");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as PNG image
                else if (pngRadioBtn.Checked)
                {
                    for (int i = 0; i < image.Length; i++)
                    {
                        image[i].Save(@"WordToImage_" + ++pageNumber + ".png", ImageFormat.Png);
                    }
                    if (MessageBoxAdv.Show("Do you want to view the Image file?", "File has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("WordToImage_1.png")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("WordToImage_1.png");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as JPEG image
                else if (jpegRadioBtn.Checked)
                {
                    for (int i = 0; i < image.Length; i++)
                    {
                        image[i].Save(@"WordToImage_" + ++pageNumber + ".jpeg", ImageFormat.Jpeg);
                    }
                    if (MessageBoxAdv.Show("Do you want to view the Image file?", "File has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("WordToImage_1.jpeg")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("WordToImage_1.jpeg");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as EMF image
                else if (emfRadioBtn.Checked)
                {
                    for (int i = 0; i < image.Length; i++)
                    {
                        MemoryStream stream = (MemoryStream)wordDoc.RenderAsImages(i, ImageFormat.Emf);
                        using (FileStream fstream = new FileStream(@"WordToImage_" + ++pageNumber + ".emf", FileMode.OpenOrCreate))
                        {
                            stream.WriteTo(fstream);
                        }
                    }
                    if (MessageBoxAdv.Show("Do you want to view the Image file?", "File has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("WordToImage_1.emf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("WordToImage_1.emf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
            }
            else
            {
                MessageBoxAdv.Show("Browse a word document and click the button to convert as a Image.");
            }
        }
Exemplo n.º 30
0
        private void WorkerFile_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string       text;
            MessageTitle title = new MessageTitle();

            if (e.Cancelled)
            {
                text  = "Validacija datoteka od Columbia State modifikacije je prekunita.\n";
                text += "Ne možete se spojiti na server sve dok uspješno ne završite validaciju.";
                MessageBoxAdv.Show(text, title.WarningMsg, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //workerFile.CancelAsync();
                //text = String.Format("Tokom provjere došlo je do neovlaštene izmjene fajlova.\nAplikacija iz sigurnostnih razloga bit æe zatvorena, pokušajte ponovo.");
                //MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //Application.Exit();
                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                this.Close();
                //return;
            }
            else if (this.fileUnknown > 0 || this.fileMissed > 0 || this.fileIncorrect > 0)
            {
                text  = "Vaša modifikacija sadrži nekoliko pogrešaka sa datotekama.\n";
                text += "Da li želite detaljno pogledati listu datoteka sa greškom?.";
                if (MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    FileForm ff = new FileForm(this.errorFiles);
                    ff.FileMissed    = this.fileMissed;
                    ff.FileUnknown   = this.fileUnknown;
                    ff.FileIncorrect = this.fileIncorrect;
                    ff.FileTotal     = Launcher.Name.Length;

                    ff.ShowDialog();
                }

                //ako potoje nepoznate datoteke, ponudit ce se brisanje istih
                //i ako se izvede brisanje onda ce se nastaviti sa vlidacijom
                if (this.fileUnknown > 0)
                {
                    text  = "Da bih ste se uspješno spojili na server potrebno je da uklonite nepoznate fajlove.\n";
                    text += "Da li želite sada ukloniti nepoznate fajlove i tako omoguæiti uspješnu validaciju datoteka?\n";
                    text += "Napomena, datoteke koje su u listi tj. zapisniku oznaèene kao nepoznate æe biti trajno uklonjene.";
                    if (MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        Library  libs = new Library();
                        DataFile df   = new DataFile();
                        df.ReadUnknown(Launcher.Name, libs.Name);
                        foreach (string file in df.UnknownFiles)
                        {
                            if (!File.Exists(file))
                            {
                                continue;
                            }
                            File.Delete(file);
                        }

                        text = "Nepoznate datoteke su uspješno obrisane, sada možete nastaviti.";
                        MessageBoxAdv.Show(text, title.InfoMsg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //korisnik je odabrao da ne zeli ukloniti nepoznate fajlove
                        //time se validacija ne ispunjava i prekida se zatvaranjem forme
                        this.DialogResult = System.Windows.Forms.DialogResult.Abort;
                        this.Close();
                        return;
                    }
                }

                //ako potoje nedotajuce i nekorektne datoteke onda ce biti ponudjeno skidanje istih
                //u slucaju da se uspjesno izvede validacija ce biti nastavljena dalje;
                if (this.fileMissed > 0 || this.fileIncorrect > 0)
                {
                    long lenght = 0;
                    //sabira se ukupna velicina svih pojedinih fajlova na listi za download
                    foreach (int id in this.id)
                    {
                        lenght += Launcher.Size[id];
                    }
                    text  = "Da bih ste se spojili uspješno na server sve datoteke trebaju biti validne.\n";
                    text += "Da li želite sada skinuti potrebne datotke i tako omoguæiti uspješnu validaciju?\n";
                    text += String.Format("Napomena, broj datoteka za skidanje je {0} i ukupna velièina je {1:0.00}MB.", this.fileMissed + this.fileIncorrect, lenght / 1048576.0);
                    if (MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        this.Hide();
                        DownloadForm dw = new DownloadForm();
                        foreach (int index in this.id)
                        {
                            dw.Id.Add(index);
                        }
                        if (dw.ShowDialog() == DialogResult.Abort)
                        {
                            //ažuriranje datoteka nije uspješno izvršeno i validacija se prekida;
                            text  = "Skidanje i ažuriranje datoteka sa servisa nije uspješno izvršeno.\n";
                            text += "Nažalost validacija ne može biti nastavljena dalje, pokušajte ponovo.\n";
                            text += "U sluèaju da ne može proæi postupak validacije, obratite se na forumu.";
                            MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.DialogResult = System.Windows.Forms.DialogResult.Abort;
                            this.Close();
                            return;
                        }

                        /*if (dw.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                         *  this.DialogResult = System.Windows.Forms.DialogResult.OK;
                         * else
                         *  this.DialogResult = System.Windows.Forms.DialogResult.Abort;*/
                    }
                    else
                    {
                        //korisnik je odabrao da ne zeli skinuti protrebne fajlove
                        //time validacija ne može biti zadovoljena i forma se zatvara
                        this.DialogResult = System.Windows.Forms.DialogResult.Abort;
                        this.Close();
                        return;
                    }
                }
            }

            /*else if (this.id.Count > 0)
             * {
             *  text = String.Format("Ukupno ima {0} fajlova za ažuriranje.\nDa li želite sada izvršiti nadogradnju istih?", this.id.Count);
             *  if (MessageBoxAdv.Show(text, title.WarningMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
             *  {
             *      DownloadForm dw = new DownloadForm(true);
             *      foreach (int index in this.id) dw.Id.Add(index);
             *
             *      if (dw.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
             *          this.DialogResult = System.Windows.Forms.DialogResult.OK;
             *      else
             *          this.DialogResult = System.Windows.Forms.DialogResult.Abort;
             *  }
             *  else
             *  {
             *      this.DialogResult = System.Windows.Forms.DialogResult.Abort;
             *  }
             * }
             * else
             * {
             *  this.DialogResult = System.Windows.Forms.DialogResult.OK;
             * }*/

#if DEBUG
            /*Library lib = new Library();
             * if (!lib.Valid())
             * {
             *  text = "Columbia State Launcher biblioteke nisu validne!";
             *  MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Stop);
             *  this.DialogResult = System.Windows.Forms.DialogResult.Abort;
             * }*/
#endif

            //this.fileStream.Clear();
            //this.fileStream = null;
            //GC.Collect();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }