YNICTE/Base/Controller/FOCommon.cs

1140 lines
53 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NP.Model;
using System.Collections;
using NP.Base.Auth;
using NP.Base.ENUM;
using System.Web.ModelBinding;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace NP.Base.Controllers
{
public partial class FOCommonController : NP.Base.BaseController
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
}
protected override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);
if (Request.IsAjaxRequest())
{
filterContext.Result = new RedirectResult("/Account/NoPermit?_code=" + NP.Base.ENUM.JSONCode.Error + "&_msg=알수없는오류");
}
else
{
filterContext.Result = new RedirectResult("/Account/Error?_code=" + NP.Base.ENUM.JSONCode.Error + "&_msg=알수없는오류");
}
}
public JsonResult Html(int pno)
{
return JsonBack(Dao.Get<MenuPage>("mm.pages", new Hashtable() { { "pno", pno } }).First());
}
public JsonResult HidePop(int pno)
{
var p = CookieGet("popup", "");
CookieSet("popup", p == "" ? pno.ToString() : (p + "p" + pno), 7);
return JsonOK(1);
}
public void DownFile(Int64 fno, int getdel = 0, String loginfo = "", int issubject = 0)
{
Dao.Save("sys.file.down", fno);
var file = Dao.Get<File>("sys.file.get" + (getdel > 0 ? "all" : ""), fno).FirstOrDefault();
//if (!string.IsNullOrEmpty(loginfo))
//{
// LogSet(GetLong(loginfo.Split('|')[0]), null, fno, GetInt(loginfo.Split('|')[1]), 5, null);
//}
//if (((file.tablename ?? "").ToUpper() +"."+ (file.columnname??"").ToUpper()).Equals("삭제체크테이블.삭제체크컬럼"))
//{
// //프로젝트파일 권한 확인
// if (Dao.Get<int>("sys.file.authcheck.orderfgno", new Hashtable() { {"FGNo", file.fgno }, {"UserNo", SUserInfo.UserNo } }).First() < 1)
// {
// return;
// }
//}
//else if ((file.UsingTable ?? "").ToUpper().Equals("users.fgno"))
//{
// //이력서파일 권한 확인
// if (Dao.Get<int>("sys.file.authcheck.usersfgno", new Hashtable() { { "FGNo", file.FGNo }, { "UserNo", SUserInfo.UserNo } }).First() < 1)
// {
// return;
// }
//}
if (Request.UrlReferrer == null || (!SUserInfo.IsAdmin && file.tablename == "lectsd" && file.columnname == "fgno" && SUserInfo.UserNo != file.cno))
{
//Response.AppendHeader("Content-Disposition", cds.ToString());
//return File(string.Format("{0}\\{1}", uploadDir, entity.SaveFileName), "application/file");
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "Application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode("권한없음.png"));
//Response.AppendHeader("Content-Length", file.filesize.ToString());
Response.TransmitFile(string.Format("{0}", Server.MapPath("/img/repute_tail.png")));
Response.Flush();
Response.End();
}
else
{
string fileurl = Server.MapPath((issubject == 1 ? file.fullurl2 : file.fullurl));
//var cds = new System.Net.Mime.ContentDisposition
//{
// FileName = Server.UrlEncode(file.orgname), // 파일의 원래이름(등록할때의 이름)
// Inline = false,
//};
//Response.AppendHeader("Content-Disposition", cds.ToString());
//return File(string.Format("{0}\\{1}", uploadDir, entity.SaveFileName), "application/file");
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "Application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(file.orgname));
Response.AppendHeader("Content-Length", file.filesize.ToString());
Response.TransmitFile(string.Format("{0}", fileurl));
Response.Flush();
Response.End();
}
}
[HttpPost]
public JsonResult Login(VMUser vm, String uid, String upw, int logincnt, bool issaveid)
{
if (issaveid)
{
CookieSet("savedid", uid);
}
else
{
CookieClear("savedid");
}
if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(upw))
{
var u = GoLogin(uid, upw);
if (u != null)
{
if(u.intv1 == 1)
{
++logincnt;
if (logincnt > 4)
{
Dao.Save("users.disable", new Hashtable() { { "userno", u.userno } });
}
return JsonBack(new JsonRtn() { code = 1000, msg = "-4", obj = u.userno });
}
if (u.intv1 == 2 || u.status == 8) // 휴면상태 포함
{
// 비활성 상태(비번 5회 이상)
return JsonBack(new JsonRtn() { code = 1000, msg = "-5", obj = u.userno });
}
else
{
if (u.userno < 0)
{
return JsonBack(new JsonRtn() { code = 1000, obj = -1, msg = u.subdomain });
}
//비밀번호 변경 90일 경과
if (u.udt.AddDays(90) < DateTime.Now)
{
return JsonBack(new JsonRtn() { code = 1000, msg = "-2", obj = u.userno });
}
// 휴면상태
if (u.status == 8)
{
return JsonBack(new JsonRtn() { code = 1000, msg = "-3", obj = u.userno });
}
return JsonOK(u.userno);
}
}
}
return JsonOK(0);
}
/// <summary>
/// 비밀번호 변경 저장 (비밀번호 변경 90일 지난 사용자)
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
public JsonResult PwChange(VMUser vm)
{
if (string.IsNullOrEmpty(vm.User.userpass) || vm.User.userpass.Trim() == "")
{
Dao.Save("users.resetuserpass", new Hashtable() { { "userno", vm.userno } });
return JsonOK(1);
}
if (vm.userno > 0 && !string.IsNullOrEmpty(vm.User.userpass) && vm.User.userpass.Trim() != "")
{
//if (Dao.Save("users.resetuserpass", new Hashtable() { { "userpass", NP.Base.Lib.KISA_SHA256.SHA256Hash(vm.User.userpass) }, { "userno", vm.userno } }) == 1)
//{
// var u = GoLogin(vm.User.userid, vm.User.userpass);
// if (u != null)
// {
// return JsonOK(1);
// }
//}
if (Dao.Save("users.resetuserpass", new Hashtable() { { "userpass", NP.Base.Lib.KISA_SHA256.SHA256Hash(vm.User.userpass) }, { "userno", vm.userno } }) > 0)
{
var u = GoLogin(vm.User.userid, vm.User.userpass);
if (u != null)
{
return JsonOK(1);
}
}
}
return JsonOK(0);
}
/// <summary>
/// 휴면해제
/// </summary>
/// <param name="userno"></param>
/// <returns></returns>
public JsonResult DormantCancel(int userno)
{
if (Dao.Get<Users>("users.dormants", new Hashtable() { { "userno", userno } }).Count() < 1)
{
return JsonBack(new JsonRtn() { code = 1 });
}
var result = Dao.Save("users.dormant.cancel", new Hashtable() { { "usernos", userno }, { "uno", SUserInfo.UserNo }, { "uip", GetUserIP() } });
var user = Dao.Get<Users>("users.findmes", new Hashtable() { { "userno", userno } }).FirstOrDefault();
if (user != null)
{
var u = GoLogin(user.userid, "rhksflwkfhrmdls999");
if (u != null)
{
return JsonOK(result);
}
else
{
return JsonBack(new JsonRtn() { code = 2 });
}
}
return JsonOK(0);
}
[HttpPost]
public JsonResult GetBoards(int btype, int pn, int prc, String sc)
{
return JsonBackList<Board>(Dao.Get<Board>("board.list", new Hashtable() { { "BType", btype }, { "SubjectContents", sc.Trim() == "" ? null : sc.Trim() }, { "PAGENUM", pn }, { "PAGEROWSIZE", prc } }));
}
[HttpPost]
public JsonResult CMInnings(int cmno)
{
return JsonBack(Dao.Get<CMInning>("cm.cminnings", new System.Collections.Hashtable() { { "cmno", cmno } }));
}
[HttpPost]
public JsonResult CMRelays(int cmno)
{
var cms = Dao.Get<CM>("cm.cmrelays", new System.Collections.Hashtable() { { "cmno", cmno }, { "userno", SUserInfo.UserNo } });
return JsonBack(new Hashtable() { { "pre", cms.Where(w => w.ispre == 1).ToList() }, { "after", cms.Where(w => w.ispre == 0).ToList() } });
}
[HttpPost]
public JsonResult AssignFind(String brno, int? pno)
{
brno = (brno ?? "").Replace("-", "");
return JsonBack(Dao.Get<Assign>("users.assigns", new Hashtable() { { "brno", brno }, { "pagenum", pno }, { "pagerowsize", 10 } }));
}
[HttpPost]
public JsonResult AssignSave(String brno, String asname,String ceoname)
{
var ht = new Hashtable() { { "asno", 0 }, { "isjoin", 0 }, { "ascode", Dao.Get<int>("users.assign.newascode", 1).First() }, { "joinprice", 0 }, { "asname", asname }, { "brno", brno.Replace("-", "")}, { "ceoname", ceoname }, { "salesamount", 0 }, { "mcount", 0 }, { "status", 1 }, { "isdel", 0 }, { "uno", SUserInfo.UserNo }, { "uip", GetUserIP() } };
Dao.Insert("users.assign.in", ht);
return JsonOK(GetInt(ht["asno"]));
}
[HttpPost]
public JsonResult Join(Users u)
{
u.uip = GetUserIP();
//이메일, 아이디 중복 체크
var u129 = Dao.Get<int>("users.checkuser", new Hashtable() { { "userid", u.userid }, { "email", u.email },{"mobile",u.mobile } }).First();
if (u129 != 9)
{
return JsonOK(u129 * -1);
}
u.userpass = NP.Base.Lib.KISA_SHA256.SHA256Hash(u.userpass.Trim());
u.birthday = u.birthday != null && u.birthday.Length == 8 ? (u.birthday ?? "").Substring(0, 4) + "-" + (u.birthday ?? "").Substring(4, 2) + "-" + (u.birthday ?? "").Substring(6, 2) : null;
u.usertype = u.status = 1;
Dao.Insert("users.in", u);
return JsonOK(u.userno);
}
// 이후 전문건설과 같이 본인인증시 팝업을 제한할 경우 Join -> Join_new 서로 매서드 변경할것
public JsonResult Join_new(Users u)
{
if (!string.IsNullOrWhiteSpace(u.zstring0))
{
// 인증 후 okcert3log.no와 sn 값으로 인증된 결과값 가져오기
string decStr = DecString(u.zstring0);
string[] tempArr = decStr.Split(',');
string gubn = tempArr[2];
ViewBag.reason = tempArr[3];
ViewBag.rsltCd = tempArr[4];
string certiOkData = Dao.Get<string>("sys.okcert3.get", new Hashtable { { "no", tempArr[0] }, { "sn", tempArr[1] } }).FirstOrDefault();
JObject data = JObject.FromObject(JsonConvert.DeserializeObject(certiOkData));
// 인증 후 강제로 수정된 정보를 인증 정보로 대체하기
u.username = data["RSLT_NAME"].ToString();
u.ci = data["CI"].ToString();
u.di = data["DI"].ToString();
u.birthday = data["RSLT_BIRTHDAY"].ToString();
if(gubn == "MOBI")
{
u.mobile = data["TEL_NO"] == null ? "" : data["TEL_NO"].ToString();
}
u.vssn = data["VSSN"] == null ? "" : data["VSSN"].ToString();
u.uip = GetUserIP();
//이메일, 아이디 중복 체크
var u129 = Dao.Get<int>("users.checkuser", new Hashtable() { { "userid", u.userid }, { "email", u.email }, { "mobile", u.mobile } }).First();
if (u129 != 9)
{
return JsonOK(u129 * -1);
}
u.userpass = NP.Base.Lib.KISA_SHA256.SHA256Hash(u.userpass.Trim());
u.birthday = u.birthday != null && u.birthday.Length == 8 ? (u.birthday ?? "").Substring(0, 4) + "-" + (u.birthday ?? "").Substring(4, 2) + "-" + (u.birthday ?? "").Substring(6, 2) : null;
u.usertype = u.status = 1;
Dao.Insert("users.in", u);
return JsonOK(u.userno);
}
else
{
return JsonOK(0);
}
}
[HttpPost]
public JsonResult FindMe(String email)
{
if (string.IsNullOrEmpty(email)) { return JsonOK(-1); }
email = email.Replace(" ", "").Replace(" ", "");
List<Users> users = new List<Users>() { };
bool IsEmail = false;
if (email.Contains("@"))
{
IsEmail = true;
users = Dao.Get<Users>("users.findme", new Hashtable() { { "email", email } }).ToList();
if(users.Count() < 1)
{
// user 테이블 검색 뒤 없을 경우 휴면테이블에서 검색
users = Dao.Get<Users>("users.findmes", new Hashtable() { { "email", email } }).ToList();
}
}
//else
//{
// users = Dao.Get<Users>("users.findme", new Hashtable() { { "Mobile1", em }, { "Mobile2", em.Replace("-", "") } }).ToList();
//}
if (users.Count() != 1)
{
//검색결과 2개 개정이라면 보내면 안됨..다른사람일 수도
return JsonOK(-1);
}
var user = users.First();
//메시지 전송시간 기록
Random r = new Random();
int pwcallno = r.Next(1, 30000);
Dao.Save("users.pwcalltime", new Hashtable() { { "userno", user.userno }, { "pwcallno", pwcallno } });
var masteremail = GetConfig("masteremail");
String fronturl = GetConfig("fronturl");
//if (IsEmail)
//{
//var et = Dao.Get<MailTP>("mm.mailtp.get", 1).FirstOrDefault();
//var MHtml = "";
//if (et != null)
//{
// MHtml = et.MHtml.Replace("src=\"/Files/Editor", "src=\"" + fronturl + "/Files/Editor").Replace("^비밀번호링크^", fronturl + "/Account/FindMe?PWCallNo=" + pwcallno + "&UserNo=" + user.UserNo).Replace("^회원명^", user.UserName).Replace("../img/", fronturl + "/img/").Replace("^fronturl^", fronturl);
//}
//else
//{
var MHtml = "<img src=\"" + fronturl + "/img/common/gnb_logo.gif\" alt=\"\" /><br /><br />안녕하세요, " + user.username + "님,<br />당신의 영남건설기술교육원 비밀번호를 재설정하기 위한 링크를 전달합니다.<br />" +
"아래 링크를 클릭하셔서 비밀번호를 재설정해주세요.<br /><br />" +
"<a href=\"" + fronturl + "/Account/FindMe?pwcallno=" + pwcallno + "&userno=" + user.userno + "\" target=\"_blank\" style=\"color: #0094ff;\">비밀번호 재설정</a><br /><br />이 링크는 24시간 뒤 만료됩니다.";
//}
//return JsonOK(SendEmail(0, user.userid, null, null, user.username + "님, 유앤파트너즈 비밀번호를 재설정할 수 있는 링크를 전달합니다.", MHtml));
return JsonOK(SendEmail(masteremail.Split(';')[1], GetInt(masteremail.Split(';')[2]), masteremail.Split(';')[3], masteremail.Split(';')[4], 999, user.email, masteremail.Split(';')[0], "영남건설기술교육원 운영자", "[영남건설기술교육원] 비밀번호 찾기 안내", MHtml, "", "0:0"));
//}
//else
//{
// var html = "회원님의 이메일주소는 " + user.UserId + " 아래 링크를 클릭해주셔서 인증을 완료해주세요. [" + fronturl + "/Account/FindMe?PWCallNo=" + pwcallno + "&UserNo=" + user.UserNo + "]";
// return JsonOK(SendSms(null, user.Mobile, "[유앤파트너즈] 계정찾기", html, null, true, "7"));
// //Sms.Save("test", new Hashtable() { });
// //return JsonOK(1);
//}
}
[HttpPost]
public JsonResult FindMeFinal(VMUser vm)
{
if (vm.userno > 0 && vm.pwcallno > 0 && !string.IsNullOrEmpty(vm.User.userpass) && vm.User.userpass.Trim() != "")
{
if (Dao.Save("users.resetuser", new Hashtable() { { "userpass", NP.Base.Lib.KISA_SHA256.SHA256Hash(vm.User.userpass) }, { "userno", vm.userno }, { "pwcallno", vm.pwcallno } }) == 1)
{
//자동로그인처리
var u = GoLogin(vm.User.userid, vm.User.userpass);
if (u != null)
{
return JsonOK(1);
}
}
}
return JsonOK(0);
}
[HttpPost]
public JsonResult MyPageLeftMenu(String on)
{
CookieSet("mypageleftmenutoggle", on);
return JsonOK(1);
}
[HttpPost]
public JsonResult CRoomPageLeftMenu(String on)
{
CookieSet("croompageleftmenutoggle", on);
return JsonOK(1);
}
[HttpPost]
public JsonResult IsAuth()
{
if (SUserInfo.UserNo > 0)
{
return JsonOK(1);
}
return JsonOK(0);
}
[HttpPost]
/// 반환값이 100일때 플레이바 및 다음페이지이동 허용
public JsonResult PRGRS(Int64 lectno, Int64 cmino)
{
if (SUserInfo.UserNo > 0)
{
try
{
return Json(Dao.Get<int>("cr.getprogress", new Hashtable() { { "lectno", lectno }, { "cmino", cmino } }).First(), JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return Json(-1, JsonRequestBehavior.AllowGet);
}
[HttpPost]
public JsonResult StudyLog(Int64 logno, Int64 lectno, Int64 cmino, int cpno, int studysec, int ispc, int nextcpno, int getiframe, int issample = 0, int psec = 0)
{
if (SUserInfo.UserNo > 0 || issample > 0)
{
int rtn = 0;
if (issample < 1)
{
rtn = Dao.Save("cr.studylog", new Hashtable() { { "logno", logno }, { "lectno", lectno }, { "cmino", cmino },{ "userno",SUserInfo.UserNo},
{"psec", psec },
{ "cpno", cpno }, { "studysec", studysec }, { "ispc", ispc }, {"uno", SUserInfo.UserNo },{"uip",GetUserIP() } });
}
if (nextcpno > 0)
{
String ua = "";
try
{
ua = (Request.UserAgent ?? "").ToLower();
}
catch (Exception ex)
{
Logger.Error("ExamStart Get UserAgent Info Error" + ex.StackTrace);
}
var lip = new LectInningPage() { lectno = lectno, cmino = cmino, cpno = nextcpno, userno = SUserInfo.UserNo, uno = SUserInfo.UserNo, uip = GetUserIP(), ispc = ispc, webkitinfo = ua };
if (issample < 1)
{
Dao.Insert("cr.lectinningpage.in", lip);
if (lip.logno < 1 || getiframe == 0)
{
return JsonOK(lip.logno);
}
}
return JsonBack(new JsonRtn() { code = 1000, msg = Dao.Get<String>("cr.ctpage.iframe", new Hashtable() { { "cpno", nextcpno }, { "src", ispc > 1 ? "srcp" : "srcm" } }).First(), obj = lip.logno });
}
return JsonOK(rtn);
}
else
{
return JsonOK(0);
}
}
[HttpPost]
public JsonResult StudyClose(Int64 logno, int issample = 0)
{
if (SUserInfo.UserNo > 0 || issample > 0)
{
int rtn = 0;
if (issample < 1)
{
rtn = Dao.Save("cr.studyclose", new Hashtable() { { "logno", logno }, {"uno", SUserInfo.UserNo },{"uip",GetUserIP() } });
}
return JsonOK(rtn);
}
else
{
return JsonOK(0);
}
}
[HttpPost]
public JsonResult checklectdate(Int64 lectno)
{
Lect lect = Dao.Get<Lect>("cr.checklectdate", new Hashtable() { { "lectno", lectno } }).First();
if (DateTime.Now <= lect.edate) //lect.수강종료일 이후 클릭시, 학습만 허용하나 로그는 쌓지 않음
return Json(new { result = 1 });
else
return Json(new { result = -1 });
}
[HttpPost]
public JsonResult StudyLogMid(Int64 lectno, Int64 cmino)
{
if (SUserInfo.UserNo > 0)
{
return JsonOK(Dao.Save("cr.studymid", new Hashtable() { { "lectno", lectno }, { "cmino", cmino } }));
}
return JsonOK(0);
}
[HttpPost]
public JsonResult CheckInningChange(Int64 lectno, Int64 cmino, bool ispre)
{
if (SUserInfo.UserNo > 0)
{
var cmi = Dao.Get<LectInning>("cr.inningchange." + (ispre ? "pre" : "next"), new Hashtable() { { "lectno", lectno }, { "cmino", cmino } }).FirstOrDefault();
if (cmi == null)
{
return JsonBack(new JsonRtn() { code = 1000, obj = -1 });
}
else if (cmi.iseq > 1 && cmi.precmino > 0 && cmi.isseq == 1 && cmi.preistatus != 2)
{
return JsonBack(new JsonRtn() { code = 1000, obj = -2 });
}
else
{
var intval = Dao.Get<LectInning>("cr.lectinnings", new System.Collections.Hashtable() { /*{ "lectno", lectno }*/ { "userno",SUserInfo.UserNo}, { "isfinishtoday", 1 } }).Count();
if (intval > Convert.ToInt32((GetConfig("inninglimit") ?? "10")) && cmi.istatus < 2)
{
return JsonBack(new JsonRtn() { code = 1000, obj = -3 });
}
}
return JsonOK(cmi.cmino);
}
return JsonOK(0);
}
[HttpPost]
public JsonResult idchk(String id)
{
//이메일, 아이디 중복 체크
var u129 = Dao.Get<Users>("users.usersbyuserids", new Hashtable() { { "userids", "'"+id+"'" },{"usertype",1} });
if (u129.Count() > 0)
{
return JsonOK(-1);
}
return JsonOK(1);
}
[HttpPost]
public JsonResult GetSubCm(int cmno, int? studyplace = null)
{
//20220726 소스 정리
Hashtable hsData = new Hashtable();
hsData.Add("cmno", cmno);
hsData.Add("studyplace", studyplace);
var result = Dao.Get<CM>("cm.subcms", hsData).Where(w => w.isuse == 1).ToList();
//var result = Dao.Get<CM>("cm.subcms", new System.Collections.Hashtable() { { "cmno", cmno }, { "studyplace", studyplace } }).Where(w => w.isuse == 1).ToList();
return JsonBack(result);
}
[HttpPost]
public JsonResult GetCmUser(int cmno)
{
var comcodes = GetComCodes("typeman,typeedu,typegrade,typejob", true);
var result = Dao.Get<CM>("cm.cmuser", new System.Collections.Hashtable() { { "cmno", cmno } });
foreach (var r in result)
{
string[] typemanArr = r.typeman.Split(',');
for (int i = 0; i < typemanArr.Length; i++)
{
r.typemans += comcodes.Where(x => x.cgroup == "typeman" && x.ccode == Convert.ToInt32(typemanArr[i])).FirstOrDefault().cname;
if (i < typemanArr.Length -1)
r.typemans += ",";
}
string[] typeeduArr = r.typeedu.Split(',');
for (int i = 0; i < typeeduArr.Length; i++)
{
r.typeedus += comcodes.Where(x => x.cgroup == "typeedu" && x.ccode == Convert.ToInt32(typeeduArr[i])).FirstOrDefault().cname;
if (i < typeeduArr.Length - 1)
r.typeedus += ",";
}
string[] typegradeArr = r.typegrade.Split(',');
for (int i = 0; i < typegradeArr.Length; i++)
{
r.typegrades += comcodes.Where(x => x.cgroup == "typegrade" && x.ccode == Convert.ToInt32(typegradeArr[i])).FirstOrDefault().cname;
if (i < typegradeArr.Length - 1)
r.typegrades += ",";
}
string[] typejobArr = r.typejob.Split(',');
for (int i = 0; i < typejobArr.Length; i++)
{
r.typejobs += comcodes.Where(x => x.cgroup == "typejob" && x.ccode == Convert.ToInt32(typejobArr[i])).FirstOrDefault().cname;
if (i < typejobArr.Length - 1)
r.typejobs += ",";
}
}
return JsonBack(result);
}
[HttpPost]
public JsonResult GetScdForMixEdu(int cmno,int? lectno, int? month, int? studyPlace)
{
Hashtable hsData = new Hashtable();
hsData.Add("cmno", cmno);
hsData.Add("lectno", lectno);
hsData.Add("month", month);
hsData.Add("studyplace", studyPlace);
var result = Dao.Get<CMinningscd>("cm.cminningscds.applyedu" + (lectno != null ? ".lectno" : ""), hsData);
IList<CMinningscd> result2 = new List<CMinningscd>();
if (result.Count() > 0)
{
long cmino = result.First().cmino;
result2 = Dao.Get<CMinningscd>("cm.cminningscds.attr2Check", new System.Collections.Hashtable() { { "cmno", cmno }, { "cmino", cmino } });
}
hsData.Clear();
hsData.Add("cmno", cmno);
var resultTmp = Dao.Get<CM>("cm.cms", hsData).FirstOrDefault();
//var result = Dao.Get<CMinningscd>("cm.cminningscds.applyedu"+(lectno != null ? ".lectno" : ""), new System.Collections.Hashtable() { { "cmno", cmno },{"lectno",lectno }, { "month", (month == null) ? null : month } });
DateTime now = DateTime.Now;
result = result.Where(c => c.estart > now.AddYears(-1) && c.estart < now.AddYears(1) && c.estart > now.AddDays(2)).ToList();
foreach (var item in result)
{
//item.scdInfoSummary = string.Format("[{0}] {1}", item.studyplacename, item.estart.ToString("yyyy년 MM월 dd일 ddd요일 HH:mm"));
//item.scdInfoSummary = string.Format("{0}", item.estart.ToString("yyyy년 MM월 dd일까지"));
if (resultTmp.cshape == 1)
{
item.scdInfoSummary = string.Format("{0} ~ {1}", item.estart.ToString("yyyy년 MM월 dd일"), item.eend.ToString("MM월 dd일"));
}
else
{
//item.scdInfoSummary = string.Format("{0}", item.estart.ToString("yyyy년 MM월 dd일까지"));
item.scdInfoSummary = string.Format("{0}", item.estart.ToString("yyyy년 MM월 dd일"));
}
if (item.estart < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")))
item.isEnd = true;
if (result2.Count() > 0)
{
item.intv1 = result2.Where(c => c.cmino == item.cmino && c.cmisno == item.cmisno && c.intv1 == 2).Count();
item.remainPeople += item.intv1;
}
}
return JsonBack(result);
}
[HttpPost]
public JsonResult GetCheckLectIsComplete(int cmno)
{
var result = Dao.Get<int>("cm.lectcheckuser", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo },{ "cmno", cmno } }).First();
return JsonBack(result);
}
[HttpPost]
/// ### ty 교육신청제한
public JsonResult GetCheckLectIs(string man, string cgcode, string edu, string grade, int cmno, int pcmno)
{
int result = 0; // 0 이면 수강 가능, 그외 수강 불가
result = CheckUserLect(man, cgcode, edu, grade, cmno, pcmno, SUserInfo.UserNo);
return JsonBack(result);
}
// pms: 5640 적용
public int CheckUserLect(string man, string cgcode, string edu, string grade, int cmno, int pcmno, long userno)
{
int result = 0; // 1:신청불가, 0:신청가능
int rst = 0;
string[] cgcodes = new string[0];
string[] edus = new string[0];
// 29:기본교육 ,30:최초교육 ,31:계속교육 ,32:안전관리계속교육(16시간) ,33:PQ가점교육 ,34:기타교육 ,35:승급교육
// 36:초급 ,37:중급 ,38:고급 ,39:특급
cgcodes = "102,103,104,105".Split(','); // 직무분야:(102), 역량강화:(103,104), 전문분야(105)
edus = "30,31,35".Split(','); // 최초교육, 계속교육, 승급교육
// man == 28 : 건설사업관리기술인(typeman)
if (man == "28" && cgcodes.Contains(cgcode) && edus.Contains(edu))
{
switch(cgcode)
{
case "102": // 직무분야
if(edu == "35" && (grade == "38" || grade == "39")) // 승급교육 && (고급 || 특급)
{
// '(역량강화 또는 전문분야) + 직무분야' 조건에 의하여 직무분야 1건이상 신청불가
rst = Dao.Get<int>("lect.count.user6", new Hashtable() { { "userno", userno }, { "pcmno", pcmno } }).First();
}
break;
case "103": // 역량강화
case "104":
switch (edu)
{
case "30": // 최초교육
// 1건이상 신청불가
rst = Dao.Get<int>("lect.count.user5", new Hashtable() { { "userno", userno }, { "cgcode", cgcode }, { "edu", edu }, { "grade", grade }, { "cmno", cmno }, { "pcmno", pcmno } }).First();
break;
case "31": // 계속교육
if(grade == "36" || grade == "37") // 초급 || 중급
{
result = 1; // 신청불가
}
// 그외는 제한 없음
break;
case "35": // 승급교육
if(grade == "38" || grade == "39")
{
// '(역량강화 또는 전문분야) + 직무분야' 조건에 의하여 역량강화 또는 전문분야중 1건이상 신청불가
rst = Dao.Get<int>("lect.count.user6", new Hashtable() { { "userno", userno }, { "pcmno", pcmno } }).First();
}
// 그외는 제한 없음
break;
}
break;
case "105": // 전문분야
switch(edu)
{
case "30": // 최초교육
result = 1; // 신청불가
break;
case "31": // 계속교육
if (grade == "36" || grade == "37") // 초급 || 중급
{
result = 1; // 신청불가
}
// 그외는 제한 없음
break;
case "35": // 승급교육
if (grade == "36" || grade == "37") // 초급 || 중급
{
result = 1; // 신청불가
}
else
{
// '(역량강화 또는 전문분야) + 직무분야' 조건에 의하여 역량강화 또는 전문분야중 1건이상 신청불가
rst = Dao.Get<int>("lect.count.user6", new Hashtable() { { "userno", userno }, { "pcmno", pcmno } }).First();
}
break;
}
break;
}
}
if (result == 0)
{
//-1= 짧은문구, smartSearch에서 오류중 짧은문구 처리할 경우 -1를 곱하여 0이하값 만들어야함
result = rst == 0 ? 0 : ((rst > 0) ? 1 : -1); //
}
return result;
}
public int CheckUserLectOld_backukp241007(string man, string cgcode, string edu, string grade, int cmno, int pcmno, long userno)
{
int result = 0;
int rst = 0;
string[] cgcodes = new string[0];
string[] edus = new string[0];
// 29:기본교육 ,30:최초교육 ,31:계속교육 ,32:안전관리계속교육(16시간) ,33:PQ가점교육 ,34:기타교육 ,35:승급교육
// 36:초급 ,37:중급 ,38:고급 ,39:특급
cgcodes = "103,104,105".Split(',');
edus = "30,31,35".Split(','); // 최초교육, 계속교육, 승급교육
// man == 28 : 건설사업관리기술인(typeman)
if (man == "28" && cgcodes.Contains(cgcode) && edus.Contains(edu))
{
// 계속교육(31)
if (edu == "31" && (cgcode == "103" || cgcode == "104") && (grade == "36" || grade == "37")) // 계속교육, (103 or 104), (초급 or 중급)
{
result = 1; // 신청불가
}
else
{
// 갯수를 가져오기
// 최초교육(30)
if (edu == "30" && cgcode == "105") // 최초교육 , 105
{
rst = 0; // 신청가능
}
// 계속교육(31)
else if (edu == "31" && cgcode == "105" && (grade == "36" || grade == "37")) // 계속교육, 105, (초급 or 중급)
{
rst = 0; // 신청가능
}
// 승급교육(35)
else if (edu == "35" && (cgcode == "103" || cgcode == "104" || cgcode == "105") && (grade == "36" || grade == "37")) // 승급교육, (103 or 104 or 105), (초급 or 중급)
{
rst = 0; // 신청가능
}
else
{
/*
* 기본 설계 쿼리
select t5.typegrade, t5.typeman, t5.typeedu, t3.cgcode, t1.lectno, t1.userno
from lect t1
inner join cm t2 on t1.cmno = t2.cmno
inner join cg t3 on t2.cgno= t3.cgno
inner join pay t4 on t1.payno = t4.payno
inner join pplog t5 on t1.cmno= t5.cmno and t1.userno = t5.userno and t4.pplno = t5.pplno
where t1.status = 1 and t4.pstatus= 1
and t3.cgcode = 103 -- and t1.userno=82 -- 82,5,31
// 29:기본교육 ,30:최초교육 ,31:계속교육 ,32:안전관리계속교육(16시간) ,33:PQ가점교육 ,34:기타교육 ,35:승급교육
// 36:초급 ,37:중급 ,38:고급 ,39:특급
*/
// "lect.count.user2" > 103,104,105
// "lect.count.user3" > 103,104
if ((edu == "31" || edu == "35") && (grade == "38" || grade == "39")) // 계속교육, 승급교육 && 고급, 특급
{
var lectCount = Dao.Get<int>("lect.count.user2", new Hashtable() { { "userno", userno }, { "cgcode", cgcode }, { "edu", edu }, { "grade", grade }, { "cmno", cmno }, { "pcmno", pcmno } });
rst = lectCount.First();
}
else if ((cgcode == "103" || cgcode == "104") && edu == "30") // 최초
{
var lectCount = Dao.Get<int>("lect.count.user3", new Hashtable() { { "userno", userno }, { "cmno", cmno }, { "pcmno", pcmno } });
rst = lectCount.First();
}
else
{
var lectCount = Dao.Get<int>("lect.count.user", new Hashtable() { { "userno", userno }, { "cgcode", cgcode }, { "edu", edu }, { "cmno", cmno }, { "pcmno", pcmno } });
rst = lectCount.First();
}
}
}
}
if (result == 0)
{
//-1= 짧은 문구
result = rst == 0 ? 0 : ((rst > 0) ? 1 : -1); //
}
return result;
}
/// <summary>
/// 교육신청 제한 해제시 GetCheckLectIs_stay를 GetCheckLectIs로 변경하여 반영한다.
/// </summary>
/// <param name="man"></param>
/// <param name="cgcode"></param>
/// <param name="edu"></param>
/// <param name="grade"></param>
/// <param name="cmno"></param>
/// <param name="pcmno"></param>
/// <returns></returns>
public JsonResult GetCheckLectIs_stay(string man, string cgcode, string edu, string grade, int cmno, int pcmno)
{
int result = 0; // 0 이면 수강 가능, 그외 수강 불가
return JsonBack(result);
}
/// <summary>
/// 수강신청시 가능인원 체크하기
/// 20220803
/// </summary>
/// <param name="cmisno"></param>
/// <returns></returns>
[HttpPost]
public JsonResult CheckQtyScd(int cmno, int cmino, int cmisno)
{
var pass = Dao.Get<int>("cm.cminningscdcheck", new System.Collections.Hashtable() { { "cmisno", cmisno }}).First();
IList<CMinningscd> result2 = Dao.Get<CMinningscd>("cm.cminningscds.attr2Check", new System.Collections.Hashtable() { { "cmno", cmno }, { "cmino", cmino }, { "cmisno", cmisno } });
if(result2.Count() > 0)
{
int addPass = result2.Where(c => c.intv1 == 2).Count();
pass += addPass;
}
if (pass == 0)
{
return JsonBack(new JsonRtn() { code = 0, msg = "해당 일정은 모집 인원이 마감되었습니다." });
}
else if (pass > 0)
{
return JsonBack(new JsonRtn() { code = 1000, msg = "" });
}
return JsonBack(new JsonRtn() { code = -1, msg = "개발자에게 문의하세요." });
}
/// <summary>
///
/// </summary>
/// <param name="cmisno"></param>
/// <param name="lectno"></param>
/// <returns></returns>
[HttpPost]
public JsonResult UpdateScd(int cmno, int cmino, int cmisno, int lectno)
{
var pass = Dao.Get<int>("cm.cminningscdcheck", new System.Collections.Hashtable() { { "cmisno", cmisno } }).First();
IList<CMinningscd> result2 = new List<CMinningscd>();
result2 = Dao.Get<CMinningscd>("cm.cminningscds.attr2Check", new System.Collections.Hashtable() { { "cmno", cmno }, { "cmino", cmino } });
if (result2.Count() > 0)
{
int tempInt = result2.Where(c => c.cmino == cmino && c.cmisno == cmisno && c.intv1 == 2).Count();
pass += tempInt;
}
if (pass == 0)
return JsonBack(new JsonRtn() { code = 0, msg = "해당 일정은 모집 인원이 마감되었습니다." });
else if (pass > 0)
{
Dao.Save("cm.lectcmisno.up" , new System.Collections.Hashtable() { { "cmisno", cmisno }, { "lectno", lectno }, { "uno", SUserInfo.UserNo }, { "uip", GetUserIP() } });
return JsonBack(new JsonRtn() { code = 1, msg = "일정을 변경하였습니다." });
}
return JsonBack(new JsonRtn() { code = -1, msg = "개발자에게 문의하세요." });
}
[HttpPost]
public JsonResult CheckExistSnsId(string snsid, int jointype)
{
var result = Dao.Get<Users>("users.check.snsid", new Hashtable() { { "snsid", snsid }, { "jointype", jointype } }).Count();
if (result > 0)
{
return JsonBack(new JsonRtn() { code = 1 });
}
else
{
return JsonBack(new JsonRtn() { code = -1 });
}
}
[HttpPost]
public JsonResult SnsLogin(String uid, bool isSns = false)
{
if (!string.IsNullOrEmpty(uid))
{
var u = GoLogin(uid, "", isSns);
if (u != null)
{
if (u.userno < 0)
{
return JsonBack(new JsonRtn() { code = 1000, obj = -1, msg = u.subdomain });
}
return JsonOK(u.userno);
}
}
return JsonOK(0);
}
[HttpPost]
public JsonResult SnsLink(String snsid, int jointype = 0)
{
try
{
if (string.IsNullOrEmpty(snsid) && jointype == 0) //SNS 연동을 해제
{
Dao.Save("users.snslink.up", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo }, { "snsid", snsid }, { "jointype", jointype }, { "uno", SUserInfo.UserNo }, { "uip", GetUserIP() } });
return JsonBack(new JsonRtn() { code = 1 });
}
else //SNS 연동
{
var result = Dao.Get<Users>("users.check.snsid", new Hashtable() { { "snsid", snsid }, { "jointype", jointype } }).Count();
if (result > 0) //SNS 연동 중복체크
{
return JsonBack(new JsonRtn() { code = -99 });
}
else
{
Dao.Save("users.snslink.up", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo }, { "snsid", snsid }, { "jointype", jointype }, { "uno", SUserInfo.UserNo }, { "uip", GetUserIP() } });
return JsonBack(new JsonRtn() { code = 1 });
}
}
}
catch (Exception e)
{
return JsonBack(new JsonRtn() { code = -1 });
}
}
[HttpPost]
public JsonResult SendLakey(Int64 lectno, String mobile)
{
Random r = new Random();
int lakey = r.Next(100000, 999999);
SmsAuth sa = new SmsAuth() { lakey = lakey.ToString(),lectno=lectno };
String msg = "[영남건설기술교육원]\n\n영남건설기술교육원 인증번호 [" + lakey + "] 입니다.";
var users = Dao.Get<Users>("users.findme", new Hashtable() { { "mobile", mobile } }).ToList();
if(users.Count() == 0)
{
return JsonBack(new JsonRtn() { code = -2 });
}
if(users.Count() != 1)
{
return JsonBack(new JsonRtn() { code = -1 });
}
Dao.Insert("common.smsauth", sa);
IList<NP.Model.MemoUser> us = new List<NP.Model.MemoUser>();
us.Add(new MemoUser()
{
userno = SUserInfo.UserNo,
mobile = mobile,
title = "인증번호",
mcontents = msg,
smstype = "A",
isok = 1
});
SaveTalk(us, "alarm");
//Dao.Insert("common.atalk.send", new Hashtable() { { "senderkey", GetConfig("mastersms").Split(';')[0] }, { "method", "alarm" }, { "DEST_PHONE", mobile.Replace(" ", "").Replace("-", "") }, { "SEND_PHONE", GetConfig("mtssendnum").Split(';')[0] }, { "title", "인증번호" }, { "MSG_BODY", msg }, { "replace_type", "S" } });
return JsonOK(sa.authno);
}
[HttpPost]
public JsonResult ExtendLakey(int authno)
{
return JsonOK(Dao.Save("common.sms.extend", new Hashtable() { { "authno", authno } }));
}
[HttpPost]
public JsonResult ChkLakey(String lakey, int authno)
{
IList<Data> datas = Dao.Get<Data>("common.sms.chk", new Hashtable() { { "authno", authno } });
if (datas.Count() < 1)
{
return JsonOK(0);
}
else if (datas.Where(w => w.strval.Replace(" ", "").Equals(lakey.Replace(" ", "")) && w.time.AddMinutes(3) < DateTime.Now).Count() > 0)
{
return JsonBack(new JsonRtn() { code = 1 });
}
else if (datas.Where(w => w.strval.Replace(" ", "").Equals(lakey.Replace(" ", "")) && w.time.AddMinutes(3) >= DateTime.Now).Count() > 0)
{
Dao.Save("lect.isatt.in", new System.Collections.Hashtable() { { "lectno", datas.FirstOrDefault().intval2 }, { "lakey", datas.FirstOrDefault().strval } });
return JsonBack(new JsonRtn() { code = 1000, obj = datas.First() });
}
return JsonOK(0);
}
[HttpPost]
public JsonResult ChkLakeyForLectinning(String lakey, int authno, long cmino)
{
IList<Data> datas = Dao.Get<Data>("common.sms.chk", new Hashtable() { { "authno", authno } });
if (datas.Count() < 1)
{
return JsonOK(0);
}
else if (datas.Where(w => w.strval.Replace(" ", "").Equals(lakey.Replace(" ", "")) && w.time.AddMinutes(3) < DateTime.Now).Count() > 0)
{
return JsonBack(new JsonRtn() { code = 1 });
}
else if (datas.Where(w => w.strval.Replace(" ", "").Equals(lakey.Replace(" ", "")) && w.time.AddMinutes(3) >= DateTime.Now).Count() > 0)
{
var lectno = datas.FirstOrDefault().intval2;
var lectInnings = Dao.Get<LectInning>("cr.cminnings", new System.Collections.Hashtable() { { "lectno", lectno }, { "userno", SUserInfo.UserNo } });
if (lectInnings.Where(w => w.cmino == cmino).Count() > 0)
{
var Hashtable = new System.Collections.Hashtable() {
{ "lectno", lectno },
{ "cmino", cmino },
{ "isattcheck", 1 },
{ "userno", SUserInfo.UserNo },
{ "uno", SUserInfo.UserNo },
{ "uip", GetUserIP() }
};
Dao.Save("lect.lectinning.isatt.in", Hashtable);
return JsonBack(new JsonRtn() { code = 1000, obj = datas.First() });
}
}
return JsonOK(0);
}
[HttpPost]
public JsonResult PageLearningTotalTime(Int64 lectno, Int64 cmino, int cpno)
{
if (SUserInfo.UserNo > 0)
{
var totstudy = Dao.Get<int>("cr.lectinningpage.totstudy", new Hashtable() { { "lectno", lectno }, { "cmino", cmino }, { "cpno", cpno } }).First();
return JsonOK(totstudy, true);
}
return JsonOK(0);
}
public JsonResult GetOkCert3Rslt(string stringval)
{
stringval = string.IsNullOrWhiteSpace(stringval) ? "" : stringval.Trim();
//string result = "NoCert"; // 초기값
OkCert3Result result = new OkCert3Result();
result.rsltCd = "NoCert";
if (!string.IsNullOrWhiteSpace(stringval))
{
stringval = HttpUtility.UrlDecode(stringval);
string decStr = DecString(stringval);
string tempStr = "";
string[] tempArr = decStr.Split(',');
string gubn = tempArr[2];
result.reasonNo = int.Parse(tempArr[3].ToString());
result.rsltCd = tempArr[4];
string certiOkData = Dao.Get<string>("sys.okcert3.get", new Hashtable { { "no", tempArr[0] }, { "sn", tempArr[1] } }).FirstOrDefault();
JObject data = JObject.FromObject(JsonConvert.DeserializeObject(certiOkData));
result.no = long.Parse(tempArr[0]);
result.sn = tempArr[1];
result.gubn = gubn;
result.ci = data["CI"].ToString();
result.di = data["DI"].ToString();
result.username = data["RSLT_NAME"].ToString();
result.birthday = data["RSLT_BIRTHDAY"].ToString();
result.mobile = data["TEL_NO"] == null ? "" : data["TEL_NO"].ToString();
result.vssn = data["VSSN"] == null ? "" : data["VSSN"].ToString();
if (!string.IsNullOrWhiteSpace(result.mobile))
{
tempStr = result.mobile.Trim();
if (tempStr.Length == 10)
{
result.mobile = tempStr.Substring(0, 3) + "-" + tempStr.Substring(3, 3) + "-" + tempStr.Substring(6, 4);
}
else if(tempStr.Length == 11)
{
result.mobile = tempStr.Substring(0, 3) + "-" + tempStr.Substring(3, 4) + "-" + tempStr.Substring(7, 4);
}
// 10,11 개 아닐 경우 그대로 표현
}
}
return JsonOKObj(result);
}
}
}