<%@ 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)
    {

      

        bool isreset = System.IO.File.Exists(Server.MapPath("reset.txt"));
        if (isreset)
        {
            Helper.Result(this, "请先删除install下的reset.txt文件");
            return;
        }
        
        
        
        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();
        
        
        System.IO.File.WriteAllText(Server.MapPath("reset.txt"), "1");

        Helper.Result(this, "操作成功","../default.aspx");
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        此工具用来重置管理员账户，将其密码设置为123456并将其加入管理员<br />
        <br />
        如果系统是集成AD的，请在下面输入AD里的用户账户，系统会将其加入helpdesk的管理员组。<br />
        <br />
    请输入管理员登陆名称<asp:TextBox runat="server" ID="txt_admin"    ></asp:TextBox> （密码为：123456）
        <br />
        <asp:Button ID="Button1" runat="server" Text="提交" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>
