/******************************************************************************** * BuscarRegistroMayoryMenor() * * - * * Metodo para seleccionar y extraer el primer y el ultimo registro de la BD * ********************************************************************************/ private void BuscarRegistroMayoryMenor() { try { //Para extraer los datos del registro seleccionado en la base de datos MySqlDataReader LectorVendedores; //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 count(id) From Vendedores"; //Ejecutamos el comando y almacenamos el resultado en el Lector de datos. LectorVendedores = Comando.ExecuteReader(); //Si se encontró un registro, entonces mostramos los datos de este registro en el formulario. if (LectorVendedores.Read() == true) { if (LectorVendedores.GetInt32(0) > 0) { LectorVendedores.Close(); //Enviamos el parametro o la consulta que se desea realizar en SQL Comando.CommandText = "Select max(id), min(id) From Vendedores"; //Ejecutamos el comando y almacenamos el resultado en el Lector de datos. LectorVendedores = Comando.ExecuteReader(); if (LectorVendedores.Read() == true) { //Asignando el valor de cada campo al objeto correspondiente mayor = LectorVendedores.GetInt32(0); menor = LectorVendedores.GetInt32(1); LectorVendedores.Close(); } } } else { //Borramos el lector que almacena el registro, para poder utilizarlo nuevamente LectorVendedores.Close(); } } catch (Exception Error) { MessageBox.Show(Error.Message, "Aviso - BuscarRegistroMayoryMenor", 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 LectorVendedores; //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 Vendedores.*, personas.* from Vendedores INNER JOIN personas ON Vendedores.persona_id = personas.id where Vendedores.id =" + txtCodigo.Text; //Ejecutamos el comando y almacenamos el resultado en el Lector de datos. LectorVendedores = Comando.ExecuteReader(); //Si se encontró un registro, entonces mostramos los datos de este registro en el formulario. if (LectorVendedores.Read() == true) { //Asignando el valor de cada campo al objeto correspondiente IdPersona = LectorVendedores.GetInt32(1); chkComision.Checked = LectorVendedores.GetBoolean(2); if (LectorVendedores.GetDateTime(3).Equals(DateTime.MinValue)) { lblUtimaCompra.Text = "-"; } else { lblUtimaCompra.Text = LectorVendedores.GetDateTime(3).ToShortDateString(); } txtNombre.Text = LectorVendedores.GetString(5); txtIdentificacion.Text = LectorVendedores.GetString(6).ToString(); txtCorreoElectronico.Text = LectorVendedores.GetString(7).ToString(); txtDireccion.Text = LectorVendedores.GetString(8).ToString(); txtTelefono1.Text = LectorVendedores.GetString(9).ToString(); txtTelefono2.Text = LectorVendedores.GetString(10).ToString(); txtFax.Text = LectorVendedores.GetString(11).ToString(); txtCelular.Text = LectorVendedores.GetString(12).ToString(); txtObservaciones.Text = LectorVendedores.GetString(13).ToString(); lblFechaRegistro.Text = LectorVendedores.GetDateTime(15).ToShortDateString(); if (LectorVendedores.GetString(17).Length > 0) { pbxVendedor.Image = Image.FromFile(LectorVendedores.GetString(17)); pbxVendedor.ImageLocation = LectorVendedores.GetString(17); btnQuitarFoto.Visible = true; } else { pbxVendedor.Image = PymeSoft.Properties.Resources.default_user_icon; pbxVendedor.ImageLocation = ""; btnQuitarFoto.Visible = false; } 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 LectorVendedores.Close(); } catch (Exception Error) { MessageBox.Show(Error.Message, "Aviso - BuscarRegistro", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } finally { conexion.conexion.Close(); } }