Exemple #1
0
        public JsonResult GetCategories(string categoryid)
        {
            var bll  = new DangerMeasureBLL();
            var data = bll.GetCategories(categoryid).OrderBy(x => x.Sort).ToList();

            return(Json(data.Where(x => x.ParentCategoryId == null).Select(x => new TreeModel {
                id = x.CategoryId.ToString(), value = x.CategoryId.ToString(), text = x.CategoryName, isexpand = data.Count(y => y.ParentCategoryId == x.CategoryId) > 0, hasChildren = data.Count(y => y.ParentCategoryId == x.CategoryId) > 0, ChildNodes = GetChildren(data, x.CategoryId)
            }).ToList(), JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        private List <DangerMeasureEntity> GetMeasureData(Worksheet sheet, int titleIndex)
        {
            var result     = new List <DangerMeasureEntity>();
            var bll        = new DangerMeasureBLL();
            var categories = bll.GetCategories(null);

            for (int i = titleIndex + 1; i <= sheet.Cells.MaxDataRow; i++)
            {
                var measure = new DangerMeasureEntity()
                {
                    MeasureId      = Guid.NewGuid().ToString(),
                    Category       = sheet.Cells[i, 0].StringValue,
                    DangerReason   = sheet.Cells[i, 1].StringValue,
                    MeasureContent = sheet.Cells[i, 2].StringValue
                };
                if (string.IsNullOrEmpty(measure.DangerReason))
                {
                    throw new Exception(string.Format("行 {0} 风险因素为空!", i + 1));
                }
                var category = categories.FirstOrDefault(x => x.CategoryName == measure.Category);
                if (category == null)
                {
                    throw new Exception(string.Format("行 {0} 风险类别不存在!", i + 1));
                }
                else
                {
                    measure.CategoryId = category.CategoryId;
                }

                if (bll.ExistDangerReason(measure.CategoryId, measure.DangerReason))
                {
                    throw new Exception(string.Format("行 {0} 风险因素已存在!", i + 1));
                }

                if (result.Count(x => x.CategoryId == measure.CategoryId && x.DangerReason == measure.DangerReason) > 0)
                {
                    throw new Exception(string.Format("行 {0} 风险因素重复!", i + 1));
                }
                result.Add(measure);
            }

            return(result);
        }