コード例 #1
0
        public static ArticleDto GetOneArticleDto(string table,string strwhere)
        {
            ArticleDto articleDto=new ArticleDto();

            articleDto = ArticleDal.GetOneArticle(table, strwhere);

            return articleDto;
        }
コード例 #2
0
        public static void AddArticle(ArticleDto articleDto)
        {
            SqlParameter[] arParames = ArticleDal.getParameters(articleDto);
            SqlConnection myconn = new SqlConnection(CommonDal.ConnectionString);
            try
            {
                SqlHelper.ExecuteNonQuery(myconn, CommandType.StoredProcedure, "CreateArticle", arParames);
             }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {

                myconn.Close();
                myconn.Dispose();
            }
        }
コード例 #3
0
        public ActionResult ArticleInsert(ArticleAddViewModel model)
        {
            ArticleDto articleDto = new ArticleDto();

            articleDto.ArticleTitle= model.ArticleTitle;
            articleDto.ArticleImg=model.ArticleImg;
            articleDto.ArticleContent=model.ArticleContent;
            articleDto.ArticleInfo=model.ArticleInfo ;

            articleDto.ArticleClass=model.ArticleClass;
            articleDto.ArticleTop = model.ArticleTop;
            articleDto.ArticleHot = model.ArticleHot;

            articleDto.ArticleImportant = model.ArticleImportant;
            articleDto.ArticleDateTime = System.DateTime.Now;

            ArticleBll.AddArticle(articleDto);

            return RedirectTo("/Article/ArticleIndex", "文章添加成功了");
               // return RedirectToAction("ArticleIndex");
        }
コード例 #4
0
        public static List<ArticleDto> GetArticleList(string strwhere)
        {
            List<ArticleDto> articlelist = new List<ArticleDto>();

            SqlParameter[] arParames = new SqlParameter[2];
            arParames[0] = new SqlParameter("@table ", SqlDbType.VarChar, 200);
            arParames[0].Value = "QxsqArticle";

            arParames[1] = new SqlParameter("@Where ", SqlDbType.VarChar, 8000);
            arParames[1].Value = strwhere;
            SqlConnection myconn = new SqlConnection(CommonDal.ConnectionString);
            try
            {
            DataTable dt = null;
            DataSet ds = SqlHelper.ExecuteDataset(myconn, CommandType.StoredProcedure, "getModelByWhere", arParames);
            dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                ArticleDto ArticleDto = new ArticleDto();

                ArticleDto = ArticleDal.getDataRowToArticleDto(dr);

                articlelist.Add(ArticleDto);

            }

            return articlelist;
             }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {

                myconn.Close();
                myconn.Dispose();
            }
        }
コード例 #5
0
 public static void UpdateArticleDto(ArticleDto articleDto)
 {
     ArticleDal.UpdateArticle(articleDto);
 }
コード例 #6
0
 public static void AddArticle(ArticleDto articleDto)
 {
     ArticleDal.AddArticle(articleDto);
 }
コード例 #7
0
        private static SqlParameter[] getParameters(ArticleDto articleDto)
        {
            SqlParameter[] arParames = new SqlParameter[10];

            arParames[0] = new SqlParameter("@ArticleId", SqlDbType.Int);
            arParames[0].Value = articleDto.ArticleId;

            arParames[1] = new SqlParameter("@ArticleTitle", SqlDbType.VarChar, 500);
            arParames[1].Value = articleDto.ArticleTitle;

            arParames[2] = new SqlParameter("@ArticleClass", SqlDbType.VarChar, 500);
            arParames[2].Value = articleDto.ArticleClass;

            arParames[3] = new SqlParameter("@ArticleImg", SqlDbType.VarChar, 500);
            arParames[3].Value = articleDto.ArticleImg;

            arParames[4] = new SqlParameter("@ArticleContent", SqlDbType.Text);
            arParames[4].Value = articleDto.ArticleContent;

            arParames[5] = new SqlParameter("@ArticleDateTime", SqlDbType.DateTime);
            arParames[5].Value = articleDto.ArticleDateTime;

            arParames[6] = new SqlParameter("@ArticleTop", SqlDbType.Bit);
            arParames[6].Value = articleDto.ArticleTop;

            arParames[7] = new SqlParameter("@ArticleHot", SqlDbType.Bit);
            arParames[7].Value = articleDto.ArticleHot;

            arParames[8] = new SqlParameter("@ArticleImportant", SqlDbType.Bit);
            arParames[8].Value = articleDto.ArticleImportant;

            arParames[9] = new SqlParameter("@ArticleInfo", SqlDbType.Text);
            arParames[9].Value = articleDto.ArticleInfo;

            return arParames;
        }
コード例 #8
0
        private static ArticleDto getDataRowToArticleDto(DataRow dr)
        {
            ArticleDto articleDto = new ArticleDto();

            articleDto.ArticleId = int.Parse(dr["ArticleId"].ToString());
            articleDto.ArticleTitle = dr["ArticleTitle"].ToString();
            articleDto.ArticleClass = dr["ArticleClass"].ToString();
            articleDto.ArticleImg = dr["ArticleImg"].ToString();

            articleDto.ArticleContent = dr["ArticleContent"].ToString();
            articleDto.ArticleInfo = dr["ArticleInfo"].ToString();

            articleDto.ArticleHot = bool.Parse(dr["ArticleHot"].ToString());
            articleDto.ArticleTop = bool.Parse(dr["ArticleTop"].ToString());
            articleDto.ArticleImportant = bool.Parse(dr["ArticleImportant"].ToString());

            articleDto.ArticleDateTime = DateTime.Parse(dr["ArticleDateTime"].ToString());

            return articleDto;
        }