Exemplo n.º 1
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="cmd">Command对象</param>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>影响的记录行数</returns>
 internal static int ExcuteDeleteCommand(SqlCommand cmd, JCUser jCUser)
 {
     cmd.Parameters.Clear();
     cmd.CommandText = "delete from JC_User where UserID=@UserID";
     //从实体中取出值放入Command的参数列表
     cmd.Parameters.Add(new SqlParameter("@UserID", jCUser.UserID));
     return cmd.ExecuteNonQuery();
 }
Exemplo n.º 2
0
 /// <summary>
 /// 不使用事务的删除方法
 /// </summary>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>影响的记录行数</returns>
 internal static int Delete(JCUser jCUser)
 {
     using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
     {
         conn.Open();
         using (SqlCommand cmd = conn.CreateCommand())
         {
             return ExcuteDeleteCommand(cmd, jCUser);
         }
     }
 }
Exemplo n.º 3
0
        private void RegisterUser()
        {
            try
            {
                JCUser user = new JCUser();
                #region 验证
                string regNickName = conn.Request["regNickName"];
                if (string.IsNullOrEmpty(regNickName))
                {
                    json.success = false;
                    json.msg = "请输入昵称";
                    return;
                }

                string regUserName = conn.Request["regUserName"];
                if (string.IsNullOrEmpty(regUserName))
                {
                    json.success = false;
                    json.msg = "请输入账号";
                    return;
                }
                if (regUserName.Length < 6)
                {
                    json.success = false;
                    json.msg = "长度不得小于6";
                    return;
                }
                if (regUserName.Length > 100)
                {
                    json.success = false;
                    json.msg = "长度不得大于100";
                    return;
                }

                string regPassword = conn.Request["regPassword"];
                if (string.IsNullOrEmpty(regPassword))
                {
                    json.success = false;
                    json.msg = "请输入密码";
                    return;
                }
                if (regPassword.Length < 8)
                {
                    json.success = false;
                    json.msg = "长度不得小于8";
                    return;
                }
                if (regPassword.Length > 100)
                {
                    json.success = false;
                    json.msg = "长度不得大于100";
                    return;
                }

                string regPasswordCheck = conn.Request["regPasswordCheck"];
                if (string.IsNullOrEmpty(regPasswordCheck))
                {
                    json.success = false;
                    json.msg = "请输入密码确认";
                    return;
                }

                if (regPassword != regPasswordCheck)
                {
                    json.success = false;
                    json.msg = "两次密码不一致";
                    return;
                }

                string regEmail = conn.Request["regEmail"];
                if (string.IsNullOrEmpty(regEmail))
                {
                    json.success = false;
                    json.msg = "请输入邮箱";
                    return;
                }

                if (!Common.Helper.Common.IsValidEmail(regEmail))
                {
                    json.success = false;
                    json.msg = "邮箱格式不正确";
                    return;
                }

               // BJCUser.Select();
                #endregion

                bool isExist = BJCUser.Select("UserName=@UserName", new ParameterList("@UserName", regUserName)).Count > 0;

                if(isExist)
                {
                    json.success = false;
                    json.msg = "账号已存在,请重新输入";
                    return;
                }

                user.UserName = regUserName;
                user.NickName = regNickName;
                user.PassWord= Common.Helper.Common.GetSHA1EnryptStr(regPassword);
                user.Email = regEmail;
                user.CreateTime = DateTime.Now;
                Guid tempGuid= BJCUser.Insert(user);

                if (tempGuid != new Guid())
                {
                    json.success = true;
                    json.msg = "新增成功";
                }
                else
                {
                    json.success = false;
                    json.msg = "新增失败";
                }
            }
            catch (Exception e)
            {
                json.success = false;
                json.msg = e.Message;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 插入实体
 /// </summary>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>标识列值或影响的记录行数</returns>
 public static Guid Insert(JCUser jCUser)
 {
     return DJCUser.Insert(jCUser);
 }
Exemplo n.º 5
0
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>影响的记录行数</returns>
 public static int Delete(JCUser jCUser)
 {
     return DJCUser.Delete(jCUser);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 更新实体
 /// </summary>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>影响的记录行数</returns>
 public static int Update(JCUser jCUser)
 {
     return DJCUser.Update(jCUser);
 }
Exemplo n.º 7
0
 /// <summary>
 /// 从DataReader中取出值生成实体对象
 /// </summary>
 /// <param name="searcher">查询对象</param>
 /// <returns>过滤条件字符串</returns>
 private static JCUser DataReaderToEntity(SqlDataReader dr)
 {
     JCUser entity = new JCUser ();
     if(dr["UserID"]!=System.DBNull.Value)
     {
         Guid tempGuid = new Guid();Guid.TryParse(dr["UserID"].ToString(),out tempGuid);entity.UserID = tempGuid;;
     }
     if(dr["UserName"]!=System.DBNull.Value)
     {
         entity.UserName=dr["UserName"].ToString();
     }
     if(dr["PassWord"]!=System.DBNull.Value)
     {
         entity.PassWord=dr["PassWord"].ToString();
     }
     if(dr["NickName"]!=System.DBNull.Value)
     {
         entity.NickName=dr["NickName"].ToString();
     }
     if(dr["TrueName"]!=System.DBNull.Value)
     {
         entity.TrueName=dr["TrueName"].ToString();
     }
     if(dr["Email"]!=System.DBNull.Value)
     {
         entity.Email=dr["Email"].ToString();
     }
     if(dr["Phone"]!=System.DBNull.Value)
     {
         entity.Phone=dr["Phone"].ToString();
     }
     if(dr["QQ"]!=System.DBNull.Value)
     {
         entity.QQ=dr["QQ"].ToString();
     }
     if(dr["CreateTime"]!=System.DBNull.Value)
     {
         entity.CreateTime=Convert.ToDateTime(dr["CreateTime"]);
     }
     if(dr["LastLoginTime"]!=System.DBNull.Value)
     {
         entity.LastLoginTime=Convert.ToDateTime(dr["LastLoginTime"]);
     }
     if(dr["Birthday"]!=System.DBNull.Value)
     {
         entity.Birthday=Convert.ToDateTime(dr["Birthday"]);
     }
     return entity;
 }
Exemplo n.º 8
0
 /// <summary>
 /// 使用事务的更新方法
 /// </summary>
 /// <param name="connection">实现共享Connection的对象</param>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>影响的记录行数</returns>
 internal static int Update(Connection connection,JCUser jCUser)
 {
     return ExcuteUpdateCommand(connection.Command, jCUser);
 }
Exemplo n.º 9
0
 /// <summary>
 /// 使用事务的插入方法
 /// </summary>
 /// <param name="connection">实现共享Connection的对象</param>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>标识列值或影响的记录行数</returns>
 internal static Guid Insert(Connection connection,JCUser jCUser)
 {
     return Insert(connection.Command, jCUser);
 }
Exemplo n.º 10
0
 /// <summary>
 /// 不使用事务的插入方法
 /// </summary>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>标识列值或影响的记录行数</returns>
 internal static Guid Insert(JCUser jCUser)
 {
     using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
     {
         conn.Open();
         using (SqlCommand cmd = conn.CreateCommand())
         {
             return Insert(cmd, jCUser);
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cmd">Command对象</param>
        /// <param name="jCUser">实体类对象</param>
        /// <returns>标识列值或影响的记录行数</returns>
        internal static Guid Insert(SqlCommand cmd, JCUser jCUser)
        {
            cmd.Parameters.Clear();
            cmd.CommandText = "insert into JC_User (UserName,PassWord,NickName,TrueName,Email,Phone,QQ,CreateTime,LastLoginTime,Birthday) output inserted.UserID values (@UserName,@PassWord,@NickName,@TrueName,@Email,@Phone,@QQ,@CreateTime,@LastLoginTime,@Birthday)";
            //从实体中取出值放入Command的参数列表
            cmd.Parameters.Add(new SqlParameter("@UserID",jCUser.UserID==null?(object)DBNull.Value:(object)jCUser.UserID));
            cmd.Parameters.Add(new SqlParameter("@UserName",jCUser.UserName==null?(object)DBNull.Value:(object)jCUser.UserName));
            cmd.Parameters.Add(new SqlParameter("@PassWord",jCUser.PassWord==null?(object)DBNull.Value:(object)jCUser.PassWord));
            cmd.Parameters.Add(new SqlParameter("@NickName",jCUser.NickName==null?(object)DBNull.Value:(object)jCUser.NickName));
            cmd.Parameters.Add(new SqlParameter("@TrueName",jCUser.TrueName==null?(object)DBNull.Value:(object)jCUser.TrueName));
            cmd.Parameters.Add(new SqlParameter("@Email",jCUser.Email==null?(object)DBNull.Value:(object)jCUser.Email));
            cmd.Parameters.Add(new SqlParameter("@Phone",jCUser.Phone==null?(object)DBNull.Value:(object)jCUser.Phone));
            cmd.Parameters.Add(new SqlParameter("@QQ",jCUser.QQ==null?(object)DBNull.Value:(object)jCUser.QQ));
            cmd.Parameters.Add(new SqlParameter("@CreateTime",jCUser.CreateTime.HasValue?(object)jCUser.CreateTime.Value:(object)DBNull.Value));
            cmd.Parameters.Add(new SqlParameter("@LastLoginTime",jCUser.LastLoginTime.HasValue?(object)jCUser.LastLoginTime.Value:(object)DBNull.Value));

            cmd.Parameters.Add(new SqlParameter("@Birthday",jCUser.Birthday.HasValue?(object)jCUser.Birthday.Value:(object)DBNull.Value));

            return Guid.Parse(cmd.ExecuteScalar().ToString());
        }
Exemplo n.º 12
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="cmd">Command对象</param>
 /// <param name="jCUser">实体类对象</param>
 /// <returns>影响的记录行数</returns>
 internal static int ExcuteUpdateCommand(SqlCommand cmd, JCUser jCUser)
 {
     cmd.CommandText = "update JC_User set UserID=@UserID,UserName=@UserName,PassWord=@PassWord,NickName=@NickName,TrueName=@TrueName,Email=@Email,Phone=@Phone,QQ=@QQ,CreateTime=@CreateTime,LastLoginTime=@LastLoginTime,Birthday=@Birthday where UserID=@UserID";
     //从实体中取出值放入Command的参数列表
     cmd.Parameters.Add(new SqlParameter("@UserName",jCUser.UserName==null?(object)DBNull.Value:(object)jCUser.UserName));
     cmd.Parameters.Add(new SqlParameter("@PassWord",jCUser.PassWord==null?(object)DBNull.Value:(object)jCUser.PassWord));
     cmd.Parameters.Add(new SqlParameter("@NickName",jCUser.NickName==null?(object)DBNull.Value:(object)jCUser.NickName));
     cmd.Parameters.Add(new SqlParameter("@TrueName",jCUser.TrueName==null?(object)DBNull.Value:(object)jCUser.TrueName));
     cmd.Parameters.Add(new SqlParameter("@Email",jCUser.Email==null?(object)DBNull.Value:(object)jCUser.Email));
     cmd.Parameters.Add(new SqlParameter("@Phone",jCUser.Phone==null?(object)DBNull.Value:(object)jCUser.Phone));
     cmd.Parameters.Add(new SqlParameter("@QQ",jCUser.QQ==null?(object)DBNull.Value:(object)jCUser.QQ));
     cmd.Parameters.Add(new SqlParameter("@CreateTime",jCUser.CreateTime.HasValue?(object)jCUser.CreateTime.Value:(object)DBNull.Value));
     cmd.Parameters.Add(new SqlParameter("@LastLoginTime",jCUser.LastLoginTime.HasValue?(object)jCUser.LastLoginTime.Value:(object)DBNull.Value));
     cmd.Parameters.Add(new SqlParameter("@Birthday",jCUser.Birthday.HasValue?(object)jCUser.Birthday.Value:(object)DBNull.Value));
     cmd.Parameters.Add(new SqlParameter("@UserID", jCUser.UserID));
     return cmd.ExecuteNonQuery();
 }