public async Task <ActionResult> Create([Bind(Include = "PrintSizeId,Name,SizeX,SizeY,ValueSize,MeasureId,DataCreate")] PrintSize printSize)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.PrintSizes.Add(printSize);
                    await db.SaveChangesAsync();
                }

                catch (System.Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("PrintSize_Name_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "Não é possível inserir com o mesmo nome!");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }

                    ViewBag.MeasureId = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name", printSize.MeasureId);

                    return(View(printSize));
                }

                return(RedirectToAction("Index"));
            }

            return(View(printSize));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            PrintSize printSize = await db.PrintSizes.FindAsync(id);

            db.PrintSizes.Remove(printSize);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        // GET: PrintSizes/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PrintSize printSize = await db.PrintSizes.FindAsync(id);

            if (printSize == null)
            {
                return(HttpNotFound());
            }
            return(View(printSize));
        }
        // GET: PrintSizes/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PrintSize printSize = await db.PrintSizes.FindAsync(id);

            if (printSize == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MeasureId = new SelectList(db.Measures, "MeasureId", "Name", printSize.MeasureId);
            return(View(printSize));
        }
        public PdfPrintDocument(PdfDocument pdf, PrintSize printSize)
        {
            if (pdf == null)
            {
                throw new ArgumentNullException("pdf");
            }

            m_pdf       = pdf;
            m_printSize = printSize;

            m_printDocument                    = new PrintDocument();
            m_printDocument.BeginPrint        += printDocument_BeginPrint;
            m_printDocument.QueryPageSettings += printDocument_QueryPageSettings;
            m_printDocument.PrintPage         += printDocument_PrintPage;
            m_printDocument.EndPrint          += printDocument_EndPrint;
        }
Esempio n. 6
0
 /// <summary>
 /// Add named worksheet with orientation, print size, and layout
 /// </summary>
 public void AddSheet(
     string sheetName,
     PageOrientation orientation,
     PrintSize printSize,
     double defaultColWidth = 0D,
     bool pageLayoutView    = false)
 {
     Worksheet = _package.Workbook.Worksheets.Add(sheetName);
     Worksheet.PrinterSettings.Orientation = (eOrientation)orientation;
     Worksheet.PrinterSettings.PaperSize   = (ePaperSize)printSize;
     Worksheet.View.PageLayoutView         = pageLayoutView;
     if (defaultColWidth > 0)
     {
         Worksheet.DefaultColWidth = defaultColWidth;
     }
 }
        public static DialogResult ShowPrintPreview(PdfDocument pdf, PrintSize printSize)
        {
            using (var previewDialog = new PrintPreviewDialog())
            {
                using (var printDocument = new PdfPrintDocument(pdf, printSize))
                {
                    previewDialog.Document = printDocument.PrintDocument;

                    // By default the print button sends the preview to the default printer
                    // The following method replaces the default button with the custom button.
                    // The custom button opens print dialog.
                    setupPrintButton(previewDialog, pdf, printSize);

                    // Remove the following line if you do not want preview maximized
                    previewDialog.WindowState = FormWindowState.Maximized;

                    return(previewDialog.ShowDialog());
                }
            }
        }
        public async Task <ActionResult> Edit([Bind(Include = "PrintSizeId,Name,SizeX,SizeY,ValueSize,MeasureId,DataCreate")] PrintSize printSize)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(printSize).State = EntityState.Modified;
                    await db.SaveChangesAsync();
                }
                catch (System.Exception)
                {
                    ModelState.AddModelError(string.Empty, "Não possível adicionar, por ter um item cadastrado com esse mesmo nome!");
                    return(View(printSize));

                    throw;
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.MeasureId = new SelectList(db.Measures, "MeasureId", "Name", printSize.MeasureId);
            return(View(printSize));
        }
        public static DialogResult ShowPrintDialog(PdfDocument pdf, PrintSize printSize)
        {
            using (var printDialog = new PrintDialog())
            {
                printDialog.AllowSomePages   = true;
                printDialog.AllowCurrentPage = true;
                printDialog.AllowSelection   = true;

                printDialog.PrinterSettings.MinimumPage = 1;
                printDialog.PrinterSettings.MaximumPage = pdf.PageCount;
                printDialog.PrinterSettings.FromPage    = printDialog.PrinterSettings.MinimumPage;
                printDialog.PrinterSettings.ToPage      = printDialog.PrinterSettings.MaximumPage;

                var result = printDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    using (var printDocument = new PdfPrintDocument(pdf, printSize))
                        printDocument.Print(printDialog.PrinterSettings);
                }

                return(result);
            }
        }
        private static void setupPrintButton(PrintPreviewDialog previewDialog, PdfDocument pdf, PrintSize printSize)
        {
            ToolStripButton openPrintDialog = new ToolStripButton
            {
                // reuse the image of the default print button
                Image        = ((ToolStrip)previewDialog.Controls[1]).ImageList.Images[0],
                DisplayStyle = ToolStripItemDisplayStyle.Image
            };

            openPrintDialog.Click += new EventHandler(delegate(object sender, EventArgs e)
            {
                if (ShowPrintDialog(pdf, printSize) == DialogResult.OK)
                {
                    previewDialog.Close();
                }
            });

            ((ToolStrip)previewDialog.Controls[1]).Items.RemoveAt(0);
            ((ToolStrip)previewDialog.Controls[1]).Items.Insert(0, openPrintDialog);
        }
Esempio n. 11
0
        public ChartSheetContentSequence(IStreamReader reader)
            : base(reader)
        {
            // reset id counter for chart groups
            ChartFormatIdGenerator.Instance.StartNewChartsheetSubstream();
            ChartAxisIdGenerator.Instance.StartNewChartsheetSubstream();

            // CHARTSHEETCONTENT = [WriteProtect] [SheetExt] [WebPub] *HFPicture PAGESETUP PrintSize [HeaderFooter] [BACKGROUND] *Fbi *Fbi2 [ClrtClient] [PROTECTION]
            //          [Palette] [SXViewLink] [PivotChartBits] [SBaseRef] [MsoDrawingGroup] OBJECTS Units CHARTFOMATS SERIESDATA *WINDOW *CUSTOMVIEW [CodeName] [CRTMLFRT] EOF

            // [WriteProtect]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.WriteProtect)
            {
                this.WriteProtect = (WriteProtect)BiffRecord.ReadRecord(reader);
            }

            // [SheetExt]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.SheetExt)
            {
                this.SheetExt = (SheetExt)BiffRecord.ReadRecord(reader);
            }

            // [WebPub]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.WebPub)
            {
                this.WebPub = (WebPub)BiffRecord.ReadRecord(reader);
            }

            // *HFPicture
            while (BiffRecord.GetNextRecordType(reader) == RecordType.HFPicture)
            {
                this.HFPictures.Add((HFPicture)BiffRecord.ReadRecord(reader));
            }

            // PAGESETUP
            this.PageSetupSequence = new PageSetupSequence(reader);

            // PrintSize
            if (BiffRecord.GetNextRecordType(reader) == RecordType.PrintSize)
            {
                this.PrintSize = (PrintSize)BiffRecord.ReadRecord(reader);
            }

            // [HeaderFooter]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.HeaderFooter)
            {
                this.HeaderFooter = (HeaderFooter)BiffRecord.ReadRecord(reader);
            }

            // [BACKGROUND]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.BkHim)
            {
                this.BackgroundSequence = new BackgroundSequence(reader);
            }

            // *Fbi
            this.Fbis = new List <Fbi>();
            while (BiffRecord.GetNextRecordType(reader) == RecordType.Fbi)
            {
                this.Fbis.Add((Fbi)BiffRecord.ReadRecord(reader));
            }

            // *Fbi2
            this.Fbi2s = new List <Fbi2>();
            while (BiffRecord.GetNextRecordType(reader) == RecordType.Fbi2)
            {
                this.Fbi2s.Add((Fbi2)BiffRecord.ReadRecord(reader));
            }

            // [ClrtClient]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.ClrtClient)
            {
                this.ClrtClient = (ClrtClient)BiffRecord.ReadRecord(reader);
            }

            // [PROTECTION]
            this.ProtectionSequence = new ProtectionSequence(reader);

            // [Palette]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Palette)
            {
                this.Palette = (Palette)BiffRecord.ReadRecord(reader);
            }

            // [SXViewLink]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.SXViewLink)
            {
                this.SXViewLink = (SXViewLink)BiffRecord.ReadRecord(reader);
            }

            // [PivotChartBits]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.PivotChartBits)
            {
                this.PivotChartBits = (PivotChartBits)BiffRecord.ReadRecord(reader);
            }

            // [SBaseRef]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.SBaseRef)
            {
                this.SBaseRef = (SBaseRef)BiffRecord.ReadRecord(reader);
            }

            // [MsoDrawingGroup]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.MsoDrawingGroup)
            {
                this.MsoDrawingGroup = (MsoDrawingGroup)BiffRecord.ReadRecord(reader);
            }

            // OBJECTS
            this.ObjectsSequence = new ObjectsSequence(reader);

            // Units
            this.Units = (Units)BiffRecord.ReadRecord(reader);

            // CHARTFOMATS
            this.ChartFormatsSequence = new ChartFormatsSequence(reader);

            // SERIESDATA
            this.SeriesDataSequence = new SeriesDataSequence(reader);

            // *WINDOW
            this.WindowSequences = new List <WindowSequence>();
            while (BiffRecord.GetNextRecordType(reader) == RecordType.Window2)
            {
                this.WindowSequences.Add(new WindowSequence(reader));
            }

            // *CUSTOMVIEW
            this.CustomViewSequences = new List <CustomViewSequence>();

            // CUSTOMVIEW seems to be totally optional,
            // so check for the existence of the next sequences
            while (BiffRecord.GetNextRecordType(reader) != RecordType.CodeName &&
                   BiffRecord.GetNextRecordType(reader) != RecordType.CrtMlFrt &&
                   BiffRecord.GetNextRecordType(reader) != RecordType.EOF)
            {
                this.CustomViewSequences.Add(new CustomViewSequence(reader));
            }

            //this.CustomViewSequences = new List<CustomViewSequence>();
            //while (BiffRecord.GetNextRecordType(reader) == RecordType.UserSViewBegin)
            //{
            //    this.CustomViewSequences.Add(new CustomViewSequence(reader));
            //}

            // [CodeName]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.CodeName)
            {
                this.CodeName = (CodeName)BiffRecord.ReadRecord(reader);
            }

            // [CRTMLFRT]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.CrtMlFrt)
            {
                this.CrtMlfrtSequence = new CrtMlfrtSequence(reader);
            }

            // EOF
            this.EOF = (EOF)BiffRecord.ReadRecord(reader);
        }
Esempio n. 12
0
        public CustomViewSequence(IStreamReader reader)
            : base(reader)
        {
            // CUSTOMVIEW = UserSViewBegin *Selection [HorizontalPageBreaks] [VerticalPageBreaks] [Header]
            //    [Footer] [HCenter] [VCenter] [LeftMargin] [RightMargin] [TopMargin] [BottomMargin]
            //    [Pls] [Setup] [PrintSize] [HeaderFooter] [AUTOFILTER] UserSViewEnd


            // NOTE: UserSViewBegin and UserSViewEnd seem to be optional to!


            // UserSViewBegin
            if (BiffRecord.GetNextRecordType(reader) == RecordType.UserSViewBegin)
            {
                this.UserSViewBegin = (UserSViewBegin)BiffRecord.ReadRecord(reader);
            }

            // *Selection
            this.Selections = new List <Selection>();
            while (BiffRecord.GetNextRecordType(reader) == RecordType.Selection)
            {
                this.Selections.Add((Selection)BiffRecord.ReadRecord(reader));
            }

            // [HorizontalPageBreaks]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.HorizontalPageBreaks)
            {
                this.HorizontalPageBreaks = (HorizontalPageBreaks)BiffRecord.ReadRecord(reader);
            }

            // [VerticalPageBreaks]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.VerticalPageBreaks)
            {
                this.VerticalPageBreaks = (VerticalPageBreaks)BiffRecord.ReadRecord(reader);
            }

            // [Header]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Header)
            {
                this.Header = (Header)BiffRecord.ReadRecord(reader);
            }

            // [Footer]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Footer)
            {
                this.Footer = (Footer)BiffRecord.ReadRecord(reader);
            }

            // [HCenter]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.HCenter)
            {
                this.HCenter = (HCenter)BiffRecord.ReadRecord(reader);
            }

            // [VCenter]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.VCenter)
            {
                this.VCenter = (VCenter)BiffRecord.ReadRecord(reader);
            }

            // [LeftMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.LeftMargin)
            {
                this.LeftMargin = (LeftMargin)BiffRecord.ReadRecord(reader);
            }

            // [RightMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.RightMargin)
            {
                this.RightMargin = (RightMargin)BiffRecord.ReadRecord(reader);
            }

            // [TopMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.TopMargin)
            {
                this.TopMargin = (TopMargin)BiffRecord.ReadRecord(reader);
            }

            // [BottomMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.BottomMargin)
            {
                this.BottomMargin = (BottomMargin)BiffRecord.ReadRecord(reader);
            }

            // [Pls]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Pls)
            {
                this.Pls = (Pls)BiffRecord.ReadRecord(reader);
            }

            // [Setup]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Setup)
            {
                this.Setup = (Setup)BiffRecord.ReadRecord(reader);
            }

            // [PrintSize]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.PrintSize)
            {
                this.PrintSize = (PrintSize)BiffRecord.ReadRecord(reader);
            }

            // [HeaderFooter]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.HeaderFooter)
            {
                this.HeaderFooter = (HeaderFooter)BiffRecord.ReadRecord(reader);
            }

            // [AUTOFILTER]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.AutoFilterInfo)
            {
                this.AutoFilterSequence = new AutoFilterSequence(reader);
            }

            // UserSViewEnd
            if (BiffRecord.GetNextRecordType(reader) == RecordType.UserSViewEnd)
            {
                this.UserSViewEnd = (UserSViewEnd)BiffRecord.ReadRecord(reader);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Prepare image to print
        /// </summary>
        /// <param name="imgToPrint"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static Bitmap setPrintSize(Bitmap imgToPrint, PrintSize printSize)
        {
            Size sourceSize = imgToPrint.Size;
            Size destSize   = new Size(0, 0);

            switch (printSize)
            {
            case PrintSize.cm10x15:
                destSize = new Size(1772, 1181);
                break;

            case PrintSize.cm13x18:
                destSize = new Size(2126, 1535);
                break;

            case PrintSize.cm15x21:
                destSize = new Size(2480, 1772);
                break;

            case PrintSize.cm20x25:
                destSize = new Size(2953, 2362);
                break;

            case PrintSize.cm20x30:
                destSize = new Size(3543, 2362);
                break;
            }

            //Muda a orientação se necessário
            if (sourceSize.Height > sourceSize.Width)
            {
                destSize = new Size(destSize.Height, destSize.Width);
            }

            //Calcula a área a imagem de origem que será copiada
            float nPercent  = 0;
            float nPercentW = 0;
            float nPercentH = 0;

            nPercentW = ((float)destSize.Width / (float)sourceSize.Width);
            nPercentH = ((float)destSize.Height / (float)sourceSize.Height);

            if (nPercentH > nPercentW)
            {
                nPercent = nPercentH;
            }
            else
            {
                nPercent = nPercentW;
            }


            Size  tmpNewSize  = new Size((int)(sourceSize.Width * nPercent), (int)(sourceSize.Height * nPercent));
            Point posNewPoint = new Point(0, 0);

            //Verifica se necessita fazer crop
            if ((tmpNewSize.Width > destSize.Width) || (tmpNewSize.Height > destSize.Height))
            {
                //Calcula a posição do crop
                if (tmpNewSize.Width > destSize.Width)
                {
                    posNewPoint.X = (Int32)(((float)tmpNewSize.Width - (float)destSize.Width) / 2);
                }

                if (tmpNewSize.Height > destSize.Height)
                {
                    posNewPoint.Y = (Int32)(((float)tmpNewSize.Height - (float)destSize.Height) / 2);
                }
            }


            //Calcula a área de corte com base no tamanho original da imagem
            RectangleF cropRect = new Rectangle();

            cropRect.X = ((float)posNewPoint.X / nPercent);
            if (cropRect.X < 0)
            {
                cropRect.X = 0;
            }

            cropRect.Y = (float)posNewPoint.Y / nPercent;
            if (cropRect.Y < 0)
            {
                cropRect.Y = 0;
            }

            cropRect.Width  = (float)destSize.Width / nPercent;
            cropRect.Height = (float)destSize.Height / nPercent;


            //Cria a imagem base com fundo branco
            Bitmap baseBmp = new Bitmap(destSize.Width, destSize.Height, PixelFormat.Format24bppRgb);

            baseBmp.SetResolution(300, 300);

            //Cria o objeto de desenho e fundo branco
            Graphics gfx = Graphics.FromImage(baseBmp);

            gfx.SmoothingMode     = SmoothingMode.AntiAlias;
            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gfx.PixelOffsetMode   = PixelOffsetMode.HighQuality;

            gfx.FillRectangle(new SolidBrush(Color.White), 0, 0, destSize.Width, destSize.Height);

            gfx.DrawImage(imgToPrint, new Rectangle(0, 0, destSize.Width, destSize.Height), cropRect.X, cropRect.Y, cropRect.Width, cropRect.Height, GraphicsUnit.Pixel);

            gfx.Dispose();
            gfx = null;

            return(baseBmp);
        }
 public static void SetPrintSelection(PrintSize printSize)
 {
     _PrintSelection = printSize;
 }