Ejemplo n.º 1
0
 /// <summary>
 /// 获取单个实体
 /// </summary>
 /// <param name="keyValue"></param>
 /// <returns></returns>
 public ActionResult GetFormJson(string keyValue)
 {
     try
     {
         AccountRuleEntity entity = _bll.GetEntity(keyValue);
         return(ToJsonResult(entity));
     }
     catch (Exception ex)
     {
         return(ToJsonResult(ex));
     }
 }
Ejemplo n.º 2
0
        public ActionResult SaveForm(string keyValue, AccountRuleEntity entity)
        {
            Operator user = OperatorProvider.Provider.Current();

            WriteLog.AddLog($"用户:{user.UserName}  id:{user.UserId}开始编辑积分配置{keyValue} \r\n {JsonConvert.SerializeObject(entity)}", "SafetyScore");
            try
            {
                if (_bll.SaveForm(keyValue, entity))
                {
                    return(Success("操作成功"));
                }
                else
                {
                    return(Error("操作失败"));
                }
            }
            catch (Exception ex)
            {
                WriteLog.AddLog($"错误 \r\n用户:{user.UserName}  id:{user.UserId}编辑积分配置{keyValue}失败 \r\n 错误信息:{JsonConvert.SerializeObject(ex)}", "SafetyScore");
                return(Error(ex.Message));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 保存数据(新增、修改)
 /// </summary>
 /// <param name="keyValue"></param>
 /// <param name="entity"></param>
 /// <returns></returns>
 public bool SaveForm(string keyValue, AccountRuleEntity entity)
 {
     return(_ruleService.SaveForm(keyValue, entity));
 }
Ejemplo n.º 4
0
        public ActionResult Import()
        {
            Operator user = OperatorProvider.Provider.Current();

            try
            {
                if (this.Request.Files.Count == 0)
                {
                    throw new Exception("请上传文件");
                }
                if (!this.Request.Files[0].FileName.EndsWith(".xlsx"))
                {
                    return(Json(new { success = false, message = "请上传excel文件!" }));
                }

                var book  = new Workbook(this.Request.Files[0].InputStream);
                var sheet = book.Worksheets[0];

                if (sheet.Cells[1, 0].StringValue != "标准*" || sheet.Cells[1, 1].StringValue != "分值*" || sheet.Cells[1, 2].StringValue != "顺序号" || sheet.Cells[1, 3].StringValue != "备注")
                {
                    return(Json(new { success = false, message = "请使用正确的模板导入!" }));
                }


                List <AccountRuleEntity> importList = new List <AccountRuleEntity>();
                for (int i = 2; i <= sheet.Cells.MaxDataRow; i++)
                {
                    if (string.IsNullOrEmpty(sheet.Cells[i, 0].StringValue))
                    {
                        throw new Exception($"行号{i + 1}的”标准“不能为空");
                    }
                    if (sheet.Cells[i, 0].StringValue.Length > 512)
                    {
                        throw new Exception($"行号{i + 1}的”标准“长度不能超过512");
                    }
                    if (string.IsNullOrEmpty(sheet.Cells[i, 1].StringValue))
                    {
                        throw new Exception($"行号{i + 1}的”分值“不能为空");
                    }

                    decimal score = 0;
                    int     sort  = 0;
                    if (decimal.TryParse(sheet.Cells[i, 1].StringValue, out score))
                    {
                        Math.Round(score, 1);
                    }
                    else
                    {
                        throw new Exception($"行号{i + 1}的”分值“必须为小数");
                    }
                    if (score < 0)
                    {
                        throw new Exception($"行号{i + 1}的”分值“不能为负数");
                    }
                    if (!string.IsNullOrEmpty(sheet.Cells[i, 2].StringValue))
                    {
                        if (int.TryParse(sheet.Cells[i, 2].StringValue, out sort))
                        {
                        }
                    }

                    AccountRuleEntity import = new AccountRuleEntity()
                    {
                        Standard  = sheet.Cells[i, 0].StringValue,
                        Score     = score,
                        ScoreType = Enum.GetName(typeof(ScoreType), ScoreType.手动),
                        Sort      = sort,
                        Remark    = sheet.Cells[i, 3].StringValue,
                        IsOpen    = 1,
                    };
                    import.Create();
                    importList.Add(import);
                }
                if (importList.Count > 0)
                {
                    _bll.Insert(importList);
                }
                return(Json(new { success = true, message = "导入成功" }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }));
            }
        }