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 Base;
using Solely;
using WebBasicInfo;
using UserInfo;
using VipGrade;

public partial class Member_Index : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (CheckCookies())
            {
                if (!IsPostBack)
                {
                    Bind();
                }
            }
            else
            {
                Response.Redirect("~/login/login.aspx");
            }
        }
        catch(Exception ex)
        {
            // Response.Redirect("../Error.aspx");
            Response.Write(ex.Message);
        }

    }

    /// <summary>
    /// 会员中心首页
    /// </summary>
    private void Bind()
    {
        BasicBind();
        Product();
        ConsultativeBind();
        ExpoNewsBind();
        NewsBind();
    }
    /// <summary>
    /// 会员身份及网站咨询热线信息
    /// </summary>
    private void BasicBind()
    {
        IWebBasicInfo rbasic = new RWebBasicInfo();
        TWebBasicInfo tbasic = rbasic.GateItem();
        lblHotTel.Text = tbasic.HotTel;//热线电话

        IUserInfo ruser = new RUserInfo();
        TUserInfo tuser = ruser.GateItem(int.Parse(GetCookie("UserID")));

        IVipGrade grade = new RVipGrade();
        //DataTable dt = grade.GetDataTable(tuser.GradeID);
        DataSet dt = grade.GetDataTable();

        if (dt.Tables[0].Rows.Count == 0)     //没有会员等级
        {
            //Response.Redirect("");
        }
        else if (dt.Tables[0].Rows.Count == 1)
        {
            lblGrade.Text += "您现在是" + dt.Tables[0].Rows[0]["Name"].ToString() + ",可以享受" + BasePage.Config.WebName + "的特权服务";
        }
        else
        {
            string strGradeName = "普通会员";
            for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
            {
                if (dt.Tables[0].Rows[i]["ID"].ToString() == GetCookie("GradeID"))
                {
                    strGradeName = dt.Tables[0].Rows[i]["Name"].ToString();
                }
            }
            if (strGradeName != dt.Tables[0].Rows[0]["Name"].ToString())
                lblGrade.Text = "您现在是" + strGradeName + ",无法享受" + BasePage.Config.WebName + "的特权服务，建议您升级为" + dt.Tables[0].Rows[0]["Name"].ToString(); 
            else
                lblGrade.Text += "您现在是" + dt.Tables[0].Rows[0]["Name"].ToString() + ",可以享受" + BasePage.Config.WebName + "的特权服务";
        }
        this.Introduce.InnerHtml = dt.Tables[0].Rows[0]["Name"].ToString() + "是" + BasePage.Config.WebName + "的一种会员身份，拥有多种优势、多种增值服务，及享有网站各种推广、优惠的活动的优先权利！";
        //lblGrade.Text += "您现在是";
        //if (dt.Rows[0]["Name"].ToString() == "普通会员")
        //{
        //    lblGrade.Text += dt.Rows[0]["Name"].ToString();//会员等级名称
        //    lblGrade.Text += ",无法享受WebSen!NT的特权服务，建议您升级为网胜通";
        //}
        //else
        //{
        //    lblGrade.Text += dt.Rows[0]["Name"].ToString();
        //    lblGrade.Text += ",可以享受WebSen!NT的特权服务";
        //}
    }
    /// <summary>
    /// 行业资讯
    /// </summary>
    private void ConsultativeBind()
    {
        int Pageindex = 1;
        int pageSize = 5;
        string strWhere = "1=1";
        string table = "W_Consultative as a LEFT  JOIN W_ConsultativeType as b ON a.TypeID = b.ID";
        string select = "a.ID,a.Title,a.TypeID,a.Picture,a.KeyWord,a.Author,a.Origin,a.Reading,a.AddDate,a.ClickCount,b.Name";
        DataTable dt = PageList.GetDataTable(strWhere, table, 1, "a.AddDate", select, pageSize, Pageindex, 0);
        dlstConsultative.DataSource = dt.DefaultView;
        dlstConsultative.DataBind();
    }

    /// <summary>
    ///展会资讯 
    /// </summary>
    private void ExpoNewsBind()
    {
        int Pageindex = 1;
        int pageSize = 4;
        string strWhere = "1=1";
        string table = "W_ExpoNews as a LEFT  JOIN W_ExpoNewsType as b ON a.TypeID = b.ID";
        string select = "a.ID,a.TypeID,a.Title,a.Attribute,a.Origin,a.Detail,a.Origin,a.Picture,a.AddDate,b.Type";
        DataTable dt = PageList.GetDataTable(strWhere, table, 1, "a.AddDate", select, pageSize, Pageindex, 0);
        dlstExpoNews.DataSource = dt.DefaultView;
        dlstExpoNews.DataBind();
    }
    /// <summary>
    /// 公司新闻
    /// </summary>
    private void NewsBind()
    {
        int Pageindex = 1;
        int pageSize = 4;
        int Userid = int.Parse(GetCookie("UserID"));
        string strWhere = "UserID=" + Userid;
        string table = "C_News";
        string select = "*";
        DataTable dt = PageList.GetDataTable(strWhere, table, 1, "AddDate", select, pageSize, Pageindex, 0);
        dlstNews.DataSource = dt.DefaultView;
        dlstNews.DataBind();
    }
    /// <summary>
    /// 未审核、过期、未读留言的商机信息
    /// </summary>
    private void Product()
    {
        int Message = 0;
        int UnreadMessageCount = 0;
        int PastDueCount = 0;
        int UnauditedCount = 0;
        try
        {
            int Userid = int.Parse(GetCookie("UserID"));
            Other.CheckUserProductCount(Userid, out UnreadMessageCount, out PastDueCount, out UnauditedCount);
        }
        catch
        {
            return;
        }
        lblUnreadMesage.Text = UnreadMessageCount.ToString();
        lblPastDue.Text = PastDueCount.ToString();
        lblUnaudited.Text = UnauditedCount.ToString();
        if (UnreadMessageCount != 0)
            Message++;
        if (PastDueCount != 0)
            Message++;
        if (UnauditedCount != 0)
            Message++;
        lblMesage.Text = Message.ToString();
    }
}
