Example #1
0
        //Stampa PDF

        public void ExportToPdfPerContoFinCli(List <MaterialiCantieri> matCantList)
        {
            decimal           totale     = 0m;
            int               idCantiere = Convert.ToInt32(ddlScegliCant.SelectedValue);
            Cantieri          cant       = CantieriDAO.GetSingle(idCantiere);
            MaterialiCantieri mc         = new MaterialiCantieri
            {
                RagSocCli     = cant.RagSocCli,
                CodCant       = cant.CodCant,
                DescriCodCant = cant.DescriCodCant
            };

            //Apro lo stream verso il file PDF
            Document pdfDoc = new Document(PageSize.A4, 8f, 2f, 2f, 2f);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();

            PdfPTable table = RicalcoloContiManager.InitializePdfTableDDT();

            Phrase title = new Phrase($"Ragione Sociale Cliente: {mc.RagSocCli}", FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.BLACK));

            pdfDoc.Add(title);

            RicalcoloContiManager.GeneraPDFPerContoFinCli(pdfDoc, mc, table, matCantList, totale, idCantiere, ddlScegliTipoNote.SelectedValue);

            pdfDoc.Close();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=" + mc.RagSocCli + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(pdfDoc);
            Response.End();
        }
Example #2
0
        protected void btnInserisci_Click(object sender, EventArgs e)
        {
            MaterialiCantieri mc = new MaterialiCantieri();

            FillMatCant(mc);

            if (Convert.ToInt32(txtQta.Text) > 0)
            {
                bool isInserito = MaterialiCantieriDAO.InserisciSpesa(mc);

                if (isInserito)
                {
                    lblIsManodopInserita.Text      = "Record inserito con successo";
                    lblIsManodopInserita.ForeColor = Color.Blue;
                }
                else
                {
                    lblIsManodopInserita.Text      = "Errore durante l'inserimento del record";
                    lblIsManodopInserita.ForeColor = Color.Red;
                }
            }
            else
            {
                lblIsManodopInserita.Text      = "La quantità deve essere maggiore di '0'";
                lblIsManodopInserita.ForeColor = Color.Red;
            }
        }
        protected void btnInserisci_Click(object sender, EventArgs e)
        {
            string            idCant     = ddlScegliCant.SelectedItem.Value;
            string            acquirente = ddlScegliOperaio.SelectedItem.Value;
            MaterialiCantieri mc         = new MaterialiCantieri();

            FillMatCant(mc);

            if (Convert.ToInt32(txtQta.Text) > 0)
            {
                bool isInserito = MaterialiCantieriDAO.InserisciOperaio(mc);

                if (isInserito)
                {
                    lblIsOperInserita.Text      = "Record inserito con successo";
                    lblIsOperInserita.ForeColor = Color.Blue;
                }
                else
                {
                    lblIsOperInserita.Text      = "Errore durante l'inserimento del record";
                    lblIsOperInserita.ForeColor = Color.Red;
                }
            }
            else
            {
                lblIsOperInserita.Text      = "Il valore della quantità deve essere maggiore di '0'";
                lblIsOperInserita.ForeColor = Color.Red;
            }
        }
Example #4
0
 /* HELPERS */
 protected void FillMatCant(MaterialiCantieri mc)
 {
     mc.IdTblCantieri   = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
     mc.Qta             = Convert.ToDouble(txtQta.Text);
     mc.Tipologia       = "SPE";
     mc.PzzoUniCantiere = Convert.ToDecimal(txtPzzoManodop.Text);
     mc.DescriMateriali = txtDescrManodop.Text;
     mc.Note            = txtNote1.Text + " - " + txtNote2.Text;
 }
        public static Phrase GeneraIntestazioneContoFinCli(MaterialiCantieri mc)
        {
            string codCant         = $"Codice Cantiere: {mc.CodCant}";
            string descriCodCant   = $"Descrizione Codice Cantiere: {mc.DescriCodCant}";
            string intestazioneObj = $"{codCant}    -    {descriCodCant}";
            Phrase intestazione    = new Phrase(intestazioneObj, FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.ITALIC, BaseColor.BLACK));

            return(intestazione);
        }
 /* HELPERS */
 //Popola un oggetto di tipo MaterialiCantieri
 protected void FillMatCant(MaterialiCantieri mc)
 {
     mc.IdTblCantieri   = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
     mc.DescriMateriali = txtDescrOper.Text;
     mc.Qta             = Convert.ToDouble(txtQta.Text);
     mc.Visibile        = chkVisibile.Checked;
     mc.Ricalcolo       = chkRicalcolo.Checked;
     mc.RicaricoSiNo    = chkRicarico.Checked;
     mc.Tipologia       = "OPERAIO";
     mc.Data            = Convert.ToDateTime(DateTime.Now);
     mc.Note            = txtNote1.Text + " - " + txtNote2.Text;
 }
        /* HELPERS */
        protected void FillMatCant(MaterialiCantieri mc)
        {
            mc.IdTblCantieri = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
            mc.Qta           = Convert.ToDouble(txtQta.Text);
            mc.Tipologia     = "ARROTONDAMENTO";
            mc.CodArt        = txtCodArt.Text;
            mc.DescriCodArt  = txtDescriCodArt.Text;
            mc.Data          = DateTime.Now;

            if (txtPzzoUnit.Text != "")
            {
                mc.PzzoUniCantiere = Convert.ToDecimal(txtPzzoUnit.Text);
            }
            else
            {
                mc.PzzoUniCantiere = -1;
            }
        }
Example #8
0
        public static MaterialiCantieri GetSingle(int idMaterialiCantiere)
        {
            MaterialiCantieri ret = new MaterialiCantieri();
            StringBuilder     sql = new StringBuilder();

            sql.AppendLine($"SELECT * FROM TblMaterialiCantieri WHERE idMaterialiCantiere = @idMaterialiCantiere");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Query <MaterialiCantieri>(sql.ToString(), new { idMaterialiCantiere }).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante il recupero del singolo record dei Materiali Cantieri", ex);
            }
            return(ret);
        }
        /* HELPERS */
        protected void FillMatCant(MaterialiCantieri mc)
        {
            mc.IdTblCantieri   = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
            mc.Acquirente      = ddlScegliOperaio.SelectedItem.Value;
            mc.Qta             = Convert.ToDouble(txtQta.Text);
            mc.Tipologia       = "MANODOPERA";
            mc.DescriMateriali = txtDescrManodop.Text;
            mc.Data            = DateTime.Now;
            mc.Note            = txtNote1.Text + " - " + txtNote2.Text;
            mc.Visibile        = chkVisibile.Checked;

            if (txtPzzoManodop.Text != "")
            {
                mc.PzzoUniCantiere = Convert.ToDecimal(txtPzzoManodop.Text);
            }
            else
            {
                mc.PzzoUniCantiere = -1;
            }
        }
Example #10
0
        public static bool UpdateMatCant(MaterialiCantieri mc)
        {
            bool          ret = false;
            StringBuilder sql = new StringBuilder();

            sql.AppendLine($"UPDATE TblMaterialiCantieri");
            sql.AppendLine($"SET IdTblCantieri = @IdTblCantieri");
            sql.AppendLine(mc.IdTblOperaio != 0 ? $",IdTblOperaio = @IdTblOperaio" : "");
            sql.AppendLine($",DescriMateriali = @DescriMateriali");
            sql.AppendLine($",Qta = @Qta");
            sql.AppendLine($",Visibile = @Visibile");
            sql.AppendLine($",Ricalcolo = @Ricalcolo");
            sql.AppendLine($",ricaricoSiNo = @RicaricoSiNo");
            sql.AppendLine($",Data = @Data");
            sql.AppendLine($",PzzoUniCantiere = @PzzoUniCantiere");
            sql.AppendLine($",CodArt = @CodArt");
            sql.AppendLine($",DescriCodArt = @DescriCodArt");
            sql.AppendLine($",Fascia = @Fascia");
            sql.AppendLine($",NumeroBolla = @NumeroBolla");
            sql.AppendLine($",ProtocolloInterno = @ProtocolloInterno");
            sql.AppendLine($",Note = @Note");
            sql.AppendLine($",Tipologia = @Tipologia");
            sql.AppendLine($",PzzoFinCli = @PzzoFinCli");
            sql.AppendLine($",Acquirente = @Acquirente");
            sql.AppendLine($",Fornitore = @Fornitore");
            sql.AppendLine($",Note2 = @Note2");
            sql.AppendLine($"WHERE IdMaterialiCantiere = @IdMaterialiCantiere");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Execute(sql.ToString(), mc) > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante l'update del record MatCant", ex);
            }
            return(ret);
        }
Example #11
0
        //INSERT
        public static bool InserisciMaterialeCantiere(MaterialiCantieri mc)
        {
            bool          ret = false;
            StringBuilder sql = new StringBuilder();

            sql.AppendLine($"INSERT INTO TblMaterialiCantieri (IdTblCantieri{(mc.IdTblOperaio != 0 ? ",IdTblOperaio" : "")},DescriMateriali,Qta,Visibile,Ricalcolo,ricaricoSiNo,Data,");
            sql.AppendLine($"PzzoUniCantiere,CodArt,DescriCodArt,Tipologia,Fascia,Acquirente,Fornitore,NumeroBolla,ProtocolloInterno,Note,Note2,pzzoFinCli)");
            sql.AppendLine($"VALUES (@IdTblCantieri{(mc.IdTblOperaio != 0 ? ",@IdTblOperaio" : "")},@DescriMateriali,@Qta,@Visibile,@Ricalcolo,@RicaricoSiNo,@Data,@PzzoUniCantiere,@CodArt,@DescriCodArt,@Tipologia,@Fascia,");
            sql.AppendLine($"@Acquirente,@Fornitore,@NumeroBolla,@ProtocolloInterno,@Note,@Note2,@pzzoFinCli)");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Execute(sql.ToString(), mc) > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante l'inserimento di un materiale cantiere", ex);
            }
            return(ret);
        }
        protected void btnInserisci_Click(object sender, EventArgs e)
        {
            int maxQta = Convert.ToInt32((ddlScegliMatCant.SelectedItem.Text).Split('-')[2]);

            MaterialiCantieri mc = new MaterialiCantieri();

            FillMatCant(mc);

            if (Convert.ToDecimal(txtPzzoUnit.Text) > 0)
            {
                if (Convert.ToInt32(txtQta.Text) > 0 && Convert.ToInt32(txtQta.Text) <= maxQta)
                {
                    bool isInserito = MaterialiCantieriDAO.InserisciMaterialeCantiere(mc);

                    if (isInserito)
                    {
                        lblIsRecordInserito.Text      = "Record inserito con successo";
                        lblIsRecordInserito.ForeColor = Color.Blue;
                    }
                    else
                    {
                        lblIsRecordInserito.Text      = "Errore durante l'inserimento del record";
                        lblIsRecordInserito.ForeColor = Color.Red;
                    }
                }
                else
                {
                    lblIsRecordInserito.Text      = "La quantità è 0 o maggiore di quella del materiale scelto";
                    lblIsRecordInserito.ForeColor = Color.Red;
                }
            }
            else
            {
                lblIsRecordInserito.Text      = "Inserire un valore maggiore di '0' per il campo Prezzo Unitario";
                lblIsRecordInserito.ForeColor = Color.Red;
            }
        }
        protected void btnStampaContoCliente_Click(object sender, EventArgs e)
        {
            //Ricreo i passaggi della "Stampa Ricalcolo Conti" per ottenere il valore del "Totale Ricalcolo"
            int               idCantiere = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
            Cantieri          cant       = CantieriDAO.GetSingle(idCantiere);
            MaterialiCantieri mc         = new MaterialiCantieri
            {
                RagSocCli     = cant.RagSocCli,
                CodCant       = cant.CodCant,
                DescriCodCant = cant.DescriCodCant
            };

            PdfPTable pTable = RicalcoloContiManager.InitializePdfTableDDT();
            Document  pdfDoc = new Document(PageSize.A4, 8f, 2f, 2f, 2f);

            pdfDoc.Open();
            List <MaterialiCantieri> materiali = RicalcoloContiManager.GetMaterialiCantieri(idCantiere);

            RicalcoloContiManager.GeneraPDFPerContoFinCli(pdfDoc, mc, pTable, materiali, 0, idCantiere);
            pdfDoc.Close();

            //Popolo i campi di riepilogo con i dati necessari
            CompilaCampi(idCantiere, materiali.Sum(s => s.Valore));
        }
        /* HELPERS */
        //Popolo un oggetto di tipo MaterialeCantiere per fare la insert
        protected void FillMatCant(MaterialiCantieri mc)
        {
            mc.IdTblCantieri   = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
            mc.DescriMateriali = txtDescrMat.Text;
            mc.Qta             = Convert.ToDouble(txtQta.Text);
            mc.Visibile        = chkVisibile.Checked;
            mc.Ricalcolo       = chkRicalcolo.Checked;
            mc.RicaricoSiNo    = chkRicarico.Checked;
            mc.PzzoUniCantiere = Convert.ToDecimal(txtPzzoUnit.Text);
            mc.CodArt          = txtCodArt.Text;
            mc.DescriCodArt    = txtDescriCodArt.Text;
            mc.Tipologia       = txtTipologia.Text;
            mc.Acquirente      = ddlScegliAcquirente.SelectedItem.Value;
            mc.Fornitore       = ddlScegliFornit.SelectedItem.Value;
            mc.Note            = txtNote.Text;

            if (txtDataDDT.Text != "")
            {
                mc.Data = Convert.ToDateTime(txtDataDDT.Text);
            }
            else
            {
                mc.Data = DateTime.Now;
            }

            if (txtFascia.Text != "")
            {
                mc.Fascia = Convert.ToInt32(txtFascia.Text);
            }
            else
            {
                mc.Fascia = -1;
            }

            if (txtProtocollo.Text != "")
            {
                mc.ProtocolloInterno = Convert.ToInt32(txtProtocollo.Text);
            }
            else
            {
                mc.ProtocolloInterno = -1;
            }

            if (txtNumBolla.Text != "")
            {
                mc.NumeroBolla = Convert.ToInt32(txtNumBolla.Text);
            }
            else
            {
                mc.NumeroBolla = -1;
            }

            if (txtPzzoFinCli.Text != "")
            {
                mc.PzzoFinCli = Convert.ToDecimal(txtPzzoFinCli.Text);
            }
            else
            {
                mc.PzzoFinCli = -1;
            }
        }
        public static void GeneraPDFPerContoFinCli(Document pdfDoc, MaterialiCantieri mc, PdfPTable table, List <MaterialiCantieri> matCantList, decimal totale, int idCantiere, string tipoNote = "")
        {
            Phrase intestazione       = GeneraIntestazioneContoFinCli(mc);
            Phrase dataPhrase         = new Phrase("Data", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
            Phrase descriptionPhrase  = new Phrase("Descrizione Codice Articolo", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
            Phrase quantityPhrase     = new Phrase("Qtà", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
            Phrase unitaryPricePhrase = new Phrase("Prezzo Unitario", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
            Phrase valuePhrase        = new Phrase("Valore", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK));

            PdfPCell dataCell         = new PdfPCell(dataPhrase);
            PdfPCell descriptionCell  = new PdfPCell(descriptionPhrase);
            PdfPCell quantityCell     = new PdfPCell(quantityPhrase);
            PdfPCell unitaryPriceCell = new PdfPCell(unitaryPricePhrase);
            PdfPCell valueCell        = new PdfPCell(valuePhrase);

            dataCell.BorderWidth             = descriptionCell.BorderWidth = quantityCell.BorderWidth = unitaryPriceCell.BorderWidth = valueCell.BorderWidth = 0;
            dataCell.BorderWidthBottom       = descriptionCell.BorderWidthBottom = quantityCell.BorderWidthBottom = unitaryPriceCell.BorderWidthBottom = valueCell.BorderWidthBottom = 1;
            dataCell.BorderColorBottom       = descriptionCell.BorderColorBottom = quantityCell.BorderColorBottom = unitaryPriceCell.BorderColorBottom = valueCell.BorderColorBottom = BaseColor.BLUE;
            dataCell.HorizontalAlignment     = descriptionCell.HorizontalAlignment = quantityCell.HorizontalAlignment = unitaryPriceCell.HorizontalAlignment = valueCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            quantityCell.HorizontalAlignment = unitaryPriceCell.HorizontalAlignment = valueCell.HorizontalAlignment = Element.ALIGN_CENTER;

            table.AddCell(dataCell);
            table.AddCell(descriptionCell);
            table.AddCell(quantityCell);
            table.AddCell(unitaryPriceCell);
            table.AddCell(valueCell);

            int j = 0;

            foreach (MaterialiCantieri materiale in matCantList)
            {
                unitaryPricePhrase               = new Phrase($"{Convert.ToDecimal(materiale.PzzoFinCli):n}", FontFactory.GetFont("Arial", 10, BaseColor.BLACK));
                valuePhrase                      = new Phrase($"{Convert.ToDecimal(materiale.Valore):n}", FontFactory.GetFont("Arial", 10, BaseColor.BLACK));
                dataPhrase                       = new Phrase(materiale.Data.ToString("dd/MM/yyyy"), FontFactory.GetFont("Arial", 10, BaseColor.BLACK));
                descriptionPhrase                = new Phrase(materiale.DescriCodArt, FontFactory.GetFont("Arial", 10, BaseColor.BLACK));
                quantityPhrase                   = new Phrase(materiale.Qta.ToString(), FontFactory.GetFont("Arial", 10, BaseColor.BLACK));
                dataCell                         = new PdfPCell(dataPhrase);
                descriptionCell                  = new PdfPCell(descriptionPhrase);
                quantityCell                     = new PdfPCell(quantityPhrase);
                unitaryPriceCell                 = new PdfPCell(unitaryPricePhrase);
                valueCell                        = new PdfPCell(valuePhrase);
                dataCell.BorderWidth             = descriptionCell.BorderWidth = quantityCell.BorderWidth = unitaryPriceCell.BorderWidth = valueCell.BorderWidth = 0;
                quantityCell.HorizontalAlignment = unitaryPriceCell.HorizontalAlignment = valueCell.HorizontalAlignment = Element.ALIGN_CENTER;

                //Set Color of Alternating row
                if (j % 2 != 0)
                {
                    dataCell.BackgroundColor         = descriptionCell.BackgroundColor = quantityCell.BackgroundColor = new BaseColor(ColorTranslator.FromHtml("#F7F7F7"));
                    unitaryPriceCell.BackgroundColor = valueCell.BackgroundColor = new BaseColor(ColorTranslator.FromHtml("#F7F7F7"));
                }
                table.AddCell(dataCell);
                table.AddCell(descriptionCell);
                table.AddCell(quantityCell);
                table.AddCell(unitaryPriceCell);
                table.AddCell(valueCell);

                if (tipoNote != "")
                {
                    // Aggiunta della riga contenente le note in base alla scelta della tipoNote
                    if (tipoNote == "note1note2")
                    {
                        PdfPCell note1Cell = new PdfPCell(new Phrase(materiale.Note, FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.ITALIC, BaseColor.BLACK)));
                        PdfPCell note2Cell = new PdfPCell(new Phrase(materiale.Note2, FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.ITALIC, BaseColor.BLACK)));
                        note1Cell.Colspan             = note2Cell.Colspan = 5;
                        note1Cell.BorderWidth         = note2Cell.BorderWidth = 0;
                        note1Cell.HorizontalAlignment = note2Cell.HorizontalAlignment = 0;
                        table.AddCell(note1Cell);
                        table.AddCell(note2Cell);
                    }
                    else if (tipoNote != "noNote")
                    {
                        if (materiale.Note != "" && materiale.Note != null)
                        {
                            PdfPCell noteCell = null;
                            if (tipoNote == "note1")
                            {
                                noteCell = new PdfPCell(new Phrase(materiale.Note, FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.ITALIC, BaseColor.BLACK)));
                            }
                            else if (tipoNote == "note2")
                            {
                                noteCell = new PdfPCell(new Phrase(materiale.Note2, FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.ITALIC, BaseColor.BLACK)));
                            }
                            noteCell.Colspan             = 5;
                            noteCell.BorderWidth         = 0;
                            noteCell.HorizontalAlignment = 0;
                            table.AddCell(noteCell);
                        }
                    }
                }
                totale += Convert.ToDecimal(materiale.Valore);
                j++;
            }

            PdfPTable tblTotali = new PdfPTable(1)
            {
                WidthPercentage = 100
            };

            GeneraTotalePerContoFinCli(tblTotali, totale, idCantiere);
            pdfDoc.Add(new Paragraph(""));
            pdfDoc.Add(intestazione);
            pdfDoc.Add(table);
            pdfDoc.Add(new Paragraph(""));
            pdfDoc.Add(tblTotali);
            InitializePdfTableDDT();
        }