Example #1
0
        /********************************************************************************
        *                              BuscarRegistro()                                *
        *                                     -                                        *
        *     Metodo para seleccionar y extraer los datos de un registro de la BD      *
        ********************************************************************************/
        private void BuscarRegistro()
        {
            try
            {
                //Para extraer los datos del registro seleccionado en la base de datos
                MySqlDataReader LectorClientes;

                //Abrimos la conexion hacia la BD
                conexion.conexion.Open();

                //Creamos una instruccion o comando SQL
                MySqlCommand Comando = new MySqlCommand();

                //Le asignamos la conexion actual
                Comando.Connection = conexion.conexion;

                //Enviamos el parametro o la consulta que se desea realizar en SQL
                Comando.CommandText = "select * from usuarios where usuarios.id =" + txtCodigo.Text;

                //Ejecutamos el comando y almacenamos el resultado en el Lector de datos.
                LectorClientes = Comando.ExecuteReader();

                //Si se encontró un registro, entonces mostramos los datos de este registro en el formulario.
                if (LectorClientes.Read() == true)
                {
                    //Asignando el valor de cada campo al objeto correspondiente
                    txtNombre.Text                 = LectorClientes.GetString(1);
                    txtUsuario.Text                = LectorClientes.GetString(2).ToString();
                    txtContrasena.Text             = LectorClientes.GetString(3).ToString();
                    cmbTiposUsuarios.SelectedValue = LectorClientes.GetInt32(4);
                    lblFechaRegistro.Text          = LectorClientes.GetDateTime(5).ToShortDateString();
                    chkActivo.Checked              = LectorClientes.GetBoolean(6);
                    btnRegistroAnterior.Enabled    = btnRegistroSiguiente.Enabled = true;
                }
                //De lo contrario, si no se encontró ningun registro, Enviamos un mensaje al usuario.
                else
                {
                    MessageBox.Show("No existe un registro con este código, verifique y trate de nuevo", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    Limpiar(this);
                    return;
                }

                //Borramos el lector que almacena el registro, para poder utilizarlo nuevamente
                LectorClientes.Close();
            }
            catch (Exception Error)
            {
                MessageBox.Show(Error.Message, "Aviso - BuscarRegistro", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            finally
            {
                conexion.conexion.Close();
            }
        }
Example #2
0
        /********************************************************************************
        *                              BuscarRegistro()                                *
        *                                     -                                        *
        *     Metodo para seleccionar y extraer los datos de un registro de la BD      *
        ********************************************************************************/
        private void BuscarRegistro()
        {
            try
            {
                //Para extraer los datos del registro seleccionado en la base de datos
                MySqlDataReader LectorClientes;

                //Abrimos la conexion hacia la BD
                conexion.conexion.Open();

                //Creamos una instruccion o comando SQL
                MySqlCommand Comando = new MySqlCommand();

                //Le asignamos la conexion actual
                Comando.Connection = conexion.conexion;

                //Enviamos el parametro o la consulta que se desea realizar en SQL
                Comando.CommandText = "Select * From Productos where id =" + txtCodigo.Text;

                //Ejecutamos el comando y almacenamos el resultado en el Lector de datos.
                LectorClientes = Comando.ExecuteReader();

                //Si se encontró un registro, entonces mostramos los datos de este registro en el formulario.
                if (LectorClientes.Read() == true)
                {
                    //Asignando el valor de cada campo al objeto correspondiente
                    txtDenominacion.Text          = LectorClientes.GetString(1);
                    txtReferencia.Text            = LectorClientes.GetString(2).ToString();
                    txtCodigoBarra.Text           = LectorClientes.GetString(3).ToString();
                    txtCosto.Text                 = LectorClientes.GetDecimal(4).ToString();
                    txtPrecioVenta.Text           = LectorClientes.GetDecimal(5).ToString();
                    txtDescripcion.Text           = LectorClientes.GetString(6).ToString();
                    txtMesesGarantia.Text         = LectorClientes.GetInt32(7).ToString();
                    txtDiasEntrega.Text           = LectorClientes.GetInt32(8).ToString();
                    chkBloqueado.Checked          = LectorClientes.GetBoolean(9);
                    chkITBIS.Checked              = LectorClientes.GetBoolean(10);
                    chkProductoInventario.Checked = LectorClientes.GetBoolean(11);
                    lblExistencia.Text            = LectorClientes.GetDecimal(12).ToString();
                    lblFechaRegistro.Text         = LectorClientes.GetDateTime(13).ToShortDateString();
                    lblUltimaVenta.Text           = LectorClientes.GetDateTime(14).ToShortDateString();
                    cmbTipoProducto.SelectedValue = LectorClientes.GetInt32(15);
                    cmbSuplidor.SelectedValue     = LectorClientes.GetInt32(16);
                    if (LectorClientes.GetString(17).Length > 0)
                    {
                        pbxProducto.Image         = Image.FromFile(LectorClientes.GetString(17));
                        pbxProducto.ImageLocation = LectorClientes.GetString(17);
                    }
                    btnRegistroAnterior.Enabled = btnRegistroSiguiente.Enabled = true;
                }
                //De lo contrario, si no se encontró ningun registro, Enviamos un mensaje al usuario.
                else
                {
                    MessageBox.Show("No existe un registro con este código, verifique y trate de nuevo", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    Limpiar(this);
                    return;
                }

                //Borramos el lector que almacena el registro, para poder utilizarlo nuevamente
                LectorClientes.Close();
            }
            catch (Exception Error)
            {
                MessageBox.Show(Error.Message, "Aviso - BuscarRegistro", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            finally
            {
                conexion.conexion.Close();
            }
        }
        /********************************************************************************
        *                              BuscarRegistro()                                *
        *                                     -                                        *
        *     Metodo para seleccionar y extraer los datos de un registro de la BD      *
        ********************************************************************************/
        private void BuscarRegistro()
        {
            try
            {
                //Para extraer los datos del registro seleccionado en la base de datos
                MySqlDataReader LectorClientes;

                //Abrimos la conexion hacia la BD
                conexion.conexion.Open();

                //Creamos una instruccion o comando SQL
                MySqlCommand Comando = new MySqlCommand();

                //Le asignamos la conexion actual
                Comando.Connection = conexion.conexion;

                //Enviamos el parametro o la consulta que se desea realizar en SQL
                Comando.CommandText = "select clientes.*, personas.* from clientes INNER JOIN personas ON clientes.persona_id = personas.id where clientes.id =" + txtCodigo.Text;

                //Ejecutamos el comando y almacenamos el resultado en el Lector de datos.
                LectorClientes = Comando.ExecuteReader();

                //Si se encontró un registro, entonces mostramos los datos de este registro en el formulario.
                if (LectorClientes.Read() == true)
                {
                    //Asignando el valor de cada campo al objeto correspondiente
                    IdPersona = LectorClientes.GetInt32(1);
                    cmbVendedores.SelectedValue    = LectorClientes.GetInt32(2);
                    cmbTerminosPagos.SelectedValue = LectorClientes.GetInt32(3);
                    lblBalancePendiente.Text       = LectorClientes.GetDecimal(4).ToString();
                    txtLimiteCredito.Text          = LectorClientes.GetDecimal(5).ToString();
                    if (LectorClientes.GetDateTime(6).Equals(DateTime.MinValue))
                    {
                        lblUtimaVenta.Text = "-";
                    }
                    else
                    {
                        lblUtimaVenta.Text = LectorClientes.GetDateTime(6).ToShortDateString();
                    }
                    chkBloqueado.Checked      = LectorClientes.GetBoolean(7);
                    txtNombre.Text            = LectorClientes.GetString(9);
                    txtIdentificacion.Text    = LectorClientes.GetString(10).ToString();
                    txtCorreoElectronico.Text = LectorClientes.GetString(11).ToString();
                    txtDireccion.Text         = LectorClientes.GetString(12).ToString();
                    txtTelefono1.Text         = LectorClientes.GetString(13).ToString();
                    txtTelefono2.Text         = LectorClientes.GetString(14).ToString();
                    txtFax.Text           = LectorClientes.GetString(15).ToString();
                    txtCelular.Text       = LectorClientes.GetString(16).ToString();
                    txtObservaciones.Text = LectorClientes.GetString(17).ToString();
                    txtPaginaWeb.Text     = LectorClientes.GetString(18).ToString();
                    lblFechaRegistro.Text = LectorClientes.GetDateTime(19).ToShortDateString();
                    if (LectorClientes.GetString(21).Length > 0)
                    {
                        pbxCliente.Image         = Image.FromFile(LectorClientes.GetString(21));
                        pbxCliente.ImageLocation = LectorClientes.GetString(21);
                        btnQuitarFoto.Visible    = true;
                    }
                    else
                    {
                        pbxCliente.Image         = PymeSoft.Properties.Resources.default_user_icon;
                        pbxCliente.ImageLocation = "";
                        btnQuitarFoto.Visible    = false;
                    }
                    //cmbListaPrecios.SelectedValue = LectorClientes.GetInt32(18);
                    btnRegistroAnterior.Enabled = btnRegistroSiguiente.Enabled = true;
                }
                //De lo contrario, si no se encontró ningun registro, Enviamos un mensaje al usuario.
                else
                {
                    MessageBox.Show("No existe un registro con este código, verifique y trate de nuevo", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    Limpiar(this);
                    return;
                }

                //Borramos el lector que almacena el registro, para poder utilizarlo nuevamente
                LectorClientes.Close();
            }
            catch (Exception Error)
            {
                MessageBox.Show(Error.Message, "Aviso - BuscarRegistro", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            finally
            {
                conexion.conexion.Close();
            }
        }