();
foreach(var item in vt.Split(';'))
{
list.Add(new NP.Model.BaseModel() { value = item.Split(':')[0], text = item.Split(':')[1] });
}
return list;
}
public static System.Web.Mvc.ViewDataDictionary DicText(NP.Model.TextDic dic)
{
System.Web.Mvc.ViewDataDictionary vdd = new System.Web.Mvc.ViewDataDictionary() { };
vdd.Add("name", dic.Name);
vdd.Add("df", dic.DF);
vdd.Add("value", dic.Value);
vdd.Add("special", dic.Special);
vdd.Add("cssclass", dic.CssClass);
vdd.Add("onchange", dic.OnChange);
vdd.Add("ph", dic.PH);
vdd.Add("style", dic.Style);
if (dic.IsReadOnly)
{
vdd.Add("read", "1");
}
return vdd;
}
public static System.Web.Mvc.ViewDataDictionary DicSelect(NP.Model.SelectDic dic)
{
System.Web.Mvc.ViewDataDictionary vdd = new System.Web.Mvc.ViewDataDictionary() { };
vdd.Add("name", dic.Name);
vdd.Add("df", dic.DF);
vdd.Add("selected", dic.Selected);
vdd.Add("special", dic.Special);
vdd.Add("cssclass", dic.CssClass);
vdd.Add("onchange", dic.OnChange);
return vdd;
}
public static System.Web.Mvc.MvcHtmlString DateTimeBox(this System.Web.Mvc.HtmlHelper helper, NP.Model.DateTimeBox d)
{
StringBuilder sb = new StringBuilder();
sb.Append(""
+ ""
+ " 9 ? d.Value.Substring(0, 10) : "")+ "\" data-groupname=\"" + d.Name + "\" id=\"" + (d.Id ?? "") + "Date\" />"
+ ""
+ ""
+ "");
return System.Web.Mvc.MvcHtmlString.Create(sb.ToString());
}
public static System.Web.Mvc.MvcHtmlString DateBox(this System.Web.Mvc.HtmlHelper helper, NP.Model.DateBox d)
{
StringBuilder sb = new StringBuilder();
sb.Append(" 9 ? d.Value.Substring(0, 10) : "") + "\" name=\"" + d.Name + "\" id=\"" + d.Name.Replace(".", "_") + "\" />");
return System.Web.Mvc.MvcHtmlString.Create(sb.ToString());
}
private static String GetHour(String sv)
{
StringBuilder sb = new StringBuilder();
for(int i = 0; i < 24; i++)
{
sb.Append("");
}
return sb.ToString();
}
private static String GetMinute(String sv)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 60; i++)
{
sb.Append("");
}
return sb.ToString();
}
public static System.Web.Mvc.MvcHtmlString Select(this System.Web.Mvc.HtmlHelper helper, NP.Model.Select s)
{
var name = s.Name;
var id = s.Name.Replace(".", "_");
var onchange = string.IsNullOrEmpty(s.OnChange) ? "" : ("onchange='" + s.OnChange + "'");
var sblist = new StringBuilder();
sblist.Append("");
if (s.ComCodes != null)
{
foreach(var item in s.ComCodes)
{
sblist.Append(string.Format("", item.value, item.value == s.Selected ? "selected" : "", item.text));
}
}
else if (!string.IsNullOrEmpty(s.ListData))
{
foreach (var item in s.ListData.Split(';'))
{
sblist.Append(string.Format("", item.Split(':')[0], item.Split(':')[0] == s.Selected ? "selected" : "", item.Split(':')[1]));
}
}
StringBuilder sb = new StringBuilder();
if (s.Special != null)
{
switch (s.Special)
{
case NP.Model.ENUM.Special.Area1:
break;
case NP.Model.ENUM.Special.VocaSeq:
sb.Append(string.Format(""
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : ("")) + GetFromToOption(1, 100, "회차", s.Selected)));
break;
case NP.Model.ENUM.Special.IsOpenBoard:
sb.Append(string.Format(""
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : ("")) + ("")+ ("")));
break;
case NP.Model.ENUM.Special.Year:
sb.Append(string.Format(""
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : (""))
+ GetYearOption(2018, s.Selected)));
break;
case NP.Model.ENUM.Special.Month:
sb.Append(string.Format(""
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : (""))
+ GetMonthOption(s.Selected)));
break;
}
}
else
{
sb.Append(string.Format(""
, id
, name
, onchange
, (string.IsNullOrEmpty(s.DefaultText) && string.IsNullOrEmpty(s.DefaultValue) ? "" : (""))
+
sblist
)
);
}
return System.Web.Mvc.MvcHtmlString.Create(sb.ToString());
}
public static String GetYearOption(int minYear, String selected)
{
String op = "";
for(var i = minYear; i < DateTime.Now.Year + 2; i++)
{
op += string.Format("", i);
}
return op;
}
public static String GetMonthOption(String selected)
{
String op = "";
for (var i = 1; i < 13; i++)
{
op += string.Format("", i);
}
return op;
}
public static System.Web.Mvc.MvcHtmlString Radio(this System.Web.Mvc.HtmlHelper helper, NP.Model.InputRadio ir)
{
StringBuilder sb = new StringBuilder();
if (ir.Special != null)
{
switch (ir.Special)
{
case NP.Model.ENUM.Special.IsUse:
sb.Append(string.Format(
" "+
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\""+ir.OnChange+"\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.IsExclude:
sb.Append(string.Format(
" " +
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.IsUseBoard:
sb.Append(string.Format(
" " +
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.IsOpen:
sb.Append(string.Format(
" " +
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.IsApproval:
sb.Append(string.Format(
" " +
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.IsYesNo:
sb.Append(string.Format(
" " +
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.IsNoYes:
sb.Append(string.Format(
" " +
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.IsTop:
sb.Append(string.Format(
" " +
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""));
break;
case NP.Model.ENUM.Special.StringList:
{
int i = 0;
foreach (var s in ir.ListData.Split(';'))
{
sb.Append(string.Format(
" "
, ir.Name
, s.Split(':')[0]
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""
, s.Split(':')[1]));
i++;
}
}
break;
}
}
else
{
foreach (var item in ir.ComCodes)
{
sb.Append(string.Format(
" "
, ir.Name
, (string.IsNullOrEmpty(ir.OnChange) ? ("onchange=\"javascript:radioed(this);\"") : ("onchange =\"" + ir.OnChange + "\""))
, ir.ChangeId ?? ""
, item.ccode
, item.cname));
}
}
return System.Web.Mvc.MvcHtmlString.Create(sb.ToString());
}
public static System.Web.Mvc.MvcHtmlString Pager(this System.Web.Mvc.HtmlHelper helper, int currentPage, int pagesToShowSize, int pageSize, int totalRecords, String methodname = "gopage")
{
StringBuilder html = new StringBuilder(@"");
return System.Web.Mvc.MvcHtmlString.Create(html.ToString());
}
public static System.Web.Mvc.MvcHtmlString Pager2(this System.Web.Mvc.HtmlHelper helper, int currentPage, int pagesToShowSize, int pageSize, int totalRecords, String methodname = "gopage", String fid = "mform", String pid = "pagenum")
{
StringBuilder html = new StringBuilder(@"");
if (totalRecords <= pageSize)
{
return System.Web.Mvc.MvcHtmlString.Create(html + "
");
}
if (totalRecords > 0)
{
int maxPageNo = (int)Math.Ceiling((float)totalRecords / pageSize);
var htmlDic = new Dictionary();
int startPage = currentPage - ((currentPage - 1) % pagesToShowSize);
int endPage = startPage + (pagesToShowSize - 1);
if (maxPageNo < endPage)
{
endPage = maxPageNo;
}
int prevPage = Math.Max(startPage - pagesToShowSize, 1);
int nextPage = Math.Min(endPage + 1, maxPageNo);
html.Append(new StringBuilder("맨앞 "));
html.Append(new StringBuilder(" 이전"));
for (int page = startPage; page <= endPage; page++)
{
if (page == currentPage)
{
html.AppendFormat("- " + page + "
");
}
else
{
html.Append(new StringBuilder("- " + page + "
"));
}
}
html.Append(new StringBuilder("
다음 "));
html.Append(new StringBuilder("맨뒤"));
}
html.Append(@"");
return System.Web.Mvc.MvcHtmlString.Create(html.ToString());
}
public static String GetFromToOption(int start, int end, String textAppend, String selected)
{
StringBuilder sb = new StringBuilder();
for(int i = start; i < end + 1; i++)
{
sb.Append("");
}
return sb.ToString();
}
public static string RenderView(this System.Web.Mvc.Controller controller, string viewName, object model)
{
return RenderView(controller, viewName, new System.Web.Mvc.ViewDataDictionary(model));
}
public static string RenderView(this System.Web.Mvc.Controller controller, string viewName, System.Web.Mvc.ViewDataDictionary viewData)
{
var controllerContext = controller.ControllerContext;
var viewResult = System.Web.Mvc.ViewEngines.Engines.FindView(controllerContext, viewName, null);
System.IO.StringWriter stringWriter;
using (stringWriter = new System.IO.StringWriter())
{
var viewContext = new System.Web.Mvc.ViewContext(
controllerContext,
viewResult.View,
viewData,
controllerContext.Controller.TempData,
stringWriter);
viewResult.View.Render(viewContext, stringWriter);
viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
}
return stringWriter.ToString();
}
///
/// 압축 파일 풀기
///
/// ZIP파일 경로
/// 압축 풀 폴더 경로
/// 해지 암호
/// zip파일 삭제 여부
/// 압축 풀기 성공 여부
public static bool UnZipFiles(string zipFilePath, string unZipTargetFolderPath, string password = null, bool isDeleteZipFile = false)
{
// 반환 값
bool retVal = false;
// ZIP 파일 존재 여부 확인
if (File.Exists(zipFilePath))
{
try
{
using (var zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFilePath)))
{
if (!string.IsNullOrEmpty(password))
{
zipInputStream.Password = password; // 패스워드 설정
}
ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry;
// 압축 파일 내의 엔트리를 읽으면서 처리
while ((theEntry = zipInputStream.GetNextEntry()) != null)
{
// 압축 엔트리 이름 처리
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
// 디렉터리 생성
if (!string.IsNullOrEmpty(directoryName))
{
Directory.CreateDirectory(Path.Combine(unZipTargetFolderPath, directoryName));
}
// 파일이 있는 경우
if (!string.IsNullOrEmpty(fileName))
{
string fullPath = Path.Combine(unZipTargetFolderPath, theEntry.Name);
// 파일스트림 생성 및 파일 복사
using (FileStream streamWriter = File.Create(fullPath))
{
byte[] data = new byte[2048];
int size;
while ((size = zipInputStream.Read(data, 0, data.Length)) > 0)
{
streamWriter.Write(data, 0, size);
}
}
}
}
}
// 압축 해제가 성공적으로 완료되었음을 표시
retVal = true;
// ZIP 파일 삭제를 원하는 경우 처리
if (isDeleteZipFile)
{
File.Delete(zipFilePath);
}
}
catch
{
retVal = false; // 예외 발생 시 실행 실패로 표시
}
}
return retVal;
}
/*
public static bool UnZipFiles(string zipFilePath, string unZipTargetFolderPath, string password = null, bool isDeleteZipFile = false)
{
bool retVal = false;
//ZIP파일이있는경우만수행.
if (System.IO.File.Exists(zipFilePath))
{
//ZIP스트림생성.
ICSharpCode.SharpZipLib.Zip.ZipInputStream zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipFilePath));
//패스워드가있는경우패스워드지정.
if (password != null && password != String.Empty)
zipInputStream.Password = password;
try
{
ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry;
//반복하며파일을가져옴.
while ((theEntry = zipInputStream.GetNextEntry()) != null)
{
//폴더
string directoryName = System.IO.Path.GetDirectoryName(theEntry.Name);
string fileName = System.IO.Path.GetFileName(theEntry.Name);//파일
//폴더생성
System.IO.Directory.CreateDirectory(unZipTargetFolderPath+"\\" + directoryName);
//파일이름이있는경우
if (fileName != String.Empty)
{
//파일스트림생성.(파일생성)
System.IO.FileStream streamWriter = System.IO.File.Create((unZipTargetFolderPath +"\\"+ theEntry.Name));
int size = 2048;
byte[] data = new byte[2048];
//파일복사
while (true)
{
size = zipInputStream.Read(data, 0, data.Length);
if (size > 0)
streamWriter.Write(data, 0, size);
else
break;
}
//파일스트림종료
streamWriter.Close();
}
}
retVal = true;
}
catch
{
retVal = false;
}
finally
{
//ZIP파일스트림종료
zipInputStream.Close();
}
//ZIP파일삭제를원할경우파일삭제.
if (isDeleteZipFile)
try
{
System.IO.File.Delete(zipFilePath);
}
catch { }
}
return retVal;
}
*/
public static string MD5Hash(string data)
{
var mdHash = MD5.Create();
byte[] hash = mdHash.ComputeHash(Encoding.UTF8.GetBytes(data));
StringBuilder stringBuilder = new StringBuilder();
foreach (byte b in hash)
{
stringBuilder.AppendFormat("{0:x2}", b);
}
return stringBuilder.ToString();
}
///
/// 사용자 인증체크시(로그인/본인인증) 특정ip또는host skip할건지 여부
/// pwd:패스워드skip, smsauth:sms인증skip(
///
///
/// true:skip처리, false:skip하지않음
///
public static bool IsSkipIPorHost(IpHostSkipGb gb, string ip, string host)
{
string ipAddrs, hosts;
//ipAddrs1 = "127.0.0.1,218.232.111.111,59.150.105.195,59.150.105.198";
//ipAddrs2 = "218.232.111.111,59.150.105.195,59.150.105.198";
//ipAddrs1 = "127.0.0.1,218.232.111.111,59.150.105.195,59.150.105.198";
//hosts = "ynictea.nptc.kr";
ipAddrs = "";
hosts = "";
switch (gb)
{
case IpHostSkipGb.PassWord:
if (ipAddrs.Contains(ip) || hosts.Contains(host))
{
return true;
}
break;
case IpHostSkipGb.SmsAuth:
if (ipAddrs.Contains(ip) || hosts.Contains(host))
{
return true;
}
break;
default:
break;
}
return false;
}
}