Пример #1
0
        //Select statement
        public Modulo Select(int id)
        {
            string query = "select modulo.tipo,modulo.idmodulo,modulo.nome,localizacao,estado,para from   modulo join usuario on modulo.idusuario=usuario.idusuario left join ligacao l on l.idmodulo = modulo.idmodulo where usuario.idusuario=" + id;

            //Create a list to store the result

            Modulo         modulo          = new Modulo();
            List <No>      lista           = new List <No>();
            List <Ligacao> ligacao         = new List <Ligacao>();
            No             auxiliarNo      = new No();
            Ligacao        auxiliarLigacao = new Ligacao();

            auxiliarNo.id = 0; auxiliarNo.label = "Casa";
            lista.Add(auxiliarNo);
            //Open connection
            if (this.OpenConnection() == true)
            {
                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, connection);
                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    auxiliarNo           = new No();
                    auxiliarLigacao      = new Ligacao();
                    auxiliarNo.id        = Convert.ToInt32(dataReader["idmodulo"]);
                    auxiliarNo.label     = Convert.ToString(dataReader["nome"]);
                    auxiliarLigacao.from = Convert.ToInt32(dataReader["idmodulo"]);
                    auxiliarNo.tipo      = Convert.ToInt32(dataReader["tipo"]);
                    if (auxiliarNo.tipo == 1)
                    {
                        auxiliarLigacao.to    = Convert.ToInt32(dataReader["para"]);
                        auxiliarNo.attributes = Convert.ToString(dataReader["localizacao"]);
                        auxiliarNo.title      = Convert.ToInt32(dataReader["estado"]) == 1 ? "Ligado" : "Desligado";
                        if (Convert.ToInt32(dataReader["estado"]) == 1)
                        {
                            auxiliarNo.color = "#FA5858";
                        }
                        else
                        {
                            auxiliarNo.color = "#00FF80";
                        }
                    }
                    else
                    {
                        auxiliarNo.color   = "#F2F5A9";
                        auxiliarLigacao.to = 0;
                    }
                    lista.Add(auxiliarNo);
                    ligacao.Add(auxiliarLigacao);
                }
                modulo.nos      = lista;
                modulo.ligacoes = ligacao;


                //close Data Reader
                dataReader.Close();

                //close Connection
                this.CloseConnection();

                //return list to be displayed
                return(modulo);
            }
            else
            {
                return(modulo);
            }
        }
Пример #2
0
 public Controladora()
 {
     Controladora_Modulo      = new Modulo();
     Controladora_Operaciones = new List <Operacion>();
 }