<%@ Page Language="C#" AutoEventWireup="true"  %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        
        string sql = @"
if(not exists(select * from users_users where username=@username))
begin
 insert into users_users(username,Password)values(@username,'CE-0B-FD-15-05-9B-68-D6-76-88-88-4D-7A-3D-3E-8C')
end
else
begin
update users_users set Password='CE-0B-FD-15-05-9B-68-D6-76-88-88-4D-7A-3D-3E-8C' where username=@username
end

declare @uid int 
select @uid=uid from users_users where username=@username

if(not exists(select * from users_usersinroles where  uid=@uid and rolename='administrators'))
begin
insert into users_usersinroles(uid,rolename)values(@uid,'administrators')
end
"; string con = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connectionstring"].ToString();
        SqlCommand cmd = new SqlCommand(sql);
        SqlConnection c = new SqlConnection(con);
        cmd.Connection = c;
        cmd.Parameters.AddWithValue("@username", txt_admin.Text);
        c.Open();
        cmd.ExecuteNonQuery();
        c.Close();
             
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Helpdesk.BLL.HelpdeskHelper.EnableResetPassword())
        {
            Helper.Result(this, "系统管理员禁用了重置密码功能，要启用，请将app_data/too.xml里的enableResetPassword设置为1");
            Button1.Enabled = false;
            return;
        }
        
        
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="  font-size:12px; font-family:Verdana ">
    <form id="form1" runat="server">
    <div>
        此工具用来重置管理员账户，并将其加入管理员<br />
        <br />
        **如果系统是集成AD的，请在下面输入AD里的用户账户**,集成AD情况下，下面的密码无效** <br />
        <br />
   
    管理员名称<asp:TextBox runat="server" ID="txt_admin"    Text="admin"  ></asp:TextBox>
      重置密码：<asp:TextBox runat="server" ID="txt_pwd"  Enabled="false"  Text="123456"  ></asp:TextBox>

       <asp:Button ID="Button1" runat="server" Text="提交" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>
