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 Email.Subscription;

public partial class Member_Subscription_SubscriptionNewsList : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CheckCookies())
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        else
            Response.Redirect("../../login/login.aspx");
    }
    private void Bind()
    {
        int userid = int.Parse(GetCookie("UserID"));
        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx";
        PageNo1.Strurl = strURl;
        PageNo1.FldName = "AddDate";
        PageNo1.Table = "U_SubscriptionNews as a inner join W_ConsultativeType b on a.Type=b.ID inner join U_UserInfo c on a.UserID=c.UserID and c.UserID="+userid;
        PageNo1.StrGetFields = "a.ID,a.UserID,a.Type,a.AddDate,b.Name";
        PageNo1.PageSize = 5;
        if (Request.QueryString["page"] != "" && Request.QueryString["page"] != null)
        {
            PageNo1.Pageindex = Convert.ToInt32(Request.QueryString["page"].ToString());
            if (Session["strWhere"] != null)
            {
                PageNo1.Where = Session["strWhere"].ToString();
            }
            else
            {
                PageNo1.Where = "1=1";
            }
            DataTable dt = PageNo1.BindViewDesc();
            if (dt.DefaultView.Count == 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "暂无数据信息2";
            }
            else
            {
                lblMessage.Visible = false;
            }
            dlstSubscription.DataSource = dt.DefaultView;
            dlstSubscription.DataBind();
        }
        else
        {
            Session["strWhere"] = "1=1";
            PageNo1.Where = "1=1";
            PageNo1.Pageindex = 1;
            DataTable dt = PageNo1.BindViewDesc();
            if (dt.DefaultView.Count == 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "暂无数据信息2";
            }
            else
            {
                lblMessage.Visible = false;
            }
            dlstSubscription.DataSource = dt.DefaultView;
            dlstSubscription.DataBind();
        }
    }
    protected void dlstSubscription_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int ID = int.Parse(dlstSubscription.DataKeys[e.Item.ItemIndex].ToString());
        SubscriptionNews product = new SubscriptionNews();
        product.Delete(ID);
        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx?page=1";
        Response.Redirect(strURl);
        Response.End();
    }
}
