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.Data.SqlClient;

public partial class msg : System.Web.UI.Page
{
    public string x;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        
        if (!IsPostBack)
        {
            curpage.Text = Convert.ToString(1);
            fanye();            //翻页函数
        }
    }

    //短日期处理
    protected string short_time(object times)
    {
        stringdo shortime = new stringdo();
        return shortime.short_time(times);
    }

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.Item.ItemIndex != -1 && e.CommandName == "DRdel")//判断索引和CommandName
        {
            int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());//获取激发事件时的行的主键ID
            SqlConnection one = conn.sqlconn();
            one.Open();
            String Sql = "delete from book where id=" + id;
            SqlCommand cmd = new SqlCommand(Sql, one);
            cmd.ExecuteNonQuery();
            fanye();

        }

        if (e.Item.ItemIndex != -1 && e.CommandName == "recall")//判断索引和CommandName
        {
            //LinkButton txt = (LinkButton)e.Item.FindControl("call");
            //txt.Attributes["target"] = "showup";
           
            int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());//获取激发事件时的行的主键ID
            if (id != 0 && Session["profile"].ToString() == "前台管理员")
            {
                Response.Redirect("adcall.aspx?id=" + id);

            }
            else
            {
                Response.Write("<script>window.alert('你不是管理员,请登录后回复!')</script>");
            }
            fanye();

        }
    }

    public string replay(string recontent)          //管理员是否有回复【判断函数】
    {
        string myvalue = "";
        if (recontent == "")
        {
            myvalue = "";
            return myvalue;
        }
        else
        {
            myvalue = myvalue + "<tr>";
            myvalue = myvalue + "<td colspan='2' style='color:#333333'>-------------------------------------------------------------------------</td>";
            myvalue = myvalue + "</tr>";
            myvalue = myvalue + "<tr>";
            myvalue = myvalue + "<td colspan='2' style='color:#333333'>回复：  " + wormubb.ubb.UBBToHTML(recontent) + "</td>";
            myvalue = myvalue + "</tr>";
            return myvalue;
        }
    }

    public string level(int mylevel)          //用户级别【判断函数】
    {
        int star = 0;
        int i = 0;
        string imglevel = "";
        if (mylevel <= 10 && mylevel >= 0)
        {
            star = 1;
        }
        if (mylevel > 10 && mylevel <= 30)
        {
            star = 2;
        }
        if (mylevel > 30 && mylevel <= 80)
        {
            star = 3;
        }
        if (mylevel > 80)
        {
            star = 4;
        }
        for (i = 1; i <= star; i++)
        {
            imglevel = imglevel + "<img src='images/icon/level2.gif' width='13' height='12'alt='等级" + star + "' style='cursor:hand;'/>";
        }
        return imglevel;
    }


    protected void fanye()       //上一步，下一步，首尾页翻页函数
    {
        SqlConnection one = conn.sqlconn();
        one.Open();
        PagedDataSource ps = new PagedDataSource();
        SqlDataAdapter sda = new SqlDataAdapter("select * from book,customer where book.cname=customer.cname order by book.id desc", one);    //建立容器
        DataSet ds = new DataSet();        //数据设置对象
        try
        {

            sda.Fill(ds, "order");
            ps.DataSource = ds.Tables["order"].DefaultView;
            ps.AllowPaging = true;
            ps.PageSize = 4;
            ps.CurrentPageIndex = Convert.ToInt32(curpage.Text) - 1;
            allpage.Text = Convert.ToString(ps.PageCount);
            DataList1.DataSource = ps;

            //初始化下拉列表－－－－－－－－－－
            int i = 1;
            pagelist.Items.Clear();

            while (i <= ps.PageCount)
            {
                pagelist.Items.Add(new ListItem(Convert.ToString(i), Convert.ToString(i)));
                i = i + 1;
            }
            pagelist.SelectedIndex = int.Parse(curpage.Text) - 1;
            //结束－－－－－－－－－－－－－－－－－

            first.Enabled = true;
            pre.Enabled = true;
            next.Enabled = true;
            last.Enabled = true;
            if (curpage.Text == "1")
            {
                first.Enabled = false;
                pre.Enabled = false;
            }
            if (curpage.Text == allpage.Text)
            {
                next.Enabled = false;
                last.Enabled = false;
            }
            DataList1.DataBind();

        }
        catch (System.Exception ee)
        {
            Response.Write(ee.Message.ToString());
        }
        finally
        {
            DataList1.Dispose();
            ds.Dispose();
            sda.Dispose();
            one.Dispose();
            one.Close();
        }

    }

    protected void first_Click(object sender, EventArgs e)
    {
        curpage.Text = Convert.ToString(1);
        fanye();
    }
    protected void pre_Click(object sender, EventArgs e)
    {
        curpage.Text = Convert.ToString(Convert.ToInt32(curpage.Text) - 1);
        fanye();
    }
    protected void next_Click(object sender, EventArgs e)
    {
        curpage.Text = Convert.ToString(Convert.ToInt32(curpage.Text) + 1);
        fanye();
    }
    protected void last_Click(object sender, EventArgs e)
    {
        curpage.Text = allpage.Text;
        fanye();
    }

    protected void downchange(object sender, EventArgs e)   //下拉列框的翻页
    {
        curpage.Text = Convert.ToString(pagelist.SelectedValue);
        fanye();
    }
}
