using System;
using System.Data.SqlClient;

public partial class controls_left : System.Web.UI.UserControl
{
    sqloper sqloper = new sqloper();
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    //把Application["EveryIP"]的在线ip地址列表显示出来
    public string getip()      
    {
        if (Application["EveryIP"].ToString().IndexOf(Request.UserHostAddress.ToString()) < 0)
        {
            string ad;
            if (Session["ad"].ToString() == "")
            { ad = "游客"; }
            else
            { ad = Session["ad"].ToString(); }
            string tempip = ad + "[" + Session["ip"].ToString() + "]&nbsp;&nbsp;|&nbsp;&nbsp;";
            Application.Lock();
            Application["EveryIP"] = Application["EveryIP"].ToString() + tempip;
            Application["total"] = (int)Application["total"] + 1;    //增加一个在线人数
            Application.UnLock();//解锁
        }
        return Application["EveryIP"].ToString();
    }

    //浏览者身份显示
    public string customer()
    {
        string sheng;
        string ad = Convert.ToString(Session["ad"]);
        if (ad != "")
        {
            sheng = ad;
            return sheng;
        }
        else
        {
            sheng = "游客";
            return sheng;
        }
    }

    //浏览者权限显示
    public string profiles()
    {
        string profile = Convert.ToString(Session["profile"]);
        if (profile != "")
        {
            profile = ",你是" +"<font style='text-decoration:underline'>"+profile+"</font>";
            return profile;
        }
        else
        {
            profile = "";
            return profile;
        }
    }

    //注销
    protected void leave_Click(object sender, EventArgs e)      
    {
            //注销动作,把application赋空值
            string ad;
            if (Session["ad"].ToString() == "")
            { ad = "游客"; }
            else
            { ad = Session["ad"].ToString(); }
            string tempip = ad + "[" + Session["ip"].ToString() + "]&nbsp;&nbsp;|&nbsp;&nbsp;";
            string tempip2 = "游客" + "[" + Session["ip"].ToString() + "]&nbsp;&nbsp;|&nbsp;&nbsp;";
            Application.Lock();
            Application["EveryIP"] = Application["EveryIP"].ToString().Replace(tempip, tempip2);
            Application.UnLock();//解锁
            //End    

            Session["ad"] = "";
            Session["oldad"] = "";
            Session["pw"] = "";
            Session["profile"] = "";
            Response.Redirect("Default.aspx");      
    }

    //清楚application缓存
    protected void LinkButton1_Click(object sender, EventArgs e)      
    {
            //初始化application
            string ad;
            if (Session["ad"].ToString() == "")
            { ad = "游客"; }
            else
            { ad = Session["ad"].ToString(); }
            string tempip = ad + "[" + Session["ip"].ToString() + "]&nbsp;&nbsp;|&nbsp;&nbsp;";
            Application.Lock();
            Application["EveryIP"] = tempip;
            Application["total"] = 1;    //变为一个在线人数
            Application.UnLock();//解锁
            //End
    }

    //日志分类子栏目
    public string dairy_class()
    {
        string temp="";
        SqlConnection one = conn.sqlconn();
        sqloper sqloper = new sqloper();
        SqlDataReader rs = sqloper.readsql("select * from classdai order by dsort desc", one);
        temp = temp + "<ul>";
        while (rs.Read())
        {
            temp = temp + "<li><a href='dairy.aspx?daiclass=" + Encryption.Encrypt(rs["dclass"].ToString()) + "' target='showup'>" + rs["dclass"].ToString() + "</a></li>";
        }
        temp = temp + "</ul>";
        return temp;
    }

    //图片分类子栏目
    public string pic_class()
    {
        string temp = "";
        SqlConnection one = conn.sqlconn();
        sqloper sqloper = new sqloper();
        SqlDataReader rs = sqloper.readsql("select * from picclass order by psort desc", one);
        temp = temp + "<ul>";
        while (rs.Read())
        {
            temp = temp + "<li><a href='pic.aspx?pclass=" + Encryption.Encrypt(rs["pclass"].ToString()) + "'  target='showup'>" + rs["pclass"].ToString() + "</a></li>";
        }
        temp = temp + "</ul>";
        return temp;
    }

    //公告栏读取
    protected string gonggao_show()
    {
        return sqloper.loaddb("select * from config","gmsg");
    }

    //留言本名字读取
    protected string bookname_show()
    {
        return sqloper.loaddb("select * from config", "gname");
    }
}
