コード例 #1
0
ファイル: MensagemDB.cs プロジェクト: neidsonh/Bellaweb
        public static Mensagem Select(long codigo)
        {
            Mensagem msg;
            string   query = "SELECT * FROM msg_mensagens WHERE msg_codigo = ?codigo;";

            DBHelper    dbHelper;
            IDataReader dataReader;

            try
            {
                dbHelper = new DBHelper(query);
                dbHelper.AddParameter("?codigo", codigo);
                dataReader = dbHelper.Command.ExecuteReader();

                msg = new Mensagem();
                while (dataReader.Read())
                {
                    msg.Codigo          = Convert.ToInt64(dataReader["msg_codigo"]);
                    msg.Assunto         = Convert.ToString(dataReader["msg_assunto"]);
                    msg.Texto           = Convert.ToString(dataReader["msg_texto"]);
                    msg.AutorEmail      = Convert.ToString(dataReader["msg_autoremail"]);
                    msg.AutorNome       = Convert.ToString(dataReader["msg_autornome"]);
                    msg.Estabelecimento = EstabelecimentoDB.Select(Convert.ToInt64(dataReader["est_codigo"]));
                }
                dbHelper.Dispose();
            }
            catch
            {
                msg = null;
            }

            return(msg);
        }
コード例 #2
0
ファイル: ServicoDB.cs プロジェクト: neidsonh/Bellaweb
        public static Servico Select(long codigo)
        {
            Servico servico;
            string  query = "SELECT * FROM srv_servicos WHERE srv_codigo = ?codigo;";

            DBHelper    dbHelper;
            IDataReader dataReader;

            try
            {
                dbHelper = new DBHelper(query);
                dbHelper.AddParameter("?codigo", codigo);
                dataReader = dbHelper.Command.ExecuteReader();

                servico = new Servico();
                while (dataReader.Read())
                {
                    servico.Codigo          = Convert.ToInt64(dataReader["srv_codigo"]);
                    servico.Nome            = Convert.ToString(dataReader["srv_nome"]);
                    servico.Preco           = Convert.ToDouble(dataReader["srv_valor"]);
                    servico.Estabelecimento = EstabelecimentoDB.Select(Convert.ToInt64(dataReader["est_codigo"]));
                    servico.TipoServico     = TipoServicoDB.Select(Convert.ToInt64(dataReader["tps_codigo"]));
                }
                dbHelper.Dispose();
            }
            catch
            {
                servico = null;
            }

            return(servico);
        }
コード例 #3
0
ファイル: ServicoDB.cs プロジェクト: neidsonh/Bellaweb
        public static List <Servico> SelectByEstabelecimento(Estabelecimento estabelecimento)
        {
            string         query    = "SELECT * FROM srv_servicos WHERE est_codigo = ?estabelecimento;";
            List <Servico> servicos = new List <Servico>();
            DBHelper       dbHelper;
            IDataReader    reader;

            try
            {
                dbHelper = new DBHelper(query);
                dbHelper.AddParameter("?estabelecimento", estabelecimento.Codigo);
                reader = dbHelper.Command.ExecuteReader();

                while (reader.Read())
                {
                    servicos.Add(new Servico()
                    {
                        Codigo          = Convert.ToInt64(reader["srv_codigo"]),
                        Nome            = Convert.ToString(reader["srv_nome"]),
                        Preco           = Convert.ToDouble(reader["srv_valor"]),
                        Estabelecimento = EstabelecimentoDB.Select(Convert.ToInt64(reader["est_codigo"])),
                        TipoServico     = TipoServicoDB.Select(Convert.ToInt64(reader["tps_codigo"]))
                    });
                }
                dbHelper.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(servicos);
        }
コード例 #4
0
        public static Usuario Select(long codigo)
        {
            Usuario usuario;
            string  query = "SELECT * FROM usr_usuarios WHERE usr_codigo = ?codigo AND usr_ativo = 1;";

            DBHelper    dbHelper;
            IDataReader dataReader;

            try
            {
                dbHelper = new DBHelper(query);
                dbHelper.AddParameter("?codigo", codigo);
                dataReader = dbHelper.Command.ExecuteReader();

                usuario = new Usuario();
                while (dataReader.Read())
                {
                    usuario.Codigo = Convert.ToInt64(dataReader["usr_codigo"]);
                    usuario.Email  = Convert.ToString(dataReader["usr_email"]);
                    usuario.Senha  = Convert.ToString(dataReader["usr_senha"]);
                    usuario.Ativo  = Convert.ToInt32(dataReader["usr_ativo"]) != 0;

                    if (Convert.IsDBNull(dataReader["adm_codigo"]))
                    {
                        usuario.Estabelecimento = EstabelecimentoDB.Select(Convert.ToInt64(dataReader["est_codigo"]));
                        usuario.Administrador   = null;
                    }
                    else
                    {
                        usuario.Administrador   = AdministradorDB.Select(Convert.ToInt64(dataReader["adm_codigo"]));
                        usuario.Estabelecimento = null;
                    }
                }
                dbHelper.Dispose();
            }
            catch
            {
                usuario = null;
            }

            return(usuario);
        }