제목 : RedPlus.Library.Board 클래스 : 게시판/웹 애플리케이션 관련 주요 함수 모음
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mail;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.IO;
using System.Xml;
using System.Collections;
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")
{
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)
{
//Function ConvertToHTML(ByVal strContent)
//
// Dim strTemp
//
// If Len(strContent) = 0 Or IsNull(Len(strContent)) = True Then
// strTemp = ""
// Else
// strTemp = strContent
// strTemp = Replace(strTemp, "&", "&")
// strTemp = Replace(strTemp, ">", ">")
// strTemp = Replace(strTemp, "<", "<")
// strTemp = Replace(strTemp, chr(13), "<br>")
// strTemp = Replace(strTemp, chr(34), """)
// strTemp = Replace(strTemp, chr(9), " ")
// strTemp = Replace(strTemp, chr(32) & chr(32), " ")
// End If
//
// ConvertToHTML = strTemp
//
//End Function
string strTemp = "";
if(strContent.Length == 0 || strContent == null)
{
strTemp = "";
}
else
{
strTemp = strContent;
strTemp = strTemp.Replace("&", "&");
strTemp = strTemp.Replace(">", ">");
strTemp = strTemp.Replace("<", "<");
strTemp = strTemp.Replace("\r\n", "<br>");
strTemp = strTemp.Replace("\"", """);
strTemp = strTemp.Replace("\t", " ");
strTemp = strTemp.Replace(" "+" ", " ");
}
return strTemp;
}
#endregion
#region ConvertToHtml2() 함수
/// <summary>
/// 주어진 문자열을 HTML코드로 바꿈. (바꿀 문자열)
/// </summary>
/// <param name="strContent"></param>
/// <returns></returns>
public static string ConvertToHtml2(string strContent)
{
string strTemp = "";
if(strContent.Length == 0 || strContent == null)
{
strTemp = "";
}
else
{
strTemp = strContent;
strTemp = strTemp.Replace("&", "&");
strTemp = strTemp.Replace(">", ">");
strTemp = strTemp.Replace("<", "<");
strTemp = strTemp.Replace("\r\n", "<br>");
strTemp = strTemp.Replace("\"", """);
}
return strTemp;
}
#endregion
#region ConvertToSql() 함수
/// <summary>
/// 주어진 문자열에 있는 SQL 특수 문자를 바꿈. (바꿀 문자열)
/// </summary>
/// <param name="strContent"></param>
/// <returns></returns>
public static string ConvertToSql(string strContent)
{
//'주어진 문자열에 있는 SQL 특수 문자를 바꿈. (바꿀 문자열)
//Function ConvertToSQL(strContent)
//
// strTemp = strContent
// strTemp = Replace(strTemp, "%", "[%]")
// strTemp = Replace(strTemp, "_", "[_]")
// 'strTemp = Replace(strTemp, "@", "[@]")
// strTemp = Replace(strTemp, "'", "''")
//
// ConvertToSQL = strTemp
//
//End Function
string strTemp = strContent;
strTemp = strTemp.Replace("%", "[%]");
strTemp = strTemp.Replace("_", "[_]");
strTemp = strTemp.Replace("@", "[@]");
strTemp = strTemp.Replace("'", "''");
return strTemp;
}
#endregion
#region GetDirectorySize() 함수
/// <summary>
/// 디렉터리 크기 구하기 메서드
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public long GetDirectorySize(string path)
{
long dirSize = 0;
DirectoryInfo dir = new DirectoryInfo(path);
//section 1. 현재 디렉터리내의 파일들의 크기를 더함
FileInfo [] files = dir.GetFiles();
foreach(FileInfo file in files)
{
dirSize += file.Length;
}
//section 2. 하위 폴더의 파일들의 크기를 더함
foreach(DirectoryInfo subdir in dir.GetDirectories())
{
dirSize += GetDirectorySize(subdir.FullName);
}
return dirSize;
}
#endregion
#region GetUniqueFileNameWithPath() 함수
/// <summary>
/// 파일명 뒤에 번호 붙이는 메서드
/// </summary>
/// <param name="dirPath"></param>
/// <param name="fileNameTemp"></param>
/// <returns></returns>
public string GetUniqueFileNameWithPath(string dirPath, string fileNameTemp)
{
string fileName = fileNameTemp;
//파일이름에서 . 의 위치를 알아낸다.
int indexOfDot = fileName.LastIndexOf(".");
//파일명만을 떼어낸다
string strName = fileName.Substring(0, indexOfDot);
//파일의 확장자만을 떼어낸다.
string strExt = fileName.Substring(++indexOfDot);
//같은 이름의 파일의 존재여부, 우선 있다고 가정.
bool bExist = true; int fileCount = 0;
while(bExist)
{
if(File.Exists(Path.Combine(dirPath, fileName)))
{
fileCount++;
fileName =
strName + "(" + fileCount + ")." + strExt;
}
else
{
bExist = false;
}
}
return Path.Combine(dirPath, fileName);
}//end function
#endregion
#region IsSqlReserved() 함수
/// <summary>
/// SQL 예약어 검사
/// </summary>
/// <param name="strKeyword"></param>
/// <returns></returns>
public static bool IsSqlReserved(string strKeyword)
{
string [] arrReserved = new string[100];
arrReserved[0] = "ABSOLUTE";
arrReserved[1] = "ACTION";
arrReserved[2] = "ALLOCATE";
arrReserved[3] = "ARE";
arrReserved[4] = "ASSERTION";
arrReserved[5] = "AT";
arrReserved[6] = "AUTHORIZATION";
arrReserved[7] = "BOTH";
arrReserved[8] = "CASCADE";
arrReserved[9] = "CASCADED";
arrReserved[10] = "CAST";
arrReserved[11] = "CATALOG";
arrReserved[12] = "CHAR_LENGTH";
arrReserved[13] = "CHARACTER";
arrReserved[14] = "CHARACTER_LENGTH";
arrReserved[15] = "COLLATE";
arrReserved[16] = "COLLATION";
arrReserved[17] = "COLUMN";
arrReserved[18] = "CONNECTION";
arrReserved[19] = "CONNECT";
arrReserved[20] = "CONSTRAINTS";
arrReserved[21] = "CORRESPONDING";
arrReserved[22] = "DATE";
arrReserved[23] = "DAY";
arrReserved[24] = "DEFERRABLE";
arrReserved[25] = "DEFERRED";
arrReserved[26] = "DESCRIBE";
arrReserved[27] = "DESCRIPTOR";
arrReserved[28] = "DIAGNOSTICS";
arrReserved[29] = "DISCONNECT";
arrReserved[30] = "Domains";
arrReserved[31] = "END_EXEC";
arrReserved[32] = "ESCAPE";
arrReserved[33] = "EXCEPTION";
arrReserved[34] = "EXPIREDATE";
arrReserved[35] = "EXTERNAL";
arrReserved[36] = "EXTRACT";
arrReserved[37] = "FALSE";
arrReserved[38] = "FILE";
arrReserved[39] = "FIRST";
arrReserved[40] = "FULL";
arrReserved[41] = "GET";
arrReserved[42] = "GLOBAL";
arrReserved[43] = "HOUR";
arrReserved[44] = "IMMEDIATE";
arrReserved[45] = "INITIALLY";
arrReserved[46] = "INNER";
arrReserved[47] = "INPUT";
arrReserved[48] = "INTERVAL";
arrReserved[49] = "JOIN";
arrReserved[50] = "LAST";
arrReserved[51] = "LEADING";
arrReserved[52] = "LEFT";
arrReserved[53] = "LOCAL";
arrReserved[54] = "MATCH";
arrReserved[55] = "MINUTE";
arrReserved[56] = "MONTH";
arrReserved[57] = "NATIONAL";
arrReserved[58] = "NAMES";
arrReserved[59] = "NATURAL";
arrReserved[60] = "NCHAR";
arrReserved[61] = "NEXT";
arrReserved[62] = "NO";
arrReserved[63] = "OCTET_LENGTH";
arrReserved[64] = "OUTER";
arrReserved[65] = "OUTPUT";
arrReserved[66] = "OVERLAPS";
arrReserved[67] = "PAD";
arrReserved[68] = "PARTIAL";
arrReserved[69] = "POSITION";
arrReserved[70] = "PRESERVE";
arrReserved[71] = "PRIOR";
arrReserved[72] = "PRIVILEGES";
arrReserved[73] = "RELATIVE";
arrReserved[74] = "RESTRICT";
arrReserved[75] = "RETAINDAYS";
arrReserved[76] = "RIGHT";
arrReserved[77] = "ROWS";
arrReserved[78] = "SCHEMA";
arrReserved[79] = "SECOND";
arrReserved[80] = "SESSION";
arrReserved[81] = "SIZE";
arrReserved[82] = "SPACE";
arrReserved[83] = "SQLSTATE";
arrReserved[84] = "TIME";
arrReserved[85] = "TIMESTAMP";
arrReserved[86] = "TIMEZONE_HOUR";
arrReserved[87] = "TIMEZONE_MINUTE";
arrReserved[88] = "TRAILING";
arrReserved[89] = "TRANSLATE";
arrReserved[90] = "TRANSLATION";
arrReserved[91] = "TRUE";
arrReserved[92] = "UNKNOWN";
arrReserved[93] = "USAGE";
arrReserved[94] = "USING";
arrReserved[95] = "VALUE";
arrReserved[96] = "VOLUME";
arrReserved[97] = "WORK";
arrReserved[98] = "WRITE";
arrReserved[99] = "YEAR";
arrReserved[100] = "ZONE";
bool strTemp = false;
foreach(string strItem in arrReserved)
{
if(strKeyword == strItem)
{
strTemp = true;
break;
}
}
return strTemp;
}
#endregion
#region GetUniqName() 함수
/// <summary>
/// 중복파일명 체크
/// </summary>
/// <param name="DirName">체크할 디렉토리</param>
/// <param name="fn">파일명</param>
/// <param name="DirName">확장자</param>
public string GetUniqName(string DirName, string fn, string fe)
{
FileInfo info = new FileInfo(DirName+"\\"+fn+fe);
int i = 1;
while(true)
{
if(info.Exists)
{
info = new FileInfo(DirName+"\\"+fn+"("+i+")"+fe);
i++;
continue;
}
else
{
break;
}
}
return info.Name;
}
#endregion
#region strCut() 함수
/// <summary>
/// 한글*영문 Word길이 제어
/// </summary>
/// <param name="str"></param>
/// <param name="max"></param>
/// <param name="suffix"></param>
/// <returns></returns>
public string strCut(string str, int max, string suffix)
{
string strResult="";
string s = str.ToString();
if (s == "") return strResult;
int count = 0;
string tmpStr = str.Trim().ToString();
char [] chrarr = tmpStr.ToCharArray();
if (tmpStr.Length != 0)
{
for (int i=0; i< chrarr.Length; i++)
{
int temp = Convert.ToInt32(chrarr[i]);
if (temp < 0 || temp >= 128 )
{
//한글 2byte
count = count+2;
}
else
{
count = count+1;
}
if (count <= max)
{
strResult = strResult + tmpStr.Substring(i,1);
}
else
{
strResult = strResult + suffix;
break;
}
}
}
return strResult;
}
#endregion
#region PrintMsg() 함수
/// <summary>
/// MsgBox 출력
/// </summary>
/// <param name="strMessage">메세지 박스에 출력할 문자열</param>
public void PrintMsg(string strMessage)
{
string strHTML;
strHTML = "<script language=\"javascript\">\n <!--\n" +
" alert('" + strMessage + "');\n//-->\n </script>\n";
HttpContext.Current.Response.Write(strHTML);
}
#endregion
#region PrintMsgAndClose() 함수
/// <summary>
/// MsgBox 출력 후 브라우져 창을 닫는다.
/// </summary>
/// <param name="strMessage">메세지 박스에 출력할 문자열</param>
public void PrintMsgAndClose(string strMessage)
{
string strHTML;
strHTML = "<script language=\"javascript\">\n <!--\n alert('" + strMessage + "');\n" +
" self.close();\n" +
"//-->\n </script>\n";
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.End();
}
#endregion
#region PrintMsgAndRedir() 함수
/// <summary>
/// MsgBox 출력 후 리 디렉션
/// </summary>
/// <param name="strMessage">메세지 박스에 출력할 문자열</param>
/// <param name="redirUri">리디렉션 주소</param>
public void PrintMsgAndRedir(string strMessage, string redirUri)
{
string strHTML;
strHTML = "<script language=\"javascript\">\n <!--\n alert('" + strMessage + "');\n" +
" window.document.location.href='" + redirUri + "';\n" +
"//-->\n </script>\n";
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.End();
}
#endregion
#region PrintMsgAndCloseAndOpenerRedir() 함수
/// <summary>
/// MsgBox 출력 후 opener를 리 디렉션
/// </summary>
/// <param name="strMessage">클라이언트로 출력될 문자열</param>
/// <param name="redirUri">부모창의 주소</param>
public void PrintMsgAndCloseAndOpenerRedir(string strMessage, string redirUri)
{
string strHTML;
strHTML = "<script language=\"javascript\">\n <!--\n alert('" + strMessage + "');\n" +
" opener.document.location.href='" + redirUri + "';\n" +
" self.close();\n" +
"//-->\n </script>\n";
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.End();
}
#endregion
#region PrintMsgBack() 함수
/// <summary>
/// MsgBox 출력후 이전화면으로 이동
/// </summary>
/// <param name="strMessage">클라이언트로 출력될 문자열</param>
public void PrintMsgBack(string strMessage)
{
string strHTML;
strHTML = "<script language=\"javascript\">\n" +
"<!--\n" +
"alert('" + strMessage + "');\n" +
"history.back();\n" +
"//-->\n" +
"</script>\n";
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.End();
}
#endregion
#region PrintMsgRedirectTarget() 함수
/// <summary>
/// 메세지박스 출력 후 지정된 타겟에 해당 url 로 이동
/// </summary>
/// <param name="message"> 출력 문자열</param>
/// <param name="url"> 이동할 URI</param>
/// <param name="target"> 페이지가 열릴 프래임 명</param>
public void PrintMsgRedirectTarget(string message, string url, string target)
{
string strHTML;
strHTML = "<html>\n" +
"<body onLoad=\"alert('" + message + "');document.redir.submit();\">\n" +
"<form action=\"" + url + "\" target=\""+target+"\" name=redir method=post>\n" +
"<input type=hidden name=name value=''>\n" +
"</form>\n" +
"</body>\n" +
"</html>\n";
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.End();
}
#endregion
#region RedirectTarget() 함수
/// <summary>
/// 지정된 타겟에 해당 url 로 이동
/// </summary>
/// <param name="url"> 이동할 URI</param>
/// <param name="target"> 페이지가 열릴 프래임 명</param>
public void RedirectTarget(string url, string target)
{
string strHTML;
strHTML = "<html>\n" +
"<body onLoad=\"document.redir.submit();\">\n" +
"<form action=\"" + url + "\" target=\""+target+"\" name=redir method=post>\n" +
"<input type=hidden name=name value=''>\n" +
"</form>\n" +
"</body>\n" +
"</html>\n";
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.End();
}
#endregion
#region 기타 함수
#region FindControlAll() 함수
/// <summary>
/// 컨트롤안에 속한 모든 자식컨트롤을 검색한다.
/// 기존의 FindControl메소드는 자신의 네이밍스코프 안에서만 검색한다.
/// </summary>
/// <param name="o"></param>
/// <param name="sName"></param>
/// <returns></returns>
public Control FindControlAll(Control o, string sName)
{
foreach(Control oChild in o.Controls)
{
if (oChild.ID == sName)
return oChild;
if (oChild.HasControls())
{
Control oFind = FindControlAll(oChild, sName);
if (oFind != null)
return oFind;
}
}
return null;
}
#endregion
#region GetForm() 함수
/// <summary>
/// Page 클레스에서 폼객체의 인스턴스를 찾아 리턴
/// </summary>
/// <param name="op">검색할 Page 클레스</param>
/// <returns>검색되 HomlForm 객채의 인스탄스</returns>
public HtmlForm GetForm(Page op)
{
foreach(Control oc in op.Controls)
{
if(oc is HtmlForm)
return (HtmlForm)oc;
}
throw new Exception("Find Not Form!!!!!");
}
#endregion
#region ReplaceBR() 함수
public string ReplaceBR(string str)
{
return str.Replace("\n", "<br/>");
}
#endregion
#region SetFocus() 함수
/// <summary>
/// 인자로 넘어온 컨트롤이 초기 포커스를 같도록 지정한다.
/// 페이지의 다른곳에서 이 함수가 호출되었다면 등록에 실페한다
/// </summary>
/// <param name="oc">포커스를 줄 컨트롤</param>
/// <returns> 포커스 지정 성공 : true, 이미 포커스가 지정된 컨트롤이 있음 : false</returns>
public bool SetFocus(Control oc)
{
if (oc.Page == null)
throw new Exception("SetFocus 메소드의 인자는 페이지에 추가된 컨트롤만 사용하실 수 있습니다.");
string ClientFocusScript = @"
<script language=""javascript"">
<!--
function _StartupFocus()
{{
document.{0}.{1}.focus();
}}
-->
</script>
";
if (!oc.Page.IsStartupScriptRegistered("_ClientFocusScript"))
{
ClientFocusScript = String.Format(ClientFocusScript, GetForm(oc.Page).ClientID, oc.ClientID);
oc.Page.RegisterStartupScript("_ClientFocusScript", ClientFocusScript);
RegisterOnloadFunction(oc.Page, "_StartupFocus()");
return true;
}
else
return false;
}
#endregion
#region RegisterOnloadFunction() 함수
/// <summary>
/// 클라이언트의 Onload이벤트에서 실행할 함수를 등록한다.
/// </summary>
/// <param name="page">Page 클레스</param>
/// <param name="functionName">등록할 함수명</param>
public void RegisterOnloadFunction(Page page, string functionName)
{
if (!page.IsClientScriptBlockRegistered("_ClientOnloadOnScript"))
{
string ClientOnloadOnScript = @"
<script language=""javascript"">
<!--
function _OnloadExectionFunction()
{
for (var i=0; i<__onloadFunctionArray.length; i++)
{
eval(__onloadFunctionArray[i]);
}
}
window.onload = _OnloadExectionFunction;
-->
</script>
";
page.RegisterClientScriptBlock("_ClientOnloadOnScript", ClientOnloadOnScript);
}
page.RegisterArrayDeclaration("__onloadFunctionArray", "'"+ functionName + "'");
}
#endregion
#region SetObjectToCache() 함수
//다른 페이지에서도 접근 가능한 키로 오브젝트를 저장한다.
public void SetObjectToCache(string key, object toCache, int lifeMinute)
{
HttpContext.Current.Cache.Insert("__Obj"+key, toCache, null, DateTime.Now.AddMinutes(lifeMinute),
TimeSpan.Zero, CacheItemPriority.High, null);
}
#endregion
#region GetObjectFromCache() 함수
//다른 페이지에서도 접근 가능한 키의 오브젝트를 가져온다.
public object GetObjectFromCache(string key)
{
return HttpContext.Current.Cache["__Obj"+key];
}
#endregion
#region RemoveObjectCache() 함수
//다른 페이지에서도 접근 가능한 키의 오브젝트를 케시에서 삭제한다.
public void RemoveObjectCache(string key)
{
HttpContext.Current.Cache.Remove("__Obj"+key);
}
#endregion
#endregion
}
}