Пример #1
0
 protected void btAlteracoes_Click(object sender, EventArgs e)
 {
     try
     {
         clsAutor obj = new clsAutor();
         obj.Id     = Convert.ToInt32(Request.Form["txtEditId"]);
         obj.Nome   = Request.Form["txtEditNome"];
         obj.Origem = Request.Form["txtEditOrigem"];
         string caminhoServer = Server.MapPath("~/IMAGENS/AUTORES/");
         string imgName       = Path.GetFileName(editFoto.PostedFile.FileName);
         if (imgName == "")
         {
             var x = Autores.SelecionarPeloId(obj.Id);
             imgName = x.Foto;
         }
         obj.Foto = Path.Combine(caminhoServer, imgName);
         editFoto.SaveAs(obj.Foto);
         obj.Foto = imgName;
         Autores dalAut = new Autores();
         dalAut.Atualizar(obj);
         Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Atualização Realizada Com Sucesso');window.location.href='Autor.aspx';", true);
     }
     catch
     {
         Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Não foi possivel atualizar!!!');window.location.href='Autor.aspx';", true);
     }
 }
Пример #2
0
        public void Atualizar(clsAutor obj)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbfrasesfamosas"].ConnectionString);
            SqlCommand    cmd = new SqlCommand("SPR_ATUALIZAR_AUTOR", con);

            try
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ID", obj.Id);
                cmd.Parameters.AddWithValue("@NOME_AUTOR", obj.Nome);
                cmd.Parameters.AddWithValue("@ORIGEM_AUTOR", obj.Origem);
                cmd.Parameters.AddWithValue("@FOTO_AUTOR", obj.Foto);
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                con.Close();
                cmd.Dispose();
            }
        }
Пример #3
0
        public static clsAutor SelecionarPeloId(int Id)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbfrasesfamosas"].ConnectionString);
            SqlCommand    cmd = new SqlCommand("SPR_LISTAR_POR_ID_AUTOR", con);

            try
            {
                clsAutor obj = new clsAutor();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ID", Id);
                con.Open();
                cmd.ExecuteNonQuery();
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    clsAutor aut = new clsAutor();
                    aut.Id     = Convert.ToInt32(reader["ID_AUTOR"]);
                    aut.Nome   = Convert.ToString(reader["NOME_AUTOR"]);
                    aut.Origem = Convert.ToString(reader["ORIGEM_AUTOR"]);
                    aut.Foto   = Convert.ToString(reader["FOTO_AUTOR"]);
                    obj        = aut;
                }
                return(obj);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                con.Close();
                cmd.Dispose();
            }
        }
Пример #4
0
        public static void RemoverAutor(int Id)
        {
            Autores.SelecionarPeloId(Id);
            clsAutor autor      = new clsAutor();
            string   deleteFile = Path.Combine(Autor.FullPath + clsAutor.pathForDelete);

            File.Delete(deleteFile);
            Autores.RemoverAutor(Id);
        }
Пример #5
0
        //Ocorre uma sobrecarga dos metodos Localizar. Se não for passado nenhum parametro ele ira executar o metodo
        //abaixo, pois não possui parametros. Caso tenha ele irá executar o que possui.

        public static List <clsAutor> SelecionarAutores()
        {
            //SqlCommand cmd = new SqlCommand("SPR_LISTAR_CATEGORIA", con);
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbfrasesfamosas"].ConnectionString);
            SqlCommand    cmd = new SqlCommand("SPR_SELECIONAR_AUTORES", con);

            cmd.CommandType = CommandType.StoredProcedure;

            List <clsAutor> lista = new List <clsAutor>();

            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    clsAutor autor = new clsAutor();
                    autor.Id               = Convert.ToInt32(reader["ID_AUTOR"]);
                    autor.Nome             = Convert.ToString(reader["NOME_AUTOR"]);
                    autor.Origem           = Convert.ToString(reader["ORIGEM_AUTOR"]);
                    autor.Foto             = Convert.ToString(reader["FOTO_AUTOR"]);
                    clsAutor.pathForDelete = autor.Foto;
                    lista.Add(autor);
                }
                return(lista);
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cmd.Dispose();
                con.Close();
            }
        }
Пример #6
0
        protected void btnConfirmar_Click(object sender, EventArgs e)
        {
            clsAutor autor = new clsAutor();

            autor.Nome   = Request.Form["txtNome"];
            autor.Origem = Request.Form["txtOrigem"];
            if (autor.Nome == "" || autor.Origem == "" || fileFoto.HasFile == false)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "modalMessage('Aviso', 'Preencha todos os campos!!');", true);
            }
            else if (fileFoto.HasFile == true || autor.Nome != "" || autor.Origem != "")
            {
                string caminhoServer = Server.MapPath("~/IMAGENS/AUTORES/");
                string imgFile       = Path.GetFileName(fileFoto.PostedFile.FileName);
                string caminho       = Path.Combine(caminhoServer, imgFile);
                fileFoto.SaveAs(caminho);
                autor.Foto = imgFile;
                Autores autores = new Autores();
                autores.Inserir(autor);
                autor.Nome   = "";
                autor.Origem = "";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Cadastro Realizado');window.location.href='Autor.aspx';", true);
            }
        }