using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Text;
public partial class BackCenter_Links_LinksIndex : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        #region 过期和权限

        PageFunc.IfLogin(this.Page);
        //PubPageFunc.PageHavePurview(this.Page, "2001");

        #endregion
        if (!IsPostBack)
        {
            BindData();
        }
    }

    //绑定
    public void BindData()
    {

        //计算总数的语句的头部
        string sql_CountFirst = string.Empty;
        sql_CountFirst += " select";
        sql_CountFirst += " count(*)";
        sql_CountFirst += " from NT_Links";
        sql_CountFirst += " where 1=1";


        //查询语句的头部
        string sql_SelectFirst = "select ";
        sql_SelectFirst += " Id,";
        sql_SelectFirst += " Type,";
        sql_SelectFirst += " Title,";
        sql_SelectFirst += " AltTitle,";
        sql_SelectFirst += " PicturePath,";
        sql_SelectFirst += " LinkPath,";
        sql_SelectFirst += " OrderNum  ";
        sql_SelectFirst += " from NT_Links";
        sql_SelectFirst += " where 1=1";

        //排序
        string sql_SelectLast = " order by OrderNum asc,Id desc";


        //查询条件
        string sql_Conditions = string.Empty;

        #region 查询条件

        string str_Name = StringFunc.DataFilter(this.txt_Title.Text.Trim());
        if (str_Name.Length > 0)
        {
            sql_Conditions += " and Title like '%" + str_Name + "%'";
        }
        string str_Type = this.ddls_Type.SelectedValue;
        if (str_Type.Length > 0)
        {
            sql_Conditions += " and Type ='" + str_Type + "'";
        }

        #endregion

        //计算总数的语句
        string str_Count = sql_CountFirst + sql_Conditions;

        //查询语句
        string str_Select = sql_SelectFirst + sql_Conditions + sql_SelectLast;



        //AspNetPager
        //WebControlsFunc.BindToAspNetPager(this.AspNetPager1, CommandType.Text, str_count, null);

        //GridView
        //WebControlsFunc.BindToGridView(this.GridView1, this.AspNetPager1, CommandType.Text, str_select, null);

        WebControlsFunc.BindToAspNetPagerAndGridView(GridView1, AspNetPager1, str_Count, str_Select);
    }

    //查询
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }

    //分页
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindData();
    }

    //转向修改页
    protected void btnUpdate_Command(object sender, CommandEventArgs e)
    {
        JavaScriptFunc.Redirect("LinksEdit.aspx?Id=" + e.CommandArgument.ToString());
    }

    //删除
    protected void btnDelete_Command(object sender, CommandEventArgs e)
    {

        StringBuilder strSql = new StringBuilder();
        strSql.Append("delete from NT_Links ");
        strSql.Append(" where Id=@Id");
        OleDbParameter[] parameters = {
					new OleDbParameter("@ID",e.CommandArgument.ToString())
			};


        int rows = DbHelperOleDb.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);

        BindData();
    }

}
