Example #1
0
        public bool Inserir(Regiao regiao)
        {
            _bd.Comando.Parameters.Clear();

            _bd.Comando.CommandText = @"SELEXT MAX(REGIONID) AS MAX
                                        FROM REGION";

            object maxCod = _bd.ExecutarComandoScalar();

            if (maxCod != DBNull.Value)
                maxCod = Convert.ToInt32(maxCod) + 1;
            else maxCod = 1;

            _bd.Comando.CommandText = @"INSERT INTO REGION (REGIONID, REGIONDESCRIPTION)
                                          VALUES(@REGIONID, @REGIONDESCRIPTION)";
            _bd.Comando.Parameters.AddWithValue("@REGIONID", regiao.Id);
            _bd.Comando.Parameters.AddWithValue("@REGIONDESCRIPTION", regiao.Descricao);

            if (_bd.ExecutarComandoNonQuery() > 0)
            {
                regiao.Id = Convert.ToInt32(maxCod);
                return true;
            }
            else return false;
        }
Example #2
0
        public bool Alterar(Regiao regiao)
        {
            _bd.Comando.Parameters.Clear();
            _bd.Comando.CommandText = @"UPDATE REGION
                                           SET REGIONDESCRIPTION = @REGIONDESCRIPTION
                                        WHERE REGIONID = @REGIONID)";

            _bd.Comando.Parameters.AddWithValue("@REGIONDESCRIPTION", regiao.Descricao);
            _bd.Comando.Parameters.AddWithValue("@REGIONID", regiao.Id);

            if (_bd.ExecutarComandoNonQuery() > 0)
                return true;
            else return false;
        }
Example #3
0
        public bool Recuperar(int id, Regiao regiao)
        {
            _bd.Comando.Parameters.Clear();
            _bd.Comando.CommandText = "select REGIONID, REGIONDESCRIPTION from REGION where REGIONID = @REGIONID";
            _bd.Comando.Parameters.AddWithValue("@REGIONID", id);

            DataTable dt = _bd.ExecutarComando();

            if (dt.Rows.Count == 1)
            {

                regiao.Id = Convert.ToInt32(dt.Rows[0]["REGIONID"]);
                regiao.Descricao = dt.Rows[0]["REGIONDESCRIPTION"].ToString();

                return true;
            }
            else return false;
        }
Example #4
0
        public List<Territorio> RetornarTerritorios(string descricao)
        {
            SqlServer bd = new SqlServer();
            bd.Comando.CommandText = @"SELECT *
                                       FROM TERRITORIES
                                       WHERE TERRITORYDESCRIPTION LIKE @DESCR";
            bd.Comando.Parameters.AddWithValue("@DESCR", descricao + "%");
            DataTable dt = bd.ExecutarComando();

            List<Territorio> list = new List<Territorio>();

            foreach (DataRow row in dt.Rows)
            {
                Regiao r = new Regiao(Convert.ToInt32(row["REGIONID"].ToString()));
                Territorio t = new Territorio(Convert.ToInt32(row["TERRITORYID"]), row["TERRITORYDESCRIPTION"].ToString(), r);
                list.Add(t);
            }

            return list;
        }
Example #5
0
 public Territorio(int id, string description, Regiao regiao)
 {
     _id = id;
     _description = description;
     _regiao = regiao;
 }
Example #6
0
 public Territorio()
 {
     _id = 0;
     _description = "";
     _regiao = new Regiao();
 }