Exemplo n.º 1
0
        public bool Update(SystemUsers model, List <string> fileds, string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.AppendFormat("update {0} set ", model.GetType().Name);
            List <string>       filedsList   = new List <string>();
            List <SqlParameter> sqlParameter = new List <SqlParameter>();
            SqlParameter        Param        = new SqlParameter("@ID", SqlDbType.Int, 4);

            if (string.IsNullOrEmpty(sqlWhere))
            {
                Param.Value = model.ID;
                sqlParameter.Add(Param);
            }
            foreach (string filed in fileds)
            {
                filedsList.Add(string.Format("{0}=@{0}", filed));
                Param = new SqlParameter(string.Format("@{0}", filed), model.GetType().GetProperty(filed).GetValue(model, null));
                sqlParameter.Add(Param);
            }
            strSql.AppendFormat("{0}", string.Join(",", filedsList.ToArray()));
            if (string.IsNullOrEmpty(sqlWhere))
            {
                strSql.Append(" where ID=@ID ");
            }
            else
            {
                strSql.AppendFormat(" where 1=1 and {0} ", sqlWhere);
            }
            SqlParameter[] parameters = sqlParameter.ToArray();
            return(db.ExecNon(strSql.ToString(), parameters) > 0 ? true : false);
        }