Esempio n. 1
0
        public bool InsertRota(string Idrota, string DescricaoRota)
        {
            bool         lVerifica = true;
            string       cQuery    = "";
            MySqlCommand Command;
            dbMngmt      Database = new dbMngmt();

            cQuery += "INSERT INTO Savar.rota (id_rota,desc_rota,codigo_sequencia,numero_onibus, id_ponto) VALUES ";
            for (int nI = 0; nI < PontosRota.Count; nI++)
            {
                if (nI > 0)
                {
                    cQuery += " , ";
                }
                cQuery += "  ('" + Idrota + "','" + DescricaoRota + "','"
                          + nI.ToString() + "', ' ' , " + PontosRota[nI] + ") ";
            }
            cQuery += ";";

            Command = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    Command.ExecuteNonQuery();
                }
            }
            catch (MySqlException ex)
            {
                ex.ToString();
                lVerifica = false;
            }
            return(lVerifica);
        }
Esempio n. 2
0
        public bool InsertPonto(string Descricao_ponto, double PosiX, double PosiY)
        {
            string       cQuery = "";
            MySqlCommand Comand;
            dbMngmt      Database = new dbMngmt();
            DataTable    MaxId    = new DataTable();
            bool         lValida  = true;

            cQuery += "INSERT INTO Savar.ponto_onibus (Descricao_ponto,x,y) ";
            cQuery += "VALUES ('" + Descricao_ponto + "', " + PosiX.ToString().Replace(',', '.') + "," + PosiY.ToString().Replace(',', '.') + " ) ;";

            Comand = new MySqlCommand(cQuery, Database.GetDataBase());

            try
            {
                if (Database.ConectionTest())
                {
                    Comand.ExecuteNonQuery();
                }
                else
                {
                    lValida = false;
                }
            }
            catch (MySqlException ex)
            {
                ex.ToString();
                lValida = false;
            }
            return(lValida);
        }
Esempio n. 3
0
        public string UpdateRota(string idRota, string hora = "", string NumOnibus = "")
        {
            string       cRet   = "";
            string       cQuery = "";
            MySqlCommand Command;
            dbMngmt      Database = new dbMngmt();

            cQuery += "UPDATE Savar.rota SET ";
            if (hora != "")
            {
                cQuery += " Hora = '" + hora + "' ";
                if (NumOnibus != "")
                {
                    cQuery += " , ";
                }
            }
            if (NumOnibus != "")
            {
                cQuery += " numero_onibus = '" + NumOnibus + "' ";
            }
            cQuery += "WHERE id_rota = '" + idRota + "' ; ";
            Command = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    Command.ExecuteNonQuery();
                }
            }
            catch (MySqlException ex)
            {
                cRet = ex.ToString();
            }
            return(cRet);
        }
Esempio n. 4
0
        public DataRow GetUser(string Usuario)
        {
            string           cQuery   = "";
            dbMngmt          Database = new dbMngmt();
            MySqlDataAdapter MyData   = new MySqlDataAdapter();
            DataTable        Users    = new DataTable();
            DataRow          RowRet   = null;

            this.cLog = "";
            cQuery   += "USE Savar; ";
            cQuery   += " SELECT   * FROM Savar.cliente";
            cQuery   += " WHERE  usuario = '" + Usuario.ToUpper() + "' ";
            try
            {
                if (Database.ConectionTest())
                {
                    MyData.SelectCommand = new MySqlCommand(cQuery, Database.GetDataBase());
                    MyData.Fill(Users);
                }
            }
            catch (MySqlException ex)
            {
                this.cLog = ex.ToString();
            }
            if (Users.Rows.Count > 0)
            {
                RowRet = Users.Rows[0];
            }
            return(RowRet);
        }
Esempio n. 5
0
        /*Insert User - Inserção de usuários
         *  Função realiza a criação de um novo usuário.
         *  Retorno String - Caso de erro, retorna o log do erro.
         *  Parametros
         *      User - Nome do usuário Para ser incluso
         *      Senha - Senha do usuário novo.
         *      NomeUser - Nome completo do novo usuário
         *      email - Email do usuário
         *      AtualContext - Contexto para execução do Toast
         */
        public string InsertUser(string User, string Senha, string NomeUser, string email, Context AtualContext)
        {
            string       cLog     = "";
            dbMngmt      Database = new dbMngmt();
            MySqlCommand Command;
            string       cQuery = "";

            cQuery += "Use Savar; ";
            cQuery += "INSERT INTO Savar.cliente (usuario,senha,nome,email,Tipo_conta)  VALUES";
            cQuery += "( '" + User.ToUpper() + "' ,";
            cQuery += " '" + Senha + "' ,";
            cQuery += " '" + NomeUser + "' ,'" + email + "','1' ) ;";
            Command = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    if (VerificaUsuario(AtualContext, User.ToUpper()).Length == 1)
                    {
                        cLog = "Usuário já existe! ";
                    }
                    else
                    {
                        Command.ExecuteNonQuery();
                    }
                }
            }
            catch (MySqlException ex)
            {
                cLog += ex.ToString();
            }
            return(cLog);
        }
Esempio n. 6
0
/*********************************
 * Função SelectOnibus()
 * Parametros :
 *      nNumero = Número do Onibus.
 *      cPlaca  = String com a placa do Veículo
 *      cRota   = Rota De ônibus
 *  Deve ser passado o parametro nNumero e cPlaca, ou Somemente o cRota,
 *  caso quera verificar os ônibus de uma determinada rota.
 *
 * ******************************/
        public DataTable SelectOnibus(int nNumero = 0, string cPlaca = "", string cRota = "")
        {
            dbMngmt          Database   = new dbMngmt();
            DataTable        Onibus     = new DataTable();
            MySqlDataAdapter OnibusData = new MySqlDataAdapter();
            MySqlCommand     Command    = null;
            string           cQuery     = "";

            cQuery += "USE Savar; ";
            cQuery += "SELECT * FROM Savar.onibus ";
            if (nNumero != 0 || cPlaca != "" || cRota != "")
            {
                cQuery += " WHERE ";
            }
            if (nNumero != 0)
            {
                cQuery += " numero_onibus = " + nNumero.ToString();
                if (cPlaca != "" || cRota != "")
                {
                    cQuery += " AND ";
                }
            }
            if (cPlaca != "")
            {
                cQuery += " placa = '" + cPlaca + "' ";
                if (cRota != "")
                {
                    cQuery += " AND ";
                }
            }
            if (cRota != "")
            {
                cQuery += " rota = '" + cRota + "' ";
            }

            cQuery += "; ";

            Command = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    OnibusData.SelectCommand = Command;
                    OnibusData.Fill(Onibus);
                }
            }
            catch (MySqlException ex)
            {
                ex.ToString();
            }
            return(Onibus);
        }
Esempio n. 7
0
        public DataTable SelectPonto(string IdPonto = "", string DescricaoPonto = "")
        {
            DataTable        Pontos = new DataTable();
            MySqlCommand     Comando;
            MySqlDataAdapter PontosAdapter = new MySqlDataAdapter();
            dbMngmt          Database      = new dbMngmt();


            string cQuery = "";

            cQuery += "SELECT * FROM Savar.ponto_onibus ";

            if (IdPonto != "")
            {
                cQuery += "  ID_ponto = '" + IdPonto + "' ";
                if (DescricaoPonto != "")
                {
                    cQuery += " AND ";
                }
            }
            if (DescricaoPonto != "")
            {
                cQuery += "Descricao_ponto = '%" + DescricaoPonto + "%' ";
            }

            cQuery += ";";

            Comando = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    PontosAdapter.SelectCommand = Comando;
                    PontosAdapter.Fill(Pontos);
                }
                else
                {
                    Pontos = null;
                }
            }
            catch (MySqlException ex)
            {
                ex.ToString();
                Pontos = null;
            }
            return(Pontos);
        }
Esempio n. 8
0
        public bool UpdatePonto(string IdPonto, string Descricao_ponto = "", double PosiX = 0, double PosiY = 0)
        {
            string       cQuery = "";
            MySqlCommand Comand;
            dbMngmt      Database = new dbMngmt();
            bool         lValida  = true;

            cQuery += "UPDATE Savar.ponto_onibus ";
            cQuery += " SET ";
            if (Descricao_ponto != "")
            {
                cQuery += "Descricao_ponto = '" + Descricao_ponto + "' ";
                if (PosiX != 0 || PosiY != 0)
                {
                    cQuery += " , ";
                }
            }
            if (PosiX != 0 || PosiY != 0)
            {
                cQuery += " x = " + PosiX.ToString() + " , y = " + PosiY.ToString() + " ";
            }
            cQuery += "WHERE ID_ponto = " + IdPonto + " ; ";

            Comand = new MySqlCommand(cQuery, Database.GetDataBase());

            try
            {
                if (Database.ConectionTest())
                {
                    Comand.ExecuteNonQuery();
                }
                else
                {
                    lValida = false;
                }
            }
            catch (MySqlException ex)
            {
                ex.ToString();
                lValida = false;
            }



            return(lValida);
        }
Esempio n. 9
0
        public string UpdateOnibus(string cNumOnibus, string cPlaca, double PosX = 0, double PosY = 0, double PosZ = 0, string cNewNumOnibus = "", string cNewPlaca = "")
        {
            string       cRet     = "";
            string       cQuery   = "";
            dbMngmt      Database = new dbMngmt();
            MySqlCommand Command;

            cQuery += "USE Savar; ";
            cQuery += "UPDATE Savar.onibus ";

            cQuery += " SET  ";
            if (cNewNumOnibus != "")
            {
                cQuery += " numero_onibus = '" + cNewNumOnibus + "'  ";
                if (cNewPlaca != "" || PosX != 0)
                {
                    cQuery += " , ";
                }
            }
            if (cNewPlaca != "")
            {
                cQuery += " placa = '" + cNewPlaca + "'  ";
                if (PosX != 0)
                {
                    cQuery += " , ";
                }
            }
            if (PosX != 0 || PosY != 0 || PosZ != 0)
            {
                cQuery += " x = " + PosX.ToString().Replace(',', '.') + " , y = " + PosY.ToString().Replace(',', '.') + " ,z =  " + PosZ.ToString().Replace(',', '.') + " ";
            }
            cQuery += "  WHERE numero_onibus = '" + cNumOnibus + "' AND placa = '" + cPlaca + "' ; ";
            Command = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    Command.ExecuteNonQuery();
                }
            }catch (MySqlException ex)
            {
                cRet = ex.ToString();
            }
            return(cRet);
        }
Esempio n. 10
0
/**************************************
* Função InputOnibus - Função para realizar inclusão de novo ônibus
* Parâmetros
*      cNunOnibus - Variavel String com o número identificado  do Onibus
*      cPlaca - Placa do Veículo
*      cRota - Identificador de uma rota que o ônibus vai fazer.
**************************************/
        public void InputOnibus(string cNunOnibus, string cPlaca, string cRota = "")
        {
            string           lRet       = "";
            dbMngmt          Database   = new dbMngmt();
            string           cQuery     = "";
            MySqlDataAdapter OnibusData = new MySqlDataAdapter();
            MySqlCommand     Command    = null;


            cQuery += "USE Savar; ";
            cQuery += "INSERT INTO Savar.onibus (numero_onibus, placa ";
            if (cRota != "")
            {
                cQuery += ", rota) ";
            }
            else
            {
                cQuery += ") ";
            }
            cQuery += " VALUES (" + cNunOnibus + ",  '" + cPlaca + "' ";
            if (cRota != "")
            {
                cQuery += ", " + cRota + " ) ;";
            }
            else
            {
                cQuery += ") ;";
            }

            Command = new MySqlCommand(cQuery, Database.GetDataBase());

            try
            {
                if (Database.ConectionTest())
                {
                    Command.ExecuteNonQuery();
                }
            }
            catch (MySqlException ex)
            {
                lRet = ex.ToString();
            }
        }
Esempio n. 11
0
        public DataTable SelectRota(string id_rota = "", bool EmAcao = false)
        {
            DataTable        MyData = new DataTable();
            MySqlCommand     Command;
            dbMngmt          Database = new dbMngmt();
            MySqlDataAdapter MyRotas  = new MySqlDataAdapter();
            string           cQuery   = "";

            cQuery += "SELECT * FROM Savar.rota  ";
            if (id_rota != "" || EmAcao)
            {
                cQuery += " WHERE ";
            }
            if (id_rota != "")
            {
                cQuery += "  id_rota = '" + id_rota + "'";
                if (EmAcao)
                {
                    cQuery += ",";
                }
            }
            if (EmAcao)
            {
                cQuery += " numero_onibus <> ' ' ";
            }
            cQuery += " ; ";
            Command = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    MyRotas.SelectCommand = Command;
                    MyRotas.Fill(MyData);
                }
            }
            catch (MySqlException ex)
            {
                ex.ToString();
            }

            return(MyData);
        }
Esempio n. 12
0
        public string DeletaPonto(string idPonto)
        {
            dbMngmt      Database = new dbMngmt();
            string       cQuery   = "";
            MySqlCommand Command;

            cQuery += "DELETE FROM Savar.ponto_onibus WHERE ID_ponto = " + idPonto + " ;";
            Command = new MySqlCommand(cQuery, Database.GetDataBase());

            try
            {
                if (Database.ConectionTest())
                {
                    Command.ExecuteNonQuery();
                }
            }
            catch (MySqlException ex)
            {
                return(ex.ToString());
            }

            return("");
        }
Esempio n. 13
0
        /*UpdateUser - Atualização de algum dado do usuário
         * Atualiza senha, nome e pontuãção do usuário.
         * Retorno String, retorna algum erro caso exista
         * Parametros
         *      User - Nome do usuário a ser alterado
         *      AtualContext - Conexto da tela, para execução do Toast
         *      User - Nome do usuário para encontrar no banco de dados
         *      Pontos - Nova quantidade de pontos do usuário
         *      Senha - Nova Senha do usuário
         *      Email - Novo Email do usuário
         *      Nome - Novo Nome do usuário
         *      Tipo conta - Altera o tipo da conta do usuário.
         */
        public string UpdateUser(Context AtualContext, string User, string Pontos = "", string Senha = "", string Email = "", string Nome = "", string TipoConta = "")
        {
            string       cLog     = "";
            string       cQuery   = "";
            dbMngmt      Database = new dbMngmt();
            MySqlCommand Command;

            cQuery += "USE Savar; ";
            cQuery += "UPDATE cliente";
            cQuery += " SET ";
            if (Senha != "")
            {
                cQuery += " senha = '" + Senha + " ";
                if ((Pontos + Email + Nome + TipoConta).Length > 0)
                {
                    cQuery += " , ";
                }
            }
            if (Nome != "")
            {
                cQuery += " nome = '" + Nome + "' ";
                if ((Pontos + Email + TipoConta).Length > 0)
                {
                    cQuery += " , ";
                }
            }
            if (Pontos != "")
            {
                cQuery += " pontos = " + Pontos + " ";
                if ((Email + TipoConta).Length > 0)
                {
                    cQuery += " , ";
                }
            }
            if (TipoConta != "")
            {
                cQuery += " Tipo_conta = '" + TipoConta + " ";
                if (Email != "")
                {
                    cQuery += " , ";
                }
            }
            if (Email != "")
            {
                cQuery += " email = '" + Email + "' ";
            }
            cQuery += "Where usuario = '" + User.TrimEnd().TrimStart().ToUpper() + "' ;";
            Command = new MySqlCommand(cQuery, Database.GetDataBase());
            try
            {
                if (Database.ConectionTest())
                {
                    if (VerificaUsuario(AtualContext, User).Length == 1)
                    {
                        Command.ExecuteNonQuery();
                    }
                    else
                    {
                        cLog = "Não foi possível encontrar o usuário " + User.ToUpper() + "!";
                    }
                }
                else
                {
                    cLog = "Erro de conexão com o banco de dados";
                }
            }
            catch (MySqlException ex)
            {
                cLog = ex.ToString();
            }
            return(cLog);
        }