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;
///
/// 标签快捷管理
///
namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
{
public class ClassController : BaseController
{
BLL.T_Com_Class busClass = new BLL.T_Com_Class();
#region 纯视图
///
/// 回复列表
///
///
public ActionResult GetList()
{
return View();
}
///
/// 添加 视图
///
///
public ActionResult Add()
{
return View();
}
///
/// 修改 视图
///
///
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 获取树结构
///
/// 获得当前节点下的所有子集以tree的格式
///
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 modelList = new List();
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;
}
///
/// 获取chlid
///
/// 数据结合
/// 当前model
///
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 modelList = new List();
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
}
}