YNICTE/Base/Lib/Helpers.cs

526 lines
28 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using NP.Base.ENUM;
public static class Helpers
{
/// <summary>
/// Value:Text;Value:Text
/// </summary>
/// <param name="vt"></param>
/// <returns></returns>
public static IList<NP.Model.BaseModel> ValueText(String vt)
{
List<NP.Model.BaseModel> list = new List<NP.Model.BaseModel>();
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(""
+ "<input type=\"hidden\" id=\""+d.Name.Replace(".", "_")+"\" name=\""+d.Name+"\" value=\""+d.Value+ "\" class=\"datetime\" />"
+ "<input type=\"text\" class=\"datepicker datetime datetimedate\" value=\"" + (d.Value.Length > 9 ? d.Value.Substring(0, 10) : "")+ "\" data-groupname=\"" + d.Name + "\" id=\"" + (d.Id ?? "") + "Date\" />"
+ "<select class=\"datetime datetimehour\" data-groupname=\"" + d.Name + "\"" + d.Name + "\" id=\"" + (d.Id ?? "") + "Hour\">"
+ GetHour(d.Value.Length > 12 ? d.Value.Substring(11, 2) : "")
+ "</select>"
+ "<select class=\"datetime datetimeminute\" data-groupname=\"" + d.Name + "\"" + d.Name + "\" id=\"" + (d.Id ?? "") + "Minute\">"
+ GetMinute(d.Value.Length > 15 ? d.Value.Substring(14, 2) : "")
+ "</select>"
+ "");
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("<input type=\"text\" class=\"datepicker date\" value=\"" + ((d.Value ?? "").Length > 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("<option value=\"" + i.ToString("00") + "\" " + (sv == i.ToString("00") ? "selected" : "") + ">" + i.ToString("00") + "시</option>");
}
return sb.ToString();
}
private static String GetMinute(String sv)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 60; i++)
{
sb.Append("<option value=\"" + i.ToString("00") + "\" " + (sv == i.ToString("00") ? "selected" : "") + ">" + i.ToString("00") + "분</option>");
}
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("<option value='{0}' {1}>{2}</option>", 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("<option value='{0}' {1}>{2}</option>", 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("<select id='{0}' name='{1}' {2}>{3}</select>"
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : ("<option value=''>"+s.DefaultText + "</option>")) + GetFromToOption(1, 100, "회차", s.Selected)));
break;
case NP.Model.ENUM.Special.IsOpenBoard:
sb.Append(string.Format("<select id='{0}' name='{1}' {2} class='"+(s.CssClass??"")+"' style='width: 100px;"+(s.Style)+"'>{3}</select>"
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : ("<option value=''>" + s.DefaultText + "</option>")) + ("<option value='1'"+(s.Selected == "1" ? "selected" : "")+">개시</option>")+ ("<option value='0'" + (s.Selected == "0" ? "selected" : "") + ">종료</option>")));
break;
case NP.Model.ENUM.Special.Year:
sb.Append(string.Format("<select id='{0}' name='{1}' {2} class='" + (s.CssClass ?? "") + "' style='width: 100px;" + (s.Style) + "'>{3}</select>"
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : ("<option value=''>" + s.DefaultText + "</option>"))
+ GetYearOption(2018, s.Selected)));
break;
case NP.Model.ENUM.Special.Month:
sb.Append(string.Format("<select id='{0}' name='{1}' {2} class='" + (s.CssClass ?? "") + "' style='width: 100px;" + (s.Style) + "'>{3}</select>"
, id, name, onchange, (string.IsNullOrEmpty(s.DefaultText) ? "" : ("<option value=''>" + s.DefaultText + "</option>"))
+ GetMonthOption(s.Selected)));
break;
}
}
else
{
sb.Append(string.Format("<select id='{0}' name='{1}' {2} style='"+s.Style+"'>{3}</select>"
, id
, name
, onchange
, (string.IsNullOrEmpty(s.DefaultText) && string.IsNullOrEmpty(s.DefaultValue) ? "" : ("<option value='" + (s.DefaultValue ?? "") + "'>" + s.DefaultText + "</option>"))
+
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("<option value='{0}'" + (selected == i.ToString() ? "selected" : "") + ">{0}년도</option>", i);
}
return op;
}
public static String GetMonthOption(String selected)
{
String op = "";
for (var i = 1; i < 13; i++)
{
op += string.Format("<option value='{0}'" + (selected == i.ToString() ? "selected" : "") + ">{0}월</option>", 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(
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">사용&nbsp;&nbsp;</label></span>"+
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">사용안함&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">제외&nbsp;&nbsp;</label></span>" +
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">제외안함&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">개시&nbsp;&nbsp;</label></span>" +
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">종료&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">공개&nbsp;&nbsp;</label></span>" +
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">비공개&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">승인&nbsp;&nbsp;</label></span>" +
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">대기&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">예&nbsp;&nbsp;</label></span>" +
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">아니오&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">아니오&nbsp;&nbsp;</label></span>" +
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">예&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}0\" name=\"{0}\" value=\"0\" {1} data-rname=\"{2}\" " + (ir.Selected == "0" ? "checked" : "") + " />&nbsp;<label for=\"{0}0\">일반글&nbsp;&nbsp;</label></span>" +
"<span><input type=\"radio\" id=\"{0}1\" name=\"{0}\" value=\"1\" {1} data-rname=\"{2}\" " + (ir.Selected == "1" ? "checked" : "") + " />&nbsp;<label for=\"{0}1\">상위고정글&nbsp;&nbsp;</label></span>"
, 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(
"<span><input type=\"radio\" id=\"{0}{1}\" name=\"{0}\" value=\"{1}\" {2} data-rname=\"{3}\" " + (ir.Selected == s.Split(':')[0] ? "checked" : "") + " />&nbsp;<label for=\"{0}{1}\">{4}&nbsp;&nbsp;</label></span>"
, 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(
"<span style=\"display: inline-block;\"><input type=\"radio\" id=\"{0}{3}\" name=\"{0}\" value=\"{3}\" {1} data-rname=\"{2}\" " + (ir.Selected == item.ccode.ToString() ? "checked" : "") + " />&nbsp;<label for=\"{0}{3}\">{4}&nbsp;&nbsp;</label>&nbsp;</span>"
, 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(@"<footer class='panel-footer'><input type='hidden' id='pagenum' name='pagenum' value='" + currentPage.ToString() + "' /><div class='row'><div class='col-sm-6 text-left'><small class='text-muted inline m-t-sm m-b-sm'>" + totalRecords.ToString("#,0") + " 개의 데이터 </small></div>");
if (totalRecords <= pageSize)
{
return System.Web.Mvc.MvcHtmlString.Create(html + "</fotter>");
}
html.Append(new StringBuilder(@"<div class='col-sm-6 text-right text-center-xs'><ul class='pagination pagination-sm m-t-none m-b-none'>"));
if (totalRecords > 0)
{
int maxPageNo = (int)Math.Ceiling((float)totalRecords / pageSize);
var htmlDic = new Dictionary<string, object>();
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(@"<li><a href='#' onclick='javascript:" + methodname + @"(1, this);'><i class='fa fa-chevron-left'></i><i class='fa fa-chevron-left'></i></a></li>"));
html.Append(new StringBuilder(@"<li><a href='#' onclick='javascript:" + methodname + @"(" + prevPage + @", this);'><i class='fa fa-chevron-left'></i></a>"));
for (int page = startPage; page <= endPage; page++)
{
if (page == currentPage)
{
html.AppendFormat("<li class='active'><a href='#' style='cursor: default;' /><strong>{0}</strong></a></li>", page);
}
else
{
html.Append(new StringBuilder(@"<li><a href='#' onclick='javascript:" + methodname + @"(" + page + @", this);'>" + page + @"</a></li>"));
}
}
html.Append(new StringBuilder(@"<li><a href='#' onclick='javascript:" + methodname + @"(" + nextPage + @", this);'><i class='fa fa-chevron-right'></i></a></li>"));
html.Append(new StringBuilder(@"<li><a href='#' onclick='javascript:" + methodname + @"(" + maxPageNo + @", this);'><i class='fa fa-chevron-right'></i><i class='fa fa-chevron-right'></i></a></li>"));
}
html.Append(@"</ul></div></div></footer>");
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(@"<div class='paging'><input type='hidden' id='pagenum' name='pagenum' value='" + currentPage.ToString() + "' />");
if (totalRecords <= pageSize)
{
return System.Web.Mvc.MvcHtmlString.Create(html + "</div>");
}
if (totalRecords > 0)
{
int maxPageNo = (int)Math.Ceiling((float)totalRecords / pageSize);
var htmlDic = new Dictionary<string, object>();
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("<a href=\"#\" class=\"first\" onclick=\"javascript:" + methodname + @"('"+fid+"','"+pid+ "',1, this);\">맨앞</a> "));
html.Append(new StringBuilder("<a href=\"#\" class=\"prev\"onclick=\"javascript:" + methodname + @"('" + fid + "','" + pid + "'," + prevPage + ", this);\" > 이전</a><ul>"));
for (int page = startPage; page <= endPage; page++)
{
if (page == currentPage)
{
html.AppendFormat("<li class=\"on\"><a href=\"#\">" + page + "</a></li> ");
}
else
{
html.Append(new StringBuilder("<li><a href=\"#\" onclick=\"javascript:" + methodname + @"('" + fid + "','" + pid + "'," + page + ", this);\">" + page + "</a></li> "));
}
}
html.Append(new StringBuilder("</ul><a href=\"#\" class=\"next\" onclick=\"javascript:" + methodname + @"('" + fid + "','" + pid + "'," + nextPage + ", this);\">다음</a> "));
html.Append(new StringBuilder("<a href=\"#\" class=\"last\" onclick=\"javascript:" + methodname + @"('" + fid + "','" + pid + "'," + maxPageNo + ", this);\">맨뒤</a>"));
}
html.Append(@"</div>");
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("<option value='" + i + "' " + (i.ToString() == selected ? "selected" : "") + ">" + i + textAppend + "</option>");
}
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();
}
/// <summary>
/// 압축 파일 풀기
/// </summary>
/// <param name="zipFilePath">ZIP파일 경로</param>
/// <param name="unZipTargetFolderPath">압축 풀 폴더 경로</param>
/// <param name="password">해지 암호</param>
/// <param name="isDeleteZipFile">zip파일 삭제 여부</param>
/// <returns>압축 풀기 성공 여부 </returns>
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();
}
/// <summary>
/// 사용자 인증체크시(로그인/본인인증) 특정ip또는host skip할건지 여부
/// <param name="gb">pwd:패스워드skip, smsauth:sms인증skip(</param>
/// <param name="ip"></param>
/// <param name="host"></param>
/// <returns>true:skip처리, false:skip하지않음</returns>
/// </summary>
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;
}
}