using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Configuration;
using System.Xml;
using System.Data;
using System.Data.SqlClient;
using SysCore;

public partial class Root_OnlineUsers_OnlineUsers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        new RootControl().CheckRootLogin();
        if (!Page.IsPostBack)
        {
            InitDB();
            InitTable();
        }
    }
    protected void Page_PreRender(object sender, EventArgs e)
    {
        
    }
    /// <summary>
    /// 绑定数据
    /// </summary>
    void InitDB()
    {
        string db = "";
        if (Request["db"] != null)
        {
            db = Request["db"].ToString();
        }
        SqlUtil su = new SqlUtil();
        su.SetDatabaseName("master");
        string sql_db = @"SELECT name
                        FROM master.dbo.sysdatabases
                        WHERE name like 'xplat%'
                        ORDER BY name ";
        DataTable dt_db = su.GetDataTable(sql_db, null);
        foreach (DataRow dr in dt_db.Rows)
        {
            //dll_db.Items.Add(dr["name"].ToString().Replace("xplat",""));
            dll_db.Items.Add(dr["name"].ToString());
        }
        if (!db.Equals(""))
        {
            dll_db.SelectedValue = db;
        }

    }
    void InitTable()
    {
        try
        {
            SqlUtil su = new SqlUtil();
            su.SetDatabaseName(dll_db.SelectedValue);
            string sql = @"select ou.ou_id,ou.u_id,m.username,m.nickname,login_date,ip
                    from System_OnlineUsers ou
                    left join System_Member m on ou.u_id=m.uid ";

            sql += " order by ou_id asc";
            //Response.Write(sql);
            DataTable dt = su.GetDataTable(sql, null);
            list_view.DataSource = dt;
            list_view.DataBind();
        }
        catch
        {
            list_view.Items.Clear();
            //Response.Write(err.Message);
        }
    }
    protected void dll_db_SelectedIndexChanged(object sender, EventArgs e)
    {
        InitTable();
    }
    protected void Refresh_Click(object sender, EventArgs e)
    {
        InitTable();
    }
}