示例#1
0
        public ActionResult Delete(string primaryKey)
        {
            var id = int.Parse(primaryKey);

            if (_itemService.Exists(r => r.SD_ITEM_ID == id))
            {
                var catCode   = _procStateService.DataItemProcCatCode();
                var procState = _procStateService.Get(
                    item => item.PROC_CAT_CODE == catCode && item.PROC_CONTENT_ID == primaryKey.Trim());
                if (procState != null)
                {
                    //var executeState = procState.PROC_STAT_CODE;
                    //if (executeState == _procStateService.HadExedProcStatCode() )
                    //    return Error("已被执行,请清库后再进行删除!");
                    var depCount = _itemDepService.GetManay(dep => dep.DEP_SD_ITEM_ID == id).Count;
                    if (depCount > 0)
                    {
                        return(Error("已被其它数据项依赖,不可删除!"));
                    }
                    var kpiCount = _kpiParamService.GetManay(param => param.SD_ITEM_ID == id).Count;
                    if (kpiCount > 0)
                    {
                        return(Error("已被评价指标当作参数使用,不可删除!"));
                    }
                }
                //清除单元库
                _itemResultService.UnitClearData(id);
                //清除PDP锁定数据
                _itemResultService.Delete(i => i.SD_ITEM_ID == id);
                //应先删除关联表
                _procStateService.Delete(item => item.PROC_CAT_CODE == catCode && item.PROC_CONTENT_ID == primaryKey.Trim());
                _itemDepService.Delete(item => item.SD_ITEM_ID == id);
                _itemOptionService.Delete(item => item.SD_ITEM_ID == id);
                //删除主表
                var row = _itemService.Delete(id);
                return(row > 0 ? Success("删除成功!") : Error("删除失败!"));
            }
            return(Success());
        }