protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["UserInfo"] != null)
     {
         var abc = Session["UserInfo"];
         UserInfo = (BookShop.Model.User)Session["UserInfo"];
     }
 }
Beispiel #2
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void DeleteModel(BookShop.Model.User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from Users ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Id;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BookShop.Model.User model, out string msg)
        {
            int isSuccess = -1;

            if (ValidateUserName(model.LoginId))
            {
                msg = "此用户名已经注册!!";
            }
            else
            {
                isSuccess = dal.Add(model);
                msg       = "注册成功!!";
            }
            return(isSuccess);
        }
Beispiel #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string Id       = textID.Text;
            string userName = textUserName.Text.Trim();
            string password = textPassword.Text;

            BookShop.BLL.UserManager mgr  = new BookShop.BLL.UserManager();
            BookShop.Model.User      user = mgr.Login(Id, userName, password);
            if (user == null)
            {
                MessageBox.Show("登陆失败!");
            }

            if (user != null)//登录成功跳转主界面
            {
                staticInf.user = user;
                主界面 fm = new 主界面();
                fm.ShowDialog();
            }
        }
Beispiel #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.User GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,LoginId,LoginPwd,Name,Address,Phone,Mail,UserStateId from Users ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            BookShop.Model.User model = new BookShop.Model.User();
            DataSet             ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.LoginId  = ds.Tables[0].Rows[0]["LoginId"].ToString();
                model.LoginPwd = ds.Tables[0].Rows[0]["LoginPwd"].ToString();
                model.Name     = ds.Tables[0].Rows[0]["Name"].ToString();
                model.Address  = ds.Tables[0].Rows[0]["Address"].ToString();
                model.Phone    = ds.Tables[0].Rows[0]["Phone"].ToString();
                model.Mail     = ds.Tables[0].Rows[0]["Mail"].ToString();

                if (ds.Tables[0].Rows[0]["UserStateId"].ToString() != "")
                {
                    //帮你再查询一次数据库 给对象的属性 也赋值上就一个最简单 关系 和对象 的映射上了。
                    int UserStateId = int.Parse(ds.Tables[0].Rows[0]["UserStateId"].ToString());
                    model.UserState = userStateServices.GetModel(UserStateId);
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 根据用户的邮箱找一个人
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        public Model.User GetUserByMail(string mail)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,LoginId,LoginPwd,Name,Address,Phone,Mail,UserStateId from Users ");
            strSql.Append(" where Mail=@Mail ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Mail", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = mail;

            BookShop.Model.User model = new BookShop.Model.User();
            DataSet             ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.LoginId  = ds.Tables[0].Rows[0]["LoginId"].ToString();
                model.LoginPwd = ds.Tables[0].Rows[0]["LoginPwd"].ToString();
                model.Name     = ds.Tables[0].Rows[0]["Name"].ToString();
                model.Address  = ds.Tables[0].Rows[0]["Address"].ToString();
                model.Phone    = ds.Tables[0].Rows[0]["Phone"].ToString();
                model.Mail     = ds.Tables[0].Rows[0]["Mail"].ToString();

                if (ds.Tables[0].Rows[0]["UserStateId"].ToString() != "")
                {
                    int UserStateId = int.Parse(ds.Tables[0].Rows[0]["UserStateId"].ToString());
                    model.UserState = userStateServices.GetModel(UserStateId);
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BookShop.Model.User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Users(");
            strSql.Append("LoginId,LoginPwd,Name,Address,Phone,Mail,UserStateId)");
            strSql.Append(" values (");
            strSql.Append("@LoginId,@LoginPwd,@Name,@Address,@Phone,@Mail,@UserStateId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@LoginId",     SqlDbType.NVarChar,  50),
                new SqlParameter("@LoginPwd",    SqlDbType.NVarChar,  50),
                new SqlParameter("@Name",        SqlDbType.NVarChar,  50),
                new SqlParameter("@Address",     SqlDbType.NVarChar, 200),
                new SqlParameter("@Phone",       SqlDbType.NVarChar, 100),
                new SqlParameter("@Mail",        SqlDbType.NVarChar, 100),
                new SqlParameter("@UserStateId", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.LoginId;
            parameters[1].Value = model.LoginPwd;
            parameters[2].Value = model.Name;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Phone;
            parameters[5].Value = model.Mail;
            parameters[6].Value = model.UserState.Id;


            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        private void btnRegister_Click(object sender, EventArgs e)
        {
            string userName = textUserName.Text.Trim();
            string password = textPassword.Text;

            if (password.Length > 8)
            {
                MessageBox.Show("密码格式错误!密码长度最长不超过8。请重新输入!");
            }
            else
            {
                BookShop.Model.User      user = new BookShop.Model.User();
                BookShop.BLL.UserManager mgr  = new BookShop.BLL.UserManager();
                user = mgr.Register(userName, password);
                if (user == null)
                {
                    MessageBox.Show("注册失败");
                }
                else
                {
                    MessageBox.Show("注册成功!欢迎" + user.UserName + "!请记住您的ID:" + user.ID);
                }
            }
        }