Ejemplo n.º 1
0
        private void butBuscarVentas_Click(object sender, EventArgs e)
        {
            string select = "SELECT  c.fecha FECHA,cli.apellido APELLIDO,cli.nombre NOMBRE,t.nro_tarjeta NRO_TARJETA,c.cod_postnet COD_POSNET,pos.marca MARCA,pos.modelo MODELO,c.monto MONTO FROM (((ntvc.beneficiario b INNER JOIN ntvc.compra c ON b.cod_beneficiario=c.cod_beneficiario) INNER JOIN ntvc.postnet pos ON pos.cod_postnet=c.cod_postnet) INNER JOIN ntvc.tarjeta t ON t.cod_tarjeta=c.cod_tarjeta) INNER JOIN ntvc.cliente cli ON cli.cod_cliente=t.cod_cliente WHERE c.pagado=0 and b.razon_social=";

            if (!FuncionesUtiles.estaVacio(textBeneficiario))
            {
                select += "'" + textBeneficiario.Text + "' and ";
            }
            if (!FuncionesUtiles.estaVacio(textFechaInicio))
            {
                select += "c.fecha between'" + textFechaInicio.Text + "' and ";
            }
            if (!FuncionesUtiles.estaVacio(textFechaFin))
            {
                select += "'" + textFechaFin.Text + "'";
            }
            if ((!FuncionesUtiles.estaVacio(textFechaFin)) && (!FuncionesUtiles.estaVacio(textFechaInicio)) && (!FuncionesUtiles.estaVacio(textBeneficiario)))
            {
                FuncionesUtiles.llenarDataGridView(select, dataGridView1);
            }
            else
            {
                MessageBox.Show("Debe llenar todos los campos", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
        }
 private void botBuscar_Click(object sender, EventArgs e)
 {
     //verificar los numericos
     if ((!FuncionesUtiles.esNumerico(textNumero) && !FuncionesUtiles.estaVacio(textNumero)))
     {
         //hay campos numericos con valores no numericos
         string mensaje = "Los siguientes campos deben ser numéricos y positivos:";
         if (!FuncionesUtiles.esNumerico(textNumero) && !FuncionesUtiles.estaVacio(textNumero))
         {
             mensaje += "\n-Número";
         }
     }
     else
     {
         SqlConnection con = Conexion.conectar();
         con.Open();
         SqlCommand    com;
         SqlDataReader reader;
         string        cod_rubro = "";
         if (comboBoxRubro.SelectedIndex > -1)
         {
             com = new SqlCommand("select cod_rubro from ntvc.rubro where descripcion = @descripcion", con);
             com.Parameters.AddWithValue("@descripcion", comboBoxRubro.Items[comboBoxRubro.SelectedIndex].ToString().Trim());
             reader = com.ExecuteReader();
             if (reader.Read())
             {
                 cod_rubro = reader["cod_rubro"].ToString().Trim();
             }
             reader.Close();
         }
         string select = "select distinct b.razon_social as Razón_Social, b.dir_calle as Calle, b.dir_nro as Número, b.dir_piso as Piso, b.dir_dpto as Depto, r.descripcion as Rubro from ntvc.beneficiario b, ntvc.rubro r where b.cod_rubro = r.cod_rubro and ";
         if (!FuncionesUtiles.estaVacio(textCalle))
         {
             select += "b.dir_calle like '%" + textCalle.Text + "%' and ";
         }
         if (!FuncionesUtiles.estaVacio(textDepto))
         {
             select += "b.dir_dpto like '%" + textDepto.Text + "%' and ";
         }
         if (!FuncionesUtiles.estaVacio(textNumero))
         {
             select += "b.dir_nro = " + textNumero.Text + " and ";
         }
         if (!FuncionesUtiles.estaVacio(textPiso))
         {
             select += "b.dir_piso = " + textPiso.Text + " and ";
         }
         if (!FuncionesUtiles.estaVacio(textRazonSocial))
         {
             select += "b.razon_social like '%" + textRazonSocial.Text + "%' and ";
         }
         if (comboBoxRubro.SelectedIndex > -1)
         {
             select += "r.descripcion = '" + comboBoxRubro.Items[comboBoxRubro.SelectedIndex].ToString().Trim() + "' and ";
         }
         select += "1 = 1";
         FuncionesUtiles.llenarDataGridView(select, dataGridView1);
         con.Close();
     }
 }
Ejemplo n.º 3
0
 private void botQuitarPostNets_Click(object sender, EventArgs e)
 {
     if (serials.Count() == 0)
     {
         MessageBox.Show("No hay post-nets que quitar", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
     }
     else
     {
         QuitarPostNets form = new QuitarPostNets(serials);
         form.ShowDialog(this);
         serials.Remove(form.serial_q);
         textPostNets.Text = "";
         foreach (string serial in serials)
         {
             if (FuncionesUtiles.estaVacio(textPostNets))
             {
                 textPostNets.Text = serial;
             }
             else
             {
                 textPostNets.Text += ", " + serial;
             }
         }
     }
 }
Ejemplo n.º 4
0
        private void botBuscar_Click(object sender, EventArgs e)
        {
            string query = "select c.nombre as Nombre, c.apellido as Apellido, c.doc as Documento, t.nro_tarjeta as Número_tarjeta, t.fecha_alta as Fecha from NTVC.Cliente c, NTVC.tarjeta t where t.cod_cliente = c.cod_cliente and ";

            if (FuncionesUtiles.esNumerico(textNumeroTarjeta) || FuncionesUtiles.estaVacio(textNumeroTarjeta))
            {
                if (!FuncionesUtiles.estaVacio(textNumeroTarjeta))
                {
                    query += "t.nro_tarjeta = " + textNumeroTarjeta.Text + " and ";
                }
                if (!FuncionesUtiles.estaVacio(textFechaAlta))
                {
                    query += "t.fecha_alta = '" + textFechaAlta.Text + "' and ";
                }
                if (!FuncionesUtiles.estaVacio(textCliente))
                {
                    query += "t.cod_cliente = " + textCliente.Text + " and ";
                }
                query += "1=1";
                FuncionesUtiles.llenarDataGridView(query, dataGridView1);
            }
            else
            {
                MessageBox.Show("El número de tarjeta debe ser un valor numérico y menor a 2000000000", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
        }
Ejemplo n.º 5
0
 private void botBuscar_Click(object sender, EventArgs e)
 {
     if (!FuncionesUtiles.esNumerico(textDNI) && !FuncionesUtiles.estaVacio(textDNI))
     {
         MessageBox.Show("El documento debe ser numérico.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
     }
     else
     {
         SqlConnection con = Conexion.conectar();
         con.Open();
         string busqueda = "select c.nombre as Nombre, c.apellido as Apellido, c.tipo_doc as Tipo, c.doc as Documento, p.nombre as Provincia, c.mail as Mail, c.telefono as Teléfono, c.dir_calle as Calle, c.dir_nro as Número, c.dir_piso as Piso, c.dir_dpto as Depto from NTVC.Cliente c, NTVC.provincia p where c.cod_provincia = p.cod_provincia and ";
         if (!FuncionesUtiles.estaVacio(textApellido))
         {
             busqueda += "c.apellido like '%" + textApellido.Text + "%' and ";
         }
         if (!FuncionesUtiles.estaVacio(textNombre))
         {
             busqueda += "c.nombre like '%" + textNombre.Text + "%' and ";
         }
         if (!FuncionesUtiles.estaVacio(textDNI))
         {
             busqueda += "c.doc = " + textDNI.Text + " and ";
         }
         if (comboBox1.SelectedIndex > -1)
         {
             busqueda += "p.nombre = '" + comboBox1.Items[comboBox1.SelectedIndex].ToString().Trim() + "' and ";
         }
         busqueda += "1=1";
         FuncionesUtiles.llenarDataGridView(busqueda, dataGridView1);
     }
 }
Ejemplo n.º 6
0
 private void botBuscar_Click(object sender, EventArgs e)
 {
     if (!FuncionesUtiles.esNumerico(textNumeroSerie) && !FuncionesUtiles.estaVacio(textNumeroSerie))
     {
         MessageBox.Show("El número de serie debe ser numérico.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
     }
     else
     {
         SqlConnection con = Conexion.conectar();
         con.Open();
         string busqueda = "select nro_serie as Serial, marca as Marca, modelo as Modelo from ntvc.postnet where cod_postnet not in (select cod_postnet from ntvc.beneficiario_postnet) and ";
         if (!FuncionesUtiles.estaVacio(textMarca))
         {
             busqueda += "Marca like '%" + textMarca.Text + "%' and ";
         }
         if (!FuncionesUtiles.estaVacio(textModelo))
         {
             busqueda += "Modelo like '%" + textModelo.Text + "%' and ";
         }
         if (!FuncionesUtiles.estaVacio(textNumeroSerie))
         {
             busqueda += "nro_serie  = " + textNumeroSerie.Text + " and ";
         }
         busqueda += "1=1";
         FuncionesUtiles.llenarDataGridView(busqueda, dataGridView1);
         con.Close();
     }
 }
Ejemplo n.º 7
0
 private void botSeleccionarBenficiario_Click(object sender, EventArgs e)
 {
     SeleccionarBeneficiario form = new SeleccionarBeneficiario();
     form.ShowDialog(this);
     textBeneficiario.Text = form.razon_social;
     comboBoxPostNet.Items.Clear();
     cods_postnets_.Clear();
     if(!FuncionesUtiles.estaVacio(textBeneficiario))
     {
         SqlConnection con = Conexion.conectar();
         con.Open();
         SqlCommand com = new SqlCommand("select cod_beneficiario from ntvc.beneficiario where razon_social = @rs", con);
         com.Parameters.AddWithValue("@rs", form.razon_social);
         SqlDataReader reader = com.ExecuteReader();
         cod_beneficiario_ = "";
         if (reader.Read())
         {
             cod_beneficiario_ = reader["cod_beneficiario"].ToString().Trim();
         }
         reader.Close();
         com = new SqlCommand("select p.cod_postnet, p.nro_serie, p.marca, p.modelo from ntvc.postnet p, ntvc.beneficiario_postnet bp where bp.cod_beneficiario = @cb and bp.cod_postnet = p.cod_postnet", con);
         com.Parameters.AddWithValue("@cb", cod_beneficiario_);
         reader = com.ExecuteReader();
         while (reader.Read())
         {
             string pn = reader["marca"].ToString().Trim() + " " + reader["modelo"].ToString().Trim() + " (" + reader["nro_serie"].ToString().Trim() + ")";
             comboBoxPostNet.Items.Add(pn);
             cods_postnets_.Add(reader["cod_postnet"].ToString().Trim());
         }
         reader.Close();
         con.Close();
     }
 }
Ejemplo n.º 8
0
        private void botAgregarPostNets_Click(object sender, EventArgs e)
        {
            SeleccionarPostNets form = new SeleccionarPostNets();

            form.ShowDialog(this);
            if (form.serial_a != "")
            {
                if (!serials.Contains(form.serial_a))
                {
                    serials.Add(form.serial_a);
                    textPostNets.Text = "";
                    foreach (string serial in serials)
                    {
                        if (FuncionesUtiles.estaVacio(textPostNets))
                        {
                            textPostNets.Text = serial;
                        }
                        else
                        {
                            textPostNets.Text += ", " + serial;
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void botBuscar_Click(object sender, EventArgs e)
        {
            string busqueda = "select username as Username from NTVC.usuario";

            if (!FuncionesUtiles.estaVacio(textUsername))
            {
                busqueda += " where username like '" + textUsername.Text + "'";
            }
            FuncionesUtiles.llenarDataGridView(busqueda, dataGridView1);
        }
Ejemplo n.º 10
0
        public ModificacionBeneficiario(string rs)
        {
            InitializeComponent();
            this.Icon = BoletoElectronicoDesktop.Properties.Resources.NTVCSUBE1;

            razon_social_vieja = rs;
            SqlConnection con = Conexion.conectar();

            con.Open();
            SqlCommand    com    = new SqlCommand("select * from ntvc.rubro order by descripcion", con);
            SqlDataReader reader = com.ExecuteReader();

            while (reader.Read())
            {
                comboBoxRubro.Items.Add(reader["descripcion"]);
            }
            reader.Close();
            com = new SqlCommand("select b.cod_beneficiario, b.razon_social, b.dir_calle , b.dir_nro , b.dir_piso , b.dir_dpto , r.descripcion from ntvc.beneficiario b, ntvc.rubro r where b.cod_rubro = r.cod_rubro and razon_social = @rs", con);
            com.Parameters.AddWithValue("@rs", razon_social_vieja);
            reader            = com.ExecuteReader();
            cod_beneficiario_ = "";
            if (reader.Read())
            {
                cod_beneficiario_           = reader["cod_beneficiario"].ToString().Trim();
                textCalle.Text              = reader["dir_calle"].ToString().Trim();
                textDepto.Text              = reader["dir_dpto"].ToString().Trim();
                textNumero.Text             = reader["dir_nro"].ToString().Trim();
                textPiso.Text               = reader["dir_piso"].ToString().Trim();
                textRazonSocial.Text        = reader["razon_social"].ToString().Trim();
                comboBoxRubro.SelectedIndex = comboBoxRubro.Items.IndexOf(reader["descripcion"]);
            }
            reader.Close();
            com = new SqlCommand("select p.nro_serie from ntvc.postnet p, ntvc.beneficiario_postnet bp where bp.cod_beneficiario = @cb and bp.cod_postnet = p.cod_postnet", con);
            com.Parameters.AddWithValue("@cb", cod_beneficiario_);
            reader = com.ExecuteReader();
            while (reader.Read())
            {
                serials.Add(reader["nro_serie"].ToString().Trim());
            }
            reader.Close();
            foreach (string serial in serials)
            {
                if (FuncionesUtiles.estaVacio(textPostNets))
                {
                    textPostNets.Text = serial;
                }
                else
                {
                    textPostNets.Text += ", " + serial;
                }
            }
            con.Close();
        }
Ejemplo n.º 11
0
        private void botRegistrarPago_Click(object sender, EventArgs e)
        {
            if ((!FuncionesUtiles.estaVacio(textFechaFin)) && (!FuncionesUtiles.estaVacio(textFechaInicio)) && (!FuncionesUtiles.estaVacio(textBeneficiario)))
            {
                string        consulta;
                SqlConnection con = Conexion.conectar();
                con.Open();
                consulta = "insert into ntvc.pago (monto, cod_beneficiario, cod_compra)" +
                           " select compra.monto, compra.cod_beneficiario, compra.cod_compra" +
                           " from ntvc.compra compra, ntvc.beneficiario beneficiario" +
                           " where beneficiario.razon_social = @razon_social and" +
                           " compra.fecha between @fechaInicio and @fechaFin and" +
                           " compra.cod_beneficiario = beneficiario.cod_beneficiario and" +
                           " compra.pagado = 0";
                SqlCommand com = new SqlCommand(consulta, con);
                com.Parameters.AddWithValue("@razon_social", this.textBeneficiario.Text);
                com.Parameters.AddWithValue("@fechaInicio", this.textFechaInicio.Text);
                com.Parameters.AddWithValue("@fechaFin", this.textFechaFin.Text);
                com.ExecuteNonQuery();
                consulta = "update ntvc.compra set pagado = 1" +
                           " from (select compra.monto, compra.cod_beneficiario, compra.cod_compra" +
                           " from ntvc.compra compra, ntvc.beneficiario beneficiario" +
                           " where beneficiario.razon_social = @razon_social and" +
                           " compra.fecha between @fechaInicio and @fechaFin and" +
                           " compra.cod_beneficiario = beneficiario.cod_beneficiario and" +
                           " compra.pagado = 0) as aux" +
                           " where compra.cod_compra = aux.cod_compra";
                com = new SqlCommand(consulta, con);
                com.Parameters.AddWithValue("@razon_social", this.textBeneficiario.Text);
                com.Parameters.AddWithValue("@fechaInicio", this.textFechaInicio.Text);
                com.Parameters.AddWithValue("@fechaFin", this.textFechaFin.Text);

                com.ExecuteNonQuery();
                this.Close();
                MessageBox.Show("Los pagos se han registrado.", "Registro exitoso", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
                con.Close();
            }
            else
            {
                MessageBox.Show("Debe llenar todos los campos", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
        }
Ejemplo n.º 12
0
        private void botGuardar_Click(object sender, EventArgs e)
        {
            if (FuncionesUtiles.estanVacios(new List <TextBox> {
                textPostNets, textCalle, textRazonSocial, textNumero
            }) || comboBoxRubro.SelectedIndex == -1)
            {
                string mensaje = "Debe completar los siguientes campos:";
                if (textRazonSocial.Text == "")
                {
                    mensaje += "\n-Razón social";
                }
                if (comboBoxRubro.SelectedIndex == -1)
                {
                    mensaje += "\n-Rubro";
                }
                if (textPostNets.Text == "")
                {
                    mensaje += "\n-Post-nets";
                }
                if (textCalle.Text == "")
                {
                    mensaje += "\n-Calle";
                }
                if (textNumero.Text == "")
                {
                    mensaje += "\n-Número";
                }
                MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            else
            {
                //campos completos, verificar los numericos
                if (!FuncionesUtiles.sonNumericos(new List <TextBox> {
                    textNumero
                }))
                {
                    //hay campos numericos con valores no numericos
                    string mensaje = "Los siguientes campos deben ser numéricos y positivos:";
                    if (!FuncionesUtiles.esNumerico(textNumero) && !FuncionesUtiles.estaVacio(textNumero))
                    {
                        mensaje += "\n-Número";
                    }
                    MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                }
                else
                {
                    //campos correctos, verificar unicidad de la razon social
                    SqlConnection con = Conexion.conectar();
                    con.Open();
                    SqlCommand com = new SqlCommand("select * from ntvc.beneficiario where razon_social = @razon_social", con);
                    com.Parameters.AddWithValue("@razon_social", textRazonSocial.Text);
                    SqlDataReader reader = com.ExecuteReader();
                    if (reader.Read())
                    {
                        //razon social repetida
                        reader.Close();
                        MessageBox.Show("La razón social ya se encuentra en el sistema.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                    }
                    else
                    {
                        //hacer insert
                        reader.Close();
                        string cod_rubro = "";
                        com = new SqlCommand("select cod_rubro from ntvc.rubro where descripcion = @descripcion", con);
                        com.Parameters.AddWithValue("@descripcion", comboBoxRubro.Items[comboBoxRubro.SelectedIndex].ToString().Trim());
                        reader = com.ExecuteReader();
                        if (reader.Read())
                        {
                            cod_rubro = reader["cod_rubro"].ToString().Trim();
                        }
                        reader.Close();
                        string insert = "Insert into NTVC.beneficiario (razon_social, dir_calle, dir_nro, dir_piso, dir_dpto, habilitado, cod_rubro)";
                        insert += " values(@razon_social, @dir_calle, @dir_numero, @dir_piso, @dir_depto, @habilitado, @cod_rubro)";
                        com     = new SqlCommand(insert, con);
                        com.Parameters.AddWithValue("@razon_social", textRazonSocial.Text);
                        com.Parameters.AddWithValue("@dir_calle", textCalle.Text);
                        com.Parameters.AddWithValue("@dir_numero", textNumero.Text);
                        com.Parameters.AddWithValue("@dir_piso", textPiso.Text);
                        com.Parameters.AddWithValue("@dir_depto", textDepto.Text);
                        com.Parameters.AddWithValue("@habilitado", 1);
                        com.Parameters.AddWithValue("@cod_rubro", cod_rubro);
                        com.ExecuteNonQuery();

                        //insert de postnets
                        string cod_beneficiario = "";
                        com = new SqlCommand("select cod_beneficiario from ntvc.beneficiario where razon_social = @razon_social", con);
                        com.Parameters.AddWithValue("@razon_social", textRazonSocial.Text);
                        reader = com.ExecuteReader();
                        if (reader.Read())
                        {
                            cod_beneficiario = reader["cod_beneficiario"].ToString().Trim();
                        }
                        reader.Close();
                        foreach (string serial in serials)
                        {
                            string cod_postnet = "";
                            com = new SqlCommand("select cod_postnet from ntvc.postnet where nro_serie = @serial", con);
                            com.Parameters.AddWithValue("@serial", serial);
                            reader = com.ExecuteReader();
                            if (reader.Read())
                            {
                                cod_postnet = reader["cod_postnet"].ToString().Trim();
                            }
                            reader.Close();
                            com = new SqlCommand("insert into ntvc.beneficiario_postnet (cod_beneficiario, cod_postnet) values (@cod_beneficiario, @cod_postnet)", con);
                            com.Parameters.AddWithValue("@cod_beneficiario", cod_beneficiario);
                            com.Parameters.AddWithValue("@cod_postnet", cod_postnet);
                            com.ExecuteNonQuery();
                        }
                        MessageBox.Show("El beneficiario ha sido agregado.", "Alta exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
                        this.Close();
                    }
                    con.Close();
                }
            }
        }
Ejemplo n.º 13
0
        private void botGuardar_Click(object sender, EventArgs e)
        {
            int cant_roles = 0;

            foreach (int indice in checkedListBox1.CheckedIndices)
            {
                cant_roles++;
            }
            if (FuncionesUtiles.estanVacios(new List <TextBox> {
                textPassword, textUsername
            }) || cant_roles == 0)
            {
                string mensaje = "Debe completar los siguientes campos:";
                if (FuncionesUtiles.estaVacio(textUsername))
                {
                    mensaje += "\n-Username";
                }
                if (FuncionesUtiles.estaVacio(textPassword))
                {
                    mensaje += "\n-Password";
                }
                if (cant_roles == 0)
                {
                    mensaje += "\n-Roles";
                }

                MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            else
            {
                //los campos estan completos
                SqlConnection con = Conexion.conectar();
                con.Open();
                SqlCommand com = new SqlCommand("select * from ntvc.usuario where username = @username", con);
                com.Parameters.AddWithValue("@username", textUsername.Text);
                SqlDataReader reader = com.ExecuteReader();
                if (reader.Read())
                {
                    //ya existe el username
                    reader.Close();
                    con.Close();
                    MessageBox.Show("El nombre de usuario ingresado ya existe.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                }
                else
                {
                    reader.Close();
                    com = new SqlCommand("insert into ntvc.usuario (username, password, cant_log_falla, habilitado) values (@username, @password, 0, 1)", con);
                    com.Parameters.AddWithValue("@username", textUsername.Text);
                    com.Parameters.AddWithValue("@password", Encriptar.sha256(textPassword.Text));
                    com.ExecuteNonQuery();
                    string cod_usuario = "";
                    com = new SqlCommand("select cod_usuario from ntvc.usuario where username = @username", con);
                    com.Parameters.AddWithValue("@username", textUsername.Text);
                    reader = com.ExecuteReader();
                    if (reader.Read())
                    {
                        cod_usuario = reader["cod_usuario"].ToString();
                    }
                    reader.Close();
                    foreach (int indice in checkedListBox1.CheckedIndices)
                    {
                        com = new SqlCommand("insert into ntvc.usuario_rol (cod_usuario, cod_rol) values(@cod_usuario, @cod_rol)", con);
                        com.Parameters.AddWithValue("@cod_usuario", cod_usuario);
                        SqlCommand com2 = new SqlCommand("select cod_rol from ntvc.rol where nombre = @nombre_rol", con);
                        com2.Parameters.AddWithValue("@nombre_rol", checkedListBox1.Items[indice].ToString().Trim());
                        reader = com2.ExecuteReader();
                        if (reader.Read())
                        {
                            com.Parameters.AddWithValue("@cod_rol", reader["cod_rol"].ToString());
                            reader.Close();
                            com.ExecuteNonQuery();
                        }
                        else
                        {
                            reader.Close();
                        }
                    }
                    con.Close();
                    this.Close();
                    MessageBox.Show("El usuario ha sido agregado.", "Alta exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
                }
            }
        }
Ejemplo n.º 14
0
 private void botGuardar_Click(object sender, EventArgs e)
 {
     if (FuncionesUtiles.estanVacios(new List <TextBox> {
         textApellido, textCalle, textDNI, textMail, textNombre, textNumero, textTelefono
     }) || comboBoxTD.SelectedIndex == -1 || comboBox1.SelectedIndex == -1)
     {
         string mensaje = "Debe completar los siguientes campos:";
         if (textNombre.Text == "")
         {
             mensaje += "\n-Nombre";
         }
         if (textApellido.Text == "")
         {
             mensaje += "\n-Apellido";
         }
         if (comboBoxTD.SelectedIndex == -1)
         {
             mensaje += "\n-Tipo de documento";
         }
         if (textDNI.Text == "")
         {
             mensaje += "\n-Documento";
         }
         if (comboBox1.SelectedIndex == -1)
         {
             mensaje += "\n-Provincia";
         }
         if (textTelefono.Text == "")
         {
             mensaje += "\n-Teléfono";
         }
         if (textMail.Text == "")
         {
             mensaje += "\n-Mail";
         }
         if (textCalle.Text == "")
         {
             mensaje += "\n-Calle";
         }
         if (textNumero.Text == "")
         {
             mensaje += "\n-Número";
         }
         MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
     }
     else
     {
         //campos completos, verificar los numericos
         if (!FuncionesUtiles.sonNumericos(new List <TextBox> {
             textDNI, textNumero, textTelefono
         }))
         {
             //hay campos numericos con valores no numericos
             string mensaje = "Los siguientes campos deben ser numéricos y positivos:";
             if (!FuncionesUtiles.esNumerico(textDNI) && !FuncionesUtiles.estaVacio(textDNI))
             {
                 mensaje += "\n-Documento";
             }
             if (!FuncionesUtiles.esNumerico(textTelefono) && !FuncionesUtiles.estaVacio(textTelefono))
             {
                 mensaje += "\n-Teléfono";
             }
             if (!FuncionesUtiles.esNumerico(textNumero) && !FuncionesUtiles.estaVacio(textNumero))
             {
                 mensaje += "\n-Número";
             }
             MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
         }
         else
         {
             //campos correctos, verificar unicidad del DNI
             SqlConnection con = Conexion.conectar();
             con.Open();
             SqlCommand com = new SqlCommand("select * from ntvc.cliente where doc = @doc and tipo_doc = @tipo", con);
             com.Parameters.AddWithValue("@tipo", FuncionesUtiles.obtenerTipoDoc(comboBoxTD.SelectedIndex));
             com.Parameters.AddWithValue("@doc", textDNI.Text);
             SqlDataReader reader = com.ExecuteReader();
             if (reader.Read())
             {
                 //dni repetido
                 reader.Close();
                 MessageBox.Show("El Documento ya se encuentra en el sistema.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
             }
             else
             {
                 //hacer insert
                 reader.Close();
                 string cod_prov = "";
                 com = new SqlCommand("select cod_provincia from ntvc.provincia  where nombre = @nombre_prov", con);
                 com.Parameters.AddWithValue("@nombre_prov", comboBox1.Items[comboBox1.SelectedIndex].ToString().Trim());
                 reader = com.ExecuteReader();
                 if (reader.Read())
                 {
                     cod_prov = reader["cod_provincia"].ToString().Trim();
                 }
                 reader.Close();
                 string insert = "Insert into NTVC.cliente (nombre, apellido, tipo_doc, doc, mail, telefono, dir_calle, dir_nro, dir_piso, dir_dpto, habilitado, cod_provincia)";
                 insert += " values(@nombre, @apellido, @tipo_doc, @doc, @mail, @telefono, @dir_calle, @dir_numero, @dir_piso, @dir_depto, @habilitado, @cod_provincia)";
                 com     = new SqlCommand(insert, con);
                 com.Parameters.AddWithValue("@nombre", textNombre.Text);
                 com.Parameters.AddWithValue("@apellido", textApellido.Text);
                 com.Parameters.AddWithValue("@tipo_doc", FuncionesUtiles.obtenerTipoDoc(comboBoxTD.SelectedIndex));
                 com.Parameters.AddWithValue("@doc", textDNI.Text);
                 com.Parameters.AddWithValue("@mail", textMail.Text);
                 com.Parameters.AddWithValue("@telefono", textTelefono.Text);
                 com.Parameters.AddWithValue("@dir_calle", textCalle.Text);
                 com.Parameters.AddWithValue("@dir_numero", textNumero.Text);
                 com.Parameters.AddWithValue("@dir_piso", textPiso.Text);
                 com.Parameters.AddWithValue("@dir_depto", textDepto.Text);
                 com.Parameters.AddWithValue("@habilitado", 1);
                 com.Parameters.AddWithValue("@cod_provincia", cod_prov);
                 com.ExecuteNonQuery();
                 MessageBox.Show("El cliente ha sido agregado.", "Alta exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
                 this.Close();
             }
             con.Close();
         }
     }
 }
Ejemplo n.º 15
0
 private void botGuardar_Click(object sender, EventArgs e)
 {
     if (FuncionesUtiles.estanVacios(new List <TextBox> {
         textNumeroTarjeta, textFechaAlta, textCliente
     }))
     {
         string mensaje = "Debe completar los siguientes campos:";
         if (FuncionesUtiles.estaVacio(textNumeroTarjeta))
         {
             mensaje += "\n-Número de tarjeta";
         }
         if (FuncionesUtiles.estaVacio(textFechaAlta))
         {
             mensaje += "\n-Fecha de alta";
         }
         if (FuncionesUtiles.estaVacio(textCliente))
         {
             mensaje += "\n-Cliente";
         }
         MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
     }
     else
     {
         if (FuncionesUtiles.esNumerico(this.textNumeroTarjeta))
         {
             //el valor de numero de tarjeta es numerico
             SqlConnection con = Conexion.conectar();
             SqlCommand    com = new SqlCommand("select nro_tarjeta from NTVC.TARJETA where nro_tarjeta = @nro_tarjeta", con);
             com.Parameters.AddWithValue("@nro_tarjeta", this.textNumeroTarjeta.Text);
             con.Open();
             SqlDataReader reader = com.ExecuteReader();
             //veo si el numero de tarjeta está repetido
             if (reader.Read())
             {
                 //ya existe esa tarjeta
                 MessageBox.Show("El número de tarjeta ingresado ya existe", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                 reader.Close();
                 con.Close();
             }
             else
             {
                 reader.Close();
                 com = new SqlCommand("select * from NTVC.TARJETA where cod_cliente = @cod_cliente", con);
                 com.Parameters.AddWithValue("@cod_cliente", textCliente.Text);
                 reader = com.ExecuteReader();
                 if (reader.Read())
                 {
                     //el cliente ya tiene asignada una tarjeta
                     MessageBox.Show("El cliente ya tiene una tarjeta asignada.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                     reader.Close();
                     con.Close();
                 }
                 else
                 {
                     reader.Close();
                     bool habilitado = false;
                     com = new SqlCommand("select habilitado from ntvc.cliente where cod_cliente = @cod_cliente", con);
                     com.Parameters.AddWithValue("@cod_cliente", textCliente.Text);
                     reader = com.ExecuteReader();
                     if (reader.Read())
                     {
                         if (reader["habilitado"].ToString().Trim() == "1")
                         {
                             habilitado = true;
                         }
                     }
                     reader.Close();
                     if (habilitado)
                     {
                         com = new SqlCommand("insert into ntvc.tarjeta (nro_tarjeta, fecha_alta, credito, cod_cliente) values (@nro_tarjeta, @fecha_alta, @cred, @cod_cliente)", con);
                         com.Parameters.AddWithValue("@nro_tarjeta", this.textNumeroTarjeta.Text);
                         com.Parameters.AddWithValue("@fecha_alta", this.textFechaAlta.Text);
                         com.Parameters.AddWithValue("@cred", 0);
                         com.Parameters.AddWithValue("@cod_cliente", this.textCliente.Text);
                         com.ExecuteNonQuery();
                         this.Close();
                         MessageBox.Show("La tarjeta ha sido agregada.", "Alta exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
                     }
                     else
                     {
                         MessageBox.Show("El cliente se encuentra inhabilitado.\nNo se le puede asignar una tarjeta.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                     }
                     con.Close();
                 }
             }
         }
         else
         {
             MessageBox.Show("El número de tarjeta debe ser un valor numérico, positivo y menor a 2000000000", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
         }
     }
 }
Ejemplo n.º 16
0
        private void botBuscar_Click(object sender, EventArgs e)
        {
            string query = "select nombre as Nombre, apellido as Apellido, doc as Documento, mail as Mail, telefono as Teléfono, dir_Calle as Calle, dir_nro as Número, dir_piso as Piso, dir_dpto as Depto from NTVC.Cliente where ";

            //chequeo que los campos sean numericos
            if ((FuncionesUtiles.esNumerico(textDNI) || FuncionesUtiles.estaVacio(textDNI)) &&
                (FuncionesUtiles.esNumerico(textTelefono) || FuncionesUtiles.estaVacio(textTelefono)) &&
                (FuncionesUtiles.esNumerico(textNumero) || FuncionesUtiles.estaVacio(textNumero)))
            {
                if (textNombre.Text != "")
                {
                    query += "nombre like '%" + textNombre.Text + "%' and ";
                }
                if (textApellido.Text != "")
                {
                    query += "apellido like '%" + textApellido.Text + "%' and ";
                }
                if (textDNI.Text != "")
                {
                    query += "DNI = " + textDNI.Text + " and ";
                }
                if (textTelefono.Text != "")
                {
                    query += "telefono = " + textTelefono.Text + " and ";
                }
                if (textMail.Text != "")
                {
                    query += "mail like '%" + textMail.Text + "%' and ";
                }
                if (textCalle.Text != "")
                {
                    query += "dir_calle like '%" + textCalle.Text + "%' and ";
                }
                if (textNumero.Text != "")
                {
                    query += "dir_nro = " + textNumero.Text + " and ";
                }
                if (textPiso.Text != "")
                {
                    query += "dir_piso = " + textPiso.Text + " and ";
                }
                if (textDepto.Text != "")
                {
                    query += "dir_dpto = '" + textDepto.Text + "' and ";
                }

                query += "1=1";
                FuncionesUtiles.llenarDataGridView(query, dataGridView1);
            }
            else
            {
                string mensaje = "Los siguientes campos deben ser numéricos y positivos:";
                if (!FuncionesUtiles.esNumerico(textDNI) && !FuncionesUtiles.estaVacio(textDNI))
                {
                    mensaje += "\n-Documento";
                }
                if (!FuncionesUtiles.esNumerico(textTelefono) && !FuncionesUtiles.estaVacio(textTelefono))
                {
                    mensaje += "\n-Teléfono";
                }
                if (!FuncionesUtiles.esNumerico(textNumero) && !FuncionesUtiles.estaVacio(textNumero))
                {
                    mensaje += "\n-Número";
                }
                MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
        }
Ejemplo n.º 17
0
        private void botModificar_Click(object sender, EventArgs e)
        {
            if (FuncionesUtiles.estanVacios(new List <TextBox> {
                textApellido, textCalle, textMail, textNombre, textNumero, textTelefono
            }) || comboBox1.SelectedIndex == -1)
            {
                string mensaje = "Debe completar los siguientes campos:";
                if (textNombre.Text == "")
                {
                    mensaje += "\n-Nombre";
                }
                if (textApellido.Text == "")
                {
                    mensaje += "\n-Apellido";
                }
                if (comboBox1.SelectedIndex == -1)
                {
                    mensaje += "\n-Provincia";
                }
                if (textTelefono.Text == "")
                {
                    mensaje += "\n-Teléfono";
                }
                if (textMail.Text == "")
                {
                    mensaje += "\n-Mail";
                }
                if (textCalle.Text == "")
                {
                    mensaje += "\n-Calle";
                }
                if (textNumero.Text == "")
                {
                    mensaje += "\n-Número";
                }
                MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            else
            {
                //campos completos, verificar los numericos
                if (!FuncionesUtiles.sonNumericos(new List <TextBox> {
                    textNumero, textTelefono
                }))
                {
                    //hay campos numericos con valores no numericos
                    string mensaje = "Los siguientes campos deben ser numéricos y positivos:";
                    if (!FuncionesUtiles.esNumerico(textTelefono) && !FuncionesUtiles.estaVacio(textTelefono))
                    {
                        mensaje += "\n-Teléfono";
                    }
                    if (!FuncionesUtiles.esNumerico(textNumero) && !FuncionesUtiles.estaVacio(textNumero))
                    {
                        mensaje += "\n-Número";
                    }
                    MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                }
                else
                {
                    //campos correctos
                    SqlConnection con = Conexion.conectar();
                    con.Open();
                    //hacer update
                    string     cod_prov = "";
                    SqlCommand com      = new SqlCommand("select cod_provincia from ntvc.provincia  where nombre = @nombre_prov", con);
                    com.Parameters.AddWithValue("@nombre_prov", comboBox1.Items[comboBox1.SelectedIndex].ToString().Trim());
                    SqlDataReader reader = com.ExecuteReader();
                    if (reader.Read())
                    {
                        cod_prov = reader["cod_provincia"].ToString().Trim();
                    }
                    reader.Close();
                    string update = "UPDATE NTVC.cliente set nombre = @nombre, apellido = @apellido, mail = @mail, telefono = @telefono,";
                    update += " dir_calle = @dir_calle, dir_nro = @dir_numero, dir_piso = @dir_piso, dir_dpto = @dir_depto, habilitado = @habilitado, cod_provincia = @cod_provincia";
                    update += " where doc = @doc and tipo_doc = @tipo_doc";
                    com     = new SqlCommand(update, con);
                    com.Parameters.AddWithValue("@nombre", textNombre.Text);
                    com.Parameters.AddWithValue("@apellido", textApellido.Text);
                    com.Parameters.AddWithValue("@tipo_doc", tipo_doc_);
                    com.Parameters.AddWithValue("@doc", doc_);
                    com.Parameters.AddWithValue("@mail", textMail.Text);
                    com.Parameters.AddWithValue("@telefono", textTelefono.Text);
                    com.Parameters.AddWithValue("@dir_calle", textCalle.Text);
                    com.Parameters.AddWithValue("@dir_numero", textNumero.Text);
                    com.Parameters.AddWithValue("@dir_piso", textPiso.Text);
                    com.Parameters.AddWithValue("@dir_depto", textDepto.Text);
                    if (chkHabilitado.CheckState == CheckState.Checked)
                    {
                        com.Parameters.AddWithValue("@habilitado", 1);
                    }
                    else
                    {
                        com.Parameters.AddWithValue("@habilitado", 0);
                    }
                    com.Parameters.AddWithValue("@cod_provincia", cod_prov);
                    com.ExecuteNonQuery();
                    MessageBox.Show("El cliente ha sido modificado.", "Modificación exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
                    this.Close();

                    con.Close();
                }
            }
        }
Ejemplo n.º 18
0
        private void botModificar_Click(object sender, EventArgs e)
        {
            int cant_roles = 0;

            foreach (int indice in checkedListBox1.CheckedIndices)
            {
                cant_roles++;
            }
            if (FuncionesUtiles.estanVacios(new List <TextBox> {
                textPassword
            }) || cant_roles == 0)
            {
                string mensaje = "Debe completar los siguientes campos:";
                if (FuncionesUtiles.estaVacio(textPassword))
                {
                    mensaje += "\n-Password";
                }
                if (cant_roles == 0)
                {
                    mensaje += "\n-Roles";
                }

                MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            else
            {
                SqlDataReader reader;
                SqlConnection con = Conexion.conectar();
                con.Open();
                SqlCommand com = new SqlCommand("delete ntvc.usuario_rol where cod_usuario = @cod_usuario", con);
                com.Parameters.AddWithValue("@cod_usuario", cod_usuario_);
                com.ExecuteNonQuery();
                com = new SqlCommand("update ntvc.usuario set password = @password, habilitado = @habilitado where cod_usuario = @cod_usuario", con);
                com.Parameters.AddWithValue("@password", Encriptar.sha256(textPassword.Text));
                com.Parameters.AddWithValue("@cod_usuario", cod_usuario_);
                if (chkHabilitado.Checked)
                {
                    com.Parameters.AddWithValue("@habilitado", "1");
                }
                else
                {
                    com.Parameters.AddWithValue("@habilitado", "0");
                }
                com.ExecuteNonQuery();
                string cod_rol = "";
                foreach (int indice in checkedListBox1.CheckedIndices)
                {
                    com = new SqlCommand("select cod_rol from ntvc.rol where nombre = @nombre_rol", con);
                    com.Parameters.AddWithValue("@nombre_rol", checkedListBox1.GetItemText(checkedListBox1.Items[indice]).ToString().Trim());
                    reader = com.ExecuteReader();
                    if (reader.Read())
                    {
                        cod_rol = reader["cod_rol"].ToString().Trim();
                    }
                    reader.Close();
                    com = new SqlCommand("insert into ntvc.usuario_rol (cod_rol, cod_usuario) values(@cod_rol, @cod_usuario)", con);
                    com.Parameters.AddWithValue("@cod_rol", cod_rol);
                    com.Parameters.AddWithValue("@cod_usuario", cod_usuario_);
                    com.ExecuteNonQuery();
                }
                this.Close();
                MessageBox.Show("El usuario ha sido modificado.", "Modificación exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
            }
        }
Ejemplo n.º 19
0
 private void botModificar_Click(object sender, EventArgs e)
 {
     if (FuncionesUtiles.estaVacio(textNombre))
     {
         MessageBox.Show("Debe ingresar un nombre de rol.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
     }
     else
     {
         int cantFunc = 0;
         foreach (int func in checkedListBox1.CheckedIndices)
         {
             cantFunc++;
         }
         if (cantFunc == 0)
         {
             //no hay ninguna funcionalidad seleccionada
             MessageBox.Show("Debe seleccionar al menos una funcionalidad", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
         }
         else
         {
             SqlConnection con = Conexion.conectar();
             con.Open();
             SqlCommand com = new SqlCommand("select * from ntvc.rol where nombre = @nombre", con);
             com.Parameters.AddWithValue("@nombre", textNombre.Text);
             SqlDataReader reader = com.ExecuteReader();
             if (!reader.Read() || textNombre.Text == nombre_rol_viejo)
             {
                 //guardar el rol
                 reader.Close();
                 com = new SqlCommand("update ntvc.rol set nombre = @nombre, habilitacion = @habilitado where cod_rol = @cod_rol", con);
                 com.Parameters.AddWithValue("@cod_rol", cod_rol_modificar);
                 com.Parameters.AddWithValue("@nombre", textNombre.Text);
                 if (chkHabilitado.Checked)
                 {
                     com.Parameters.AddWithValue("@habilitado", "1");
                 }
                 else
                 {
                     com.Parameters.AddWithValue("@habilitado", "0");
                 }
                 com.ExecuteNonQuery();
                 com = new SqlCommand("delete ntvc.rol_funcionalidad where cod_rol = @cod_rol", con);
                 com.Parameters.AddWithValue("@cod_rol", cod_rol_modificar);
                 com.ExecuteNonQuery();
                 foreach (int indice in checkedListBox1.CheckedIndices)
                 {
                     com = new SqlCommand("insert into ntvc.rol_funcionalidad (cod_rol, cod_funcionalidad) values(@cod_rol, @cod_funcionalidad)", con);
                     com.Parameters.AddWithValue("@cod_rol", cod_rol_modificar);
                     com.Parameters.AddWithValue("@cod_funcionalidad", indice + 1);
                     com.ExecuteNonQuery();
                 }
                 con.Close();
                 this.Close();
                 MessageBox.Show("El rol ha sido modificado exitosamente.", "Rol agregado", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
             }
             else
             {
                 //ya existe el rol
                 reader.Close();
                 MessageBox.Show("El rol ya existe. Por favor, ingrese otro nombre.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                 textNombre.Text = nombre_rol_viejo;
                 con.Close();
             }
         }
     }
 }
Ejemplo n.º 20
0
        private void botCargarCredito_Click(object sender, EventArgs e)
        {
            if (FuncionesUtiles.estanVacios(new List <TextBox> {
                textNumeroTarjeta, textFecha, textMonto
            }))
            {
                string mensaje = "Debe completar los siguientes campos:";
                if (FuncionesUtiles.estaVacio(textNumeroTarjeta))
                {
                    mensaje += "\n-Número de tarjeta";
                }
                if (FuncionesUtiles.estaVacio(textFecha))
                {
                    mensaje += "\n-Fecha";
                }
                if (FuncionesUtiles.estaVacio(textMonto))
                {
                    mensaje += "\n-Monto";
                }
                MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            else
            {
                if (!FuncionesUtiles.sonNumericos(new List <TextBox> {
                    textNumeroTarjeta
                }) || !FuncionesUtiles.esDecimal(textMonto))
                {
                    //hay campos numericos con valores no numericos
                    string mensaje = "Los siguientes campos deben ser numéricos y positivos:";
                    if (!FuncionesUtiles.esDecimal(textMonto))
                    {
                        mensaje += "\n-Monto";
                    }
                    if (!FuncionesUtiles.esNumerico(textNumeroTarjeta))
                    {
                        mensaje += "\n-Número de tarjeta";
                    }
                    MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                }
                else
                {
                    //el valor de numero de tarjeta es numerico
                    SqlConnection con = Conexion.conectar();
                    SqlCommand    com = new SqlCommand("select * from NTVC.TARJETA where nro_tarjeta = @nro_tarjeta", con);
                    com.Parameters.AddWithValue("@nro_tarjeta", this.textNumeroTarjeta.Text);
                    con.Open();
                    SqlDataReader reader = com.ExecuteReader();
                    //veo si el numero de tarjeta existe

                    if (reader.Read())
                    {
                        //la tarjeta existe

                        //verifico que este habilitada
                        if (reader["habilitado"].ToString().Trim() == "1")
                        {
                            string  cod_tarjeta   = reader["cod_tarjeta"].ToString().Trim();
                            decimal credito_nuevo = Convert.ToDecimal(reader["credito"].ToString().Trim()) + Convert.ToDecimal(textMonto.Text);
                            reader.Close();
                            com = new SqlCommand("update ntvc.tarjeta set credito = @credito where cod_tarjeta = @cod_tarjeta", con);
                            com.Parameters.AddWithValue("@credito", credito_nuevo);
                            com.Parameters.AddWithValue("@cod_tarjeta", cod_tarjeta);
                            com.ExecuteNonQuery();
                            com = new SqlCommand("insert into ntvc.carga (cod_tarjeta, fecha,monto) values (@cod_tarjeta, @fecha, @monto)", con);
                            com.Parameters.AddWithValue("@cod_tarjeta", cod_tarjeta);
                            com.Parameters.AddWithValue("@fecha", this.textFecha.Text);
                            com.Parameters.AddWithValue("@monto", this.textMonto.Text);
                            com.ExecuteNonQuery();
                            this.Close();
                            BoletoElectronicoDesktop.Facturación.Saldo form = new BoletoElectronicoDesktop.Facturación.Saldo();
                            form.labelSaldo.Text = "La carga ha sido efectuada exitosamente.\nSu saldo es " + credito_nuevo.ToString() + ".";
                            form.ShowDialog(this);
                        }
                        else
                        {
                            //la tarjeta esta deshabilitada
                            reader.Close();
                            MessageBox.Show("La tarjeta se encuentra inhabilitada.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                        }
                        con.Close();
                    }
                    else
                    {
                        MessageBox.Show("El número de tarjeta ingresado no existe.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                        reader.Close();
                        con.Close();
                    }
                }
            }
        }
Ejemplo n.º 21
0
 private void botModificar_Click(object sender, EventArgs e)
 {
     if (FuncionesUtiles.estanVacios(new List <TextBox> {
         textNumeroTarjeta, textCliente
     }))
     {
         string mensaje = "Debe completar los siguientes campos:";
         if (FuncionesUtiles.estaVacio(textNumeroTarjeta))
         {
             mensaje += "\n-Número de tarjeta";
         }
         if (FuncionesUtiles.estaVacio(textCliente))
         {
             mensaje += "\n-Cliente";
         }
         MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
     }
     else
     {
         if (FuncionesUtiles.esNumerico(this.textNumeroTarjeta))
         {
             //el valor de numero de tarjeta es numerico
             SqlConnection con = Conexion.conectar();
             SqlCommand    com = new SqlCommand("select nro_tarjeta from NTVC.TARJETA where nro_tarjeta = @nro_tarjeta", con);
             com.Parameters.AddWithValue("@nro_tarjeta", this.textNumeroTarjeta.Text);
             con.Open();
             SqlDataReader reader = com.ExecuteReader();
             if (reader.Read() && reader["nro_tarjeta"].ToString() != nro_tarjeta_viejo)
             {
                 //ya existe esa tarjeta
                 MessageBox.Show("El número de tarjeta ingresado ya existe", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                 textNumeroTarjeta.Text = nro_tarjeta_viejo;
                 reader.Close();
                 con.Close();
             }
             else
             {
                 reader.Close();
                 com = new SqlCommand("select * from NTVC.TARJETA where cod_cliente = @cod_cliente", con);
                 com.Parameters.AddWithValue("@cod_cliente", textCliente.Text);
                 reader = com.ExecuteReader();
                 if (reader.Read() && reader["cod_cliente"].ToString() != cod_cliente_viejo)
                 {
                     //el cliente ya tiene asignada una tarjeta
                     MessageBox.Show("El cliente ya tiene una tarjeta asignada.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                     textCliente.Text = cod_cliente_viejo;
                     reader.Close();
                     con.Close();
                 }
                 else
                 {
                     reader.Close();
                     bool habilitado = false;
                     com = new SqlCommand("select habilitado from ntvc.cliente where cod_cliente = @cod_cliente", con);
                     com.Parameters.AddWithValue("@cod_cliente", textCliente.Text);
                     reader = com.ExecuteReader();
                     if (reader.Read())
                     {
                         if (reader["habilitado"].ToString().Trim() == "1")
                         {
                             habilitado = true;
                         }
                     }
                     reader.Close();
                     if (habilitado)
                     {
                         com = new SqlCommand("update ntvc.tarjeta set nro_tarjeta = @nro_tarjeta, cod_cliente = @cod_cliente, habilitado = @habilitado where nro_tarjeta = @nro_viejo", con);
                         com.Parameters.AddWithValue("@nro_tarjeta", this.textNumeroTarjeta.Text);
                         if (chkHabilitado.Checked)
                         {
                             com.Parameters.AddWithValue("@habilitado", "1");
                         }
                         else
                         {
                             com.Parameters.AddWithValue("@habilitado", "0");
                         }
                         com.Parameters.AddWithValue("@nro_viejo", nro_tarjeta_viejo);
                         com.Parameters.AddWithValue("@cod_cliente", this.textCliente.Text);
                         com.ExecuteNonQuery();
                         this.Close();
                         MessageBox.Show("La tarjeta ha sido modificada.", "Modificación exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
                     }
                     else
                     {
                         MessageBox.Show("El cliente se encuentra inhabilitado.\nNo se le puede asignar una tarjeta.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                         textCliente.Text = cod_cliente_viejo;
                     }
                     con.Close();
                 }
             }
         }
         else
         {
             MessageBox.Show("El número de tarjeta debe ser un valor numérico menor a 2000000000", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
         }
     }
 }