using System;
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 nspEmail;
using nspEmail.Lables;

public partial class Admin_Email_EmailStatistics : Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("Basic", "D1");
        if (!IsPostBack)
        {
            Bind();
        }
    }
    private void Bind()
    {
        string strUrlTo = Request.RawUrl;
        strUrlTo = strUrlTo.Substring(0, strUrlTo.IndexOf(".aspx")) + ".aspx";
        PageNo1.Strurl = strUrlTo;
        PageNo1.PageSize = 12;
        PageNo1.Table = "W_EmailStatistics as a inner join U_UserInfo b on a.UserID=b.UserID";
        PageNo1.FldName = "AddDate";
        PageNo1.StrGetFields = "a.ID,a.State,a.SubscriptionType,a.AddDate,b.LoginName";
        PageNo1.Where = "1=1";
        if (Request.QueryString["page"] != null && Request.QueryString["page"] != "")
        {
            PageNo1.Pageindex = Convert.ToInt32(Request.QueryString["page"].ToString());
            DataTable dt = PageNo1.BindView();
            if (dt.Rows.Count == 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "暂无数据！";
            }
            else
                lblMessage.Visible = false;
            dlEmaillist.DataSource = dt.DefaultView;
            dlEmaillist.DataBind();
        }
        else
        {
            PageNo1.Pageindex = 1;
            DataTable dt = PageNo1.BindView();            
            dlEmaillist.DataSource = dt.DefaultView;
            dlEmaillist.DataBind();
        }
    }
    protected void dlEmaillist_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id = int.Parse(dlEmaillist.DataKeys[e.Item.ItemIndex].ToString());
        EmailStatistics email = new EmailStatistics();
        email.Delete(id);
        string strUrlTo = Request.RawUrl;
        strUrlTo = strUrlTo.Substring(0, strUrlTo.IndexOf(".aspx")) + ".aspx";
        Response.Redirect(strUrlTo + "?page=1");
        Response.End();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < dlEmaillist.Items.Count; i++)
        {
            CheckBox cbox = (CheckBox)dlEmaillist.Items[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                int id = int.Parse(dlEmaillist.DataKeys[i].ToString());
                EmailStatistics email = new EmailStatistics();
                email.Delete(id);
            }

        }
        string strUrlTo = Request.RawUrl;
        strUrlTo = strUrlTo.Substring(0, strUrlTo.IndexOf(".aspx")) + ".aspx";
        Response.Redirect(strUrlTo + "?page=1");
        Response.End();
    }
}
