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/NoticeController.cs

109 lines
3.9 KiB
C#

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
/// <summary>
/// 首页
/// </summary>
/// <returns></returns>
//[ModuleAuthFilter(Name = "")]//过滤器
public ActionResult Index()
{
return View();
}
#endregion
#region Handler
/// <summary>
/// 获取列表
/// </summary>
/// <param name="startIndex">开始索引</param>
/// <param name="limit">分页大小</param>
/// <param name="search">搜索框的值</param>
/// <param name="sortName">排序字段</param>
/// <param name="sortOrder">排序方式</param>
/// <returns></returns>
//[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 });
}
/// <summary>
/// 保存
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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 ? "操作成功" : "操作失败" });
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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
}
}