using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Spaces;
using Spaces.Controls;
public partial class Manage_AdminUser : ManagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        UsersView.RowDeleting += new GridViewDeleteEventHandler(UsersView_RowDeleting);
        if (!IsPostBack)
            BindUsers();
    }

    void UsersView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label AdminID = UsersView.Rows[e.RowIndex].FindControl("AdminID") as Label;
        if (AdminID != null)
        {
            string sql = string.Format("DELETE FROM tbl_Admin WHERE AdminID={0}",AdminID.Text);
            SpacesDataProvider.Instance().ExecuteNonQuery(sql);
            BindUsers();
        }
    }

    private void BindUsers()
    {
        string sql = @"select * from tbl_Admin";
        UsersView.DataSource = SpacesDataProvider.Instance().GetDataView(sql);
        UsersView.DataBind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string username = txtUsername.Text;
        string password = txtPassword.Text;
        password = Des.Encrypt(password,"xiaoxiao");
        string sql = string.Format(@"INSERT INTO tbl_Admin([Username], [Password])
VALUES('{0}','{1}')",Utils.SqlInput(username),password);
        if(Config.GetConfig().DefaultProvider=="MySql")
            sql = string.Format(@"INSERT INTO tbl_Admin(`Username`, `Password`)
VALUES('{0}','{1}')", Utils.SqlInput(username), password);
        SpacesDataProvider.Instance().ExecuteNonQuery(sql);
        BindUsers();
    }
}
