394 lines
14 KiB
Plaintext
394 lines
14 KiB
Plaintext
<%@ WebHandler Language="C#" Class="projectData" %>
|
||
|
||
using System;
|
||
using System.Web;
|
||
using System.Runtime.Serialization.Json;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System.Web.Services.Protocols;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using System.Web.SessionState;
|
||
using System.Data;
|
||
using System.Collections.Generic;
|
||
using System.IO.Compression;
|
||
using System.Drawing;
|
||
using System.Drawing.Imaging;
|
||
using System.IO;
|
||
using System.Linq;
|
||
|
||
public class projectData : IHttpHandler, IReadOnlySessionState
|
||
{
|
||
|
||
public void ProcessRequest(HttpContext context)
|
||
{
|
||
result objRet = new result();
|
||
DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType());
|
||
context.Response.ContentType = "application/json;charset=utf-8";
|
||
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
|
||
|
||
string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToString().ToUpperInvariant();
|
||
if (!String.IsNullOrEmpty(acceptEncoding))
|
||
{
|
||
if (acceptEncoding.Contains("GZIP"))
|
||
{
|
||
//输出流头部GZIP压缩
|
||
context.Response.AppendHeader("Content-encoding", "gzip");
|
||
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
|
||
}
|
||
else if (acceptEncoding.Contains("DEFLATE"))
|
||
{
|
||
//输出流头部DEFLATE压缩
|
||
context.Response.AppendHeader("Content-encoding", "deflate");
|
||
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
|
||
}
|
||
}
|
||
|
||
authPermission objAuth = new authPermission();
|
||
|
||
string method = (context.Request["method"] == null) ? "" : context.Request["method"].ToString();
|
||
string project_uid = (context.Request["project_uid"] == null) ? "" : context.Request["project_uid"].ToString();
|
||
string project_name = (context.Request["project_name"] == null) ? "" : context.Request["project_name"].ToString();
|
||
string project_descript = (context.Request["project_descript"] == null) ? "" : context.Request["project_descript"].ToString();
|
||
string project_limited = (context.Request["project_dateLimit"] == null) ? "N" : context.Request["project_dateLimit"].ToString();
|
||
string project_enddate = (context.Request["project_enddate"] == null) ? "" : context.Request["project_enddate"].ToString();
|
||
string project_endToRedirect = (context.Request["project_endToRedirect"] == null) ? "" : context.Request["project_endToRedirect"].ToString();
|
||
string userJson = (context.Request["userList"] == null) ? "[]" : context.Request["userList"].ToString();
|
||
string project_apiId = (context.Request["project_apiId"] == null) ? "" : context.Request["project_apiId"].ToString();
|
||
string project_apiKey = (context.Request["project_apiKey"] == null) ? "" : context.Request["project_apiKey"].ToString();
|
||
string domainList = (context.Request["domainList"] == null) ? "[]" : context.Request["domainList"].ToString();
|
||
string ipList = (context.Request["ipList"] == null) ? "[]" : context.Request["ipList"].ToString();
|
||
string delUserJson = (context.Request["delUserJson"] == null) ? "[]" : context.Request["delUserJson"].ToString();
|
||
|
||
dynamic usersJson;
|
||
dynamic delUsersJson;
|
||
dynamic domainJson;
|
||
dynamic ipJson;
|
||
|
||
usersJson = JValue.Parse(userJson);
|
||
|
||
if (!objAuth.isLogin())
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0001";
|
||
objRet.message = "尚未登入,請登入後使用";
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
if (method == "")
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0999";
|
||
objRet.message = "沒有Method,無法使用";
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
|
||
|
||
string errmsg = "";
|
||
|
||
if (method != "add")
|
||
{
|
||
if (project_uid == "")
|
||
{
|
||
errmsg += "沒有系統編號!\n";
|
||
}
|
||
}
|
||
|
||
if (errmsg.Length > 0)
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0005";
|
||
objRet.message = errmsg;
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
if (method == "get")
|
||
{
|
||
project objProj = new project(project_uid);
|
||
|
||
objRet.ret = "yes";
|
||
objRet.data = objProj;
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
if (method == "delete")
|
||
{
|
||
if (objAuth.user_perm != "A" && objAuth.user_perm != "P")
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0003";
|
||
objRet.message = "無權限刪除專案基本資訊!";
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
if (project_uid == "")
|
||
{
|
||
errmsg += "沒有系統編號!\n";
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0005";
|
||
objRet.message = errmsg;
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
string delQuotationString = string.Format("update projects set project_isRevoke = 'Y' where project_uid = '{0}'", project_uid);
|
||
autoExecSQL objDel = new autoExecSQL(delQuotationString);
|
||
|
||
if (objDel.effectDataCount > 0)
|
||
{
|
||
objRet.ret = "yes";
|
||
}
|
||
else
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0033";
|
||
objRet.message = "無專案被刪除,請重新整理後重新刪除!";
|
||
}
|
||
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
if (project_name == "")
|
||
{
|
||
errmsg += "沒有專案名稱!\n";
|
||
}
|
||
|
||
if (project_limited == "Y" && globalClass.IsDate(project_enddate) == false)
|
||
{
|
||
errmsg += "沒有專案結束日期或專案結束日期格式錯誤!\n";
|
||
}
|
||
|
||
if (project_limited == "Y" && project_endToRedirect == "")
|
||
{
|
||
errmsg += "沒有專案結束後導向的網址!\n";
|
||
}
|
||
|
||
if (usersJson.Count == 0)
|
||
{
|
||
errmsg += "沒有專案成員\n";
|
||
}
|
||
|
||
if (project_apiId == "" || project_apiKey == "")
|
||
{
|
||
errmsg += "沒有App ID或App Key!\n";
|
||
}
|
||
|
||
if (errmsg.Length > 0)
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0005";
|
||
objRet.message = errmsg;
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
if (method == "edit")
|
||
{
|
||
if (objAuth.user_perm != "A" && objAuth.user_perm != "P")
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "0003";
|
||
objRet.message = "無權限修改專案基本資訊!";
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
domainJson = JValue.Parse(domainList);
|
||
ipJson = JValue.Parse(ipList);
|
||
delUsersJson = JValue.Parse(delUserJson);
|
||
|
||
project objProj = new project(project_uid);
|
||
|
||
objProj.project_name = project_name;
|
||
objProj.project_descript = project_descript;
|
||
objProj.project_dateLimit = project_limited;
|
||
|
||
if (project_limited == "Y")
|
||
{
|
||
objProj.project_endDate = DateTime.Parse(project_enddate + " 23:59:59");
|
||
objProj.project_endToRedirect = project_endToRedirect;
|
||
}
|
||
else
|
||
{
|
||
objProj.project_endToRedirect = "";
|
||
}
|
||
|
||
objProj.project_apiId = project_apiId;
|
||
objProj.project_apiKey = project_apiKey;
|
||
|
||
//autoExecSQL delProjectUser = new autoExecSQL(string.Format("delete projectUser where project_uid = '{0}'", project_uid));
|
||
string projUserString = "select * from projectUser where projectUser_sn = -1";
|
||
autoBindDataTable projUserSQL = new autoBindDataTable(projUserString);
|
||
|
||
foreach (JToken item in usersJson)
|
||
{
|
||
DataRow projUserRow = projUserSQL.newRow;
|
||
projUserSQL.dataRows.Add(projUserRow);
|
||
|
||
projUserRow["project_uid"] = project_uid;
|
||
projUserRow["user_uid"] = item["user_uid"].ToString();
|
||
}
|
||
|
||
//autoExecSQL delApiDomain = new autoExecSQL(string.Format("delete projectApiDomain where project_uid = '{0}'", project_uid));
|
||
string projApiDomainString = "select * from projectApiDomain where projectApiDomain_sn = -1";
|
||
autoBindDataTable projApiDomainSQL = new autoBindDataTable(projApiDomainString);
|
||
|
||
foreach (string item in domainJson)
|
||
{
|
||
if (item != "")
|
||
{
|
||
DataRow domainRow = projApiDomainSQL.newRow;
|
||
projApiDomainSQL.dataRows.Add(domainRow);
|
||
|
||
domainRow["project_uid"] = project_uid;
|
||
domainRow["projectApiDomain_type"] = "domain";
|
||
domainRow["projectApiDomain_address"] = item.ToString();
|
||
}
|
||
}
|
||
|
||
foreach (string item in ipJson)
|
||
{
|
||
if (item != "")
|
||
{
|
||
DataRow domainRow = projApiDomainSQL.newRow;
|
||
projApiDomainSQL.dataRows.Add(domainRow);
|
||
|
||
domainRow["project_uid"] = project_uid;
|
||
domainRow["projectApiDomain_type"] = "ip";
|
||
domainRow["projectApiDomain_address"] = item.ToString();
|
||
}
|
||
}
|
||
|
||
try
|
||
{
|
||
objProj.updateData();
|
||
autoExecSQL delProjectUser = new autoExecSQL(string.Format("delete projectUser where project_uid = '{0}'", project_uid));
|
||
autoExecSQL delApiDomain = new autoExecSQL(string.Format("delete projectApiDomain where project_uid = '{0}'", project_uid));
|
||
projUserSQL.updateDataTable();
|
||
projApiDomainSQL.updateDataTable();
|
||
|
||
objRet.data = objProj;
|
||
objRet.ret = "yes";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "9999";
|
||
objRet.message = ex.Message;
|
||
}
|
||
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
|
||
if (method == "add")
|
||
{
|
||
domainJson = JValue.Parse(domainList);
|
||
ipJson = JValue.Parse(ipList);
|
||
|
||
project_uid = globalClass.CreateRandomCode(16);
|
||
|
||
project objProj = new project();
|
||
|
||
objProj.project_uid = project_uid;
|
||
objProj.project_recTableName = "rec_" + project_uid;
|
||
objProj.project_name = project_name;
|
||
objProj.project_descript = project_descript;
|
||
objProj.project_dateLimit = project_limited;
|
||
|
||
if (project_limited == "Y")
|
||
{
|
||
objProj.project_endDate = DateTime.Parse(project_enddate + " 23:59:59");
|
||
objProj.project_endToRedirect = project_endToRedirect;
|
||
}
|
||
|
||
objProj.project_apiId = project_apiId;
|
||
objProj.project_apiKey = project_apiKey;
|
||
objProj.project_createUid = objAuth.user_uid;
|
||
|
||
string projUserString = "select * from projectUser where projectUser_sn = -1";
|
||
autoBindDataTable projUserSQL = new autoBindDataTable(projUserString);
|
||
|
||
string projApiDomainString = "select * from projectApiDomain where projectApiDomain_sn = -1";
|
||
autoBindDataTable projApiDomainSQL = new autoBindDataTable(projApiDomainString);
|
||
|
||
foreach (JToken item in usersJson)
|
||
{
|
||
DataRow projUserRow = projUserSQL.newRow;
|
||
projUserSQL.dataRows.Add(projUserRow);
|
||
|
||
projUserRow["project_uid"] = project_uid;
|
||
projUserRow["user_uid"] = item["user_uid"].ToString();
|
||
}
|
||
|
||
foreach (string item in domainJson)
|
||
{
|
||
if (item != "")
|
||
{
|
||
DataRow domainRow = projApiDomainSQL.newRow;
|
||
projApiDomainSQL.dataRows.Add(domainRow);
|
||
|
||
domainRow["project_uid"] = project_uid;
|
||
domainRow["projectApiDomain_type"] = "domain";
|
||
domainRow["projectApiDomain_address"] = item.ToString();
|
||
}
|
||
}
|
||
|
||
foreach (string item in ipJson)
|
||
{
|
||
if (item != "")
|
||
{
|
||
DataRow domainRow = projApiDomainSQL.newRow;
|
||
projApiDomainSQL.dataRows.Add(domainRow);
|
||
|
||
domainRow["project_uid"] = project_uid;
|
||
domainRow["projectApiDomain_type"] = "ip";
|
||
domainRow["projectApiDomain_address"] = item.ToString();
|
||
}
|
||
}
|
||
|
||
try
|
||
{
|
||
projUserSQL.updateDataTable();
|
||
projApiDomainSQL.updateDataTable();
|
||
objProj.updateData();
|
||
objRet.data = objProj;
|
||
objRet.ret = "yes";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
objRet.ret = "no";
|
||
objRet.err_code = "9999";
|
||
objRet.message = ex.Message;
|
||
}
|
||
|
||
|
||
json.WriteObject(context.Response.OutputStream, objRet);
|
||
return;
|
||
}
|
||
}
|
||
|
||
public class result
|
||
{
|
||
public string ret = "no";
|
||
public string err_code = "0000";
|
||
public string message = "";
|
||
public project data = new project();
|
||
}
|
||
|
||
public bool IsReusable
|
||
{
|
||
get
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
} |