《MVC——“树形的增删查改”》项目研发阶段性总结
作者:李坤凤
本次任务完成时间:2019年1月31日
开发工具与关键技术:开发工具:SQL、.net,关键技术:JS、JavaScript、C#语法
完成模块功能:树形图的增删查改
一、树形图的增删查改功能实现效果图
1)新增
1、 在图中有三个按钮,点击新增按钮,弹出新增商品分类模态框;
2、 在新增数据时如没有选择分类,则弹出显示框提示新增不成功;选择分类,则弹出显示框提示新增成功;
2)查询
1、新增成功后,刷新查询,父节点下新增了一个节点;
3)修改
1、 获取需要修改的节点数据,点击修改按钮,弹出修改模态框,修改成功则弹出显示框,提示修改成功,刷新页面,父节点下的节点显示已修改;
4)删除
1、获取需要删除的节点数据,点击删除按钮,弹出显示框,点击确定按钮就删除成功,刷新页面被选中的节点已删除,点击取消按钮则返回主页面;
二、相关业务表和关系
三、代码
控制器
<ul id="Fejie" class="ztree"></ul>
<script>
//供应商树形图
function Fejie() {
$(function () {
$.ajax({
type: "Get",
url: "/Intelligencemenge/Borrow/selectClientele",
async: true,
success: function (date) {
$.fn.zTree.init($("#treedemo"), setting, date);
$.fn.zTree.init($("#Fejie"), setting, date);
}
});
});
var setting = {
async: {
enable: true,
},
data: {
simpleData: {
enable: true,
idKey: "id",
}
},
callback: {
onClick: zTreeOnClick
}
};
function zTreeOnClick(event, treeId, treeNode) {
TreeId = parseInt(treeNode.id);
TreeName = treeNode.name;
ClassId = parseInt(treeNode.pId);
btnButtom();//调用供应商多条件查询
}
}
//供应商分类模态框新增保存按钮 树形
function doAdd() {
var Id = TreeId;
var name = encodeURI($("#ClassifyName").val()).trim();
if (Id == undefined) {
swal({ title: "", text: "请选择分类", showConfirmButton: true, type: "warning" });
}
else if (Id != 2) {
if (name !=""){
$.getJSON("/Intelligencemenge/Clientele/InsertClientele?son=" + Id + "&name=" + name, function (msg) {//异步提交
if (msg = "success") {
swal({ title: "", text: "保存成功!", showConfirmButton: true, type: "success" }, function () {
Fejie();
$("#modBaseT").modal("hide");
});
}
});
}
else {
swal({ title: "", text: "节点名称不能为空!", showConfirmButton: true, type: "success" });
}
}
else {
swal({ title: "", text: "供应商分类为系统初始化分类,不允许编辑、删除、添加新的子节点!", timer: 2000, showConfirmButton: false, type: "success" });
}
}
//供应商分类模态框修改按钮 树形
function BtnEdit() {
var Id = TreeId;
var name = encodeURI($("#ClassifyName").val()).trim();
var cId = ClassId;
if (Id == undefined || cId == undefined) {
swal({ title: "", text: "请选择分类", showConfirmButton: true, type: "warning" });
} else {
$.getJSON("/Intelligencemenge/Clientele/UpdateClientType?Id=" + Id + "&ClassId=" + cId + "&name=" + name, function (msg) {
if (msg == "success") {
swal({ title: "", text: "修改成功", showConfirmButton: true, type: "success" }, function () {
location.reload();
Fejie();
//treeDemo();
$("#modBase").modal("hide");
});
}
else {
swal({ title: "", text: "修改失败", showConfirmButton: true, type: "warning" });
}
});
}
}
//供应商删除按钮 树形
$("#btnDelete").click(function () {
var Id = TreeId;
if (TreeId != undefined) {
if (TreeId != 1) {
if (TreeId != 2) {
swal({
title: "",//大字体
text: "确定要删除吗?",//小字体
type: "warning",//图标内容
showCancelButton: true,//是否显示取消按钮
cancelButtonColor: '#d33',//取消按钮颜色
confirmButtonColor: "#DD6B55",//确认按钮颜色
confirmButtonText: "确定",//确认按钮 文本内容
cancelButtonText: "取消",//取消按钮 文本内容
closeOnConfirm: false,
closeOnCancel: false
}, function (isConfirm) {
if (isConfirm) {
$.getJSON("/Intelligencemenge/Clientele/DeleteClientType?Id=" + Id, function (msg) {
if (msg == "success") {
swal({ title: "", text: "删除成功", showConfirmButton: true, type: "success" }, function () {
location.reload();//刷新
Fejie();
//treeDemo();
$("#modBase").modal("hide");
});
}
else if (msg == "have") {
swal({ title: "", text: "存在有子节点,先删除子节点!", showConfirmButton: true, type: "warning" });
}
});
}
});
}
else {
swal({ title: "", text: "供应商分类为默认分类,不允许编辑、删除、添加新的子节点!", showConfirmButton: true, type: "warning" });
}
}
else {
swal({ title: "", text: "供应商分类为系统初始化分类,不允许编辑、删除、添加新的子节点!", showConfirmButton: true, type: "warning" });
}
}
else {
swal({ title: "", text: "请选择分类", showConfirmButton: true, type: "warning" });
}
});
</script>