コード例 #1
0
 public int update(CommentModels item) {
     StringBuilder sqlBuilder = new StringBuilder();
     sqlBuilder.Append("UPDATE ");
     sqlBuilder.Append("gov_comments ");
     sqlBuilder.Append("SET ");
     sqlBuilder.Append("user_id = @1, ");
     sqlBuilder.Append("full_name = @2, ");
     sqlBuilder.Append("parent_id = @3, ");
     sqlBuilder.Append("news_id = @4, ");
     sqlBuilder.Append("comments_content = @5, ");
     sqlBuilder.Append("total_like =  @6, ");
     sqlBuilder.Append("like_info = @7, ");
     sqlBuilder.Append("active_flg = @8, ");
     sqlBuilder.Append("entry_datetime = @9, ");
     sqlBuilder.Append("email = @10 ");
     sqlBuilder.Append("WHERE ");
     sqlBuilder.Append("id = @11 ");
     this.Sql = sqlBuilder.ToString();
     MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
     objCmd.Parameters.AddWithValue("@1", item.UserId);
     objCmd.Parameters.AddWithValue("@2", item.FullName);
     objCmd.Parameters.AddWithValue("@3", item.ParentId);
     objCmd.Parameters.AddWithValue("@4", item.NewsId);
     objCmd.Parameters.AddWithValue("@5", item.CommentsContent);
     objCmd.Parameters.AddWithValue("@6", item.TotalLike);
     objCmd.Parameters.AddWithValue("@7", item.LikeInfo);
     objCmd.Parameters.AddWithValue("@8", item.ActiveFlg);
     objCmd.Parameters.AddWithValue("@9", item.EntryDatetime);
     objCmd.Parameters.AddWithValue("@10", item.Email);
     objCmd.Parameters.AddWithValue("@11", item.Id);
     int rs = objCmd.ExecuteNonQuery();
     return rs;
 }
コード例 #2
0
 public int insert(CommentModels item)
 {
     StringBuilder sqlBuilder = new StringBuilder();
     sqlBuilder.Append("INSERT ");
     sqlBuilder.Append("INTO ");
     sqlBuilder.Append("gov_comments ");
     sqlBuilder.Append("( ");
     sqlBuilder.Append("user_id, ");
     sqlBuilder.Append("full_name, ");
     sqlBuilder.Append("parent_id, ");
     sqlBuilder.Append("news_id, ");
     sqlBuilder.Append("comments_content, ");
     sqlBuilder.Append("total_like, ");
     sqlBuilder.Append("like_info, ");
     sqlBuilder.Append("active_flg,");
     sqlBuilder.Append("entry_datetime,");
     sqlBuilder.Append("email");
     sqlBuilder.Append(") ");
     sqlBuilder.Append("values(");
     sqlBuilder.Append("@1, @2, @3, @4, @5, @6, @7, @8, @9, @10");
     sqlBuilder.Append(")");
     this.Sql = sqlBuilder.ToString();
     MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
     objCmd.Parameters.AddWithValue("@1", item.UserId);
     objCmd.Parameters.AddWithValue("@2", item.FullName);
     objCmd.Parameters.AddWithValue("@3", item.ParentId);
     objCmd.Parameters.AddWithValue("@4", item.NewsId);
     objCmd.Parameters.AddWithValue("@5", item.CommentsContent);
     objCmd.Parameters.AddWithValue("@6", item.TotalLike);
     objCmd.Parameters.AddWithValue("@7", item.LikeInfo);
     objCmd.Parameters.AddWithValue("@8", item.ActiveFlg);
     objCmd.Parameters.AddWithValue("@9", item.EntryDatetime);
     objCmd.Parameters.AddWithValue("@10", item.Email);
     int rs = objCmd.ExecuteNonQuery();
     return rs;
 }
コード例 #3
0
        public List<CommentModels> select(int page, int limit)
        {
            int offset = (page - 1) * limit;
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("SELECT ");
            sqlBuilder.Append("* ");
            sqlBuilder.Append("FROM ");
            sqlBuilder.Append("gov_comments gcm ");
            sqlBuilder.Append(getBaseSQL());
            if (page > 0 && limit > 0)
            {
                sqlBuilder.Append(" LIMIT @limit ");
                sqlBuilder.Append(" OFFSET @offset ");
            }
            this.Sql = sqlBuilder.ToString();

            MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
            if (page > 0 && limit > 0)
            {
                objCmd.Parameters.AddWithValue("@limit", limit);
                objCmd.Parameters.AddWithValue("@offset", offset);
            }

            MySqlDataReader dataReader = objCmd.ExecuteReader();
            List<CommentModels> lstMenu = new List<CommentModels>();
            CommentModels item;
            while (dataReader.Read())
            {
                item = new CommentModels();
                item.Id = Convert.ToInt32(dataReader["id"]);
                item.UserId = Convert.ToInt32(dataReader["user_id"]);
                item.FullName = dataReader["full_name"].ToString();
                item.Email = dataReader["email"].ToString();
                item.ParentId = Convert.ToInt32(dataReader["parent_id"]);
                item.NewsId = Convert.ToInt32(dataReader["news_id"]);
                item.CommentsContent = dataReader["comments_content"].ToString();
                item.TotalLike = Convert.ToInt32(dataReader["total_like"]);
                item.LikeInfo = dataReader["like_info"].ToString();
                item.ActiveFlg = Convert.ToBoolean(dataReader["active_flg"]);
                item.EntryDatetime = Convert.ToDateTime(dataReader["entry_datetime"]);
                lstMenu.Add(item);
            }
            getConnection().Close();
            return lstMenu;
        }