Ejemplo n.º 1
0
        public ActionResult Cadastrar(Perigo oPerigo)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Perigo obj = PerigoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.Descricao.Trim().ToUpper().Equals(oPerigo.Descricao.Trim().ToUpper()) && a.Template);
                    if (obj != null)
                    {
                        throw new Exception("Já existe um perigo com este nome cadastrado no sistema.");
                    }


                    oPerigo.UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                    oPerigo.Template        = true;
                    PerigoBusiness.Inserir(oPerigo);

                    Extensions.GravaCookie("MensagemSucesso", "O evento '" + oPerigo.Descricao + "' foi cadastrado com sucesso!", 10);

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Perigo")
                                      } }));
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException() == null)
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.Message
                                          } }));
                    }
                    else
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.GetBaseException().Message
                                          } }));
                    }
                }
            }
            else
            {
                return(Json(new { resultado = TratarRetornoValidacaoToJSON() }));
            }
        }
Ejemplo n.º 2
0
        public ActionResult ConfirmarPerigoForAutoComplete(string key)
        {
            try
            {
                Perigo item = PerigoBusiness.Consulta.FirstOrDefault(a => a.Descricao.ToUpper().Equals(key.ToUpper()) && a.Template);

                if (item == null)
                {
                    throw new Exception();
                }

                return(Json(new { Result = true }));
            }
            catch
            {
                return(Json(new { Result = false }));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Terminar(string id)
        {
            var ID = Guid.Parse(id);

            try
            {
                Perigo oPerigo = PerigoBusiness.Consulta.FirstOrDefault(p => p.ID.Equals(ID));
                if (oPerigo == null)
                {
                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Erro = "Não foi possível excluir o Evento Perigoso, pois o mesmo não foi localizado."
                                      } }));
                }
                else
                {
                    oPerigo.DataExclusao    = DateTime.Now;
                    oPerigo.UsuarioExclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                    PerigoBusiness.Alterar(oPerigo);

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Sucesso = "O  Perigo '" + oPerigo.Descricao + "' foi excluído com sucesso."
                                      } }));
                }
            }
            catch (Exception ex)
            {
                if (ex.GetBaseException() == null)
                {
                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Erro = ex.Message
                                      } }));
                }
                else
                {
                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Erro = ex.GetBaseException().Message
                                      } }));
                }
            }
        }
Ejemplo n.º 4
0
        public ActionResult Atualizar(Perigo oPerigo)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    PerigoBusiness.Alterar(oPerigo);

                    Extensions.GravaCookie("MensagemSucesso", "O Evento Perigoso '" + oPerigo.Descricao + "' foi atualizado com sucesso.", 10);


                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Perigo")
                                      } }));
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException() == null)
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.Message
                                          } }));
                    }
                    else
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.GetBaseException().Message
                                          } }));
                    }
                }
            }
            else
            {
                return(Json(new { resultado = TratarRetornoValidacaoToJSON() }));
            }
        }
Ejemplo n.º 5
0
        public ActionResult ListaPerigo()
        {
            //string sql = @"select p.UniqueKey as UK_P, p.Descricao, r.UniqueKey as UK_R, r.Nome, pr.UKPerigo, pr.UKRisco as relR
            //                from tbPerigo p
            //                left join REL_PerigoRisco pr on pr.UKPerigo = p.UniqueKey
            //                left join tbRisco r on r.UniqueKey = pr.UKRisco
            //                order by p.Descricao";

            string sql = @"select p.UniqueKey as UK_P, p.Descricao, r.UniqueKey as UK_R, r.Nome, pr.UKPerigo, pr.UKRisco as relR, d.UniqueKey as UK_Danos, d.DescricaoDanos, 
                            rd.UKRiscos as rel01, rd.UKDanosSaude as rel02 
                            from tbPerigo p
                            left join REL_PerigoRisco pr on pr.UKPerigo = p.UniqueKey
                            left join tbRisco r on r.UniqueKey = pr.UKRisco
                            left join REL_RiscoDanosASaude rd on rd.UKRiscos = r.UniqueKey and r.DataExclusao = CAST('9999-12-31 23:59:59.997'as datetime2)
                            left join tbPossiveisDanos d on d.UniqueKey = rd.UKDanosSaude and d.DataExclusao = CAST('9999-12-31 23:59:59.997'as datetime2)
                            order by p.Descricao";



            DataTable result = PerigoBusiness.GetDataTable(sql);

            List <Perigo> lista = new List <Perigo>();


            if (result.Rows.Count > 0)
            {
                Perigo obj    = null;
                Risco  oRisco = null;

                foreach (DataRow row in result.Rows)
                {
                    if (obj == null)
                    {
                        obj = new Perigo()
                        {
                            UniqueKey = Guid.Parse(row["UK_P"].ToString()),
                            Descricao = row["Descricao"].ToString(),
                            Riscos    = new List <Risco>()
                        };


                        if (!string.IsNullOrEmpty(row["relR"].ToString()))
                        {
                            oRisco = new Risco()
                            {
                                UniqueKey = Guid.Parse(row["relR"].ToString()),
                                Nome      = row["Nome"].ToString(),
                                Danos     = new List <PossiveisDanos>()
                            };
                        }

                        if (!string.IsNullOrEmpty(row["rel02"].ToString()))
                        {
                            oRisco.Danos.Add(new PossiveisDanos()
                            {
                                UniqueKey      = Guid.Parse(row["rel02"].ToString()),
                                DescricaoDanos = row["DescricaoDanos"].ToString(),
                            });
                        }

                        obj.Riscos.Add(oRisco);
                    }


                    else if (obj.UniqueKey.Equals(Guid.Parse(row["UK_P"].ToString())))
                    {
                        if (!string.IsNullOrEmpty(row["relR"].ToString()))
                        {
                            if (oRisco == null)
                            {
                                oRisco = new Risco()
                                {
                                    UniqueKey = Guid.Parse(row["relR"].ToString()),
                                    Nome      = row["Nome"].ToString(),
                                    Danos     = new List <PossiveisDanos>()
                                };

                                if (!string.IsNullOrEmpty(row["rel02"].ToString()))
                                {
                                    oRisco.Danos.Add(new PossiveisDanos()
                                    {
                                        UniqueKey      = Guid.Parse(row["rel02"].ToString()),
                                        DescricaoDanos = row["DescricaoDanos"].ToString(),
                                    });
                                }

                                obj.Riscos.Add(oRisco);
                            }
                            else if (oRisco.Nome.Equals(row["Nome"].ToString()))
                            {
                                if (!string.IsNullOrEmpty(row["relR"].ToString()))
                                {
                                    oRisco.Danos.Add(new PossiveisDanos()
                                    {
                                        UniqueKey      = Guid.Parse(row["relR"].ToString()),
                                        DescricaoDanos = row["DescricaoDanos"].ToString()
                                    });
                                }
                            }
                            else
                            {
                                oRisco = new Risco()
                                {
                                    UniqueKey = Guid.Parse(row["relR"].ToString()),
                                    Nome      = row["Nome"].ToString(),
                                    Danos     = new List <PossiveisDanos>()
                                };

                                if (!string.IsNullOrEmpty(row["rel01"].ToString()))
                                {
                                    oRisco.Danos.Add(new PossiveisDanos()
                                    {
                                        UniqueKey      = Guid.Parse(row["rel02"].ToString()),
                                        DescricaoDanos = row["DescricaoDanos"].ToString()
                                    });
                                }

                                obj.Riscos.Add(oRisco);
                            }
                        }
                    }
                    else
                    {
                        lista.Add(obj);

                        obj = new Perigo()
                        {
                            UniqueKey = Guid.Parse(row["UK_P"].ToString()),
                            Descricao = row["Descricao"].ToString(),
                            Riscos    = new List <Risco>()
                        };


                        if (!string.IsNullOrEmpty(row["relR"].ToString()))
                        {
                            oRisco = new Risco()
                            {
                                UniqueKey = Guid.Parse(row["relR"].ToString()),
                                Nome      = row["Nome"].ToString(),
                                Danos     = new List <PossiveisDanos>()
                            };


                            if (!string.IsNullOrEmpty(row["rel02"].ToString()))
                            {
                                oRisco.Danos.Add(new PossiveisDanos()
                                {
                                    UniqueKey      = Guid.Parse(row["rel02"].ToString()),
                                    DescricaoDanos = row["DescricaoDanos"].ToString(),
                                });
                            }

                            obj.Riscos.Add(oRisco);
                        }
                    }
                }

                if (obj != null)
                {
                    lista.Add(obj);
                }
            }

            return(View("_ListaPerigo", lista));
        }
Ejemplo n.º 6
0
        public ActionResult ListaPerigoPorAtividade()
        {
            string sql = @"select a.UniqueKey as UK_Atividade, a.Descricao as nome,
					 p.UniqueKey as UK_Perigo, p.Descricao as NomePerigo, 
					 ap.UniqueKey as relap, ap.UKAtividade as rel01, ap.UKPerigo as rel02
                    from tbAtividade  a
					left join REL_AtividadePerigo ap on a.UniqueKey = ap.UKAtividade and a.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
					left join tbPerigo p on p.UniqueKey = ap.UKPerigo and a.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
					order by a.Descricao"                    ;


            DataTable result = AtividadeBusiness.GetDataTable(sql);

            List <Atividade> lista = new List <Atividade>();

            if (result.Rows.Count > 0)
            {
                Atividade obj     = null;
                Perigo    oPerigo = null;

                foreach (DataRow row in result.Rows)
                {
                    if (obj == null)
                    {
                        obj = new Atividade()
                        {
                            UniqueKey = Guid.Parse(row["UK_Atividade"].ToString()),
                            Descricao = row["nome"].ToString(),
                            Perigos   = new List <Perigo>()
                        };

                        if (!string.IsNullOrEmpty(row["relap"].ToString()))
                        {
                            oPerigo = new Perigo()
                            {
                                UniqueKey = Guid.Parse(row["rel02"].ToString()),
                                Descricao = row["NomePerigo"].ToString(),
                            };


                            obj.Perigos.Add(oPerigo);
                        }
                    }
                    //
                    else if (obj.UniqueKey.Equals(Guid.Parse(row["UK_Atividade"].ToString())))
                    {
                        if (!string.IsNullOrEmpty(row["relap"].ToString()))
                        {
                            if (oPerigo == null)
                            {
                                oPerigo = new Perigo()
                                {
                                    UniqueKey = Guid.Parse(row["UK_Perigo"].ToString()),
                                    Descricao = row["NomePerigo"].ToString(),
                                };

                                obj.Perigos.Add(oPerigo);
                            }



                            else if (oPerigo.UniqueKey.ToString().Equals(row["UK_Perigo"].ToString()))

                            {
                                Perigo pTemp = obj.Perigos.FirstOrDefault(a => a.Descricao.Equals(row["Descricao"].ToString()));

                                if (pTemp == null)
                                {
                                    oPerigo = new Perigo()
                                    {
                                        UniqueKey = Guid.Parse(row["UK_Perigo"].ToString()),
                                        Descricao = row["NomePerigo"].ToString(),
                                    };


                                    obj.Perigos.Add(oPerigo);
                                }
                            }
                            else
                            {
                                oPerigo = new Perigo()
                                {
                                    UniqueKey = Guid.Parse(row["UK_Perigo"].ToString()),
                                    Descricao = row["NomePerigo"].ToString(),
                                };

                                if (!string.IsNullOrEmpty(row["relap"].ToString()))
                                {
                                    oPerigo = new Perigo()
                                    {
                                        UniqueKey = Guid.Parse(row["UK_Perigo"].ToString()),
                                        Descricao = row["NomePerigo"].ToString(),
                                    };
                                }

                                obj.Perigos.Add(oPerigo);
                            }
                        }
                    }

                    else
                    {
                        lista.Add(obj);

                        obj = new Atividade()
                        {
                            UniqueKey = Guid.Parse(row["UK_Atividade"].ToString()),
                            Descricao = row["nome"].ToString(),
                            Perigos   = new List <Perigo>()
                        };

                        if (!string.IsNullOrEmpty(row["relap"].ToString()))
                        {
                            oPerigo = new Perigo()
                            {
                                UniqueKey = Guid.Parse(row["rel02"].ToString()),
                                Descricao = row["NomePerigo"].ToString(),
                            };

                            obj.Perigos.Add(oPerigo);
                        }
                    }
                }

                if (obj != null)
                {
                    lista.Add(obj);
                }
            }

            return(View("_ListaPerigoPorAtividade", lista));
        }
Ejemplo n.º 7
0
        public ActionResult VincularPerigo(string UKAtividade, string UKPerigo)
        {
            try
            {
                //Guid UK_Perigo = Guid.Parse(UKPerigo);
                Guid UK_Atividade = Guid.Parse(UKAtividade);
                if (string.IsNullOrEmpty(UKAtividade))
                {
                    throw new Exception("Não foi possível localizar a Atividade.");
                }

                if (string.IsNullOrEmpty(UKPerigo))
                {
                    throw new Exception("Nenhum Perigo para vincular.");
                }


                if (UKPerigo.Contains(","))
                {
                    foreach (string ativ in UKPerigo.Split(','))
                    {
                        if (!string.IsNullOrEmpty(ativ.Trim()))
                        {
                            Perigo pTemp = PerigoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.Descricao.Equals(ativ.Trim()));
                            if (pTemp != null)
                            {
                                if (AtividadePerigoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKPerigo.Equals(pTemp.UniqueKey) && a.UKAtividade.Equals(UK_Atividade)).Count() == 0)
                                {
                                    AtividadePerigoBusiness.Inserir(new REL_AtividadePerigo()
                                    {
                                        UKAtividade     = UK_Atividade,
                                        UKPerigo        = pTemp.UniqueKey,
                                        UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                                    });
                                }
                            }
                        }
                    }
                }
                else
                {
                    Perigo pTemp = PerigoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.Descricao.Equals(UKPerigo));

                    if (pTemp != null)
                    {
                        if (AtividadePerigoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKPerigo.Equals(pTemp.UniqueKey) && a.UKAtividade.Equals(UK_Atividade)).Count() == 0)
                        {
                            AtividadePerigoBusiness.Inserir(new REL_AtividadePerigo()
                            {
                                UKAtividade     = UK_Atividade,
                                UKPerigo        = pTemp.UniqueKey,
                                UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                            });
                        }
                    }
                }

                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      Sucesso = "Perigo vinculado a Atividade com sucesso."
                                  } }));
            }
            catch (Exception ex)
            {
                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      Erro = ex.Message
                                  } }));
            }
        }
Ejemplo n.º 8
0
        // GET: ASO



        public ActionResult ListaASOEmpregado(string ukEmpregado)
        {
            Guid emp = Guid.Parse(ukEmpregado);

            var ListaASO = (from al in AlocacaoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            join ad in AdmissaoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao) && p.UKEmpregado.Equals(emp)).ToList()
                            on al.UKAdmissao equals ad.UniqueKey
                            join e in EmpregadoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao) && p.UniqueKey.Equals(emp)).ToList()
                            on ad.UKEmpregado equals e.UniqueKey
                            join f in FuncaoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on al.UKFuncao equals f.UniqueKey
                            join est in EstabelecimentoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on al.UKEstabelecimento equals est.UniqueKey
                            join wa in WorkAreaBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on al.UKEstabelecimento equals wa.UKEstabelecimento
                            join fon in FonteGeradoraDeRiscoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on wa.UniqueKey equals fon.UKWorkArea
                            join fp in REL_FontePerigoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on fon.UniqueKey equals fp.UKFonteGeradora
                            join re in REL_RiscosExamesBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on fp.UKPerigo equals re.ukPerigo
                            join pr in REL_PerigoRiscoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on fp.UKPerigo equals pr.UKPerigo
                            join r in RiscoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on pr.UKRisco equals r.UniqueKey
                            join p in PerigoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                            on fp.UKPerigo equals p.UniqueKey

                            //where r.UniqueKey.Equals(emp) && ad.UKEmpregado.Equals(emp)
                            select new VMLaso()
            {
                ukPerigo = fp.UKPerigo,
                Estabelecimento = est.NomeCompleto,
                NomeEmpregado = e.Nome,
                CPF = e.CPF,
                Funcao = f.NomeDaFuncao,
                Perigo = p.Descricao,
            }).ToList();

            List <VMLaso> asolist = ListaASO;



            List <VMLExamesRiscos> ListaE = new List <VMLExamesRiscos>();
            VMLExamesRiscos        obj    = null;
            Exames oEx = null;
            Perigo Per = null;

            if (obj == null)
            {
                List <VMLExamesRiscos> ListaExame = new List <VMLExamesRiscos>();


                foreach (var item3 in asolist)
                {
                    if (item3 != null)
                    {
                        var oListaExame = (from r in REL_RiscosExamesBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao) && p.ukPerigo.Equals(item3.ukPerigo)).ToList()
                                           join e in ExamesBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                                           on r.ukExame equals e.UniqueKey
                                           join p in PerigoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList()
                                           on r.ukPerigo equals p.UniqueKey
                                           select new VMLExamesRiscos()
                        {
                            Perigo = p.Descricao,
                            TipoExame = r.TipoExame,
                            Exame = e.Nome,
                            Obrigatoriedade = r.Obrigariedade,
                        }).ToList();


                        ListaExame = oListaExame.ToList();
                    }
                }

                foreach (var item2 in ListaExame)
                {
                    if (obj == null)
                    {
                        obj = new VMLExamesRiscos()
                        {
                            Perigo          = item2.Perigo,
                            Exame           = item2.Exame,
                            Obrigatoriedade = item2.Obrigatoriedade,
                            TipoExame       = item2.TipoExame,

                            ListaExames = new List <Exames>()
                        };

                        oEx = new Exames()
                        {
                            Nome = item2.Exame,
                        };

                        obj.ListaExames.Add(oEx);
                        ListaE.Add(obj);
                    }

                    else
                    {
                        if (obj.Perigo.Equals(item2.Perigo))
                        {
                            oEx = new Exames()
                            {
                                Nome = item2.Exame,
                            };

                            obj.ListaExames.Add(oEx);
                            ListaE.Add(obj);
                        }
                    }
                }

                ViewBag.ListaExame = ListaE.ToList().OrderBy(p => p.TipoExame);
            }


            ViewBag.listaASO = ListaASO.ToList();

            return(View());
        }
Ejemplo n.º 9
0
        public ActionResult CriarControle(string UKWorkarea, string UKRisco)
        {
            ViewBag.UKWorkArea = UKWorkarea;
            ViewBag.UKRisco    = UKRisco;

            var UKRisc = Guid.Parse(UKRisco);
            var UKWork = Guid.Parse(UKWorkarea);


            var Nome = RiscoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao) && (p.UniqueKey.Equals(UKRisc))).ToList();

            var WArea = WorkAreaBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao) && (p.UniqueKey.Equals(UKWork))).ToList();

            var enumData = from EClasseDoRisco e in Enum.GetValues(typeof(EClasseDoRisco))
                           select new
            {
                ID   = (int)e,
                Name = e.ToString()
            };

            ViewBag.Eclasse = new SelectList(enumData, "ID", "Name");


            var enumData01 = from ETrajetoria e in Enum.GetValues(typeof(ETrajetoria))
                             select new
            {
                ID   = (int)e,
                Name = e.ToString()
            };

            ViewBag.ETrajetoria = new SelectList(enumData01, "ID", "Name");


            var enumData02 = from EClassificacaoDaMedia e in Enum.GetValues(typeof(EClassificacaoDaMedia))
                             select new
            {
                ID   = (int)e,
                Name = e.ToString()
            };

            ViewBag.EClassificacaoDaMedia = new SelectList(enumData02, "ID", "Name");

            var enumData03 = from EControle e in Enum.GetValues(typeof(EControle))
                             select new
            {
                ID   = (int)e,
                Name = e.ToString()
            };

            ViewBag.EControle = new SelectList(enumData03, "ID", "Name");



            ViewBag.FonteGeradora = new SelectList(FonteGeradoraDeRiscoBusiness.Consulta.Where(p => string.IsNullOrEmpty(p.UsuarioExclusao)).ToList(), "ID", "FonteGeradora");

            List <WorkArea> lista = new List <WorkArea>();

            string sql = @"select wa.UniqueKey, wa.Nome, wa.Descricao, 
	                                  r1.Uniquekey as relwap, p.UniqueKey as ukperigo, p.Descricao as perigo, 
	                                  r2.UniqueKey as relpr, r.UniqueKey as ukrisco, r.Nome as risco 
                               from tbWorkArea wa 
	                                left join [dbGestor].[dbo].[REL_WorkAreaPerigo]  r1 on r1.UKWorkArea = wa.UniqueKey  and r1.DataExclusao = CAST('9999-12-31 23:59:59.997' as datetime2)  
	                                left join  [dbGestor].[dbo].[tbPerigo] p on r1.UKPerigo = p.UniqueKey and p.DataExclusao = CAST('9999-12-31 23:59:59.997' as datetime2) 
	                                left join [dbGestor].[dbo].[REL_PerigoRisco] r2 on r2.UKPerigo = p.UniqueKey and r2.DataExclusao =CAST('9999-12-31 23:59:59.997' as datetime2)  
	                                left join [dbGestor].[dbo].[tbRisco] r on r2.UKRisco = r.UniqueKey  and r.DataExclusao = CAST('9999-12-31 23:59:59.997' as datetime2) 
                               where wa.DataExclusao =CAST('9999-12-31 23:59:59.997' as datetime2)   and wa.UniqueKey = '" + UKWorkarea + @"'
                               and r.UniqueKey = '" + UKRisco + @"'
                               order by wa.UniqueKey ";

            DataTable result = WorkAreaBusiness.GetDataTable(sql);

            if (result.Rows.Count > 0)
            {
                WorkArea obj     = null;
                Perigo   oPerigo = null;

                foreach (DataRow row in result.Rows)
                {
                    if (obj == null)
                    {
                        //obj = new WorkArea()
                        //{
                        //    UniqueKey = Guid.Parse(row["UniqueKey"].ToString()),
                        //    Nome = row["Nome"].ToString(),
                        //    Descricao = row["Descricao"].ToString(),
                        //    Perigos = new List<Perigo>()
                        //};


                        //if (!string.IsNullOrEmpty(row["relwap"].ToString()))
                        //{
                        //    oPerigo = new Perigo()
                        //    {
                        //        ID = Guid.Parse(row["relwap"].ToString()),
                        //        UniqueKey = Guid.Parse(row["ukperigo"].ToString()),
                        //        Descricao = row["perigo"].ToString(),
                        //        Riscos = new List<Risco>()
                        //    };

                        //    if (!string.IsNullOrEmpty(row["relpr"].ToString()))
                        //    {
                        //        oPerigo.Riscos.Add(new Risco()
                        //        {
                        //            ID = Guid.Parse(row["relpr"].ToString()),
                        //            UniqueKey = Guid.Parse(row["ukrisco"].ToString()),
                        //            Nome = row["risco"].ToString()
                        //        });
                        //    }

                        //    obj.Perigos.Add(oPerigo);
                        //}
                    }
                }
                if (obj != null)
                {
                    lista.Add(obj);
                }
            }



            return(PartialView("_CadastrarControleDeRisco", lista));
        }
Ejemplo n.º 10
0
        public ActionResult VincularPerigoAFonte(string UKPerigo, string UKFonte)
        {
            try
            {
                if (string.IsNullOrEmpty(UKPerigo))
                {
                    throw new Exception("Não foi possível localizar a identificação do perigo.");
                }

                if (string.IsNullOrEmpty(UKFonte))
                {
                    throw new Exception("Nenhuma fonte recebida como parâmetro para vincular ao perigo.");
                }

                Guid guidFonte = Guid.Parse(UKFonte);


                if (UKPerigo.Contains(","))
                {
                    foreach (string risk in UKPerigo.Split(','))
                    {
                        if (!string.IsNullOrEmpty(risk.Trim()))
                        {
                            Perigo rTemp = PerigoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.Descricao.Equals(risk.Trim()));
                            if (rTemp != null)
                            {
                                if (REL_FontePerigoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKFonteGeradora.Equals(guidFonte) && a.UKPerigo.Equals(rTemp.UniqueKey)).Count() == 0)
                                {
                                    //Perigo p = new Perigo()
                                    //{
                                    //    UniqueKey = rTemp.UniqueKey
                                    //    Descricao = rTemp.Descricao,
                                    //    UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                                    //};
                                    //PerigoBusiness.Inserir(p);

                                    REL_FontePerigo FontePerigo = new REL_FontePerigo()
                                    {
                                        UKFonteGeradora = guidFonte,
                                        UKPerigo        = rTemp.UniqueKey,
                                        UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                                    };

                                    REL_FontePerigoBusiness.Inserir(FontePerigo);
                                }
                                else
                                {
                                    throw new Exception("O perigo '" + rTemp.Descricao + "' já está vinculado a esta fonte geradora.");
                                }
                            }
                            else
                            {
                                throw new Exception("Não foi possível encontrar o perigo a ser vinculado a fonte geradora na base de dados.");
                            }
                        }
                    }
                }
                else
                {
                    Perigo rTemp = PerigoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.Descricao.Equals(UKPerigo));
                    if (rTemp != null)
                    {
                        if (REL_FontePerigoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKFonteGeradora.Equals(guidFonte) && a.UKPerigo.Equals(rTemp.UniqueKey)).Count() == 0)
                        {
                            //Perigo p = new Perigo()
                            //{

                            //    Descricao = rTemp.Descricao,
                            //    UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                            //};
                            //PerigoBusiness.Inserir(p);

                            REL_FontePerigo FontePerigo = new REL_FontePerigo()
                            {
                                UKFonteGeradora = guidFonte,
                                UKPerigo        = rTemp.UniqueKey,
                                UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                            };

                            REL_FontePerigoBusiness.Inserir(FontePerigo);
                        }
                        else
                        {
                            throw new Exception("O perigo '" + rTemp.Descricao + "' já está vinculado a esta fonte geradora.");
                        }
                    }
                    else
                    {
                        throw new Exception("Não foi possível encontrar o perigo a ser vinculado a fonte geradora na base de dados.");
                    }
                }

                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      Sucesso = "Perigo relacionado a Fonte Geradora de Risco com sucesso."
                                  } }));
            }
            catch (Exception ex)
            {
                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      Erro = ex.Message
                                  } }));
            }
        }
Ejemplo n.º 11
0
        public ActionResult PesquisarWorkArea(FonteGeradoraViewModel entidade)
        {
            try
            {
                List <WorkArea> lista = new List <WorkArea>();

                Guid   guid = Guid.Empty;
                string sql  = @"select wa.UniqueKey as UniqWa, wa.UKEstabelecimento, wa.Nome, wa.Descricao,f.UniqueKey as UniqFon, f.FonteGeradora, 
	                                  r1.Uniquekey as relfp,
									  p.UniqueKey as ukperigo, p.Descricao as perigo, 
	                                  r2.UniqueKey as relpr,r.UniqueKey as ukrisco, r.Nome as risco, 
                                re.UniqueKey as UKReconhecimento, re.UKRisco as rUKrisco, re.UKWorkarea as rWorkarea , re.UKFonteGeradora as rUKFonte
                               from tbWorkArea wa                                                               
									left join tbFonteGeradoraDeRisco f on f.UKWorkarea = wa.UniqueKey and f.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101) 
									left join REL_FontePerigo r1 on r1.UKFonteGeradora = f.UniqueKey and r1.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)  
									left join tbPerigo p on r1.UKPerigo = p.UniqueKey and p.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)  
									left join REL_PerigoRisco r2 on r2.UKPerigo = p.UniqueKey and r2.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)     
	                                left join tbRisco r on r2.UKRisco = r.UniqueKey  and r.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)  
                                    left join tbReconhecimentoDoRisco re on r.UniqueKey = re.UKRisco and f.Uniquekey = re.UKFonteGeradora  and re.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)  
                               where wa.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)  
							   and wa.UKEstabelecimento = '"                             + entidade.UKEstabelecimento + @"'
                               order by wa.UniqueKey";

                DataTable result = WorkAreaBusiness.GetDataTable(sql);
                if (result.Rows.Count > 0)
                {
                    WorkArea             obj    = null;
                    FonteGeradoraDeRisco oFonte = null;
                    Perigo oPerigo = null;

                    foreach (DataRow row in result.Rows)
                    {
                        if (obj == null)
                        {
                            obj = new WorkArea()
                            {
                                UniqueKey         = Guid.Parse(row["UniqWa"].ToString()),
                                UKEstabelecimento = Guid.Parse(row["UKEstabelecimento"].ToString()),
                                Nome                 = row["Nome"].ToString(),
                                Descricao            = row["Descricao"].ToString(),
                                FonteGeradoraDeRisco = new List <FonteGeradoraDeRisco>()
                            };


                            if (!string.IsNullOrEmpty(row["UniqFon"].ToString()))
                            {
                                oFonte = new FonteGeradoraDeRisco()
                                {
                                    UniqueKey     = Guid.Parse(row["UniqFon"].ToString()),
                                    FonteGeradora = row["FonteGeradora"].ToString(),
                                    Descricao     = row["Descricao"].ToString(),
                                    Perigos       = new List <Perigo>()
                                };

                                if (!string.IsNullOrEmpty(row["relfp"].ToString()))
                                {
                                    oPerigo = new Perigo()
                                    {
                                        ID        = Guid.Parse(row["relfp"].ToString()),
                                        UniqueKey = Guid.Parse(row["UKPerigo"].ToString()),
                                        Descricao = row["perigo"].ToString(),
                                        Riscos    = new List <Risco>()
                                    };

                                    if (!string.IsNullOrEmpty(row["relpr"].ToString()))
                                    {
                                        Risco oRisco = new Risco()
                                        {
                                            ID        = Guid.Parse(row["relpr"].ToString()),
                                            UniqueKey = Guid.Parse(row["ukrisco"].ToString()),
                                            Nome      = row["risco"].ToString()
                                        };

                                        if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                        {
                                            oRisco.Reconhecimento = new ReconhecimentoDoRisco()
                                            {
                                                UniqueKey = Guid.Parse(row["UKReconhecimento"].ToString()) != null?Guid.Parse(row["UKReconhecimento"].ToString()) : guid,
                                                                UKWorkarea      = Guid.Parse(row["rWorkarea"].ToString()),
                                                                UKRisco         = Guid.Parse(row["rUKRisco"].ToString()),
                                                                UKFonteGeradora = Guid.Parse(row["rUKFonte"].ToString()),
                                            };
                                        }

                                        oPerigo.Riscos.Add(oRisco);
                                    }

                                    oFonte.Perigos.Add(oPerigo);
                                }


                                obj.FonteGeradoraDeRisco.Add(oFonte);
                            }
                        }
                        else
                        if (obj.UniqueKey.Equals(Guid.Parse(row["UniqWa"].ToString())))
                        {
                            if (!string.IsNullOrEmpty(row["UniqFon"].ToString()))
                            {
                                if (oFonte == null)
                                {
                                    oFonte = new FonteGeradoraDeRisco()
                                    {
                                        UniqueKey     = Guid.Parse(row["UniqFon"].ToString()),
                                        FonteGeradora = row["FonteGeradora"].ToString(),
                                        Descricao     = row["Descricao"].ToString(),
                                        Perigos       = new List <Perigo>()
                                    };
                                    if (!string.IsNullOrEmpty(row["relfp"].ToString()))
                                    {
                                        if (oFonte.Perigos.Equals(row["relfp"].ToString()))
                                        {
                                            oPerigo = new Perigo()
                                            {
                                                ID        = Guid.Parse(row["relfp"].ToString()),
                                                UniqueKey = Guid.Parse(row["UKPerigo"].ToString()),
                                                Descricao = row["perigo"].ToString(),
                                                Riscos    = new List <Risco>()
                                            };

                                            if (!string.IsNullOrEmpty(row["relpr"].ToString()))
                                            {
                                                Risco oRisco = new Risco()
                                                {
                                                    ID        = Guid.Parse(row["relpr"].ToString()),
                                                    UniqueKey = Guid.Parse(row["ukrisco"].ToString()),
                                                    Nome      = row["risco"].ToString()
                                                };

                                                if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                                {
                                                    oRisco.Reconhecimento = new ReconhecimentoDoRisco()
                                                    {
                                                        UniqueKey = Guid.Parse(row["UKReconhecimento"].ToString()) != null?Guid.Parse(row["UKReconhecimento"].ToString()) : guid,
                                                                        UKWorkarea      = Guid.Parse(row["rWorkarea"].ToString()),
                                                                        UKRisco         = Guid.Parse(row["rUKRisco"].ToString()),
                                                                        UKFonteGeradora = Guid.Parse(row["rUKFonte"].ToString()),
                                                    };
                                                }

                                                oPerigo.Riscos.Add(oRisco);
                                            }

                                            oFonte.Perigos.Add(oPerigo);
                                        }
                                    }

                                    obj.FonteGeradoraDeRisco.Add(oFonte);
                                }
                                else if (oFonte.UniqueKey.ToString().Equals(row["UniqFon"].ToString()))
                                {
                                    Perigo pTemp = oFonte.Perigos.FirstOrDefault(a => a.Descricao.Equals(row["perigo"].ToString()));
                                    if (pTemp == null)
                                    {
                                        oPerigo = new Perigo()
                                        {
                                            ID        = Guid.Parse(row["relfp"].ToString()),
                                            UniqueKey = Guid.Parse(row["ukperigo"].ToString()),
                                            Descricao = row["perigo"].ToString(),
                                            Riscos    = new List <Risco>()
                                        };

                                        if (!string.IsNullOrEmpty(row["relpr"].ToString()))
                                        {
                                            Risco oRisco = new Risco()
                                            {
                                                ID        = Guid.Parse(row["relpr"].ToString()),
                                                UniqueKey = Guid.Parse(row["ukrisco"].ToString()),
                                                Nome      = row["risco"].ToString()
                                            };

                                            if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                            {
                                                oRisco.Reconhecimento = new ReconhecimentoDoRisco()
                                                {
                                                    UniqueKey = Guid.Parse(row["UKReconhecimento"].ToString()) != null?Guid.Parse(row["UKReconhecimento"].ToString()) : guid,
                                                                    UKWorkarea      = Guid.Parse(row["rWorkarea"].ToString()),
                                                                    UKRisco         = Guid.Parse(row["rUKRisco"].ToString()),
                                                                    UKFonteGeradora = Guid.Parse(row["rUKFonte"].ToString()),
                                                };
                                            }

                                            oPerigo.Riscos.Add(oRisco);
                                        }

                                        oFonte.Perigos.Add(oPerigo);
                                    }
                                    else
                                    {
                                        Risco riskTemp = pTemp.Riscos.FirstOrDefault(a => a.Nome.Equals(row["risco"].ToString()));
                                        if (riskTemp == null)
                                        {
                                            Risco oRisco = new Risco()
                                            {
                                                ID        = Guid.Parse(row["relpr"].ToString()),
                                                UniqueKey = Guid.Parse(row["ukrisco"].ToString()),
                                                Nome      = row["risco"].ToString()
                                            };

                                            if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                            {
                                                oRisco.Reconhecimento = new ReconhecimentoDoRisco()
                                                {
                                                    UniqueKey = Guid.Parse(row["UKReconhecimento"].ToString())
                                                };
                                            }

                                            pTemp.Riscos.Add(oRisco);
                                        }
                                    }
                                }
                                else
                                {
                                    oFonte = new FonteGeradoraDeRisco()
                                    {
                                        UniqueKey     = Guid.Parse(row["UniqFon"].ToString()),
                                        FonteGeradora = row["FonteGeradora"].ToString(),
                                        Descricao     = row["Descricao"].ToString(),
                                        Perigos       = new List <Perigo>()
                                    };

                                    if (!string.IsNullOrEmpty(row["relfp"].ToString()))
                                    {
                                        oPerigo = new Perigo()
                                        {
                                            ID        = Guid.Parse(row["relfp"].ToString()),
                                            UniqueKey = Guid.Parse(row["ukperigo"].ToString()),
                                            Descricao = row["perigo"].ToString(),
                                            Riscos    = new List <Risco>()
                                        };

                                        if (!string.IsNullOrEmpty(row["relpr"].ToString()))
                                        {
                                            Risco oRisco = new Risco()
                                            {
                                                ID        = Guid.Parse(row["relpr"].ToString()),
                                                UniqueKey = Guid.Parse(row["ukrisco"].ToString()),
                                                Nome      = row["risco"].ToString()
                                            };

                                            if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                            {
                                                oRisco.Reconhecimento = new ReconhecimentoDoRisco()
                                                {
                                                    UniqueKey = Guid.Parse(row["UKReconhecimento"].ToString()) != null?Guid.Parse(row["UKReconhecimento"].ToString()) : guid,
                                                                    UKWorkarea      = Guid.Parse(row["rWorkarea"].ToString()),
                                                                    UKRisco         = Guid.Parse(row["rUKRisco"].ToString()),
                                                                    UKFonteGeradora = Guid.Parse(row["rUKFonte"].ToString()),
                                                };
                                            }

                                            oPerigo.Riscos.Add(oRisco);
                                        }

                                        oFonte.Perigos.Add(oPerigo);
                                    }

                                    obj.FonteGeradoraDeRisco.Add(oFonte);
                                }
                            }
                        }
                        else
                        {
                            lista.Add(obj);

                            obj = new WorkArea()
                            {
                                UniqueKey         = Guid.Parse(row["UniqWa"].ToString()),
                                UKEstabelecimento = Guid.Parse(row["UKEstabelecimento"].ToString()),
                                Nome                 = row["Nome"].ToString(),
                                Descricao            = row["Descricao"].ToString(),
                                FonteGeradoraDeRisco = new List <FonteGeradoraDeRisco>()
                            };

                            if (!string.IsNullOrEmpty(row["UniqFon"].ToString()))
                            {
                                oFonte = new FonteGeradoraDeRisco()
                                {
                                    UniqueKey     = Guid.Parse(row["UniqFon"].ToString()),
                                    FonteGeradora = row["FonteGeradora"].ToString(),
                                    Descricao     = row["Descricao"].ToString(),
                                    Perigos       = new List <Perigo>()
                                };

                                if (!string.IsNullOrEmpty(row["relfp"].ToString()))
                                {
                                    oPerigo = new Perigo()
                                    {
                                        ID        = Guid.Parse(row["relfp"].ToString()),
                                        UniqueKey = Guid.Parse(row["ukperigo"].ToString()),
                                        Descricao = row["perigo"].ToString(),
                                        Riscos    = new List <Risco>()
                                    };

                                    if (!string.IsNullOrEmpty(row["relpr"].ToString()))
                                    {
                                        Risco oRisco = new Risco()
                                        {
                                            ID        = Guid.Parse(row["relpr"].ToString()),
                                            UniqueKey = Guid.Parse(row["ukrisco"].ToString()),
                                            Nome      = row["risco"].ToString()
                                        };

                                        if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                        {
                                            oRisco.Reconhecimento = new ReconhecimentoDoRisco()
                                            {
                                                UniqueKey = Guid.Parse(row["UKReconhecimento"].ToString()) != null?Guid.Parse(row["UKReconhecimento"].ToString()) : guid,
                                                                UKWorkarea      = Guid.Parse(row["rWorkarea"].ToString()),
                                                                UKRisco         = Guid.Parse(row["rUKRisco"].ToString()),
                                                                UKFonteGeradora = Guid.Parse(row["rUKFonte"].ToString()),
                                            };
                                        }

                                        oPerigo.Riscos.Add(oRisco);
                                    }

                                    oFonte.Perigos.Add(oPerigo);
                                }

                                obj.FonteGeradoraDeRisco.Add(oFonte);
                            }
                        }
                    }

                    if (obj != null)
                    {
                        lista.Add(obj);
                    }
                }

                return(PartialView("_Pesquisa", lista));
            }
            catch (Exception ex)
            {
                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      Erro = ex.Message
                                  } }));
            }
        }
Ejemplo n.º 12
0
        public ActionResult PesquisaAtividade(string UniqueKey)
        {
            string query01 = @"select  a.Uniquekey as ukAtiv, a.Descricao as NomeAtividade, p.Uniquekey as ukPer, p.Descricao as DescPerigo, r.UniqueKey as ukrisc,
                r.Nome as NomeRisco,  pd.Uniquekey as UKdanos, pd.DescricaoDanos,re.UniqueKey as UKReconhecimento, re.UKRisco as rUKrisco                
                from tbAtividade a
				left join REL_AtividadePerigo rel02
                on a.Uniquekey = rel02.UKAtividade and a.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
                left join tbPerigo p
                on rel02.UKPerigo = p.Uniquekey and p.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
                left join REL_PerigoRisco rel03
                on p.Uniquekey = rel03.UKPerigo and p.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
                left join tbRisco r
                on rel03.UKRisco = r.Uniquekey and p.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
                left join REL_RiscoDanosASaude rel04
                on rel03.UKRisco = rel04.UKRiscos 
                left join tbPossiveisDanos pd
                on rel04.UKDanosSaude = pd.Uniquekey and pd.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
                left join tbReconhecimentoDoRisco re 
                on r.UniqueKey = re.UKRisco and re.UKAtividade = '" + UniqueKey + @"' and re.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
                where a.Uniquekey =   '" + UniqueKey + @"'
                order by p.Uniquekey";


            VMAtividadesRiscos obj1              = null;
            Atividade          atividade         = null;
            Perigo             perigo            = null;
            Risco                     risc       = null;
            PossiveisDanos            danos      = null;
            List <VMAtividadesRiscos> ListRiscos = new List <VMAtividadesRiscos>();

            DataTable result01 = AlocacaoBusiness.GetDataTable(query01);

            if (result01.Rows.Count > 0)
            {
                foreach (DataRow row in result01.Rows)
                {
                    if (obj1 == null)
                    {
                        obj1 = new VMAtividadesRiscos()
                        {
                            UKAtividade   = row["ukAtiv"].ToString(),
                            UKPerigo      = row["ukPer"].ToString(),
                            UKRisco       = row["ukrisc"].ToString(),
                            UKDanos       = row["UKdanos"].ToString(),
                            NomeAtividade = new List <Atividade>(),
                        };
                        if (!string.IsNullOrEmpty(row["ukAtiv"]?.ToString()))
                        {
                            atividade = new Atividade()
                            {
                                UniqueKey = Guid.Parse(row["ukAtiv"].ToString()),
                                Descricao = row["NomeAtividade"].ToString(),
                                Perigos   = new List <Perigo>(),
                            };

                            if (!string.IsNullOrEmpty(row["ukPer"]?.ToString()))
                            {
                                perigo = new Perigo()
                                {
                                    UniqueKey = Guid.Parse(row["ukPer"].ToString()),
                                    Descricao = row["DescPerigo"].ToString(),
                                    Riscos    = new List <Risco>()
                                };

                                atividade.Perigos.Add(perigo);
                            }

                            if (!string.IsNullOrEmpty(row["ukrisc"]?.ToString()))
                            {
                                risc = new Risco()
                                {
                                    UniqueKey = Guid.Parse(row["ukrisc"].ToString()),
                                    Nome      = row["NomeRisco"].ToString(),
                                    Danos     = new List <PossiveisDanos>(),
                                };

                                if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                {
                                    risc.Reconhecimento = new ReconhecimentoDoRisco()
                                    {
                                        UniqueKey   = Guid.Parse(row["UKReconhecimento"].ToString()),
                                        UKRisco     = Guid.Parse(row["rUKRisco"].ToString()),
                                        UKAtividade = Guid.Parse(row["ukAtiv"].ToString()),
                                    };
                                }

                                perigo.Riscos.Add(risc);
                            }
                            if (!string.IsNullOrEmpty(row["UKdanos"]?.ToString()))
                            {
                                danos = new PossiveisDanos()
                                {
                                    UniqueKey      = Guid.Parse(row["UKdanos"].ToString()),
                                    DescricaoDanos = row["DescricaoDanos"].ToString()
                                };

                                risc.Danos.Add(danos);
                            }



                            obj1.NomeAtividade.Add(atividade);

                            ListRiscos.Add(obj1);
                        }
                    }
                    else
                    {
                        if (obj1.UKAtividade.Equals(row["ukAtiv"].ToString()))
                        {
                            if (obj1.UKPerigo.Equals(row["ukPer"].ToString()))
                            {
                                if (obj1.UKRisco.Equals(row["ukrisc"].ToString()))
                                {
                                    if (!string.IsNullOrEmpty(row["UKdanos"]?.ToString()))
                                    {
                                        danos = new PossiveisDanos()
                                        {
                                            DescricaoDanos = row["DescricaoDanos"].ToString()
                                        };

                                        risc.Danos.Add(danos);
                                    }
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(row["ukrisc"]?.ToString()))
                                    {
                                        risc = new Risco()
                                        {
                                            UniqueKey = Guid.Parse(row["ukrisc"].ToString()),
                                            Nome      = row["NomeRisco"].ToString(),
                                            Danos     = new List <PossiveisDanos>()
                                        };

                                        if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                        {
                                            risc.Reconhecimento = new ReconhecimentoDoRisco()
                                            {
                                                UniqueKey   = Guid.Parse(row["UKReconhecimento"].ToString()),
                                                UKRisco     = Guid.Parse(row["rUKRisco"].ToString()),
                                                UKAtividade = Guid.Parse(row["ukAtiv"].ToString()),
                                            };
                                        }

                                        perigo.Riscos.Add(risc);
                                    }
                                    if (!string.IsNullOrEmpty(row["UKdanos"]?.ToString()))
                                    {
                                        danos = new PossiveisDanos()
                                        {
                                            DescricaoDanos = row["DescricaoDanos"].ToString()
                                        };

                                        risc.Danos.Add(danos);
                                    }
                                }
                            }
                            else
                            {
                                obj1 = new VMAtividadesRiscos()
                                {
                                    UKAtividade   = row["ukAtiv"].ToString(),
                                    UKPerigo      = row["ukPer"].ToString(),
                                    UKRisco       = row["ukrisc"].ToString(),
                                    UKDanos       = row["UKdanos"].ToString(),
                                    NomeAtividade = new List <Atividade>(),
                                };

                                if (!string.IsNullOrEmpty(row["ukPer"]?.ToString()))
                                {
                                    perigo = new Perigo()
                                    {
                                        UniqueKey = Guid.Parse(row["ukPer"].ToString()),
                                        Descricao = row["DescPerigo"].ToString(),
                                        Riscos    = new List <Risco>()
                                    };

                                    atividade.Perigos.Add(perigo);
                                }

                                if (!string.IsNullOrEmpty(row["ukrisc"]?.ToString()))
                                {
                                    risc = new Risco()
                                    {
                                        UniqueKey = Guid.Parse(row["ukrisc"].ToString()),
                                        Nome      = row["NomeRisco"].ToString(),
                                        Danos     = new List <PossiveisDanos>()
                                    };
                                    if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                    {
                                        risc.Reconhecimento = new ReconhecimentoDoRisco()
                                        {
                                            UniqueKey   = Guid.Parse(row["UKReconhecimento"].ToString()),
                                            UKRisco     = Guid.Parse(row["rUKRisco"].ToString()),
                                            UKAtividade = Guid.Parse(row["ukAtiv"].ToString()),
                                        };
                                    }

                                    perigo.Riscos.Add(risc);
                                }
                                if (!string.IsNullOrEmpty(row["UKdanos"]?.ToString()))
                                {
                                    danos = new PossiveisDanos()
                                    {
                                        DescricaoDanos = row["DescricaoDanos"].ToString()
                                    };

                                    risc.Danos.Add(danos);
                                }

                                ListRiscos.Add(obj1);
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(row["ukAtiv"].ToString()))
                            {
                                obj1 = new VMAtividadesRiscos()
                                {
                                    UKAtividade   = row["ukAtiv"].ToString(),
                                    UKPerigo      = row["ukPer"].ToString(),
                                    UKRisco       = row["ukrisc"].ToString(),
                                    UKDanos       = row["UKdanos"].ToString(),
                                    NomeAtividade = new List <Atividade>(),
                                };

                                atividade = new Atividade()
                                {
                                    UniqueKey = Guid.Parse(row["ukAtiv"].ToString()),
                                    Descricao = row["NomeAtividade"].ToString(),
                                    Perigos   = new List <Perigo>(),
                                };

                                if (!string.IsNullOrEmpty(row["ukPer"].ToString()))
                                {
                                    perigo = new Perigo()
                                    {
                                        UniqueKey = Guid.Parse(row["ukPer"].ToString()),
                                        Descricao = row["DescPerigo"].ToString(),
                                        Riscos    = new List <Risco>()
                                    };

                                    atividade.Perigos.Add(perigo);
                                }

                                if (!string.IsNullOrEmpty(row["ukrisc"]?.ToString()))
                                {
                                    risc = new Risco()
                                    {
                                        UniqueKey = Guid.Parse(row["ukrisc"].ToString()),
                                        Nome      = row["NomeRisco"].ToString(),
                                        Danos     = new List <PossiveisDanos>()
                                    };
                                    if (!string.IsNullOrEmpty(row["UKReconhecimento"].ToString()))
                                    {
                                        risc.Reconhecimento = new ReconhecimentoDoRisco()
                                        {
                                            UniqueKey   = Guid.Parse(row["UKReconhecimento"].ToString()),
                                            UKRisco     = Guid.Parse(row["rUKRisco"].ToString()),
                                            UKAtividade = Guid.Parse(row["ukAtiv"].ToString()),
                                        };
                                    }

                                    perigo.Riscos.Add(risc);
                                }
                                if (!string.IsNullOrEmpty(row["UKdanos"]?.ToString()))
                                {
                                    danos = new PossiveisDanos()
                                    {
                                        DescricaoDanos = row["DescricaoDanos"].ToString()
                                    };

                                    risc.Danos.Add(danos);
                                }

                                obj1.NomeAtividade.Add(atividade);

                                ListRiscos.Add(obj1);
                            }
                        }

                        // ListRiscos.Add(obj);
                    }
                }
            }

            //ListRiscos.Add(obj1);

            ViewBag.Atividade = ListRiscos;

            return(PartialView("_PesquisaAtividade", ListRiscos));
        }