private void btnOk_Click(object sender, EventArgs e)
        {
            if (tbFilesLocation.Text == string.Empty)
            {
                if (tbFilesLocation.Text == string.Empty)
                {
                    lbLocation.ForeColor = Color.Red;
                }

                MsgBox.Show("Please specify all required site generation parameters!", @"Error", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);

                return;
            }

            PdfGenParams = new PdfGenParams
            {
                FileName   = tbFilesLocation.Text,
                PDFGenType =
                    rbMovies.Checked
                        ? rbAll.Checked
                            ? PDFGenType.All
                            : rbChristmas.Checked
                                ? PDFGenType.Christmas
                                : PDFGenType.Helloween
                        : PDFGenType.All,
                ForMovies = rbMovies.Checked
            };

            DialogResult = DialogResult.OK;
            Close();
        }
Ejemplo n.º 2
0
        public static OperationResult CreateCatalog(PdfGenParams pdfGenParams)
        {
            var result = new OperationResult();

            try
            {
                var toBeProcessedCount = Desene.DAL.GetCount(pdfGenParams.ForMovies, pdfGenParams.PDFGenType);

                var document = new Document();
                document.Info.Title  = "Movies Catalog";
                document.Info.Author = "Calin Marinescu";

                var formProgressIndicator = new FrmProgressIndicator("Movies Catalog generator", "Loading, please wait ...", toBeProcessedCount);
                formProgressIndicator.Argument = new KeyValuePair <Document, PdfGenParams>(document, pdfGenParams);
                formProgressIndicator.DoWork  += formPI_DoWork_GenerateMoviesCatalog;

                switch (formProgressIndicator.ShowDialog())
                {
                case DialogResult.Cancel:
                    result.Success            = false;
                    result.CustomErrorMessage = "Operation has been canceled";

                    return(result);

                case DialogResult.Abort:
                    result.Success            = false;
                    result.CustomErrorMessage = formProgressIndicator.Result.Error.Message;

                    return(result);

                case DialogResult.OK:
                    //var fillDoc = (Document)formProgressIndicator.Result.Result;
                    //MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "d:\\MigraDoc.pdf");

                    var pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
                    pdfRenderer.Document = document;
                    pdfRenderer.RenderDocument();

                    pdfRenderer.PdfDocument.Save(pdfGenParams.FileName);

                    break;
                }
            }
            catch (Exception ex)
            {
                return(result.FailWithMessage(ex));
            }

            return(result);
        }