using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using System.Collections;
using System.Reflection;
using System.Web.Script.Serialization;
using FangYar.Model;
using FangYar.BLL;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace FangYar.WebUI.ashx
{
///
/// OaLeaveHandler 的摘要说明
///
public class OaPatrolSpotHandler : IHttpHandler
{
private FangYar.BLL.OA_PATROL_SPOT bll = new FangYar.BLL.OA_PATROL_SPOT();
private FangYar.BLL.TBL.SysEmpBLL ebll = new FangYar.BLL.TBL.SysEmpBLL();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request.Params["Action"];
string returnstr = "";
switch (action)
{
case "List":
returnstr = getSpotlist(context);
break;
case "Add":
returnstr = AddSpot(context);
break;
case "Edit":
returnstr = EditSpot(context);
break;
case "getOrgTree":
returnstr = getOrgTree(context);
break;
case "IFIDGetModel":
returnstr = IFIDGetModel(context);
break;
case "IFIDGetModelLeave":
returnstr = IFIDGetModelLeave(context);
break;
case "getSpots":
returnstr = getSpots(context);
break;
}
context.Response.Write(returnstr);
}
//查询
private string getSpotlist(HttpContext context)
{
string returnstr = "";
try
{
string orgId = context.Request.Params["orgId"];
string keyword = context.Request.Params["keywords"];
string page = context.Request.Params["page"];
string limit = context.Request.Params["limit"];
string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"];
int pageIndex = 1;
int pageSize = 10;//
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
string where = null;
where = "ORG_ID = '" + orgId + "' ";
if (!string.IsNullOrEmpty(keyword))
{
where += " and (NAME like '%" + keyword + "%' or ADDR like '%" + keyword + "%')";
}
if (!string.IsNullOrEmpty(EXTENDCODE1))
{
where += " and EXTENDCODE1 = '" + EXTENDCODE1 + "' ";
}
returnstr = "{\"code\":0,\"msg\":\"\",";
int count = bll.GetRecordCount(where);
returnstr += "\"count\":" + count + ",\"data\":";
if (count == 0)
{
returnstr += "[]";
}
else
{
List list = bll.QueryList(pageIndex, pageSize, where, " CAST(SORT AS INTEGER)");
foreach (FangYar.Model.OA_PATROL_SPOT model in list)
{
JObject EXTENDCODE2_s = JsonConvert.DeserializeObject(model.EXTENDCODE2);
string EXTENDCODE21 = "";
int EXTENDCODE21count = 0;
if (EXTENDCODE2_s != null)
{
foreach (JObject EXTENDCODE31obj in EXTENDCODE2_s.Value("data"))
{
if (EXTENDCODE21count == 0)
{
EXTENDCODE21 = "" + EXTENDCODE31obj["ppl_Name"];
}
else
{
EXTENDCODE21 += "," + EXTENDCODE31obj["ppl_Name"];
}
EXTENDCODE21count++;
}
}
model.EXTENDCODE21 = EXTENDCODE21;
}
returnstr += FangYar.Common.JsonHelper.ToJson(list);
}
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]";
}
return returnstr;
}
//添加巡查点
private string AddSpot(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string spotId = Guid.NewGuid().ToString("N");
string orgId = context.Request.Params["orgId"];
string NAME = context.Request.Params["NAME"];
string SPOT_NO = context.Request.Params["SPOT_NO"];
string POINT = context.Request.Params["POINT"];
string DES = context.Request.Params["DES"];
string ADDR = context.Request.Params["ADDR"];
string STATE = context.Request.Params["STATE"];
string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"];
string EXTENDCODE2 = context.Request.Params["EXTENDCODE2"];
string SORT = context.Request.Params["SORT"];
//巡查点表
FangYar.Model.OA_PATROL_SPOT model = new Model.OA_PATROL_SPOT();
model.ID = spotId;
model.NAME = NAME;
model.SPOT_NO = SPOT_NO;
model.POINT = POINT;
model.DES = DES;
model.ADDR = ADDR;
model.ORG_ID = orgId;
model.STATE = STATE;
model.SORT = SORT;
model.EXTENDCODE1 = EXTENDCODE1;
model.EXTENDCODE2 = EXTENDCODE2;
bool a = bll.ExistsSpotNo(SPOT_NO);
if (a == true)
{
msg = "对不起,该芯片编号已经存在";
}
else
{
if (bll.Add(model))
{
msg = "添加成功!";
code = 1;
}
else { msg = "添加失败!"; }
}
}
catch (Exception e)
{
msg = "添加失败!";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
return returnstr;
}
//修改巡查点
private string EditSpot(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string ID = context.Request.Params["ID"];
string orgId = context.Request.Params["orgId"];
string NAME = context.Request.Params["NAME"];
string SPOT_NO = context.Request.Params["SPOT_NO"];
string POINT = context.Request.Params["POINT"];
string DES = context.Request.Params["DES"];
string ADDR = context.Request.Params["ADDR"];
string STATE = context.Request.Params["STATE"];
string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"];
string EXTENDCODE2 = context.Request.Params["EXTENDCODE2"];
string SORT = context.Request.Params["SORT"];
//巡查点表
FangYar.Model.OA_PATROL_SPOT model = new Model.OA_PATROL_SPOT();
model.ID = ID;
model.NAME = NAME;
model.SPOT_NO = SPOT_NO;
model.POINT = POINT;
model.DES = DES;
model.ADDR = ADDR;
model.ORG_ID = orgId;
model.STATE = STATE;
model.SORT = SORT;
model.EXTENDCODE1 = EXTENDCODE1;
model.EXTENDCODE2 = EXTENDCODE2;
if (bll.Update(model))
{
msg = "修改成功!";
code = 1;
}
else { msg = "修改失败!"; }
}
catch (Exception e)
{
msg = "修改失败!";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
return returnstr;
}
//获取Tree 机构下的巡查点列表
private string getOrgTree(HttpContext context)
{
string returnstr = "";
try
{
string orgId = context.Request.Params["OrgId"];
string patrolSpotType = context.Request.Params["patrolSpotType"];
returnstr = "{\"code\":0,\"msg\":\"\",\"data\":";
DataTable data = bll.getOrgTree(orgId, patrolSpotType);
returnstr += FangYar.Common.JsonHelper.ToJson(data);
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
}
return returnstr;
}
//根据IFID(芯片编号)得到一个对象实体
private string IFIDGetModel(HttpContext context)
{
string returnstr = "";
try
{
string ORG_ID = context.Request.Params["ORG_ID"];
string IFID = context.Request.Params["IFID"];
FangYar.Model.OA_PATROL_SPOT model = bll.IFIDGetModel(ORG_ID, IFID);
if (model == null)
{
returnstr = "{}";
}
else
{
returnstr += FangYar.Common.JsonHelper.ToJson(model);
}
}
catch (Exception e)
{
returnstr = null;
}
return returnstr;
}
//根据IFID(芯片编号)得到一个对象实体(查铺查哨判断被查人是否在岗)
private string IFIDGetModelLeave(HttpContext context)
{
string returnstr = "";
try
{
string ORG_ID = context.Request.Params["ORG_ID"];
string IFID = context.Request.Params["IFID"];
FangYar.Model.OA_PATROL_SPOT model = bll.IFIDGetModel(ORG_ID, IFID);
if (model != null)
{
JObject acc_ppl_s = JsonConvert.DeserializeObject(model.EXTENDCODE2);
if (acc_ppl_s != null)
{
//JObject acc_ppl_s2 = new JObject();
//JObject acc_ppl_s2 = new JObject();
//JArray arr = new JArray();
string acc_ppl_s2 = "{\"data\":[";
int a = 0;
foreach (JObject obj in acc_ppl_s.Value("data"))
{
FangYar.Model.TBL.TBL_SYS_EMP_Model emodel = ebll.GetModelByUID((string)obj["ppl_Id"]);
if (a == 0)
{
acc_ppl_s2 += "{";
}
else
{
acc_ppl_s2 += ",{";
}
acc_ppl_s2 += "\"ppl_Id\":\"" + obj["ppl_Id"] + "\"";
acc_ppl_s2 += ",\"ppl_Name\":\"" + obj["ppl_Name"] + "\"";
acc_ppl_s2 += ",\"is_work\":\"" + emodel.IS_WORK + "\"";
acc_ppl_s2 += "}";
a++;
}
acc_ppl_s2 += "]}";
model.EXTENDCODE2 = acc_ppl_s2;
returnstr = "{\"code\":1,\"msg\":\"ok\",\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(model);
returnstr += "}";
}
else
{
returnstr = "{\"code\":0,\"msg\":\"ok\",\"count\":0,\"data\":[]}";
}
}
else
{
returnstr = "{\"code\":0,\"msg\":\"ok\",\"count\":0,\"data\":[]}";
}
}
catch
{
returnstr = "{\"code\":-1,\"msg\":\"error\",\"count\":0,\"data\":[]}";
}
return returnstr;
}
//获取下拉列表 机构下的巡查点列表
private string getSpots(HttpContext context)
{
string returnstr = "";
try
{
string orgId = context.Request.Params["OrgId"];
string patrolSpotType = context.Request.Params["patrolSpotType"];
returnstr = "{\"code\":0,\"msg\":\"\",\"data\":";
DataSet data = bll.GetList(" org_id = '" + orgId + "' and EXTENDCODE1 = '" + patrolSpotType + "'");
returnstr += FangYar.Common.JsonHelper.ToJson(data);
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
}
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}