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 Expo;
using Base;

public partial class Member_Expo_ExpoNewsList : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckCookies())
        {
            Response.Redirect("../../login/login.aspx");
            return;
        }
        else
        {
            if (!IsPostBack)
            {
                ExpoNewsTypeBind();
                Bind();
            }
        }
    }
    private void Bind()
    {
        btnDelete.Attributes.Add("onclick", "return confirm('你确认要删除吗？')");
        IExpoNews RExpo = new RExpoNews();
        TExpoNews TExpo = new TExpoNews();
        TExpo.Title = txtKeyword.Text;
        TExpo.TypeID = int.Parse(dropExpoNewsType.SelectedValue);
        DataTable dt = RExpo.GetDataTable(TExpo);
        if (dt.Rows.Count == 0)
        {
            lblMessage.Visible = true;
            lblMessage.Text = "<font color='red'>暂无数据</font>";
        }
        else
            lblMessage.Visible = false;
        grdExpoNews.DataSource = dt.DefaultView;
        grdExpoNews.DataBind();
       
    }
    private void ExpoNewsTypeBind()
    {
        IExpoNewsType RExpo = new RExpoNewsType();
        DataTable dt = RExpo.GetDataTable();
        dropExpoNewsType.DataSource = dt.DefaultView;
        dropExpoNewsType.DataValueField = "ID";
        dropExpoNewsType.DataTextField = "Type";
        dropExpoNewsType.DataBind();
        ListItem li = new ListItem("--+所有分类信息+--", "0");
        dropExpoNewsType.Items.Add(li);
        li.Selected = true;
    }
    public string GetShortDate(string dateStr)
    {
        if (dateStr != string.Empty)
            return Convert.ToDateTime(dateStr).ToShortDateString();
        else
            return String.Empty;
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grdExpoNews.Rows.Count; i++)
        {
            CheckBox cbox = (CheckBox)grdExpoNews.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                int id = int.Parse(grdExpoNews.DataKeys[i].Value.ToString());
                IExpoNews RExpo = new RExpoNews();
                RExpo.Delete(id);
            }
        }
        Bind();
    }
    protected void grdConsultative_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdExpoNews.SelectedIndex = e.NewPageIndex;
        Bind();
    }
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        IExpoNews RExpo = new RExpoNews();
        TExpoNews TExpo = new TExpoNews();
        TExpo.Title = txtKeyword.Text;
        TExpo.TypeID =int.Parse(dropExpoNewsType.SelectedValue);
        DataTable dt=RExpo.GetDataTable(TExpo);
        if (dt.Rows.Count == 0)
        {
            lblMessage.Visible = true;
            lblMessage.Text = "<font color='red'>暂无数据</font>";
        }
        else
            lblMessage.Visible = false;
        grdExpoNews.DataSource = dt.DefaultView;
        grdExpoNews.DataBind();
    }
    protected void grdExpoNews_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
            e.Row.Attributes.Add("onMouseOut", "SetOldColor(this)");
        }
    }

}
