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 xabaraCOM;

public partial class WebXabara_user_Default : System.Web.UI.Page
{
    admin a = new admin();
    fileDocument f = new fileDocument();
    sqlServer sql = new sqlServer();
    user u = new user();
    classify c = new classify();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check("|user|");

        if (!IsPostBack)
        {
            string[] uLevel = xml.read("xabara.config", "userType", 180).Split(new char[] { '|' });
            for (int i = 0; i < uLevel.Length; i++)
            {
                this.levList.Items.Add(new ListItem(uLevel[i], i.ToString()));
            }

            string searchWordTemp = Server.UrlDecode(xabara.safeSql(Request.QueryString["keyWords"]));
            string strSql = string.Empty;
            string ifStr = string.Empty;
            string orderBy = Request.QueryString["orderby"];
            if (string.IsNullOrEmpty(orderBy as string))
            {
                orderBy = "uID";
            }

            long levelID = xabara.isNum(Request.QueryString["level"]);
            if (levelID > -1)
            {
                ifStr = " and userLevel=" + levelID;
                this.levList.Items.FindByValue(levelID.ToString()).Selected = true;
            }

            if (!string.IsNullOrEmpty(searchWordTemp as string))
            {
                ifStr += " and (userID ='" + searchWordTemp + "' or userCardID = '" + searchWordTemp + "' or qqID='" + searchWordTemp + "' or alipayID = '" + searchWordTemp + "' or userName ='" + searchWordTemp + "' or userMobile like '%" + searchWordTemp + "' or userQQ like '%" + searchWordTemp + "' or userEmail='" + searchWordTemp + "')";
            }

            strSql = "select * from XabaraUser where 1=1" + ifStr + " order by " + orderBy + " desc";
            //Response.Write(strSql);
            //Response.End();
            lblCurrentPage.Text = sql.RepeaterDB(RepeaterList, strSql, "&keyWords=" + Server.UrlEncode(searchWordTemp) + "&level=" + levelID.ToString() + "&orderby=" + orderBy, 20, "page", "center", true);
        }
    }

    public string img(string str)
    {
        return f.picDisplay(str);
    }

    public string getM(string str)
    {
        string returnStr = string.Empty;
        if (Convert.ToDouble(str) > 0)
        {
            returnStr = rmb.format(str);
        }
        return returnStr;
    }

    public string getL(string num)
    {
        return u.level(num, "imgText");
    }

    public string getQQHtm(string qqStr)
    {
        return xabara.QQ(qqStr, "46");
    }

    public string getWWHtm(string wwStr)
    {
        return xabara.taobao(wwStr, "1");
    }

    public string getIPStr(string ip)
    {
        return "<span style=\"color:#7e7e7e;\">" + new ipAddress().addressCN(ip) + "</span>";
    }

    public string cityName(string p, string cc, string a)
    {
        string pca = string.Empty;
        if (xabara.isNum(a) > 0)
        {
            pca = c.cityName(p, cc, a);
        }

        return pca;
    }

    protected void SearchButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("?keyWords=" + Server.UrlEncode(searchWord.Text.Trim()) + "&level=" + levList.Text, true);
    }

    protected void levList_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("?keyWords=" + Server.UrlEncode(searchWord.Text.Trim()) + "&level=" + levList.Text, true);
    }
}
