protected void Page_Load(object sender, EventArgs e)
        {
            List<Article> articleList = aArticleManager.GetArticleList();

            List<Article> customArticlList = new List<Article>();
            foreach (Article article in articleList)
            {
                Article customArticle = new Article();
                customArticle.Id = article.Id;

                string source = article.Description;
                var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
                var match = reg.Match(source);
                if (match.Success)
                {
                    string encod = match.Groups["imgSrc"].Value;
                    customArticle.Image = encod;
                }

                string strippedDescription = Regex.Replace(article.Description, "<.*?>", string.Empty);
                int length = strippedDescription.Length;
                if (length > 200)
                {
                    length = 200;
                }

                string customDescription = strippedDescription.Substring(0, length);
                customArticle.Description = customDescription;
                customArticle.Title = article.Title;
                customArticlList.Add(customArticle);
            }

            AllPost.DataSource = customArticlList;
            AllPost.DataBind();
        }
        public List<Article> GetDetailArticle(string articleId)
        {
            SqlConnection connection = new SqlConnection(dbConnectionString);
            string query = "SELECT * FROM tbl_article WHERE id = '" + articleId + "'";
            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();

            SqlDataReader reader = command.ExecuteReader();

            List<Article> articleList = new List<Article>();

            while (reader.Read())
            {
                Article article = new Article();
                article.Id = int.Parse(reader["id"].ToString());
                article.Title = reader["title"].ToString();
                article.PostUserName = reader["user_name"].ToString();
                article.Description = reader["description"].ToString();
                article.Date = reader["date"].ToString();

                article.ArticleHitCount = int.Parse(reader["article_hit_count"].ToString());

                articleList.Add(article);
            }
            reader.Close();
            connection.Close();

            return articleList;
        }
        public List<Article> GetArticleList()
        {
            SqlConnection connection = new SqlConnection(dbConnectionString);
            string query = "SELECT TOP(5) * FROM tbl_article ORDER BY id DESC";
            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();

            SqlDataReader reader = command.ExecuteReader();

            List<Article> articleList = new List<Article>();

            while (reader.Read())
            {
                Article article = new Article();
                article.Id = int.Parse(reader["id"].ToString());
                article.Title = reader["title"].ToString();
                article.Description = reader["description"].ToString();
                article.Date = reader["date"].ToString();
                article.PostUserName = reader["user_name"].ToString();

                articleList.Add(article);
            }
            reader.Close();
            connection.Close();

            return articleList;
        }
 public string Save(Article article)
 {
     if (articleGateway.Save(article) > 0)
     {
         return "Article Save Success";
     }
     else
     {
         return "Article Save Faild!";
     }
 }
        protected void postArticle_Click(object sender, EventArgs e)
        {
            Article article = new Article();
            article.Title = articletitleTextbox.Text;
            article.Description = Request.Form["edit"];

            article.Status = Request.Form["status"];
            User sessionUser = (User)Session["user"];
            article.PostUserName = sessionUser.Id.ToString();

            //User aUser = (User)Session["user"];

            //article.PostUserName = aUser.UserName;

            //User aUser = userGateway.GetUserId();
            //article.UserId = aUser.Id;

             msg.InnerHtml = articleManager.Save(article);
            //msg.InnerHtml = "Article Post Success";
        }
 public int Save(Article article)
 {
     SqlConnection connection = new SqlConnection(dbConnectionString);
     string query = "INSERT INTO tbl_article(title,description,status,date,user_name,article_hit_count) VALUES ('" + article.Title +
                    "','" +
                    article.Description + "','" + article.Status + "','" + DateTime.Now + "','" + article.PostUserName + "','0')";
     SqlCommand command = new SqlCommand(query, connection);
     connection.Open();
     int rowA = command.ExecuteNonQuery();
     connection.Close();
     return rowA;
 }