| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- using Newtonsoft.Json;
- 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.Models;
- /// <summary>
- /// 标签快捷管理
- /// </summary>
- namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
- {
- public class ClassController : BaseController
- {
- BLL.T_Com_Class busClass = new BLL.T_Com_Class();
-
- #region 纯视图
- /// <summary>
- /// 回复列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetList()
- {
- return View();
- }
- /// <summary>
- /// 添加 视图
- /// </summary>
- /// <returns></returns>
- public ActionResult Add()
- {
- return View();
- }
- /// <summary>
- /// 修改 视图
- /// </summary>
- /// <returns></returns>
- public ActionResult Edit()
- {
- return View();
- }
- #endregion
- #region 增删改查
- [ActionName("GetListData")]
- public string GetListData(string key = "", int page = 0, int limit = 20)
- {
- string strWhere = " 1=1 ";
- if (!string.IsNullOrEmpty(key))
- {
- strWhere += string.Format(" and Classname like '%{0}%'", key);
- }
- DataTable dt = busClass.GetListByPage(strWhere, " Classid desc ", (page - 1) * limit, limit).Tables[0];
- int count = busClass.GetRecordCount(strWhere);
- return Success("成功", dt, count);
- }
- [ActionName("GetData")]
- public string GettData(int id)
- {
- if (id==0)
- return Error("请输入ID");
- Model.T_Com_Class model = busClass.GetModel(id);
- return Success("成功", model, 1);
- }
- [ActionName("deletedata")]
- public string DeleteData(int id)
- {
- if (busClass.Delete(id))
- {
- //AddLog("T_Com_LogAction", model.Id, "删除消息", model, "");
- return Success("删除成功");
- }
- else
- return Error("失败");
- }
- [ActionName("adddata")]
- public string AddData(T_Com_Class modelinput)
- {
- T_Com_Class model = new T_Com_Class();
- model.Classcode = modelinput.Classcode;
- model.Classname = modelinput.Classname;
- //model.Parentcode = modelinput.Parentcode;
- model.Parentid = modelinput.Parentid;
- model.Remark = modelinput.Remark;
- model.Sort = modelinput.Sort;
- if (modelinput.Parentid != 0)
- {
- T_Com_Class modeltemp = busClass.GetModel(modelinput.Parentid);
- if (modeltemp.Parentid == 0)
- model.typeid = modeltemp.Classid;
- else
- model.typeid = modeltemp.typeid;
- }
- if (string.IsNullOrEmpty(modelinput.Classname))
- {
- return Error("请输入值Classname");
- }
- string strWhere = string.Format(" Classname='{0}' and Parentid='{1}' ", model.Classname, model.Parentid);
- int count = busClass.GetRecordCount(strWhere);
- if (count > 0)
- {
- return Error("已存在");
- }
- if (busClass.Add(model) >0)
- {
- //AddLog("T_Com_Tag", model.F_Id.ToString(), "添加标签", "", model);
- return Success("成功", modelinput, 1);
- }
- else
- return Error("失败");
- }
- [ActionName("editdata")]
- public string EditData(T_Com_Class modelinput)
- {
- if (string.IsNullOrEmpty(modelinput.Classname))
- {
- return Error("请输入值Classname");
- }
- if (modelinput.Classid == 0)
- return Error("请输入值Classid");
- string strWhere = string.Format(" Classname='{0}' and Parentid='{1}' and Classid!={2} ", modelinput.Classname, modelinput.Parentid, modelinput.Classid);
- int count = busClass.GetRecordCount(strWhere);
- if (count > 0)
- {
- return Error("已存在");
- }
- Model.T_Com_Class model = busClass.GetModel(modelinput.Classid);
- model.Classname = modelinput.Classname;
- model.Parentid = modelinput.Parentid;
- model.Remark = modelinput.Remark;
- model.Sort = modelinput.Sort;
- model.Classcode = modelinput.Classcode;
- if (modelinput.Parentid != 0)
- {
- T_Com_Class modeltemp = busClass.GetModel(modelinput.Parentid);
- if (modeltemp.Parentid == 0)
- model.typeid = modeltemp.Classid;
- else
- model.typeid = modeltemp.typeid;
- }
- if (busClass.Update(model))
- {
- //AddLog("T_Com_Tag", model.F_Id.ToString(), "修改消息", modelold, model);
- return Success("成功", model, 1);
- }
- else
- return Error("失败");
- }
- #endregion
- #region 获取树结构
- /// <summary>
- /// 获得当前节点下的所有子集以tree的格式
- /// </summary>
- public TreeNodeModel GetTreeJsonModel(int parentId, int type = 0)
- {
- TreeNodeModel returnModel = new TreeNodeModel();
- DataSet ds = busClass.GetList(string.Format("Parentid={0} Order by sort desc", parentId));
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- TreeNodeModel model = new TreeNodeModel();
- if (!false)
- {
- List<TreeNodeModel> modelList = new List<TreeNodeModel>();
- model.id = 0;
- model.name = "通用字典";
- model.code = 0;
- model.iconClose = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_close.png";
- model.iconOpen = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_open.png";
- model.open = "true";
- model.children = modelList;
- }
- returnModel = GetTreeModel(ds.Tables[0], model, type);
- }
- return returnModel;
- }
- /// <summary>
- /// 获取chlid
- /// </summary>
- /// <param name="table">数据结合</param>
- /// <param name="model">当前model</param>
- /// <returns></returns>
- public TreeNodeModel GetTreeModel(DataTable table, TreeNodeModel model, int type)
- {
- DataSet ds = busClass.GetList(string.Format("Parentid={0} Order by sort desc", model.code));
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- foreach (DataRow row in ds.Tables[0].Rows)
- {
- List<TreeNodeModel> modelList = new List<TreeNodeModel>();
- TreeNodeModel childModel = new TreeNodeModel();
- childModel.id = int.Parse(row["Classid"].ToString());
- childModel.name = row["Classname"].ToString();
- childModel.code = int.Parse(row["Parentid"].ToString());
- childModel.iconClose = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_close.png";
- childModel.iconOpen = "../../Content/layui/zTree/v3/css/zTreeStyle/img/diy/1_open.png";
- childModel.open = "true";
- childModel.children = modelList;
- model.children.Add(childModel);
- GetTreeModel(table, childModel, type);
- }
- }
-
- return model;
- }
- #endregion
- }
- }
|