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.
260 lines
8.0 KiB
260 lines
8.0 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 SysDeptHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.TBL.SysDeptBLL bll = new FangYar.BLL.TBL.SysDeptBLL();
|
|
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 "OrgTree":
|
|
returnstr = GetOrgTree(context);
|
|
break;
|
|
case "OrgDeptList":
|
|
returnstr = GetOrgDeptList(context);
|
|
break;
|
|
case "Add":
|
|
returnstr = AddOrgDept(context);
|
|
break;
|
|
case "Edit":
|
|
returnstr = EditOrgDept(context);
|
|
break;
|
|
case "Del":
|
|
returnstr = DelOrgDept(context);
|
|
break;
|
|
}
|
|
context.Response.Write(returnstr);
|
|
}
|
|
|
|
|
|
|
|
|
|
//字典表机构树
|
|
private string GetOrgTree(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string treeid = context.Request.Params["treeid"];
|
|
|
|
|
|
string where = null;
|
|
if (!string.IsNullOrEmpty(treeid))
|
|
{
|
|
where = " ID = " + treeid;
|
|
}
|
|
List<FangYar.Model.TreeNodeModel> list = new List<Model.TreeNodeModel>();
|
|
list = blltree.GetTree("ID", "PID", "ORG_NAME", "TBL_SYS_ORG", where, list);
|
|
returnstr = "{\"data\":";
|
|
if (list.Count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(list);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch
|
|
{
|
|
returnstr = "{\"data\":[]}";
|
|
}
|
|
return returnstr;
|
|
|
|
}
|
|
|
|
|
|
//查询
|
|
private string GetOrgDeptList(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
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 = null;
|
|
if (!string.IsNullOrEmpty(treeID))
|
|
{
|
|
where += " ORG_ID = '" + treeID + "'";
|
|
}
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
{
|
|
if (where != null)
|
|
{
|
|
where += " and ";
|
|
}
|
|
where += " dept_name like '%" + keyword + "%' ";
|
|
}
|
|
if (where != null)
|
|
{
|
|
where += " and ";
|
|
}
|
|
where += " is_del = '0' order by org_id ";
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.GetRecordCount(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.TBL.TBL_SYS_DEPT_Model> 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 AddOrgDept(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string orgId = context.Request.Params["org_id"];
|
|
string deptName = context.Request.Params["dept_name"];
|
|
|
|
//员工表
|
|
FangYar.Model.TBL.TBL_SYS_DEPT_Model model = new Model.TBL.TBL_SYS_DEPT_Model();
|
|
model.ORG_ID = orgId;
|
|
model.DEPT_NAME = deptName;
|
|
model.IS_DEL = "0";
|
|
|
|
if (bll.AddDept(model))
|
|
{
|
|
msg = "添加成功!";
|
|
code = 1;
|
|
}
|
|
else { msg = "添加失败!"; }
|
|
}
|
|
catch
|
|
{
|
|
msg = "添加失败!";
|
|
}
|
|
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
|
|
return returnstr;
|
|
}
|
|
|
|
//修改人员信息
|
|
private string EditOrgDept(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string id = context.Request.Params["ID"];
|
|
string orgId = context.Request.Params["org_id"];
|
|
string deptName = context.Request.Params["dept_name"];
|
|
|
|
//员工表
|
|
FangYar.Model.TBL.TBL_SYS_DEPT_Model model = new Model.TBL.TBL_SYS_DEPT_Model();
|
|
model.ID = id;
|
|
model.ORG_ID = orgId;
|
|
model.DEPT_NAME = deptName;
|
|
model.IS_DEL = "0";
|
|
|
|
if (bll.EditDept(model))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else { msg = "修改失败!"; }
|
|
}
|
|
catch
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
|
|
return returnstr;
|
|
}
|
|
|
|
//删除人员
|
|
private string DelOrgDept(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] + "'";
|
|
}
|
|
}
|
|
int rcode = bll.DelDept(DeptListString);
|
|
if (rcode == 0)
|
|
{
|
|
msg = "删除成功!";
|
|
code = 1;
|
|
}
|
|
else if (rcode == 1)
|
|
{
|
|
msg = "所选部门还有人员关联,请移除人员后再删除部门!";
|
|
}
|
|
else
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|