软测单独项目
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.
 
 
 
 
 
 

286 lines
10 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)
{
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "部门操作请求", "");
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 (Exception e)
{
returnstr = "{\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "部门操作请求", "查询异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "部门操作请求", "查询");
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 (Exception e)
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "部门操作请求", "查询异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "部门操作请求", "查询");
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 (Exception e)
{
msg = "添加失败!";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "部门操作请求", "添加部门异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "部门操作请求", "添加部门");
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 (Exception e)
{
msg = "修改失败!";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "部门操作请求", "修改部门信息异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "部门操作请求", "修改部门信息");
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 (Exception e)
{
msg = "删除失败!";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "部门操作请求", "删除部门异常:" + e);
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "部门操作请求", "删除部门");
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}