Ejemplo n.º 1
0
        //表Marketing..tbl_ArticleNewList相关操作(增,删,改,查)
        public List <ArticleNewList> SelectArticleNewList(ArticleNewList modelValue)
        {
            string strSql = @"SELECT * FROM [Marketing].[dbo].[tbl_ArticleNewList] with (nolock) Where 1=1 {0}";

            StringBuilder strSqlWhere             = new StringBuilder();
            Dictionary <string, object> dicParams = new Dictionary <string, object>();

            if (modelValue.Id > 0)
            {
                dicParams.Add("Id", modelValue.Id);
            }
            if (modelValue.ArticleId > 0)
            {
                dicParams.Add("ArticleId", modelValue.ArticleId);
            }
            if (!string.IsNullOrEmpty(modelValue.ArticleUrl))
            {
                dicParams.Add("ArticleUrl", modelValue.ArticleUrl);
            }
            if (!string.IsNullOrEmpty(modelValue.ProductId))
            {
                dicParams.Add("ProductId", modelValue.ProductId);
            }
            if (modelValue.Type > 0)
            {
                dicParams.Add("Type", modelValue.Type);
            }
            if (DateTime.Compare(modelValue.CreateTime, DateTime.MinValue) > 0)
            {
                dicParams.Add("CreateTime", modelValue.CreateTime);
            }
            if (!string.IsNullOrEmpty(modelValue.Field_1))
            {
                dicParams.Add("Field_1", modelValue.Field_1);
            }
            if (!string.IsNullOrEmpty(modelValue.Field_2))
            {
                dicParams.Add("Field_2", modelValue.Field_2);
            }
            if (!string.IsNullOrEmpty(modelValue.Field_3))
            {
                dicParams.Add("Field_3", modelValue.Field_3);
            }
            if (!string.IsNullOrEmpty(modelValue.Field_4))
            {
                dicParams.Add("Field_4", modelValue.Field_4);
            }
            SqlParameter[] sqlParams = new SqlParameter[dicParams.Count];
            for (int i = 0; i < dicParams.Count; i++)
            {
                var dicKey   = dicParams.ElementAt(i).Key;
                var dicValue = dicParams.ElementAt(i).Value;
                sqlParams[i] = new SqlParameter("@" + dicKey, dicValue);
                strSqlWhere.AppendFormat(" AND {0} = @{0} ", dicKey);
            }

            strSql = string.Format(strSql, strSqlWhere.ToString());
            Func <SqlConnection, List <ArticleNewList> > action = (connection) => DalArticle.SelectArticleNewList(connection, strSql.ToString(), sqlParams);

            return(dbManager.Execute(action));
        }