Esempio n. 1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public OnLineTest.Model.Users DataRowToModel(DataRow row)
 {
     OnLineTest.Model.Users model = new OnLineTest.Model.Users();
     if (row != null)
     {
         if (row["UserId"] != null && row["UserId"].ToString() != "")
         {
             model.UserId = int.Parse(row["UserId"].ToString());
         }
         if (row["UserName"] != null)
         {
             model.UserName = row["UserName"].ToString();
         }
         if (row["UserPassword"] != null)
         {
             model.UserPassword = row["UserPassword"].ToString();
         }
         if (row["UserChineseName"] != null)
         {
             model.UserChineseName = row["UserChineseName"].ToString();
         }
         if (row["UserImageName"] != null)
         {
             model.UserImageName = row["UserImageName"].ToString();
         }
         if (row["UserEmail"] != null)
         {
             model.UserEmail = row["UserEmail"].ToString();
         }
         if (row["IsValidate"] != null && row["IsValidate"].ToString() != "")
         {
             if ((row["IsValidate"].ToString() == "1") || (row["IsValidate"].ToString().ToLower() == "true"))
             {
                 model.IsValidate = true;
             }
             else
             {
                 model.IsValidate = false;
             }
         }
         if (row["Tel"] != null)
         {
             model.Tel = row["Tel"].ToString();
         }
         if (row["UserScore"] != null && row["UserScore"].ToString() != "")
         {
             model.UserScore = int.Parse(row["UserScore"].ToString());
         }
         if (row["UserRegisterDatetime"] != null && row["UserRegisterDatetime"].ToString() != "")
         {
             model.UserRegisterDatetime = DateTime.Parse(row["UserRegisterDatetime"].ToString());
         }
         if (row["UserGroupId"] != null && row["UserGroupId"].ToString() != "")
         {
             model.UserGroupId = int.Parse(row["UserGroupId"].ToString());
         }
     }
     return(model);
 }
        public DataSet getLastContact(OnLineTest.Model.Users users)
        {
            DataSet ds  = new DataSet();
            string  sql = "select top(10) MessageTO,MessageFrom,u.UserId as messagetoid,u.UserName as messagetoname,u2.UserId as messagefromid,u2.UserName as messagefromname from Message_table as m left join Users as u on u.UserId=m.MessageTO left join Users as u2 on u2.UserId=m.MessageFrom  where MessageTO=@userid or MessageFrom=@userid   order by MessageSendTime desc";

            SqlParameter[] parm = { new SqlParameter("@userid", SqlDbType.Int) };
            parm[0].Value = users.UserId;
            ds            = DbHelperSQL.Query(sql, parm);
            return(ds);
        }
Esempio n. 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OnLineTest.Model.Users model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Users set ");
            strSql.Append("UserPassword=@UserPassword,");
            strSql.Append("UserChineseName=@UserChineseName,");
            strSql.Append("UserImageName=@UserImageName,");
            strSql.Append("UserEmail=@UserEmail,");
            strSql.Append("IsValidate=@IsValidate,");
            strSql.Append("Tel=@Tel,");
            strSql.Append("UserScore=@UserScore,");
            strSql.Append("UserRegisterDatetime=@UserRegisterDatetime,");
            strSql.Append("UserGroupId=@UserGroupId");
            strSql.Append(" where UserId=@UserId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserPassword",         SqlDbType.VarChar,   200),
                new SqlParameter("@UserChineseName",      SqlDbType.NVarChar,   20),
                new SqlParameter("@UserImageName",        SqlDbType.NVarChar,  100),
                new SqlParameter("@UserEmail",            SqlDbType.VarChar,    50),
                new SqlParameter("@IsValidate",           SqlDbType.Bit,         1),
                new SqlParameter("@Tel",                  SqlDbType.VarChar,    20),
                new SqlParameter("@UserScore",            SqlDbType.Int,         4),
                new SqlParameter("@UserRegisterDatetime", SqlDbType.DateTime),
                new SqlParameter("@UserGroupId",          SqlDbType.Int,         4),
                new SqlParameter("@UserId",               SqlDbType.Int,         4),
                new SqlParameter("@UserName",             SqlDbType.VarChar, 20)
            };
            parameters[0].Value  = model.UserPassword;
            parameters[1].Value  = model.UserChineseName;
            parameters[2].Value  = model.UserImageName;
            parameters[3].Value  = model.UserEmail;
            parameters[4].Value  = model.IsValidate;
            parameters[5].Value  = model.Tel;
            parameters[6].Value  = model.UserScore;
            parameters[7].Value  = model.UserRegisterDatetime;
            parameters[8].Value  = model.UserGroupId;
            parameters[9].Value  = model.UserId;
            parameters[10].Value = model.UserName;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(OnLineTest.Model.Users model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Users(");
            strSql.Append("UserName,UserPassword,UserChineseName,UserImageName,UserEmail,IsValidate,Tel,UserScore,UserRegisterDatetime,UserGroupId)");
            strSql.Append(" values (");
            strSql.Append("@UserName,@UserPassword,@UserChineseName,@UserImageName,@UserEmail,@IsValidate,@Tel,@UserScore,@UserRegisterDatetime,@UserGroupId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName",             SqlDbType.VarChar,    20),
                new SqlParameter("@UserPassword",         SqlDbType.VarChar,   200),
                new SqlParameter("@UserChineseName",      SqlDbType.NVarChar,   20),
                new SqlParameter("@UserImageName",        SqlDbType.NVarChar,  100),
                new SqlParameter("@UserEmail",            SqlDbType.VarChar,    50),
                new SqlParameter("@IsValidate",           SqlDbType.Bit,         1),
                new SqlParameter("@Tel",                  SqlDbType.VarChar,    20),
                new SqlParameter("@UserScore",            SqlDbType.Int,         4),
                new SqlParameter("@UserRegisterDatetime", SqlDbType.DateTime),
                new SqlParameter("@UserGroupId",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserName;
            parameters[1].Value = model.UserPassword;
            parameters[2].Value = model.UserChineseName;
            parameters[3].Value = model.UserImageName;
            parameters[4].Value = model.UserEmail;
            parameters[5].Value = model.IsValidate;
            parameters[6].Value = model.Tel;
            parameters[7].Value = model.UserScore;
            parameters[8].Value = model.UserRegisterDatetime;
            parameters[9].Value = model.UserGroupId;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OnLineTest.Model.Users GetModel(int UserId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UserId,UserName,UserPassword,UserChineseName,UserImageName,UserEmail,IsValidate,Tel,UserScore,UserRegisterDatetime,UserGroupId from Users ");
            strSql.Append(" where UserId=@UserId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId", SqlDbType.Int, 4)
            };
            parameters[0].Value = UserId;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }