Exemplo n.º 1
0
 public virtual void SetImageMask(iText.IO.Image.ImageData imageMask)
 {
     if (this.mask)
     {
         throw new iText.IO.IOException(iText.IO.IOException.ImageMaskCannotContainAnotherImageMask);
     }
     if (!imageMask.mask)
     {
         throw new iText.IO.IOException(iText.IO.IOException.ImageIsNotMaskYouMustCallImageDataMakeMask);
     }
     this.imageMask = imageMask;
 }
Exemplo n.º 2
0
        private static void ConfiguraAparencia(PdfSigner objStamper, CertSimples cert, int X, int Y, int Largura, int Altura, int Pagina, int Rotation, string Contact = "", string Reason = "Assinatura Digital", string Location = "Indústrias Nucleares do Brasil S/A - INB", string Creator = "Assinador da INB", TipoAssinatura Tipo = TipoAssinatura.Normal, string Cargo = "", string CREACRM = "")
        {
            PdfDocument pdfDoc = objStamper.GetDocument();
            PdfPage     oPage = pdfDoc.GetPage(Pagina);
            int         LarguraAssinatura = Largura;
            int         AlturaAssinatura = Altura;
            int         X_Ajustado, Y_Ajustado;

            X_Ajustado = X;
            Y_Ajustado = Y;
            var    crop = oPage.GetCropBox();
            float  Left, Top, Width, Height;
            Bitmap bmp            = Graphic.ConfiguraBMP(cert, out Altura, Tipo);

            if (Rotation == 270)
            {
                Left = (int)crop.GetLeft() + X_Ajustado;
                Top  = (int)crop.GetRight() - (Y_Ajustado + AlturaAssinatura + 5);
            }
            else if (Rotation == 90)
            {
                Left = (int)crop.GetRight() + X_Ajustado;
                Top  = (int)crop.GetLeft() - (Y_Ajustado + AlturaAssinatura + 5);
            }
            else
            {
                Left = (int)crop.GetLeft() + X_Ajustado;
                Top  = (int)crop.GetTop() - (Y_Ajustado + AlturaAssinatura + 5);
            }
            Width  = LarguraAssinatura;
            Height = AlturaAssinatura;
            iText.Kernel.Geom.Rectangle oRetangulo = new iText.Kernel.Geom.Rectangle(Left, Top, Width, Height);
            var pageSize          = pdfDoc.GetPage(Pagina).GetMediaBox();
            var signaturePosition = new iText.Kernel.Geom.Rectangle(pageSize.GetLeft(), pageSize.GetBottom(), pageSize.GetWidth(), pageSize.GetHeight());
            PdfSignatureAppearance signatureAppearance = objStamper.GetSignatureAppearance();
            var memoryStream = new MemoryStream();

            bmp.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            iText.IO.Image.ImageData pic = iText.IO.Image.ImageDataFactory.Create(memoryStream.ToArray());
            signatureAppearance.SetReason(Reason);
            signatureAppearance.SetLocation(Location);
            signatureAppearance.SetSignatureCreator(Creator);
            signatureAppearance.SetSignatureGraphic(pic);
            signatureAppearance.SetRenderingMode(PdfSignatureAppearance.RenderingMode.GRAPHIC);
            signatureAppearance.SetPageRect(oRetangulo);
            signatureAppearance.SetPageNumber(Pagina);
        }
Exemplo n.º 3
0
        //private void Helper_GeneralSummary(GridViewRow row)
        //{
        //    row.BackColor = Color.Gray;
        //    row.Cells[0].HorizontalAlign = HorizontalAlign.Right;
        //    row.Cells[0].Text = "<b>Totale</b>";
        //    row.Cells[1].Text = "<b>" + row.Cells[1].Text + "</b>";
        //    row.Cells[2].Text = "<b>" + row.Cells[2].Text + "</b>";
        //    row.Cells[3].Text = "<b>" + row.Cells[3].Text + "</b>";
        //    row.Cells[4].Text = "<b>" + row.Cells[4].Text + "</b>";
        //    row.Cells[5].Text = "<b>" + row.Cells[5].Text + "</b>";
        //    //row.Cells[6].Text = "<b>" + row.Cells[6].Text + "</b>";
        //}

        protected void btnStampa_Click(object sender, EventArgs e)
        {
            try
            {
                Esito    esito         = new Esito();
                DateTime dataInizio    = DateTime.Parse(txt_DataInizio.Text);
                DateTime dataFine      = DateTime.Parse(txt_DataFine.Text);
                string   nominativo    = txt_Nominativo.Text;
                string   lavorazione   = txt_Lavorazione.Text;
                string   produzione    = txt_Produzione.Text;
                bool     soloFornitori = chk_Fornitore.Checked;

                List <DatiReport> listaDatiReport = Report_BLL.Instance.GetListaDatiReportCollaboratoriFornitori(dataInizio, dataFine, nominativo, lavorazione, produzione, soloFornitori, ref esito);

                Report_BLL.Instance.EliminaCollaboratoriImportoZero(ref listaDatiReport);

                if (esito.Codice == 0 && listaDatiReport != null && listaDatiReport.Count > 0)
                {
                    // LEGGO I PARAMETRI DI VS
                    Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA");
                    string pIvaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE");
                    string denominazioneVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO");
                    string toponimoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO");
                    string indirizzoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO");
                    string civicoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP");
                    string capVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA");
                    string cittaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA");
                    string provinciaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL");
                    string emailVs = cfAppo.valore;

                    // export SU PDF

                    string nomeFile      = "Report_Collaboratori.pdf";
                    string pathReport    = ConfigurationManager.AppSettings["PATH_DOCUMENTI_REPORT"] + nomeFile;
                    string mapPathReport = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_REPORT"]) + nomeFile;

                    //string prefissoUrl = Request.Url.Scheme + "://" + Request.Url.Authority;
                    iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png"));


                    PdfWriter   wr  = new PdfWriter(mapPathReport);
                    PdfDocument doc = new PdfDocument(wr);
                    doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate());
                    //doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4);
                    Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4.Rotate(), false);

                    document.SetMargins(50, 30, 50, 30);

                    //iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(0, 225, 0);
                    // COLORE BLU VIDEOSYSTEM
                    iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243);

                    //CICLO LISTA DATI REPORT
                    int totCollaboratoriUtilizzati = 0;

                    foreach (DatiReport collaboratore in listaDatiReport)
                    {
                        totCollaboratoriUtilizzati++;
                        // AGGIUNGO TABLE PER LAYOUT INTESTAZIONE
                        iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(new float[] { 1, 9 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        iText.Layout.Element.Image image          = new iText.Layout.Element.Image(imageData).ScaleAbsolute(100, 70).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
                        Cell cellaImmagine = new Cell().SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.MIDDLE).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
                        cellaImmagine.Add(image);
                        tbIntestazione.AddCell(cellaImmagine);

                        iText.Layout.Element.Table tbIntestazioneDx = new iText.Layout.Element.Table(new float[] { 4, 6 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        Paragraph pTitolo = new Paragraph("Nome").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        Paragraph pValore = new Paragraph(collaboratore.NomeCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Qualifica").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pValore = new Paragraph(collaboratore.QualificaCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Indirizzo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pValore = new Paragraph(collaboratore.IndirizzoCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Città").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pValore = new Paragraph(collaboratore.CittaCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Telefono").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pValore = new Paragraph(collaboratore.TelefonoCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Cod.Fiscale/P.Iva").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pValore = new Paragraph(collaboratore.CodFiscaleCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        // AGGIUNGO INTESTAZIONE COLLABORATORE
                        tbIntestazione.AddCell(tbIntestazioneDx).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        document.Add(tbIntestazione);

                        Paragraph pSpazio = new Paragraph(" ");
                        document.Add(pSpazio);

                        Paragraph pLuogoData = new Paragraph(cittaVs + ", " + DateTime.Today.ToLongDateString());
                        document.Add(pLuogoData);

                        document.Add(pSpazio);

                        // CREAZIONE GRIGLIA
                        iText.Layout.Element.Table tbGrigla = new iText.Layout.Element.Table(new float[] { 67, 138, 120, 100, 100, 55, 50, 50, 50, 50 }).SetWidth(780).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetFixedLayout();
                        Paragraph pGriglia;
                        Cell      cellaGriglia;

                        // INTESTAZIONE GRIGLIA
                        pGriglia     = new Paragraph("Data").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Lavorazione").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Produzione").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Cliente").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Descrizione").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Assunz.").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Mista").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Rimb. KM").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Rit. Acconto").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Fattura").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        //pGriglia = new Paragraph("Diaria").SetFontSize(10);
                        //cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        //cellaGriglia.Add(pGriglia);
                        //tbGrigla.AddHeaderCell(cellaGriglia);

                        // TOTALI PARZIALI
                        decimal fattura         = 0;
                        decimal ritenutaAcconto = 0;
                        decimal assunzione      = 0;
                        decimal mista           = 0;
                        decimal rimborsoKm      = 0;
                        //int diaria = 0;

                        foreach (DatiFiscaliLavorazione datiFiscali in collaboratore.ListaDatiFiscali)
                        {
                            pGriglia     = new Paragraph(datiFiscali.DataLavorazione.ToShortDateString()).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            pGriglia     = new Paragraph(datiFiscali.Lavorazione).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            pGriglia     = new Paragraph(datiFiscali.Produzione).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            pGriglia     = new Paragraph(datiFiscali.Cliente).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            pGriglia     = new Paragraph(datiFiscali.Descrizione).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            assunzione  += datiFiscali.Assunzione;
                            pGriglia     = new Paragraph(datiFiscali.Assunzione.ToString("###,##0.00")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            mista       += datiFiscali.Mista;
                            pGriglia     = new Paragraph(datiFiscali.Mista.ToString("###,##0.00")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            rimborsoKm  += datiFiscali.RimborsoKm;
                            pGriglia     = new Paragraph(datiFiscali.RimborsoKm.ToString("###,##0.00")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            ritenutaAcconto += datiFiscali.RitenutaAcconto;
                            pGriglia         = new Paragraph(datiFiscali.RitenutaAcconto.ToString("###,##0.00")).SetFontSize(9);
                            cellaGriglia     = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            fattura     += datiFiscali.Fattura;
                            pGriglia     = new Paragraph(datiFiscali.Fattura.ToString("###,##0.00")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            //diaria += datiFiscali.Diaria;
                            //pGriglia = new Paragraph(datiFiscali.Diaria.ToString("###")).SetFontSize(9);
                            //cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            //cellaGriglia.Add(pGriglia);
                            //tbGrigla.AddCell(cellaGriglia);
                        }

                        pGriglia     = new Paragraph("TOTALI").SetFontSize(9);
                        cellaGriglia = new Cell(1, 5).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph(assunzione.ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph(mista.ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph(rimborsoKm.ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph(ritenutaAcconto.ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph(fattura.ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        //pGriglia = new Paragraph(diaria.ToString("##0")).SetFontSize(9);
                        //cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        //cellaGriglia.Add(pGriglia);
                        //tbGrigla.AddCell(cellaGriglia);

                        // AGGIUNGO TABELLA
                        document.Add(tbGrigla);

                        if (totCollaboratoriUtilizzati < listaDatiReport.Count)
                        {
                            // AGGIUNGO SALTO PAGINA
                            document.Add(new AreaBreak());
                        }
                    }

                    int n = doc.GetNumberOfPages();
                    iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize();

                    // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA
                    for (int i = 1; i <= n; i++)
                    {
                        //AGGIUNGO NUM.PAGINA
                        document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7),
                                                 pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);
                        //AGGIUNGO FOOTER
                        document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                                                 pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);
                    }

                    // CHIUDO IL PDF
                    document.Flush();
                    document.Close();
                    wr.Close();

                    btnRicerca_Click(null, null);

                    // CREO STRINGA PER IL JAVASCRIPT DI VISUALIZZAZIONE
                    if (System.IO.File.Exists(mapPathReport))
                    {
                        Page page = HttpContext.Current.Handler as Page;
                        ScriptManager.RegisterStartupScript(page, page.GetType(), "apriPdf", script: "window.open('" + pathReport.Replace("~", "") + "')", addScriptTags: true);
                    }
                    else
                    {
                        esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                        esito.Descrizione = "Il File " + pathReport.Replace("~", "") + " non è stato creato correttamente!";
                        BasePage p = new BasePage();
                        p.ShowError(esito.Descrizione);
                    }
                }
            }
            catch (Exception ex)
            {
                BasePage p = new BasePage();
                p.ShowError(ex.Message + " " + ex.StackTrace);
            }
        }
Exemplo n.º 4
0
        public Esito popolaPannelloFattura(DatiAgenda eventoSelezionato)
        {
            Esito esito = new Esito();

            try
            {
                if (eventoSelezionato != null && eventoSelezionato.LavorazioneCorrente != null)
                {
                    // LEGGO I PARAMETRI DI VS
                    Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA");
                    string pIvaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE");
                    string denominazioneVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO");
                    string toponimoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO");
                    string indirizzoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO");
                    string civicoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP");
                    string capVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA");
                    string cittaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA");
                    string provinciaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL");
                    string emailVs = cfAppo.valore;

                    //List<DatiArticoliLavorazione> listaArticoliLavorazione = eventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.Where(x => x.Stampa).OrderBy(x => x.Fattura).ToList<DatiArticoliLavorazione>();
                    List <DatiArticoliLavorazione> listaArticoliLavorazione = eventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.Where(x => x.Stampa).ToList <DatiArticoliLavorazione>();

                    if (listaArticoliLavorazione != null)
                    {
                        Protocolli        protocolloFattura = new Protocolli();
                        int               idTipoProtocollo  = UtilityTipologiche.getElementByNome(UtilityTipologiche.caricaTipologica(EnumTipologiche.TIPO_PROTOCOLLO), "Fattura", ref esito).id;
                        List <Protocolli> listaProtocolli   = Protocolli_BLL.Instance.getProtocolliByCodLavIdTipoProtocollo(eventoSelezionato.codice_lavoro, idTipoProtocollo, ref esito, true);
                        string            numeroProtocollo  = "";
                        string            numeroFattura     = "";
                        if (listaProtocolli.Count == 0)
                        {
                            numeroProtocollo = Protocolli_BLL.Instance.getNumeroProtocollo();
                            // ESTRAPOLO IL NUMERO FATTURA DALLA TABELLA TAB_NUMERO_FATTURA
                            numeroFattura = Protocolli_BLL.Instance.getNumeroFattura();
                        }
                        else
                        {
                            bool trovato = false;
                            foreach (Protocolli protocollo in listaProtocolli)
                            {
                                if (protocollo.Destinatario == "Cliente")
                                {
                                    //protocolloFattura = listaProtocolli.First();
                                    numeroProtocollo  = protocollo.Numero_protocollo;
                                    numeroFattura     = protocollo.Protocollo_riferimento;
                                    protocolloFattura = protocollo;
                                    trovato           = true;
                                    break;
                                }
                            }
                            if (!trovato)
                            {
                                numeroProtocollo = Protocolli_BLL.Instance.getNumeroProtocollo();
                                // ESTRAPOLO IL NUMERO FATTURA DALLA TABELLA TAB_NUMERO_FATTURA
                                numeroFattura = Protocolli_BLL.Instance.getNumeroFattura();
                                listaProtocolli.Clear();
                            }
                        }

                        // GESTIONE NOMI FILE PDF
                        //string nomeFile = "Fattura_" + eventoSelezionato.codice_lavoro + ".pdf";
                        string nomeFile       = "Fattura_" + numeroFattura + ".pdf";
                        string pathFattura    = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile;
                        string mapPathFattura = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile;

                        //string prefissoUrl = Request.Url.Scheme + "://" + Request.Url.Authority;
                        iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png"));

                        iText.IO.Image.ImageData imageDNV = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/DNV_2008_ITA2.jpg"));


                        PdfWriter   wr  = new PdfWriter(mapPathFattura);
                        PdfDocument doc = new PdfDocument(wr);
                        doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4);
                        //Document document = new Document(doc);
                        Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4, false);

                        document.SetMargins(245, 30, 110, 30);



                        // ESTRAPOLO IL CLIENTE
                        Anag_Clienti_Fornitori cliente = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(eventoSelezionato.id_cliente, ref esito);

                        Paragraph pSpazio = new Paragraph(" ");
                        document.Add(pSpazio);

                        // CREAZIONE GRIGLIA
                        iText.Layout.Element.Table tbGrigla = new iText.Layout.Element.Table(new float[] { 80, 70, 180, 70, 30, 30, 70 }).SetWidth(530).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetFixedLayout();
                        Paragraph pGriglia;
                        Cell      cellaGriglia;

                        // COLORE BLU VIDEOSYSTEM
                        iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243);

                        // INTESTAZIONE FATTURA
                        pGriglia     = new Paragraph("Fattura").SetFontSize(10).SetBold();
                        cellaGriglia = new Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph(numeroFattura + "                 Rif.Lav. " + eventoSelezionato.codice_lavoro).SetFontSize(10).SetBold();
                        cellaGriglia = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        //pGriglia = new Paragraph("").SetFontSize(10);
                        //cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                        //cellaGriglia.Add(pGriglia);
                        //tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Rif.Prot. " + numeroProtocollo).SetFontSize(10).SetBold();
                        cellaGriglia = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        // INTESTAZIONE GRIGLIA
                        pGriglia     = new Paragraph("Codice").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Descrizione Offerta").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Prezzo").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Qta").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Iva").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);

                        pGriglia     = new Paragraph("Totale").SetFontSize(10);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddHeaderCell(cellaGriglia);


                        decimal totPrezzo = 0;
                        decimal totIVA    = 0;

                        // CICLO GLI ARTICOLI
                        //foreach (DatiArticoli da in listaDatiArticoli)
                        foreach (DatiArticoliLavorazione da in listaArticoliLavorazione)
                        {
                            // CALCOLO I TOTALI
                            //totPrezzo += da.Prezzo * da.Quantita;
                            totPrezzo += da.Prezzo * 1;
                            //totIVA += (da.Prezzo * da.Iva / 100) * da.Quantita;
                            totIVA += (da.Prezzo * da.Iva / 100) * 1;

                            string descrizione      = da.Descrizione;
                            string descrizioneLunga = da.DescrizioneLunga;


                            pGriglia     = new Paragraph(descrizione).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);


                            if (da.Consuntivo == true)
                            {
                                //descrizione = "(c)" + descrizione;
                                //descrizioneLunga = "(Consuntivo)" + Environment.NewLine + descrizioneLunga;

                                Text firstDesc  = new Text("(Consuntivo)" + Environment.NewLine).SetFontSize(9).SetBold();
                                Text secondDesc = new Text(descrizioneLunga).SetFontSize(9);
                                pGriglia = new Paragraph().Add(firstDesc).Add(secondDesc);
                            }
                            else
                            {
                                pGriglia = new Paragraph(descrizioneLunga).SetFontSize(9);
                            }

                            cellaGriglia = new Cell(1, 2).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            pGriglia     = new Paragraph(da.Prezzo.ToString("###,##0.00")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            //pGriglia = new Paragraph(da.Quantita.ToString("##0")).SetFontSize(9);
                            pGriglia     = new Paragraph(1.ToString("##0")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            pGriglia     = new Paragraph(da.Iva.ToString("##")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);

                            //decimal totale = da.Prezzo * da.Quantita;
                            decimal totale = da.Prezzo * 1;

                            pGriglia     = new Paragraph(totale.ToString("###,##0.00")).SetFontSize(9);
                            cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            cellaGriglia.Add(pGriglia);
                            tbGrigla.AddCell(cellaGriglia);
                        }

                        // AGGIUNGO UNO SPAZIO
                        pGriglia     = new Paragraph(" ").SetFontSize(9);
                        cellaGriglia = new Cell(1, 7).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);


                        // ESTRAPOLO NOTEOFFERTA
                        NoteOfferta noteOfferta = Offerta_BLL.Instance.getNoteOffertaByIdDatiAgenda(eventoSelezionato.id, ref esito);

                        // NOTE
                        Text first = new Text("Note:").SetFontSize(9).SetBold();
                        //Text second = new Text(Environment.NewLine + "Gli articoli con la dicitura 'Cons' sono da ritenersi a CONSUNTIVO" + Environment.NewLine + noteOfferta.Note.Trim()).SetFontSize(9);
                        Text      second        = new Text(Environment.NewLine + noteOfferta.Note.Trim()).SetFontSize(9);
                        Paragraph paragraphNote = new Paragraph().Add(first).Add(second);

                        cellaGriglia = new iText.Layout.Element.Cell(3, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10);
                        cellaGriglia.Add(paragraphNote);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph("Imponibile").SetFontSize(9);
                        cellaGriglia = new iText.Layout.Element.Cell(1, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph(totPrezzo.ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        // TOTALE IVA
                        pGriglia     = new Paragraph("i.v.a.").SetFontSize(9);
                        cellaGriglia = new iText.Layout.Element.Cell(1, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph(totIVA.ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        // TOTALE EURO
                        pGriglia     = new Paragraph("Totale Euro").SetFontSize(9);
                        cellaGriglia = new iText.Layout.Element.Cell(1, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        pGriglia     = new Paragraph((totPrezzo + totIVA).ToString("###,##0.00")).SetFontSize(9);
                        cellaGriglia = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold();
                        cellaGriglia.Add(pGriglia);
                        tbGrigla.AddCell(cellaGriglia);

                        document.Add(tbGrigla);

                        //iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(1).GetPageSize();

                        int n = doc.GetNumberOfPages();
                        iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize();


                        // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA
                        for (int i = 1; i <= n; i++)
                        {
                            // AGGIUNGO LOGO
                            iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(90, 80).SetFixedPosition(i, 30, 740);
                            document.Add(image);


                            // CREAZIONE GRIGLIA INFORMAZIONI
                            iText.Layout.Element.Table tbGriglaInfo = new iText.Layout.Element.Table(new float[] { 70, 230 }).SetWidth(300).SetFixedPosition(i, 30, 640, 300);
                            Paragraph pGrigliaInfo = new Paragraph(cittaVs).SetFontSize(9).SetBold();
                            iText.Layout.Element.Cell cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            //pGrigliaInfo = new Paragraph(DateTime.Today.ToLongDateString()).SetFontSize(9);
                            if (string.IsNullOrEmpty(tbDataProtocollo.Text))
                            {
                                tbDataProtocollo.Text = eventoSelezionato.data_inizio_lavorazione.ToShortDateString();
                            }
                            pGrigliaInfo     = new Paragraph(Convert.ToDateTime(tbDataProtocollo.Text).ToLongDateString()).SetFontSize(9);
                            cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            pGrigliaInfo     = new Paragraph("Produzione:").SetFontSize(9).SetBold();
                            cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            pGrigliaInfo     = new Paragraph(eventoSelezionato.produzione).SetFontSize(9);
                            cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            pGrigliaInfo     = new Paragraph("Lavorazione:").SetFontSize(9).SetBold();
                            cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            pGrigliaInfo     = new Paragraph(eventoSelezionato.lavorazione).SetFontSize(9);
                            cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            pGrigliaInfo     = new Paragraph("Data Lav.ne:").SetFontSize(9).SetBold();
                            cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            pGrigliaInfo     = new Paragraph(eventoSelezionato.data_inizio_lavorazione.ToString("dd/MM/yyyy")).SetFontSize(9);
                            cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaInfo.Add(pGrigliaInfo);
                            tbGriglaInfo.AddCell(cellaGrigliaInfo);

                            document.Add(tbGriglaInfo);


                            // CREAZIONE GRIGLIA DESTINATARIO
                            iText.Layout.Element.Table tbGriglaDest = new iText.Layout.Element.Table(new float[] { 70, 230 }).SetWidth(300).SetFixedPosition(i, 350, 650, 300);
                            Paragraph pGrigliaDest = new Paragraph("Spettabile").SetFontSize(9).SetBold();
                            iText.Layout.Element.Cell cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaDest.Add(pGrigliaDest);
                            tbGriglaDest.AddCell(cellaGrigliaDest);

                            pGrigliaDest     = new Paragraph(cliente.RagioneSociale).SetFontSize(9);
                            cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaDest.Add(pGrigliaDest);
                            tbGriglaDest.AddCell(cellaGrigliaDest);

                            // INDIRIZZO DESTINATARIO
                            pGrigliaDest     = new Paragraph("Indirizzo").SetFontSize(9).SetBold();
                            cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaDest.Add(pGrigliaDest);
                            tbGriglaDest.AddCell(cellaGrigliaDest);

                            //pGrigliaDest = new Paragraph(cliente.TipoIndirizzoOperativo + " " + cliente.IndirizzoOperativo + " " + cliente.NumeroCivicoOperativo + Environment.NewLine + cliente.CapOperativo + " " + cliente.ComuneOperativo + " " + cliente.ProvinciaOperativo).SetFontSize(9);
                            //cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            //cellaGrigliaDest.Add(pGrigliaDest);
                            //tbGriglaDest.AddCell(cellaGrigliaDest);

                            pGrigliaDest     = new Paragraph(cliente.TipoIndirizzoLegale + " " + cliente.IndirizzoLegale + " " + cliente.NumeroCivicoLegale + Environment.NewLine + cliente.CapLegale + " " + cliente.ComuneLegale + " " + cliente.ProvinciaLegale).SetFontSize(9);
                            cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaDest.Add(pGrigliaDest);
                            tbGriglaDest.AddCell(cellaGrigliaDest);

                            // PARTITA IVA DESTINATARIO
                            pGrigliaDest     = new Paragraph("P.Iva/C.F.").SetFontSize(9).SetBold();
                            cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaDest.Add(pGrigliaDest);
                            tbGriglaDest.AddCell(cellaGrigliaDest);

                            string pIvaCF = cliente.PartitaIva;
                            if (string.IsNullOrEmpty(pIvaCF))
                            {
                                pIvaCF = cliente.CodiceFiscale;
                            }

                            pGrigliaDest     = new Paragraph(pIvaCF).SetFontSize(9);
                            cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                            cellaGrigliaDest.Add(pGrigliaDest);
                            tbGriglaDest.AddCell(cellaGrigliaDest);

                            document.Add(tbGriglaDest);


                            //document.Add(pSpazio);
                            //document.Add(pSpazio);

                            // CREAZIONE INTESTAZIONE GRIGLIA
                            //iText.Layout.Element.Table tbGriglaInt = new iText.Layout.Element.Table(new float[] { 80, 50, 200, 80, 20, 20, 80 }).SetWidth(530).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetFixedPosition(i, 30, 595, 530); ;



                            //document.Add(tbGriglaInt);


                            // AGGIUNGO LOGO DNV
                            iText.Layout.Element.Image logoDnv = new iText.Layout.Element.Image(imageDNV).ScaleAbsolute(40, 40).SetFixedPosition(i, 518, 8);
                            document.Add(logoDnv);

                            //AGGIUNGO NUM.PAGINA
                            document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7),
                                                     pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);
                            //AGGIUNGO FOOTER
                            document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                                                     pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);

                            if (i == n)
                            {
                                // NELL'ULTIMA PAGINA AGGIUNGO LA GRIGLIA CON LE NOTE E IL TIMBRO
                                // CREAZIONE GRIGLIA
                                iText.Layout.Element.Table tbGriglaNoteFooter = new iText.Layout.Element.Table(new float[] { 80, 70, 180, 70, 30, 30, 70 }).SetWidth(530).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.LIGHT_GRAY, 10).SetFixedPosition(30, 50, 530).SetFixedLayout();

                                // PRIMA RIGA GRIGLIA NOTE FOOTER
                                Paragraph pGrigliaNoteFooter = new Paragraph("Banca").SetFontSize(9);
                                iText.Layout.Element.Cell cellaGrigliaNoteFooter = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                pGrigliaNoteFooter = new Paragraph(noteOfferta.Banca).SetFontSize(9);
                                //cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1,2).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.LIGHT_GRAY, 10).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(2);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 2, 50)).SetBorderTop(iText.Layout.Borders.Border.NO_BORDER).SetBorderLeft(iText.Layout.Borders.Border.NO_BORDER).SetBorderBottom(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);

                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                pGrigliaNoteFooter     = new Paragraph("Timbro e firma per accettazione").SetFontSize(9);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                // SECONDA RIGA GRIGLIA NOTE FOOTER
                                pGrigliaNoteFooter     = new Paragraph("Pagamento").SetFontSize(9);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                pGrigliaNoteFooter     = new Paragraph(noteOfferta.NotaPagamento).SetFontSize(9);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 2, 50)).SetBorderTop(iText.Layout.Borders.Border.NO_BORDER).SetBorderLeft(iText.Layout.Borders.Border.NO_BORDER).SetBorderBottom(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                pGrigliaNoteFooter     = new Paragraph(" ").SetFontSize(9);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                // TERZA RIGA GRIGLIA NOTE FOOTER
                                pGrigliaNoteFooter     = new Paragraph("Consegna").SetFontSize(9);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                pGrigliaNoteFooter     = new Paragraph(noteOfferta.Consegna.Replace("\r\n", " ")).SetFontSize(9);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 2, 50)).SetBorderTop(iText.Layout.Borders.Border.NO_BORDER).SetBorderLeft(iText.Layout.Borders.Border.NO_BORDER).SetBorderBottom(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                pGrigliaNoteFooter     = new Paragraph(" ").SetFontSize(9);
                                cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5);
                                cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter);
                                tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter);

                                document.Add(tbGriglaNoteFooter);
                            }
                        }

                        document.Close();
                        wr.Close();

                        if (File.Exists(mapPathFattura))
                        {
                            // SE FILE OK INSERISCO O AGGIORNO PROTOCOLLO DI FATTURA
                            if (listaProtocolli.Count == 0)
                            {
                                //INSERISCO
                                protocolloFattura.Attivo                  = true;
                                protocolloFattura.Cliente                 = cliente.RagioneSociale.Trim();
                                protocolloFattura.Codice_lavoro           = eventoSelezionato.codice_lavoro;
                                protocolloFattura.Data_inizio_lavorazione = eventoSelezionato.data_inizio_impegno;
                                //protocolloFattura.Data_protocollo = DateTime.Today;
                                protocolloFattura.Data_protocollo        = Convert.ToDateTime(tbDataProtocollo.Text);
                                protocolloFattura.Descrizione            = "Fattura";
                                protocolloFattura.Id_cliente             = eventoSelezionato.id_cliente;
                                protocolloFattura.Id_tipo_protocollo     = idTipoProtocollo;
                                protocolloFattura.Lavorazione            = eventoSelezionato.lavorazione;
                                protocolloFattura.PathDocumento          = Path.GetFileName(mapPathFattura);
                                protocolloFattura.Produzione             = eventoSelezionato.produzione;
                                protocolloFattura.Protocollo_riferimento = numeroFattura;
                                protocolloFattura.Numero_protocollo      = numeroProtocollo;
                                protocolloFattura.Pregresso    = false;
                                protocolloFattura.Destinatario = "Cliente";

                                int idProtPianoEsterno = Protocolli_BLL.Instance.CreaProtocollo(protocolloFattura, ref esito);

                                ViewState["idProtocollo"] = idProtPianoEsterno;
                            }
                            else
                            {
                                // AGGIORNO
                                protocolloFattura.PathDocumento   = Path.GetFileName(mapPathFattura);
                                protocolloFattura.Data_protocollo = Convert.ToDateTime(tbDataProtocollo.Text);
                                esito = Protocolli_BLL.Instance.AggiornaProtocollo(protocolloFattura);

                                ViewState["idProtocollo"] = protocolloFattura.Id;
                            }

                            ViewState["importo"]         = totPrezzo;
                            ViewState["iva"]             = listaArticoliLavorazione[0].Iva;// totIVA;
                            ViewState["importoIva"]      = totPrezzo + totIVA;
                            ViewState["banca"]           = noteOfferta.Banca;
                            ViewState["numeroDocumento"] = eventoSelezionato.codice_lavoro;

                            framePdfFattura.Attributes.Remove("src");
                            framePdfFattura.Attributes.Add("src", pathFattura.Replace("~", ""));

                            DivFramePdfFattura.Visible = true;
                            framePdfFattura.Visible    = true;

                            ScriptManager.RegisterStartupScript(Page, typeof(Page), "aggiornaFrame", script: "javascript: document.getElementById('" + framePdfFattura.ClientID + "').contentDocument.location.reload(true);", addScriptTags: true);
                            btnStampaFattura.Attributes.Add("onclick", "window.open('" + pathFattura.Replace("~", "") + "');");
                            //}
                        }
                        else
                        {
                            esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                            esito.Descrizione = "Il File " + pathFattura.Replace("~", "") + " non è stato creato correttamente!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                esito.Descrizione = "popolaPannelloFattura(DatiAgenda eventoSelezionato) " + ex.Message + Environment.NewLine + ex.StackTrace;
            }

            return(esito);
        }
Exemplo n.º 5
0
        public Esito PopolaPannelloNotaSpese(DatiAgenda eventoSelezionato, FiguraProfessionale figuraProfessionaleSelezionata)
        {
            Esito esito = new Esito();

            try
            {
                if (eventoSelezionato != null && eventoSelezionato.LavorazioneCorrente != null)
                {
                    #region LEGGO I PARAMETRI DI VS
                    Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA");
                    string pIvaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE");
                    string denominazioneVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO");
                    string toponimoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO");
                    string indirizzoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO");
                    string civicoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP");
                    string capVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA");
                    string cittaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA");
                    string provinciaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL");
                    string emailVs = cfAppo.valore;
                    #endregion

                    List <DatiPianoEsternoLavorazione> listaDatiPianoEsternoLavorazione = eventoSelezionato.LavorazioneCorrente.ListaDatiPianoEsternoLavorazione;
                    if (listaDatiPianoEsternoLavorazione != null)
                    {
                        string nomeFile         = "NotaSpese.pdf";
                        string pathNotaSpese    = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile;
                        string mapPathNotaSpese = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile;

                        //string prefissoUrl = Request.Url.Scheme + "://" + Request.Url.Authority;
                        iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png"));

                        PdfWriter wr = new PdfWriter(mapPathNotaSpese);

                        PdfDocument doc = new PdfDocument(wr);
                        doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate());
                        Document document = new Document(doc);

                        document.SetMargins(50, 30, 50, 30);

                        // COLORE BLU VIDEOSYSTEM
                        iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243);

                        Paragraph pIntestazioneNotaSpese = new Paragraph("Nota Spese di: " + figuraProfessionaleSelezionata.Nome + " " + figuraProfessionaleSelezionata.Cognome);
                        pIntestazioneNotaSpese.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        pIntestazioneNotaSpese.SetFontSize(20);
                        pIntestazioneNotaSpese.SetBold();
                        document.Add(pIntestazioneNotaSpese);

                        // AGGIUNGO TABLE PER LAYOUT INTESTAZIONE
                        iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(new float[] { 1, 9 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        iText.Layout.Element.Image image          = new iText.Layout.Element.Image(imageData).ScaleAbsolute(90, 80).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
                        Cell cellaImmagine = new Cell().SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.MIDDLE).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
                        cellaImmagine.Add(image);
                        tbIntestazione.AddCell(cellaImmagine);

                        iText.Layout.Element.Table tbIntestazioneDx = new iText.Layout.Element.Table(new float[] { 2, 3, 2, 3 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        Anag_Clienti_Fornitori cliente = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(eventoSelezionato.id_cliente, ref esito);

                        Paragraph pTitolo = new Paragraph("Cliente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        Paragraph pValore = new Paragraph(cliente.RagioneSociale.Trim()).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pTitolo = new Paragraph("Referente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        string nomeReferente = "";
                        if (eventoSelezionato.LavorazioneCorrente.IdReferente != null)
                        {
                            Anag_Referente_Clienti_Fornitori referente = Anag_Referente_Clienti_Fornitori_BLL.Instance.getReferenteById(ref esito, Convert.ToInt32(eventoSelezionato.LavorazioneCorrente.IdReferente.Value));
                            nomeReferente = referente.Nome + " " + referente.Cognome;
                        }
                        pValore = new Paragraph(nomeReferente).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Produzione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pValore = new Paragraph(eventoSelezionato.produzione).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pTitolo = new Paragraph("Capotecnico").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        string nomeCapotecnico = "";
                        if (eventoSelezionato.LavorazioneCorrente.IdCapoTecnico != null)
                        {
                            Anag_Collaboratori coll = Anag_Collaboratori_BLL.Instance.getCollaboratoreById(eventoSelezionato.LavorazioneCorrente.IdCapoTecnico.Value, ref esito);
                            nomeCapotecnico = coll.Nome + " " + coll.Cognome;
                        }
                        pValore = new Paragraph(nomeCapotecnico).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Lavorazione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.lavorazione).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Data Inizio").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_impegno.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Luogo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.luogo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Data Lavoraz.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_lavorazione.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Indirizzo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.indirizzo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Cod.Lavor.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.codice_lavoro).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        tbIntestazione.AddCell(tbIntestazioneDx).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        document.Add(tbIntestazione);

                        Paragraph pSpazio = new Paragraph(" ");
                        document.Add(pSpazio);

                        Paragraph pLuogoData = new Paragraph(cittaVs + ", " + DateTime.Today.ToLongDateString());
                        pLuogoData.SetFontSize(8);
                        document.Add(pLuogoData);

                        document.Add(pSpazio);

                        // INTESTAZIONE GRIGLIA
                        iText.Layout.Element.Table table = new iText.Layout.Element.Table(new float[] { 90, 70, 70, 70, 70, 70, 70, 70, 200 }).SetWidth(780);

                        Border bordoDoppio = new DoubleBorder(1);

                        Cell cella = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        table.AddHeaderCell(cella);

                        Paragraph intestazioneMain = new Paragraph("Tipologia di pagamento").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        cella = new Cell(1, 3).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        cella.SetBorderLeft(bordoDoppio);
                        cella.Add(intestazioneMain);
                        table.AddHeaderCell(cella);

                        intestazioneMain = new Paragraph("Costi in Euro").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        cella            = new Cell(1, 5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        cella.SetBorderLeft(bordoDoppio);
                        cella.Add(intestazioneMain);
                        table.AddHeaderCell(cella);

                        Paragraph intestazione = new Paragraph("Data").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Sofid").SetFontSize(10).SetBold().SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        cella        = new Cell().SetBorderLeft(bordoDoppio);
                        cella.Add(intestazione);
                        table.AddHeaderCell(cella).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Carta").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Contanti").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Carburante").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        cella        = new Cell().SetBorderLeft(bordoDoppio);
                        cella.Add(intestazione);
                        table.AddHeaderCell(cella).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Albergo").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Trasporti").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Pasti").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        intestazione = new Paragraph("Varie").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);

                        // CELLE VUOTE
                        for (int i = 0; i < 12; i++)
                        {
                            table.AddCell(new Cell().SetHeight(15));

                            cella = new Cell().SetBorderLeft(bordoDoppio);
                            table.AddCell(cella);

                            table.AddCell(" ");
                            table.AddCell(" ");

                            cella = new Cell().SetBorderLeft(bordoDoppio);
                            table.AddCell(cella);

                            table.AddCell(" ");
                            table.AddCell(" ");
                            table.AddCell(" ");
                            table.AddCell(" ");
                        }
                        document.Add(table);

                        Paragraph pFirma = new Paragraph("in fede");
                        pFirma.SetFontSize(9);
                        pFirma.SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                        pFirma.SetMarginRight(90);
                        pFirma.SetMarginTop(13);
                        document.Add(pFirma);


                        iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(1).GetPageSize();
                        int n = doc.GetNumberOfPages();


                        // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA
                        for (int i = 1; i <= n; i++)
                        {
                            //AGGIUNGO NUM.PAGINA
                            document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7),
                                                     pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);
                            //AGGIUNGO FOOTER
                            document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                                                     pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);
                        }

                        //document.Flush();
                        document.Close();
                        wr.Close();

                        framePdfNotaSpese.Attributes.Remove("src");
                        framePdfNotaSpese.Attributes.Add("src", pathNotaSpese.Replace("~", ""));

                        DivFramePdfNotaSpese.Visible = true;
                        framePdfNotaSpese.Visible    = true;

                        ScriptManager.RegisterStartupScript(Page, typeof(Page), "aggiornaFrame", script: "javascript: document.getElementById('" + framePdfNotaSpese.ClientID + "').contentDocument.location.reload(true);", addScriptTags: true);
                        btnStampaNotaSpese.Attributes.Add("onclick", "window.open('" + pathNotaSpese.Replace("~", "") + "');");
                    }
                }
            }
            catch (Exception ex)
            {
                esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                esito.Descrizione = "PopolaPannelloNotaSpese(DatiAgenda eventoSelezionato, FiguraProfessionale figuraProfessionaleSelezionata) " + ex.Message + Environment.NewLine + ex.StackTrace;
            }

            return(esito);
        }
Exemplo n.º 6
0
        //Função que gera um PDF do orçamento
        private void printBudget()
        {
            if (this.cbb_clientName.SelectedIndex == -1 || Globals.numeroOrcamento == 0)
            {
                MessageBox.Show("Selecione um cliente e um orçamento para imprimi-lo.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                this.sfd_saveBudget.Filter = "Portable Document File (.pdf)|*.pdf";

                //Abrir a janela "Salvar arquivo"
                if (this.sfd_saveBudget.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        using (PdfWriter pdfWriter = new PdfWriter(sfd_saveBudget.FileName, new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)))
                        {
                            //Document
                            var pdfDocument = new PdfDocument(pdfWriter);
                            var document    = new Document(pdfDocument, PageSize.A4);

                            //Font
                            string avengeance = Globals.path + @"\assets\fonts\avengeance.ttf";

                            //Image
                            string logo = Globals.path + @"\assets\img\icon\logo.jpg";
                            iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(logo);
                            Image image = new Image(imageData);
                            image.SetWidth(150).SetHeight(150);

                            PdfFont pdfFontBody = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.COURIER);
                            PdfFontFactory.EmbeddingStrategy embeddingStrategy = new PdfFontFactory.EmbeddingStrategy();
                            PdfFont pdfFontCompanyName = PdfFontFactory.CreateFont(avengeance, embeddingStrategy); //PdfFontFactory.CreateFont(avengeance, true);
                            PdfFont pdfFontTitle       = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.TIMES_ROMAN);

                            //Color
                            DeviceRgb deviceRgbTitle = new DeviceRgb(190, 255, 255);

                            //Styles
                            Style companyStyle = new Style();
                            companyStyle.SetBorder(Border.NO_BORDER).SetFont(pdfFontCompanyName).SetFontSize(48).SetPaddingBottom(-20).SetTextAlignment(TextAlignment.CENTER);

                            Style titleStyle = new Style();
                            titleStyle.SetBorder(Border.NO_BORDER).SetFont(pdfFontTitle).SetFontSize(10).SetTextAlignment(TextAlignment.CENTER);

                            Style bodyStyle = new Style();
                            bodyStyle.SetBorder(Border.NO_BORDER).SetFont(pdfFontBody).SetFontSize(10).SetTextAlignment(TextAlignment.CENTER);

                            //Table 1
                            float[] columnWidth = new float[] { 140, 140, 140, 140, 140, 140, 140, 140 };

                            Table headerTable = new Table(columnWidth);

                            //Row 1
                            headerTable.AddCell(new Cell(6, 4).Add(image).SetBorder(Border.NO_BORDER).SetPaddingLeft(60).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER));
                            headerTable.AddCell(new Cell(1, 4).Add(new Paragraph("Sisteg")).AddStyle(companyStyle));

                            //Row 2
                            headerTable.AddCell(new Cell(1, 4).Add(new Paragraph("SEGURANÇA ELETRÔNICA")).AddStyle(titleStyle));

                            //Row 3
                            headerTable.AddCell(new Cell(1, 4).Add(new Paragraph("Rua professora Angelina de Felice Mesanelli, 152")).AddStyle(bodyStyle));

                            //Row 4
                            headerTable.AddCell(new Cell(1, 4).Add(new Paragraph("Jd. Victório Lucato - Limeira - SP")).AddStyle(bodyStyle));

                            //Row 5
                            headerTable.AddCell(new Cell(1, 2).Add(new Paragraph("Telefone:")).AddStyle(titleStyle));
                            headerTable.AddCell(new Cell(1, 2).Add(new Paragraph("(19) 98881-1660")).AddStyle(bodyStyle));

                            //Row 6
                            headerTable.AddCell(new Cell(1, 2).Add(new Paragraph("CNPJ:")).AddStyle(titleStyle));
                            headerTable.AddCell(new Cell(1, 2).Add(new Paragraph("23.524.384/0001-47")).AddStyle(bodyStyle));

                            DataTable budgetDataTable = Database.query("SELECT * FROM orcamento WHERE numeroOrcamento = " + Globals.numeroOrcamento);

                            //Table 2
                            float[] clientColumnWidth = new float[] { 160, 140, 140, 140, 140, 140, 140, 120 };

                            Table clientTable = new Table(clientColumnWidth);

                            //Row 7
                            if (this.ckb_technicalReport.Checked)
                            {
                                headerTable.AddCell(new Cell(1, 8).Add(new Paragraph("LAUDO TÉCNICO:")).AddStyle(titleStyle).SetFontSize(12));
                            }
                            else
                            {
                                clientTable.SetMarginTop(20);
                            }

                            document.Add(headerTable);

                            //Row 1
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph("PEDIDO:")).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph(budgetDataTable.Rows[0].ItemArray[0].ToString())).AddStyle(bodyStyle).SetBackgroundColor(deviceRgbTitle).SetTextAlignment(TextAlignment.LEFT));
                            clientTable.AddCell(new Cell(1, 4).Add(new Paragraph()).SetBorder(Border.NO_BORDER).SetBackgroundColor(deviceRgbTitle));
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph("DATA:")).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph(Convert.ToDateTime(budgetDataTable.Rows[0].ItemArray[2]).ToShortDateString().Trim())).AddStyle(bodyStyle).SetBackgroundColor(deviceRgbTitle).SetTextAlignment(TextAlignment.LEFT));

                            //Row 2
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph("Nome:")).AddStyle(titleStyle));
                            clientTable.AddCell(new Cell(1, 7).Add(new Paragraph(Globals.clientStepDataTable.Rows[0].ItemArray[1].ToString().Trim())).AddStyle(bodyStyle).SetTextAlignment(TextAlignment.LEFT));

                            //Row 3
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph("Endereço:")).AddStyle(titleStyle));
                            clientTable.AddCell(new Cell(1, 7).Add(new Paragraph(Globals.clientStepDataTable.Rows[0].ItemArray[2].ToString().Trim() + ", " + Globals.clientStepDataTable.Rows[0].ItemArray[3].ToString())).AddStyle(bodyStyle).SetTextAlignment(TextAlignment.LEFT));

                            //Row 4
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph("Cidade:")).AddStyle(titleStyle));
                            clientTable.AddCell(new Cell(1, 5).Add(new Paragraph(Globals.clientStepDataTable.Rows[0].ItemArray[4].ToString().Trim())).AddStyle(bodyStyle).SetTextAlignment(TextAlignment.LEFT));
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph("Estado:")).AddStyle(titleStyle));
                            clientTable.AddCell(new Cell(1, 1).Add(new Paragraph(Globals.clientStepDataTable.Rows[0].ItemArray[5].ToString().Trim())).AddStyle(bodyStyle).SetTextAlignment(TextAlignment.LEFT));

                            DataTable telephoneDataTable = Database.query("SELECT * FROM telefone WHERE idCliente = " + Globals.clientStepDataTable.Rows[0].ItemArray[0] + " ORDER BY tipoTelefone ASC;");
                            this.listTelephones(telephoneDataTable, clientTable, titleStyle, bodyStyle);

                            clientTable.SetBorder(new SolidBorder(deviceRgbTitle, 1));

                            document.Add(clientTable);

                            //Table 3
                            float[] budgetedProductColumnWidth = new float[] { 62, 112, 162, 112, 112 };

                            Table budgetedProductTable = new Table(budgetedProductColumnWidth);

                            DataTable productStepBudgetedProduct = Database.query("SELECT produtoOrcado.idProdutoOrcado, produtoOrcado.item AS 'Item:', produtoOrcado.quantidadeProduto AS 'Quantidade:', produto.nomeProduto AS 'Nome do produto:', produto.valorUnitario AS 'Valor unitário:', produtoOrcado.valorTotal AS 'Valor total:' FROM produtoOrcado JOIN produto ON produtoOrcado.idProduto = produto.idProduto WHERE produtoOrcado.numeroOrcamento = " + Globals.numeroOrcamento + " ORDER BY produtoOrcado.item;");

                            budgetedProductTable.SetMarginTop(20);

                            //Row 1
                            if (productStepBudgetedProduct.Rows.Count > 0)
                            {
                                budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph("Item:")).SetBorder(Border.NO_BORDER).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                                budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph("Quantidade:")).SetBorder(Border.NO_BORDER).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                                budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph("Nome do produto:")).SetBorder(Border.NO_BORDER).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                                budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph("Valor unitário:")).SetBorder(Border.NO_BORDER).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                                budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph("Valor total:")).SetBorder(Border.NO_BORDER).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                            }

                            int j = 0;
                            foreach (DataRow dataRow in productStepBudgetedProduct.Rows)
                            {
                                for (int i = 1; i < 6; i++)
                                {
                                    if (j == productStepBudgetedProduct.Rows.Count - 1)
                                    {
                                        if (i == 4 || i == 5)
                                        {
                                            budgetedProductTable.AddCell(new Cell().Add(new Paragraph(Convert.ToDecimal(dataRow.ItemArray[i]).ToString("C").Trim())).AddStyle(bodyStyle).SetBorderBottom(new SolidBorder(deviceRgbTitle, 1)));
                                        }
                                        else
                                        {
                                            budgetedProductTable.AddCell(new Cell().Add(new Paragraph(dataRow.ItemArray[i].ToString().Trim())).AddStyle(bodyStyle).SetBorderBottom(new SolidBorder(deviceRgbTitle, 1)));
                                        }
                                    }
                                    else
                                    {
                                        if (i == 4 || i == 5)
                                        {
                                            budgetedProductTable.AddCell(new Cell().Add(new Paragraph(Convert.ToDecimal(dataRow.ItemArray[i]).ToString("C").Trim())).AddStyle(bodyStyle));
                                        }
                                        else
                                        {
                                            budgetedProductTable.AddCell(new Cell().Add(new Paragraph(dataRow.ItemArray[i].ToString().Trim())).AddStyle(bodyStyle));
                                        }
                                    }
                                }
                                j++;
                            }

                            budgetedProductTable.AddCell(new Cell(1, 3).Add(new Paragraph()).SetBorder(Border.NO_BORDER).SetBackgroundColor(deviceRgbTitle));
                            budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph("Valor do trabalho:")).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                            budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph(Convert.ToDecimal(budgetDataTable.Rows[0].ItemArray[3]).ToString("C").Trim())).AddStyle(bodyStyle).SetBackgroundColor(deviceRgbTitle));

                            budgetedProductTable.AddCell(new Cell(1, 2).Add(new Paragraph("Condigação de pagamento:")).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                            budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph(budgetDataTable.Rows[0].ItemArray[5].ToString().Trim())).AddStyle(bodyStyle).SetBackgroundColor(deviceRgbTitle));
                            budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph("TOTAL R$:")).AddStyle(titleStyle).SetBackgroundColor(deviceRgbTitle));
                            budgetedProductTable.AddCell(new Cell(1, 1).Add(new Paragraph(Convert.ToDecimal(budgetDataTable.Rows[0].ItemArray[4]).ToString("C").Trim())).AddStyle(bodyStyle).SetBackgroundColor(deviceRgbTitle));

                            budgetedProductTable.SetBorder(new SolidBorder(deviceRgbTitle, 1));

                            document.Add(budgetedProductTable);

                            document.Close();

                            System.Diagnostics.Process.Start(this.sfd_saveBudget.FileName);
                        }
                    }catch (Exception exception)
                    {
                        MessageBox.Show("[ERRO] " + exception.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public Esito popolaPannelloPianoEsterno(DatiAgenda eventoSelezionato)
        {
            Esito esito = new Esito();

            try
            {
                if (eventoSelezionato != null && eventoSelezionato.LavorazioneCorrente != null)
                {
                    // LEGGO I PARAMETRI DI VS
                    Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA");
                    string pIvaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE");
                    string denominazioneVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO");
                    string toponimoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO");
                    string indirizzoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO");
                    string civicoVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP");
                    string capVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA");
                    string cittaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA");
                    string provinciaVs = cfAppo.valore;
                    cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL");
                    string emailVs = cfAppo.valore;

                    List <DatiPianoEsternoLavorazione> listaDatiPianoEsternoLavorazione = eventoSelezionato.LavorazioneCorrente.ListaDatiPianoEsternoLavorazione;
                    if (listaDatiPianoEsternoLavorazione != null)
                    {
                        Protocolli        protocolloPianoEsterno = new Protocolli();
                        int               idTipoProtocollo       = UtilityTipologiche.getElementByNome(UtilityTipologiche.caricaTipologica(EnumTipologiche.TIPO_PROTOCOLLO), "Piano Esterno", ref esito).id;
                        List <Protocolli> listaProtocolli        = Protocolli_BLL.Instance.getProtocolliByCodLavIdTipoProtocollo(eventoSelezionato.codice_lavoro, idTipoProtocollo, ref esito, true);
                        string            numeroProtocollo       = "";
                        if (listaProtocolli.Count == 0)
                        {
                            numeroProtocollo = Protocolli_BLL.Instance.getNumeroProtocollo();
                        }
                        else
                        {
                            protocolloPianoEsterno = listaProtocolli.First();
                            numeroProtocollo       = protocolloPianoEsterno.Numero_protocollo;
                        }

                        // GESTIONE NOMI FILE PDF
                        //string nomeFile = "PianoEsterno_" + eventoSelezionato.LavorazioneCorrente.Id.ToString() + ".pdf";
                        //string nomeFile = "PianoEsterno_" + numeroProtocollo + ".pdf";
                        string nomeFile            = "PianoEsterno_" + eventoSelezionato.codice_lavoro + ".pdf";
                        string pathPianoEsterno    = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile;
                        string mapPathPianoEsterno = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile;

                        //string prefissoUrl = Request.Url.Scheme + "://" + Request.Url.Authority;
                        iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png"));


                        PdfWriter   wr  = new PdfWriter(mapPathPianoEsterno);
                        PdfDocument doc = new PdfDocument(wr);
                        doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate());
                        //doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4);
                        //Document document = new Document(doc);
                        Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4.Rotate(), false);

                        //document.SetMargins(90, 30, 50, 30);
                        document.SetMargins(50, 30, 50, 30);

                        //iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(0, 225, 0);
                        // COLORE BLU VIDEOSYSTEM
                        iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243);

                        // AGGIUNGO TABLE PER LAYOUT INTESTAZIONE
                        iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(new float[] { 1, 9 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        //iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(3).UseAllAvailableWidth();
                        iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(90, 80).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
                        Cell cellaImmagine = new Cell().SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.MIDDLE).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
                        cellaImmagine.Add(image);
                        tbIntestazione.AddCell(cellaImmagine);

                        iText.Layout.Element.Table tbIntestazioneDx = new iText.Layout.Element.Table(new float[] { 2, 3, 2, 3 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        Anag_Clienti_Fornitori cliente = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(eventoSelezionato.id_cliente, ref esito);

                        Paragraph pTitolo = new Paragraph("Cliente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        Paragraph pValore = new Paragraph(cliente.RagioneSociale.Trim()).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pTitolo = new Paragraph("Referente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        string nomeReferente = "";
                        if (eventoSelezionato.LavorazioneCorrente.IdReferente != null)
                        {
                            Anag_Referente_Clienti_Fornitori referente = Anag_Referente_Clienti_Fornitori_BLL.Instance.getReferenteById(ref esito, Convert.ToInt32(eventoSelezionato.LavorazioneCorrente.IdReferente.Value));
                            nomeReferente = referente.Nome + " " + referente.Cognome;
                        }
                        pValore = new Paragraph(nomeReferente).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Produzione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pValore = new Paragraph(eventoSelezionato.produzione).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        pTitolo = new Paragraph("Capotecnico").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        string nomeCapotecnico = "";
                        if (eventoSelezionato.LavorazioneCorrente.IdCapoTecnico != null)
                        {
                            Anag_Collaboratori coll = Anag_Collaboratori_BLL.Instance.getCollaboratoreById(eventoSelezionato.LavorazioneCorrente.IdCapoTecnico.Value, ref esito);
                            nomeCapotecnico = coll.Nome + " " + coll.Cognome;
                        }
                        pValore = new Paragraph(nomeCapotecnico).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Lavorazione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.lavorazione).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Data Inizio").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_impegno.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Luogo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.luogo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Data Lavoraz.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_lavorazione.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Indirizzo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.indirizzo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        pTitolo = new Paragraph("Cod.Lavor.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(eventoSelezionato.codice_lavoro).SetBorder(iText.Layout.Borders.Border.NO_BORDER);


                        iText.Layout.Element.Cell cellaNote = new iText.Layout.Element.Cell(2, 4).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        string notePianoEsterno             = "";
                        if (eventoSelezionato.LavorazioneCorrente.NotePianoEsterno != null)
                        {
                            notePianoEsterno = eventoSelezionato.LavorazioneCorrente.NotePianoEsterno;
                        }
                        Paragraph pNotePiano = new Paragraph(notePianoEsterno.Trim()).SetFontSize(10).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        cellaNote.Add(pNotePiano).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER);
                        tbIntestazioneDx.AddCell(cellaNote).SetBorder(iText.Layout.Borders.Border.NO_BORDER);


                        tbIntestazione.AddCell(tbIntestazioneDx).SetBorder(iText.Layout.Borders.Border.NO_BORDER);

                        document.Add(tbIntestazione);

                        Paragraph pSpazio = new Paragraph(" ");
                        document.Add(pSpazio);

                        Paragraph pLuogoData = new Paragraph(cittaVs + ", " + DateTime.Today.ToLongDateString());
                        document.Add(pLuogoData);

                        document.Add(pSpazio);

                        // INTESTAZIONE GRIGLIA

                        iText.Layout.Element.Table table = new iText.Layout.Element.Table(10).UseAllAvailableWidth(); //.SetBorderTop(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.ORANGE, 5)).SetBorderBottom(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.YELLOW, 5)).SetBorderLeft(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.GREEN, 5)).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.RED, 5));
                        Paragraph intestazione           = new Paragraph("Data").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Personale").SetFontSize(10).SetBold().SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Qualifica").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Intervento").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Telefono").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Città").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Albergo").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Diaria").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Orario").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);
                        intestazione = new Paragraph("Note").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                        table.AddHeaderCell(intestazione);


                        string dataConfronto = "";
                        foreach (DatiPianoEsternoLavorazione dpe in listaDatiPianoEsternoLavorazione)
                        {
                            string collaboratoreFornitore = "";
                            string telefono  = "";
                            string qualifica = "";
                            string citta     = "";

                            string descrizioneArticoloAssociato = "";

                            if (dpe.IdCollaboratori != null)
                            {
                                Anag_Collaboratori coll = Anag_Collaboratori_BLL.Instance.getCollaboratoreById(dpe.IdCollaboratori.Value, ref esito);
                                collaboratoreFornitore = coll.Cognome.Trim() + " " + coll.Nome.Trim();

                                // prendo descrizione da datiArticoliLavorazione filtrando per data, idCollaboratore e idLavorazione
                                DatiArticoliLavorazione articoloAssociato = SessionManager.EventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.FirstOrDefault(x => x.IdCollaboratori == coll.Id && x.Data == dpe.Data);
                                if (articoloAssociato != null)
                                {
                                    descrizioneArticoloAssociato = articoloAssociato.Descrizione;
                                }

                                FiguraProfessionale fp = coll.CreaFiguraProfessionale(descrizioneArticoloAssociato);
                                //if (fp!=null && !string.IsNullOrEmpty(fp.ElencoQualifiche)) qualifica = fp.ElencoQualifiche;
                                if (fp != null && !string.IsNullOrEmpty(fp.DescrizioneArticoloAssociato))
                                {
                                    qualifica = fp.DescrizioneArticoloAssociato;
                                }



                                if (fp != null && !string.IsNullOrEmpty(fp.Telefono))
                                {
                                    telefono = fp.Telefono;
                                }
                                if (telefono.StartsWith("0039"))
                                {
                                    telefono = telefono.Substring(4);
                                }
                                if (telefono.StartsWith("+39"))
                                {
                                    telefono = telefono.Substring(3);
                                }

                                if (fp != null && !string.IsNullOrEmpty(fp.Citta))
                                {
                                    citta = fp.Citta;
                                }
                            }
                            else if (dpe.IdFornitori != null)
                            {
                                Anag_Clienti_Fornitori clienteFornitore = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(dpe.IdFornitori.Value, ref esito);
                                collaboratoreFornitore = clienteFornitore.RagioneSociale.Trim();

                                // prendo descrizione da datiArticoliLavorazione filtrando per data, idFornitore e idLavorazione
                                DatiArticoliLavorazione articoloAssociato = SessionManager.EventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.FirstOrDefault(x => x.IdFornitori == clienteFornitore.Id && x.Data == dpe.Data);
                                if (articoloAssociato != null)
                                {
                                    descrizioneArticoloAssociato = articoloAssociato.Descrizione;
                                }

                                FiguraProfessionale fp = clienteFornitore.CreaFiguraProfessionale(descrizioneArticoloAssociato);
                                //if (fp != null && !string.IsNullOrEmpty(fp.ElencoQualifiche)) qualifica = fp.ElencoQualifiche;
                                if (fp != null && !string.IsNullOrEmpty(fp.DescrizioneArticoloAssociato))
                                {
                                    qualifica = fp.DescrizioneArticoloAssociato;
                                }
                                if (fp != null && !string.IsNullOrEmpty(fp.Telefono))
                                {
                                    telefono = fp.Telefono;
                                }
                                if (fp != null && !string.IsNullOrEmpty(fp.Citta))
                                {
                                    citta = fp.Citta;
                                }
                            }



                            string importoDiaria = "0,00";
                            if (dpe.ImportoDiaria != null)
                            {
                                importoDiaria = dpe.ImportoDiaria.Value.ToString("###,###.00");
                            }

                            string nota = "";
                            if (!string.IsNullOrEmpty(dpe.Nota))
                            {
                                nota = dpe.Nota;
                            }

                            string dataPiano = "";
                            if (dpe.Data != null)
                            {
                                dataPiano = dpe.Data.Value.ToShortDateString();
                            }

                            // METTO SEPARATORE QUANDO CAMBIA DATA
                            if (string.IsNullOrEmpty(dataConfronto))
                            {
                                dataConfronto = dataPiano;
                            }
                            if (!string.IsNullOrEmpty(dataConfronto) && !dataConfronto.Equals(dataPiano))
                            {
                                dataConfronto = dataPiano;
                                Cell cellavuota = new Cell(2, 10).SetHeight(10f);
                                table.AddCell(cellavuota);
                            }


                            string orario = "";
                            if (dpe.Orario != null)
                            {
                                orario = dpe.Orario.Value.ToShortTimeString();
                            }

                            string intervento = "";
                            if (dpe.IdIntervento != null)
                            {
                                intervento = SessionManager.ListaTipiIntervento.FirstOrDefault(x => x.id == dpe.IdIntervento).nome;
                            }

                            string albergo = "no";
                            if (dpe.Albergo != null && dpe.Albergo == true)
                            {
                                albergo = "si";
                            }

                            //Paragraph p = new Paragraph(dpe.Data.Value.ToLongDateString() + " " + orario + " " + collaboratoreFornitore + " " + nota).SetFontSize(8);
                            //document.Add(p);
                            table.AddCell(dataPiano).SetFontSize(8).SetFontSize(10);
                            table.AddCell(collaboratoreFornitore);


                            table.AddCell(qualifica).SetFontSize(8);

                            table.AddCell(intervento).SetFontSize(8);

                            table.AddCell(telefono).SetFontSize(8);
                            table.AddCell(citta).SetFontSize(8);

                            table.AddCell(albergo).SetFontSize(8);
                            Paragraph pImportoDiaria = new Paragraph(importoDiaria).SetFontSize(8).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                            table.AddCell(pImportoDiaria);
                            table.AddCell(orario).SetFontSize(8);
                            table.AddCell(nota).SetFontSize(8);
                        }
                        document.Add(table);


                        //iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(1).GetPageSize();
                        int n = doc.GetNumberOfPages();
                        iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize();

                        // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA
                        for (int i = 1; i <= n; i++)
                        {
                            // AGGIUNGO LOGO
                            //iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(60, 60).SetFixedPosition(i, 20, pageSize.GetHeight() - 80);
                            //document.Add(image);
                            //AGGIUNGO NUM.PAGINA
                            document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7),
                                                     pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);
                            //AGGIUNGO FOOTER
                            document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                                                     pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);
                        }

                        document.Close();
                        wr.Close();

                        if (File.Exists(mapPathPianoEsterno))
                        {
                            // SE FILE OK INSERISCO O AGGIORNO PROTOCOLLO DI TIPO PIANO ESTERNO
                            if (listaProtocolli.Count == 0)
                            {
                                //INSERISCO
                                protocolloPianoEsterno.Attivo                  = true;
                                protocolloPianoEsterno.Cliente                 = cliente.RagioneSociale.Trim();
                                protocolloPianoEsterno.Codice_lavoro           = eventoSelezionato.codice_lavoro;
                                protocolloPianoEsterno.Data_inizio_lavorazione = eventoSelezionato.data_inizio_impegno;
                                protocolloPianoEsterno.Data_protocollo         = DateTime.Today;
                                protocolloPianoEsterno.Descrizione             = "Piano Esterno";
                                protocolloPianoEsterno.Id_cliente              = eventoSelezionato.id_cliente;
                                protocolloPianoEsterno.Id_tipo_protocollo      = idTipoProtocollo;
                                protocolloPianoEsterno.Lavorazione             = eventoSelezionato.lavorazione;
                                protocolloPianoEsterno.PathDocumento           = Path.GetFileName(mapPathPianoEsterno);
                                protocolloPianoEsterno.Produzione              = eventoSelezionato.produzione;
                                protocolloPianoEsterno.Protocollo_riferimento  = "";
                                protocolloPianoEsterno.Numero_protocollo       = numeroProtocollo;
                                protocolloPianoEsterno.Pregresso               = false;
                                protocolloPianoEsterno.Destinatario            = "Cliente";
                                int idProtPianoEsterno = Protocolli_BLL.Instance.CreaProtocollo(protocolloPianoEsterno, ref esito);
                            }
                            else
                            {
                                // AGGIORNO
                                protocolloPianoEsterno.PathDocumento = Path.GetFileName(mapPathPianoEsterno);
                                esito = Protocolli_BLL.Instance.AggiornaProtocollo(protocolloPianoEsterno);
                            }

                            //string nomeFileToDisplay = BaseStampa.Instance.AddPageNumber(mapPathPdfSenzaNumeroPagina, mapPianoEsterno, ref esito);
                            //if (File.Exists(mapPathPdfSenzaNumeroPagina)) File.Delete(mapPathPdfSenzaNumeroPagina);
                            //if (esito.codice == Esito.ESITO_OK) {
                            framePdfPianoEsterno.Attributes.Remove("src");
                            framePdfPianoEsterno.Attributes.Add("src", pathPianoEsterno.Replace("~", ""));

                            DivFramePdfPianoEsterno.Visible = true;
                            framePdfPianoEsterno.Visible    = true;

                            ScriptManager.RegisterStartupScript(Page, typeof(Page), "aggiornaFrame", script: "javascript: document.getElementById('" + framePdfPianoEsterno.ClientID + "').contentDocument.location.reload(true);", addScriptTags: true);
                            btnStampaPianoEsterno.Attributes.Add("onclick", "window.open('" + pathPianoEsterno.Replace("~", "") + "');");
                            //}
                        }
                        else
                        {
                            esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                            esito.Descrizione = "Il File " + pathPianoEsterno.Replace("~", "") + " non è stato creato correttamente!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                esito.Descrizione = "popolaPannelloPianoEsterno(DatiAgenda eventoSelezionato) " + ex.Message + Environment.NewLine + ex.StackTrace;
            }

            return(esito);
        }
Exemplo n.º 8
0
        public Esito popolaPannelloGiornata()
        {
            Esito esito = new Esito();

            try
            {
                // LEGGO I PARAMETRI DI VS
                Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA");
                string pIvaVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE");
                string denominazioneVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO");
                string toponimoVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO");
                string indirizzoVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO");
                string civicoVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP");
                string capVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA");
                string cittaVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA");
                string provinciaVs = cfAppo.valore;
                cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL");
                string emailVs = cfAppo.valore;

                // GESTIONE NOMI FILE PDF
                string nomeFile        = "RiepilogoGiornata.pdf";
                string pathGiornata    = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile;
                string mapPathGiornata = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile;

                iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png"));
                iText.IO.Image.ImageData imageDNV  = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/DNV_2008_ITA2.jpg"));


                PdfWriter   wr  = new PdfWriter(mapPathGiornata);
                PdfDocument doc = new PdfDocument(wr);
                doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate());
                //Document document = new Document(doc);
                Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4.Rotate(), false);

                // IMPOSTO LA DATA DI OGGI SE PRIMA ELABORAZIONE
                if (string.IsNullOrEmpty(tbDataElaborazione.Text.Trim()))
                {
                    tbDataElaborazione.Text = DateTime.Today.ToShortDateString();
                }

                document.SetMargins(90, 35, 50, 35);

                Paragraph pSpazio = new Paragraph("");
                document.Add(pSpazio);

                // COLORE BLU VIDEOSYSTEM
                iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243);


                DateTime dataTmp  = Convert.ToDateTime(tbDataElaborazione.Text.Trim());
                string   sDataTmp = dataTmp.ToString("yyyy-MM-dd") + "T00:00:00.000";

                string queryRicerca = "select dal.descrizione as qualifica,ac.cognome as cognome_operatore, ac.nome as nome_operatore, da.codice_lavoro,produzione,lavorazione " +
                                      //", da.durata_lavorazione as Durata , ca.nome,ts.nome,tt.nome " +
                                      //", ac.cognome as cognome_operatore,ac.nome as nome_operatore, dal.descrizioneLunga " +
                                      "from[dbo].[tab_dati_agenda] da " +
                                      "left join tipo_colonne_agenda ca " +
                                      "on da.id_colonne_agenda = ca.id " +
                                      "left join tipo_stato ts " +
                                      "on da.id_stato = ts.id " +
                                      "left join tipo_tipologie tt " +
                                      "on da.id_tipologia = tt.id " +
                                      "left join dati_lavorazione dl " +
                                      "on dl.idDatiAgenda = da.id " +
                                      "left join dati_articoli_lavorazione dal " +
                                      "on dl.id = dal.idDatiLavorazione " +
                                      "left join anag_collaboratori ac " +
                                      "on dal.idCollaboratori = ac.id " +
                                      "where ac.cognome is not null and dal.descrizione<> 'Diaria' " +
                                      "and data_inizio_lavorazione <= '@dataElaborazione' and data_fine_lavorazione >= '@dataElaborazione' " +
                                      //"order by codice_lavoro, dal.descrizione, ac.cognome, ac.nome";
                                      "group by dal.descrizione ,ac.cognome, ac.nome, da.codice_lavoro,produzione,lavorazione " +
                                      //"order by qualifica,ac.cognome, ac.nome, codice_lavoro";
                                      "order by codice_lavoro,qualifica,ac.cognome, ac.nome";
                queryRicerca = queryRicerca.Replace("@dataElaborazione", sDataTmp);

                esito = new Esito();
                DataTable dtProtocolli = Base_DAL.GetDatiBySql(queryRicerca, ref esito);
                if (dtProtocolli != null && dtProtocolli.Rows != null && dtProtocolli.Rows.Count > 0)
                {
                    // INTESTAZIONE GRIGLIA
                    iText.Layout.Element.Table table = new iText.Layout.Element.Table(3).UseAllAvailableWidth();
                    //Paragraph intestazione = new Paragraph("Codice Lavoro").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                    //table.AddHeaderCell(intestazione);

                    //intestazione = new Paragraph("Produzione").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                    //table.AddHeaderCell(intestazione);
                    //intestazione = new Paragraph("Lavorazione").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                    //table.AddHeaderCell(intestazione);
                    Paragraph intestazione = new Paragraph("Qualifica").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                    table.AddHeaderCell(intestazione);
                    intestazione = new Paragraph("Cognome").SetFontSize(10).SetBold().SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);
                    table.AddHeaderCell(intestazione);
                    intestazione = new Paragraph("Nome").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f);

                    table.AddHeaderCell(intestazione);


                    string codice_lavoro = "";
                    foreach (DataRow riga in dtProtocolli.Rows)
                    {
                        string qualifica = "";
                        string cognome   = "";
                        string nome      = "";

                        string produzione  = "";
                        string lavorazione = "";


                        //Cell cellaQualifica = new Cell();
                        //if (!riga["qualifica"].ToString().ToUpper().Equals(qualifica.ToUpper()))
                        //{
                        //    Paragraph pQualifica = new Paragraph(riga["qualifica"].ToString()).SetFontSize(8).SetBold();
                        //    cellaQualifica.Add(pQualifica);
                        //    qualifica = riga["qualifica"].ToString();
                        //}
                        //else
                        //{
                        //    Paragraph pQualifica = new Paragraph("").SetFontSize(8).SetBold();
                        //    cellaQualifica.Add(pQualifica);
                        //}
                        //table.AddCell(cellaQualifica);

                        Cell cellaLavorazione = new Cell(1, 3);
                        if (!riga["codice_lavoro"].ToString().ToUpper().Equals(codice_lavoro.ToUpper()))
                        {
                            if (riga["produzione"] != null)
                            {
                                produzione = riga["produzione"].ToString();
                            }
                            if (riga["lavorazione"] != null)
                            {
                                lavorazione = riga["lavorazione"].ToString();
                            }
                            Paragraph pCodiceLavoro = new Paragraph(riga["codice_lavoro"].ToString() + " - Produzione: " + produzione + " - Lavorazione: " + lavorazione).SetFontSize(10).SetBold();
                            cellaLavorazione.Add(pCodiceLavoro).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                            codice_lavoro = riga["codice_lavoro"].ToString();
                            table.AddCell(cellaLavorazione);
                        }
                        //else
                        //{
                        //    Paragraph pCodiceLavoro = new Paragraph("").SetFontSize(8).SetBold();
                        //    cellaLavorazione.Add(pCodiceLavoro);
                        //}
                        //table.AddCell(cellaLavorazione);

                        if (riga["qualifica"] != null)
                        {
                            qualifica = riga["qualifica"].ToString();
                        }
                        if (riga["cognome_operatore"] != null)
                        {
                            cognome = riga["cognome_operatore"].ToString();
                        }
                        if (riga["nome_operatore"] != null)
                        {
                            nome = riga["nome_operatore"].ToString();
                        }



                        //table.AddCell(produzione).SetFontSize(8);
                        //table.AddCell(lavorazione).SetFontSize(8);
                        Cell      cellaQualifica = new Cell();
                        Paragraph pQualifica     = new Paragraph(qualifica).SetFontSize(9).SetBold();
                        cellaQualifica.Add(pQualifica).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
                        table.AddCell(cellaQualifica);


                        table.AddCell(cognome).SetFontSize(9);
                        table.AddCell(nome).SetFontSize(9);
                    }
                    document.Add(table);
                }

                int n = doc.GetNumberOfPages();
                iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize();

                // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA
                for (int i = 1; i <= n; i++)
                {
                    // AGGIUNGO LOGO
                    iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(60, 60).SetFixedPosition(i, 20, pageSize.GetHeight() - 80);
                    document.Add(image);

                    // AGGIUNGO LOGO DNV
                    iText.Layout.Element.Image logoDnv = new iText.Layout.Element.Image(imageDNV).ScaleAbsolute(40, 40).SetFixedPosition(i, 780, 8);
                    document.Add(logoDnv);

                    //AGGIUNGO NUM.PAGINA
                    document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);

                    // AGGIUNGO TITOLO
                    document.ShowTextAligned(new Paragraph("OPERATORI IMPEGNATI PER IL " + tbDataElaborazione.Text.Trim()).SetFontSize(11), 400, pageSize.GetHeight() - 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);

                    //AGGIUNGO FOOTER
                    document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                                             pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0);

                    if (i == n)
                    {
                        // ULTIMA PAGINA
                    }
                }

                document.Close();
                wr.Close();

                if (File.Exists(mapPathGiornata))
                {
                    framePdfGiornata.Attributes.Remove("src");
                    framePdfGiornata.Attributes.Add("src", pathGiornata.Replace("~", ""));

                    DivFramePdfGiornata.Visible = true;
                    framePdfGiornata.Visible    = true;

                    ScriptManager.RegisterStartupScript(Page, typeof(Page), "aggiornaFrame", script: "javascript: document.getElementById('" + framePdfGiornata.ClientID + "').contentDocument.location.reload(true);", addScriptTags: true);
                    btnStampaGiornata.Attributes.Add("onclick", "window.open('" + pathGiornata.Replace("~", "") + "');");
                    //}
                }
                else
                {
                    esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                    esito.Descrizione = "Il File " + pathGiornata.Replace("~", "") + " non è stato creato correttamente!";
                }
            }
            catch (Exception ex)
            {
                esito.Codice      = Esito.ESITO_KO_ERRORE_GENERICO;
                esito.Descrizione = "popolaPannelloGiornata() " + ex.Message + Environment.NewLine + ex.StackTrace;
            }

            return(esito);
        }