Example #1
0
        /// <summary>
        /// Get TipoServico by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TipoServico GetTipoServico(string id)
        {
            int newId;

            if (!Int32.TryParse(id, out newId))
            {
                return(null);
            }
            SqlDataReader rdr = null;

            OpenDB();

            // create a command object
            SqlCommand cmd = new SqlCommand("select * from TipoServico", cnn);

            rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                if (newId == (int)rdr["TipoServicoID"])
                {
                    TipoServico s = new TipoServico();
                    s.TipoServicoId  = (int)rdr["TipoServicoID"];
                    s.NomeServico    = (string)rdr["NomeServico"];
                    s.PrefixoServico = (string)rdr["PrefixoServico"];
                    return(s);
                }
            }
            CloseDB();
            return(null);
        }
Example #2
0
        /// <summary>
        /// Update TipoServico
        /// </summary>
        /// <param name="st"></param>
        /// <returns></returns>
        public bool UpdateTipoServico(TipoServico st)
        {
            StringBuilder query = new StringBuilder();
            SqlDataReader rdr   = null;

            OpenDB();
            query.AppendFormat("UPDATE TipoServico SET NomeServico='{0}', PrefixoServico='{1}' WHERE TipoServicoID={2};"
                               , st.NomeServico, st.PrefixoServico, st.TipoServicoId);
            // create a command object
            SqlCommand cmd = new SqlCommand(query.ToString(), cnn);

            rdr = cmd.ExecuteReader();
            CloseDB();
            return(true);
        }
Example #3
0
        /// <summary>
        /// Add TipoServico
        /// </summary>
        /// <param name="st"></param>
        /// <returns></returns>
        public bool AddTipoServico(TipoServico st)
        {
            StringBuilder query = new StringBuilder();
            SqlDataReader rdr   = null;

            OpenDB();
            query.AppendFormat("INSERT INTO TipoServico (TipoServicoID, NomeServico, PrefixoServico) VALUES ({0}, '{1}', '{2}');"
                               , st.TipoServicoId, st.NomeServico, st.PrefixoServico);
            // create a command object
            SqlCommand cmd = new SqlCommand(query.ToString(), cnn);

            rdr = cmd.ExecuteReader();
            CloseDB();
            return(true);
        }
Example #4
0
        /// <summary>
        /// Get all TipoServico
        /// </summary>
        /// <returns></returns>
        public List <TipoServico> GetAllTipoServico()
        {
            List <TipoServico> list = new List <TipoServico>();
            SqlDataReader      rdr  = null;

            OpenDB();

            // create a command object
            SqlCommand cmd = new SqlCommand("select * from TipoServico", cnn);

            rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                TipoServico s = new TipoServico();
                s.TipoServicoId  = (int)rdr["TipoServicoID"];
                s.NomeServico    = (string)rdr["NomeServico"];
                s.PrefixoServico = (string)rdr["PrefixoServico"];
                list.Add(s);
            }
            CloseDB();
            return(list);
        }