using System;
using System.Data;
using System.Configuration;
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 System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
FileStream fs = new FileStream(Server.MapPath("LoginMsg.xml"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
DataTable dt = ds.Tables[0];
DataRow dr = dt.NewRow();
dr["custom_email"] = this.TextBox1.Text;
dr["custom_pass"] = this.TextBox2.Text;
dr["login_time"] = DateTime.Now.ToString();
fs = new FileStream(Server.MapPath("LoginMsg.xml"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
TextWriter writer = new StreamWriter(fs);
writer = TextWriter.Synchronized(writer);
ds.Tables[0].Rows.Add(dr);
ds.WriteXml(writer);
writer.Close();
Cache.Remove("myData");
LoadData();
}
public void LoadData()
{
DataView source = (DataView)Cache["myData"];
if (source == null)
{
DataSet ds = new DataSet();
FileStream fs = new FileStream(Server.MapPath("LoginMsg.xml"), FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
source = new DataView(ds.Tables[0]);
Cache.Insert("myData", source, new System.Web.Caching.CacheDependency(Server.MapPath("LoginMsg.xml")));
this.Label1.Text = "read from file";
}
else
{
this.Label1.Text = "read form cache";
}
this.GridView1.DataSource = source;
this.GridView1.DataBind();
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
}