Exemplo n.º 1
0
        private bool consultaUsuarios()
        {
            bool            flag               = false;
            int             posicion           = 0;
            string          sSQL               = "SELECT `idUser`,`noCta`,`nomUser`,`apP`,`apM`,`tel`,`email`,`sex`,`tipoUser`,`status` FROM `usuario` ";
            Conexion        cn                 = new Conexion();
            MySqlConnection databaseConnection = cn.ConexionNew();
            MySqlCommand    commandDatabase    = new MySqlCommand(sSQL, databaseConnection);

            commandDatabase.CommandTimeout = 60;
            MySqlDataReader reader;

            try
            {
                databaseConnection.Open();
                reader = commandDatabase.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string[] row = { reader.GetString("idUser"),   //0
                                         reader.GetString("noCta"),    //1
                                         reader.GetString("nomUser"),  //2
                                         reader.GetString("apP"),      //3
                                         reader.GetString("apM"),      //4
                                         reader.GetString("tel"),      //5
                                         reader.GetString("email"),    //6
                                         reader.GetString("sex"),      //7
                                         reader.GetString("tipoUser"), //8
                                         reader.GetString("status") }; //9
                        if (row.Length > 0)
                        {
                            int     idUser   = Convert.ToInt32(row[0]);
                            int     noCuenta = Convert.ToInt32(row[1]);
                            string  name     = row[2];
                            string  app      = row[3];
                            string  apm      = row[4];
                            string  tel      = row[5];
                            string  email    = row[6];
                            int     sex      = Convert.ToInt32(row[7]);
                            int     tc       = Convert.ToInt32(row[8]);
                            int     status   = Convert.ToInt32(row[9]);
                            USUARIO nvoUser  = new USUARIO(idUser, noCuenta, name, app, apm, tel, email, sex, tc, status);
                            agregarToList(listaUsuarios, nvoUser);
                            posicion++;
                            flag = true;
                        }
                        else
                        {
                            MessageBox.Show("Error");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("El No de Cuenta no existe");
                }
                // Cerrar la conexión
                databaseConnection.Close();
            }
            catch (Exception ex)
            {
                // Mostrar cualquier excepción
                MessageBox.Show(ex.Message);
            }
            return(flag);
        }
Exemplo n.º 2
0
        private void buscarUser(string noCueta)
        {
            // Tu consulta en SQL

            string query = "SELECT " +
                           " `idUser`,`noCta`,`nomUser`,`apP`,`apM`,`tel`,`email`,`sex`,`tipoUser`,`status` " +
                           " FROM `usuario` WHERE `status` = 1 AND `noCta` = '" + noCueta + "'  ;";
            // Prepara la conexión
            Conexion        cn = new Conexion();
            MySqlConnection databaseConnection = cn.ConexionNew();
            MySqlCommand    commandDatabase    = new MySqlCommand(query, databaseConnection);

            commandDatabase.CommandTimeout = 60;
            MySqlDataReader reader;

            try
            {
                databaseConnection.Open();
                reader = commandDatabase.ExecuteReader();
                //copia del reader
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        /*
                         * `idUser`,`noCta`,`nomUser`,`apP`,`apM`,`tel`,`email`,`sex`,`tipoUser`,`status`
                         */
                        // string pw = reader.GetString("psw");
                        string[] row = { reader.GetString("idUser"),   //0
                                         reader.GetString("noCta"),    //1
                                         reader.GetString("nomUser"),  //2
                                         reader.GetString("apP"),      //3
                                         reader.GetString("apM"),      //4
                                         reader.GetString("tel"),      //5
                                         reader.GetString("email"),    //6
                                         reader.GetString("sex"),      //7
                                         reader.GetString("tipoUser"), //8
                                         reader.GetString("status") }; //9
                        if (row.Length > 0)
                        {
                            //int idEmp, int noCuenta, string name, string app, string apm, string tel, string email, char sex, int tc, bool status, string psw
                            int    idUser   = Convert.ToInt32(row[0]);
                            int    noCuenta = Convert.ToInt32(row[1]);
                            string name     = row[2];
                            string app      = row[3];
                            string apm      = row[4];
                            string tel      = row[5];
                            string email    = row[6];
                            int    sex      = Convert.ToInt32(row[7]);
                            int    tc       = Convert.ToInt32(row[8]);
                            int    status   = Convert.ToInt32(row[9]);
                            //int id, int cta, string nom, string ap, string am, string tel, string email, int sex, int tipo, int status
                            this.usuario = new USUARIO(idUser, noCuenta, name, app, apm, tel, email, sex, tc, status);
                        }
                        else
                        {
                            MessageBox.Show("Error");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("El No de Cuenta no existe");
                }
                // Cerrar la conexión
                databaseConnection.Close();
            }
            catch (Exception ex)
            {
                // Mostrar cualquier excepción
                MessageBox.Show(ex.Message);
            }
        }