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"; } } }
public void LINKDataInsert(LINKDataEntity lINKDataEntity) { Queries insert = new Queries(); var parametros = new SqlParameter[] { new SqlParameter("@id", lINKDataEntity.id), new SqlParameter("@FechaCaducidad", lINKDataEntity.FechaCaducidad), new SqlParameter("@Documento", lINKDataEntity.Documento), new SqlParameter("@Descripcion", lINKDataEntity.Descripcion), }; insert.Insert("LinksData_Insert", parametros); }
public List <LINKDataEntity> LINKDataSelect(LINKDataEntity lINKDataEntity) { var data = new List <LINKDataEntity>(); Queries select = new Queries(); var parametros = new SqlParameter[] { new SqlParameter("@id", lINKDataEntity.id), }; SqlDataReader reader = select.Select("SELECT [Id],[FechaCaducidad],[Documento],[Descripcion],[FechaCreacion] FROM [dbo].[LinksData] where id = @id", parametros); while (reader.Read()) { LINKDataEntity LINKDataEntityEntity_ = new LINKDataEntity(); LINKDataEntityEntity_.id = new Guid(reader["id"].ToString().ToUpper()); LINKDataEntityEntity_.FechaCaducidad = DateTime.Parse(reader["FechaCaducidad"].ToString()); LINKDataEntityEntity_.Documento = reader["Documento"].ToString().ToUpper(); LINKDataEntityEntity_.Descripcion = reader["Descripcion"].ToString().ToUpper(); LINKDataEntityEntity_.FechaCreacion = DateTime.Parse(reader["FechaCreacion"].ToString()); data.Add(LINKDataEntityEntity_); } return(data); }
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()); } }