Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public static TipoServico Select(long codigo)
        {
            TipoServico tipoServico;
            string      query = "SELECT * FROM tps_tiposervicos WHERE tps_codigo = ?codigo;";

            DBHelper    dbHelper;
            IDataReader dataReader;

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

                tipoServico = new TipoServico();
                while (dataReader.Read())
                {
                    tipoServico.Codigo    = Convert.ToInt64(dataReader["tps_codigo"]);
                    tipoServico.Descricao = Convert.ToString(dataReader["tps_nome"]);
                    if (dataReader["tps_tipopai"] == DBNull.Value)
                    {
                        tipoServico.TipoPai = null;
                    }
                    else
                    {
                        tipoServico.TipoPai = TipoServicoDB.Select(Convert.ToInt64(dataReader["tps_tipopai"]));
                    }
                }
                dbHelper.Dispose();
            }
            catch
            {
                tipoServico = null;
            }

            return(tipoServico);
        }