软测单独项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

364 lines
12 KiB

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;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// OaLeaveHandler 的摘要说明
/// </summary>
public class FireDeptHandler : IHttpHandler
{
private FangYar.BLL.FIRE.FIRE_DEPT bll = new FangYar.BLL.FIRE.FIRE_DEPT();
private FangYar.BLL.ToTree_BLL blltree = new BLL.ToTree_BLL();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request.Params["Action"];
string returnstr = "";
switch (action)
{
case "DeptList":
returnstr = GetDeptList(context);
break;
case "Add":
returnstr = AddDept(context);
break;
case "Edit":
returnstr = EditDept(context);
break;
case "Del":
returnstr = DelDept(context);
break;
case "DeptTree":
returnstr = GetDeptTree(context);
break;
case "Model":
returnstr = GetDeptModel(context);
break;
case "getDeptEmpUidTree":
returnstr = getDeptEmpUidTree(context);
break;
case "getDeptEmpTree":
returnstr = getDeptEmpTree(context);
break;
}
context.Response.Write(returnstr);
}
//查询
private string GetDeptList(HttpContext context)
{
string returnstr = "";
try
{
string OrgId = context.Request.Params["OrgId"];
string keyword = context.Request.Params["keywords"];
string treeID = context.Request.Params["treeID"];
string page = context.Request.Params["page"];
string limit = context.Request.Params["limit"];
int pageIndex = 1;
int pageSize = 10;
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
string where = " (IS_DEL <> '1' or IS_DEL is null) ";
if (!string.IsNullOrEmpty(treeID) && treeID != OrgId)
{
where = " and org_id ='" + treeID + "' ";
}
else if (!string.IsNullOrEmpty(OrgId))
{
where += " and (ORG_ID ='" + OrgId + "' or ORG_ID in (select o.org_id from fire_org o where o.pid = '" + OrgId + "') )";
}
if (!string.IsNullOrEmpty(keyword))
{
if (where != null)
{
where += " and ";
}
where += "( name like '%" + keyword + "%' or ADDR like '%" + keyword + "%')";
}
returnstr = "{\"code\":0,\"msg\":\"\",";
int count = bll.GetRecordCount(where);
returnstr += "\"count\":" + count + ",\"data\":";
if (count == 0)
{
returnstr += "[]";
}
else
{
List<FangYar.Model.FIRE.FIRE_DEPT> list = bll.QueryList(pageIndex, pageSize, where, "");
returnstr += FangYar.Common.JsonHelper.ToJson(list);
}
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
}
return returnstr;
}
//添加部门
private string AddDept(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string USER_ID = context.Request.Params["USER_ID"];
string ID = Guid.NewGuid().ToString("N");
string NAME = context.Request.Params["NAME"];
string ORG_ID = context.Request.Params["ORG_ID"];
string FID = context.Request.Params["FID"];
string REMARKS = context.Request.Params["REMARKS"];
//部门表
FangYar.Model.FIRE.FIRE_DEPT model = new Model.FIRE.FIRE_DEPT();
model.ID = ID;
model.NAME = NAME;
model.ORG_ID = ORG_ID;
model.FID = FID;
model.REMARKS = REMARKS;
model.A_PER = USER_ID;
if (bll.Add(model))
{
msg = "添加成功!";
code = 1;
}
else { msg = "添加失败!"; }
}
catch
{
msg = "添加失败:装备编码有重复数据";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
return returnstr;
}
//修改部门
private string EditDept(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string USER_ID = context.Request.Params["USER_ID"];
string ID = context.Request.Params["ID"];
string NAME = context.Request.Params["NAME"];
string FID = context.Request.Params["FID"];
string ORG_ID = context.Request.Params["ORG_ID"];
string REMARKS = context.Request.Params["REMARKS"];
//部门表
FangYar.Model.FIRE.FIRE_DEPT model = new Model.FIRE.FIRE_DEPT();
model.ID = ID;
model.NAME = NAME;
model.FID = FID;
model.ORG_ID = ORG_ID;
model.REMARKS = REMARKS;
model.U_PER = USER_ID;
if (bll.Update(model))
{
msg = "修改成功!";
code = 1;
}
else { msg = "修改失败!"; }
}
catch
{
msg = "修改失败!";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
return returnstr;
}
//删除部门
private string DelDept(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string DeptList = context.Request.Params["DeptList"];
string[] DeptArray = DeptList.Split(',');
string DeptListString = "";
for (int i = 0; i < DeptArray.Length; i++)
{
if (i == 0)
{
DeptListString = "'" + DeptArray[i] + "'";
}
else
{
DeptListString += ",'" + DeptArray[i] + "'";
}
}
//var rcode = bll.DelDept(DeptListString,"1");
var rcode = bll.getDelId(DeptListString);
if (rcode == 0)
{
msg = "删除成功!";
code = 1;
}
else if (rcode == 1)
{
msg = "所选部门还有人员关联,请移除人员后再删除当前所选部门!";
}
else if (rcode == 2)
{
msg = "删除失败!";
}
}
catch
{
msg = "删除失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
return returnstr;
}
//部门树
private string GetDeptTree(HttpContext context)
{
string returnstr = "";
try
{
string OrgId = context.Request.Params["OrgId"];
string where = " (IS_DEL <> '1' or IS_DEL is null) ";
if (!string.IsNullOrEmpty(OrgId))
{
where += " and ORG_ID = '" + OrgId + "' ";
}
else
{
return "{\"data\":[]}";
}
List<FangYar.Model.TreeNodeModel> list = new List<Model.TreeNodeModel>();
list = blltree.GetTree3("ID", "FID", "NAME", "FIRE_DEPT", where, list);
returnstr = "{\"data\":";
if (list.Count == 0)
{
returnstr += "[]";
}
else
{
returnstr += FangYar.Common.JsonHelper.ToJson(list);
}
returnstr += "}";
}
catch
{
returnstr = "{\"data\":[]}";
}
return returnstr;
}
//根据ID获取部门详情
private string GetDeptModel(HttpContext context)
{
string returnstr = "";
try
{
string Id = context.Request.Params["Id"];
FangYar.Model.FIRE.FIRE_DEPT model = bll.GetModel(Id);
returnstr = "{\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(model);
}
catch
{
returnstr = "{\"data\":[]}";
}
return returnstr;
}
//获取Tree 机构-部门-员工(获取UID)
private string getDeptEmpUidTree(HttpContext context)
{
string returnstr = "";
try
{
string DeptId = context.Request.Params["DeptId"];
string type = context.Request.Params["type"];
returnstr = "{\"code\":0,\"msg\":\"\",\"data\":";
DataTable data = bll.getDeptEmpUidTree(DeptId);
data.Columns.Add("nocheck", typeof(string)); //数据类型为文本
for (int i = 0; i < data.Rows.Count; i++)
{
string aaa = data.Rows[i]["TYPE"].ToString();
if (data.Rows[i]["TYPE"].ToString() == "emp")
{
data.Rows[i]["nocheck"] = "false";
}
else
{
data.Rows[i]["nocheck"] = "true";
}
}
returnstr += FangYar.Common.JsonHelper.ToJson(data);
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]";
}
return returnstr;
}
//获取Tree 机构-部门-员工(获取EMP_ID)
private string getDeptEmpTree(HttpContext context)
{
string returnstr = "";
try
{
string DeptId = context.Request.Params["DeptId"];
string type = context.Request.Params["type"];
returnstr = "{\"code\":0,\"msg\":\"\",\"data\":";
DataTable data = bll.getDeptEmpTree(DeptId);
returnstr += FangYar.Common.JsonHelper.ToJson(data);
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]";
}
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}