using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Configuration;

namespace baoge.Admin
{
	/// <summary>
	/// log_look 的摘要说明。
	/// </summary>
	public class log_look : System.Web.UI.Page
	{
        protected System.IO.StreamWriter fs;
		protected System.Web.UI.WebControls.Label logshow;
		protected System.Web.UI.WebControls.Button clear_log;
		
		protected System.IO.StreamReader rs;
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("Admin_Login.aspx");
				
			}
			if(!IsPostBack)
			{
				log_show();
			}
		}


		private void log_show()
		{
			string logfile=System.Configuration.ConfigurationSettings.AppSettings["logfile"];
//			string log="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(logfile);
			string log="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+logfile;
			rs=new StreamReader(Server.MapPath(log),Encoding.Default);
			string logchar="<strong>登陆日志</strong><br>";
			while(rs.Peek()>-1)
			{
				logchar=logchar+rs.ReadLine()+"<br>";
			}
			rs.Close();
			logchar=logchar+"<br>*注若日志太多了,可能会影响到日志写入的速度,建议将日志下载到自己电脑上,再清除服务器上的日志.<br><a href=\""+log+"\">下载日志</a>(<FONT color=#ff6633>不能直接下载请点鼠标右键,选择目标另存为</FONT>)";
			logshow.Text=logchar;
		}
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.clear_log.Click += new System.EventHandler(this.clear_log_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void clear_log_Click(object sender, System.EventArgs e)
		{
			string logfile=System.Configuration.ConfigurationSettings.AppSettings["logfile"];
			
			string log="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+logfile;
			fs=new StreamWriter(Server.MapPath(log),false,Encoding.Default);
			fs.WriteLine(System.DateTime.Now+"开始统计:");
			fs.Close();
			log_show();
		}
	}
}
