Beispiel #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Light.Model.userinfo GetModel(int id)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select id, phone, email, qqid, weiboid, password, username, sex, gender, createtime, logincount, lastlogintime, userid, birthday, cityid, roleid, loginvalidate, faceurl, state  ");
            strSql.Append("  from userinfo ");
            strSql.Append(" where id=@id ");
                        MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32,10)			};
            parameters[0].Value = id;

            Light.Model.userinfo model=new Light.Model.userinfo();
            DataSet ds=DbHelperMySQL.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.phone= ds.Tables[0].Rows[0]["phone"].ToString();
                                                                                                                                model.email= ds.Tables[0].Rows[0]["email"].ToString();
                                                                                                                                model.qqid= ds.Tables[0].Rows[0]["qqid"].ToString();
                                                                                                                                model.weiboid= ds.Tables[0].Rows[0]["weiboid"].ToString();
                                                                                                                                model.password= ds.Tables[0].Rows[0]["password"].ToString();
                                                                                                                                model.username= ds.Tables[0].Rows[0]["username"].ToString();
                                                                                                                                model.sex= ds.Tables[0].Rows[0]["sex"].ToString();
                                                                                                                                model.gender= ds.Tables[0].Rows[0]["gender"].ToString();
                                                                                                                if(ds.Tables[0].Rows[0]["createtime"].ToString()!="")
                {
                    model.createtime=DateTime.Parse(ds.Tables[0].Rows[0]["createtime"].ToString());
                }
                                                                                                                                if(ds.Tables[0].Rows[0]["logincount"].ToString()!="")
                {
                    model.logincount=int.Parse(ds.Tables[0].Rows[0]["logincount"].ToString());
                }
                                                                                                                                if(ds.Tables[0].Rows[0]["lastlogintime"].ToString()!="")
                {
                    model.lastlogintime=DateTime.Parse(ds.Tables[0].Rows[0]["lastlogintime"].ToString());
                }
                                                                                                                                                model.userid= ds.Tables[0].Rows[0]["userid"].ToString();
                                                                                                                if(ds.Tables[0].Rows[0]["birthday"].ToString()!="")
                {
                    model.birthday=DateTime.Parse(ds.Tables[0].Rows[0]["birthday"].ToString());
                }
                                                                                                                                if(ds.Tables[0].Rows[0]["cityid"].ToString()!="")
                {
                    model.cityid=int.Parse(ds.Tables[0].Rows[0]["cityid"].ToString());
                }
                                                                                                                                if(ds.Tables[0].Rows[0]["roleid"].ToString()!="")
                {
                    model.roleid=int.Parse(ds.Tables[0].Rows[0]["roleid"].ToString());
                }
                                                                                                                                                model.loginvalidate= ds.Tables[0].Rows[0]["loginvalidate"].ToString();
                                                                                                                                model.faceurl= ds.Tables[0].Rows[0]["faceurl"].ToString();
                                                                                                                if(ds.Tables[0].Rows[0]["state"].ToString()!="")
                {
                    model.state=int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
                }

                return model;
            }
            else
            {
                return null;
            }
        }