블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 10. 27. 02:32 .Net Project/ASP.NET 3.5 Sp1
반응형

Common 프로젝트 안에 Reply.Common 클래스 라이브러리 안에 Border.CS 클래스 파일 생성

GetNewImg(), ConvertContentByEncoding()
메서드 정의

GetNewImg() : 24 시간 내의 글이면 New 이미지 붙이기

ConvertContentByEncoding() : 인코딩 방식에 따른 Content 문자열 변환

 Border.Cs

using System;


//
한번 이상 사용되는 코드는 메서드

// Common 구현

namespace Reply.Common

{

    public class Board

    {

        /// <summary>

        /// 날짜값 받아서 24시간내의 글이면 New 이미지 붙이기

        /// </summary>

        /// Reply.Common.Board.GetNewImg 써서 사용

        public static string GetNewImg(object postDate)

        {

            TimeSpan ts = DateTime.Now - Convert.ToDateTime(postDate);

            string result = "";

            if (ts.TotalHours < 24) // 24시간 내의 글이면...

            {

                result = "<img src='images/new.gif'/>";

            }

            return result;

        }

 

        /// <summary>

        /// 인코딩 방식에 따른 Content 문자열 반환 : Text/Mixed/HTML

        /// </summary>

        /// <param name="content"></param>

        /// <param name="encoding"></param>

        /// <returns></returns>

        public static string ConvertContentByEncoding
                                    (
string content, string encoding)

        {

            string result = String.Empty;

            encoding = encoding.ToLower(); // 소문자로 비교

            if (encoding == "Text") // 태그 실행 방지/소스 그대로

            {

                result = content

                            .Replace("&", "&amp;")

                            .Replace("<", "&lt;")

                            .Replace(">", "&gt;")

                            .Replace("\r\n", "<br />")

                            .Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");

            }

            else if (encoding == "Mixed") // 태그 실행

            {

                result = content.Replace("\r\n", "<br />");

            }

            else // HTML 표시

            {

                result = content;

            }

            return result;

        }

    }

}







반응형
posted by Magic_kit