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_Site_SiteIndex : 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_Site a left join NT_Siteconfig b on a.SiteTypeId=b.ID";
        sql_CountFirst += " where a.[UserId]=" + Session["ID"] + "";


        //查询语句的头部
        string sql_SelectFirst = string.Empty;
        sql_SelectFirst += " select a.[Id],a.[SiteTypeId],a.[SiteName],a.[SiteImg],a.[SiteFeature],";
        sql_SelectFirst += " a.[SiteInfo],a.[SitePrice],a.[SiteCycle],a.[SiteAttachment],a.[UserId],b.[Name] ";
        sql_SelectFirst += " from NT_Site a left join NT_SiteType b on a.SiteTypeId=b.ID";
        sql_SelectFirst += " where a.[UserId]=" + Session["ID"] + "";

        //排序
        string sql_SelectLast = " order by a.ID desc";


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

        #region 查询条件

        string str_SiteName = StringFunc.DataFilter(this.txt_SiteName.Text.Trim());
        if (str_SiteName.Length > 0)
        {
            sql_Conditions += " and a.SiteName like '%" + str_SiteName + "%'";
        }

        #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 btnUpdate_Command(object sender, CommandEventArgs e)
    {
        JavaScriptFunc.Redirect("SiteEdit.aspx?Id=" + e.CommandArgument.ToString());
    }
    //删除
    protected void btnDelete_Command(object sender, CommandEventArgs e)
    {

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


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

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

    //GridView1_RowDataBound
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         int RowIndex = e.Row.RowIndex;
         if (RowIndex > -1)
         {
             //根据类型显示隐藏设置列
             //if ((e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.Footer))
             if (e.Row.RowType != DataControlRowType.Header)
             {

                 if (e.Row.Cells[1].Text.Trim().Length > 0)
                 {
                     string str_1 = e.Row.Cells[1].Text.Trim();
                     e.Row.Cells[1].Text = "<img src='" + str_1 + "' width='50px' height='50px' alt='暂无' />";
                 }
                 else
                 {
                     e.Row.Cells[1].Text = "暂无";
                 }


             }
         }
    }
}
