using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using xabaraCOM;

public partial class webXabara_adminUser_userAdd : System.Web.UI.Page
{
    admin a = new admin();
    classify c = new classify();
    sqlServer sql = new sqlServer();
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check("|admins|");
        if (!IsPostBack)
        {
            c.bindingDropDownList("all", false, 0, "city", cityID);
            c.bindingDropDownList("all", false, 0, "group", groupID);
            c.bindingDropDownList("all", false, 0, "class", classID);

            regExpression reg = new regExpression();
            adminIDRegularExpressionValidator.ValidationExpression = reg.userID(2, 20);
            adminIDRegularExpressionValidator.ErrorMessage = reg.userIDError(2, 20);
            adminNameRegularExpressionValidator.ValidationExpression = reg.chinese;
            adminNameRegularExpressionValidator.ErrorMessage = reg.chineseError;
            adminPWRegularExpressionValidator.ValidationExpression = reg.passWord(6, 20);
            adminPWRegularExpressionValidator.ErrorMessage = reg.passWordError(6, 20);
        }
    }

    protected void addAdmin_Click(object sender, EventArgs e)
    {
        string adminIDTemp = adminID.Text.Trim().ToLower();
        string strSql = "select * from AdminUser where userID='" + adminIDTemp + "'";
        if (sql.getDataTable(strSql).Rows.Count > 0)
        {
            js.div(false, "", "text", "已存在该管理员！", 300, 0, "", "");
        }
        else
        {
            string dimStr = "@UserId,@UserName,@UserPW,@SessionError,@loginFlag,@LoginNum,@RegDate,@LoginDate,@LoginIP,@classID,@postIF,@cityID,@groupID";

            string[] strValue = new string[15];
            strValue[0] = adminIDTemp;
            strValue[1] = adminName.Text.Trim();
            strValue[2] = xabara.md5(adminPW.Text.Trim());
            strValue[3] = "xabara.com";
            strValue[4] = "1";
            strValue[5] = "0";
            strValue[6] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            strValue[7] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            strValue[8] = new ipAddress().address();
            strValue[9] = classID.Text;
            strValue[10] = postIF.Text;
            strValue[11] = cityID.Text;
            strValue[12] = groupID.Text;

            if (sql.add("AdminUser", dimStr, strValue).Equals("发布成功"))
            {
                sql.log(a.uid, "admin", "添加管理员：" + adminIDTemp);
                js.div(false, "", "text", "添加管理员成功！<br />请对 " + adminName.Text.Trim() + " 进行权限设置后才可以正常登陆！", 300, 0, "userPopedom.aspx?page=" + Request.QueryString["page"] + "&id=" + adminIDTemp, "goto");
            }
            else
            {
                js.div(false, "", "text", "添加管理员失败！", 300, 0, "", "");
            }
        }
    }
}
