private void btnBuscarEncargado_Click(object sender, EventArgs e) { frmBuscarMilitar ofrmBuscarMilitar = new frmBuscarMilitar(); ofrmBuscarMilitar.ShowDialog(); string cCodigo = ofrmBuscarMilitar.cCodigo; // Si selecciono un registro if (cCodigo != "" && cCodigo != null) { // Mostrar el codigo txtCedulaEncargado.Text = Convert.ToString(cCodigo).Trim(); try { // Step 1 - clsConexion MySqlConnection MyclsConexion = new MySqlConnection(clsConexion.ConectionString); // Step 2 - creating the command object MySqlCommand MyCommand = MyclsConexion.CreateCommand(); // Step 3 - creating the commandtext //MyCommand.CommandText = "SELECT * FROM paciente WHERE cedula = ' " + txtCedula.Text.Trim() + "' " ; MyCommand.CommandText = "SELECT * from militar WHERE cedula = '" + txtCedulaEncargado.Text.Trim() + "'"; // Step 4 - connection open MyclsConexion.Open(); // Step 5 - Creating the DataReader MySqlDataReader MyReader = MyCommand.ExecuteReader(); // Step 6 - Verifying if Reader has rows if (MyReader.HasRows) { while (MyReader.Read()) { cmbRangoEncargado.SelectedValue = MyReader["rango"].ToString(); txtNombreEncargado.Text = MyReader["nombre"].ToString(); txtApellidoEncargado.Text = MyReader["apellido"].ToString(); } this.cModo = "Buscar"; this.Botones(); } else { MessageBox.Show("No se encontraron registros con esta cedula...", "SisGesCom", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.txtCedula.Focus(); this.cModo = "Inicio"; this.Botones(); //this.Limpiar(); //this.txtID.Focus(); } // Step 6 - Closing all MyReader.Close(); MyCommand.Dispose(); MyclsConexion.Close(); } catch (Exception MyEx) { MessageBox.Show(MyEx.Message); } } }
private void btnBuscarJefe_Click(object sender, EventArgs e) { frmBuscarMilitar ofrmBuscarMilitar = new frmBuscarMilitar(); ofrmBuscarMilitar.ShowDialog(); string cCodigo = ofrmBuscarMilitar.cCodigo; // Si selecciono un registro if (cCodigo != "" && cCodigo != null) { // Mostrar el codigo txtCedulaJefe.Text = Convert.ToString(cCodigo).Trim(); try { // Step 1 - clsConexion MySqlConnection MyclsConexion = new MySqlConnection(clsConexion.ConectionString); // Step 2 - creating the command object MySqlCommand MyCommand = MyclsConexion.CreateCommand(); // Step 3 - creating the commandtext //MyCommand.CommandText = "SELECT * FROM paciente WHERE cedula = ' " + txtCedula.Text.Trim() + "' " ; MyCommand.CommandText = "SELECT * from tickets WHERE cedula = '" + txtCedulaJefe.Text.Trim() + "'"; // Step 4 - connection open MyclsConexion.Open(); // Step 5 - Creating the DataReader MySqlDataReader MyReader = MyCommand.ExecuteReader(); // Step 6 - Verifying if Reader has rows if (MyReader.HasRows) { while (MyReader.Read()) { cmbRangoJefe.SelectedValue = MyReader["rango"].ToString(); txtNombreJefe.Text = MyReader["nombre"].ToString(); txtApellidoJefe.Text = MyReader["apellido"].ToString(); } //this.cModo = "Buscar"; //this.Botones(); } else { MessageBox.Show("No se encontraron registros con esta cedula...", "SisGesCom", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.txtCedula.Focus(); this.cModo = "Inicio"; this.Botones(); //this.Limpiar(); //this.txtID.Focus(); } // Step 6 - Closing all MyReader.Close(); MyCommand.Dispose(); MyclsConexion.Close(); } catch (Exception MyEx) { MessageBox.Show(MyEx.Message); } } else { // ESTO ES CUANDO LA BUSQUEDA SE HACE PONIENDO LA CEDULA DESDE UN REGISTRO // QUE YA HA SIDO GUARDADO ANTERIORMENTE try { // Step 1 - clsConexion MySqlConnection MyclsConexion = new MySqlConnection(clsConexion.ConectionString); // Step 2 - creating the command object MySqlCommand MyCommand = MyclsConexion.CreateCommand(); // Step 3 - creating the commandtext //MyCommand.CommandText = "SELECT * FROM paciente WHERE cedula = ' " + txtCedula.Text.Trim() + "' " ; MyCommand.CommandText = "SELECT * from tickets WHERE cedula = '" + txtCedulaJefe.Text.Trim() + "'"; // Step 4 - connection open MyclsConexion.Open(); // Step 5 - Creating the DataReader MySqlDataReader MyReader = MyCommand.ExecuteReader(); // Step 6 - Verifying if Reader has rows if (MyReader.HasRows) { while (MyReader.Read()) { cmbRangoJefe.SelectedValue = MyReader["rango"].ToString(); txtNombreJefe.Text = MyReader["nombre"].ToString(); txtApellidoJefe.Text = MyReader["apellido"].ToString(); } //this.cModo = "Buscar"; //this.Botones(); } else { MessageBox.Show("No se encontraron registros con esta cedula...", "SisGesCom", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.txtCedula.Focus(); this.cModo = "Inicio"; this.Botones(); //this.Limpiar(); //this.txtID.Focus(); } // Step 6 - Closing all MyReader.Close(); MyCommand.Dispose(); MyclsConexion.Close(); } catch (Exception MyEx) { MessageBox.Show(MyEx.Message); } } }