You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/SoftMng/Controllers/JsonHandlerController.cs

120 lines
4.3 KiB
C#

3 years ago
using System;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
// ReSharper disable once CheckNamespace
namespace DSWeb.SoftMng.Controllers
{
public class JsonHandlerController : Controller
{
#region Json 读写
/// <summary>
/// 写入 Json 文件
/// </summary>
/// <param name="name">根节点名称</param>
/// <param name="path">路径</param>
/// <param name="key">键</param>
/// <param name="value">值</param>
public void WriteJson(string name,string path,string key, string value)
{
//获取物理路径
path = Server.MapPath(path);
//判断文件是否存在
if (System.IO.File.Exists(path))
{
string jsonString = System.IO.File.ReadAllText(path, Encoding.Default);//读取 Json 文件
JObject jo = JObject.Parse(jsonString);//解析 Json 文件
//JObject json = new JObject()
//{
// ["Key"] = key,
// ["Value"] = value
//};
// jo[name][0].AddAfterSelf(json);
System.IO.File.WriteAllText(path, Convert.ToString(jo));//将内容写进jon文件中
}
else
{
throw new Exception("文件不存在");
}
}
#endregion
#region 自定义列 操作
/// <summary>
/// 获取自定义列
/// </summary>
/// <returns></returns>
public JsonResult GetCustomHead(string nodeName, string userCode)
{
sys_CustomColumnsConfigBLL bll = new sys_CustomColumnsConfigBLL();
StringBuilder where = new StringBuilder();
where.Append(string.Format(" NodeName = '{0}' AND UserCode = '{1}'", nodeName, userCode));
var model = bll.GetModelList(where.ToString()).FirstOrDefault();
return model != null ? Json(new { data = model.UserConfig, exist = true }) : Json(new { exist = false });
}
/// <summary>
/// 配置自定义列
/// </summary>
/// <returns></returns>
public JsonResult SetCustomHead(sys_CustomColumnsConfig model)
{
bool result;
sys_CustomColumnsConfigBLL bll = new sys_CustomColumnsConfigBLL();
StringBuilder where = new StringBuilder();
where.Append(string.Format(" NodeName = '{0}' AND UserCode = '{1}'", model.NodeName, model.UserCode));
var list = bll.GetModelList(where.ToString());
if (list.Count == 0)
{
model.GId = Guid.NewGuid().ToString();
result = bll.Add(model) > 0;
}
else
{
model.GId = list[0].GId;
result = bll.Update(model) > 0;
}
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
/// <summary>
/// 删除自定义列
/// </summary>
/// <param name="nodeName"></param>
/// <param name="userCode"></param>
/// <returns></returns>
public JsonResult DelCustomHead(string nodeName, string userCode)
{
bool result;
sys_CustomColumnsConfigBLL bll = new sys_CustomColumnsConfigBLL();
StringBuilder where = new StringBuilder();
where.Append(string.Format(" NodeName = '{0}' AND UserCode = '{1}'", nodeName, userCode));
result = bll.DeleteListWhere(where.ToString()) > 0;
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
#endregion
#region 即时通讯
[HttpPost]
public JsonResult GetOnlineUser()
{
userBLL bll=new userBLL();
try
{
var list = bll.GetModelList("");
var result = new { state = true, data = list };
return Json(result);
}
catch (Exception e)
{
var result = new { state = false, message = e.Message };
return Json(result);
}
}
#endregion
}
}