using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SQLite; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace CKUERA { public partial class Usuarios : Form { public Usuarios() { InitializeComponent(); } private void Usuarios_Load(object sender, EventArgs e) { button5.Left = 3000; DataG1.Width = 586; DataG1.Height = 195; DataG1.Left = 28; DataG1.Top = TextBox1.Top + TextBox1.Height + 1; ComboBox1.Items.Add("Administrador"); ComboBox1.Items.Add("Operador"); ComboBox1.Items.Add("<>"); ComboBox1.SelectedIndex = 2; { 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) { } } } private void Usuarios_Resize(object sender, EventArgs e) { panel1.Left = this.Width / 2 - panel1.Width / 2; panel1.Top = this.Height / 2 - panel1.Height / 2; Btn_Cerrar.Top = 0; Btn_Cerrar.Left = panel1.Width - Btn_Cerrar.Width; Lb_Titulo.Top = 0; Lb_Titulo.Left = 0; Lb_Titulo.Text = this.Text; Principal fp = new Principal(); this.Left = (fp.Width / 2) - (this.Width / 2) + (fp.Boton1.Width / 3); this.Top = fp.Height / 2 - this.Height / 2; //this.FormBorderStyle = FormBorderStyle.FixedToolWindow; //Label6.Top = 9; //Label6.Left = Label6.Top; //this.Width = Label6.Width + Label6.Left + 25;// * (3.8); this.BackColor = Global.ColorSistema; //this.Height = Label6.Height + Label6.Top + 48; this.StartPosition = FormStartPosition.Manual; Button1.BackColor = Global.ColorSistema;// Button2.BackColor = Global.ColorSistema;// Button3.BackColor = Global.ColorSistema;// button4.BackColor = Global.ColorSistema;// } private void Usuarios_Activated(object sender, EventArgs e) { //this.Width = Label6.Width + Label6.Left + 25;// * (3.8); } public void REEMPLZAR() { TextBox1.Text = TextBox1.Text.ToUpper().Trim().Replace("'", "´"); TextBox2.Text = TextBox2.Text.ToUpper().Trim().Replace("'", "´"); TextBox3.Text = TextBox3.Text.ToUpper().Trim().Replace("'", "´"); TextBox4.Text = TextBox4.Text.ToUpper().Trim().Replace("'", "´"); TextBox5.Text = TextBox5.Text.ToUpper().Trim().Replace("'", "´"); TextBox1.SelectionStart = TextBox1.Text.Length + 1; TextBox2.SelectionStart = TextBox2.Text.Length + 1; TextBox3.SelectionStart = TextBox3.Text.Length + 1; TextBox4.SelectionStart = TextBox4.Text.Length + 1; TextBox5.SelectionStart = TextBox5.Text.Length + 1; } public void LIMPIAR() { // LIMPIA TODO TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; ComboBox1.Text = ""; ComboBox1.Items.Clear(); ComboBox1.Items.Add("Administrador"); ComboBox1.Items.Add("Operador"); No_Buscar.Checked = false; CheckBox1.Checked = false; CheckBox2.Checked = false; chec_config.Checked = false; chec_regProd.Checked = false; chec_verreport.Checked = false; chec_reg_comp.Checked = false; TextBox1.Select(); } private void TextBox1_TextChanged_1(object sender, EventArgs e) { if (RadioButton1.Checked == false) { if (RadioButton2.Checked == false) { MessageBox.Show("Selecciones una opción de lo que desea hacer; ''Registrar nuevo'' o ''Modificar''","!Atención!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); return; } } if (TextBox1.Text.Length > 20) { MessageBox.Show("La longitud de caracteres no puede ser más que 20.", "!Atención!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); TextBox1.Text = TextBox1.Text.Substring(0, 20); TextBox1.Select(); return; } if (TextBox1.Text == "") LIMPIAR(); TextBox1.ReadOnly = false; { if (No_Buscar.Checked == true) return; // NO BUSCAR SI YA ENCONTRÓ if (RadioButton2.Checked == true) // SI ES MODIFICAR { if (No_Buscar.Checked==true) { REEMPLZAR(); } //SQLiteDataReader RS = null; //string SQL = "SELECT ID,NOMBRE,CI FROM USUARIOS WHERE NOMBRE LIKE '%" + TextBox1.Text + "%' OR CI='" + TextBox1.Text + "';"; //SQLiteCommand CMD3 = new SQLiteCommand(SQL, Global.conexion); //RS = CMD3.ExecuteReader(); //RS.Read(); HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/usuarios_consultar.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", TextBox1.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(">") { MessageBox.Show("Seleccione una opción de Rango; Administrador u Operador.", "¡ATENCIÓN!",MessageBoxButtons.OK,MessageBoxIcon.Information); ComboBox1.Select(); return; } if (TextBox5.Text == "") { TextBox5.Select(); return; } TextBox5.Text = TextBox5.Text.Replace("&", "y"); TextBox5.Text = TextBox5.Text.Replace("'", "`"); TextBox5.Text = TextBox5.Text.Replace(";", ","); TextBox5.Text = TextBox5.Text.Replace("\\", ","); if (Regex.IsMatch(TextBox5.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); TextBox5.Select(); return; } int Vende = 0; // SI VENDE POR PRECIO O NO if (CheckBox1.Checked == true) { Vende = 1; } int Modi = 0; // SI MODIFICA PRECIO O NO if (CheckBox2.Checked == true) { Modi = 1; } int reg = 0; // SI registra prod if (chec_regProd.Checked == true) { reg = 1; } int rep = 0; // SI pueder ver reportes if (chec_verreport.Checked == true) { rep = 1; } int conf = 0; // SI puede configurar if (chec_config.Checked == true) { conf = 1; } int reg_comp = 0; // SI puede configurar if (chec_reg_comp.Checked == true) { reg_comp = 1; } REEMPLZAR(); if (RadioButton1.Checked == true) { HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/usuarios_insert.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}▼{7}▼{8}▼{9}▼{10}▼{11}", TextBox5.Text.Trim(), TextBox1.Text, ComboBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, Modi, Vende, reg, rep, conf, reg_comp)); 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(">") { MessageBox.Show("Seleccione una opción de Rango; Administrador u Operador.", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Information); ComboBox1.Select(); return; } if (TextBox5.Text == "") { TextBox5.Select(); return; } TextBox5.Text = TextBox5.Text.Replace("&", "y"); TextBox5.Text = TextBox5.Text.Replace("'", "`"); TextBox5.Text = TextBox5.Text.Replace(";", ","); TextBox5.Text = TextBox5.Text.Replace("\\", ","); if (Regex.IsMatch(TextBox5.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); TextBox5.Select(); return; } HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/usuarios_update.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}", TextBox5.Text.Trim(), TextBox1.Text, ComboBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, Global.chec2, Global.chec1, ID_LABEL.Text,reg,rep,conf,regComp)); 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("