⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin.aspx.cs

📁 物业管理系统
💻 CS
字号:
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 System.Data.SqlClient;


public partial class admin_Default2 : System.Web.UI.Page
{ 


    static string valpass="";//验证原密码是否正确
    BaseClass bc=new BaseClass();
    protected void Page_Load(object sender, EventArgs e)
    {
      
            if (Convert.ToString(Session["UID"]) == "")
            {
                Response.Redirect("login.aspx");

            }

            if (!IsPostBack)
            {
              this.bind();
            }
            
       

        
    }

    //初使时对数据进行绑定
    protected void bind()
    {
        string sqlstr="select * from admin";
        bc.ExecGridView(GridView1, sqlstr);
        
    
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        adduser.Visible = true;
    }

    //取消输入
    protected void Button1_Click(object sender, EventArgs e)
    {
        tbuser.Text = "";
        tbpass.Text = "";
        tbtwopass.Text = "";
        adduser.Visible = false;
    }

    //添加用户名
    protected void btnadduser_Click(object sender, EventArgs e)
    {

        try
        {
            if (val())
            {
                string sqlstr = "insert into admin(name,UID,PWD)values('" + tbname.Text + "','" + tbuser.Text + "','" + tbpass.Text + "')";
                
                if (bc.ExecSql(sqlstr))
                {
                    Response.Write("<script language=javascript>alert('用户名添加成功!');</script>");
                    adduser.Visible = false;
                    this.bind();
                    

                }
                else
                {
                    Response.Write("<script language=javascript>alert('添加失败,请重试!');</script>");
                    return;
                }
            }
            else
            {
                Response.Write("<script language=javascript>alert('用户名存在,请选择其它用户名!');</script>");
                return;
            }
        }
        finally
        {
             bc.Closeconn();
        }
       
    }


    //验证新的用户名是否存在
    protected bool val()
    {
        string conn = Convert.ToString(ConfigurationManager.ConnectionStrings["SmallHouseConn"]);

        SqlConnection sqlcon = new SqlConnection(conn);
        sqlcon.Open();
        string sqlstr = "select count(*) from admin where uid='" + tbuser.Text + "'";


        //Response.Write(sqlstr);
        SqlCommand scd = new SqlCommand(sqlstr, sqlcon);
        int count = Convert.ToInt32(scd.ExecuteScalar());

        //Response.Write(count);
        //Response.End();

        if (count <= 0)
        {

            return true;
        }
        else
        {

            return false;

        }
    }
    //gridview 数数绑定时执行
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {


            ((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#22dd22';this.Style.color='buttontext';this.Style.cursor='default';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';");
        }
    }
  
    
    ///修改密码

   












    //删除管理员帐号时执行

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       
        string uid = GridView1.DataKeys[e.RowIndex].Value.ToString();


        if (Session["UID"].ToString() != uid)
        {
            string sqlstr = "delete from admin where ID='" + uid + "'";
            //Response.Write(sqlstr);
            //Response.End();
            try
            {
                if (bc.ExecSql(sqlstr))
                {
                    Response.Write("<script>alert('删除管理员帐号成功!');</script>");
                    this.bind();
                }
                else
                {
                    Response.Write("<script>alert('操作失败,请重试!');</script>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('删除失败,失败原因:" + ex.Message.ToString() + "');</script>");
                return;
            }
        }
        else
        {
            Response.Write("<script>alert('管理员用不能删除自已');</script>");
            return;
        }


       

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -