Example #1
0
        public static ItemCategoria GetByID(int id)
        {
            DataTable     table = new DataTable();
            ItemCategoria cat   = null;

            OpenConn();
            try
            {
                NpgsqlCommand command = new NpgsqlCommand(null, dbConn);
                command.CommandText = "SELECT * FROM item_categoria WHERE id = " + id;
                NpgsqlDataAdapter Adpt = new NpgsqlDataAdapter(command);
                Adpt.Fill(table);

                if (table.Rows.Count > 0)
                {
                    foreach (DataRow dr in table.Rows)
                    {
                        cat = new ItemCategoria
                        {
                            ID        = Convert.ToInt32(dr["id"]),
                            Nome      = dr["nome"].ToString(),
                            Descricao = dr["descricao"].ToString()
                        };
                        dbConn.Close();
                        return(cat);
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("INVENTARIO/ItemCategoriaDAO/GetAll:: " + e);
            }
            dbConn.Close();
            return(cat);
        }
        public ActionResult Edit(ItemCategoria cat)
        {
            // Início: Proteção de rota
            if (Session["usuario_nivel"] == null)
            {
                TempData["msg"]      = "Necessário estar logado!";
                TempData["msg_type"] = "warning";
                return(RedirectToAction("Index", "Home"));
            }

            if (Convert.ToInt32(Session["usuario_nivel"]) > 1)
            {
                TempData["msg"]      = "Você não tem autorização para acessar esta área!";
                TempData["msg_type"] = "danger";
                return(RedirectToAction("Index", "Home"));
            }
            // Fim: Proteção de Rota

            try
            {
                if (ItemCategoriaDAO.Update(cat))
                {
                    TempData["msg"]      = "Alterado com sucesso!";
                    TempData["msg_type"] = "success";
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
            }
            TempData["msg"]      = "Erro ao criar";
            TempData["msg_type"] = "danger";
            return(View());
        }
        public ActionResult Edit(int id)
        {
            // Início: Proteção de rota
            if (Session["usuario_nivel"] == null)
            {
                TempData["msg"]      = "Necessário estar logado!";
                TempData["msg_type"] = "warning";
                return(RedirectToAction("Index", "Home"));
            }

            if (Convert.ToInt32(Session["usuario_nivel"]) > 1)
            {
                TempData["msg"]      = "Você não tem autorização para acessar esta área!";
                TempData["msg_type"] = "danger";
                return(RedirectToAction("Index", "Home"));
            }
            // Fim: Proteção de Rota

            try
            {
                LocalidadeCategoriaDAO.AtualizaCategorias();
                ItemCategoria cat = ItemCategoriaDAO.GetByID(id);
                if (cat != null)
                {
                    return(View(cat));
                }
            }
            catch
            {
            }
            TempData["msg"]      = "Erro ao buscar dados";
            TempData["msg_type"] = "danger";
            return(View());
        }
Example #4
0
        private void PainelBalcao_Load(object sender, EventArgs e)
        {
            List <string> nome        = controllerCategoria.BuscarTodas();
            List <int>    idCategoria = controllerCategoria.BuscarTodasId();

            foreach (string n in nome)
            {
                ItemCategoria itemCategoria = new ItemCategoria();
                itemCategoria.Name     = ("categoria").ToString();
                itemCategoria.NameItem = n.ToString();
                flowLayoutCategoria.Controls.Add(itemCategoria);
                itemCategoria.MouseDown += new MouseEventHandler(itemCategoria_Clique);
                itemCategoria.pictureBoxCategoria.MouseDown += new MouseEventHandler(itemCategoria_Clique);
            }
        }
Example #5
0
        public static Boolean Update(ItemCategoria categoria)
        {
            NpgsqlParameter param;

            OpenConn();
            try
            {
                NpgsqlCommand command = new NpgsqlCommand(null, dbConn);
                command.CommandText = "UPDATE item_categoria SET nome = @nome, descricao = @descricao WHERE id =@id  RETURNING id";

                param       = new NpgsqlParameter("@nome", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
                param.Value = categoria.Nome;
                command.Parameters.Add(param);

                param       = new NpgsqlParameter("@descricao", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
                param.Value = categoria.Descricao;
                command.Parameters.Add(param);

                param       = new NpgsqlParameter("@id", NpgsqlTypes.NpgsqlDbType.Integer, 0);
                param.Value = categoria.ID;
                command.Parameters.Add(param);

                command.Prepare();

                var result = command.ExecuteScalar();
                dbConn.Close();

                if (result != null && (int)result > 0)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("INVENTARIO/ItemCategoriaDAO/Update:: " + e);

                dbConn.Close();
            }
            return(false);
        }
Example #6
0
        // Cria subcategoria
        public static object Create(ItemCategoria categoria)
        {
            NpgsqlParameter param;

            if (dbConn == null)
            {
                dbConn = Database.Conexao;
            }
            else
            {
                dbConn.Open();
            }
            try
            {
                NpgsqlCommand command = new NpgsqlCommand(null, dbConn);
                command.CommandText = "INSERT INTO item_categoria(nome, descricao) values (@nome, @descricao) RETURNING id";

                param       = new NpgsqlParameter("@nome", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
                param.Value = categoria.Nome;
                command.Parameters.Add(param);

                param       = new NpgsqlParameter("@descricao", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
                param.Value = categoria.Descricao;
                command.Parameters.Add(param);

                command.Prepare();
                var result = command.ExecuteScalar();
                dbConn.Close();

                return(result);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("INVENTARIO/ItemCategoriaDAO/Create:: " + e);
                dbConn.Close();
                return(null);
            }
        }