コード例 #1
0
        /// <summary>
        /// Reads the saved posters from the database, convert them to smaller size and save them on disk
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void formPI_DoWork_GenerateSitePosters(FrmProgressIndicator sender, DoWorkEventArgs e)
        {
            var args = (BgwArgument_Work)e.Argument;
            var errorsWhileSaving = new List <TechnicalDetailsImportError>();

            var i = 0;

            foreach (var movieShortInfo in args.MSI)
            {
                if (sender.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                i++;
                sender.SetProgress(i, Path.GetFileName(movieShortInfo.FileName));

                if (!movieShortInfo.HasPoster)
                {
                    continue;
                }

                var fileName = Path.Combine(args.SiteGenLocation, string.Format("Imgs\\{0}\\poster-{1}.jpg", args.SubFolder, movieShortInfo.Id));
                if (File.Exists(fileName))
                {
                    continue;                        //?? wasn't it excluded before this ?
                }
                try
                {
                    var cover = Desene.DAL.GetPoster(movieShortInfo.Id);

                    using (var ms = new MemoryStream(cover))
                    {
                        var imgOgj = GraphicsHelpers.CreatePosterThumbnail(250, 388, Image.FromStream(ms));

                        imgOgj.Save(fileName, ImageFormat.Jpeg);
                    }
                }
                catch (Exception ex)
                {
                    errorsWhileSaving.Add(
                        new TechnicalDetailsImportError
                    {
                        FilePath    = movieShortInfo.FileName,
                        ErrorMesage = OperationResult.GetErrorMessage(ex)
                    });
                }
            }

            e.Result = errorsWhileSaving;
        }
コード例 #2
0
        private static void formPI_DoWork_GenerateMoviesCatalog(FrmProgressIndicator sender, DoWorkEventArgs e)
        {
            var catalogGenDet = (KeyValuePair <Document, PdfGenParams>)e.Argument;
            var document      = catalogGenDet.Key;
            var pdfGenParams  = catalogGenDet.Value;

            var movies = Desene.DAL.GetMoviesForPDF(pdfGenParams);

            //var style = document.Styles["Normal"];
            //style.Font.Name = "Arial Narrow";
            //style.Font.Size = 10;

            var section = document.AddSection();

            section.PageSetup.PageFormat    = PageFormat.A4;
            section.PageSetup.MirrorMargins = true;
            section.PageSetup.TopMargin     = Unit.FromCentimeter(0.5);
            section.PageSetup.BottomMargin  = Unit.FromCentimeter(0.5);
            section.PageSetup.LeftMargin    = Unit.FromCentimeter(2);
            section.PageSetup.RightMargin   = Unit.FromCentimeter(1);

            var table = section.AddTable();

            var sectionWidth =
                (int)document.DefaultPageSetup.PageWidth -
                (int)section.PageSetup.LeftMargin -
                (int)section.PageSetup.RightMargin;

            var columnWidth = sectionWidth / 4;

            var column = table.AddColumn();

            column.Width = columnWidth;
            var column2 = table.AddColumn();

            column2.Width = columnWidth;
            var column3 = table.AddColumn();

            column3.Width = columnWidth;
            var column4 = table.AddColumn();

            column4.Width = columnWidth;

            Row row = null;

            var indexPos = 0;

            for (var i = 0; i < movies.Count; i += 4)
            {
                if (sender.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                row = table.AddRow();

                for (var j = 0; j < 4; j++)
                {
                    var k = i + j;
                    if (k >= movies.Count)
                    {
                        break;
                    }

                    var movieObj = movies[k];

                    indexPos++;
                    sender.SetProgress(indexPos, movieObj.FN);

                    var imgOgj = GraphicsHelpers.CreatePosterThumbnailForPDF(150, 232, movieObj.Cover, movieObj.R, movieObj.A,
                                                                             pdfGenParams.PDFGenType == PDFGenType.All
                            ? movieObj.T == "Craciun"
                                ? Properties.Resources.Christmas_Tree_icon
                                : movieObj.T == "Helloween"
                                    ? Properties.Resources.Pumpkin_icon
                                    : null
                            : null);

                    row.Cells[j].Format.Alignment  = ParagraphAlignment.Center;
                    row.Cells[j].VerticalAlignment = VerticalAlignment.Center;
                    row.Cells[j].AddParagraph().AddImage(MigraDocFilenameFromByteArray(imgOgj));
                }

                row = table.AddRow();

                for (var j = 0; j < 4; j++)
                {
                    var k = i + j;
                    if (k >= movies.Count)
                    {
                        break;
                    }

                    var movieObj = movies[k];

                    var dataTable = new Table();
                    var columnD1  = dataTable.AddColumn();
                    columnD1.Width = columnWidth;

                    var rowD1 = dataTable.AddRow();
                    rowD1.Cells[0].Format.Alignment = ParagraphAlignment.Center;
                    rowD1.Cells[0].Format.Font.Name = "Arial Narrow";
                    rowD1.Cells[0].Format.Font.Size = 10;

                    var tm = new TextMeasurement(rowD1.Cells[0].Format.Font);
                    //var strWidth = tm.MeasureString(movieObj.FN).Width;

                    var movieTitle = movieObj.FN;
                    var lineCount  = tm.GetSplittedLineCount(movieTitle, columnWidth, null);

                    if (lineCount > 2)
                    {
                        movieTitle = tm.GetStringWithEllipsis(movieObj.FN, columnWidth, 2);
                    }

                    rowD1.Cells[0].AddParagraph(movieTitle);

                    row.Cells[j].Elements.Add(dataTable);
                }
            }

            //e.Result = document;
        }