using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using Image = System.Drawing.Image;
using ImageI = iTextSharp.text.Image;
using System.Data.SQLite;
using System.Net;
using System.Text.RegularExpressions;
using iTextSharp.text.pdf.parser;
using Microsoft.Web.XmlTransform;
using Org.BouncyCastle.Ocsp;
using System.Security.Cryptography;
using ECV;
namespace CKUERA
{
public partial class Productos : Form
{
public Productos()
{
InitializeComponent();
}
int vecesRUC = 0;
int vecesPROV_RUC=0;
int vecesPROV_RUC_cambio=0;
static int id_prov=0;
private void RutaImagenes()
{
var request = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/direcc.php");
//request.UserAgent = "curl";
request.Method = "GET";
string Direccion;
using (WebResponse response = request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
Direccion = reader.ReadToEnd();
}
}
Ruta_img.Text = Direccion.Replace("\n", "").Trim() + "/ecv/imagenes";
}
private void Productos_Load(object sender, EventArgs e)
{
Global.L_CompraProv = "";
Global.L_CompraRUC = "";
RutaImagenes();
No_Buscar.Left = 3000;
COD_TEMP.Left = 3000;
DataG2.Left = 3000;
label16.Left = 3000;
pa_Transfer.Left = 3000;
button5.Left = 3000;
button7.Left = 3000;
//DataG1.Left = 3000;
//mensaje_lab.Left = 3000;
Principal principal = new Principal();
principal.ActualizarProductos();
DataG1.Left = textBox9.Left;
DataG1.Top = textBox9.Top + textBox9.Height+2;
DataG1.Width = 598;
DataG1.Height = 266;
Vence.Text = "31/12/2100";
if (Global.Boton10 == "Óptica")
{
Label4.Text = "Modelo, Calibre, Color";
}
//Global.version = "2";
if (int.Parse(Global.version.ToString()) < 2)//versión menos de 2 no muestra
{
Rec2.Enabled = false;
Precio2.Enabled = false;
Rec3.Enabled = false;
Precio3.Enabled = false;
Apartir2.Enabled = false;
Apartir3.Enabled = false;
Btn_Tr.Enabled = false;
Btn_compras.Enabled = false;
}
else
{
Rec2.Enabled = true;
Precio2.Enabled = true;
Rec3.Enabled = true;
Precio3.Enabled = true;
Apartir2.Enabled = true;
Apartir3.Enabled = true;
Btn_Tr.Enabled = true;
Btn_compras.Enabled = true;
if (Global.USUARIO_SIST.Length > 2)
{
if (Global.US_REG_COMP == 1 || Global.USUARIO_RANGO == "Administrador")
{
Btn_compras.Enabled = true;
}
else
{
Btn_compras.Enabled = false;
}
}
}
{
string name = "iconos\\registrar.png";
try { Button1.Image = System.Drawing.Image.FromFile(name); }
catch (Exception) { }
}
{
string name = "iconos\\modificar.png";
try { Button4.Image = System.Drawing.Image.FromFile(name); }
catch (Exception) { }
}
{
string name = "iconos\\limpiar.png";
try { Button2.Image = System.Drawing.Image.FromFile(name); }
catch (Exception) { }
}
{
string name = "iconos\\eliminar.png";
try { Button3.Image = System.Drawing.Image.FromFile(name); }
catch (Exception) { }
}
{
string name = "iconos\\reportar.png";
try { button6.Image = System.Drawing.Image.FromFile(name); }
catch (Exception) { }
}
{
string name = "imagen.png";
try { pictureBox1.Image = System.Drawing.Image.FromFile(name); }
catch (Exception) { }
}
}
private void Productos_Resize(object sender, EventArgs e)
{
Principal fp = new Principal();
panel1.Left = this.Width/2-panel1.Width/2;
panel1.Top = this.Height / 2 - panel1.Height / 2;
Button1.BackColor = this.BackColor = Global.ColorSistema;//
Button2.BackColor = this.BackColor = Global.ColorSistema;//
Button3.BackColor = this.BackColor = Global.ColorSistema;//
Button4.BackColor = this.BackColor = Global.ColorSistema;//
button6.BackColor = this.BackColor = Global.ColorSistema;//
Btn_compras.BackColor = Global.ColorSistema;
btn_Lista_precio.BackColor = Global.ColorSistema;
pictureBox1.Top = Txt_timbrado.Top + Txt_timbrado.Height + 10;
pictureBox1.Left = ComboBox5.Left;
pictureBox1.Width = 593;//ComboBox5.Width;
Btn_Cerrar.Top = 0;
Btn_Cerrar.Left = panel1.Width - Btn_Cerrar.Width;
Lb_Titulo.Top = 0; Lb_Titulo.Left = 0;
Lb_Titulo.Text = this.Text;
}
private void TextBox1_TextChanged_1(object sender, EventArgs e)
{
if (TextBox1.Text.Length > 150)
{
MessageBox.Show("No se permite texto mayor a 150 dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
TextBox1.Text = TextBox1.Text.Substring(0, 150);
TextBox1.SelectionStart = TextBox1.Text.Length + 1;
}
if (RadioButton1.Checked == false)
{
if (RadioButton2.Checked == false)
{
MessageBox.Show("Seleccione una opción de lo que desea hacer; ''Registrar nuevo'' o ''Modificar Registro''");
return;
}
}
if (RadioButton2.Checked == true)
{
if (TextBox1.Text == "") { No_Buscar.Checked = false; }
if (No_Buscar.Checked == true) { return; }
DataG1.Rows.Clear();//VACÍA EL DATAGRID
string filtro = TextBox1.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,"",""));
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();
if (devuelve != "")
{
DataG1.Visible = true;
foreach (var line in devuelve.Split('↔'))
{
if (string.IsNullOrWhiteSpace(line))
continue;
var valores = line.Split('▲');
DataG1.Rows.Add(valores[0], valores[2], valores[1]);
}
}
else
{
DataG1.Visible = false;
}
}
}
private void Button1_Click_1(object sender, EventArgs e)
{
if (DataG2.Visible == true)//DATAGRID DINÁMICO
{
AccionDataG2();//LLENA LOS DATOS DE ACUERDO A LA POSICIÓN
DataG2.Visible = false;
}
if (RadioButton1.Checked == false & RadioButton2.Checked == false)
{
MessageBox.Show("Marque una opción de lo que desea hacer; Registrar Nuevo o Modificar Registro", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox9.Select();
return;
}
if (textBox9.Text == "")
{
textBox9.Select();
return;
}
Llenar_cero();
string codigox = textBox9.Text; //cons_temp_usu.php
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/consultar_prod_x_cod.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", codigox));
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('▲');
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
return;
}
if (devuelve != "")
{
if (c[2] != "")
{
MessageBox.Show("Este Código ya está registrado y pertenece al producto " + c[2]);
textBox9.Select();
return;
}
}
//ValidarCampos();
if (TextBox1.Text == "")
{
TextBox1.Select();
return;
}
TextBox1.Text = TextBox1.Text.Replace("&", "y");
TextBox1.Text = TextBox1.Text.Replace("'", "`");
TextBox1.Text = TextBox1.Text.Replace(";", ",");
TextBox1.Text = TextBox1.Text.Replace("\\", ",");
if (Regex.IsMatch(TextBox1.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);
TextBox1.Select();
return;
}
if (ComboBox1.Text == "")
{
ComboBox1.Select();
return;
}
ComboBox1.Text = ComboBox1.Text.Replace("&", "y");
ComboBox1.Text = ComboBox1.Text.Replace("'", "`");
ComboBox1.Text = ComboBox1.Text.Replace(";", ",");
ComboBox1.Text = ComboBox1.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox1.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);
ComboBox1.Select();
return;
}
if (ComboBox2.Text == "")
{
ComboBox2.Select();
return;
}
ComboBox2.Text = ComboBox2.Text.Replace("&", "y");
ComboBox2.Text = ComboBox2.Text.Replace("'", "`");
ComboBox2.Text = ComboBox2.Text.Replace(";", ",");
ComboBox2.Text = ComboBox2.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox2.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);
ComboBox2.Select();
return;
}
if (ComboBox4.Text == "")
{
ComboBox4.Select();
return;
}
ComboBox4.Text = ComboBox4.Text.Replace("&", "y");
ComboBox4.Text = ComboBox4.Text.Replace("'", "`");
ComboBox4.Text = ComboBox4.Text.Replace(";", ",");
ComboBox4.Text = ComboBox4.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox4.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);
ComboBox4.Select();
return;
}
if (ComboBox3.Text == "")
{
ComboBox3.Select();
return;
}
ComboBox3.Text = ComboBox3.Text.Replace("&", "y");
ComboBox3.Text = ComboBox3.Text.Replace("'", "`");
ComboBox3.Text = ComboBox3.Text.Replace(";", ",");
ComboBox3.Text = ComboBox3.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox3.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);
ComboBox3.Select();
return;
}
if (TextBox2.Text == "")
{
TextBox2.Select();
return;
}
TextBox2.Text = TextBox2.Text.Replace("&", "y");
TextBox2.Text = TextBox2.Text.Replace("'", "`");
TextBox2.Text = TextBox2.Text.Replace(";", ",");
TextBox2.Text = TextBox2.Text.Replace("\\", ",");
if (Regex.IsMatch(TextBox2.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);
TextBox2.Select();
return;
}
if (TextBox5.Text == "")
{
TextBox5.Select();
return;
}
//CARACTYERES PERMITIDOS
if (TextBox5.Text != "10")
{
if (TextBox5.Text != "0")
{
if (TextBox5.Text != "00")
{
if (TextBox5.Text != "5")
{
if (TextBox5.Text != "05")
{
MessageBox.Show("Valor de IVA no es correcto. Debe ser 0, 05, o 10");
TextBox5.Select();
return;
}
}
}
}
}
if (txtPrecioComp.Text == "" || txtPrecioComp.Text == ".")
{
txtPrecioComp.Select();
return;
}
if (textRec1.Text == "" || textRec1.Text == ".")
{
textRec1.Select();
return;
}
if (txtVenta1.Text == "" || txtVenta1.Text == ".")
{
txtVenta1.Select();
return;
}
if (int.Parse(Global.version.ToString()) > 1)//versión menos de 2 no muestra
{
if (Rec2.Text == "" || Rec2.Text == ".")
{
Rec2.Select();
return;
}
if (Precio2.Text == "" || Precio2.Text == ".")
{
Precio2.Select();
return;
}
if (Apartir2.Text == "" || Apartir2.Text == ".")
{
Apartir2.Select();
return;
}
if (Rec3.Text == "" || Rec3.Text == ".")
{
Rec3.Select();
return;
}
if (Precio3.Text == "" || Precio3.Text == ".")
{
Precio3.Select();
return;
}
if (Apartir3.Text == "" || Apartir3.Text == ".")
{
Apartir3.Select();
return;
}
}
else
{
Rec2.Text = textRec1.Text;
Precio2.Text = txtVenta1.Text;
Rec3.Text = textRec1.Text;
Precio3.Text = txtVenta1.Text;
Apartir2.Text = "100";
Apartir3.Text = "200";
}
if (TextBox7.Text == "")
{
TextBox7.Text = "";
}
ComboBox5.Text = ComboBox5.Text.Replace("&", "y");
ComboBox5.Text = ComboBox5.Text.Replace("'", "`");
ComboBox5.Text = ComboBox5.Text.Replace(";", ",");
ComboBox5.Text = ComboBox5.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox5.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);
ComboBox5.Select();
return;
}
if (ComboBox5.Text == "")
{
ComboBox5.Select();
return;
}
Reemplazar();
string pdcX;
if (PDC1.Checked == true)
{
pdcX = "1";
}
else
{
pdcX = "0";
}
if (Vence.Text == "31/12/2100")
{
DialogResult result = MessageBox.Show("¿Confirma que el vencimiento es correcto?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
{
Vence.Select();
return;
}
else { Vence.Text = "30/12/2100"; }
}
string editarRegComp = "0";
if (chec_Compras.Checked == true)
{
if (ComboBox5.Text == "")
{
MessageBox.Show("Seleccione un proveedor.");
ComboBox5.Focus();
return;
}
if (Txt_RUC.Text == "")
{
MessageBox.Show("Escriba un RUC para este proveedor.");
Txt_RUC.Focus();
return;
}
if (Global.L_CompraProv != "")
{
if (Global.L_CompraProv != ComboBox5.Text.Trim())
{
MessageBox.Show("El registro de Compras no puede continuar con este Proveedor. Cambie a " + Global.L_CompraProv);
return;
}
}
if (Global.L_CompraRUC != "")
{
if (Global.L_CompraRUC != Txt_RUC.Text.Trim())
{
MessageBox.Show("El registro de Compras no puede continuar con este RUC del Proveedor. Cambie a " + Global.L_CompraRUC);
return;
}
}
if (Txt_RUC.Text.Length < 6)
{
MessageBox.Show("Verifique si el RUC para este proveedor es correcto.");
Proveedor proveedor = new Proveedor();
proveedor.Com_proveedor.Text = ComboBox5.Text.Trim();
proveedor.Txt_RUC.Text = Txt_RUC.Text.Trim();
proveedor.label_id.Text = id_prov.ToString();
proveedor.ShowDialog();
ComboBox5.Text = "";
Txt_RUC.Text = "";
return;
}
string pattern0 = @"^\d+-\d$";
string input0 = Txt_RUC.Text;
if (!Regex.IsMatch(input0, pattern0))
{
if (vecesRUC == 0)
{
MessageBox.Show("Verifique el formato del RUC. Debe ser ''123456-9''");
Txt_RUC.Focus();
vecesRUC = 1;
Proveedor proveedor = new Proveedor();
proveedor.Com_proveedor.Text = ComboBox5.Text.Trim();
proveedor.Txt_RUC.Text = Txt_RUC.Text.Trim();
proveedor.label_id.Text = id_prov.ToString();
proveedor.ShowDialog();
ComboBox5.Text = "";
Txt_RUC.Text = "";
return;
}
}
if (vecesPROV_RUC == 0)
{
DialogResult result = MessageBox.Show("¿Confirma que PROVEEDOR y RUC son correctos?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) return;
Global.L_CompraProv = ComboBox5.Text.Trim();
Global.L_CompraRUC = Txt_RUC.Text.Trim();
vecesPROV_RUC = 1;
}
if (Txt_FactNum.Text == "")
{
MessageBox.Show("Escriba el número de la factura para esta compra.");
Txt_FactNum.Focus();
return;
}
string serie = Txt_FactNum.Text.Substring(0, 3);
string subSerie = Txt_FactNum.Text.Substring(3, 3);
string numero = Txt_FactNum.Text.Substring(6, 7);
if (Txt_timbrado.Text == "")
{
MessageBox.Show("Escriba el timbrado de la factura para esta compra.");
Txt_timbrado.Focus();
return;
}
editarRegComp = "1";
}
if (Txt_RUC.Text == "")
{
Txt_RUC.Focus();
return;
}
string[] rows;
rows = Vence.Text.Split('/');
string Vencex = rows[2] + "-" + rows[1] + "-" + rows[0];
//string Vencex = Vence.Text.Substring(6, 4) + "-" + Vence.Text.Substring(3, 2) + "-" + Vence.Text.Substring(0, 2);
string codigo = textBox9.Text;
string descripcion = TextBox1.Text;
string compra = txtPrecioComp.Text;
string rec = textRec1.Text;
string venta = txtVenta1.Text;
string prov = ComboBox5.Text + " | " + Txt_RUC.Text;
string stock = TextBox2.Text;
string perdida = TextBox7.Text;
string otro = ComboBox3.Text;
string secc = ComboBox1.Text;
string sub_secc = ComboBox2.Text;
string marca = ComboBox4.Text;
string iva = TextBox5.Text;
string pdc1 = pdcX;
string rec2 = Rec2.Text;
string rec3 = Rec3.Text;
string venta2 = Precio2.Text;
string venta3 = Precio3.Text;
string apartir2 = Apartir2.Text;
string apartir3 = Apartir3.Text;
this.Cursor = Cursors.WaitCursor;//CURSOR ESPERE...
string timbrado = Txt_timbrado.Text.Trim();
string factnum = Txt_FactNum.Text.Trim();
string ruc = Txt_RUC.Text.Trim();
float cant = float.Parse(TextBox2.Text);
HttpWebRequest rq2 = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/insert_productos.php");
rq2.Method = "POST";
byte[] byteArray2 = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}▼{7}▼{8}▼{9}▼{10}▼{11}▼{12}▼{13}▼{14}▼{15}▼{16}▼{17}▼{18}▼{19}▼{20}▼{21}▼{22}▼{23}▼{24}▼{25}▼{26}▼{27}", codigo, descripcion, compra, rec, venta, prov, stock, perdida, otro, secc, sub_secc, marca, iva, pdc1, rec2, rec3, venta2, venta3, apartir2, apartir3,Vencex, cant, Global.USUARIO_SIST, ruc, factnum, timbrado, editarRegComp,id_prov));
rq2.ContentType = "application/x-www-form-urlencoded";
rq2.ContentLength = byteArray2.Length;
Stream stream2 = rq2.GetRequestStream();
stream2.Write(byteArray2, 0, byteArray2.Length);
stream2.Close();
//
WebResponse response2 = rq2.GetResponse();
stream2 = response2.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
string devuelve2 = reader2.ReadToEnd();
reader2.Close();
stream2.Close();
response2.Close();
this.Cursor = Cursors.Default;//CURSOR NORMAL
if (devuelve2.ToUpper().Contains("WARNING"))
{
MessageBox.Show(devuelve2);
return;
}
if (devuelve2.Contains("Este proveedor no existe"))
{
MessageBox.Show(devuelve2);
Proveedor proveedor = new Proveedor();
proveedor.Com_proveedor.Text = ComboBox5.Text.Trim();
proveedor.Txt_RUC.Text = Txt_RUC.Text;
proveedor.ShowDialog();
ComboBox5.Text = "";
Txt_RUC.Text = "";
ComboBox5.Focus();
return;
}
MessageBox.Show(devuelve2);
if(devuelve2.Contains("Este artículo ya existe en el Registro de Compras"))
{
MessageBox.Show(devuelve2);
return;
}
Limpiar();
RadioButton1.Checked = true;
textBox9.Select();
}
public void Reemplazar()
{
textBox9.Text = textBox9.Text.Trim().ToUpper().Replace("'", "´");
TextBox1.Text = TextBox1.Text.Trim().ToUpper().Replace("'", "´");
TextBox2.Text = TextBox2.Text.Trim().ToUpper().Replace("'", "´");
TextBox3.Text = TextBox3.Text.Trim().ToUpper().Replace("'", "´");
txtPrecioComp.Text = txtPrecioComp.Text.Trim().ToUpper().Replace("'", "´");
TextBox5.Text = TextBox5.Text.Trim().ToUpper().Replace("'", "´");
ComboBox1.Text = ComboBox1.Text.Trim().ToUpper().Replace("'", "´");
ComboBox2.Text = ComboBox2.Text.Trim().ToUpper().Replace("'", "´");
ComboBox3.Text = ComboBox3.Text.Trim().ToUpper().Replace("'", "´");
ComboBox4.Text = ComboBox4.Text.Trim().ToUpper().Replace("'", "´");
ComboBox5.Text = ComboBox5.Text.Trim().ToUpper().Replace("'", "´");
textBox9.SelectionStart = textBox9.Text.Length + 1;
TextBox1.SelectionStart = TextBox1.Text.Length + 1;
TextBox2.SelectionStart = TextBox2.Text.Length + 1;
TextBox3.SelectionStart = TextBox3.Text.Length + 1;
txtPrecioComp.SelectionStart = txtPrecioComp.Text.Length + 1;
TextBox5.SelectionStart = TextBox5.Text.Length + 1;
txtVenta1.SelectionStart = txtVenta1.Text.Length + 1;
TextBox7.SelectionStart = TextBox7.Text.Length + 1;
textRec1.SelectionStart = textRec1.Text.Length + 1;
ComboBox1.SelectionStart = ComboBox1.Text.Length + 1;
ComboBox2.SelectionStart = ComboBox2.Text.Length + 1;
ComboBox3.SelectionStart = ComboBox3.Text.Length + 1;
ComboBox4.SelectionStart = ComboBox4.Text.Length + 1;
ComboBox5.SelectionStart = ComboBox5.Text.Length + 1;
}
public void Limpiar()
{
textBox9.Text = "";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
txtPrecioComp.Text = "";
TextBox5.Text = "";
txtVenta1.Text = "";
TextBox7.Text = "";
textRec1.Text = "";
ComboBox1.Text = "";
ComboBox2.Text = "";
ComboBox3.Text = "";
ComboBox4.Text = "";
label16.Text = "";
Rec2.Text = "";
Rec3.Text = "";
Precio2.Text = "";
Precio3.Text = "";
Apartir2.Text = "";
Apartir3.Text = "";
ID_Label.Text = "";
DataG1.Visible = false;
DataG2.Visible = false;
PDC1.Checked = true;
No_Buscar.Checked = false;
Vence.Text="31/12/2100";
TextBox1.Select();
pictureBox1.Image = Image.FromFile("imagen.png");
if (chec_Compras.Checked == false & chec_ModComp.Checked == false & chec_ElimComp.Checked == false) {
Txt_RUC.Text = "";
Txt_FactNum.Text = "";
Txt_timbrado.Text = "";
ComboBox5.Text = "";
chec_ElimComp.Checked = false; chec_ModComp.Checked = false; chec_Compras.Checked = false;
}
}
private void button5_Click(object sender, EventArgs e)
{
Close();
}
private void textBox9_TextChanged_1(object sender, EventArgs e)//CODIGO
{
textBox9.Text = textBox9.Text.Replace("&", "y");
textBox9.Text = textBox9.Text.Replace("'", "`");
textBox9.Text = textBox9.Text.Replace(";", ",");
textBox9.Text = textBox9.Text.Replace("\\", ",");
textBox9.SelectionStart= textBox9.Text.Length+1;
if (Regex.IsMatch(textBox9.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);
textBox9.Select();
return;
}
if (textBox9.Text.Length > 15)
{
MessageBox.Show("No se permite código mayor a 15 dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
textBox9.Text = textBox9.Text.Substring(0, 15);
textBox9.SelectionStart = textBox9.Text.Length + 1;
}
if (RadioButton1.Checked == false)
{
if (RadioButton2.Checked == false)
{
MessageBox.Show("Seleccione una opción de lo que desea hacer; ''Registrar nuevo'' o ''Modificar Registro''", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
}
private void BuscarConsultarValidar()
{
// SI UNO U OTRO ESTÁ SELECCIONADO
if (RadioButton1.Checked == true | RadioButton2.Checked == true)
{
//if (textBox9.Text.Length < 7 & textBox9.Text.Length > 0)
//{ //AGREGA CERO, LAS CANTIDAD QUE HAGA FALTA
// while (!(textBox9.Text.Length == 7))
// {
// textBox9.Text = "0" + textBox9.Text;
// }
//}
//SI ESTÁ EN NO BUSCAR PASA EL CODIGO EN EL CAMPO DE NOMBRE
if (textBox9.Text.Length > 7) { if (No_Buscar.Checked == false) { TextBox1.Text = textBox9.Text; }; }
}
string filtro = textBox9.Text;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/consultar_prod_x_cod.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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('▲');
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
return;
}
//SI ESTÁ OPCION REGISTRAR NUEVO
if (RadioButton1.Checked == true)
{
if (devuelve != "")
{
MessageBox.Show("Este código ya está registrado para el producto " + c[1], "¡ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox9.Text = "";
textBox9.Select();
return;
}
}
//SI ESTA SELECCIONADO EN LA OPCIÓN MODIFICAR
if (RadioButton2.Checked == true)
{
if (No_Buscar.Checked == false)
{
if (devuelve != "")
{
ID_Label.Text = c[0];//ID
TextBox1.Text = c[1];//DESCRIPCION
textBox9.Text = c[2];//CODIGO
COD_TEMP.Text = c[2];//CODIGO
txtPrecioComp.Text = c[3];//COMPRA
textRec1.Text = c[4];//REC
txtVenta1.Text = c[5];//VENTA
TextBox3.Text = c[7];//STOCK
//TextBox7.Text = c[8);//BAJA DE STOCK
ComboBox3.Text = c[9];//OTRO
ComboBox1.Text = c[10];//SECC
ComboBox2.Text = c[11];//SUB_SECC
ComboBox4.Text = c[12];//MARCA
TextBox5.Text = c[13];//IVA
if(Global.L_CompraProv=="") ComboBox5.Text = c[6];//PROV
if (c[14] == "0") { PDC1.Checked = false; } else { PDC1.Checked = true; }
Rec2.Text = c[15];//RECARGO2
Rec3.Text = c[16];//PRECIO2
Precio2.Text = c[17];//RECARGO3
Precio3.Text = c[18];//PRECIO3
Apartir2.Text = c[19];//APARTIR DE... APLICA PRECIO2
Apartir3.Text = c[20];//APARTIR DE... APLICA PRECIO3
Vence.Text = c[21];//VENCIMIENTO
DataG1.Visible = false;
DataG2.Visible = false;
No_Buscar.Checked = true;
textBox9.Select();
label16.Text = "Margen " + string.Format("{0:#,##0.##}", double.Parse(txtVenta1.Text) - double.Parse(txtPrecioComp.Text));
No_Buscar.Checked = true;
}
if (Precio2.Text == "0") { Precio2.Text = txtVenta1.Text; }
if (Precio3.Text == "0") { Precio3.Text = txtVenta1.Text; }
//MUESTRA LA IMAGEN
pictureBox1.ImageLocation = "http://" + Global._host + "/ecv/imagenes/" + textBox9.Text + ".jpg";
}
}
}
private void RadioButton2_CheckedChanged_1(object sender, EventArgs e)
{
Limpiar();
if (RadioButton2.Checked == true)
{
this.AcceptButton = Button4;
TextBox1.Select();
Label8.Visible = true;
}
else
{
Label8.Visible = false;
}
}
private void Llenar_cero()
{
if (textBox9.Text.Length < 7 & textBox9.Text.Length > 0)
{ //AGREGA CERO, LAS CANTIDAD QUE HAGA FALTA
while (!(textBox9.Text.Length == 7))
{
textBox9.Text = "0" + textBox9.Text;
}
}
}
private void Button4_Click_1(object sender, EventArgs e)
{
if (DataG1.Visible == true)//DATAGRID DE PRODUCTOS
{
AccionDataG1();//RELLENA LOS DATOS DE PRODUCTOS
//DataG1.Visible = false;
}
if (DataG2.Visible == true)//DATAGRID DINÁMICO
{
AccionDataG2();//LLENA LOS DATOS DE ACUERDO A LA POSICIÓN
DataG2.Visible = false;
}
if (textBox9.Text == "")
{
textBox9.Select();
return;
}
Llenar_cero();
BuscarConsultarValidar();
if (COD_TEMP.Text != textBox9.Text)//SI SE CAMBIA EL CODIGO CONSULTA EL NUEVO CÓDIGO PROPUESTO
{
if (ID_Label.Text.Length > 0)
{
string codigox = textBox9.Text; //cons_temp_usu.php
HttpWebRequest rqx = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/consultar_prod_x_cod.php");
rqx.Method = "POST";
byte[] byteArrayx = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", codigox));
rqx.ContentType = "application/x-www-form-urlencoded";
rqx.ContentLength = byteArrayx.Length;
Stream streamx = rqx.GetRequestStream();
streamx.Write(byteArrayx, 0, byteArrayx.Length);
streamx.Close();
//
WebResponse responsex = rqx.GetResponse();
streamx = responsex.GetResponseStream();
StreamReader readerx = new StreamReader(streamx);
string devuelvex = readerx.ReadToEnd();
readerx.Close();
streamx.Close();
responsex.Close();
string[] cx = devuelvex.Split('▲');
if (cx[0].Length > 100)
{
MessageBox.Show(devuelvex);
return;
}
if (devuelvex != "")
{
if (cx[2] != "")
{
MessageBox.Show("Este Código ya está registrado y pertenece al producto " + cx[1]);
textBox9.Select();
return;
}
}
}
}
if (TextBox1.Text == "")
{
TextBox1.Select();
return;
}
TextBox1.Text = TextBox1.Text.Replace("&", "y");
TextBox1.Text = TextBox1.Text.Replace("'", "`");
TextBox1.Text = TextBox1.Text.Replace(";", ",");
TextBox1.Text = TextBox1.Text.Replace("\\", ",");
if (Regex.IsMatch(TextBox1.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);
TextBox1.Select();
return;
}
if (ComboBox1.Text == "")
{
ComboBox1.Select();
return;
}
ComboBox1.Text = ComboBox1.Text.Replace("&", "y");
ComboBox1.Text = ComboBox1.Text.Replace("'", "`");
ComboBox1.Text = ComboBox1.Text.Replace(";", ",");
ComboBox1.Text = ComboBox1.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox1.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);
ComboBox1.Select();
return;
}
if (ComboBox2.Text == "")
{
ComboBox2.Select();
return;
}
ComboBox2.Text = ComboBox2.Text.Replace("&", "y");
ComboBox2.Text = ComboBox2.Text.Replace("'", "`");
ComboBox2.Text = ComboBox2.Text.Replace(";", ",");
ComboBox2.Text = ComboBox2.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox2.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);
ComboBox2.Select();
return;
}
if (ComboBox4.Text == "")
{
ComboBox4.Select();
return;
}
ComboBox4.Text = ComboBox4.Text.Replace("&", "y");
ComboBox4.Text = ComboBox4.Text.Replace("'", "`");
ComboBox4.Text = ComboBox4.Text.Replace(";", ",");
ComboBox4.Text = ComboBox4.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox4.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);
ComboBox4.Select();
return;
}
if (ComboBox3.Text == "")
{
ComboBox3.Select();
return;
}
ComboBox3.Text = ComboBox3.Text.Replace("&", "y");
ComboBox3.Text = ComboBox3.Text.Replace("'", "`");
ComboBox3.Text = ComboBox3.Text.Replace(";", ",");
ComboBox3.Text = ComboBox3.Text.Replace("\\", ",");
if (Regex.IsMatch(ComboBox3.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);
ComboBox3.Select();
return;
}
if (TextBox2.Text == "")
{
TextBox2.Select();
return;
}
TextBox2.Text = TextBox2.Text.Replace("&", "y");
TextBox2.Text = TextBox2.Text.Replace("'", "`");
TextBox2.Text = TextBox2.Text.Replace(";", ",");
TextBox2.Text = TextBox2.Text.Replace("\\", ",");
if (Regex.IsMatch(TextBox2.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);
TextBox2.Select();
return;
}
if (TextBox5.Text == "")
{
TextBox5.Select();
return;
}
//CARACTYERES PERMITIDOS
if (TextBox5.Text != "10")
{
if (TextBox5.Text != "0")
{
if (TextBox5.Text != "00")
{
if (TextBox5.Text != "5")
{
if (TextBox5.Text != "05")
{
MessageBox.Show("Valor de IVA no es correcto. Debe ser 0, 05, o 10");
TextBox5.Select();
return;
}
}
}
}
}
if (textRec1.Text == "")
{
textRec1.Select();
return;
}
if (txtPrecioComp.Text == "" || txtPrecioComp.Text == ".")
{
txtPrecioComp.Select();
return;
}
if (txtVenta1.Text == "" || txtVenta1.Text == ".")
{
txtVenta1.Select();
return;
}
if (int.Parse(Global.version.ToString()) > 1)//versión menos de 2 no muestra
{
if (Rec2.Text == "" || Rec2.Text == ".")
{
Rec2.Select();
return;
}
if (Precio2.Text == "" || Precio2.Text == ".")
{
Precio2.Select();
return;
}
if (Rec3.Text == "" || Rec3.Text == ".")
{
Rec3.Select();
return;
}
if (Precio3.Text == "" || Precio3.Text == ".")
{
Precio3.Select();
return;
}
if (Apartir2.Text == "" || Apartir2.Text == ".")
{
Apartir2.Select();
return;
}
if (Apartir3.Text == "" || Apartir3.Text == ".")
{
Apartir3.Select();
return;
}
}
else
{
Rec2.Text = textRec1.Text;
Precio2.Text = txtVenta1.Text;
Rec3.Text = textRec1.Text;
Precio3.Text = txtVenta1.Text;
Apartir2.Text = "100";
Apartir3.Text = "200";
}
if (TextBox7.Text == "")
{
TextBox7.Select();
return;
}
if (ComboBox5.Text == "")
{
ComboBox5.Select();
return;
}
if (chec_Compras.Checked == true)
{
if (ComboBox5.Text == "")
{
MessageBox.Show("Seleccione un proveedor.");
ComboBox5.Focus();
return;
}
if (Txt_RUC.Text == "")
{
MessageBox.Show("Escriba un RUC para este proveedor.");
Txt_RUC.Focus();
return;
}
if (Global.L_CompraProv != "")
{
if (Global.L_CompraProv != ComboBox5.Text.Trim())
{
MessageBox.Show("El registro de Compras no puede continuar con este Proveedor. Cambie a " + Global.L_CompraProv);
return;
}
}
if (Global.L_CompraRUC != "")
{
if (Global.L_CompraRUC != Txt_RUC.Text.Trim())
{
MessageBox.Show("El registro de Compras no puede continuar con este RUC del Proveedor. Cambie a " + Global.L_CompraRUC);
return;
}
}
if (Txt_RUC.Text.Length < 6)
{
MessageBox.Show("Verifique si el RUC para este proveedor es correcto.");
Proveedor proveedor = new Proveedor();
proveedor.Com_proveedor.Text = ComboBox5.Text.Trim();
proveedor.Txt_RUC.Text = Txt_RUC.Text.Trim();
proveedor.label_id.Text = id_prov.ToString();
ComboBox5.Text = "";
Txt_RUC.Text = "";
proveedor.ShowDialog();
return;
}
string pattern0 = @"^\d+-\d$";
string input0 = Txt_RUC.Text;
if (!Regex.IsMatch(input0, pattern0))
{
if (vecesRUC == 0)
{
MessageBox.Show("Verifique el formato del RUC. Debe ser ''123456-9''");
vecesRUC = 1;
Proveedor proveedor = new Proveedor();
proveedor.Com_proveedor.Text = ComboBox5.Text.Trim();
proveedor.Txt_RUC.Text = Txt_RUC.Text.Trim();
proveedor.label_id.Text = id_prov.ToString();
ComboBox5.Text = "";
Txt_RUC.Text = "";
proveedor.ShowDialog();
return;
}
}
if (vecesPROV_RUC == 0)
{
DialogResult result = MessageBox.Show("¿Confirma que PROVEEDOR y RUC son correctos?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) return;
Global.L_CompraProv = ComboBox5.Text.Trim();
Global.L_CompraRUC = Txt_RUC.Text.Trim();
vecesPROV_RUC = 1;
}
if (Txt_FactNum.Text == "")
{
MessageBox.Show("Escriba el número de la factura para esta compra.");
Txt_FactNum.Focus();
return;
}
string pattern = @"^\d{3}-\d{3}-\d{7}$";
string input = Txt_FactNum.Text;
if (!Regex.IsMatch(input, pattern))
{//001-010-1000000 0010010000002
string serie = Txt_FactNum.Text.Substring(0, 3);
string subSerie = Txt_FactNum.Text.Substring(3, 3);
string numero = Txt_FactNum.Text.Substring(6, 7);
Txt_FactNum.Text = $"{serie:D3}-{subSerie:D3}-{numero:D7}";
}
if (Txt_timbrado.Text == "")
{
MessageBox.Show("Escriba el timbrado de la factura para esta compra.");
Txt_timbrado.Focus();
return;
}
}
if (Vence.Text == "31/12/2100")
{
DialogResult result = MessageBox.Show("¿Confirma que el vencimiento es correcto?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
{
Vence.Select();
return;
}
else { Vence.Text = "30/12/2100"; }
}
string[] rows;
rows = Vence.Text.Split('/');
string Vencex = rows[2] + "-" + rows[1] + "-" + rows[0];
Reemplazar();
string pdc1x;
if (PDC1.Checked == true) { pdc1x = "1"; } else { pdc1x = "0"; }
string editarRegComp="0";
if (chec_Compras.Checked == true) { editarRegComp = "1"; }
if (chec_ModComp.Checked == true)
{
editarRegComp = "2";
if (ComboBox5.Text == "")
{
MessageBox.Show("Indique un Proveedor para continuar.");
ComboBox5.Focus();
return;
}
if (Txt_RUC.Text == "")
{
MessageBox.Show("Indique un RUC del Proveedor para continuar.");
Txt_RUC.Focus();
return;
}
if (Txt_FactNum.Text == "")
{
MessageBox.Show("Indique una Factura para continuar.");
Txt_FactNum.Focus();
return;
}
if (Txt_timbrado.Text == "")
{
MessageBox.Show("Indique un Timbrado para continuar.");
Txt_timbrado.Focus();
return;
}
}
if (TextBox3.Text == "") TextBox3.Text = "0";
string timbrado = Txt_timbrado.Text.Trim();
string factnum = Txt_FactNum.Text.Trim();
string ruc = Txt_RUC.Text.Trim();
float cant = float.Parse(TextBox2.Text);
float stokx = float.Parse(TextBox2.Text) + float.Parse(TextBox3.Text) - float.Parse(TextBox7.Text);
string codigo = textBox9.Text, DESCRIPCION = TextBox1.Text, COMPRA = txtPrecioComp.Text, REC = textRec1.Text, VENTA = txtVenta1.Text, PROV = ComboBox5.Text + " | " + Txt_RUC.Text, STOCK = stokx.ToString(), PERDIDA = TextBox7.Text, OTRO = ComboBox3.Text, SECC = ComboBox1.Text, SUB_SECC = ComboBox2.Text, MARCA = ComboBox4.Text, IVA = TextBox5.Text, pdc1 = pdc1x, rec2 = Rec2.Text, rec3 = Rec3.Text, venta2 = Precio2.Text, venta3 = Precio3.Text, apartir2 = Apartir2.Text, apartir3 = Apartir3.Text, id = ID_Label.Text;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/update_productos.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}▼{7}▼{8}▼{9}▼{10}▼{11}▼{12}▼{13}▼{14}▼{15}▼{16}▼{17}▼{18}▼{19}▼{20}▼{21}▼{22}▼{23}▼{24}▼{25}▼{26}▼{27}▼{28}", codigo, DESCRIPCION, COMPRA, REC, VENTA, PROV, STOCK, PERDIDA, OTRO, SECC, SUB_SECC, MARCA, IVA, pdc1, rec2, rec3, venta2, venta3, apartir2, apartir3, id, Vencex,cant,Global.USUARIO_SIST,ruc,factnum,timbrado, editarRegComp,id_prov));
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('▲');
MessageBox.Show(devuelve);
if (devuelve.Contains("Este proveedor no existe"))
{
Proveedor proveedor = new Proveedor();
proveedor.Com_proveedor.Text= ComboBox5.Text;
proveedor.Txt_RUC.Text = Txt_RUC.Text;
proveedor.label_id.Text = id_prov.ToString();
proveedor.ShowDialog();
ComboBox5.Text = "";
Txt_RUC.Text = "";
return;
}
if (!devuelve.Contains("Este artículo ya existe en el Registro de Compras"))
{
Limpiar();
RadioButton2.Checked = true;
}
}
private void TextBox2_TextChanged_1(object sender, EventArgs e)
{
string txt = TextBox2.Text;
int i = 10;
if (txt.Length > i)
{
MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
TextBox2.Text = txt;
}
//if (System.Text.RegularExpressions.Regex.IsMatch(TextBox2.Text, "[^0-9`]"))
//{
// TextBox2.Text = "";
//}
TextBox2.Text = TextBox2.Text.Replace(",", ".");
}
private void TextBox5_TextChanged_1(object sender, EventArgs e)
{
string txt = TextBox5.Text;
int i = 2;
if (txt.Length > i)
{
MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
TextBox5.Text = txt;
}
}
private void TextBox2_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// solo 1 punto decimal
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void TextBox5_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// solo 1 punto decimal
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void textRec1_KeyPress(object sender, KeyPressEventArgs e)
{
//if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
//{
// e.Handled = true;
//}
//// solo 1 punto decimal
//if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
//{
// e.Handled = true;
//}
}
private void txtPrecioComp_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// solo 1 punto decimal
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void txtVenta1_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// solo 1 punto decimal
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void TextBox7_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// solo 1 punto decimal
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void txtPrecioComp_TextChanged_1(object sender, EventArgs e)
{
string txt = txtPrecioComp.Text;
int i = 10;//100000000
if (txt.Length > i)
{
MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
txtPrecioComp.Text = txt;
}
if (txtPrecioComp.Text == "")
{
txtVenta1.Text = "";
}
if(textRec1.MaxLength>0) { textRec1_Leave(null,null); }
if (Rec2.MaxLength > 0) { Rec2_Leave(null, null); }
if (Rec3.MaxLength > 0) { Rec3_Leave_1(null, null); }
txtPrecioComp.Text = txtPrecioComp.Text.Replace(",", ".");
}
private void txtVenta1_TextChanged_1(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(txtVenta1.Text, "[^0-9-.,`]"))
{
txtVenta1.Text = "";
txtVenta1.Select();
}
//string txt = txtVenta1.Text;
//int i = 10;
//if (txt.Length > i)
//{
// MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// txt = txt.Substring(0, i);
// txtVenta1.Text = txt;
//}
txtVenta1.Text = txtVenta1.Text.Replace(",", ".");
}
private void textRec1_TextChanged_1(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(textRec1.Text, "[^0-9-.,`]"))
{
textRec1.Text = "";
textRec1.Select();
}
textRec1.Text = textRec1.Text.Replace(",", ".");
}
private void textRec1_Enter(object sender, EventArgs e)
{
//textRec1.Text = "";
//txtVenta1.Text = "";
}
private void txtVenta1_Enter(object sender, EventArgs e)
{
//if (textRec1.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
//{
// double venta = double.Parse(txtPrecioComp.Text) + (double.Parse(txtPrecioComp.Text) * double.Parse(textRec1.Text) / 100);
// double margen = double.Parse(txtPrecioComp.Text) * (double.Parse(textRec1.Text) / 100); ;
// txtVenta1.Text = string.Format("{0:0.##}", venta);//Precio venta
// label16.Text = "Margen " + string.Format("{0:#,##0.##}", margen);
//}
}
public void DataG1_Click(object sender, EventArgs e)
{
AccionDataG1();
}
public void AccionDataG1()
{
ID_Label.Text = DataG1.CurrentRow.Cells[0].Value.ToString();
string filtroID = DataG1.CurrentRow.Cells[0].Value.ToString(); //cons_temp_usu.php
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/consultar_prod_x_id.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtroID));
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('▲');
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
return;
}
if (devuelve != "")
{
// Si el formato de entrada es "yyyy-dd-MM" (ej: 2100-31-12)
string fechaOriginal = c[21]; // "2100-31-12"
if (DateTime.TryParseExact(fechaOriginal, "yyyy-dd-MM",
CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fecha))
{
// Convertir al formato que necesita el control: "dd-MM-yyyy"
Vence.Value = fecha; // Si el control acepta DateTime
// O si necesitas la cadena formateada:
// Vence.Value = fecha.ToString("dd-MM-yyyy"); // "31-12-2100"
}
else
{
Console.WriteLine($"Fecha inválida: '{fechaOriginal}'");
}
TextBox1.Text = c[1];//DESCRIPCION
textBox9.Text = c[2];//CODIGO
COD_TEMP.Text = c[2];//CODIGO
txtPrecioComp.Text = c[3];//COMPRA
textRec1.Text = c[4];//REC
txtVenta1.Text = c[5];//VENTA
TextBox3.Text = c[7];//STOCK
ComboBox3.Text = c[9];//OTRO
ComboBox1.Text = c[10];//SECC
ComboBox2.Text = c[11];//SUB_SECC
ComboBox4.Text = c[12];//MARCA
TextBox5.Text = c[13];//IVA
if(Global.L_CompraProv=="") ComboBox5.Text = c[6];//PROV
if (c[14] == "0") { PDC1.Checked = false; } else { PDC1.Checked = true; }
Rec2.Text = c[15];//RECARGO2
Rec3.Text = c[16];//RECARGO3
Precio2.Text = c[17];//PRECIO2
Precio3.Text = c[18];//PRECIO3
Apartir2.Text = c[19];//APARTIR DE... APLICA PRECIO2
Apartir3.Text = c[20];//APARTIR DE... APLICA PRECIO3
//Vence.Text = c[21];//VENCIMIENTO
id_prov = int.Parse(c[22]);
DataG1.Visible = false;
DataG2.Visible = false;
No_Buscar.Checked = true;
textBox9.Select();
label16.Text = "Margen " + string.Format("{0:#,##0.##}", double.Parse(txtVenta1.Text) - double.Parse(txtPrecioComp.Text));
No_Buscar.Checked = true;
AccionDataG2();
}
if (Precio2.Text == "0") { Precio2.Text = txtVenta1.Text; }
if (Precio3.Text == "0") { Precio3.Text = txtVenta1.Text; }
//MUESTRA LA IMAGEN
pictureBox1.ImageLocation = "http://" + Global._host + "/ecv/imagenes/" + textBox9.Text + ".jpg";
}
private void Productos_Activated(object sender, EventArgs e)
{
//this.Width = Label6.Width + Label6.Left + 25;// * (3.8);
}
private void Button2_Click_1(object sender, EventArgs e)
{
Limpiar();
if (RadioButton1.Checked == true)
{
textBox9.Select();
}
else
{
TextBox1.Select();
}
}
private void Button3_Click_1(object sender, EventArgs e)
{
if (chec_ElimComp.Checked == false)
{
DialogResult result = MessageBox.Show("¿Confirma que realmente desea eliminar?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
return;
}
else
{
if (ComboBox5.Text == "")
{
MessageBox.Show("Indique un proveedor para continuar.");
ComboBox5.Focus();
return;
}
if (Txt_RUC.Text == "")
{
MessageBox.Show("Indique el RUC del Cliente para continuar.");
Txt_RUC.Focus();
return;
}
if (Txt_FactNum.Text == "")
{
MessageBox.Show("Escriba un Número de Factura para continuar.");
Txt_FactNum.Focus();
return;
}
if (Txt_timbrado.Text == "")
{
MessageBox.Show("Escriba un Número de Timbrado para continuar.");
Txt_timbrado.Focus();
return;
}
DialogResult result2 = MessageBox.Show("¿Confirma que realmente desea eliminar este artículo del Registro de compra?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result2 == DialogResult.No)
return;
}
string id = ID_Label.Text;
string editarRegComp;
if (chec_ElimComp.Checked == true) { editarRegComp = "3"; } else { editarRegComp = "0"; }
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/delete_productos.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}▼", id, editarRegComp,ComboBox5.Text.Trim(),Txt_RUC.Text.Trim(),Txt_FactNum.Text.Trim(),Txt_timbrado.Text.Trim(), textBox9.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;
MessageBox.Show(devuelve);
if (c[0].Length > 100)//si hay error
{
return; //detenerse
}
//MessageBox.Show(TextBox1.Text + " fue eliminado.", "YA FUE", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpiar();
TextBox1.Select();
}
public void DataG2_Click(object sender, EventArgs e)
{
AccionDataG2();
}
public void AccionDataG2()
{
if (DataG2.Left == ComboBox1.Left & DataG2.Top == ComboBox1.Top + ComboBox1.Height + 1)
{
ComboBox1.Text = DataG2.CurrentRow.Cells[0].Value.ToString();
DataG2.Visible = false;
}
if (DataG2.Left == ComboBox2.Left & DataG2.Top == ComboBox2.Top + ComboBox2.Height + 1)
{
ComboBox2.Text = DataG2.CurrentRow.Cells[0].Value.ToString();
DataG2.Visible = false;
}
if (DataG2.Left == ComboBox3.Left & DataG2.Top == ComboBox3.Top + ComboBox3.Height + 1)
{
ComboBox3.Text = DataG2.CurrentRow.Cells[0].Value.ToString();
DataG2.Visible = false;
}
if (DataG2.Left == ComboBox4.Left & DataG2.Top == ComboBox4.Top + ComboBox4.Height + 1)
{
if(DataG2.CurrentRow!=null)
{
ComboBox4.Text = DataG2.CurrentRow.Cells[0].Value.ToString();
DataG2.Visible = false;
}
}
//MessageBox.Show((ComboBox5.Width/2).ToString() +" - "+ DataG2.Height.ToString());
if (DataG2.Height == ComboBox5.Width / 2)
{
//if (panel_Compras.Visible == false)
{
var valores = DataG2.CurrentRow.Cells[0].Value.ToString().Split('|');
if (valores[0] != "")
{
ComboBox5.Text = valores[0];
Txt_RUC.Text = valores[1];
id_prov = int.Parse(valores[2]);//id de proveedor
}
DataG2.Visible = false;
}
}
}
private void ComboBox3_TextChanged_1(object sender, EventArgs e)
{
string txt = ComboBox3.Text;
int i = 30;
if (txt.Length > i)
{
MessageBox.Show("No se permite texto mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
ComboBox3.Text = txt;
}
if (ComboBox3.Text == "")
{
DataG2.Visible = false;
return;
}
DataG2.Rows.Clear();
string filtro = ComboBox3.Text;
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/listar_otro.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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("
i)
{
MessageBox.Show("No se permite texto mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
ComboBox4.Text = txt;
}
if (ComboBox4.Text == "")
{
DataG2.Visible = false;
return;
}
DataG2.Rows.Clear();
string filtro = ComboBox4.Text;
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/listar_marca.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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("
i)
{
MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
TextBox7.Text = txt;
}
TextBox7.Text = TextBox7.Text.Replace(",", ".");
}
private void button6_Click_1(object sender, EventArgs e)
{
//panel1.Top = panel1.Top + 7;
//panel1.Left = panel1.Left + 12;
mensaje_lab.Visible = true;
mensaje_lab.Refresh();
button6.Enabled = false;
this.Cursor = Cursors.WaitCursor;
Global.secc = ComboBox1.Text;
Global.Total_Rep_Prod = 0;
pdf_ReportPRO pdf_repPRO = new pdf_ReportPRO();
pdf_repPRO.Mostrar_ReportPRO_pdf();
mensaje_lab.Visible = false;
mensaje_lab.Refresh();
button6.Enabled = true;
this.Cursor = Cursors.Default;
}
private void Conf_Click_1(object sender, EventArgs e)
{
if (Ruta_img.Visible == true)
{
string Ruta = Ruta_img.Text.Replace(@"\", @"\\");
//string SQLin = "UPDATE config" + Global.NUM_caja + " SET ruta_img='" + Ruta + "';";
//SQLiteCommand CMD = new SQLiteCommand(SQLin, Global.conexion);
//CMD.ExecuteNonQuery();
//SI NO EXISTE LA CARPETA SE CREA
if (!Directory.Exists(Ruta))
{
Directory.CreateDirectory(Ruta);
}
Ruta_img.Visible = false;
}
else
{
Ruta_img.Visible = true;
}
}
private void pictureBox1_Click_1(object sender, EventArgs e)
{
var fileContent = string.Empty;
var filePath = string.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = Ruta_img.Text;
openFileDialog.Filter = "(*.jpg)|*.jpg";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
var fileStream = openFileDialog.OpenFile();
using (StreamReader reader = new StreamReader(fileStream))
{
fileContent = reader.ReadToEnd();
}
}
}
try
{
if (double.Parse(Global.NUM_caja) > 0)
{
MessageBox.Show("No es posible guardar la imagen desde una terminar, sólo desde el servidor.");
}
else
{
pictureBox1.Image = Image.FromFile(filePath);
pictureBox1.Image.Save(Ruta_img.Text + "\\" + textBox9.Text + ".jpg");
}
}
catch (Exception)
{
if (textBox9.Text.Length > 0)
{
MessageBox.Show("La imagen no se puede reemplazar antes de eliminar. Elimine primero el archivo " + textBox9.Text + ".jpg");
}
this.Close();
}
}
private void Rec2_TextChanged_1(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(Rec2.Text, "[^0-9-.,`]"))
{
Rec2.Text = "";
Rec2.Select();
}
//string txt = Rec2.Text;
//int i = 30;
//if (txt.Length > i)
//{
// MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// txt = txt.Substring(0, i);
// Rec2.Text = txt;
//}
Rec2.Text = Rec2.Text.Replace(",", ".");
}
private void Rec2_Enter(object sender, EventArgs e)
{
//Rec2.Text = "";
//Precio2.Text = "";
}
private void Precio2_TextChanged_1(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(Precio2.Text, "[^0-9-.,`]"))
{
Precio2.Text = "";
Precio2.Select();
}
Precio2.Text = Precio2.Text.Replace(",", ".");
}
private void Rec3_TextChanged_1(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(Rec3.Text, "[^0-9-.,`]"))
{
Rec3.Text = "";
Rec3.Select();
}
Rec3.Text = Rec3.Text.Replace(",", ".");
}
private void Rec3_Enter(object sender, EventArgs e)
{
//Rec3.Text = "";
//Precio3.Text = "";
}
private void Precio3_TextChanged_1(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(Precio3.Text, "[^0-9-.,`]"))
{
Precio3.Text = "";
Precio3.Select();
}
//string txt = Precio3.Text;
//int i = 10;
//if (txt.Length > i)
//{
// MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// txt = txt.Substring(0, i);
// Precio3.Text = txt;
//}
Precio3.Text = Precio3.Text.Replace(",", ".");
}
private void Precio2_Enter(object sender, EventArgs e)
{
//if (Rec2.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
//{
// double venta = double.Parse(txtPrecioComp.Text) + (double.Parse(txtPrecioComp.Text) * double.Parse(Rec2.Text) / 100);
// double margen = double.Parse(txtPrecioComp.Text) * (double.Parse(Rec2.Text) / 100); ;
// Precio2.Text = string.Format("{0:0}", venta);//Precio venta
// label16.Text = "Margen " + string.Format("{0:#,##0.##}", margen);
//}
}
private void Precio3_Enter(object sender, EventArgs e)
{
//if (Rec3.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
//{
// double venta = double.Parse(txtPrecioComp.Text) + (double.Parse(txtPrecioComp.Text) * double.Parse(Rec3.Text) / 100);
// double margen = double.Parse(txtPrecioComp.Text) * (double.Parse(Rec3.Text) / 100); ;
// Precio3.Text = string.Format("{0:0}", venta);//Precio venta
// label16.Text = "Margen " + string.Format("{0:#,##0.##}", margen);
//}
}
private void DataG2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
Compras Comp = new Compras();
Comp.ShowDialog();
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ComboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ComboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ComboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ComboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textRec1_Leave(object sender, EventArgs e)
{
if (textRec1.Text == "0")
{
txtVenta1.Text = txtPrecioComp.Text;
}
if (textRec1.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
{
double venta = double.Parse(txtPrecioComp.Text) + (double.Parse(txtPrecioComp.Text) * double.Parse(textRec1.Text) / 100);
double margen = double.Parse(txtPrecioComp.Text) * (double.Parse(textRec1.Text) / 100); ;
txtVenta1.Text = string.Format("{0:0.##}", venta);//Precio venta
label16.Text = "Margen " + string.Format("{0:#,##0.##}", margen);
}
if (txtVenta1.Text == "" || txtVenta1.Text == "0")
{
txtVenta1.Text = "";
//txtVenta1.Select();
}
}
private void txtPrecioComp_Leave(object sender, EventArgs e)
{
if (txtPrecioComp.Text == "" || txtPrecioComp.Text == "0")
{
txtPrecioComp.Text = "";
}
}
private void txtVenta1_Leave_1(object sender, EventArgs e)
{
if (txtVenta1.Text == "0")
{
txtVenta1.Text = "";
}
if (textRec1.Text.Length > 0 & txtVenta1.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
{
try
{
if (double.Parse(txtVenta1.Text) > 0)
{
double resultado = double.Parse(txtVenta1.Text) - double.Parse(txtPrecioComp.Text);
double rec = (resultado / double.Parse(txtPrecioComp.Text) * 100);
textRec1.Text = rec.ToString("0.######");
}
}
catch (Exception)
{
}
}
}
private void Precio2_Leave_1(object sender, EventArgs e)
{
if (Precio2.Text == "0")
{
Precio2.Text = "";
}
if (Rec2.Text.Length > 0 & Precio2.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
{
try
{
double resultado = double.Parse(Precio2.Text) - double.Parse(txtPrecioComp.Text);
double rec = (resultado / double.Parse(txtPrecioComp.Text) * 100);
Rec2.Text = string.Format("{0:0.#######}", rec);
}
catch (Exception)
{
}
}
}
private void Rec3_Leave_1(object sender, EventArgs e)
{
if (Rec3.Text == "0")
{
Precio3.Text = txtPrecioComp.Text;
}
if (Rec3.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
{
double venta = double.Parse(txtPrecioComp.Text) + (double.Parse(txtPrecioComp.Text) * double.Parse(Rec3.Text) / 100);
double margen = double.Parse(txtPrecioComp.Text) * (double.Parse(Rec3.Text) / 100); ;
Precio3.Text = string.Format("{0:0.##}", venta);//Precio venta
label16.Text = "Margen " + string.Format("{0:#,##0.##}", margen);
}
if (Precio3.Text == "0")
{
Precio3.Text = "";
}
}
private void textBox9_KeyPress(object sender, KeyPressEventArgs e)
{
//if (RadioButton2.Checked == true)
//{
// Button4_Click(null, null);
//}
}
private void Productos_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
if (RadioButton2.Checked == true)
{
Button4_Click_1(null, null);
}
if (RadioButton1.Checked == true)
{
Button1_Click_1(null, null);
}
}
}
private void DataG1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void Btn_Tr_Click_1(object sender, EventArgs e)
{
if (textBox9.Text == "")
{
MessageBox.Show("Seleccione un Artículo.");
textBox9.Select();
return;
}
pa_Transfer.Visible = true;
pa_Transfer.Top = Btn_Tr.Top;
pa_Transfer.Left = Btn_Tr.Left - 25;
Txt_Etabl.Select();
}
private void Lb_Cerrar_Transf_Click(object sender, EventArgs e)
{
pa_Transfer.Visible = false;
}
private void Txt_Etabl_TextChanged(object sender, EventArgs e)
{
try
{
double d = double.Parse(Txt_Etabl.Text);
}
catch { Txt_Etabl.Text = ""; }
if (Txt_Etabl.Text == "0")
{
MessageBox.Show("El valor correcto de Número de Establecimiento es a apartir de 1", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Txt_Etabl.Text = "";
}
}
public class pdf_ReportPRO
{
public object Mostrar_ReportPRO_pdf()
{
// 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);
if (Global.secc != "")
{
title.Add("REPORTE DE PRODUCTOS POR SECCIÓN " + Global.secc + "." +
"\nGenerado por " + Global.USUARIO_SIST + " - Terminal " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString());
}
else
{
title.Add("REPORTE DE TODOS LOS PRODUCTOS " +
"\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("STOCK");
Paragraph TEXTO_T2 = new Paragraph();
TEXTO_T2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK);
TEXTO_T2.Add("DESCRIPCION");
Paragraph TEXTO_T3 = new Paragraph();
TEXTO_T3.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK);
TEXTO_T3.Add("PROVEEDOR");
Paragraph TEXTO_VEN = new Paragraph();
TEXTO_VEN.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK);
TEXTO_VEN.Add("VENCE");
Phrase Titulo4 = new Phrase("P. COMPRA", FontFactory.GetFont(FontFactory.DefaultEncoding, 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("SUBTOTAL", 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[] { 72f, 35f, 207f, 70f, 50f, 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);
//MySqlDataReader RS = null;
string devuelve = "";
if (Global.secc != "")
{
//string POR_OPER = "SELECT codigo,stock,descripcion,prov,compra,SUM(compra*stock) monto FROM productos WHERE secc= '" + Global.secc + "' GROUP BY codigo,stock,descripcion,prov,compra;";
//MySqlCommand CMD_POR_OPER = new MySqlCommand(POR_OPER, Conex);
//RS = CMD_POR_OPER.ExecuteReader();
string filtro = Global.secc;
//this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/rep_prod_x_secc.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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();
string[] c = devuelve.Split('▲');
//this.Cursor = Cursors.Default;
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
//return;
}
}
else
{
string filtro = Global.secc;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/rep_prod_x_todo.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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();
string[] c = devuelve.Split('▲');
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
Application.Exit();
}
}
//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 factura = new Paragraph();
factura.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
factura.Add(valores[0]);
Paragraph fecha = new Paragraph();
fecha.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
fecha.Add(double.Parse(valores[1]).ToString("#,##0.##"));
Paragraph hora = new Paragraph();
hora.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
hora.Add(valores[2]);
Paragraph descrip = new Paragraph();
descrip.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
descrip.Add(valores[3]);
string[] rows;
rows = valores[6].Split('-');
string VENCEX = rows[2] + "-" + rows[1] + "-" + rows[0];
Paragraph VENCE = new Paragraph();
VENCE.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
VENCE.Add(VENCEX);
double Montox = 0;
double Operx = 0;
try { Montox = double.Parse(valores[4]); Operx = double.Parse(valores[5]); } catch { Montox = 0; Operx = 0; }
Phrase Conte4 = new Phrase(string.Format("{0:#,##0.##}", Montox), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell montoG = new PdfPCell(Conte4);
montoG.HorizontalAlignment = Element.ALIGN_RIGHT;
montoG.BackgroundColor = new BaseColor(255, 255, 255);
montoG.BorderColor = new BaseColor(211, 211, 211);//125,125,255
Phrase Conte6 = new Phrase(string.Format("{0:#,##0.##}", Operx), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell oper = new PdfPCell(Conte6);
oper.HorizontalAlignment = Element.ALIGN_RIGHT;
oper.BackgroundColor = new BaseColor(255, 255, 255);
oper.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(factura); table.AddCell(fecha); table.AddCell(hora);
table.AddCell(descrip); table.AddCell(VENCE); table.AddCell(montoG); table.AddCell(oper);
Global.Total_Rep_Prod = Global.Total_Rep_Prod + double.Parse(valores[5]);
}
}
}
//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);
pdfw.Flush();
oDoc.Close();
System.Diagnostics.Process.Start(@pdfgenerate);//MUESTRA EL REPORTE EN PDF
return (null);
}
}
private void Txt_cant_Transf_TextChanged(object sender, EventArgs e)
{
try
{
double d = double.Parse(Txt_cant_Transf.Text);
}
catch { Txt_cant_Transf.Text = ""; }
}
private void Btn_Tranasf_Click(object sender, EventArgs e)
{
if (textBox9.Text == "")
{
textBox9.Select();
return;
}
if (Txt_Etabl.Text == "" || double.Parse(Txt_Etabl.Text) < 1)
{
Txt_Etabl.Select();
return;
}
if (Txt_cant_Transf.Text=="")
{
Txt_cant_Transf.Select();
return;
}
Transferir();
}
private void Transferir()
{
string devuelve;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/transferencia.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}", Txt_Etabl.Text.Trim(),Txt_cant_Transf.Text,textBox9.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);
devuelve = reader.ReadToEnd();
reader.Close();
stream.Close();
response.Close();
string[] c = devuelve.Split('▲');
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
//Application.Exit();
}
MessageBox.Show("Transferencia realizada al establecimiento \"" + Txt_Etabl.Text+"\"\nCódigo: "+textBox9.Text + "\nDescripción: " + TextBox1.Text+"\nCantidad: "+Txt_cant_Transf.Text,"TRANSFERENCIA LISTA", MessageBoxButtons.OK, MessageBoxIcon.Information);
Txt_Etabl.Text = "";
Txt_cant_Transf.Text = "";
pa_Transfer.Visible = false;
TextBox1.Select();
}
private void label25_Click_1(object sender, EventArgs e)
{
mensaje_lab.Visible = true;
Global.secc = ComboBox1.Text;
// 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);
if (Global.secc != "")
{
title.Add("REPORTE DE PRODUCTOS POR SECCIÓN QUE VENCEN HASTA EL " + Vence.Text + "." +
"\nGenerado por " + Global.USUARIO_SIST + " - Terminal " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString());
}
else
{
title.Add("REPORTE DE TODOS LOS PRODUCTOS QUE VENCEN HASTA EL " + Vence.Text +
"\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("STOCK");
Paragraph TEXTO_T2 = new Paragraph();
TEXTO_T2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK);
TEXTO_T2.Add("DESCRIPCION");
Paragraph TEXTO_T3 = new Paragraph();
TEXTO_T3.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK);
TEXTO_T3.Add("PROVEEDOR");
Paragraph TEXTO_VEN = new Paragraph();
TEXTO_VEN.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK);
TEXTO_VEN.Add("VENCE");
Phrase Titulo4 = new Phrase("P. COMPRA", FontFactory.GetFont(FontFactory.DefaultEncoding, 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("SUBTOTAL", 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[] { 72f, 35f, 207f, 70f, 50f, 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);
//MySqlDataReader RS = null;
string devuelve = "";
if (Global.secc != "")
{
string filtro = Global.secc;
string[] rows;
rows = Vence.Text.Split('/');
string Vencex = rows[2] + "-" + rows[1] + "-" + rows[0];
//this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/rep_prod_vence_x_secc.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼", filtro, Vencex));
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();
string[] c = devuelve.Split('▲');
//this.Cursor = Cursors.Default;
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
//return;
}
}
else
{
string[] rows;
rows=Vence.Text.Split('/');
string Vencex = rows[2] + "-" + rows[1] + "-" + rows[0];
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/rep_prod_vence_x_todo.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", Vencex));
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();
string[] c = devuelve.Split('▲');
if (c[0].Length > 100)
{
MessageBox.Show(devuelve);
mensaje_lab.Visible = false;
Application.Exit();
}
mensaje_lab.Visible = false;
}
//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 factura = new Paragraph();
factura.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
factura.Add(valores[0]);
Paragraph fecha = new Paragraph();
fecha.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
fecha.Add(double.Parse(valores[1]).ToString("#,##0.##"));
Paragraph hora = new Paragraph();
hora.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
hora.Add(valores[2]);
Paragraph descrip = new Paragraph();
descrip.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
descrip.Add(valores[3]);
string[] rows;
rows = valores[6].Split('-');
string VENCEX = rows[2] + "-" + rows[1] + "-" + rows[0];
Paragraph VENCE = new Paragraph();
VENCE.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK);
VENCE.Add(VENCEX);
double Montox = 0;
double Operx = 0;
try { Montox = double.Parse(valores[4]); Operx = double.Parse(valores[5]); } catch { Montox = 0; Operx = 0; }
Phrase Conte4 = new Phrase(string.Format("{0:#,##0.##}", Montox), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell montoG = new PdfPCell(Conte4);
montoG.HorizontalAlignment = Element.ALIGN_RIGHT;
montoG.BackgroundColor = new BaseColor(255, 255, 255);
montoG.BorderColor = new BaseColor(211, 211, 211);//125,125,255
Phrase Conte6 = new Phrase(string.Format("{0:#,##0.##}", Operx), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell oper = new PdfPCell(Conte6);
oper.HorizontalAlignment = Element.ALIGN_RIGHT;
oper.BackgroundColor = new BaseColor(255, 255, 255);
oper.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(factura); table.AddCell(fecha); table.AddCell(hora);
table.AddCell(descrip); table.AddCell(VENCE); table.AddCell(montoG); table.AddCell(oper);
Global.Total_Rep_Prod = Global.Total_Rep_Prod + double.Parse(valores[5]);
}
}
}
//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);
pdfw.Flush();
oDoc.Close();
System.Diagnostics.Process.Start(@pdfgenerate);//MUESTRA EL REPORTE EN PDF
}
private void label25_MouseMove_1(object sender, MouseEventArgs e)
{
label25.Text = "Reportar >";
label25.BackColor = Button2.BackColor;
label25.ForeColor = Button2.ForeColor;
label25.TextAlign = ContentAlignment.MiddleCenter;
}
private void label25_MouseLeave_1(object sender, EventArgs e)
{
label25.Text = "Vence >";
label25.BackColor = Color.White;
label25.ForeColor = Color.Black;
label25.TextAlign = ContentAlignment.MiddleRight;
}
private void Btn_Cerrar_Click(object sender, EventArgs e)
{
this.Close();
}
private void PDC1_CheckedChanged(object sender, EventArgs e)
{
}
private void RadioButton1_CheckedChanged_1(object sender, EventArgs e)
{
Limpiar();
if (RadioButton1.Checked == true)
{
this.AcceptButton = Button1;
TextBox7.Text = "0";
textBox9.Select();
}
}
private void No_Buscar_CheckedChanged(object sender, EventArgs e)
{
}
private void ComboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
}
private void ComboBox1_TextChanged(object sender, EventArgs e)
{
if (ComboBox1.Text.Length > 30)
{
MessageBox.Show("No se permite texto mayor a 30 dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
ComboBox1.Text = ComboBox1.Text.Substring(0, 30);
ComboBox1.SelectionStart = ComboBox1.Text.Length + 1;
}
if (ComboBox1.Text == "")
{
DataG2.Visible = false;
return;
}
DataG2.Rows.Clear();
string filtro = ComboBox1.Text;
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/listar_seccion.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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("
i)
{
MessageBox.Show("No se permite texto mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
ComboBox2.Text = txt;
}
if (ComboBox2.Text == "")
{
DataG2.Visible = false;
return;
}
DataG2.Rows.Clear();
string filtro = ComboBox2.Text;
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/listar_sub_secc.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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 & Precio2.Text.Length > 0)
//{
// double venta = double.Parse(txtPrecioComp.Text) + (double.Parse(txtPrecioComp.Text) * double.Parse(Rec2.Text) / 100);
// double margen = double.Parse(txtPrecioComp.Text) * (double.Parse(Rec2.Text) / 100); ;
// Precio2.Text = string.Format("{0:0.##}", venta);//Precio venta
// //label16.Text = "Margen " + string.Format("{0:#,##0.##}", margen);
//}
//if (Precio2.Text == "" || Precio2.Text == "0")
//{
// Precio2.Text = "";
// //Precio2.Select();
//}
if (Rec2.Text == "0")
{
Precio2.Text = txtPrecioComp.Text;
}
if (Rec2.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
{
double venta = double.Parse(txtPrecioComp.Text) + (double.Parse(txtPrecioComp.Text) * double.Parse(Rec2.Text) / 100);
double margen = double.Parse(txtPrecioComp.Text) * (double.Parse(Rec2.Text) / 100); ;
Precio2.Text = string.Format("{0:0.##}", venta);//Precio venta
label16.Text = "Margen " + string.Format("{0:#,##0.##}", margen);
}
if (Precio2.Text == "0")
{
Precio2.Text = "";
}
}
private void Precio3_Leave_1(object sender, EventArgs e)
{
if (Precio3.Text == "0")
{
Precio3.Text = "";
}
if (Rec3.Text.Length > 0 & Precio3.Text.Length > 0 & txtPrecioComp.Text.Length > 0)
{
try
{
double resultado = double.Parse(Precio3.Text) - double.Parse(txtPrecioComp.Text);
double rec = (resultado / double.Parse(txtPrecioComp.Text) * 100);
Rec3.Text = string.Format("{0:0.#######}", rec);
}
catch (Exception)
{
}
}
}
private void button8_Click(object sender, EventArgs e)
{
if (panel_Compras.Visible)
{
if (Txt_FactNum.Text.Length > 0)
{
string pattern = @"^\d{3}-\d{3}-\d{7}$";
string input = Txt_FactNum.Text;
try
{
if (!Regex.IsMatch(input, pattern))
{//001-010-1000000 0010010000002
string serie = Txt_FactNum.Text.Substring(0, 3);
string subSerie = Txt_FactNum.Text.Substring(3, 3);
string numero = Txt_FactNum.Text.Substring(6, 7);
Txt_FactNum.Text = $"{serie:D3}-{subSerie:D3}-{numero:D7}";
}
}
catch { } }
compras_reg compras_Reg = new compras_reg();
if (ComboBox5.Text.Length > 0) { compras_Reg.com_prov.Text = ComboBox5.Text.Trim() + " | " + Txt_RUC.Text.Trim(); }
compras_Reg.Txt_Fact.Text = Txt_FactNum.Text.Trim();
compras_Reg.Txt_Timbrado.Text = Txt_timbrado.Text.Trim();
compras_Reg.ShowDialog();
}
if (panel_Compras.Visible == true) { panel_Compras.Visible = false; Btn_compras.Text = "Compras"; chec_ElimComp.Checked = false; chec_ModComp.Checked = false; chec_Compras.Checked = false; return; }
if (panel_Compras.Visible == false) { panel_Compras.Visible = true; Btn_compras.Text = "Ver Compras"; return; }
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void panel1_Click(object sender, EventArgs e)
{
chec_ElimComp.Checked = false; chec_ModComp.Checked = false; chec_Compras.Checked = false;
}
private void Txt_FactNum_TextChanged(object sender, EventArgs e)
{
}
private void Txt_FactNum_Leave(object sender, EventArgs e)
{
if (Txt_FactNum.Text.Length > 0)
{
string pattern = @"^\d{3}-\d{3}-\d{7}$";
string input = Txt_FactNum.Text;
try
{
if (!Regex.IsMatch(input, pattern))
{//001-010-1000000 0010010000002
string serie = Txt_FactNum.Text.Substring(0, 3);
string subSerie = Txt_FactNum.Text.Substring(3, 3);
string numero = Txt_FactNum.Text.Substring(6, 7);
Txt_FactNum.Text = $"{serie:D3}-{subSerie:D3}-{numero:D7}";
}
}
catch { }
}
}
private void Txt_timbrado_TextChanged(object sender, EventArgs e)
{
}
private void Txt_timbrado_Leave(object sender, EventArgs e)
{
if (panel_Compras.Visible == false)
{
button8_Click(null, null);
MessageBox.Show("Marque una opción para continuar o presione el botón ''Compras'' para ver reporte.");
}
}
private void Btn_EminaComp_Click_1(object sender, EventArgs e)
{
if (ComboBox5.Text == "")
{
MessageBox.Show("Indique un proveedor para continuar.");
ComboBox5.Focus();
return;
}
if (Txt_RUC.Text == "")
{
MessageBox.Show("Indique el RUC del Cliente para continuar.");
Txt_RUC.Focus();
return;
}
if (Txt_FactNum.Text == "")
{
MessageBox.Show("Escriba un Número de Factura para continuar.");
Txt_FactNum.Focus();
return;
}
string pattern = @"^\d{3}-\d{3}-\d{7}$";
string input = Txt_FactNum.Text;
if (!Regex.IsMatch(input, pattern))
{//001-010-1000000 0010010000002
string serie = Txt_FactNum.Text.Substring(0, 3);
string subSerie = Txt_FactNum.Text.Substring(3, 3);
string numero = Txt_FactNum.Text.Substring(6, 7);
Txt_FactNum.Text = $"{serie:D3}-{subSerie:D3}-{numero:D7}";
}
if (Txt_timbrado.Text == "")
{
MessageBox.Show("Escriba un Número de Timbrado para continuar.");
Txt_timbrado.Focus();
return;
}
chec_ElimComp.Checked = false; chec_ModComp.Checked = false; chec_Compras.Checked = false;
DialogResult result = MessageBox.Show("¿Confirma que realmente desea eliminar todo el registro de esta compra?", "¿ESTÁ SEGURO/A?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
return;
string id = "";
string editarRegComp = "4";
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/delete_productos.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}▼", id, editarRegComp, ComboBox5.Text.Trim(), Txt_RUC.Text.Trim(), Txt_FactNum.Text.Trim(), Txt_timbrado.Text.Trim(), textBox9.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;
MessageBox.Show(devuelve);
if (c[0].Length > 100)//si hay error
{
return; //detenerse
}
}
private void chec_Compras_CheckedChanged(object sender, EventArgs e)
{
if (chec_Compras.Checked) { chec_ModComp.Checked = false; chec_ElimComp.Checked = false; }
}
private void chec_ModComp_CheckedChanged_1(object sender, EventArgs e)
{
if (chec_ModComp.Checked) { chec_Compras.Checked = false; chec_ElimComp.Checked = false; }
}
private void chec_ElimComp_CheckedChanged_1(object sender, EventArgs e)
{
if (chec_ElimComp.Checked) { chec_ModComp.Checked = false; chec_Compras.Checked = false; }
}
private void ComboBox5_SelectedIndexChanged_1(object sender, EventArgs e)
{
}
private void Label14_Click(object sender, EventArgs e)
{
Proveedor proveedor = new Proveedor();
proveedor.ShowDialog();
}
private void ComboBox5_TextChanged(object sender, EventArgs e)
{
if (ComboBox5.Text == "")
{
Txt_RUC.Text = "";
id_prov = 0;
return;
}
if (ComboBox5.Text.Length > 0)
{
if (ComboBox5.Text.Contains("|"))
{
string[] a = ComboBox5.Text.Split('|');
try
{
ComboBox5.Text = a[0].Trim();
Txt_RUC.Text = a[1].Trim();
}
catch { }
}
}
string txt = TextBox5.Text;
int i = 100;
if (txt.Length > i)
{
MessageBox.Show("No se permite mayor a " + i + " dógitos", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt = txt.Substring(0, i);
TextBox5.Text = txt;
}
if (ComboBox5.Text == "")
{
DataG2.Visible = false;
return;
}
DataG2.Rows.Clear();
string filtro = ComboBox5.Text;
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/listar_prov.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", filtro));
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("WARNING");
if (re == true)
{
MessageBox.Show(devuelve);
return;
}
if (devuelve != "")
{
DataG2.Visible = true;
foreach (var line in devuelve.Split('↔'))
{
var valores = line.Split('▲');
if (valores[0] != "")
{
DataG2.Rows.Add(valores[0].Trim() + "|" + valores[1].Trim() + "|" + valores[2].Trim());
}
}
DataG2.Visible = true;
DataG2.Left = ComboBox5.Left;
DataG2.Top = ComboBox5.Top + ComboBox5.Height + 1;
DataG2.Width = ComboBox5.Width;
DataG2.Columns[0].Width = ComboBox5.Width - 18;
DataG2.Height = ComboBox5.Width / 2;
}
else
{
DataG2.Visible = false;
}
}
private void btn_Lista_precio_Click(object sender, EventArgs e)
{
Prod_Lista_Precios prod_Lista_Precios = new Prod_Lista_Precios();
prod_Lista_Precios.ShowDialog();
}
}
}