using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.DBUtility;
using DSWeb.SoftMng.Model;
using DSWeb.SoftMng.Filter;
using System.Reflection;
// ReSharper disable once CheckNamespace
namespace DSWeb.SoftMng.Controllers
{
public class SignalRController:Controller
{
private readonly sys_messageBLL _bll = new sys_messageBLL();
private readonly op_message_configBLL _bllc = new op_message_configBLL();
private readonly op_message_moduleBLL _bllm = new op_message_moduleBLL();
#region View
///
/// 即时通讯页面
///
///
public ActionResult Index()
{
if (Session["CODENAME"] == null)
Response.Redirect("/login.aspx");
ViewData["USERID"] = Session["USERID"];
ViewData["CODENAME"] = Session["CODENAME"];
ViewData["SHOWNAME"] = Session["SHOWNAME"];
return View();
}
///
/// 配置页面
///
///
public ActionResult Config()
{
return View();
}
///
/// 模块页面
///
///
public ActionResult Module()
{
return View();
}
#endregion
#region Handler
///
/// 获取消息提醒配置列表
///
/// 开始索引
/// 分页大小
/// 搜索框的值
/// 排序字段
/// 排序方式
/// 状态(0 | 1)
///
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public JsonResult GetConfigList(int startIndex, int limit, string search, string sortName, string sortOrder, string status)
{
StringBuilder where = new StringBuilder();
where.Append(string.Format("UserCode='{0}'", Session["USERID"]));
if (!(String.IsNullOrEmpty(search) || String.IsNullOrWhiteSpace(search)))
where.Append(string.Format(" And PId in (SELECT GId from op_message_module where Name like '%{0}%' OR Descr like '%{0}%')", search));
//单独查询 各类别数量
Dictionary dict = new Dictionary();
string[] arr = { "", "0", "1"};
for (int i = 0; i < arr.Length; i++)
dict.Add(i.ToString(), _bllc.GetRecordCount(where + (arr[i] == "" ? "" : string.Format(" And IsPush = {0}", arr[i]))));
if (!String.IsNullOrEmpty(status))
where.Append(string.Format(" And IsPush = {0}", status));
var list = _bllc.GetModelList(startIndex, limit, where.ToString(), String.Format("{0} {1}", sortName, sortOrder));
var result = from p in list
select new
{
p.GId,
IsPush = p.IsPush == true ? "1" : "0",
p.UserCode,
p.UpdateTime,
p.PId,
Name = _bllm.GetModel(p.PId).Name,
PId_Text = _bllm.GetModel(p.PId).Descr
};
var count = _bllc.GetRecordCount(where.ToString());//总数
return Json(new { total = count, groupTotal = dict, rows = result });
}
///
/// 保存
///
///
///
public JsonResult ConfigSave(Model.op_message_config model)
{
bool result;
model.IsPush = Request["IsPush"] != "0";
if (String.IsNullOrEmpty(model.GId))
{
var count = _bllc.GetRecordCount(string.Format("PId='{0}' AND UserCode='{1}'", model.PId, Session["USERID"]));
if (count == 0)
{
int num = _bllc.GetRecordCount("") + 1; //编号
model.GId = Guid.NewGuid().ToString();
model.UserCode = Session["USERID"].ToString();
model.UpdateTime = DateTime.Now;
result = _bllc.Add(model) > 0;
}
else
result = false;
} //新增
else
{
//获取原数据
var oldModel = _bllc.GetModel(model.GId);
//类反射
Type type = typeof(Model.op_message_config);
PropertyInfo[] piArr = type.GetProperties();
foreach (var pi in piArr)
{
if (Array.IndexOf(Request.Params.AllKeys, pi.Name) < 0)
pi.SetValue(model, pi.GetValue(oldModel, null), null);
}
model.UpdateTime = DateTime.Now;
result = _bllc.Update(model) > 0;
} //修改
return Json(new { success = result, message = result ? "操作成功" : "已存在该配置" });
}
///
/// 删除
///
///
///
public JsonResult ConfigDelete(string ids)
{
bool result = _bllc.DeleteListWhere(string.Format("GId in({0})", ids)) > 0;
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
///
/// 获取模块管理列表
///
/// 开始索引
/// 分页大小
/// 搜索框的值
/// 排序字段
/// 排序方式
/// 状态(0 | 1)
///
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public JsonResult GetModuleList(int startIndex, int limit, string search, string sortName, string sortOrder, string status)
{
StringBuilder where = new StringBuilder();
where.Append("1=1");
if (!(String.IsNullOrEmpty(search) || String.IsNullOrWhiteSpace(search)))
where.Append(string.Format(" And (Name like '%{0}%' OR Descr like '%{0}%')", search));
//单独查询 各类别数量
Dictionary dict = new Dictionary();
string[] arr = { "", "0", "1" };
for (int i = 0; i < arr.Length; i++)
dict.Add(i.ToString(), _bllm.GetRecordCount(where + (arr[i] == "" ? "" : string.Format(" And IsDeleted = {0}", arr[i]))));
if (!String.IsNullOrEmpty(status))
where.Append(string.Format(" And IsDeleted = {0}", status));
var list = _bllm.GetModelList(startIndex, limit, where.ToString(), String.Format("{0} {1}", sortName, sortOrder));
var result = from p in list
select new
{
p.GId,
IsDeleted = p.IsDeleted == true ? "1" : "0",
p.CreateTime,
p.CreateUser,
p.Name,
p.Descr
};
var count = _bllm.GetRecordCount(where.ToString());//总数
return Json(new { total = count, groupTotal = dict, rows = result });
}
///
/// 保存
///
///
///
public JsonResult ModuleSave(Model.op_message_module model)
{
bool result;
model.IsDeleted = Request["IsDeleted"] != "0";
if (String.IsNullOrEmpty(model.GId))
{
var count = _bllm.GetRecordCount(string.Format("Name='{0}'", model.Name));
if (count == 0)
{
model.GId = Guid.NewGuid().ToString();
model.CreateUser = Session["SHOWNAME"].ToString();
model.CreateTime = DateTime.Now;
result = _bllm.Add(model) > 0;
}
else
result = false;
} //新增
else
{
//获取原数据
var oldModel = _bllm.GetModel(model.GId);
//类反射
Type type = typeof(Model.op_message_module);
PropertyInfo[] piArr = type.GetProperties();
foreach (var pi in piArr)
{
if (Array.IndexOf(Request.Params.AllKeys, pi.Name) < 0)
pi.SetValue(model, pi.GetValue(oldModel, null), null);
}
result = _bllm.Update(model) > 0;
} //修改
return Json(new { success = result, message = result ? "操作成功" : "已存在该配置" });
}
///
/// 删除
///
///
///
public JsonResult ModuleDelete(string ids)
{
bool result = _bllm.DeleteListWhere(string.Format("GId in({0})", ids)) > 0;
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
///
/// 懒加载模块信息
///
///
///
///
///
public JsonResult GetInfoModuleList(int pageIndex, int pageSize, string query)
{
StringBuilder where = new StringBuilder();
if (!String.IsNullOrEmpty(query))
where.Append(string.Format("Name LIKE '%{0}%' OR Descr LIKE '%{0}%'", query));
var list = _bllm.GetModelList(pageIndex, pageSize, where.ToString(), "Descr collate Chinese_PRC_CS_AS_KS_WS");
var total = _bllm.GetRecordCount(where.ToString());
var result = from p in list
select new
{
id = p.GId,
text = p.Descr
};
return Json(new { data = result, total }, JsonRequestBehavior.AllowGet);
}
///
/// 获取历史消息通知
///
///
///
public JsonResult GetHistoryMsg(string userid)
{
StringBuilder where = new StringBuilder();
where.Append(string.Format("RECEIVER ='{0}'", userid));
var list = _bll.GetModelList(0,200,where.ToString(), "CREATETIME DESC").OrderBy(p=>p.ISREAD).ToList();
return Json(list);
}
///
/// 设置消息状态
///
///
public JsonResult SetMsgStatus(string gid,int status)
{
var model = _bll.GetModel(gid);
model.ISREAD = status == 0 ? false : true;
var result = _bll.Update(model)>0;
return Json(result);
}
#endregion
}
}