Ejemplo n.º 1
0
        /// <summary>增加一条数据
        ///
        /// </summary>
        public int Add(mhqNetAPP.Model.User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [user](");
            strSql.Append("[creatdate], [username], [password], [face], [usertype], [phone], [qq], [email], [remark]  )");
            strSql.Append(" values (");
            strSql.Append("@creatdate, @username, @password, @face, @usertype, @phone, @qq, @email, @remark  )");
            strSql.Append(";select @@IDENTITY");
            MSSQLHelper h = new MSSQLHelper();

            h.CreateCommand(strSql.ToString());
            if (model.creatdate == null)
            {
                h.AddParameter("@creatdate", DBNull.Value);
            }
            else
            {
                h.AddParameter("@creatdate", model.creatdate);
            }
            if (model.username == null)
            {
                h.AddParameter("@username", DBNull.Value);
            }
            else
            {
                h.AddParameter("@username", model.username);
            }
            if (model.password == null)
            {
                h.AddParameter("@password", DBNull.Value);
            }
            else
            {
                h.AddParameter("@password", model.password);
            }
            if (model.face == null)
            {
                h.AddParameter("@face", DBNull.Value);
            }
            else
            {
                h.AddParameter("@face", model.face);
            }
            if (model.usertype == null)
            {
                h.AddParameter("@usertype", DBNull.Value);
            }
            else
            {
                h.AddParameter("@usertype", model.usertype);
            }
            if (model.phone == null)
            {
                h.AddParameter("@phone", DBNull.Value);
            }
            else
            {
                h.AddParameter("@phone", model.phone);
            }
            if (model.qq == null)
            {
                h.AddParameter("@qq", DBNull.Value);
            }
            else
            {
                h.AddParameter("@qq", model.qq);
            }
            if (model.email == null)
            {
                h.AddParameter("@email", DBNull.Value);
            }
            else
            {
                h.AddParameter("@email", model.email);
            }
            if (model.remark == null)
            {
                h.AddParameter("@remark", DBNull.Value);
            }
            else
            {
                h.AddParameter("@remark", model.remark);
            }

            int    result;
            string obj = h.ExecuteScalar();

            if (!int.TryParse(obj, out result))
            {
                return(0);
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>更新一条数据
        ///
        /// </summary>
        public bool Update(mhqNetAPP.Model.User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update [user] set ");
            strSql.Append("[creatdate]=@creatdate, [username]=@username, [password]=@password, [face]=@face, [usertype]=@usertype, [phone]=@phone, [qq]=@qq, [email]=@email, [remark]=@remark  ");
            strSql.Append(" where id=@id ");
            MSSQLHelper h = new MSSQLHelper();

            h.CreateCommand(strSql.ToString());
            if (model.id == null)
            {
                h.AddParameter("@id", DBNull.Value);
            }
            else
            {
                h.AddParameter("@id", model.id);
            }
            if (model.creatdate == null)
            {
                h.AddParameter("@creatdate", DBNull.Value);
            }
            else
            {
                h.AddParameter("@creatdate", model.creatdate);
            }
            if (model.username == null)
            {
                h.AddParameter("@username", DBNull.Value);
            }
            else
            {
                h.AddParameter("@username", model.username);
            }
            if (model.password == null)
            {
                h.AddParameter("@password", DBNull.Value);
            }
            else
            {
                h.AddParameter("@password", model.password);
            }
            if (model.face == null)
            {
                h.AddParameter("@face", DBNull.Value);
            }
            else
            {
                h.AddParameter("@face", model.face);
            }
            if (model.usertype == null)
            {
                h.AddParameter("@usertype", DBNull.Value);
            }
            else
            {
                h.AddParameter("@usertype", model.usertype);
            }
            if (model.phone == null)
            {
                h.AddParameter("@phone", DBNull.Value);
            }
            else
            {
                h.AddParameter("@phone", model.phone);
            }
            if (model.qq == null)
            {
                h.AddParameter("@qq", DBNull.Value);
            }
            else
            {
                h.AddParameter("@qq", model.qq);
            }
            if (model.email == null)
            {
                h.AddParameter("@email", DBNull.Value);
            }
            else
            {
                h.AddParameter("@email", model.email);
            }
            if (model.remark == null)
            {
                h.AddParameter("@remark", DBNull.Value);
            }
            else
            {
                h.AddParameter("@remark", model.remark);
            }

            return(h.ExecuteNonQuery());
        }