예제 #1
0
        protected void sub_btn_ServerClick(object sender, EventArgs e)
        {
            //获取用户名和密码
            string username = UserName.Value;
            string pwd      = Pwd.Value;
            bool   tag      = true;

            if (username == "")
            {
                Response.Write("<script>alert('用户名不能为空!!!')</script>");
                tag = false;
            }
            else if (pwd == "")
            {
                Response.Write("<script>alert('密码不能为空!!!')</script>");
                tag = false;
            }
            if (tag)
            {
                AdminBLL admin = new AdminBLL();
                Adminor  a1    = admin.Login(username, pwd);
                if (a1 != null)
                {
                    Response.Redirect("index.aspx");
                }
                else
                {
                    Response.Write("<script>alert('用户名不存在或者密码错误!!!')</script>");
                }
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //接收参数
            int id = int.Parse(Request["id"]);

            if (id > 0)
            {
                admin = bll.adminsel(id);
                if (!IsPostBack)
                {
                    txtUserName.Value = admin.UserName;
                }
            }
        }
예제 #3
0
        //用户查询  按id查询
        public Adminor adminsel(int id)
        {
            string sql = "select * from Admin where Id=@id";

            SqlParameter[] sps =
            {
                new SqlParameter("@Id", id)
            };

            DataTable dt    = SqlHelper.ExeDataTable(sql, sps);
            Adminor   model = null;

            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];

                model = DataRowToModel(dr);
            }
            return(model);
        }
예제 #4
0
        public Adminor Login(string username, string pwd)
        {
            string sql = "select * from Admin where username=@username and password=@pwd";

            SqlParameter[] sps =
            {
                new SqlParameter("@username", username),
                new SqlParameter("@pwd",      pwd)
            };

            DataTable dt = SqlHelper.ExeDataTable(sql, sps);

            Adminor model = null;

            //如果查询后的这个结果表里面有值  说明登陆成功
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                model = DataRowToModel(dr);
            }
            return(model);
        }
예제 #5
0
        public Adminor DataRowToModel(DataRow dr)
        {
            Adminor model = new Adminor();

            if (dr["Id"] != DBNull.Value)
            {
                model.Id = Convert.ToInt32(dr["Id"]);
            }
            if (dr["username"] != DBNull.Value)
            {
                model.UserName = dr["username"].ToString();
            }
            if (dr["password"] != DBNull.Value)
            {
                model.PassWord = dr["password"].ToString();
            }
            if (dr["state"] != DBNull.Value)
            {
                model.State = Convert.ToInt32(dr["state"]);
            }
            return(model);
        }