示例#1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public WebApi_Model.T_User_BaseInfo DataRowToModel(DataRow row)
 {
     WebApi_Model.T_User_BaseInfo model = new WebApi_Model.T_User_BaseInfo();
     if (row != null)
     {
         if (row["UID"] != null && row["UID"].ToString() != "")
         {
             model.UID = int.Parse(row["UID"].ToString());
         }
         if (row["Tel"] != null)
         {
             model.Tel = row["Tel"].ToString();
         }
         if (row["Nickname"] != null)
         {
             model.Nickname = row["Nickname"].ToString();
         }
         if (row["HeadImg"] != null)
         {
             model.HeadImg = row["HeadImg"].ToString();
         }
         if (row["Sex"] != null && row["Sex"].ToString() != "")
         {
             model.Sex = int.Parse(row["Sex"].ToString());
         }
         if (row["Age"] != null && row["Age"].ToString() != "")
         {
             model.Age = int.Parse(row["Age"].ToString());
         }
     }
     return(model);
 }
示例#2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WebApi_Model.T_User_BaseInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into T_User(");
            strSql.Append("Tel,Nickname,HeadImg,Sex,Age)");
            strSql.Append(" values (");
            strSql.Append("@Tel,@Nickname,@HeadImg,@Sex,@Age)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Tel",      SqlDbType.NVarChar, 11),
                new SqlParameter("@Nickname", SqlDbType.NVarChar, 50),
                new SqlParameter("@HeadImg",  SqlDbType.NVarChar, 50),
                new SqlParameter("@Sex",      SqlDbType.Int,       4),
                new SqlParameter("@Age",      SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Tel;
            parameters[1].Value = model.Nickname;
            parameters[2].Value = model.HeadImg;
            parameters[3].Value = model.Sex;
            parameters[4].Value = model.Age;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
示例#3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WebApi_Model.T_User_BaseInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_User set ");
            strSql.Append("Tel=@Tel,");
            strSql.Append("Nickname=@Nickname,");
            strSql.Append("HeadImg=@HeadImg,");
            strSql.Append("Sex=@Sex,");
            strSql.Append("Age=@Age");
            strSql.Append(" where UID=@UID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Tel",      SqlDbType.NVarChar, 11),
                new SqlParameter("@Nickname", SqlDbType.NVarChar, 50),
                new SqlParameter("@HeadImg",  SqlDbType.NVarChar, 50),
                new SqlParameter("@Sex",      SqlDbType.Int,       4),
                new SqlParameter("@Age",      SqlDbType.Int,       4),
                new SqlParameter("@UID",      SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Tel;
            parameters[1].Value = model.Nickname;
            parameters[2].Value = model.HeadImg;
            parameters[3].Value = model.Sex;
            parameters[4].Value = model.Age;
            parameters[5].Value = model.UID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebApi_Model.T_User_BaseInfo GetModel(int UID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UID,Tel,Nickname,HeadImg,Sex,Age from T_User ");
            strSql.Append(" where UID=@UID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UID", SqlDbType.Int, 4)
            };
            parameters[0].Value = UID;

            WebApi_Model.T_User_BaseInfo model = new WebApi_Model.T_User_BaseInfo();
            DataSet ds = DBHelper.Query(strSql.ToString(), parameters);

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