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 System.Web.Security;
using System.Data.SqlClient;

namespace norke
{
public partial class zs_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //权限检查
        HttpCookie cookie = Request.Cookies["norkeyangjian"];
        if (cookie == null)
        {
            Response.Redirect("~/login.aspx");
            return;
        }

        if (!IsPostBack)
        {
            Data();           
        }
    }
    private void Data()//绑定数据
    {
        DBConn myDB = new DBConn();
        string sql = "select * from zhaoshang Left Outer join Category on  zhaoshang.zspfl = Category.CID where hyname='" + Request.Cookies["norkeyangjian"].Value + "' order by ID desc";
        DataGrid1.DataSource = myDB.getDataReader(sql);
        DataGrid1.DataBind();
        mySqlPager.setAttribute(SqlPager1, "DataGrid1", sql, "1000000-PID", 20);
    }   
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        DBConn myDB = new DBConn();
        string sql = "select * from zhaoshang Left Outer join Category on  zhaoshang.zspfl = Category.CID  where zname like '%" + this.txtSelect.Text.Trim() + "%' and hyname='" + Request.Cookies["norkeyangjian"].Value + "' order by ID desc";
        DataGrid1.DataSource = myDB.getDataReader(sql);
        DataGrid1.DataBind();
        mySqlPager.setAttribute(SqlPager1, "DataGrid1", sql, "1000000-PID", 20);
    }
    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
    {
        string strid = e.Item.Cells[0].Text;
        DBConn myDB = new DBConn();
        string sql = "select zimg from zhaoshang where ID=" + strid;
        SqlDataReader dr = myDB.getDataReader(sql);
        if (dr.Read())
        {
            Label1.Text = dr["zimg"].ToString();
        }
        dr.Close();
        if (Label1.Text != "showimg.gif")
        {
            System.IO.File.Delete(base.Server.MapPath(".\\zhaoshang\\") + Label1.Text);           
        }      
            DBConn myDB1 = new DBConn();
            string mySql = "Delete from zhaoshang where ID=" + strid;
            myDB1.Delete(mySql);
            myDB1.Close();
            Data();
    }
}
}