ASP.NET 기초 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : 32. 자주 사용되는 메서드를 클래스라이브러리 프로젝트로 포함
글번호: 199
작성자: 레드플러스
작성일: 2007/06/26 오후 7:55:00
조회수: 6005
using System;
using System.Collections.Generic;
using System.Text;
using System.IO; // 네임스페이스 추가

namespace RedPlus.Library
{
  /// <summary>
  /// RedPlus.Library.Board : 게시판/웹 애플리케이션 관련 주요 함수 모음
  /// </summary>
  public class Board
  {
    #region CutString() 함수
    /// <summary>
    /// 주어진 스트링을 주어진 길이만큼만 잘라서 돌려줌.
    /// 나머지 부분은 '...'을 붙임 (대상 문자열, 길이)
    /// </summary>
    /// <param name="strCut">잘라낼 원본 문자열</param>
    /// <param name="intChar">제한할 글자 수</param>
    /// <returns>제한된 문자열</returns>
    public static string CutString(string strCut, int intChar)
    {
      if (strCut.Length > intChar - 3)
      {
        string strTemp = "";
        strTemp = strCut.Substring(0, intChar - 3);
        strTemp += "...";

        return strTemp;
      }
      else
      {
        return strCut;
      }
    }
    #endregion


    #region IsPhoto() 함수
    /// <summary>
    /// 첨부된 파일이 이미지 파일인지 검사
    /// </summary>
    /// <param name="strFileNameTemp"></param>
    /// <returns></returns>
    public static bool IsPhoto(string strFileNameTemp)
    {
      string strFileExt =
        Path.GetExtension(strFileNameTemp).Replace(".", "").ToLower();
      bool blnResult = false;
      if (strFileExt == "gif" || strFileExt == "jpg" ||
        strFileExt == "jpeg" || strFileExt == "png")
      {
        blnResult = true;
      }
      else
      {
        blnResult = false;
      }
      return blnResult;
    }
    #endregion


    #region IsImage() 함수
    /// <summary>
    /// 첨부된 파일이 이미지 파일인지 검사
    /// </summary>
    /// <param name="strFileExt"></param>
    /// <returns></returns>
    public static bool IsImage(string strFileExt)
    {
      bool blnResult = false;
      string[] arrImgExt = { ".GIF", ".JPG", ".JPEG", ".PNG" };

      foreach (string strExt in arrImgExt)
      {
        if (strFileExt.Trim().ToUpper().Equals(strExt))
        {
          blnResult = true;
          break;
        }
      }

      return blnResult;
    }
    #endregion


    #region IsMovie() 함수
    /// <summary>
    /// 첨부파일이 동영상 파일인지 검사
    /// </summary>
    /// <param name="strFileNameTemp"></param>
    /// <returns></returns>
    public static bool IsMovie(string strFileNameTemp)
    {
      string strFileExt =
        Path.GetExtension(strFileNameTemp).Replace(".", "").ToLower();
      bool blnResult = false;
      if (strFileExt == "asf" || strFileExt == "wmv")
      {
        blnResult = true;
      }
      else
      {
        blnResult = false;
      }
      return blnResult;
    }
    #endregion


    #region DownloadType() 함수
    /// <summary>
    /// 다운로드할 파일의 확장자를 통해 아이콘을 결정.
    /// (파일 이름, alt 메세지로 넣을 문자열)
    /// </summary>
    /// <param name="strFileName"></param>
    /// <param name="altString"></param>
    /// <returns></returns>
    public static string DownloadType(
      string strFileName, string altString)
    {
      string strFileExt =
        Path.GetExtension(strFileName).Replace(".", "");
      string strResult = "";
      switch (strFileExt)
      {
        case "ace":
          strResult = "<img src='images/ext_ace.gif' width='16' "
            + "height='16' border='0' alt='" + altString + "'>"; break;

        case "ai":
          strResult = "<img src='images/ext_ai.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "alz":
          strResult = "<img src='images/ext_alz.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "arj":
          strResult = "<img src='images/ext_arj.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "asa":
          strResult = "<img src='images/ext_asa.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "asax":
          strResult = "<img src='images/ext_asax.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "ascx":
          strResult = "<img src='images/ext_ascx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "asf":
          strResult = "<img src='images/ext_asf.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "asmx":
          strResult = "<img src='images/ext_asmx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "asp":
          strResult = "<img src='images/ext_asp.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "aspx":
          strResult = "<img src='images/ext_aspx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "asx":
          strResult = "<img src='images/ext_asx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "au":
          strResult = "<img src='images/ext_au.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "avi":
          strResult = "<img src='images/ext_avi.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "bat":
          strResult = "<img src='images/ext_bat.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "bmp":
          strResult = "<img src='images/ext_bmp.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "c":
          strResult = "<img src='images/ext_c.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "cs":
          strResult = "<img src='images/ext_cs.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "csproj":
          strResult = "<img src='images/ext_csproj.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "cab":
          strResult = "<img src='images/ext_cab.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "chm":
          strResult = "<img src='images/ext_chm.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "com":
          strResult = "<img src='images/ext_com.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "config":
          strResult = "<img src='images/ext_config.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "cpp":
          strResult = "<img src='images/ext_cpp.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "css":
          strResult = "<img src='images/ext_css.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "csv":
          strResult = "<img src='images/ext_csv.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "disco":
          strResult = "<img src='images/ext_disco.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "dll":
          strResult = "<img src='images/ext_dll.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "doc":
          strResult = "<img src='images/ext_doc.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "eml":
          strResult = "<img src='images/ext_eml.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "exe":
          strResult = "<img src='images/ext_exe.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "gif":
          strResult = "<img src='images/ext_gif.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "gz":
          strResult = "<img src='images/ext_gz.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "h":
          strResult = "<img src='images/ext_h.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "hlp":
          strResult = "<img src='images/ext_hlp.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "htm":
          strResult = "<img src='images/ext_htm.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "html":
          strResult = "<img src='images/ext_html.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "hwp":
          strResult = "<img src='images/ext_hwp.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "hwt":
          strResult = "<img src='images/ext_hwt.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "inc":
          strResult = "<img src='images/ext_inc.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "ini":
          strResult = "<img src='images/ext_ini.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "jpg":
          strResult = "<img src='images/ext_jpg.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "jpeg":
          strResult = "<img src='images/ext_jpeg.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "js":
          strResult = "<img src='images/ext_js.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "lzh":
          strResult = "<img src='images/ext_lzh.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "m3u":
          strResult = "<img src='images/ext_m3u.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "max":
          strResult = "<img src='images/ext_max.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mdb":
          strResult = "<img src='images/ext_mdb.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mid":
          strResult = "<img src='images/ext_mid.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mov":
          strResult = "<img src='images/ext_mov.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mp2":
          strResult = "<img src='images/ext_mp2.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mp3":
          strResult = "<img src='images/ext_mp3.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mpe":
          strResult = "<img src='images/ext_mpe.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mpeg":
          strResult = "<img src='images/ext_mpeg.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "mpg":
          strResult = "<img src='images/ext_mpg.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "msi":
          strResult = "<img src='images/ext_exe.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "":
          strResult = "<img src='images/ext_none.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "pcx":
          strResult = "<img src='images/ext_pcx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "pdb":
          strResult = "<img src='images/ext_pdb.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "pdf":
          strResult = "<img src='images/ext_pdf.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "pls":
          strResult = "<img src='images/ext_pls.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "png":
          strResult = "<img src='images/ext_png.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "ppt":
          strResult = "<img src='images/ext_ppt.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "psd":
          strResult = "<img src='images/ext_psd.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "ra":
          strResult = "<img src='images/ext_ra.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "ram":
          strResult = "<img src='images/ext_ram.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "rar":
          strResult = "<img src='images/ext_rar.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "reg":
          strResult = "<img src='images/ext_reg.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "resx":
          strResult = "<img src='images/ext_resx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "rm":
          strResult = "<img src='images/ext_rm.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "rmi":
          strResult = "<img src='images/ext_rmi.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "rtf":
          strResult = "<img src='images/ext_rtf.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "sql":
          strResult = "<img src='images/ext_sql.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "swf":
          strResult = "<img src='images/ext_swf.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "sys":
          strResult = "<img src='images/ext_sys.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "tar":
          strResult = "<img src='images/ext_tar.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "tga":
          strResult = "<img src='images/ext_tga.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "tif":
          strResult = "<img src='images/ext_tif.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "ttf":
          strResult = "<img src='images/ext_ttf.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "txt":
          strResult = "<img src='images/ext_txt.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "vb":
          strResult = "<img src='images/ext_vb.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "vbs":
          strResult = "<img src='images/ext_vbs.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "vbdisco":
          strResult = "<img src='images/ext_vbdisco.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "wav":
          strResult = "<img src='images/ext_wav.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "wax":
          strResult = "<img src='images/ext_wax.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "webinfo":
          strResult = "<img src='images/ext_webinfo.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "wma":
          strResult = "<img src='images/ext_wma.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "wmv":
          strResult = "<img src='images/ext_wmv.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "wmx":
          strResult = "<img src='images/ext_wmx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "wri":
          strResult = "<img src='images/ext_wri.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "wvx":
          strResult = "<img src='images/ext_wvx.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "xls":
          strResult = "<img src='images/ext_xls.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "xml":
          strResult = "<img src='images/ext_xml.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        case "zip":
          strResult = "<img src='images/ext_zip.gif' width='16' height='16' border='0' alt='" + altString + "'>"; break;

        default:
          strResult = "<img src='images/ext_unknown.gif' width='16' "
            + "height='16' border='0' alt='" + altString + "'>"; break;
      }
      return strResult;
    }
    #endregion


    #region ConvertToFileSize() 함수
    /// <summary>
    /// 파일 크기를 계산해서 알맞은 단위로 변환해줌. (바이트 수)
    /// </summary>
    /// <param name="intByte">바이트 단위 숫자</param>
    /// <returns>단위에 맞는 문자열</returns>
    public static string ConvertToFileSize(int intByte)
    {
      int intFileSize = Convert.ToInt32(intByte);
      string strResult = "";
      if (intFileSize >= 1048576)
      {
        strResult = string.Format("{0:F} MB", (intByte / 1048576));
      }
      else
      {
        if (intFileSize >= 1024)
        {
          strResult = string.Format("{0} KB", (intByte / 1024));
        }
        else
        {
          strResult = intByte + " Byte(s)";
        }
      }
      return strResult;
    }
    #endregion


    #region ConvertToHtml() 함수
    /// <summary>
    /// 주어진 문자열을 HTML코드로 바꿈. 특히 탭이나 공백도 처리함. (바꿀 문자열)
    /// </summary>
    /// <param name="strContent"></param>
    /// <returns></returns>
    public static string ConvertToHtml(string strContent)
    {
      string strTemp = "";
      if (strContent.Length == 0 || strContent == null)
      {
        strTemp = "";
      }
      else
      {
        strTemp = strContent;
        strTemp = strTemp.Replace("&", "&amp;");
        strTemp = strTemp.Replace(">", "&gt;");
        strTemp = strTemp.Replace("<", "&lt;");
        strTemp = strTemp.Replace("\r\n", "<br />");
        strTemp = strTemp.Replace("\"", "&#34;");
        strTemp = strTemp.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
        strTemp = strTemp.Replace(" " + " ", "&nbsp;&nbsp;");
      }
      return strTemp;
    }
    #endregion    
  }
}
 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트


관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 33. 완성형 게시판(기본형+자료실+답변형) (1) - 레드플러스 2007-07-03 6825
현재글 32. 자주 사용되는 메서드를 클래스라이브러리 프로젝트로 포함 - 레드플러스 2007-06-26 6005
  32.1. 자주 사용되는 메서드를 클래스라이브러리 프로젝트로 포함 소스 RedPlus.Library.zip(23 KB) 레드플러스 2007-06-26 4599
다음글 31. 회원 가입 - 레드플러스 2007-06-22 7402
 
손님 사용자 Anonymous (손님)
로그인 Home