Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(lostPropertyMngt.Model.userInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update userInfo set ");
            strSql.Append("userName=@userName,");
            strSql.Append("headImg=@headImg,");
            strSql.Append("relName=@relName,");
            strSql.Append("gender=@gender,");
            strSql.Append("stuNum=@stuNum,");
            strSql.Append("college=@college,");
            strSql.Append("password=@password,");
            strSql.Append("contact=@contact");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@userName", SqlDbType.NVarChar, 10),
                new SqlParameter("@headImg",  SqlDbType.NVarChar, 50),
                new SqlParameter("@relName",  SqlDbType.NVarChar,  5),
                new SqlParameter("@gender",   SqlDbType.NVarChar,  2),
                new SqlParameter("@stuNum",   SqlDbType.NVarChar, 10),
                new SqlParameter("@college",  SqlDbType.NVarChar, 20),
                new SqlParameter("@password", SqlDbType.VarChar,  20),
                new SqlParameter("@contact",  SqlDbType.VarChar,  11),
                new SqlParameter("@ID",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.userName;
            parameters[1].Value = model.headImg;
            parameters[2].Value = model.relName;
            parameters[3].Value = model.gender;
            parameters[4].Value = model.stuNum;
            parameters[5].Value = model.college;
            parameters[6].Value = model.password;
            parameters[7].Value = model.contact;
            parameters[8].Value = model.ID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public lostPropertyMngt.Model.userInfo DataRowToModel(DataRow row)
 {
     lostPropertyMngt.Model.userInfo model = new lostPropertyMngt.Model.userInfo();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["userName"] != null)
         {
             model.userName = row["userName"].ToString();
         }
         if (row["headImg"] != null)
         {
             model.headImg = row["headImg"].ToString();
         }
         if (row["relName"] != null)
         {
             model.relName = row["relName"].ToString();
         }
         if (row["gender"] != null)
         {
             model.gender = row["gender"].ToString();
         }
         if (row["stuNum"] != null)
         {
             model.stuNum = row["stuNum"].ToString();
         }
         if (row["college"] != null)
         {
             model.college = row["college"].ToString();
         }
         if (row["password"] != null)
         {
             model.password = row["password"].ToString();
         }
         if (row["contact"] != null)
         {
             model.contact = row["contact"].ToString();
         }
     }
     return(model);
 }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(lostPropertyMngt.Model.userInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into userInfo(");
            strSql.Append("userName,headImg,relName,gender,stuNum,college,password,contact)");
            strSql.Append(" values (");
            strSql.Append("@userName,@headImg,@relName,@gender,@stuNum,@college,@password,@contact)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@userName", SqlDbType.NVarChar, 10),
                new SqlParameter("@headImg",  SqlDbType.NVarChar, 50),
                new SqlParameter("@relName",  SqlDbType.NVarChar,  5),
                new SqlParameter("@gender",   SqlDbType.NVarChar,  2),
                new SqlParameter("@stuNum",   SqlDbType.NVarChar, 10),
                new SqlParameter("@college",  SqlDbType.NVarChar, 20),
                new SqlParameter("@password", SqlDbType.VarChar,  20),
                new SqlParameter("@contact",  SqlDbType.VarChar, 11)
            };
            parameters[0].Value = model.userName;
            parameters[1].Value = model.headImg;
            parameters[2].Value = model.relName;
            parameters[3].Value = model.gender;
            parameters[4].Value = model.stuNum;
            parameters[5].Value = model.college;
            parameters[6].Value = model.password;
            parameters[7].Value = model.contact;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public lostPropertyMngt.Model.userInfo GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,userName,headImg,relName,gender,stuNum,college,password,contact from userInfo ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

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

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