using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using YTSoft.BaseCallCenter.Model;
using YTSoft.BaseCallCenter.MVCWeb.Commons;
using YTSoft.BaseCallCenter.MVCWeb.Models;
namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
{
public class SystemManageController : BaseController
{
#region 部门管理
BLL.T_Sys_Department deptBLL = new BLL.T_Sys_Department();
///
/// 部门列表
///
///
public ActionResult DepartmentList()
{
WorkOrderMyModel model = new WorkOrderMyModel();
return View(model);
}
///通过部门父级节点获取数据
///
///
///
public string GetDepartmentJsonModel(int parentId)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(deptBLL.GetDepartmentJsonModel(parentId));
}
///
/// 部门编辑
///
/// 类型1、新增 2、修改
/// ///
public ActionResult DepartmentEdit(int deptId, int editType)
{
Model.T_Sys_Department viewModel = new Model.T_Sys_Department();
//当前对象实体
if (editType == 1)
{
viewModel.F_ParentId = deptId;
viewModel.F_Sort = 1;
}
else
{
Model.T_Sys_Department deptModel = deptBLL.GetModel(deptId);
viewModel = deptModel;
}
return View(viewModel);
}
///
/// 保存编辑
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveDeptData(T_Sys_Department deptModel)
{
if (deptModel.F_DeptId > 0)
{
return deptBLL.Update(deptModel);
}
else
{
return deptBLL.Add(deptModel) > 0;
}
}
///
/// 删除部门
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteDeptData(int deptId)
{
return deptBLL.Delete(deptId);
}
///
/// 获取部门数据
///
/// 当前页码
/// 每页数据量
///
[ActionName("DeptDate")]
[HttpGet]
public string DeptDate(DateTime? NowDateTime, int page, int limit, int? parentId)
{
//数据结果集
ResponseData dataModel = new ResponseData();
string sql = "";
if (parentId != null)
{
sql += " and F_ParentId=" + parentId;
}
DataTable dt = new DataTable();
int recordCount = 0;
Model.PageData pageModel = new Model.PageData();
dt = BLL.PagerBLL.GetListPager(
"T_Sys_Department",
"F_DeptId",
"*",
sql,
"ORDER BY F_Sort asc ",
limit,
page,
true,
out recordCount);
dataModel.code = 0;
dataModel.count = recordCount;
dataModel.data = dt;
return JsonConvert.SerializeObject(dataModel);
}
#endregion
#region 角色管理
BLL.T_Sys_RoleInfo roleBLL = new BLL.T_Sys_RoleInfo();
public ActionResult RoleList()
{
WorkOrderMyModel model = new WorkOrderMyModel();
return View(model);
}
///
/// 获取角色列表
///
/// 当前页码
/// 每页数据量
///
[ActionName("RoleDate")]
[HttpGet]
public string RoleDate(DateTime? NowDateTime, int page, int limit)
{
//数据结果集
ResponseData dataModel = new ResponseData();
string sql = "";
DataTable dt = new DataTable();
int recordCount = 0;
Model.PageData pageModel = new Model.PageData();
dt = BLL.PagerBLL.GetListPager(
"T_Sys_RoleInfo",
"F_RoleId",
"*",
sql,
"ORDER BY F_RoleId",
limit,
page,
true,
out recordCount);
dataModel.code = 0;
dataModel.count = recordCount;
dataModel.data = dt;
return JsonConvert.SerializeObject(dataModel);
}
///
/// 编辑角色
///
///
public ActionResult RoleEdit(int? roleId)
{
Model.T_Sys_RoleInfo viewModel = new Model.T_Sys_RoleInfo();
if (roleId != null && roleId > 0)
{
viewModel = roleBLL.GetModel(int.Parse(roleId.ToString()));
}
return View(viewModel);
}
///
/// 保存编辑
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveRoleEdit(T_Sys_RoleInfo roleInfoModel)
{
if (roleInfoModel.F_RoleId > 0)
{
return roleBLL.Update(roleInfoModel);
}
else
{
return roleBLL.Add(roleInfoModel) > 0;
}
}
///
/// 删除数据
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteRoleData(string roleId)
{
return roleBLL.DeleteList(roleId);
}
#endregion
#region 获取菜单树
public class DicSeaarchModel
{
public string RootCode
{
get;
set;
}
}
///
/// 初始化字典结构
///
///
///
public ActionResult MenuTree(string rootCode)
{
DicSeaarchModel model = new DicSeaarchModel();
model.RootCode = rootCode;
return View(model);
}
///
/// 获取字典数据
///
///
///
public string GetMenuTreeData(int roleId)
{
try
{
return "[" + Newtonsoft.Json.JsonConvert.SerializeObject(roleBLL.GetMenuTree(roleId)).Replace("Checked", "checked") + "]";
}
catch (Exception ex)
{
return "";
}
}
///
///授权
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool AcceptList(int roleId, string MenuIdStr)
{
bool accRersult = false;
if (roleBLL.AddRolesMenuList(roleId, MenuIdStr))
{
accRersult = true;
}
return accRersult;
}
#endregion
#region 业务类型管理
BLL.T_Wo_WorkOrderType dicTittleBLL = new BLL.T_Wo_WorkOrderType();
public ActionResult BusinessTypeList()
{
WorkOrderMyModel model = new WorkOrderMyModel();
return View(model);
}
///通过dic编码获取dic值
///
///
///
public string GetDicTittleJson(int parentId)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(dicTittleBLL.GetDicTittleJsonModel(parentId));
}
///
/// 获取业务类型数据
///
/// 当前页码
/// 每页数据量
///
[ActionName("OrderTypeDate")]
[HttpGet]
public string OrderTypeDate(DateTime? NowDateTime, int page, int limit, int? parentId)
{
//数据结果集
ResponseData dataModel = new ResponseData();
string sql = "";
if (parentId != null && parentId > 0)
{
sql += " and F_ParentId=" + parentId;
}
DataTable dt = new DataTable();
int recordCount = 0;
Model.PageData pageModel = new Model.PageData();
dt = BLL.PagerBLL.GetListPager(
"T_Wo_WorkOrderType",
"F_WorkOrderTypeId",
"*",
sql,
"ORDER BY F_Sort asc ",
limit,
page,
true,
out recordCount);
dataModel.code = 0;
dataModel.count = recordCount;
dataModel.data = dt;
return JsonConvert.SerializeObject(dataModel);
}
///
/// 编辑业务类型
///
/// 当前选中id
/// 类型1、新增 2、修改
///
public ActionResult BussinessTypeEdit(int F_WorkOrderTypeId, int editType)
{
Model.T_Wo_WorkOrderType viewModel = new Model.T_Wo_WorkOrderType();
//当前对象实体
Model.T_Wo_WorkOrderType orderTypeModel = dicTittleBLL.GetModel(F_WorkOrderTypeId);
if (editType == 1)
{
viewModel.F_ParentId = orderTypeModel.F_WorkOrderTypeId;
viewModel.F_ParentName = orderTypeModel.F_ParentName;
viewModel.F_Sort = 1;
}
else
{
viewModel = orderTypeModel;
}
return View(viewModel);
}
///
/// 保存编辑
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveBussiTypeData(T_Wo_WorkOrderType WorkOrderTypeModel)
{
////当前用户信息
//workOrderBaseModel.F_USERID = F_UserID;//id
//workOrderBaseModel.F_LINKMAN = F_UserCode;//工号
//workOrderBaseModel.F_REPAIRMANNAME = "12";//姓名
if (WorkOrderTypeModel.F_WorkOrderTypeId > 0)
{
return dicTittleBLL.Update(WorkOrderTypeModel) > 0;
}
else
{
return dicTittleBLL.Add(WorkOrderTypeModel) > 0;
}
}
///
/// 删除数据
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteBussiTypeData(int WorkOrderTypeId)
{
return dicTittleBLL.Delete(WorkOrderTypeId);
}
#endregion
#region 字典管理
BLL.T_Sys_DictionaryValue dicValueBLL = new BLL.T_Sys_DictionaryValue();
BLL.T_Sys_DictionaryBase dicBaseBLL = new BLL.T_Sys_DictionaryBase();
///
/// 字典列表
///
///
public ActionResult DictionaryList()
{
WorkOrderMyModel model = new WorkOrderMyModel();
return View(model);
}
///通过字典获取数据
///
///
///
public string GetDictionaryJsonModel(int parentId)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(dicBaseBLL.GetDictionaryJsonModel());
}
///
/// 获取字典值数据
///
/// 当前页码
/// 每页数据量
///
[ActionName("DictionaryDate")]
[HttpGet]
public string DictionaryDate(DateTime? NowDateTime, int page, int limit, string dictionaryFlag)
{
//数据结果集
ResponseData dataModel = new ResponseData();
string sql = "";
if (!string.IsNullOrEmpty(dictionaryFlag) && dictionaryFlag != "0")
{
sql += " and F_DictionaryFlag='" + dictionaryFlag + "'";
}
DataTable dt = new DataTable();
int recordCount = 0;
Model.PageData pageModel = new Model.PageData();
if (string.IsNullOrEmpty(dictionaryFlag) || dictionaryFlag != "0")
{
dt = BLL.PagerBLL.GetListPager(
"T_Sys_DictionaryValue",
"F_DictionaryValueId",
"*",
sql,
"ORDER BY F_Sort asc ",
limit,
page,
true,
out recordCount);
}
else
{
dt = BLL.PagerBLL.GetListPager(
"T_Sys_DictionaryBase",
"F_DictionaryName",
"*,F_DictionaryName as F_Name",
sql,
"ORDER BY F_Sort asc ",
limit,
page,
true,
out recordCount);
}
dataModel.code = 0;
dataModel.count = recordCount;
dataModel.data = dt;
return JsonConvert.SerializeObject(dataModel);
}
///
/// 字典项编辑
///
/// 类型1、新增 2、修改
/// ///
public ActionResult DictionaryBaseEdit(string dicCode, int editType)
{
Model.T_Sys_DictionaryBase viewModel = new Model.T_Sys_DictionaryBase();
//当前对象实体
if (editType == 1)
{
viewModel.F_Sort = 1;
}
else
{
Model.T_Sys_DictionaryBase dicBaseModel = dicBaseBLL.GetModel(dicCode);
viewModel = dicBaseModel;
}
return View(viewModel);
}
///
/// 保存字典项编辑
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveDictionaryBaseData(T_Sys_DictionaryBase dicBaseModel)
{
if (!string.IsNullOrEmpty(dicBaseModel.F_DictionaryFlagType))
{
return dicBaseBLL.Update(dicBaseModel);
}
else
{
return dicBaseBLL.Add(dicBaseModel);
}
}
///
/// 删除字典项
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteBaseData(string baseCode)
{
return dicBaseBLL.Delete(baseCode);
}
///
/// 字典值编辑
///
/// 类型1、新增 2、修改
/// ///
public ActionResult DictionaryValueEdit(int? valueId, string parentCode, int editType)
{
Model.T_Sys_DictionaryValue viewModel = new Model.T_Sys_DictionaryValue();
//当前对象实体
if (editType == 1)
{
viewModel.F_Sort = 1;
viewModel.F_DictionaryFlag = parentCode;
}
else
{
Model.T_Sys_DictionaryValue dicValueModel = dicValueBLL.GetModel(int.Parse(valueId.ToString()));
viewModel = dicValueModel;
}
return View(viewModel);
}
///
/// 保存字典值
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveDictionaryValueData(T_Sys_DictionaryValue dicBaseModel)
{
if (dicBaseModel.F_DictionaryValueId > 0)
{
return dicValueBLL.Update(dicBaseModel);
}
else
{
return dicValueBLL.Add(dicBaseModel) > 0;
}
}
///
/// 删除字典值
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteValueData(int id)
{
return dicValueBLL.Delete(id);
}
#endregion
#region 菜单管理
BLL.T_Sys_ModuleFunctions menuBLL = new BLL.T_Sys_ModuleFunctions();
///
/// 部门列表
///
///
public ActionResult MenuList()
{
WorkOrderMyModel model = new WorkOrderMyModel();
return View(model);
}
///通过部门父级节点获取数据
///
///
///
public string GetMenuJsonModel(int parentId)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(menuBLL.GetMenuJsonModel(parentId));
}
///
/// 获取部门数据
///
/// 当前页码
/// 每页数据量
///
[ActionName("MenuDate")]
[HttpGet]
public string MenuDate(DateTime? NowDateTime, int page, int limit, int? parentId)
{
//数据结果集
ResponseData dataModel = new ResponseData();
string sql = "";
if (parentId != null)
{
sql += " and F_ParentId=" + parentId;
}
DataTable dt = new DataTable();
int recordCount = 0;
Model.PageData pageModel = new Model.PageData();
dt = BLL.PagerBLL.GetListPager(
"T_Sys_ModuleFunctions",
"F_FunctionId",
"* ,(CASE F_StateFlag WHEN 1 THEN '启用' WHEN 0 THEN '禁用' ELSE NULL END ) as F_StateFlagName",
sql,
"ORDER BY F_Sort asc ",
limit,
page,
true,
out recordCount);
dataModel.code = 0;
dataModel.count = recordCount;
dataModel.data = dt;
return JsonConvert.SerializeObject(dataModel);
}
///
/// 功能编辑
///
/// 类型1、新增 2、修改
/// ///
public ActionResult MenuEdit(int menuId, int editType)
{
Model.T_Sys_ModuleFunctions viewModel = new Model.T_Sys_ModuleFunctions();
//当前对象实体
if (editType == 1)
{
viewModel.F_ParentId = menuId;
viewModel.F_Sort = 1;
}
else
{
Model.T_Sys_ModuleFunctions deptModel = menuBLL.GetModel(menuId);
viewModel = deptModel;
}
return View(viewModel);
}
///
/// 保存编辑
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveMenuData(T_Sys_ModuleFunctions menuModel)
{
if (menuModel.F_FunctionId > 0)
{
return menuBLL.Update(menuModel);
}
else
{
return menuBLL.Add(menuModel) > 0;
}
}
///
/// 删除功能
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteMenuData(int menuId)
{
return menuBLL.Delete(menuId);
}
#endregion
#region 用户管理
BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
///
/// 部门列表
///
///
public ActionResult UserList()
{
WorkOrderMyModel model = new WorkOrderMyModel();
return View(model);
}
///
/// 用户编辑
///
/// 类型1、新增 2、修改
/// ///
public ActionResult UserEdit(int? userId, int? deptId, int editType)
{
Model.T_Sys_UserAccount viewModel = new Model.T_Sys_UserAccount();
//当前对象实体
if (editType == 1)
{
viewModel.F_DeptId = int.Parse(deptId.ToString());
}
else
{
Model.T_Sys_UserAccount userModel = userBLL.GetModel(int.Parse(userId.ToString()));
viewModel = userModel;
}
//获取部门列表
viewModel.DepartmentList = deptBLL.GetModelList("F_ParentId=0");
//获取角色列表
viewModel.RoleInfoList = roleBLL.GetModelList("");
return View(viewModel);
}
///
/// 保存编辑
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveUserData(T_Sys_UserAccount userModel)
{
userModel.F_WorkNumber = userModel.F_UserCode;
if (userModel.F_UserId > 0)
{
T_Sys_UserAccount oldUserModel = userBLL.GetModel(userModel.F_UserId);
oldUserModel.F_WorkNumber = userModel.F_WorkNumber;
oldUserModel.F_UserName = userModel.F_UserName;
oldUserModel.F_UserCode = userModel.F_UserCode;
oldUserModel.F_DeptId = userModel.F_DeptId;
oldUserModel.F_RoleId = userModel.F_RoleId;
oldUserModel.F_SexFlag = userModel.F_SexFlag;
oldUserModel.F_Telephone = userModel.F_Telephone;
oldUserModel.F_SeatFlag = userModel.F_SeatFlag;
oldUserModel.F_SeatRight = userModel.F_SeatRight;
oldUserModel.F_Password = userModel.F_Password;
oldUserModel.F_Remark = userModel.F_Remark;
return userBLL.Update(oldUserModel);
}
else
{
userModel.F_HJType = 0;
userModel.F_GroupId = 1;
if (userModel.F_SeatFlag)
{
#region 调用接口插入用户信息
try
{
StringBuilder returnStr = new StringBuilder();
string wxAddUrl = "http://zzmetro-kf.sujie-china.com/api/customer/insert";
UserInfo model = new UserInfo();
model.name = userModel.F_UserCode;
object userInfo = JObject.Parse(JsonConvert.SerializeObject(model));
string addWxResult = HttpHelper.HttpPost(wxAddUrl, userInfo);
ResponseResult ResultModel = JsonConvert.DeserializeObject(addWxResult);
userModel.F_PId = ResultModel.data;
}
catch (Exception ex)
{
}
#endregion
}
return userBLL.Add(userModel) > 0;
}
}
///
/// 删除用户
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteUserData(int userId)
{
return userBLL.Delete(userId);
}
///
/// 获取用户数据
///
/// 当前页码
/// 每页数据量
///
[ActionName("UserDate")]
[HttpGet]
public string UserDate(DateTime? NowDateTime, int page, int limit, int? deptId)
{
//数据结果集
ResponseData dataModel = new ResponseData();
string sql = "";
if (deptId != null && deptId > 0)
{
sql += " and F_DeptId=" + deptId;
}
DataTable dt = new DataTable();
int recordCount = 0;
Model.PageData pageModel = new Model.PageData();
dt = BLL.PagerBLL.GetListPager(
"T_Sys_UserAccount",
"F_UserId",
"*"
+ ",(select top 1 t.F_DeptName from T_Sys_Department t where t.F_DeptId=T_Sys_UserAccount.F_DeptId) as F_DeptName "
+ ",(select top 1 t.F_RoleName from T_Sys_RoleInfo t where t.F_RoleId=T_Sys_UserAccount.F_RoleId) as F_RoleName "
+ ",(CASE F_SeatFlag WHEN 1 THEN '使用' WHEN 0 THEN '不使用' ELSE NULL END ) as F_SeatFlagName"
+ ",(CASE F_SeatRight WHEN 1 THEN '班长坐席' WHEN 0 THEN '普通坐席' ELSE NULL END ) as F_SeatRightName"
,
sql,
"ORDER BY F_UserCode asc ",
limit,
page,
true,
out recordCount);
dataModel.code = 0;
dataModel.count = recordCount;
dataModel.data = dt;
return JsonConvert.SerializeObject(dataModel);
}
#endregion
#region 修改密码
///
///用户修改个人密码
///
///
///
public ActionResult UserPwdEdit()
{
Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
if (F_UserID > 0)
{
model = userBLL.GetModel(F_UserID);
}
return View(model);
}
///
///保存修改密码
///
[AcceptVerbs(HttpVerbs.Post)]
public string UpdateUserPwd(Model.T_Sys_UserAccount model)
{
string AddRersult = "false";
if (model.F_UserId > 0)
{
Model.T_Sys_UserAccount newModel = userBLL.GetModel(model.F_UserId);
if (newModel != null && newModel.F_Password == model.oldPwd)
{
newModel.F_Password = model.password;
if (userBLL.Update(newModel))
{
AddRersult = "True";
}
}
else
{
AddRersult = "旧密码不正确!";
}
}
return AddRersult;
}
#endregion
#region 基本信息
///
/// 用户编辑
///
/// 类型1、新增 2、修改
/// ///
public ActionResult UserView()
{
Model.T_Sys_UserAccount userModel = userBLL.GetModel(F_UserID);
if (string.IsNullOrEmpty(userModel.F_HomePhone))
{
userModel.F_HomePhone = "/Content/images/face.jpg";
}
else
{
if (!System.IO.File.Exists(Server.MapPath(userModel.F_HomePhone)))
{
userModel.F_HomePhone = "/Content/images/face.jpg";
}
}
return View(userModel);
}
#endregion
#region 图片上传
///
/// 图片上传
///
///
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadFile()
{
try
{
if (Request.Files.Count > 0)
{
string uppath = string.Empty;
string savepath = string.Empty;
HttpPostedFileBase imgFile = Request.Files[0];
if (imgFile != null)
{
//创建图片新的名称
string nameImg = DateTime.Now.ToString("yyyyMMddHHmmssfff");
//获得上传图片的路径
string strPath = imgFile.FileName;
//获得上传图片的类型(后缀名)
string type = strPath.Substring(strPath.LastIndexOf(".") + 1).ToLower();
//拼写数据库保存的相对路径字符串
savepath = "/Content/HeadImg/images/";
//拼写上传图片的路径
uppath = Server.MapPath("~/Content/HeadImg/images/");
if (!Directory.Exists(Path.GetDirectoryName(uppath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(uppath));
}
uppath += nameImg + "." + type;
savepath += nameImg + "." + type;
//上传图片
imgFile.SaveAs(uppath); //原图片路径
}
Model.T_Sys_UserAccount userModel = userBLL.GetModel(F_UserID);
userModel.F_HomePhone = savepath;
if (userBLL.Update(userModel))
{
return Json(new
{
code = 0,
src = savepath,
msg = "上传成功"
});
}
else
{
return Json(new
{
code = 1,
src = "",
msg = "上传出错 请检查图片名称或图片内容"
});
}
}
else
{
return Json(new
{
code = 1,
src = "",
msg = "上传出错 请检查图片名称或图片内容"
});
}
}
catch (Exception ex)
{
return Json(new
{
code = 1,
src = "",
msg = "上传出错: " + ex.Message
});
}
}
#endregion
#region 公告管理
///
/// 公告管理
///
///
public ActionResult noticeManage()
{
Model.T_Msg_NoticeInfo noticeModel = new Model.T_Msg_NoticeInfo();
return View(noticeModel);
}
public ActionResult test()
{
Model.T_Msg_NoticeInfo noticeModel = new Model.T_Msg_NoticeInfo();
return View(noticeModel);
}
///
/// 获取公告数据
///
/// 当前页码
/// 每页数据量
///
[ActionName("NoticeListDate")]
[HttpGet]
public string NoticeListDate(DateTime? NowDateTime, int page, int limit, int? parentId)
{
//数据结果集
ResponseData dataModel = new ResponseData();
string sql = "";
if (parentId != null)
{
sql += " and F_ParentId=" + parentId;
}
DataTable dt = new DataTable();
int recordCount = 0;
Model.PageData pageModel = new Model.PageData();
dt = BLL.PagerBLL.GetListPager(
"T_Msg_NoticeInfo",
"F_NoticeId",
"*,CONVERT(varchar,F_CreateOn, 120 ) as F_CreateOnNew ",
sql,
"ORDER BY F_NoticeId desc ",
limit,
page,
true,
out recordCount);
dataModel.code = 0;
dataModel.count = recordCount;
dataModel.data = dt;
return JsonConvert.SerializeObject(dataModel);
}
BLL.T_Msg_NoticeInfo noticeBLL = new BLL.T_Msg_NoticeInfo();
BLL.T_Msg_NoticeUsers noticeuserBLL = new BLL.T_Msg_NoticeUsers();
BLL.T_Sys_UserAccount usersBLL = new BLL.T_Sys_UserAccount();
///
/// 编辑公告
///
/// 类型1、新增 2、修改
/// ///
public ActionResult NoticeEdit(int? noticeId, int editType)
{
Model.T_Msg_NoticeInfo viewModel = new Model.T_Msg_NoticeInfo();
//当前对象实体
if (editType == 1)
{
viewModel.F_NoticeId = int.Parse(noticeId.ToString());
viewModel.UseList = userBLL.GetModelList("");
}
else
{
Model.T_Msg_NoticeInfo userModel = noticeBLL.GetModel(int.Parse(noticeId.ToString()));
viewModel = userModel;
viewModel.UseList = userBLL.GetModelList("F_DeptId=" + userModel.F_ReceiveInfo);
}
//获取部门列表
viewModel.DepartmentList = deptBLL.GetModelList("F_ParentId=0");
return View(viewModel);
}
///
/// 查看公告
///
/// 类型1、新增 2、修改
/// ///
public ActionResult NoticeView(int? noticeId)
{
Model.T_Msg_NoticeInfo viewModel = new Model.T_Msg_NoticeInfo();
viewModel.F_NoticeId = int.Parse(noticeId.ToString());
viewModel.UseList = userBLL.GetModelList("");
Model.T_Msg_NoticeInfo userModel = noticeBLL.GetModel(int.Parse(noticeId.ToString()));
viewModel = userModel;
viewModel.UseList = userBLL.GetModelList("F_DeptId=" + userModel.F_ReceiveInfo);
//获取部门列表
viewModel.DepartmentList = deptBLL.GetModelList("F_ParentId=0");
return View(viewModel);
}
///
/// 保存编辑公告
///
///
///
[AcceptVerbs(HttpVerbs.Post)]
public bool SaveNoticeData(T_Msg_NoticeInfo noticeinfoModel)
{
bool result = false;
DataTable dt = new DataTable();
DataTable dtuser = new DataTable();
int noticeid = 0;
Model.T_Msg_NoticeUsers noticeuserModel = new Model.T_Msg_NoticeUsers();
DateTime? readdate =null;
try
{
//获取当前用户
noticeinfoModel.F_CreateBy = F_UserID;
noticeinfoModel.F_CreateName = HttpUtility.UrlDecode(F_UserName);
if (noticeinfoModel.F_NoticeId > 0)
{
noticeid = noticeinfoModel.F_NoticeId;
Model.T_Msg_NoticeInfo oldnoticeinfoModel = noticeBLL.GetModel(int.Parse(noticeid.ToString())); ;
dt = new YTSoft.BaseCallCenter.BLL.T_Msg_NoticeInfo().GetList("1=1 and F_NoticeId= " + noticeid).Tables[0];
if (dt.Rows.Count > 0)
{
dtuser = new YTSoft.BaseCallCenter.BLL.T_Sys_UserAccount().GetList("1=1 and F_DeptId= " + Convert.ToInt32(dt.Rows[0]["F_ReceiveInfo"].ToString())).Tables[0];
foreach (DataRow dr in dtuser.Rows)
{
noticeuserModel.F_UserId = Convert.ToInt32(dr["F_UserId"].ToString());
result = noticeuserBLL.Delete(noticeid, noticeuserModel.F_UserId);
}
}
readdate =Convert.ToDateTime( oldnoticeinfoModel.F_CreateOn);
oldnoticeinfoModel.F_Code = noticeinfoModel.F_Code;
oldnoticeinfoModel.F_Title = noticeinfoModel.F_Title;
oldnoticeinfoModel.F_Resume = noticeinfoModel.F_Resume;
oldnoticeinfoModel.F_Content = noticeinfoModel.F_Content;
oldnoticeinfoModel.F_ReceiveInfo = noticeinfoModel.F_ReceiveInfo;
oldnoticeinfoModel.F_DeviceId = noticeinfoModel.F_DeviceId;
oldnoticeinfoModel.F_State = 1;
result = noticeBLL.Update(oldnoticeinfoModel);
}
else
{
noticeid = 0;
noticeinfoModel.F_DeviceId = noticeinfoModel.F_UserId;
noticeinfoModel.F_State = 1;
noticeinfoModel.F_CreateOn = DateTime.Now;
readdate = noticeinfoModel.F_CreateOn;
noticeid = noticeBLL.Add(noticeinfoModel);
}
//指定方式发送公告
if (noticeinfoModel.F_DeviceId > 0)
{//指定人员发公告
noticeuserModel.F_NoticeId = noticeid;
noticeuserModel.F_UserId = Convert.ToInt32(noticeinfoModel.F_UserId);
noticeuserModel.F_UserName = noticeinfoModel.F_UserName;
if (readdate.ToString() != "")
{ noticeuserModel.F_ReadDate = readdate; }
else
{
noticeuserModel.F_ReadDate = noticeinfoModel.F_CreateOn;
}
noticeuserModel.F_State = 0;
noticeuserModel.F_Type = 0;
result = noticeuserBLL.Add(noticeuserModel);
}
else
{//指定部门发公告
dt = new YTSoft.BaseCallCenter.BLL.T_Sys_UserAccount().GetList("1=1 and F_DeptId= " + noticeinfoModel.F_ReceiveInfo).Tables[0];
if (dt.Rows.Count > 0)
{
noticeuserModel.F_NoticeId = noticeid;
if (readdate.ToString()!="")
{ noticeuserModel.F_ReadDate = readdate; }
else {
noticeuserModel.F_ReadDate = noticeinfoModel.F_CreateOn;
}
foreach (DataRow dr in dt.Rows)
{
noticeuserModel.F_UserId = Convert.ToInt32(dr["F_UserId"].ToString());
noticeuserModel.F_UserName = dr["F_UserName"].ToString();
noticeuserModel.F_State = 0;
noticeuserModel.F_Type = 0;
result = noticeuserBLL.Add(noticeuserModel);
}
}
}
}
catch (Exception) { }
finally
{
dt.Clear();
dt.Dispose();
}
return result;
}
///
/// 删除公告
///
///
///
[AcceptVerbs(HttpVerbs.Get)]
public bool DeleteNoticeData(int noticeId)
{
bool res = false;
DataTable dt = new DataTable();
DataTable dtuser = new DataTable();
Model.T_Msg_NoticeUsers noticeuserModel = new Model.T_Msg_NoticeUsers();
try
{
dt = noticeBLL.GetList("1=1 and F_NoticeId= " + noticeId).Tables[0];
if (dt.Rows.Count > 0)
{
res = noticeBLL.Delete(noticeId);
//指定部门发公告
dtuser = new YTSoft.BaseCallCenter.BLL.T_Sys_UserAccount().GetList("1=1 and F_DeptId= " + Convert.ToInt32( dt.Rows[0]["F_ReceiveInfo"].ToString()) ).Tables[0];
foreach (DataRow dr in dtuser.Rows)
{
noticeuserModel.F_UserId = Convert.ToInt32(dr["F_UserId"].ToString());
noticeuserBLL.Delete(noticeId, noticeuserModel.F_UserId);
}
}
}
catch (Exception) { }
finally {
dt.Clear();
dt.Dispose();
dtuser.Clear();
dtuser.Dispose();
}
return res;
}
///
/// 未接根据recordid更新回访信息
///
///
///
[ActionName("SetNoticeState")]
[HttpGet]
public string SetNoticeState(string id, string timeno)
{
string res = "";
try
{
Model.T_Msg_NoticeInfo model = new Model.T_Msg_NoticeInfo();
model.F_State =1;
model.F_NoticeId = Convert.ToInt32(id);
bool bl = new BLL.T_Msg_NoticeInfo().UpdateNoticeState(model);
if (bl)
{
res = "success";
}
}
catch
{ }
return res;
}
[ActionName("CookieData")]
[HttpGet]
public string CookieData() {
return F_UserID.ToString();
}
#endregion
}
#region 接口基本信息
///
/// 用户信息
///
public class UserInfo
{
public int id
{
get;
set;
}
public string name
{
get;
set;
}
}
///
/// 返回结果信息
///
public class ResponseResult
{
public int code
{
get;
set;
}
public int data
{
get;
set;
}
}
///
/// 返回结果信息
///
public class WXResponseResult
{
public int customer
{
get;
set;
}
public int service
{
get;
set;
}
public int total
{
get;
set;
}
}
#endregion
}