using System;
using System.Collections.Generic;
using System.Data;

namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Vexit : System.Web.UI.Page
    {
        Model.PageInfo pageModel = new Stat.Model.PageInfo(50);
        /// <summary>
        /// 
        /// </summary>
        protected Model.StatInfo statModel = new Stat.Model.StatInfo();
        /// <summary>
        /// 
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            statModel.WebID = Plugin.Common.Rq_Int("wid");
            Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
            security.CheckReportPower(statModel.WebID);
            Model.WebSites websiteModel = Stat.Cache.CacheFatory.CreateWebSite().Get(statModel.WebID);
            if (websiteModel!=null)
            {
                this.Page.Title = "网站出口分析 " + websiteModel.WebName;
                pageModel.PageIndex = Plugin.Common.Rq_Int("page");
                pageModel.PageIndex = pageModel.PageIndex < 1 ? 1 : pageModel.PageIndex;

                if (!IsPostBack)
                {
                    statModel.StartTime = Plugin.Common.Rq_DateTime("st");
                    statModel.EndTime = Plugin.Common.Rq_DateTime("et");

                    DateTime dtNow = Convert.ToDateTime(DateTime.Now.ToShortDateString());

                    statModel.EndTime = statModel.EndTime > dtNow ? dtNow : statModel.EndTime;
                    statModel.StartTime = statModel.StartTime > statModel.EndTime ? statModel.EndTime : statModel.StartTime;

                    if (statModel.StartTime != statModel.EndTime && statModel.EndTime >= dtNow)
                    {
                        statModel.EndTime = statModel.EndTime.AddDays(-1);
                    }
                    this.txtStartDate.Text = statModel.strStartTime = statModel.StartTime.ToShortDateString();
                    this.txtEndDate.Text = statModel.strEndTime = statModel.EndTime.ToShortDateString();
                    Show();
                }
            }
        }
        /// <summary>
        /// 分析数据
        /// </summary>
        protected void Show()
        {
            statModel.StartTime = Convert.ToDateTime(statModel.strStartTime);
            statModel.EndTime = Convert.ToDateTime(statModel.strEndTime);
            ShowHtml(BLL.ViewExit.Get(statModel));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        protected void ShowHtml(DataTable dt)
        {
            string strdtRPageList = Stat.Html.Vexit.GetList(dt, pageModel.PageIndex, pageModel.PageSize);
            this.LtrVexitList.Text = strdtRPageList;
            Response.Flush();
            if (dt.Rows.Count > pageModel.PageSize)
            {
                string urlPar = "wid=" + statModel.WebID + "&st=" + statModel.strStartTime + "&et=" + statModel.strEndTime;
                this.LtrVexitPageIndex.Text = JPageIndex.GetIndex.Get(dt.Rows.Count, pageModel.PageIndex, pageModel.PageSize, urlPar, 1, 0, 1, 6);


                Response.Flush();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnTd_Click(object sender, EventArgs e)
        {
            string t1 = DateTime.Now.ToShortDateString();
            string t2 = DateTime.Now.ToShortDateString();
            string url = "Vexit.aspx?wid=" + statModel.WebID + "&st=" + t1 + "&et=" + t2;
            Response.Redirect(url);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnYd_Click(object sender, EventArgs e)
        {
            string t1 = DateTime.Now.AddDays(-1).ToShortDateString();
            string t2 = DateTime.Now.AddDays(-1).ToShortDateString();
            string url = "Vexit.aspx?wid=" + statModel.WebID + "&st=" + t1 + "&et=" + t2;
            Response.Redirect(url);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn7d_Click(object sender, EventArgs e)
        {
            string t1 = DateTime.Now.AddDays(-7).ToShortDateString();
            string t2 = DateTime.Now.ToShortDateString();
            string url = "Vexit.aspx?wid=" + statModel.WebID + "&st=" + t1 + "&et=" + t2;
            Response.Redirect(url);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMd_Click(object sender, EventArgs e)
        {
            DateTime t = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            string t1 = t.ToShortDateString();
            string t2 = t.AddMonths(1).AddDays(-1).ToShortDateString();
            string url = "Vexit.aspx?wid=" + statModel.WebID + "&st=" + t1 + "&et=" + t2;
            Response.Redirect(url);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPro_Click(object sender, EventArgs e)
        {
            string s1 = this.txtStartDate.Text.ToString();
            string s2 = this.txtEndDate.Text.ToString();
            if (s1 == "") { s1 = DateTime.Now.ToLongDateString(); }
            if (s2 == "") { s2 = DateTime.Now.ToLongDateString(); }

            s1 = Convert.ToDateTime(s1).AddDays(-1).ToShortDateString();
            s2 = Convert.ToDateTime(s2).AddDays(-1).ToShortDateString();


            string url = "Vexit.aspx?wid=" + statModel.WebID + "&st=" + s1 + "&et=" + s2;
            Response.Redirect(url);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNext_Click(object sender, EventArgs e)
        {
            string s1 = this.txtStartDate.Text.ToString();
            string s2 = this.txtEndDate.Text.ToString();
            if (s1 == "") { s1 = DateTime.Now.ToLongDateString(); }
            if (s2 == "") { s2 = DateTime.Now.ToLongDateString(); }

            DateTime t1 = Convert.ToDateTime(s1).AddDays(1);
            t1 = t1 > Convert.ToDateTime(DateTime.Now.ToShortDateString()) ? Convert.ToDateTime(DateTime.Now.ToShortDateString()) : t1;
            DateTime t2 = Convert.ToDateTime(s2).AddDays(1);
            t2 = t2 > Convert.ToDateTime(DateTime.Now.ToShortDateString()) ? Convert.ToDateTime(DateTime.Now.ToShortDateString()) : t2;

            string url = "Vexit.aspx?wid=" + statModel.WebID + "&st=" + t1.ToShortDateString() + "&et=" + t2.ToShortDateString();
            Response.Redirect(url);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnShowTime_Click(object sender, EventArgs e)
        {
            string url = "Vexit.aspx?wid=" + statModel.WebID + "&st=" + this.txtStartDate.Text + "&et=" + this.txtEndDate.Text;
            Response.Redirect(url);
        }
    }
}
