using iTextSharp.text; using iTextSharp.text.pdf; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SQLite; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using Image = iTextSharp.text.Image; namespace CKUERA { public partial class Egresos : Form { public Egresos() { InitializeComponent(); } private void Egresos_Load(object sender, EventArgs e) { if (double.Parse(Global.version) < 2) { Monto_box2.Enabled = false; Monto_box3.Enabled = false; Monto_box4.Enabled = false; Monto_box2.Text = "0"; Monto_box3.Text = "0"; Monto_box4.Text = "0"; } button2.Left = 3000; //CONSULTA Y CARGA Nombre_box { //using (MySqlConnection Conex = new MySqlConnection(string.Format("Server={0};Database={1};Uid={2};Pwd={3};Port={4};", Global._host, Global._base, Global._usuario, Global._pass, Global._port))) { //Conex.Open(); SQLiteDataReader RS = null; string SQL = "SELECT DISTINCT (EN_CONCEPTO) FROM CONCEPTO_OTROS;"; SQLiteCommand CMD3 = new SQLiteCommand(SQL, Global.conexion); RS = CMD3.ExecuteReader(); if (RS.HasRows == true) { while (RS.Read()) { Concepto_box.Items.Add(RS.GetString(0)); } } //Conex.Close(); } } //CONSULTA Y CARGA Nombre_box { //using (MySqlConnection Conex = new MySqlConnection(string.Format("Server={0};Database={1};Uid={2};Pwd={3};Port={4};", Global._host, Global._base, Global._usuario, Global._pass, Global._port))) { //Conex.Open(); SQLiteDataReader RS = null; string SQL = "SELECT DISTINCT (AFAVOR_DE) FROM CONCEPTO_OTROS;"; SQLiteCommand CMD3 = new SQLiteCommand(SQL, Global.conexion); RS = CMD3.ExecuteReader(); if (RS.HasRows == true) { while (RS.Read()) { Nombre_box.Items.Add(RS.GetString(0)); } } //Conex.Close(); } } { string name = "iconos\\registrar.png"; try { Button1.Image = System.Drawing.Image.FromFile(name); } catch (Exception) { } } Lab_mon1.Text = Global.denominacion1; Lab_mon2.Text = Global.denominacion2; Lab_mon3.Text = Global.denominacion3; Lab_mon4.Text = Global.denominacion4; } private void Button1_Click(object sender, EventArgs e) { if (Monto_box.Text == "") { Monto_box.Text = "0"; Monto_box.Select(); //return; } if (Monto_box2.Text == "") { Monto_box2.Text = "0"; Monto_box2.Select(); return; } if (Monto_box3.Text == "") { Monto_box3.Text = "0"; Monto_box3.Select(); return; } if (Monto_box4.Text == "") { Monto_box4.Text = "0"; Monto_box4.Select(); return; } if (Concepto_box.Text == "") { Concepto_box.Select(); return; } Concepto_box.Text = Concepto_box.Text.Replace("&", "y"); Concepto_box.Text = Concepto_box.Text.Replace("'", "`"); Concepto_box.Text = Concepto_box.Text.Replace(";", ","); Concepto_box.Text = Concepto_box.Text.Replace("\\", ","); if (Regex.IsMatch(Concepto_box.Text, "[^a-zA-Z0-9-/_() .,áéíóúÁÉÍÓÚñÑ`]")) { MessageBox.Show("En el campo escrito existe caracter especial no admitido. Reemplace y vuelva a presionar ENTER.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information); Concepto_box.Select(); return; } if (Nombre_box.Text == "") { Nombre_box.Select(); return; } Nombre_box.Text = Nombre_box.Text.Replace("&", "y"); Nombre_box.Text = Nombre_box.Text.Replace("'", "`"); Nombre_box.Text = Nombre_box.Text.Replace(";", ","); Nombre_box.Text = Nombre_box.Text.Replace("\\", ","); if (Regex.IsMatch(Nombre_box.Text, "[^a-zA-Z0-9-/_() .,áéíóúÁÉÍÓÚñÑ`]")) { MessageBox.Show("En el campo escrito existe caracter especial no admitido. Reemplace y vuelva a presionar ENTER.","ATENCIÓN",MessageBoxButtons.OK, MessageBoxIcon.Information); Nombre_box.Select(); return; } if (ChecCajaChica.Checked == false && ChecContable.Checked == false) { MessageBox.Show("Seleccione un opción: ''Caja Chica o Registro Contable''", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } int Contable = 0; if (ChecCajaChica.Checked == true) { Contable = 0; } else { Contable = 1; } if (Contable == 1) { if (double.Parse(Monto_box2.Text) > 0) { MessageBox.Show("El registro contable debe ser en moneda principal.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Warning); Monto_box2.Text = ""; Monto_box2.Focus(); return; } if (double.Parse(Monto_box3.Text) > 0) { MessageBox.Show("El registro contable debe ser en moneda principal.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Warning); Monto_box3.Text = ""; Monto_box3.Focus(); return; } if (double.Parse(Monto_box4.Text) > 0) { MessageBox.Show("El registro contable debe ser en moneda principal.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Warning); Monto_box4.Text = ""; Monto_box4.Select(); return; } } if (Auto_num.Checked == false)//SI NO ES AUTONÚMERO { if (Compr_box.Text == "") { Compr_box.Select(); return; } } else { Compr_box.Text = DateTime.Now.ToString("dd") + DateTime.Now.ToString("MM") + DateTime.Now.ToString("yy") + DateTime.Now.ToString("HH") + DateTime.Now.ToString("mm") + DateTime.Now.ToString("ss"); } Reemplazar();//REEMPLZA CARACTERES Y PONE EN MAYÚSCULAS ValidarInsertar();//CONSULTA, VALIDA Y INSERTA SI NO EXISTE UN NOMBRE Y/O UN CONCEPTO HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/egresar.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}▼{7}▼{8}▼{9}▼{10}", Global.NUM_caja, Global.USUARIO_SIST, Concepto_box.Text.Trim(), Monto_box.Text.Trim(), Nombre_box.Text.Trim(), Compr_box.Text.Trim(), Contable,Monto_box2.Text.Trim(), Monto_box3.Text.Trim(), Monto_box4.Text.Trim(), Concepto_box.Text)); 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[] rows; rows = devuelve.Split('▲'); //MUESTRA UN MENSAJE CUANDO HAY ERROR EN EL SERVIDOR string resultado = devuelve.ToUpper(); bool re; re = resultado.Contains("ERROR"); if (re == true) { MessageBox.Show(devuelve); return; } //AL ADMINISTRADOR Principal principal = new Principal(); string Titulo = ""; if (ChecCajaChica.Checked == true) { Titulo = "*EGRESO DE DINERO* _(Caja chica)_."; } if (ChecContable.Checked == true) { Titulo = "*EGRESO DE DINERO* _(Contable)_."; } string Monto = "*" + Global.SIMB_ + " " + double.Parse(Monto_box.Text).ToString("#,##0.##") + "*\n*" + Global.simboloMoneda2 + " " + double.Parse(Monto_box2.Text).ToString("#,##0.##") + "*\n*" + Global.simboloMoneda3 + " " + double.Parse(Monto_box3.Text).ToString("#,##0.##") + "*\n*" + Global.simboloMoneda4 + " " + double.Parse(Monto_box4.Text).ToString("#,##0.##") + "*"; principal.EnviarWhatsApp(Global.ID_WhatsApp, Titulo + "\n" + Monto + "\nEn concepto de " + Concepto_box.Text + ".\n*Pagado a* " + Nombre_box.Text + ".\n*Comprobante No.* " + Compr_box.Text + ".\n\n*_" + Global.Nom_EMPRESA + "_*\nCaja " + Global.NUM_caja + ": " + Global.USUARIO_SIST + "\n" + Global.Tel_EMPRESA, Global.Tel_WhatsApp); principal.Espera(1);//segundos //ENVIA NOMBRE A GLOBAL Global.nombre = Nombre_box.Text.ToUpper(); Global.concepto = Concepto_box.Text.ToUpper(); Global.monto = Monto_box.Text; Global.monto2 = Monto_box2.Text; Global.monto3 = Monto_box3.Text; Global.monto4 = Monto_box4.Text; Global.comprobante = Compr_box.Text; Button1.Enabled = false; MessageBox.Show("El egreso se regisró con éxito.", "¡Éxito!", MessageBoxButtons.OK, MessageBoxIcon.Information); pdf_mostrar_reciboE pdf_recibo = new pdf_mostrar_reciboE(); pdf_recibo.Mostrar_reciboE_pdf(); //Limpiar(); //Monto_box.Select(); this.Close(); } private void Reemplazar() { Concepto_box.Text = Concepto_box.Text.ToUpper().Trim().Replace("'", "´"); Nombre_box.Text = Nombre_box.Text.ToUpper().Trim().Replace("'", "´"); Concepto_box.SelectionStart = Concepto_box.Text.Length + 1; Nombre_box.SelectionStart = Nombre_box.Text.Length + 1; } private void ValidarInsertar() { //using (MySqlConnection Conex = new MySqlConnection(string.Format("Server={0};Database={1};Uid={2};Pwd={3};Port={4};", Global._host, Global._base, Global._usuario, Global._pass, Global._port))) { //Conex.Open(); SQLiteDataReader RS = null;//CONSULTA CONCEPTOS string SQL = "SELECT EN_CONCEPTO FROM CONCEPTO_OTROS WHERE EN_CONCEPTO='" + Concepto_box.Text + "';"; SQLiteCommand CMD = new SQLiteCommand(SQL, Global.conexion); RS = CMD.ExecuteReader(); if (RS.HasRows == false)//INSERTAR SI NO EXISTE CONCEPTO { RS.Close(); string SQLin = "INSERT INTO CONCEPTO_OTROS (AFAVOR_DE,EN_CONCEPTO) VALUES ('XX', '" + Concepto_box.Text + "');"; SQLiteCommand CMDin = new SQLiteCommand(SQLin, Global.conexion); CMDin.ExecuteNonQuery(); } RS.Close(); SQLiteDataReader RS2 = null;//CONSULTA AFAVOR_DE string SQL2 = "SELECT AFAVOR_DE FROM CONCEPTO_OTROS WHERE AFAVOR_DE='" + Nombre_box.Text + "';"; SQLiteCommand CMD2 = new SQLiteCommand(SQL2, Global.conexion); RS2 = CMD2.ExecuteReader(); if (RS2.HasRows == false)//INSERTAR SI NO EXISTE NOMBRE { RS2.Close(); string SQLin = "INSERT INTO CONCEPTO_OTROS(AFAVOR_DE,EN_CONCEPTO) VALUES ('" + Nombre_box.Text + "','XX');"; SQLiteCommand CMDin = new SQLiteCommand(SQLin, Global.conexion); CMDin.ExecuteNonQuery(); } //Conex.Close(); } } private void Limpiar() { Monto_box.Text = ""; Concepto_box.Text = ""; Nombre_box.Text = ""; Compr_box.Text = ""; } private void Egresos_Resize(object sender, EventArgs e) { panel1.Left = this.Width / 2 - panel1.Width / 2; panel1.Top = this.Height / 2 - panel1.Height / 2; Btn_Cerrar.Top = 0; Btn_Cerrar.Left = panel1.Width - Btn_Cerrar.Width; Button1.BackColor = Global.ColorSistema;// this.BackColor = Global.ColorSistema;//fp.Label1.BackColor; Lb_Titulo.Top = 0; Lb_Titulo.Left = 0; Lb_Titulo.Text = this.Text; } private void Egresos_Activated(object sender, EventArgs e) { this.Width = 20; } private void Monto_box_TextChanged(object sender, EventArgs e) { try { double d = double.Parse(Monto_box.Text); } catch { Monto_box.Text = ""; } } private void Nombre_box_TextChanged(object sender, EventArgs e) { ////CARACTERES PERMITIDOS //if(Nombre_box.Text=="") { return; } //Nombre_box.Text = Nombre_box.Text.Replace("&", "y"); //Nombre_box.Text = Nombre_box.Text.Replace("'", "`"); //Nombre_box.Text = Nombre_box.Text.Replace(";", ","); //Nombre_box.Text = Nombre_box.Text.Replace("\\", ","); //if (Regex.IsMatch(Nombre_box.Text, "[^a-zA-Z0-9-/_() .,áéíóúÁÉÍÓÚñÑ`]")) //{ // Nombre_box.Text = Nombre_box.Text.Substring(0,Nombre_box.Text.Length-1); //} //Nombre_box.SelectionStart = Nombre_box.Text.Length + 1; } private void Nombre_box_SelectedIndexChanged(object sender, EventArgs e) { } private void Concepto_box_SelectedIndexChanged(object sender, EventArgs e) { } private void Btn_Cerrar_Click(object sender, EventArgs e) { Close(); } private void button2_Click(object sender, EventArgs e) { Close(); } private void Monto_box2_TextChanged(object sender, EventArgs e) { try { double d = double.Parse(Monto_box2.Text); } catch { Monto_box2.Text = ""; } } private void Monto_box3_TextChanged(object sender, EventArgs e) { try { double d = double.Parse(Monto_box3.Text); } catch { Monto_box3.Text = ""; } } private void Monto_box4_TextChanged(object sender, EventArgs e) { try { double d = double.Parse(Monto_box4.Text); } catch { Monto_box4.Text = ""; } } } public class pdf_mostrar_reciboE { public object Mostrar_reciboE_pdf() { string NUMERO = Global.comprobante; //CREAR PDF string pdfgenerate = "\\DOC_PDF\\RECIBOS_PDF\\EGRESOS\\" + NUMERO +"_RECIBOS.pdf"; iTextSharp.text.Document oDoc; iTextSharp.text.pdf.PdfWriter pdfw; PdfContentByte cb; float top1; //PREPARA EL PDF oDoc = new iTextSharp.text.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) Image logo = Image.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 // Creamos un titulo personalizado con tamaño de fuente 18 y color Azul Paragraph title = new Paragraph(); title.Font = FontFactory.GetFont(FontFactory.TIMES, 18f, BaseColor.BLACK); title.Add("* RECIBO DE DINERO * "); oDoc.Add(title); // Agregamos un parrafo vacio como separacion. oDoc.Add(new Paragraph(" ")); //COLOR Y TIPO DE FUENTE cb.SetColorFill(iTextSharp.text.BaseColor.BLACK); cb.SetFontAndSize(BaseFont.CreateFont(@"arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 12); NumLet NumLet = new NumLet(); string enletras = NumLet.enletras(Global.monto); string enletras2 = NumLet.enletras(Global.monto2); string enletras3 = NumLet.enletras(Global.monto3); string enletras4 = NumLet.enletras(Global.monto4); PdfPTable table = new PdfPTable(1); table.WidthPercentage = 100; table.DefaultCell.BorderColor = new iTextSharp.text.BaseColor(128, 128, 128); table.AddCell("Número " + NUMERO); table.AddCell("Fecha " + DateTime.Now.ToString()); table.AddCell("Son " + Global.SIMB_ + " " + string.Format("{0:#,##0.##}", double.Parse(Global.monto)) + ".- | " + Global.simboloMoneda2 + " " + string.Format("{0:#,##0.##}", double.Parse(Global.monto2)) + ".- | " + Global.simboloMoneda3 + " " + string.Format("{0:#,##0.##}", double.Parse(Global.monto3)) + ".- | " + Global.simboloMoneda4 + " " + string.Format("{0:#,##0.##}", double.Parse(Global.monto4)) + ".-"); table.AddCell("Recibí de " + Global._nom_empresa); table.AddCell("La cantidad de " + Global.SIMB_ + " " + enletras + ".- | " + Global.simboloMoneda2 + " " + enletras2 + ".- | " + Global.simboloMoneda3 + " " + enletras3 + ".- | " + Global.simboloMoneda4 + " " + enletras4 + ".-"); table.AddCell("En concepto de " + Global.concepto + "."); table.AddCell(" "); table.AddCell("Firma " + Global.nombre.ToUpper()); oDoc.Add(table); pdfw.Flush(); oDoc.Close(); System.Diagnostics.Process.Start(@pdfgenerate);//MUESTRA EL RECIBO EN PDF return (null); } } }