Beispiel #1
0
 public void Calculate()
 {
     if (DangerousList != null && RuleList != null && DangerousList.Count > 0)
     {
         List <int> dtgroup = DangerousList.GroupBy(e => e.TypeId).Select(e => e.Key).ToList();
         foreach (var dtkey in dtgroup)
         {
             var dangeroursList  = DangerousList.Where(e => e.TypeId == dtkey).ToList();
             var dangeroursName  = DangerousList.Where(e => e.TypeId == dtkey).FirstOrDefault().TypeName;
             var targetDangerous = new DangerousType()
             {
                 TypeName               = dangeroursName,
                 TypeId                 = dtkey,
                 Dangerous_level_Id     = -1,
                 Dangerous_level_string = "未定义",
             };
             foreach (var rule in RuleList.Where(e => e.DangerousTypeID == dtkey))
             {
                 var result = rule.Func(dangeroursList);
                 if (result)
                 {
                     targetDangerous.Dangerous_level_Id     = rule.result_level_Id;
                     targetDangerous.Dangerous_level_string = rule.result_string;
                     //   Console.WriteLine(String.Format("{0} 危险级别为 {1}", dangeroursName, rule.result_string));
                     break;
                 }
             }
             TargetDangerousList.Add(targetDangerous);
             Console.WriteLine(String.Format("{0} 危险级别为 {1}", dangeroursName, targetDangerous.Dangerous_level_string));
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 初始化得到混合各个危险各个级别的浓度值
 /// </summary>
 private void Init()
 {
     if (entityList != null && entityList.Count > 0)
     {
         DangerousList = new List <DangerousType>();
         foreach (var entity in entityList)
         {
             if (entity.DangerousList != null && entity.DangerousList.Count > 0)
             {
                 foreach (var dangerous in entity.DangerousList)
                 {
                     var dangerous1 = DangerousList.Where(e => e.TypeId == dangerous.TypeId && e.Dangerous_level_Id == dangerous.Dangerous_level_Id).FirstOrDefault();
                     //是否已经存在这个级别的危险类型 ,如果存在直接加上浓度的值
                     if (dangerous1 != null)
                     {
                         dangerous1.c_param += entity.c_param;
                     }
                     else
                     {
                         dangerous1 = new DangerousType()
                         {
                             TypeId             = dangerous.TypeId,
                             TypeName           = dangerous.TypeName,
                             Dangerous_level    = dangerous.Dangerous_level,
                             Dangerous_level_Id = dangerous.Dangerous_level_Id,
                             c_param            = entity.c_param,
                             // Rules = dangerous.Rules,
                         };
                         DangerousList.Add(dangerous1);
                     }
                 }
             }
         }
     }
 }