78 lines
2.5 KiB
Plaintext
78 lines
2.5 KiB
Plaintext
<%@ WebHandler Language="C#" Class="projectsList" %>
|
|
|
|
using System;
|
|
using System.Web;
|
|
using System.Collections.Generic;
|
|
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;
|
|
|
|
public class projectsList : 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", "*");
|
|
authPermission objAuth = new authPermission();
|
|
|
|
if (!objAuth.isLogin())
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0001";
|
|
objRet.message = "尚未登入,請登入後使用";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
//if (objAuth.user_perm != "A" && objAuth.user_perm != "P")
|
|
//{
|
|
// objRet.ret = "no";
|
|
// objRet.err_code = "0002";
|
|
// objRet.message = "權限不足,無法使用";
|
|
// json.WriteObject(context.Response.OutputStream, objRet);
|
|
// return;
|
|
//}
|
|
|
|
objRet.user_perm = objAuth.user_perm;
|
|
|
|
string projectString = "select * from projects where project_isRevoke = 'N' order by project_sn desc";
|
|
|
|
if (objAuth.user_perm != "A")
|
|
{
|
|
projectString = string.Format("select A.* from projects A, projectUser B where A.project_uid = B.project_uid and A.project_isRevoke = 'N' and B.user_uid = '{0}' order by A.project_sn desc", objAuth.user_uid);
|
|
}
|
|
|
|
autoBindDataTable sqlProjects = new autoBindDataTable(projectString);
|
|
|
|
foreach(DataRow tmpRow in sqlProjects.dataRows)
|
|
{
|
|
projectBase tmpProject = new projectBase(tmpRow["project_uid"].ToString());
|
|
objRet.projectlist.Add(tmpProject);
|
|
}
|
|
|
|
objRet.ret = "yes";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
public class result {
|
|
public string ret = "no";
|
|
public string err_code = "0000";
|
|
public string message = "";
|
|
public string user_perm = "N";
|
|
public List<projectBase> projectlist = new List<projectBase>();
|
|
}
|
|
|
|
public bool IsReusable {
|
|
get {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
} |