Beispiel #1
0
        public static void Delete(dtoMenu Menu)
        {
            using (SqlConnection connection = new SqlConnection(DataAccess.Configuracao.getConnectionString()))
            {
                string stringSQL = @"DELETE tbMenu 
                                      WHERE idMenu = @idMenu";

                SqlCommand cmdDeletar = new SqlCommand(stringSQL, connection);
                cmdDeletar.Parameters.Add("idMenu", SqlDbType.Int).Value = Menu.idMenu;

                try
                {
                    connection.Open();
                    cmdDeletar.ExecuteNonQuery();
                }
                catch
                {
                    throw new ApplicationException("Erro ao excluir registro");
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Beispiel #2
0
 private static void ValidaCampos(ref dtoMenu Menu)
 {
     if (String.IsNullOrEmpty(Menu.Descricao))
     {
         Menu.Descricao = String.Empty;
     }
     if (String.IsNullOrEmpty(Menu.descricaoMenuPai))
     {
         Menu.descricaoMenuPai = String.Empty;
     }
     if (String.IsNullOrEmpty(Menu.Url))
     {
         Menu.Url = String.Empty;
     }
 }
Beispiel #3
0
        public static void Update(dtoMenu Menu)
        {
            using (SqlConnection connection = new SqlConnection(DataAccess.Configuracao.getConnectionString()))
            {
                string stringSQL = @"UPDATE tbMenu SET 
                                        idChave = @idChave,
                                        idMenuPai = @idMenuPai,
                                        Descricao = @Descricao,
                                        Visivel = @Visivel,
                                        Url = @Url,
                                        dataUltimaAlteracao = getdate(),
                                        idUsuarioUltimaAlteracao = @idUsuarioUltimaAlteracao
                                      WHERE idMenu = @idMenu";

                SqlCommand cmdAtualizar = new SqlCommand(stringSQL, connection);

                ValidaCampos(ref Menu);

                cmdAtualizar.Parameters.Add("idUsuarioUltimaAlteracao", SqlDbType.Int).Value = Menu.idUsuarioUltimaAlteracao;

                cmdAtualizar.Parameters.Add("idChave", SqlDbType.VarChar).Value   = Menu.idChave;
                cmdAtualizar.Parameters.Add("idMenu", SqlDbType.Int).Value        = Menu.idMenu;
                cmdAtualizar.Parameters.Add("idMenuPai", SqlDbType.Int).Value     = Menu.idMenuPai;
                cmdAtualizar.Parameters.Add("Descricao", SqlDbType.VarChar).Value = Menu.Descricao;
                cmdAtualizar.Parameters.Add("Visivel", SqlDbType.Bit).Value       = Menu.Visivel;
                cmdAtualizar.Parameters.Add("Url", SqlDbType.VarChar).Value       = Menu.Url;


                try
                {
                    connection.Open();
                    cmdAtualizar.ExecuteNonQuery();
                }
                catch
                {
                    throw new ApplicationException("Erro ao atualizar registro");
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Beispiel #4
0
        public static int Insert(dtoMenu Menu)
        {
            using (SqlConnection connection = new SqlConnection(DataAccess.Configuracao.getConnectionString()))
            {
                string stringSQL = @"INSERT INTO tbMenu(idChave, idMenuPai, Descricao, Visivel, Url, dataCadastro, idUsuarioCadastro)
                                            VALUES(@idChave, @idMenuPai, @Descricao, @Visivel, @Url, getdate(), @idUsuarioCadastro);
                                            SET @idMenu = SCOPE_IDENTITY()";

                SqlCommand cmdInserir = new SqlCommand(stringSQL, connection);

                ValidaCampos(ref Menu);

                cmdInserir.Parameters.Add("idMenu", SqlDbType.Int);
                cmdInserir.Parameters["idMenu"].Direction = ParameterDirection.Output;

                cmdInserir.Parameters.Add("idUsuarioCadastro", SqlDbType.Int).Value = Menu.idUsuarioCadastro;

                cmdInserir.Parameters.Add("idChave", SqlDbType.VarChar).Value   = Menu.idChave;
                cmdInserir.Parameters.Add("idMenuPai", SqlDbType.Int).Value     = Menu.idMenuPai;
                cmdInserir.Parameters.Add("Descricao", SqlDbType.VarChar).Value = Menu.Descricao;
                cmdInserir.Parameters.Add("Visivel", SqlDbType.Bit).Value       = Menu.Visivel;
                cmdInserir.Parameters.Add("Url", SqlDbType.VarChar).Value       = Menu.Url;

                try
                {
                    connection.Open();
                    cmdInserir.ExecuteNonQuery();
                    return((int)cmdInserir.Parameters["idMenu"].Value);
                }
                catch
                {
                    //throw new ApplicationException("

                    throw new ApplicationException("Erro ao inserir registro");
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Beispiel #5
0
        public static dtoMenu Get(int idMenu)
        {
            dtoMenu menu = new dtoMenu();

            using (SqlConnection connection = new SqlConnection(DataAccess.Configuracao.getConnectionString()))
            {
                string stringSQL = @"SELECT tb1.*, tb2.Descricao AS descricaoPai
                                    FROM tbMenu AS tb1
                                    LEFT JOIN tbMenu AS tb2
	                                    ON tb1.idMenuPai = tb2.idMenu
                                    WHERE tb1.idMenu = @idMenu";

                SqlCommand cmdMenu = new SqlCommand(stringSQL, connection);

                cmdMenu.Parameters.Add("idMenu", SqlDbType.Int).Value = idMenu;

                try
                {
                    connection.Open();
                    SqlDataReader drMenu = cmdMenu.ExecuteReader();

                    if (drMenu.Read())
                    {
                        PreencheCampos(drMenu, ref menu);
                    }
                }
                catch
                {
                    throw new ApplicationException("Erro ao capturar registro");
                }
                finally
                {
                    connection.Close();
                }
            }

            return(menu);
        }
Beispiel #6
0
        protected void rptMenuGrupos_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                dtoUsuario usuario = bllUsuario.GetByLogin(HttpContext.Current.User.Identity.Name);

                Repeater       rptMenuItens = (Repeater)e.Item.FindControl("rptMenuItens");
                dtoMenu        menuItem     = (dtoMenu)e.Item.DataItem;
                List <dtoMenu> menusFilhos  = null;

                if (usuario.Administrador)
                {
                    menusFilhos = bllMenu.GetAllChildrens(menuItem.idMenu);
                }
                else
                {
                    menusFilhos = bllMenu.GetAllChildrensByUsuario(menuItem.idMenu, usuario.idUsuario);
                }

                rptMenuItens.DataSource = menusFilhos;
                rptMenuItens.DataBind();
            }
        }
Beispiel #7
0
        private static void PreencheCampos(SqlDataReader drMenu, ref dtoMenu Menu)
        {
            // CAMPOS CHAVES
            if (drMenu["idChave"] != DBNull.Value)
            {
                Menu.idChave = drMenu["idChave"].ToString();
            }


            if (drMenu["idMenu"] != DBNull.Value)
            {
                Menu.idMenu = Convert.ToInt32(drMenu["idMenu"].ToString());
            }

            if (drMenu["idMenuPai"] != DBNull.Value)
            {
                Menu.idMenuPai = Convert.ToInt32(drMenu["idMenuPai"].ToString());
            }

            // CAMPOS PADRAO SEGURANCA
            if (ProJur.DataAccess.Utilitarios.ColumnExists(drMenu, "descricaoPai"))
            {
                if (drMenu["descricaoPai"] != DBNull.Value)
                {
                    Menu.descricaoMenuPai = drMenu["descricaoPai"].ToString();
                }
            }

            if (drMenu["idUsuarioCadastro"] != DBNull.Value)
            {
                Menu.idUsuarioCadastro = Convert.ToInt32(drMenu["idUsuarioCadastro"].ToString());
            }

            if (drMenu["idUsuarioUltimaAlteracao"] != DBNull.Value)
            {
                Menu.idUsuarioCadastro = Convert.ToInt32(drMenu["idUsuarioUltimaAlteracao"].ToString());
            }

            if (drMenu["dataCadastro"] != DBNull.Value)
            {
                Menu.dataCadastro = Convert.ToDateTime(drMenu["dataCadastro"]);
            }
            else
            {
                Menu.dataCadastro = null;
            }

            if (drMenu["dataUltimaAlteracao"] != DBNull.Value)
            {
                Menu.dataUltimaAlteracao = Convert.ToDateTime(drMenu["dataUltimaAlteracao"]);
            }
            else
            {
                Menu.dataUltimaAlteracao = null;
            }

            if (drMenu["Visivel"] != DBNull.Value)
            {
                Menu.Visivel = Convert.ToBoolean(drMenu["Visivel"]);
            }


            // CAMPOS NORMAIS
            if (drMenu["Url"] != DBNull.Value)
            {
                Menu.Url = drMenu["Url"].ToString();
            }


            if (drMenu["Descricao"] != DBNull.Value)
            {
                Menu.Descricao = drMenu["Descricao"].ToString();
            }
        }