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 static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Image = iTextSharp.text.Image;
using System.Drawing.Printing;
using Microsoft.SqlServer.Server;
using System.Reflection.Emit;
namespace CKUERA
{
public partial class Optica : Form
{
public Optica()
{
InitializeComponent();
}
private void Optica_Load(object sender, EventArgs e)
{
panel2.Width = 831;
panel2.Height= 628;
panel2.Left = this.Width / 2 - panel2.Width / 2;
panel2.Top = this.Height / 2 - panel2.Height / 2;
Btn_Cerrar.Top = 0;
Btn_Cerrar.Left = panel2.Width - Btn_Cerrar.Width;
label6.Left=0; label6.Top=0;
DataG1.Left = Txt_buscar.Left;
DataG1.Top = Txt_buscar.Top + Txt_buscar.Height + 2;
button1.Top = Txt_buscar.Top;
button1.Left = Txt_buscar.Left + Txt_buscar.Width + 1;
panel3.Top = button2.Top + button2.Height;
panel3.Left = label4.Left;
Btn_Guardar.BackColor = Global.ColorSistema;
Btn_Historial.BackColor = Global.ColorSistema;
Btn_Limpiar.BackColor = Global.ColorSistema;
Btn_Eliminar.BackColor = Global.ColorSistema;
Btn_Facturar.BackColor = Global.ColorSistema;
panel1.Top = DataG1.Top;
panel1.Left = DataG1.Left;
panel1.Width = label4.Width;//DataG1.Width;
label19.Text = "Entrega " + Global.SIMB_;
BackColor= Global.ColorSistema;
panel5.Top = 0;
panel5.Left = 0;
panel5.Height = this.Height;
panel5.Width = this.Width;
Licencia();
}
private void Txt_buscar_TextChanged(object sender, EventArgs e)
{
Txt_buscar.ForeColor = Color.Black;
dataLista.Rows.Clear();
num_pedido = "";
//CONSULTA LA TABLA CLIENTES
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/clientes_listar.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", Txt_buscar.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 resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("
");
if (re2 == true)
{
MessageBox.Show(devuelve2);
return;
}
if (devuelve2 != "")
{
dataLista.Rows.Clear();
double ST = 0;
t = 0;
Lb_Total.Text = "0";
foreach (var line2 in devuelve2.Trim().Split('↔'))
{
var v2 = line2.Split('▲');
if (v2[0] != "")
{
Fecha_Entrga.Enabled = false;
ST = double.Parse(v2[7]) * double.Parse(v2[17]);
dataLista.Rows.Add(v2[0],//ID
v2[6],//CODIGO
v2[7],//CANT
v2[8],//DESCRIP
v2[6],//COMPRA
v2[10],//PROVEE
v2[11],//SECC
v2[12],//SUBSECC
v2[13],//IVA
v2[14],//MODELO
v2[15],//CALIBRE
v2[16],//COLOR
double.Parse(v2[17]).ToString("#,##0.##"),//PRECIO
ST.ToString("#,##0.##"),//SUBTOTAL
num_pedido= v2[2],//Num_Pedido
Fecha_op.Text= v2[3],//FECHA OPERACIÓN
Fecha_Entrga.Text = v2[4],//FECHA ENTREGA
Txt_DR.Text = v2[18],//DR.
Txt_D_ESF.Text = v2[19],//D_ESF
Txt_D_CIL.Text = v2[20],
Txt_D_EJE.Text = v2[21],
Txt_D_ADD.Text = v2[22],
Txt_D_D.Text = v2[23],
Txt_I_ESF.Text = v2[24],//I_ESF
Txt_I_CIL.Text = v2[25],
Txt_I_EJE.Text = v2[26],
Txt_I_ADD.Text = v2[27],
Txt_I_D.Text = v2[28],
Txt_TIPO.Text = v2[29],
Txt_COLOR.Text = v2[30],
Txt_ALTURA_B.Text = v2[31],
Txt_ALTURA_M.Text = v2[32],
Txt_OBS.Text = v2[33],
Estado = v2[34],
Txt_Entrega.Text = double.Parse(v2[35]).ToString("0.##"),
Txt_D_ESFX.Text = v2[35],//D_ESF
Txt_D_CILX.Text = v2[36],
Txt_D_EJEX.Text = v2[37],
Txt_D_ADDX.Text = v2[38],
Txt_D_DX.Text = v2[39],
Txt_I_ESFX.Text = v2[40],//I_ESF
Txt_I_CILX.Text = v2[41],
Txt_I_EJEX.Text = v2[42],
Txt_I_ADDX.Text = v2[43],
Txt_I_DX.Text = v2[44]
);
t = ST + t;
//Lb_Total.Text = t.ToString("#,##0.##");
}
}
Lb_Total.Text = "Total " + Global.SIMB_ + " " + t.ToString("#,##0.##");
Saldo();//Lb_Saldo.Text = "Saldo " + Global.SIMB_ + " " + (t-double.Parse(Txt_Entrega.Text)).ToString("#,##0.##");
Btn_Facturar.Enabled = true;
Btn_Guardar.Enabled = true;
Btn_Eliminar.Enabled = true;
Txt_Entrega.Enabled = false;
Txt_buscar.Enabled = false;
}
}
double t=0;
private void Saldo()
{
try
{
Lb_Saldo.Text = "Saldo " + Global.SIMB_ + " " + (t - double.Parse(Txt_Entrega.Text)).ToString("#,##0.##");
}
catch
{
Lb_Saldo.Text = "Saldo " + Global.SIMB_ + " ";
}
}
string Estado="0";
private void Txt_bus_art_TextChanged(object sender, EventArgs e)
{
if (Txt_bus_art.TextLength > 0)
{
label4.BackColor = System.Drawing.Color.SeaGreen;
Txt_ayuda.BackColor = System.Drawing.Color.SeaGreen;
}
else
{ label4.BackColor = System.Drawing.Color.Silver; }
button2.BackColor = label4.BackColor;
Txt_ayuda.BackColor = label4.BackColor;
//CARACTERES PERMITIDOS
if (System.Text.RegularExpressions.Regex.IsMatch(Txt_bus_art.Text, "[^a-zA-Z0-9-/_() .+:%áéíóúÁÉÍÓÚ`]")) { Txt_bus_art.Text = ""; return; }
dataProd.Rows.Clear();
string filtro = Txt_bus_art.Text; //cons_temp_usu.php
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/consultar_precios.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}", filtro, Global.num_esta, Global.ConSuc));
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 resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("
0) { Btn_Guardar.Enabled = true; } else { Btn_Guardar.Enabled = false; }
Txt_bus_art.Text = "";
Txt_bus_art.Select();
Sumar_dataLista();
Saldo();
}
private void Sumar_dataLista()
{
double Suma = 0;
foreach (DataGridViewRow row in dataLista.Rows)
{
Suma = Suma + double.Parse(row.Cells[13].Value.ToString());
}
Lb_Total.Text = "Total " + Global.SIMB_ + " " + Suma.ToString("#,##0.##");
t= Suma;
}
private void dataLista_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
double Cant = 0;
foreach (DataGridViewRow dgvRenglon in dataLista.Rows)
{
try
{
Cant = double.Parse(dgvRenglon.Cells[2].Value.ToString());
}
catch
{
MessageBox.Show("Escriba en Número, por favor.","CUIDADO",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
dgvRenglon.Cells[2].Value = "1";
}
double a = double.Parse(dgvRenglon.Cells[12].Value.ToString()) * Cant;
dgvRenglon.Cells[13].Value = a.ToString("#,##0.##");
}
Sumar_dataLista();
Saldo();
}
private void dataLista_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
dataLista.Rows.RemoveAt(dataLista.CurrentRow.Index);
}
}
static string num_pedido="";
private void Btn_Guardar_Click(object sender, EventArgs e)
{
if (ID_LABEL.Text == "") { MessageBox.Show("Falta un cliente. Seleccione uno.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; }
if (dataLista.Rows.Count < 1) { MessageBox.Show("No hay artículos para guardar.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; }
if (DateTime.Now.ToString("dd/MM/yyyy") == string.Format("{0:dd/MM/yyyy}",DateTime.Parse(Fecha_Entrga.Text)))
{
if (Fecha_Entrga.Enabled == true)
{
DialogResult result = MessageBox.Show("¿Confirma que realmente la fecha de entrega es hoy?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
return;
}
}
string Fe = string.Format("{0:yyyyMMdd}", DateTime.Parse(Fecha_Entrga.Text)); //11/10/2022
string Fh = DateTime.Now.ToString("yyyyMMdd"); //11/10/2022
if (double.Parse(Fe)< double.Parse(Fh))
{
MessageBox.Show("Escriba una fecha superior a la de hoy.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (Txt_DR.Text == "") { MessageBox.Show("Escriba un Doctor para continuar.","ATENCIÓN",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); Txt_DR.Select(); return; }
Txt_DR.Text = Txt_DR.Text.ToUpper();
if (Txt_D_ESF.Text == "") Txt_D_ESF.Text ="X";
if (Txt_D_CIL.Text == "") Txt_D_CIL.Text = "X";
if(Txt_D_EJE.Text == "") Txt_D_EJE.Text = "X";
if (Txt_D_ADD.Text == "") Txt_D_ADD.Text = "X";
if (Txt_I_ESF.Text == "") Txt_I_ESF.Text = "X";
if (Txt_I_CIL.Text == "") Txt_I_CIL.Text = "X";
if (Txt_I_EJE.Text == "") Txt_I_EJE.Text = "X";
if (Txt_I_ADD.Text == "") Txt_I_ADD.Text = "X";
if (Txt_I_D.Text == "") Txt_I_D.Text = "X";
if (Txt_D_ESFX.Text == "") Txt_D_ESFX.Text = "X";
if (Txt_D_CILX.Text == "") Txt_D_CILX.Text = "X";
if (Txt_D_EJEX.Text == "") Txt_D_EJEX.Text = "X";
if (Txt_D_ADDX.Text == "") Txt_D_ADDX.Text = "X";
if (Txt_I_ESFX.Text == "") Txt_I_ESFX.Text = "X";
if (Txt_I_CILX.Text == "") Txt_I_CILX.Text = "X";
if (Txt_I_EJEX.Text == "") Txt_I_EJEX.Text = "X";
if (Txt_I_ADDX.Text == "") Txt_I_ADDX.Text = "X";
if (Txt_I_DX.Text == "") Txt_I_DX.Text = "X";
if (Txt_TIPO.Text == "") Txt_TIPO.Text = "X";
if(Txt_COLOR.Text == "") Txt_COLOR.Text = "X";
if (Txt_ALTURA_B.Text == "") Txt_ALTURA_B.Text = "X";
if (Txt_ALTURA_M.Text == "") Txt_ALTURA_M.Text = "X";
if (Txt_OBS.Text == "") Txt_OBS.Text = "NO HAY.";
string mje ="";
if (num_pedido == "")
{
num_pedido = DateTime.Now.ToString("yyMMddHHmmss");
}
else
{
Eiliminar_Serv(0);
}
string fecha_op = string.Format("{0:yyyy-MM-dd}", DateTime.Parse(Fecha_Entrga.Text));
string fecha_ent = string.Format("{0:yyyy-MM-dd}", DateTime.Parse(Fecha_Entrga.Text));
Txt_OBS.Text = Txt_OBS.Text.Replace("'", "´");//20/10/2022
if (Txt_OBS.Text == "") { Txt_OBS.Text = " "; }
try
{
double.Parse(Txt_Entrega.Text);
}
catch
{
Txt_Entrega.Text = "";
Txt_Entrega.Select();
return;
}
string cabecera = Global.Nom_EMPRESA + "\n" +
Global.Direc_EMPRESA + "\n" +
Global.Tel_EMPRESA + "\n" + "\n";
Global.T_Construido = "FECHA:" + fecha_op + ", " + DateTime.Now.ToString("HH:mm:ss") + " \n" +
"PEDIDO No.: " + num_pedido + "\n" +
"CONFECCIONADO POR: " + Global.USUARIO_SIST + "\n" +
"FECHA DE ENTREGA:" + fecha_ent + "\n" +
"CLIENTE: " + Txt_nombre.Text + "\n" +
"RUC O CI: " + Txt_doc.Text + "\n" +
"TELEFONO: " + Txt_tel.Text + "\n\n" +
"***DETALLE DEL PEDIDO***"
;
foreach (DataGridViewRow dgvRenglon in dataLista.Rows)
{
mje = mje + "↔"
+ Global.USUARIO_SIST
+ "▲" + num_pedido
+ "▲" + fecha_op
+ "▲" + fecha_ent
+ "▲" + ID_LABEL.Text
+ "▲" + dgvRenglon.Cells[1].Value.ToString()//CODIGO
+ "▲" + dgvRenglon.Cells[2].Value.ToString()//CANT
+ "▲" + dgvRenglon.Cells[3].Value.ToString()//DESCRIP
+ "▲" + dgvRenglon.Cells[4].Value.ToString()//COMPRA
+ "▲" + dgvRenglon.Cells[9].Value.ToString()//MODELO
+ "▲" + dgvRenglon.Cells[10].Value.ToString()//CALIBRE
+ "▲" + dgvRenglon.Cells[11].Value.ToString()//COLOR
+ "▲" + double.Parse(dgvRenglon.Cells[12].Value.ToString())//PRECIO
+ "▲" + dgvRenglon.Cells[5].Value.ToString()//PROVEE
+ "▲" + dgvRenglon.Cells[6].Value.ToString()//SECC
+ "▲" + dgvRenglon.Cells[7].Value.ToString()//SUBSECC
+ "▲" + dgvRenglon.Cells[8].Value.ToString()//IVA
+ "▲" + Txt_DR.Text//Doctor
+ "▲" + Txt_D_ESF.Text//OJO DERECHO
+ "▲" + Txt_D_CIL.Text
+ "▲" + Txt_D_EJE.Text
+ "▲" + Txt_D_ADD.Text
+ "▲" + Txt_D_D.Text
+ "▲" + Txt_I_ESF.Text//OJO IZQUIERDO
+ "▲" + Txt_I_CIL.Text
+ "▲" + Txt_I_EJE.Text
+ "▲" + Txt_I_ADD.Text
+ "▲" + Txt_I_D.Text
+ "▲" + Txt_TIPO.Text
+ "▲" + Txt_COLOR.Text
+ "▲" + Txt_ALTURA_B.Text
+ "▲" + Txt_ALTURA_M.Text
+ "▲" + Txt_OBS.Text.ToUpper()
+ "▲" + Estado
+ "▲" + Txt_Entrega.Text
+ "▲" + Txt_D_ESFX.Text//OJO DERECHO
+ "▲" + Txt_D_CILX.Text
+ "▲" + Txt_D_EJEX.Text
+ "▲" + Txt_D_ADDX.Text
+ "▲" + Txt_D_DX.Text
+ "▲" + Txt_I_ESFX.Text//OJO IZQUIERDO
+ "▲" + Txt_I_CILX.Text
+ "▲" + Txt_I_EJEX.Text
+ "▲" + Txt_I_ADDX.Text
+ "▲" + Txt_I_DX.Text
;//FIN
Global.T_Construido = Global.T_Construido + "\n\n" +
"CANTIDAD: " + double.Parse(dgvRenglon.Cells[2].Value.ToString()).ToString("0") + "\n" +
"DESCRIPCION: " + dgvRenglon.Cells[3].Value.ToString() + "\n" +
"MODELO: " + dgvRenglon.Cells[9].Value.ToString() + "\n" +
"CALIBRE: " + dgvRenglon.Cells[10].Value.ToString() + "\n" +
"COLOR: " + dgvRenglon.Cells[11].Value.ToString() + "\n"
;
}
Global.T_Construido = Global.T_Construido + "\n" +
Lb_Total.Text.ToUpper() + "\n" +
"ENTREGA: " + Global.SIMB_ + " " + Txt_Entrega.Text + "\n" +
Lb_Saldo.Text.ToUpper() + "\n\n" +
"OBSERVACION: " + Txt_OBS.Text.ToUpper() + "\n" +
"\n\n\n\n\n\n\n\n\n\n" +
cabecera;
;
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/optica_guardar.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}↔", mje));
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;
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
return;
}
Entrega();
PrintTicket();
cabecera = "";
Global.T_Construido = "";
MessageBox.Show("El pedido se guardó.", "ÉXITO", MessageBoxButtons.OK, MessageBoxIcon.Information);
Btn_Limpiar_Click(null, null);
}
public void PrintTicket()
{
printDocument1 = new System.Drawing.Printing.PrintDocument();
PrinterSettings ps = new PrinterSettings();
printDocument1.PrinterSettings = ps;
printDocument1.PrintPage += Imprimir;
printDocument1.Print();
}
private void Imprimir(object sender, PrintPageEventArgs e)
{
System.Drawing.Font font = new System.Drawing.Font("Lucida Console", 9);
int ancho = 700;
int y = 20;
int alto = 12;
string s;
string[] rows;
s = Global.T_Construido;
rows = s.Split('\n');
int v = 0;
while (v < rows.GetUpperBound(0))
{
e.Graphics.DrawString(rows[v].ToString(), font, Brushes.Black, new RectangleF(0, y += 15, ancho, alto));
v = v + 1;
}
}
private void Imprimir_PDF()
{
//CREAR PDF
string pdfgenerate = "\\DOC_PDF\\OPTICA\\" + "ELNOMBRE" + ".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)
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
//EL TÍTULO
Paragraph title = new Paragraph();
title.Font = FontFactory.GetFont(FontFactory.TIMES, 10f, BaseColor.BLACK);
title.Add("REPORTE Ventas, Vendedor: " + Global.Vendedor + ", DOC: " + Global.DOC + ", Comisión " + Global.ComiVen + "%.\nDesde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) +
"\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(8);//TABLA CON 6 CELDAS
//TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO
Paragraph TEXTO_T0 = new Paragraph();
TEXTO_T0.Font = FontFactory.GetFont(FontFactory.TIMES, 9f, BaseColor.BLACK);
TEXTO_T0.Add("COMPROBANTE");
Paragraph TEXTO_T1 = new Paragraph();
TEXTO_T1.Font = FontFactory.GetFont(FontFactory.TIMES, 9f, BaseColor.BLACK);
TEXTO_T1.Add("FECHA");
Paragraph TEXTO_T2 = new Paragraph();
TEXTO_T2.Font = FontFactory.GetFont(FontFactory.TIMES, 9f, BaseColor.BLACK);
TEXTO_T2.Add("HORA");
Paragraph TEXTO_T3 = new Paragraph();
TEXTO_T3.Font = FontFactory.GetFont(FontFactory.TIMES, 9f, BaseColor.BLACK);
TEXTO_T3.Add("DESCRIPCION");
Paragraph TEXTO_CANT = new Paragraph();
TEXTO_CANT.Font = FontFactory.GetFont(FontFactory.TIMES, 9f, BaseColor.BLACK);
TEXTO_CANT.Add("CANT");
Phrase TEXTO_PRECIO = new Phrase("PRECIO", FontFactory.GetFont(FontFactory.TIMES, 9, BaseColor.BLACK));
PdfPCell PRECIO = new PdfPCell(TEXTO_PRECIO);
PRECIO.HorizontalAlignment = Element.ALIGN_RIGHT;
PRECIO.BackgroundColor = new BaseColor(224, 255, 255);
Phrase Titulo4 = new Phrase("MONTO", FontFactory.GetFont(FontFactory.TIMES, 9, BaseColor.BLACK));
PdfPCell TEXTO_T4 = new PdfPCell(Titulo4);
TEXTO_T4.HorizontalAlignment = Element.ALIGN_RIGHT;
TEXTO_T4.BackgroundColor = new BaseColor(224, 255, 255);
Phrase Titulo5 = new Phrase("USUARIO", FontFactory.GetFont(FontFactory.TIMES, 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[] { 75f, 50f, 30f, 200f, 30f, 55f, 55f, 50f };//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_CANT); table.AddCell(TEXTO_PRECIO); table.AddCell(TEXTO_T4); table.AddCell(TEXTO_T5);
table.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255);
//SQLiteDataReader RS = null;
//string POR_OPER = "SELECT NUM_FACT,FECHA,HORA,DESCRIPCION,SUM(VENTA*CANT) MONTO,USUARIO FROM ventas WHERE FECHA>= '" + Global.fecha_desdex + "' AND FECHA<= '" + Global.fecha_hastax + "' AND id_vendedor= " + Global.ID_vendedor + " GROUP BY NUM_FACT,FECHA,HORA,DESCRIPCION,USUARIO;";
//SQLiteCommand CMD_POR_OPER = new SQLiteCommand(POR_OPER, Global.conexion);
//RS = CMD_POR_OPER.ExecuteReader();
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/vendedores_reportar.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}", Global.fecha_desdex, Global.fecha_hastax, Global.ID_vendedor));
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 resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("
100)
{
MessageBox.Show(devuelve);
return;
}
if (Delete == 1) { MessageBox.Show(devuelve,"ÉXITO",MessageBoxButtons.OK,MessageBoxIcon.Information); }
}
private void label16_Click(object sender, EventArgs e)
{
dataGpedidos.Rows.Clear();
panel1.Visible = false;
}
private void dataGpedidos_Click(object sender, EventArgs e)
{
Cargar_Pedidos();
}
private void Txt_buscar_Leave(object sender, EventArgs e)
{
Txt_buscar.ForeColor = Color.Gray;
}
private void Txt_buscar_Enter(object sender, EventArgs e)
{
if (Txt_buscar.Text == "Escriba aquí")
{
Txt_buscar.Text = "";
}
Txt_buscar.ForeColor = Color.Black;
}
private void button1_Click(object sender, EventArgs e)
{
Txt_buscar.Select();
}
private void Ch_Consultar_CheckedChanged(object sender, EventArgs e)
{
if (Ch_Consultar.Checked == false)
{
Ch_Facturados.Checked = false;
}
Txt_buscar.Select();
//num_pedido = "";
}
private void dataGpedidos_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void Btn_Limpiar_Click(object sender, EventArgs e)
{
Txt_buscar.Text = ".";
Txt_buscar.Text = "";
Txt_nombre.Text = "";
Txt_doc.Text = "";
Txt_tel.Text = "";
lb_dir.Text = "";
ID_LABEL.Text = "";
Txt_DR.Text = "";
Txt_D_ADD.Text = "";
Txt_D_CIL.Text = "";
Txt_D_D.Text = "";
Txt_D_EJE.Text = "";
Txt_D_ESF.Text = "";
Txt_I_ADD.Text = "";
Txt_I_CIL.Text = "";
Txt_I_D.Text = "";
Txt_I_EJE.Text = "";
Txt_I_ESF.Text = "";
Txt_I_ESF.Text = "";
Txt_TIPO.Text = "";
Txt_COLOR.Text = "";
Txt_ALTURA_B.Text = "";
Txt_ALTURA_M.Text = "";
Txt_OBS.Text = "";
Lb_Total.Text = "";
Lb_Saldo.Text = "";
Txt_Entrega.Text = "";
Fecha_op.Text = DateTime.Now.ToString();
Fecha_Entrga.Text = DateTime.Now.ToString();
Ch_Consultar.Checked = false;
Btn_Guardar.Enabled = false;
//Btn_Limpiar.Enabled = false;
Btn_Eliminar.Enabled = false;
Btn_Facturar.Enabled = false;
Estado = "0";
t = 0;
Txt_Entrega.Enabled = true;
Txt_buscar.Enabled = true;
Txt_buscar.Select();
}
private void Eliminar_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("¿Confirma que realmente desea ELIMINAR este registro?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
return;
Eiliminar_Serv(1);
Btn_Limpiar_Click(null,null);
}
private void Btn_Facturar_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/optica_facturar.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼", num_pedido,Global.USUARIO_SIST));
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;
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
return;
}
MessageBox.Show(devuelve + "\n\nATENCIÓN: Ahora abra ''Ventas'' para crear la factura y cerrar la transacción.", "ATENCIÓN",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
////MUESTRA EL FORM VENTAS
if (Application.OpenForms["Ventas"] != null)
{
Application.OpenForms["Ventas"].Close();
}
//else
//{
// Ventas form = new Ventas();
// form.Show();
//}
Global.CerrarVenta = false;
//FIN DE MUESTRA VENTAS
this.Close();
}
private void Ch_Facturados_CheckedChanged(object sender, EventArgs e)
{
dataGpedidos.Rows.Clear();
panel1.Visible = false;
if (Ch_Facturados.Checked)
{
Ch_Consultar.Checked=true;
}
}
private void dataLista_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void Txt_Entrega_TextChanged(object sender, EventArgs e)
{
Saldo();
}
private void Entrega()
{
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/ingresar.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}", Global.NUM_caja, Global.USUARIO_SIST, "ENTREGA ADELANTO, PEDIDO No. " + num_pedido, Txt_Entrega.Text.Trim(), Txt_nombre.Text.Trim(), num_pedido, "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[] 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;
}
}
private void Licencia()
{
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/optica_reg_lic.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); // utf8_encode
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('▲');
string resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("
89)//SI EL REGISTRO TIENE 30 DÍGITOS...
{
string LicNum = Global.OpticaLic.Replace("xTz", "1");
LicNum = LicNum.Replace("QkU", "2");
LicNum = LicNum.Replace("oPi", "3");
LicNum = LicNum.Replace("YwB", "4");
LicNum = LicNum.Replace("lnI", "5");
LicNum = LicNum.Replace("CfL", "6");
LicNum = LicNum.Replace("VaZ", "7");
LicNum = LicNum.Replace("RgM", "8");
LicNum = LicNum.Replace("HsD", "9");
LicNum = LicNum.Replace("JuE", "0");
Global.OpticaLic = LicNum;
}
else
{
MessageBox.Show("Licencia inválida para el uso del sistema.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error);
panel5.Visible = true;
label23.Text = "Óptica - SERIE: " + Global.SerieServ;
return;
}
if (Global.OpticaLic.Length>29)//SI EL REGISTRO TIENE 30 DÍGITOS...
{
int fechalim = 0;
int Modulo = int.Parse(Global.OpticaLic.Substring(0, 4));
if (Modulo != 102)//SI EL MÓDULO NO ES
{
MessageBox.Show("La licencia del modulo no corresponde.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error);
panel5.Visible = true;
Titulo_Lic.Text = "Óptica - SERIE: " + Global.SerieServ;
return;
}
if (Global.OpticaLic.Substring(4, 15) != Global.SerieServ)//SI LOS 15 DÍGITOS NO SON IGUALES A LA SERIE DEL SERVIDOR...
{
MessageBox.Show("Licencia vencida o no es correcta.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error);
panel5.Visible = true;
Titulo_Lic.Text = "Óptica - SERIE: " + Global.SerieServ;
return;
}
else//SI EL REGISTRO CORRECPONDE A LA SERIE DE LA PC...
{
//CONSULTA LA VALIDÉZ DE LA FECHA**
fechalim = int.Parse(Global.OpticaLic.Substring(22, 8));
//SI EL REGISTRO.FECHA ES IGUAL A LA SERIE.FECHA (20210321)...
if (Global.fechahoy > fechalim)
{
MessageBox.Show("Licencia vencida.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error);
panel5.Visible = true;
Titulo_Lic.Text = "Óptica - SERIE: " + Global.SerieServ;
return;
}
}
panel5.Visible = false;
string fechaL = Global.OpticaLic.Substring(22, 8);
label6.Text = "Óptica - v.01.22.10.12 - Licencia de uso hasta el " + fechaL.Substring(6, 2) + "-" + fechaL.Substring(4, 2) + "-" + fechaL.Substring(0, 4);
}
else
{
MessageBox.Show("Licencia inválida para el uso del sistema.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error);
panel5.Visible = true;
Titulo_Lic.Text = "Óptica - SERIE: " + Global.SerieServ;
return;
}
}
private void Btn_Historial_Click(object sender, EventArgs e)
{
{
string Fecha = DateTime.Today.ToString("dd-MM-yy");
//CREAR PDF
string pdfgenerate = "\\DOC_PDF\\OPTICA\\" + DateTime.Now.ToString("dd-MM-yy") + "_" + DateTime.Now.ToString("HH-mm") + "_HISTORIAL.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)
iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("logo.png", true);
logo.CompressionLevel = PdfStream.NO_COMPRESSION;
//logo.SetAbsolutePosition(60, top1 - 130);
oDoc.Add(logo);
}
catch (Exception) { }
Global.TotalRp = 0;
cb = pdfw.DirectContent;//DEBE IR ANTES DE LAS LÍNEAS DE TEXTO
// Creamos un titulo personalizado con tamaño de fuente 10 y color Azul
Paragraph title = new Paragraph();
title.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 10f, BaseColor.BLACK);
title.Add("HISTORIAL DE SERVICIOS: CLIENTE " + Txt_nombre.Text + ", RUC o CI " + Txt_doc.Text +
"\nInforme confeccionado el " + DateTime.Now.ToString() + ".");
title.Alignment = Element.ALIGN_LEFT;
oDoc.Add(title);
PdfPTable table = new PdfPTable(8);
PdfPTable table2 = new PdfPTable(8);
table.HorizontalAlignment = 0;
table.TotalWidth = 545f;
table.LockedWidth = true;
float[] widthsx = new float[] { 40, 40, 60, 50, 25, 163, 45, 45, };
table.SetWidths(widthsx);
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/optica_historial.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", ID_LABEL.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('▲');
string resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("
0)
{
string variable;
string[] rows;
variable = v[0];//2022/10/01
rows = variable.Split('-');
FechaO = rows[2] + "-" + rows[1] + "-" + rows[0];//string.Format("{0:dd-MM-yyyy}", v[0]);
}
if (v[1].Trim().Length > 0)
{
string variable2;
string[] rows2;
variable2 = v[1];//2022/10/01
rows2 = variable2.Split('-');
FechaE = rows2[2] + "-" + rows2[1] + "-" + rows2[0];//string.Format("{0:dd-MM-yyyy}", v[1]);
}
Paragraph fecha = new Paragraph();
fecha.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK);
fecha.Add(FechaO);
Paragraph Fecha_en = new Paragraph();
Fecha_en.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK);
Fecha_en.Add(FechaE);
Paragraph Doctor = new Paragraph();
Doctor.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK);
Doctor.Add(v[2]);
Paragraph Operador = new Paragraph();
Operador.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK);
Operador.Add(v[3]);
Paragraph cant = new Paragraph();
cant.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK);
cant.Add(v[4]);
Paragraph prod = new Paragraph();
prod.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK);
prod.Add(v[5]);
Phrase Precio = new Phrase(double.Parse(v[6]).ToString("#,###.##"), FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK));
PdfPCell precio = new PdfPCell(Precio);
precio.BorderColor = new BaseColor(255, 255, 255);
precio.HorizontalAlignment = Element.ALIGN_RIGHT;
//precio.BackgroundColor = new BaseColor(224, 255, 255);
Phrase Monto = new Phrase(double.Parse(v[7]).ToString("#,###.##"), FontFactory.GetFont(FontFactory.DefaultEncoding, 8, BaseColor.BLACK));
PdfPCell monto = new PdfPCell(Monto);
monto.BorderColor = new BaseColor(255, 255, 255);
monto.HorizontalAlignment = Element.ALIGN_RIGHT;
//monto.BackgroundColor = new BaseColor(224, 255, 255);
table.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255);
table.DefaultCell.BorderColor = new iTextSharp.text.BaseColor(255, 255, 255);//211, 211, 211
table.AddCell(fecha); table.AddCell(Fecha_en); table.AddCell(Doctor);
table.AddCell(Operador); table.AddCell(cant); table.AddCell(prod); table.AddCell(precio); table.AddCell(monto);
//Global.TotalRp = Global.TotalRp + double.Parse(v[7]);
}
}
////TOTAL DE VENTA QUE SALE EN LA CABECERA
//Paragraph title2 = new Paragraph();
//title2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 14, BaseColor.BLUE);
//title2.Add("Declarado " + Global.SIMB_ + " " + double.Parse(Global.mon_declarado).ToString("#,##0.##") + ".\n" +
// "Según computo " + Global.SIMB_ + " " + Global.TotalRp.ToString("#,##0.##") + "\n" +
// "Diferencia " + Global.SIMB_ + " " + (double.Parse(Global.mon_declarado) - Global.TotalRp).ToString("#,##0.##"));
//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);
//RS.Close();
pdfw.Flush();
oDoc.Close();
System.Diagnostics.Process.Start(@pdfgenerate);//MUESTRA EL REPORTE EN PDF
}
}
private void button3_Click(object sender, EventArgs e)
{
//DEVOLVIENDO EN NÚMEROS LAS LETRAS REGISTRADAS
//string Encrip1 = Lic.Text.Trim().Replace("XT", "1");
//string Encrip2 = Encrip1.Replace("Q!K", "2");
//string Encrip3 = Encrip2.Replace("OP#", "3");
//string Encrip4 = Encrip3.Replace("Y$W", "4");
//string Encrip5 = Encrip4.Replace("NI%", "5");
//string Encrip6 = Encrip5.Replace("C&F", "6");
//string Encrip7 = Encrip6.Replace("AZ/", "7");
//string Encrip8 = Encrip7.Replace("R(G", "8");
//string Encrip9 = Encrip8.Replace("SD)", "9");
//string Encrip10 = Encrip9.Replace("U=E", "0");
string LicNum = Lic.Text.Trim();
if (LicNum.Length > 89)
{
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/optica_reg_lic.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", LicNum));
rq.ContentType = "application/x-www-form-urlencoded";
rq.ContentLength = byteArray.Length;
Stream stream = rq.GetRequestStream();
stream.Write(byteArray, 0, byteArray.Length); // utf8_encode
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('▲');
string resultado = devuelve.ToUpper();
bool re;
re = resultado.Contains("