using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using System.Xml.Serialization;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.DBUtility;
using DSWeb.SoftMng.Model;
using DSWeb.Areas.CommMng.Models;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
namespace DSWeb.SoftMng.Controllers
{
public class NoticeController : Controller
{
private readonly op_NoticeBLL _bll = new op_NoticeBLL();
#region View
///
/// 首页
///
///
//[ModuleAuthFilter(Name = "")]//过滤器
public ActionResult Index()
{
return View();
}
#endregion
#region Handler
///
/// 获取列表
///
/// 开始索引
/// 分页大小
/// 搜索框的值
/// 排序字段
/// 排序方式
///
//[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public JsonResult GetList(int startIndex, int limit, string search, string sortName, string sortOrder)
{
StringBuilder where = new StringBuilder();
where.Append("1=1");
if (!(String.IsNullOrEmpty(search) || String.IsNullOrWhiteSpace(search)))
where.Append(string.Format(" And Title like '%{0}%'", search));
var list = _bll.GetModelList(startIndex, limit, where.ToString(), String.Format("{0} {1}", sortName, sortOrder));
var count = _bll.GetRecordCount(where.ToString());//总数
return Json(new { total = count, rows = list });
}
///
/// 保存
///
///
///
public JsonResult Save(Model.op_Notice model)
{
bool result;
var nowDate = DateTime.Now;
model.CreateUser = Session["SHOWNAME"].ToString();
if (String.IsNullOrEmpty(model.GID))
{
int num = _bll.GetRecordCount("") + 1; //编号
model.GID = Guid.NewGuid().ToString();
model.CreateTime = DateTime.Now;
result = _bll.Add(model) > 0;
//推送公告
new ChatHub().SendNotice(model, "add");
} //新增
else
{
//获取原数据
var oldModel = _bll.GetModel(model.GID);
//类反射
Type type = typeof(Model.op_Notice);
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.CreateTime = DateTime.Now;
result = _bll.Update(model) > 0;
//推送公告
new ChatHub().SendNotice(model, "update");
} //修改
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
///
/// 删除
///
///
///
public JsonResult Delete(string ids)
{
bool result = _bll.DeleteListWhere(string.Format("GID in({0})", ids)) > 0;
//推送公告
new ChatHub().SendNotice(null, "delete",ids);
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
#endregion
}
}