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 Font = iTextSharp.text.Font;
using Image = iTextSharp.text.Image;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Xml.Linq;
using iTextSharp.text.pdf.parser;
using System.Text.RegularExpressions;
namespace ECV
{
public partial class compras_reg : Form
{
public compras_reg()
{
InitializeComponent();
}
private void Btn_Compras_Click(object sender, EventArgs e)
{
}
private void compras_reg_Load(object sender, EventArgs e)
{
cargar_prov();
Btn_buscar.BackColor = Global.ColorSistema;//
//BackColor = Global.ColorSistema;//
Productos productos = new Productos();
this.Top= productos.button6.Top+100;
}
private void compras_reg_Resize(object sender, EventArgs e)
{
}
private void cargar_prov()
{
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/compras_cargar_prov.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", ""));
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);
string devuelve = reader.ReadToEnd();
reader.Close();
stream.Close();
response.Close();
string[] c = devuelve.Split('▲');
this.Cursor = Cursors.Default;
string resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("
0)
{
string pattern = @"^\d{3}-\d{3}-\d{7}$";
string input = Txt_Fact.Text;
try
{
if (!Regex.IsMatch(input, pattern))
{//0010010000001
string serie = Txt_Fact.Text.Substring(0, 3);
string subSerie = Txt_Fact.Text.Substring(3, 3);
string numero = Txt_Fact.Text.Substring(6, 7);
Txt_Fact.Text = $"{serie:D3}-{subSerie:D3}-{numero:D7}";
}
}
catch { }
}
// CREAR PDF
string Provee = com_prov.Text.Replace("|","_");
string pdfgenerate = "\\DOC_PDF\\REPORTES_PDF\\COMPRAS_" + Provee.Trim() + "_" + Txt_Fact.Text.Trim() + "_" + Txt_Timbrado.Text + "_" + DateTime.Now.ToString("dd-MM-yy") + "_" + DateTime.Now.ToString("HH-mm") + "_.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.NO_COMPRESSION;
pdfw.SetFullCompression();
oDoc.Open();
oDoc.NewPage();
top1 = oDoc.PageSize.Top;
try
{
//ENCABEZADO LOGO (usado en reportes)
Image logo = Image.GetInstance("logo.png", true);
logo.CompressionLevel = PdfStream.NO_COMPRESSION;
//logo.SetAbsolutePosition(60, top1 - 80);
oDoc.Add(logo);
}
catch (Exception)
{
}
cb = pdfw.DirectContent;//DEBE IR ANTES DE LAS LÍNEAS DE TEXTO
//Colores
BaseColor FondoCab = new BaseColor(100, 200, 200);
BaseColor BordeCab = new BaseColor(200, 200, 200);
BaseColor FondoCuer = new BaseColor(255, 255, 255);
BaseColor FondoDiv = new BaseColor(180, 180, 180); ;//BaseColor(200, 150, 200);
BaseColor BordeDiv = new BaseColor(125, 125, 125);
BaseColor FondoTotal = new BaseColor(255, 255, 255);
BaseColor BordeDivTotal = new BaseColor(255, 255, 255);
//Espacio de cabecera
PdfPTable TablaEspa4 = new PdfPTable(1);
TablaEspa4.WidthPercentage = 100;
PdfPCell CelEspa4 = new PdfPCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA, 11, BaseColor.BLACK)));
CelEspa4.Border = 0;
CelEspa4.HorizontalAlignment = Element.ALIGN_LEFT;
TablaEspa4.AddCell(CelEspa4);
oDoc.Add(TablaEspa4);
PdfPTable table = new PdfPTable(7);//TABLA CON 7 CELDAS
//TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO
Phrase Titulo0 = new Phrase("CÓDIGO", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T0 = new PdfPCell(Titulo0);
TEXTO_T0.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T0.BackgroundColor = FondoCab;
//TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO
Phrase Titulo1 = new Phrase("CANT", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T1 = new PdfPCell(Titulo1);
TEXTO_T1.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T1.BackgroundColor = FondoCab;
Phrase Titulo2 = new Phrase("DESCRIPCIÓN", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T2 = new PdfPCell(Titulo2);
TEXTO_T2.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T2.BackgroundColor = FondoCab;
Phrase Titulo3 = new Phrase("PRECIO/U", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T3 = new PdfPCell(Titulo3);
TEXTO_T3.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T3.BackgroundColor = FondoCab;
Phrase Titulo4 = new Phrase("EXENTA", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T4 = new PdfPCell(Titulo4);
TEXTO_T4.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T4.BackgroundColor = FondoCab;
Phrase Titulo5 = new Phrase("IVA 5%", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T5 = new PdfPCell(Titulo5);
TEXTO_T5.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T5.BackgroundColor = FondoCab;
Phrase Titulo6 = new Phrase("IVA 10%", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T6 = new PdfPCell(Titulo6);
TEXTO_T6.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T6.BackgroundColor = FondoCab;
table.HorizontalAlignment = 0;
table.TotalWidth = 545f;//MEDIDA TOTAL DE LA TABLA
table.LockedWidth = true;
float[] widths = new float[] { 70f, 30f, 245f, 50f, 50f, 50f, 50f };//MEDIDAS DE COLUMNAS
table.SetWidths(widths);
//table.AddCell(TEXTO_T0); table.AddCell(TEXTO_T1); table.AddCell(TEXTO_T2); table.AddCell(TEXTO_T3);
//table.AddCell(TEXTO_T4); table.AddCell(TEXTO_T5); table.AddCell(TEXTO_T6);
//table.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255);
this.Cursor = Cursors.WaitCursor;
var div = com_prov.Text.Trim().Split('|');
string prov= div[0].Trim();
string ruc = div[1].Trim();
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/compras_buscar_compra.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼", prov, ruc, Txt_Fact.Text.Trim(), Txt_Timbrado.Text.Trim()));
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);
string devuelve = reader.ReadToEnd();
reader.Close();
stream.Close();
response.Close();
string[] c = devuelve.Split('▲');
this.Cursor = Cursors.Default;
string resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("
0 & Txt_Fact.Text.Length>0 & Txt_Timbrado.Text.Length > 0)
{
mensaje_lab.Visible = true;
buscar_compra();
mensaje_lab.Visible = false;
}
}
}
}