//comprobar si el niño existe
        public Boolean exist(int carnet)
        {
            Boolean          result       = true;
            DataSet          dataNino     = new DataSet();
            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;
            String           sql;

            sql = "SELECT count(carnet) as result from nino where carnet = '" + carnet + "'";
            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlAdapter.Fill(dataNino);
                int coun = int.Parse(dataNino.Tables[0].Rows[0][0].ToString());
                if (coun != 0)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                result = false;
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(result);
        }
Esempio n. 2
0
        //Añade una monitor a la tabla Monitor
        //Parametro = objeto Monitor
        //return 1 si la insercion es correcta o 0 si es error
        public int addMonitor(Monitor monitor)
        {
            int result = 0;

            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;

            String sql;
            String fechaConver = monitor.MyfechaNaci.ToString("yyyy/MM/dd");

            sql = "INSERT INTO monitor (dni, fecha_nac) VALUES ('" + monitor.Mydni.ToString() + "', '" + fechaConver + "')";

            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlCmd.ExecuteNonQuery();
                result = 1;
            }
            catch (Exception e)
            {
                Console.Write(e);
                result = 0;
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(result);
        }
Esempio n. 3
0
        //Añade una actividad a la tabla acitividad
        //Parametro = objeto Actividad
        //return 1 si la insercion es correcta o 0 si es error
        public int addActividad(Actividad actividad)
        {
            int result = 0;

            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;

            String sql;

            sql = "INSERT INTO actividad (codigo, description) VALUES ('" + actividad.MycodigoActividad.ToString() + "', '" + actividad.Mydescripcion.ToString() + "')";

            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlCmd.ExecuteNonQuery();
                result = 1;
            }
            catch (Exception e)
            {
                Console.Write(e);
                result = 0;
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(result);
        }
        //Añade una actividad a la tabla administrador
        //Parametro = objeto Administrador
        //return 1 si la insercion es correcta o 0 si es error
        public int addAdmin(Administrador admin)
        {
            int result = 0;

            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;

            String sql;

            sql = "INSERT INTO administrador (dni, num_SS , titulacion) VALUES ('" + admin.Mydni.ToString() + "', '" + admin.Mynum_SS.ToString() + "', '" + admin.Mytitulacion.ToString() + "')";

            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlCmd.ExecuteNonQuery();
                result = 1;
            }
            catch (Exception e)
            {
                Console.Write(e);
                result = 0;
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(result);
        }
Esempio n. 5
0
        //Function to search al personal,
        //return a DataSet,if is null return a null DataSet
        public List <Personal> getAllPersonal()
        {
            DataSet          dataPersonal = new DataSet();
            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;
            String           sql;
            List <Personal>  listPersonal = new List <Personal>();

            sql = "SELECT * from personal;";
            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlAdapter.Fill(dataPersonal);

                DataTable dt = dataPersonal.Tables[0];

                foreach (DataRow row in dt.Rows)
                {
                    listPersonal.Add(new Personal(Convert.ToString(row["dni"]), Convert.ToString(row["nombre"]), Convert.ToString(row["apellidos"]), Convert.ToString(row["mail"])));
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                dataPersonal = new DataSet();
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(listPersonal);
        }
Esempio n. 6
0
        //Devuelve una lista de objetos casa

        public List <Casa> getAllCasas()
        {
            List <Casa> casa = new List <Casa>();

            DataSet          dataPersonal = new DataSet();
            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;
            String           sql;

            sql = "SELECT * from casa";
            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlAdapter.Fill(dataPersonal);

                DataTable dt = dataPersonal.Tables[0];

                foreach (DataRow row in dt.Rows)
                {
                    casa.Add(new Casa(Convert.ToInt16(row["codigo"]), Convert.ToString(row["nombre"]), Convert.ToInt16(row["codigo_comarca"]), Convert.ToInt16(row["litoral"])));
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                dataPersonal = new DataSet();
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(casa);
        }