Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request.QueryString["link"] != null)
         {
             LINKDataEntity lINKDataEntity = new LINKDataEntity();
             lINKDataEntity.id = new Guid(Request.QueryString["link"].ToString());
             LINKDataDAL           lINKDataDAL = new LINKDataDAL();
             List <LINKDataEntity> DataList    = lINKDataDAL.LINKDataSelect(lINKDataEntity);
             if (DataList.Count > 0)
             {
                 if (DataList[0].FechaCaducidad >= DateTime.Now)
                 {
                     txtFilename.Value = DataList[0].Documento;
                 }
                 else
                 {
                     pMensaje.InnerHtml = "El documento ha expirado ";
                 }
             }
             else
             {
                 pMensaje.InnerHtml = "No existe el documento para este link";
             }
         }
         else
         {
             pMensaje.InnerHtml = "El link no es correcto";
         }
     }
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Guid     id            = Guid.NewGuid();
                DateTime date          = DateTime.Parse(datepicker.Value);
                string   fileNameURL   = "";
                string   fileExtension = "";
                bool     guardar       = false;
                if (FileUpload1.HasFile)
                {
                    foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
                    {
                        fileExtension = Path.GetExtension(postedFile.FileName);
                        if (fileExtension.Equals(".pdf"))
                        {
                            postedFile.SaveAs(Server.MapPath("~/pdfs/") + id + ".pdf");
                            fileNameURL = id.ToString();
                            guardar     = true;
                        }
                        else
                        {
                            string script2 = @"<script type='text/javascript'>
                                        swal('Error al generar el Link', 'El archivo adjunto debe ser PDF', 'error');
                                        </script>";
                            ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script2, false);
                        }
                    }

                    if (guardar)
                    {
                        LINKDataEntity lINKDataEntity = new LINKDataEntity();
                        lINKDataEntity.id             = id;
                        lINKDataEntity.FechaCaducidad = date;
                        lINKDataEntity.Documento      = id.ToString() + ".pdf";
                        lINKDataEntity.Descripcion    = txtDescripciones.Text;
                        LINKDataDAL lINKDataDAL = new LINKDataDAL();
                        lINKDataDAL.LINKDataInsert(lINKDataEntity);

                        string script = @"<script type='text/javascript'>  swal('Link generado!', 'El link se generĂ³ correctamente', 'success');</script>";
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false);
                        txtDescripciones.Text = String.Empty;
                        datepicker.Value      = String.Empty;

                        Alink.HRef = "ViewPdf.aspx?link=" + id;
                        divDatos.Style.Add("display", "none");
                        divLink.Style.Add("display", "inline");
                    }
                }
                else
                {
                    string script = @"<script type='text/javascript'>swal('Error', 'Debe seleccionar un archivo pdf', 'error');</script>";
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false);
                }
            }
            catch (Exception ex)
            {
                string script = @"<script type='text/javascript'>
                                        swal('Error al generar el Link', 'Por favor vuelva a intentarlo', 'error');
                                        </script>";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false);
                Response.Write(ex.ToString());
            }
        }