using CKUERA; using iTextSharp.text.pdf; using iTextSharp.text; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Image = System.Drawing.Image; using ImageI = iTextSharp.text.Image; namespace ECV { public partial class Prod_Lista_Precios : Form { public Prod_Lista_Precios() { InitializeComponent(); } private void Prod_Lista_Precios_Load(object sender, EventArgs e) { button2.BackColor = Global.ColorSistema; } private void button2_Click(object sender, EventArgs e) { //int todos=0, todos_sincosto = 0, todos_23=0, sincosto_23=0, sincosto_precio3 = 0, todos_13=0, todos_12=0, concosto_23=0, concosto_precio3=0; //int todos_1 = 0, todos_2=0, todos_3=0, sincosto_precio2=0, sincosto_precio1=0, concosto_precio2=0, concosto_precio1=0, sincosto_13=0, sincosto_12=0, concosto_13=0, concosto_12=0; //if (chec_costo.Checked & chec_precio1.Checked & chec_precio2.Checked & chec_precio3.Checked) todos = 1; //if (chec_costo.Checked == false & chec_precio1.Checked & chec_precio2.Checked & chec_precio3.Checked) todos_sincosto = 1; //if (chec_costo.Checked & chec_precio1.Checked==false & chec_precio2.Checked & chec_precio3.Checked) todos_23 = 1; //if (chec_costo.Checked & chec_precio1.Checked & chec_precio2.Checked == false & chec_precio3.Checked) todos_13 = 1; //if (chec_costo.Checked & chec_precio1.Checked & chec_precio2.Checked & chec_precio3.Checked == false) todos_12 = 1; //if (chec_costo.Checked & chec_precio1.Checked & chec_precio2.Checked == false & chec_precio3.Checked == false) todos_1 = 1; //if (chec_costo.Checked & chec_precio1.Checked == false & chec_precio2.Checked & chec_precio3.Checked == false) todos_2 = 1; //if (chec_costo.Checked & chec_precio1.Checked == false & chec_precio2.Checked == false & chec_precio3.Checked) todos_3 = 1; //if (chec_costo.Checked==false & chec_precio1.Checked == false & chec_precio2.Checked & chec_precio3.Checked) sincosto_23 = 1; //if (chec_costo.Checked == false & chec_precio1.Checked & chec_precio2.Checked == false & chec_precio3.Checked) sincosto_13 = 1; //if (chec_costo.Checked == false & chec_precio1.Checked & chec_precio2.Checked & chec_precio3.Checked == false) sincosto_12 = 1; //if (chec_costo.Checked == false & chec_precio1.Checked == false & chec_precio2.Checked == false & chec_precio3.Checked) sincosto_precio3 = 1; //if (chec_costo.Checked == false & chec_precio1.Checked == false & chec_precio2.Checked & chec_precio3.Checked == false) sincosto_precio2 = 1; //if (chec_costo.Checked == false & chec_precio1.Checked & chec_precio2.Checked == false & chec_precio3.Checked == false) sincosto_precio1 = 1; //if (chec_costo.Checked & chec_precio1.Checked == false & chec_precio2.Checked & chec_precio3.Checked) concosto_23 = 1; //if (chec_costo.Checked & chec_precio1.Checked & chec_precio2.Checked == false & chec_precio3.Checked) concosto_13 = 1; //if (chec_costo.Checked & chec_precio1.Checked & chec_precio2.Checked & chec_precio3.Checked == false) concosto_12 = 1; //if (chec_costo.Checked & chec_precio1.Checked == false & chec_precio2.Checked == false & chec_precio3.Checked) concosto_precio3 = 1; //if (chec_costo.Checked & chec_precio1.Checked == false & chec_precio2.Checked & chec_precio3.Checked == false) concosto_precio2 = 1; //if (chec_costo.Checked & chec_precio1.Checked & chec_precio2.Checked == false & chec_precio3.Checked == false) concosto_precio1 = 1; //MessageBox.Show(todos.ToString()); return; this.Cursor = Cursors.WaitCursor; label1.Visible = true; // CREAR PDF string pdfgenerate = "\\DOC_PDF\\REPORTE.pdf"; Document oDoc; PdfWriter pdfw; PdfContentByte cb; float top1; //PREPARA EL PDF oDoc = new Document(PageSize.A4, 30, 20, 20, 20); pdfw = PdfWriter.GetInstance(oDoc, new FileStream(pdfgenerate, FileMode.Create, FileAccess.Write, FileShare.None)); pdfw.CompressionLevel = PdfStream.BEST_COMPRESSION; pdfw.SetFullCompression(); oDoc.Open(); oDoc.NewPage(); top1 = oDoc.PageSize.Top; try { //ENCABEZADO LOGO (usado en reportes) ImageI logo = ImageI.GetInstance("logo.png", true); logo.CompressionLevel = PdfStream.NO_COMPRESSION; //logo.SetAbsolutePosition(60, top1 - 130); oDoc.Add(logo); } catch (Exception) { } cb = pdfw.DirectContent;//DEBE IR ANTES DE LAS LÍNEAS DE TEXTO //EL TÍTULO Paragraph title = new Paragraph(); title.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 10, BaseColor.BLACK); title.Add("LISTA DE PRECIOS" + "\nGenerado por " + Global.USUARIO_SIST + " - Terminal " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); title.Alignment = Element.ALIGN_LEFT; oDoc.Add(title); PdfPTable table = new PdfPTable(7);//TABLA CON 7 CELDAS //TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO Paragraph TEXTO_T0 = new Paragraph(); TEXTO_T0.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T0.Add("CÓDIGO"); Paragraph TEXTO_T1 = new Paragraph(); TEXTO_T1.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T1.Add("DESCRIPCIÓN"); Paragraph TEXTO_T2 = new Paragraph(); TEXTO_T2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T2.Add("STOCK"); TEXTO_T2.Alignment = Element.ALIGN_RIGHT; Paragraph TEXTO_T3 = new Paragraph(); TEXTO_T3.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T3.Add("COSTO"); Paragraph TEXTO_VEN = new Paragraph(); TEXTO_VEN.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_VEN.Add("PRECIO 1"); Phrase Titulo4 = new Phrase("PRECIO 2", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell TEXTO_T4 = new PdfPCell(Titulo4); TEXTO_T4.HorizontalAlignment = Element.ALIGN_LEFT; TEXTO_T4.BackgroundColor = new BaseColor(224, 255, 255); Phrase Titulo5 = new Phrase("PRECIO 3", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell TEXTO_T5 = new PdfPCell(Titulo5); TEXTO_T5.HorizontalAlignment = Element.ALIGN_RIGHT; TEXTO_T5.BackgroundColor = new BaseColor(224, 255, 255); //table.HorizontalAlignment = 0; table.TotalWidth = 545f;//MEDIDA TOTAL DE LA TABLA table.LockedWidth = true; float[] widths = new float[] { 70f, 212f, 40f, 55f, 55f, 55f, 55f };//MEDIDAS DE COLUMNAS table.SetWidths(widths); //table.WidthPercentage = 100; table.DefaultCell.BackgroundColor = new BaseColor(224, 255, 255); table.DefaultCell.BorderColor = new BaseColor(0, 0, 0);//125,125,255 table.AddCell(TEXTO_T0); table.AddCell(TEXTO_T1); table.AddCell(TEXTO_T2); table.AddCell(TEXTO_T3); table.AddCell(TEXTO_VEN); table.AddCell(TEXTO_T4); table.AddCell(TEXTO_T5); table.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255); string devuelve = ""; //if (chec_precio1.Checked==true) { try { HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/rep_lista_precios.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼", "", "", "", "")); rq.ContentType = "application/x-www-form-urlencoded"; rq.ContentLength = byteArray.Length; Stream stream = rq.GetRequestStream(); stream.Write(byteArray, 0, byteArray.Length); stream.Close(); // WebResponse response = rq.GetResponse(); stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); devuelve = reader.ReadToEnd(); reader.Close(); stream.Close(); response.Close(); if (devuelve.ToUpper().Contains("WARNING") | devuelve.ToUpper().Contains("ERROR")) { MessageBox.Show(devuelve); this.Cursor = Cursors.Default; return; } } catch (Exception ex) { // Mostrar la descripción del error en un MessageBox MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //TEXTO QUE IRÁ DENTRO DE LA TABLA DEL CUERPO if (devuelve != "") { foreach (var line in devuelve.Split('↔')) { var valores = line.Split('▲'); if (valores[0] != "") { Paragraph codigo = new Paragraph(); codigo.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK); codigo.Add(valores[0]); Paragraph descrip = new Paragraph(); descrip.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK); descrip.Add(valores[1]); string cant = double.Parse(valores[2]).ToString("#,##0.##"); Paragraph cantidad = new Paragraph(); cantidad.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK); cantidad.Add(cant); PdfPCell cantidadx = new PdfPCell(cantidad); cantidadx.HorizontalAlignment = Element.ALIGN_CENTER; cantidadx.BackgroundColor = new BaseColor(255, 255, 255); cantidadx.BorderColor = new BaseColor(211, 211, 211);//125,125,255 string cost = valores[3].ToString(); if (cost == "") cost = "0"; if (chec_costo.Checked == false) cost = "0"; string Costox = double.Parse(cost).ToString("#,##0.##"); Phrase costo = new Phrase(string.Format("{0:#,##0.##}", Costox), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell COSTO = new PdfPCell(costo); COSTO.HorizontalAlignment = Element.ALIGN_RIGHT; COSTO.BackgroundColor = new BaseColor(255, 255, 255); COSTO.BorderColor = new BaseColor(211, 211, 211);//125,125,255 string prec1 = valores[4].ToString(); if (prec1 == "") prec1 = "0"; if (chec_precio1.Checked == false) prec1 = "0"; string Precio1x = double.Parse(prec1).ToString("#,##0.##"); Phrase precio = new Phrase(string.Format("{0:#,##0.##}", Precio1x), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell PRECIO1 = new PdfPCell(precio); PRECIO1.HorizontalAlignment = Element.ALIGN_RIGHT; PRECIO1.BackgroundColor = new BaseColor(255, 255, 255); PRECIO1.BorderColor = new BaseColor(211, 211, 211);//125,125,255 string prec2 = valores[5].ToString(); if (prec2 == "") prec2 = "0"; if (chec_precio2.Checked == false) prec2 = "0"; string Precio2x = double.Parse(prec2).ToString("#,##0.##"); Phrase precio2 = new Phrase(string.Format("{0:#,##0.##}", Precio2x), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell PRECIO2 = new PdfPCell(precio2); PRECIO2.HorizontalAlignment = Element.ALIGN_RIGHT; PRECIO2.BackgroundColor = new BaseColor(255, 255, 255); PRECIO2.BorderColor = new BaseColor(211, 211, 211);//125,125,255 string prec3 = valores[6].ToString(); if (prec3 == "") prec3 = "0"; if (chec_precio3.Checked == false) prec3 = "0"; string Precio3x = double.Parse(prec3).ToString("#,##0.##"); Phrase precio3 = new Phrase(string.Format("{0:#,##0.##}", Precio3x), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell PRECIO3 = new PdfPCell(precio3); PRECIO3.HorizontalAlignment = Element.ALIGN_RIGHT; PRECIO3.BackgroundColor = new BaseColor(255, 255, 255); PRECIO3.BorderColor = new BaseColor(211, 211, 211);//125,125,255 //table.WidthPercentage = 100; table.DefaultCell.BorderColor = new BaseColor(211, 211, 211);//125,125,255 table.AddCell(codigo); table.AddCell(descrip); table.AddCell(cantidadx); table.AddCell(COSTO); table.AddCell(PRECIO1); table.AddCell(PRECIO2); table.AddCell(PRECIO3); } } } ////TOTAL DE VENTA QUE SALE EN LA CABECERA //Paragraph title2 = new Paragraph(); //title2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 14, BaseColor.BLUE); //title2.Add("Valor Total " + Global.SIMB_ + " " + string.Format("{0:#,##0.##}", Global.Total_Rep_Prod)); //title2.Alignment = Element.ALIGN_RIGHT; //oDoc.Add(title2); //PARRAFO VACÍO COMO SEPARADOR Paragraph title3 = new Paragraph(); title3.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 2, BaseColor.BLACK); title3.Add("."); title3.Alignment = Element.ALIGN_LEFT; oDoc.Add(title3); oDoc.Add(table); this.Cursor = Cursors.Default; pdfw.Flush(); oDoc.Close(); System.Diagnostics.Process.Start(@pdfgenerate);//MUESTRA EL REPORTE EN PDF label1.Visible = false; } } }