protected void btnEditar_Click(object sender, EventArgs e)
        {
            string idTut, idAssuntoAtual, idAssuntoNovo;

            idTut          = Session["idtutorial"].ToString();
            idAssuntoAtual = Session["idAssunto"].ToString();

            DropDownList dropTuto = (DropDownList)Repeater1.Items[0].FindControl("dropAssuntos");

            idAssuntoNovo = dropTuto.SelectedValue;

            FileUpload arquivo = (FileUpload)Repeater1.Items[0].FindControl("arquivo");

            TextBox titulo = (TextBox)Repeater1.Items[0].FindControl("titulo");

            Modelo.Tutorial attTutorial = new Modelo.Tutorial(idTut, titulo.Text, arquivo.FileBytes);

            CheckBox manter = (CheckBox)Repeater1.Items[0].FindControl("manter");

            DAL.DALTutorial dALTutorial = new DAL.DALTutorial();
            if (manter.Checked)
            {
                dALTutorial.Update(attTutorial, idAssuntoAtual, idAssuntoNovo);
            }
            else
            {
                dALTutorial.Update(attTutorial, idAssuntoAtual, idAssuntoAtual);
            }
        }
Exemple #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Modelo.Tutorial aTutorial;
            DAL.DALTutorial aDALTutorial;

            byte[] bytes = arquivo.FileBytes;

            aTutorial = new Modelo.Tutorial("1", Session["idusuario"].ToString(), titulo.Text, 3, bytes);

            aDALTutorial = new DAL.DALTutorial();

            bool ok = true;

            //validação dos outros dados
            try
            {
                aDALTutorial.Insert(aTutorial, "");
            }
            catch (SqlException error)

            {
                ok = false;

                if (error.Message.Contains("O titulo do tutorial nao deve ser vazio"))
                {
                    Session["MsgErrotitulo"] = "O titulo do tutorial nao deve ser vazio";
                }

                if (error.Message.Contains("voce deve adiconar um arquivo ao novo tutorial"))
                {
                    Session["MsgErroarquivo"] = "voce deve adiconar um arquivo ao novo tutorial";
                }
            }

            if (ok)
            {
                Response.Redirect("~\\3-Bolsista\\WebFormCRUDTutorialBolsista.aspx");
            }
            else
            {
                Response.Redirect("~\\3-Bolsista\\WebFormAddTutorialBolsista.aspx");
            }
        }
Exemple #3
0
        protected void Repeater3_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //Verifica se o comando é "Editar"
            if (e.CommandName.ToString() == "Baixar")
            {
                string id;
                //int index = Convert.ToInt32(e.CommandArgument);

                string[] arg = new string[2];
                arg = e.CommandArgument.ToString().Split(';');

                id = arg[0];
                string theFileName = arg[1];
                //string theFileName = GridView1.Rows[index].Cells[2].Text;

                DAL.DALTutorial arquivo = new DAL.DALTutorial();

                byte[] data   = arquivo.SelectDownload(id).arquivo;
                byte[] buffer = null;
                using (Stream st = new MemoryStream(data))
                {
                    buffer = new byte[st.Length];
                    long dataLengthToRead = st.Length;
                    Response.ContentType = "application/pdf";
                    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + theFileName + ".pdf\"");
                    while (dataLengthToRead > 0 && Response.IsClientConnected)
                    {
                        Int32 lengthRead = st.Read(buffer, 0, data.Length);
                        Response.OutputStream.Write(buffer, 0, lengthRead);
                        Response.Flush();
                        dataLengthToRead = dataLengthToRead - lengthRead;
                    }
                    Response.Flush();
                    Response.Close();
                }
                Response.End();
            }
        }
        protected void Repeater3_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Negar")
            {
                string id;
                //int index = Convert.ToInt32(e.CommandArgument);
                string[] arg = new string[2];
                arg = e.CommandArgument.ToString().Split(';');

                id            = arg[0];
                Session["id"] = id;
                DAL.DALTutorial arquivo = new DAL.DALTutorial();

                Modelo.Tutorial mtutorial;

                mtutorial = arquivo.Select(id);

                arquivo.Delete(mtutorial);

                Response.Redirect("~//2-Servidor/WebFormTutorialSubmetido.aspx");
            }
            if (e.CommandName == "Autorizar")
            {
                string id;
                //int index = Convert.ToInt32(e.CommandArgument);
                string[] arg = new string[2];
                arg = e.CommandArgument.ToString().Split(';');

                id            = arg[0];
                Session["id"] = id;
                DAL.DALTutorial arquivo = new DAL.DALTutorial();

                Modelo.Tutorial mtutorial;

                mtutorial = arquivo.Select(id);

                mtutorial.status = 2;

                arquivo.UpdateStatus(mtutorial);

                Response.Redirect("~//2-Servidor/WebFormTutorialSubmetido.aspx");
            }
            if (e.CommandName == "Baixar")
            {
                string id;
                //int index = Convert.ToInt32(e.CommandArgument);
                string[] arg = new string[2];
                arg = e.CommandArgument.ToString().Split(';');

                id = arg[0];
                string          theFileName = arg[1];
                DAL.DALTutorial arquivo     = new DAL.DALTutorial();

                byte[] data   = arquivo.SelectDownload(id).arquivo;
                byte[] buffer = null;
                using (Stream st = new MemoryStream(data))
                {
                    buffer = new byte[st.Length];
                    long dataLengthToRead = st.Length;
                    Response.ContentType = "application/pdf";  //Or other you need
                    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + theFileName + ".pdf\"");
                    while (dataLengthToRead > 0 && Response.IsClientConnected)
                    {
                        Int32 lengthRead = st.Read(buffer, 0, data.Length);
                        Response.OutputStream.Write(buffer, 0, lengthRead);
                        Response.Flush();
                        dataLengthToRead = dataLengthToRead - lengthRead;
                    }
                    Response.Flush();
                    Response.Close();
                }
                Response.End();
            }
        }