Пример #1
0
        public static void insertarCircuito(ClaseCircuito ocircuito)
        {
            Controlador.Conectar();
            OleDbConnection BDConexion = Controlador.BDConexion;

            BDConexion.Open();
            try
            {
                string       insertar = "INSERT INTO CIRCUITOS(TITULO,CIRCUITO_PADRE,NIVEL) VALUES (@titulo, @padre, @nivel)";
                OleDbCommand cmd      = new OleDbCommand(insertar, BDConexion);

                cmd.Parameters.AddWithValue("@titulo", ocircuito.titulo);
                cmd.Parameters.AddWithValue("@padre", ocircuito.padre);
                cmd.Parameters.AddWithValue("@nivel", ocircuito.nivel);

                cmd.ExecuteNonQuery();

                MessageBox.Show("Registro guardado");
            }
            catch (DBConcurrencyException ex)
            {
                MessageBox.Show("Error de concurrencia:\n" + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            BDConexion.Close();
        }
Пример #2
0
        public static ArrayList buscarCircuitos()
        {
            Controlador.Conectar();
            OleDbConnection BDConexion = Controlador.BDConexion;

            BDConexion.Open();
            try
            {
                string          buscar = "SELECT * FROM CIRCUITOS";
                OleDbCommand    cmd    = new OleDbCommand(buscar, BDConexion);
                OleDbDataReader lector = cmd.ExecuteReader();
                object[]        objeto = new object[10];
                bool            read;
                if (lector.Read())
                {
                    do
                    {
                        int NumberOfColums = lector.GetValues(objeto);

                        ClaseCircuito ocircuito = new ClaseCircuito(Convert.ToInt16(objeto[0]), Convert.ToInt16(objeto[1]), Convert.ToInt16(objeto[2]), objeto[3].ToString());
                        Circuito.listaCircuitos.Add(ocircuito);

                        Console.WriteLine(ocircuito);
                        read = lector.Read();
                    }while (read == true);
                    BDConexion.Close();
                    return(Circuito.listaCircuitos);
                }
                else
                {
                    BDConexion.Close();
                    return(null);
                }
            }
            catch (DBConcurrencyException ex)
            {
                MessageBox.Show("Error de concurrencia:\n" + ex.Message);
                BDConexion.Close();
                return(null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                BDConexion.Close();
                return(null);
            }
        }
Пример #3
0
        public static ArrayList buscarCircuitosHijos(int id)
        {
            Controlador.Conectar();
            OleDbConnection BDConexion = Controlador.BDConexion;

            BDConexion.Open();
            string       buscar = "SELECT * FROM CIRCUITOS WHERE CIRCUITO_PADRE = @id";
            OleDbCommand cmd    = new OleDbCommand(buscar, BDConexion);

            cmd.Parameters.AddWithValue("@id", id);

            OleDbDataReader lector = cmd.ExecuteReader();

            object[] objeto = new object[10];
            bool     read;

            if (lector.Read())
            {
                do
                {
                    int NumberOfColums = lector.GetValues(objeto);

                    ClaseCircuito ocircuito = new ClaseCircuito(Convert.ToInt16(objeto[0]), Convert.ToInt16(objeto[1]), Convert.ToInt16(objeto[2]), objeto[3].ToString());
                    Circuito.circuitosHijos.Add(ocircuito);

                    Console.WriteLine(ocircuito);
                    read = lector.Read();
                }while (read == true);
                BDConexion.Close();
                return(Circuito.circuitosHijos);
            }
            else
            {
                BDConexion.Close();
                return(null);
            }
        }