C# MVC +EasyUI 增删改查

现有三张数据表如下:

ApplyProcessModule(模块表)
模块表
ApplyProcessTemplate(模板表)
模板表
ApplyProcessStepConfigInfo(流程步骤表)
流程步骤表

表关系如下:

流程步骤表的流程模板Id=模板表模板id
流程步骤表的模块id=模块表模块id
流程步骤表的下一步骤ID=模块表模块id


View(视图)

List.cshtml
@{
    Layout = null;
}
<div class="easyui-layout" data-options="fit: true">
    <div class="@ViewBag.PageSelectorSearch applyprocessstepconfiginfo-wrapper-search" data-options="region:'north',title:'查询条件',split:true, collapsible: false">
        <ul class="clearfix">
            <li class="clearfix">
                <span class="editor-label">模板编号:</span>
                <span class="editor-field"><input class="select-applyprocesstemplate" /></span>
            </li>
            <li class="clearfix">
                <span class="editor-label">模块编号:</span>
                <span class="editor-field"><input class="select-applyprocessmodule" /></span>
            </li>
            <li class="clearfix">
                <span class="editor-label"><a href="javascript:void(0);" class="button-search">查询</a></span>
            </li>
            <li class="clearfix">
                <span class="editor-label"><a href="javascript:void(0);" class="button-clear">清空</a></span>
            </li>
        </ul>
    </div>
    <div class="applyprocessstepconfiginfo-wrapper-grid" data-options="region:'center', border:false">
        <table class="grid-table"></table>
    </div>
</div>
<style type="text/css">

    .applyprocessstepconfiginfo-wrapper-search {
        height: 80px;
    }

        .applyprocessstepconfiginfo-wrapper-search ul {
            margin: 10px 0 0 0;
            padding: 0;
        }

            .applyprocessstepconfiginfo-wrapper-search ul li {
                float: left;
                height: 30px;
            }

        .applyprocessstepconfiginfo-wrapper-search input,
        .applyprocessstepconfiginfo-wrapper-search select {
            display: inline-block;
            white-space: nowrap;
            margin: 0;
            padding: 0;
            overflow: hidden;
            vertical-align: middle;
            height: 20px;
            border: solid 1px #95B8E7;
        }

        .applyprocessstepconfiginfo-wrapper-search .editor-label {
            height: 22px;
            line-height: 22px;
            padding-left: 20px;
            display: inline-block;
            vertical-align: middle;
        }

        .applyprocessstepconfiginfo-wrapper-search .editor-label-child {
            height: 22px;
            line-height: 22px;
            display: inline-block;
            vertical-align: middle;
        }

        .applyprocessstepconfiginfo-wrapper-search .editor-field {
            height: 22px;
            line-height: 22px;
            display: inline-block;
            vertical-align: middle;
        }
</style>
<script src="~/Scripts/custom/ApplyProcessFlow/applyprocessstepconfiginfo.list.js"></script>
ApplyProcessStepConfigInfoAppend.cshtml
@{
    Layout = null;
}
@model ZAEsd.ViewModels.ApplyProcessFlow.VMApplyProcessStepConfigInfo
@using ZAEsd.Business

<div class="applyprocessstepconfiginfo-list">
    <form id="ApplyProcesStepConfigInfoAppend" method="POST" class="applyprocessstepconfiginfo-wrapper-form">
        @Html.AntiForgeryToken()
        @if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            @Html.HiddenFor(m => m.Id)
        }
        <table cellpadding="8" cellspacing="0" style="margin: 15px 10px;width: 95%;">
           <tr>
                <td> 流程模板编号:</td>
                <td>
                    @Html.TextBoxFor(m => m.TemplateId, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td> 当前步骤编号:</td>
                <td>
                    @Html.TextBoxFor(m => m.ModuleId, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>下一步骤指定方式 :</td>
                <td>
                    @Html.TextBoxFor(m => m.NextStepMethod, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>下一步骤编号:</td>
                <td>
                    @Html.TextBoxFor(m => m.NextStepId, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>下一结点配置:</td>
                <td>
                    @Html.TextBoxFor(m => m.NextStepConfig, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>起始点:</td>
                <td>
                    @Html.TextBoxFor(m => m.StepType, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>说明:</td>
                <td>
                    @Html.TextBoxFor(m => m.StepConfigDescription, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>模块动态配置:</td>
                <td>
                    @Html.TextBoxFor(m => m.StepConfigModuleJson, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>序号:</td>
                <td>
                    @Html.TextBoxFor(m => m.StepConfigSort, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
            <tr>
                <td>提示语:</td>
                <td>
                    @Html.TextBoxFor(m => m.NoticeMessage, null, new Dictionary<string, object> { { "style", "width:174px;" } })
                </td>
            </tr>
        </table>
    </form>
</div>
<script src="~/Scripts/custom/ApplyProcessFlow/applyprocessstepconfiginfo.list.js"></script>





脚本代码

applyprocessstepconfiginfo.list.js
/// <reference path="../jquery/1.8.3/jquery-1.8.3.js" />
/// <reference path="common.js" />

$(function () {
    //流程模板Id
    $("#TemplateId").combobox({
        width: 178,
        url: '/ApplyProcessStepConfigInfo/GetApplyProcessTemplate',
        valueField: 'Id',
        textField: 'Name'
    });
    //模块Id
    $("#ModuleId").combobox({
        width: 178,
        url: '/ApplyProcessStepConfigInfo/GetApplyProcessModule',
        valueField: 'Id',
        textField: 'Name'
    });
    //下一步骤Id
    $("#NextStepId").combobox({
        width: 178,
        url: '/ApplyProcessStepConfigInfo/GetApplyProcessModule',
        valueField: 'Id',
        textField: 'Name'
    });
    //下一步骤指定方式(1直接指定,2配置)
    $("#NextStepMethod").combobox({
        width: 178,
        textField: "Key",
        valueField: "Value",
        data: [
            { Key: "直接指定", Value: "1" },
            { Key: "配置", Value: "2" }
        ]
    });
    //起始点 0或1
    $("#StepType").combobox({
        width: 178,
        textField: "Key",
        valueField: "Value",
        data: [
            { Key: "是", Value: "0" },
            { Key: "否", Value: "1" }
        ],
    });
    // 页面对象内容初始化     var Page = function (selector) {
        // 唯一选择器(配合公共选择类使用)
        this.selector = selector;

        //查询区域控件
        this.zSearch = $("." + selector + "-wrapper-search");
        this.zSearch.controls = {
            button_search: this.zSearch.find(".button-search"),
            button_clear: this.zSearch.find(".button-clear"),
            select_applyprocesstemplate: this.zSearch.find(".select-applyprocesstemplate"),
            select_applyprocessmodule: this.zSearch.find(".select-applyprocessmodule")
        }

        // 列表区域控件
        this.zGrid = $("." + selector + "-wrapper-grid");
        this.zGrid.controls = {
            grid: this.zGrid.find(".grid-table")
        };
        this.InitSearchControls();
        this.InitGridControls();
    }
    // 查询区域内容初始化     Page.prototype.InitSearchControls = function () {
        var zGrid = this.zGrid;
    }
    // 查询区域内容初始化
    Page.prototype.InitSearchControls = function () {
        var zSearch = this.zSearch;
        var zGrid = this.zGrid;
        // 模板编号
        zSearch.controls.select_applyprocesstemplate.combobox({
            width: 170,
            url: '/ApplyProcessStepConfigInfo/GetApplyProcessTemplate',
            valueField: 'Id',
            textField: 'Name',
        });
        // 模块编号
        zSearch.controls.select_applyprocessmodule.combobox({
            width: 170,
            url: '/ApplyProcessStepConfigInfo/GetApplyProcessModule',
            valueField: 'Id',
            textField: 'Name',
        });
        // 搜索
        zSearch.controls.button_search.linkbutton({ iconCls: "icon-search" }).click(function () {
            if (SearchValidate()) {
                zGrid.controls.grid.datagrid("load", {
                    ApplyProcessTemplate: zSearch.controls.select_applyprocesstemplate.combobox("getValue"),
                    ApplyProcessModule: zSearch.controls.select_applyprocessmodule.combobox("getValue")
                });
            } else {
                showMsg({ icon: 'error', msg: "请选择查询条件进行查询" });
            }
        });
        function SearchValidate() {
            var result = false;
            var template = zSearch.controls.select_applyprocesstemplate.combobox("getValue")
            if (template && template.length > 0) {
                return true;
            }
            var module = zSearch.controls.select_applyprocessmodule.combobox("getValue")
            if (module && module.length > 0) {
                return true;
            }
            return result;
        }
        // 清空按钮
        zSearch.controls.button_clear.linkbutton({ iconCls: "icon-reload" })
            .click(function () {
                zSearch.controls.select_applyprocesstemplate.combobox("setValue", "");
                zSearch.controls.select_applyprocessmodule.combobox("setValue", "");
            });
    }

    // datagrid区内容初始化
    Page.prototype.InitGridControls = function () {
        var base = this;
        var zGrid = this.zGrid;
        zGrid.controls.grid.datagrid({
            title: "申请流程步骤信息",
            fit: true,
            rownumbers: true,
            pagination: true,
            url: "/ApplyProcessStepConfigInfo/ApplyProcessStepConfigInfoList",
            queryParams: {
            },
            pageSize: 20,
            singleSelect: true,
            columns: [
                [
                    { field: "Id", title: "步骤Id", width: 150, hidden: true },
                    { field: "a", title: "模板编号", width: 120, align: "center" },
                    { field: "c", title: "模块编号", width: 120, sortable: true, align: "center" },
                    {
                        field: "NextStepMethod", title: "下一步骤指定方式", width: 120, sortable: true, align: "center", formatter: function (value) {
                            return value == 0 ? "直接指定" : "配置";
                        }
                    },
                    { field: "b", title: "下一步骤编号", width: 120, sortable: true, align: "center" },
                    { field: "NextStepConfig", title: "下一节点配置", width: 100, sortable: true, align: "center" },
                    {
                        field: "StepType", title: "起始点", width: 50, sortable: true, align: "center", formatter: function (value) {
                            return value == 0 ? "是" : "否";
                        }
                    },
                    { field: "StepConfigDescription", title: "说明", width: 150, sortable: true, align: "center" },
                    { field: "StepConfigModuleJson", title: "模块动态配置", width: 120, sortable: true, align: "center" },
                    { field: "StepConfigSort", title: "序号", width: 50, sortable: true, align: "center" },
                    { field: "NoticeMessage", title: "提示语", width: 100, sortable: true, align: "center" },
                    { field: "ModuleType", title: "模板类型", width: 120, sortable: true, align: "center" },
                    { field: "AddTime", title: "新增时间", width: 150, sortable: true, align: "center" },
                    { field: "ModifyTime", title: "修改时间", width: 150, sortable: true, align: "center" },
                    { field: "CreateBy", title: "创建人", width: 120, sortable: true, align: "center" },
                    { field: "ModifyBy", title: "修改人", width: 120, sortable: true, align: "center" }
                ]
            ], toolbar: [
                {
                    id: "btnAddInfo" + base.selector,
                    text: '新增',
                    disabled: false,
                    iconCls: 'icon-01-02',
                    handler: function () { addorEditInfo("add") }
                }, '-', {
                    id: "btnEditInfo" + base.selector,
                    text: '编辑',
                    disabled: true,
                    iconCls: 'icon-17-20',
                    handler: function () { addorEditInfo("edit") }
                }, '-', {
                    id: "btnDeleteInfo" + base.selector,
                    text: '删除',
                    disabled: true,
                    iconCls: 'icon-07-08',
                    handler: function () { remove() }
                }

            ], onSelect: function (rowIndex, rowData) {
                setButtonState();
            }
        });
        //设置按钮状态
        function setButtonState() {
            var row = zGrid.controls.grid.datagrid("getSelected");
            if (row) {
                zGrid.controls.tools.button_edit.linkbutton("enable");
                zGrid.controls.tools.button_remove.linkbutton("enable");
            }
        };
        function addorEditInfo(type) {
            var row = zGrid.controls.grid.datagrid("getSelected");
            var id = "";
            var title = "";
            if (type === "edit") {
                id = row.Id;
                title = "申请流程步骤修改";
            } else {
                title = "申请流程步骤添加";
            }
            var editDialog = $("<div></div>").dialog({
                title: title,
                href: "/ApplyProcessStepConfigInfo/ApplyProcessStepConfigInfoAppend?id=" + id,
                width: 450,
                height: 550,
                modal: true,
                buttons: [
                    {
                        iconCls: "icon-save",
                        text: "保存",
                        handler: function () {
                            var form = editDialog.find(".applyprocessstepconfiginfo-list form").form({
                                url: type === "add" ? "/ApplyProcessStepConfigInfo/Add" : "/ApplyProcessStepConfigInfo/Update",
                                onSubmit: function (params) {
                                    $("#NextStepConfig").validatebox({
                                        required: true,
                                        missingMessage: '请输入下一结点配置',
                                        validType: null
                                    });
                                    $("#StepConfigDescription").validatebox({
                                        required: true,
                                        missingMessage: '请输入说明',
                                        validType: null
                                    });
                                    $("#StepConfigModuleJson").validatebox({
                                        required: true,
                                        missingMessage: '请输入模块动态配置',
                                        validType: null
                                    });
                                    $("#StepConfigSort").validatebox({
                                        required: true,
                                        missingMessage: '请输入序号',
                                        validType: null
                                    });
                                    $("#NoticeMessage").validatebox({
                                        required: true,
                                        missingMessage: '请输入提示语',
                                        validType: null
                                    });
                                    if (!form.form('validate')) {
                                        return false;
                                    }
                                },
                                success: function (data) {
                                    var json = JSON.parse(data);
                                    if (json.ResponseStatus === 0) {
                                        showMsg({ icon: "success", msg: json.ResponseDetails });
                                        editDialog.dialog("close");
                                        zGrid.controls.grid.datagrid("reload");
                                    } else {
                                        showMsg({ icon: "error", msg: json.ResponseDetails });
                                    }
                                }
                            });
                            editDialog.find("form").form("submit");
                        }
                    },
                    {
                        iconCls: "icon-cancel",
                        text: "取消",
                        handler: function () {
                            editDialog.dialog("close");
                        }
                    }
                ],
                onClose: function () {
                    editDialog.dialog("destroy");
                }
            });
        };

        function remove() {
            var row = zGrid.controls.grid.datagrid("getSelected");
            $.messager.confirm("Warning", "你确定要删除该条数据?", function (r) {
                if (r) {

                    $.ajax({
                        url: "/ApplyProcessStepConfigInfo/Delete?id=" + row.Id,
                        type: "POST",
                        dataType: "JSON",
                        success: function (data) {
                            if (data.ResponseStatus == 1) {
                                zGrid.controls.grid.datagrid("reload");
                                showMsg({ icon: "success", msg: data.ResponseDetails });
                            }
                            else {
                                showMsg({ icon: "error", msg: data.ResponseDetails });
                            }
                        }

                    })
                }
            })

        };

        zGrid.controls.tools = {
            button_edit: $("#btnEditInfo" + base.selector),
            button_remove: $("#btnDeleteInfo" + base.selector)
        };
    }
    var base = new Page("applyprocessstepconfiginfo");
});

Model(模型)

ApplyProcessStepConfigInfoConfig.cs
using System.Data.Entity.ModelConfiguration;
using ZAEsd.EFEntity.Models;

namespace ZAEsd.EFEntity.Configs
{
    class ApplyProcessStepConfigInfoConfig : EntityTypeConfiguration<ApplyProcessStepConfigInfo>
    {
        public ApplyProcessStepConfigInfoConfig()
        {
            ToTable("ApplyProcessStepConfigInfo");
            // primary key
            HasKey(m => m.Id);
            Property(m => m.Id).HasColumnType("char").HasMaxLength(36);

            //列
            Property(m => m.StepType);
            Property(m => m.ModuleId).HasColumnType("char").HasMaxLength(36);
            Property(m => m.ModuleType);
            Property(m => m.NextStepConfig).HasColumnType("nvarchar").HasMaxLength(1000);
            Property(m => m.NextStepId).HasColumnType("char").HasMaxLength(36);
            Property(m => m.NextStepMethod);
            Property(m => m.NoticeMessage).HasColumnType("nvarchar").HasMaxLength(1000);
            Property(m => m.StepConfigDescription).HasColumnType("nvarchar").HasMaxLength(1000);
            Property(m => m.StepConfigModuleJson).HasColumnType("nvarchar").HasMaxLength(1000);
            Property(m => m.StepConfigSort);
            Property(m => m.TemplateId).HasColumnType("char").HasMaxLength(36);
            Property(m => m.AddTime);
            Property(m => m.ModifyTime);
            Property(m => m.CreateBy).HasColumnType("varchar").HasMaxLength(50);
            Property(m => m.ModifyBy).HasColumnType("varchar").HasMaxLength(50);
            Property(m => m.IsGuid);
        }
    }
}
ApplyProcessStepConfigInfo.cs
using System;

namespace ZAEsd.EFEntity.Models
{
    /// <summary>
    /// 申请流程步骤配置表
    /// </summary>
    public class ApplyProcessStepConfigInfo
    {
        /// <summary>
        /// 步骤id
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 模板id
        /// </summary>
        public string TemplateId { get; set; }
        /// <summary>
        /// 模块id
        /// </summary>
        public string ModuleId { get; set; }
        /// <summary>
        /// 下一步骤指定方式(0直接指定,1配置)
        /// </summary>
        public Flow_NextStepMethod NextStepMethod { get; set; }
        /// <summary>
        /// 下一步骤ID
        /// </summary>
        public string NextStepId { get; set; }
        /// <summary>
        /// 下一节点配置(格式固定)
        /// </summary>
        public string NextStepConfig { get; set; }
        /// <summary>
        /// 步骤类型
        /// </summary>
        public Flow_StepType StepType { get; set; }
        /// <summary>
        /// 说明
        /// </summary>
        public string StepConfigDescription { get; set; }
        /// <summary>
        /// 模块动态配置(json)
        /// </summary>
        public string StepConfigModuleJson { get; set; }
        /// <summary>
        /// 序号
        /// </summary>
        public int? StepConfigSort { get; set; }
        /// <summary>
        /// 提示语
        /// </summary>
        public string NoticeMessage { get; set; }
        /// <summary>
        /// 模板类型
        /// </summary>
        public int? ModuleType { get; set; }
        /// <summary>
        /// 新增时间
        /// </summary>
        public DateTime? AddTime { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? ModifyTime { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public string CreateBy { get; set; }
        /// <summary>
        /// 修改人
        /// </summary>
        public string ModifyBy { get; set; }
        /// <summary>
        /// 是否主导
        /// </summary>
        public bool? IsGuid { get; set; }
    }

    /// <summary>
    /// ApplyProcessStepConfigInfo:下一步骤指定方式 
    /// </summary>
    public enum Flow_NextStepMethod
    {
        直接指定 = 0,
        配置 = 1
    }

    public enum Flow_StepType
    {
        开始步骤 = 0,
        普通步骤 = 1,
        结束步骤 = 2,
        临时步骤 = 3
    }
}

Controller(控制器)

ApplyProcessStepConfigInfoController.cs

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Mvc;
using ZAEsd.Business;
using ZAEsd.Common;
using ZAEsd.EFEntity;
using ZAEsd.EFEntity.Models;
using ZAEsd.Mvc.AdminSite.Filters;
using ZAEsd.ViewModels.ApplyProcessFlow;

namespace ZAEsd.Mvc.AdminSite.Controllers
{
    public class ApplyProcessStepConfigInfoController : BaseController
    {
        [System.Web.Http.HttpGet]
        [AdminGrant]
        public ActionResult List()
        {
            return View(new ZAEsd.ViewModels.VM_Base());
        }

        #region 查询列表
         public ActionResult ApplyProcessStepConfigInfoList(int page, int rows, string sort = null,
            string order = null, string ApplyProcessTemplate = null, string ApplyProcessModule = null)
          {
                var applyProcessStepConfigInfoList = new B_ApplyProcessStepConfigInfo().GetApplyProcessFirstStepConfigInfoAll(
                page, rows,
                sort: sort, order: order,
                ApplyProcessTemplate: ApplyProcessTemplate, ApplyProcessModule: ApplyProcessModule );
                var result = JsonConvert.SerializeObject(new { total = applyProcessStepConfigInfoList .Tables[0].Rows[0][0], rows = applyProcessStepConfigInfoList .Tables[1] }, new JsonSerializerSettings()
              {
                NullValueHandling = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Converters = new List<JsonConverter> { new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" } }  //格式化时间
              });
               return Content(result);
           }
        #endregion

        #region 获取
        /// <summary>
        /// 获取
        /// </summary>
        public ActionResult ApplyProcessStepConfigInfoAppend(string id = null)
        {
            VMApplyProcessStepConfigInfo vmApplyProcessStepConfigInfo = new VMApplyProcessStepConfigInfo();

            using (var db = new DBContext())
            {
                if (!string.IsNullOrEmpty(id))
                {
                    var entity = db.ApplyProcessStepConfigInfoDs.FirstOrDefault(m => m.Id == id);
                    vmApplyProcessStepConfigInfo.Id = entity.Id;
                    vmApplyProcessStepConfigInfo.StepType = entity.StepType;
                    vmApplyProcessStepConfigInfo.ModuleId = entity.ModuleId;
                    vmApplyProcessStepConfigInfo.ModuleType = entity.ModuleType;
                    vmApplyProcessStepConfigInfo.NextStepConfig = entity.NextStepConfig;
                    vmApplyProcessStepConfigInfo.NextStepId = entity.NextStepId;
                    vmApplyProcessStepConfigInfo.NextStepMethod = entity.NextStepMethod;
                    vmApplyProcessStepConfigInfo.NoticeMessage = entity.NoticeMessage;
                    vmApplyProcessStepConfigInfo.StepConfigDescription = entity.StepConfigDescription;
                    vmApplyProcessStepConfigInfo.StepConfigModuleJson = entity.StepConfigModuleJson;
                    vmApplyProcessStepConfigInfo.StepConfigSort = entity.StepConfigSort;
                    vmApplyProcessStepConfigInfo.TemplateId = entity.TemplateId;
                }
            }
            return View(vmApplyProcessStepConfigInfo);
        }
        #endregion

        #region 新增
        [System.Web.Http.HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Add(VMApplyProcessStepConfigInfo entity)
        {
            ResponseResult result = new ResponseResult();
            var applyProcessStepConfigInfo = new ApplyProcessStepConfigInfo();
            var b_ApplyProcessStepConfigInfo = new B_ApplyProcessStepConfigInfo();
            applyProcessStepConfigInfo = b_ApplyProcessStepConfigInfo.FirstOrDefault(a => a.Id == entity.Id);
            if (applyProcessStepConfigInfo != null)
            {
                result.ResponseStatus = 1;
                result.ResponseDetails = "该编号已存在对应记录!";
                return Json(result);
            }
            var userName = string.Empty;
            try
            {
                if (B_Manager.GetLoginManager() != null)
                {
                    userName = B_Manager.GetLoginManager().Name;
                }
                applyProcessStepConfigInfo = new ApplyProcessStepConfigInfo()
                {
                    Id = Guid.NewGuid().ToString(),
                    StepType = entity.StepType,
                    ModuleId = entity.ModuleId,
                    ModuleType = entity.ModuleType,
                    NextStepConfig = entity.NextStepConfig,
                    NextStepId = entity.NextStepId,
                    NextStepMethod = entity.NextStepMethod,
                    NoticeMessage = entity.NoticeMessage,
                    StepConfigDescription = entity.StepConfigDescription,
                    StepConfigModuleJson = entity.StepConfigModuleJson,
                    StepConfigSort = entity.StepConfigSort,
                    TemplateId = entity.TemplateId,
                    CreateBy = userName,
                    AddTime = DateTime.Now,
                    ModifyTime = DateTime.Now,
                    ModifyBy = userName
                };
                ResponseResult result1 = new ResponseResult();
                if (entity.ModuleId == entity.NextStepId)
                {
                    result1.ResponseStatus = 1;
                    result1.ResponseDetails = "下一步骤编号不可与当前步骤编号相同,请重新选择下一步骤编号!";
                    return Json(result1);
                }
                if (b_ApplyProcessStepConfigInfo.Add(applyProcessStepConfigInfo) > 0)
                {
                    result.ResponseStatus = 0;
                    result.ResponseDetails = "新增成功!";
                    B_Log.AddByManager(OperateType.其他, $"管理员:{userName},新增一条模块基础数据成功,Id[{applyProcessStepConfigInfo.Id}]");
                }
                else
                {
                    result.ResponseStatus = 1;
                    result.ResponseDetails = "新增失败!";
                }
            }
            catch (Exception ex)
            {
                result.ResponseStatus = 99;
                result.ResponseDetails = $"新增异常,异常信息:{ ex.Message}!";
                B_Log.AddByManager(OperateType.其他, $"管理员:{userName},新增一条模块基础数据异常,Id[{applyProcessStepConfigInfo.Id}],异常数据:{ex}");
            }

            return Json(result);
        }
        #endregion

        #region 修改
        [System.Web.Http.HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Update(VMApplyProcessStepConfigInfo entity)
        {
            ResponseResult result = new ResponseResult();
            var applyProcessStepConfigInfo = new ApplyProcessStepConfigInfo();
            var b_ApplyProcessStepConfigInfo = new B_ApplyProcessStepConfigInfo();
            var userName = string.Empty;
            applyProcessStepConfigInfo = b_ApplyProcessStepConfigInfo.FirstOrDefault(a => a.Id == entity.Id);
            try
            {
                if (B_Manager.GetLoginManager() != null)
                {
                    userName = B_Manager.GetLoginManager().Name;
                }

                applyProcessStepConfigInfo.Id = entity.Id;
                applyProcessStepConfigInfo.StepType = entity.StepType;
                applyProcessStepConfigInfo.ModuleId = entity.ModuleId;
                applyProcessStepConfigInfo.ModuleType = entity.ModuleType;
                applyProcessStepConfigInfo.NextStepConfig = entity.NextStepConfig;
                applyProcessStepConfigInfo.NextStepId = entity.NextStepId;
                applyProcessStepConfigInfo.NextStepMethod = entity.NextStepMethod;
                applyProcessStepConfigInfo.NoticeMessage = entity.NoticeMessage;
                applyProcessStepConfigInfo.StepConfigDescription = entity.StepConfigDescription;
                applyProcessStepConfigInfo.StepConfigModuleJson = entity.StepConfigModuleJson;
                applyProcessStepConfigInfo.StepConfigSort = entity.StepConfigSort;
                applyProcessStepConfigInfo.TemplateId = entity.TemplateId;
                applyProcessStepConfigInfo.ModifyTime = DateTime.Now;
                applyProcessStepConfigInfo.ModifyBy = userName;
                ResponseResult result1 = new ResponseResult();
                if (entity.ModuleId == entity.NextStepId)
                {
                    result1.ResponseStatus = 1;
                    result1.ResponseDetails = "下一步骤编号不可与当前步骤编号相同,请重新选择下一步骤编号!";
                    return Json(result1);
                }
                if (b_ApplyProcessStepConfigInfo.Update(applyProcessStepConfigInfo) > 0)
                {
                    result.ResponseStatus = 0;
                    result.ResponseDetails = "修改成功!";
                    B_Log.AddByManager(OperateType.其他, $"管理员:{userName},修改一条模块基础数据成功,Id[{applyProcessStepConfigInfo.Id}]");
                }
                else
                {
                    result.ResponseStatus = 1;
                    result.ResponseDetails = "修改失败!";
                }
            }
            catch (Exception ex)
            {
                result.ResponseStatus = 99;
                result.ResponseDetails = $"修改异常,异常信息:{ ex.Message}!";
                B_Log.AddByManager(OperateType.其他, $"管理员:{userName},修改一条模块基础数据异常,Id[{entity.Id}],异常数据:{ex}");
            }
            return Json(result);
        }
        #endregion

        #region 删除
        [System.Web.Http.HttpPost]
        public ActionResult Delete(string id)
        {
            var result = new ResponseResult();
            var b_ApplyProcessStepConfigInfo = new B_ApplyProcessStepConfigInfo();
            var entity = b_ApplyProcessStepConfigInfo.GetById(id);
            if (entity == null)
            {
                result.ResponseDetails = "模块信息不存在";
                return Json(result);
            }
            var userName = string.Empty;
            try
            {
                if (B_Manager.GetLoginManager() != null)
                {
                    userName = B_Manager.GetLoginManager().Name;
                }

                if (b_ApplyProcessStepConfigInfo.Delete(entity) > 0)
                {
                    result.ResponseStatus = 1;
                    result.ResponseDetails = "删除成功";
                    B_Log.AddByManager(OperateType.其他, $"管理员:{userName},删除一条模块基础数据成功,Id[{id}]");
                }
                else
                {
                    result.ResponseStatus = 0;
                    result.ResponseDetails = "删除失败!";
                }
            }
            catch (Exception ex)
            {
                result.ResponseStatus = 99;
                result.ResponseDetails = $"删除异常,异常信息:{ ex.Message}!";
                B_Log.AddByManager(OperateType.其他, $"管理员:{userName},删除一条模块基础数据异常,Id[{id}],异常数据:{ex}");
            }
            return Json(result);
        }
        #endregion

        #region 查询流程模板编号(模板表)
        /// <summary>
        /// 查询流程模板编号
        /// </summary>
        /// <returns></returns>

        public JsonResult GetApplyProcessTemplate()
        {
            using (DBContext dbContext = new DBContext())
            {
                return Json(dbContext.ApplyProcessTemplateDs.OrderBy(a => a.Name).Distinct().ToList());
            }
        }

        #endregion

        #region 查询流程模块编号(模块表)
        /// <summary>
        /// 查询流程模板编号
        /// </summary>
        /// <returns></returns>
        public JsonResult GetApplyProcessModule()
        {
            using (DBContext dbContext = new DBContext())
            {
                return Json(dbContext.ApplyProcessModuleDs.OrderBy(a => a.Id).Distinct().ToList());
            }
        }
        #endregion
    }
}

B_ApplyProcessStepConfigInfo.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using ZAEsd.EFEntity;
using ZAEsd.EFEntity.Models;

namespace ZAEsd.Business
{
    public class B_ApplyProcessStepConfigInfo : B_Base<ApplyProcessStepConfigInfo>
    {
        #region 根据模板Id获取 申请流程首步骤配置信息
        /// <summary>
        /// 模板Id获取 申请流程首步骤配置信息
        /// </summary>
        /// <param name="applyId"></param>
        /// <returns></returns>
        public ApplyProcessStepConfigInfo GetApplyProcessFirstStepConfigInfoByemplateId(string templateId)
        {
            using (DBContext dbContext = new DBContext())
            {
                return dbContext.ApplyProcessStepConfigInfoDs.FirstOrDefault(a => a.StepType ==  Flow_StepType.开始步骤 && a.TemplateId == templateId);
            }
        }
        #endregion
        #region 查询
        public DataSet GetApplyProcessFirstStepConfigInfoAll(int? page = null, int? rows = null,
            string sort = null, string order = null, string ApplyProcessTemplate = null, string ApplyProcessModule = null)
        {
            #region 连接SQL
            var sql_joinlist = new List<SQLJoin>()
            {
                new SQLJoin("b", @"left join ApplyProcessTemplate b ON a.TemplateId = b.Id"),
                new SQLJoin("d", @"left join ApplyProcessModule d on a.ModuleId=d.Id"),
                 new SQLJoin("h", @"left join ApplyProcessModule h on a.NextStepId=h.Id")
            };
            #endregion
            #region 条件过滤SQL
            var sb_sql_r1 = new SQLBuilder(@"
                        a.Id,
                        b.Name as a,
                        d.Name as c,
                        a.NextStepMethod,
                        h.Name as b,
                        a.NextStepConfig,
                        a.StepType,
                        a.StepConfigDescription,
                        a.StepConfigModuleJson,
                        a.StepConfigSort,
                        a.NoticeMessage,
                        a.ModuleType,
                        a.AddTime,
                        a.ModifyTime,
                        a.CreateBy,
                        a.ModifyBy
                FROM  ApplyProcessStepConfigInfo a WITH ( NOLOCK )",
     sql_footer: string.Format(@"where 1=1"),
     sql_joinlist: sql_joinlist, keys: "b,d,h");
            if (!string.IsNullOrEmpty(ApplyProcessTemplate))
            {
                sb_sql_r1.SQL_Footer.AppendFormat(" and a.TemplateId='{0}'", ApplyProcessTemplate);
            }
            if (!string.IsNullOrEmpty(ApplyProcessModule))
            {
                sb_sql_r1.SQL_Footer.AppendFormat(" and a.ModuleId='{0}'", ApplyProcessModule);
            }

            #endregion
            #region 字段查询SQL
            var sb_sql_r2 = new SQLBuilder(@"
                SELECT  a.Id,
                        b.Name as a,
                        d.Name as c,
                        a.NextStepMethod,
                        h.Name as b,
                        a.NextStepConfig,
                        a.StepType,
                        a.StepConfigDescription,
                        a.StepConfigModuleJson,
                        a.StepConfigSort,
                        a.NoticeMessage,
                        a.ModuleType,
                        a.AddTime,
                        a.ModifyTime,
                        a.CreateBy,
                        a.ModifyBy
                FROM  ApplyProcessStepConfigInfo a WITH ( NOLOCK )", sql_footer: @"
                ", sql_joinlist: sql_joinlist, keys: "b,d,h");
            #endregion
            #region 输出SQL
            if (String.IsNullOrEmpty(sort))
            {
                sort = "Id";
            }
            if (String.IsNullOrEmpty(order))
            {
                order = "asc";
            }
            StringBuilder sb_sql_r3 = new StringBuilder(string.Format(@"select * from(
    select row_number() over (order by A.{0} {1}) as num,
     {2} ) a
", sort, order, sb_sql_r1.ToString()));

            #endregion
            using (var dbContext = new DBContext())
            {
                if (!page.HasValue)
                {
                    page = 1;
                    sb_sql_r3 = new StringBuilder(string.Format(@"
                               a.Id,
                               b.Name as a,
                               d.Name as c,
                               a.NextStepMethod,
                               h.Name as b,
                               a.NextStepConfig,
                               a.StepType,
                               a.StepConfigDescription,
                               a.StepConfigModuleJson,
                               a.StepConfigSort,
                               a.NoticeMessage,
                               a.ModuleType,
                               a.AddTime,
                               a.ModifyTime,
                               a.CreateBy,
                               a.ModifyBy
                        from ( {0} ) as result ", sb_sql_r3.ToString()
                    ));
                }
                else
                {
                    sb_sql_r3.Insert(0, string.Format(@"select count(*) from ( {0} ) r2; ", sb_sql_r2));
                }
                if (!rows.HasValue)
                {
                    rows = int.MaxValue;
                }
                sb_sql_r3.AppendFormat(" where num > {0} and num <= {1} order by num ", (page - 1) * rows, page * rows);
                return dbContext.SqlDataSet(sb_sql_r3.ToString());
            }
        }
        #endregion
    }
}

猜你喜欢

转载自blog.csdn.net/My_ben/article/details/81671367