GIF89;a GIF89;a using System; using System.IO; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using BusinessLayer.BOObjects; using BusinessLayer.Controllers; using BusinessLayer.Entities; using Globals; public partial class DownloadArticle : BasePage { #region Private Variables int m_fileId = 0; #endregion protected void Page_Load(object sender, EventArgs e) { Literal label = (Literal)Login1.FindControl("FailureText1"); label.Text = ""; if (IsPostBack == false) { Control text = Page.Controls[0].Controls[0].FindControl("Sidebar1").FindControl("divText"); if (text != null) { text.Visible = false; Label title = (Label)Page.Controls[0].Controls[0].FindControl("Sidebar1").FindControl("Label2"); title.Text = Resources.Common.Title_2; } Control ctl = Login1.FindControl("LoginButton"); Control UpdateDetails = Login1.FindControl("UpdateDetails"); if (Request["file"] != null) m_fileId = Convert.ToInt32(Request["file"]); if (Session["UserId"] != null) GetFile(m_fileId); else { Login1.Attributes.Add("onkeypress", string.Format("javascript:return WebForm_FireDefaultButton(event, '{0}')", ctl.ClientID)); Login1.Attributes.Add("onkeypress", string.Format("javascript:return WebForm_FireDefaultButton(event, '{0}')", UpdateDetails.ClientID)); } } } protected void btnUpdate_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); ControllerUsers users = new ControllerUsers(); ds = users.Login(Login1.UserName, Login1.Password); if (ds.Tables[0].Rows.Count > 0) { Session.Add("UpdateUserName", Login1.UserName); Session.Add("UpdateUserPassword", Login1.Password); if (Request["file"] != null) m_fileId = Convert.ToInt32(Request["file"]); Response.Redirect("Registration.aspx?File=" + m_fileId.ToString(), true); } else { Literal label = (Literal)Login1.FindControl("FailureText1"); label.Text = GetLocalResourceObject("Login1.FailureText").ToString(); Login1.FailureText = GetLocalResourceObject("Login1.FailureText").ToString(); } } protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { DataSet ds = new DataSet(); ControllerUsers users = new ControllerUsers(); ds = users.Login(Login1.UserName, Login1.Password); if (ds.Tables[0].Rows.Count > 0) { DateTime expiredDate = DateTime.Today.AddDays(-1); if (ds.Tables[0].Rows[0]["EXPIREDDATE"] != DBNull.Value) expiredDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["EXPIREDDATE"]); if (expiredDate < DateTime.Today.AddDays(1)) { Login1.FailureText = GetLocalResourceObject("Login1.ExpiredDate").ToString(); return; } e.Authenticated = true; Session.Add("UserId", ds.Tables[0].Rows[0]["ID"].ToString()); GetFile(m_fileId); } else { Login1.FailureText = GetLocalResourceObject("Login1.FailureText").ToString(); } } private void GetFile(int p_fileId) { string result = ""; ControllerFiles files = new ControllerFiles(); DataSet ds = new DataSet(); ds = files.GetFile(p_fileId); if (ds.Tables[0].Rows.Count > 0) { result = ds.Tables[0].Rows[0]["FilePath"].ToString(); files.Download(Convert.ToInt32(Session["UserId"]), p_fileId); Response.Buffer = true; Response.ContentType = "application/pdf"; StreamReader stream = new StreamReader(Server.MapPath(result)); BinaryReader reader = new BinaryReader(stream.BaseStream); Response.BinaryWrite(reader.ReadBytes((int)reader.BaseStream.Length)); Response.End(); reader.Close(); } } }