예제 #1
0
        public ActionResult CadastrarData(string UKdate, string Unique, string UKDoc)
        {
            Guid UKdocs  = Guid.Parse(UKDoc);
            Guid Uniques = Guid.Parse(Unique);


            REL_DocumentosAlocados oTemp = REL_DocumentosAlocadoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(Uniques) && a.UKDocumento.Equals(UKdocs));

            if (ModelState.IsValid)
            {
                try
                {
                    oTemp.UKDocumento   = UKdocs;
                    oTemp.DataDocumento = Convert.ToDateTime(UKdate);

                    REL_DocumentosAlocadoBusiness.Alterar(oTemp);

                    Extensions.GravaCookie("MensagemSucesso", "As datas foram atualizado com sucesso.", 10);


                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("ConfirmaData", "DocumentoAlocacao")
                                      } }));
                }
                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() }));
            }
        }
예제 #2
0
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult EditarData(string UK, string data)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Guid UKp = Guid.Parse(UK);

                    var documento = REL_DocumentosAlocadoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(UKp));

                    documento.DataDocumento = Convert.ToDateTime(data);

                    REL_DocumentosAlocadoBusiness.Alterar(documento);

                    TempData["MensagemSucesso"] = "Data alterada para: '" + documento.DataDocumento + "' com sucesso.";

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Ged")
                                      } }));
                }
                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() }));
            }
        }
예제 #3
0
        public ActionResult DesalocarDocs(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    throw new Exception("Não foi possível localizar a identificação da alocação para prosseguir com a operação.");
                }

                Guid UKAlocacao = Guid.Parse(id);

                var al = (from r in REL_DocumentosAlocadoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKAlocacao.Equals(UKAlocacao)).ToList()
                          select new REL_DocumentosAlocados()
                {
                    ID = r.ID,
                    UKAlocacao = r.UKAlocacao,
                }).ToList();

                List <REL_DocumentosAlocados> REL = new List <REL_DocumentosAlocados>();

                REL = al;


                if (REL == null)
                {
                    throw new Exception("Não foi possível encontrar os Documentos na base de dados.");
                }

                //Admissao ad = AdmissaoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(al.UKAdmissao));
                //if (ad == null)
                //    throw new Exception("Não foi possível encontrar a admissão onde o empregado está alocado na base de dados.");
                foreach (var item in REL)
                {
                    if (item.UKAlocacao.Equals(UKAlocacao) && item.UsuarioExclusao == null)
                    {
                        REL_DocumentosAlocados docs = REL_DocumentosAlocadoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKAlocacao.Equals(UKAlocacao));
                        if (docs == null)
                        {
                            throw new Exception("Não foi possível encontrar a alocação na base de dados.");
                        }

                        docs.UsuarioExclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;

                        REL_DocumentosAlocadoBusiness.Terminar(docs);
                    }
                }

                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      Sucesso = "Documentos desalocados!"
                                  } }));


                //Extensions.GravaCookie("MensagemSucesso", "Docuemntos desalocado com sucesso.", 10);
            }
            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
                                      } }));
                }
            }
        }
예제 #4
0
        public ActionResult Cadastrar(string UKAlocacao, string UKDoc)
        {
            var documento = UKDoc;

            try
            {
                Guid UK_Alocacao = Guid.Parse(UKAlocacao);

                if (string.IsNullOrEmpty(UKAlocacao))
                {
                    throw new Exception("Não foi possível localizar a Alocação.");
                }

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


                if (documento.Contains(","))
                {
                    documento = documento.Remove(documento.Length - 1);

                    foreach (string ativ in documento.Split(','))
                    {
                        if (!string.IsNullOrEmpty(ativ.Trim()))
                        {
                            DocumentosPessoal pTemp = DocumentosPessoalBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.NomeDocumento.Equals(ativ.Trim()));
                            if (pTemp != null)
                            {
                                if (REL_DocumentosAlocadoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKDocumento.Equals(pTemp.UniqueKey) && a.UKAlocacao.Equals(UK_Alocacao)).Count() == 0)
                                {
                                    REL_DocumentosAlocadoBusiness.Inserir(new REL_DocumentosAlocados()
                                    {
                                        Posicao         = 0,
                                        UKAlocacao      = UK_Alocacao,
                                        UKDocumento     = pTemp.UniqueKey,
                                        DataDocumento   = DateTime.MaxValue,
                                        UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                                    });
                                }
                                else
                                {
                                    return(Json(new { resultado = new RetornoJSON()
                                                      {
                                                          Erro = "Este documento já está cadastrado para esta alocação!."
                                                      } }));
                                }
                            }
                        }
                    }
                }
                else
                {
                    DocumentosPessoal pTemp = DocumentosPessoalBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.NomeDocumento.Equals(documento.Trim()));
                    if (pTemp != null)
                    {
                        if (REL_DocumentosAlocadoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKDocumento.Equals(pTemp.UniqueKey) && a.UKAlocacao.Equals(UK_Alocacao)).Count() == 0)
                        {
                            REL_DocumentosAlocadoBusiness.Inserir(new REL_DocumentosAlocados()
                            {
                                UKAlocacao      = UK_Alocacao,
                                UKDocumento     = pTemp.UniqueKey,
                                UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                            });
                        }
                    }
                }



                Extensions.GravaCookie("MensagemSucesso", "Os documentos foram alocados com sucesso!", 10);

                //return RedirectToAction("ConfirmaData", "DocumentoAlocacao", UK_Alocacao) ;

                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      URL = Url.Action("ConfirmaData", "DocumentoAlocacao", UK_Alocacao)
                                  } }));
            }
            catch (Exception ex)
            {
                return(Json(new { resultado = new RetornoJSON()
                                  {
                                      Erro = ex.Message
                                  } }));
            }
        }
예제 #5
0
        public ActionResult Cadastrar(Alocacao entidade)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Admissao oAdmissao = AdmissaoBusiness.Consulta.FirstOrDefault(p => string.IsNullOrEmpty(p.UsuarioExclusao) && p.UniqueKey.Equals(entidade.UKAdmissao));
                    if (oAdmissao == null)
                    {
                        throw new Exception("Não foi possível encontrar a admissão na base de dados.");
                    }


                    Empregado emp = EmpregadoBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(oAdmissao.UKEmpregado));
                    if (emp == null)
                    {
                        throw new Exception("Não foi possível encontrar o empregado na base de dados.");
                    }



                    if (AlocacaoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) &&
                                                        a.UKAdmissao.Equals(entidade.UKAdmissao) &&
                                                        a.UKCargo.Equals(entidade.UKCargo) &&
                                                        a.UKFuncao.Equals(entidade.UKFuncao)).Count() > 0)
                    {
                        throw new Exception("Já existe uma alocação deste empregado neste cargo e função selecionado.");
                    }
                    else
                    {
                        entidade.UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                        AlocacaoBusiness.Inserir(entidade);


                        Usuario usr = UsuarioBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.Login.Equals(emp.CPF.Replace(".", "").Replace("-", "")));
                        if (usr == null)
                        {
                            // string Senha = GISHelpers.Utils.Severino.GeneratePassword();

                            string Senha = "escola10";

                            usr = new Usuario()
                            {
                                UniqueKey       = Guid.NewGuid(),
                                CPF             = emp.CPF,
                                Nome            = emp.Nome,
                                UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login,
                                Email           = emp.Email,
                                Login           = emp.CPF.Replace(".", "").Replace("-", ""),
                                Senha           = Senha,
                                TipoDeAcesso    = GISModel.Enums.TipoDeAcesso.Sistema,
                                UKEmpresa       = oAdmissao.UKEmpresa,
                                UKDepartamento  = entidade.UKDepartamento
                            };

                            UsuarioBusiness.Inserir(usr);

                            Perfil per = PerfilBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.Nome.Equals("Empregado"));
                            if (per != null)
                            {
                                UsuarioPerfilBusiness.Inserir(new UsuarioPerfil()
                                {
                                    UKPerfil        = per.UniqueKey,
                                    UKUsuario       = usr.UniqueKey,
                                    UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login,
                                    UKConfig        = entidade.UKDepartamento
                                });
                            }
                        }

                        //Cadastrando os documentos relacionados com a atividade alocada.


                        var aloc = @"select top 1  UniqueKey, DataInclusao  from tbAlocacao LAST_INSET_ID ORDER BY DataInclusao DESC  ";

                        List <Alocacao> lista1 = new List <Alocacao>();

                        DataTable result1 = DocumentosPessoalBusiness.GetDataTable(aloc);

                        if (result1.Rows.Count > 0)
                        {
                            Alocacao UkAloc = null;
                            Guid     ukal   = Guid.Empty;

                            foreach (DataRow row in result1.Rows)
                            {
                                if (UkAloc == null)
                                {
                                    UkAloc = new Alocacao()
                                    {
                                        UniqueKey = Guid.Parse(row["UniqueKey"].ToString())
                                    };
                                }
                            }

                            if (UkAloc != null)
                            {
                                lista1.Add(UkAloc);
                            }

                            foreach (var item in lista1)
                            {
                                if (item != null)
                                {
                                    ukal = item.UniqueKey;
                                }
                            }


                            //ukal = Uniquekey da ultima alocaçao


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

                            // aqui faço uma pesquisa de documentos relacionados a atividade

                            var sql = @"select al.UniqueKey as UKal, fa.UniqueKey as UKfa, d.UniqueKey as UKd, d.NomeDocumento as Nome,
                        da.UniqueKey as UKda
                        from tbAlocacao al
                        join REL_FuncaoAtividade fa
                        on al.UKFuncao = fa.UKFuncao
                        join REL_DocumentoPessoalAtividade da
                        on fa.UKAtividade = da.UKAtividade
                        join tbDocumentosPessoal d
                        on da.UKDocumentoPessoal = d.UniqueKey and d.DataExclusao = CONVERT(datetime,'9999-12-31 23:59:59.997',101)
                        where al.UniqueKey = '" + ukal + @"'
                        order by al.UniqueKey ";

                            DataTable result = DocumentosPessoalBusiness.GetDataTable(sql);

                            //abaixo monto uma lista de objetos com a Uniquekey da alocação e a relação de documentos relacionados a atividade alocada

                            if (result.Rows.Count > 0)
                            {
                                Alocacao          obj  = null;
                                DocumentosPessoal oDoc = null;

                                foreach (DataRow row in result.Rows)
                                {
                                    if (obj == null)
                                    {
                                        obj = new Alocacao()
                                        {
                                            UniqueKey         = Guid.Parse(row["UKal"].ToString()),
                                            DocumentosPessoal = new List <DocumentosPessoal>()
                                        };

                                        if (!string.IsNullOrEmpty(row["UKd"].ToString()))
                                        {
                                            oDoc = new DocumentosPessoal()
                                            {
                                                UniqueKey     = Guid.Parse(row["UKd"].ToString()),
                                                NomeDocumento = row["nome"].ToString(),
                                            };


                                            obj.DocumentosPessoal.Add(oDoc);
                                        }
                                    }
                                    else if (obj.UniqueKey.Equals(Guid.Parse(row["UKal"].ToString())))
                                    {
                                        if (!string.IsNullOrEmpty(row["UKda"].ToString()))
                                        {
                                            if (oDoc == null)
                                            {
                                                oDoc = new DocumentosPessoal()
                                                {
                                                    UniqueKey     = Guid.Parse(row["UKd"].ToString()),
                                                    NomeDocumento = row["nome"].ToString(),
                                                };

                                                obj.DocumentosPessoal.Add(oDoc);
                                            }


                                            else
                                            {
                                                oDoc = new DocumentosPessoal()
                                                {
                                                    UniqueKey     = Guid.Parse(row["UKd"].ToString()),
                                                    NomeDocumento = row["nome"].ToString(),
                                                };

                                                obj.DocumentosPessoal.Add(oDoc);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        lista.Add(obj);

                                        obj = new Alocacao()
                                        {
                                            UniqueKey         = Guid.Parse(row["UKal"].ToString()),
                                            DocumentosPessoal = new List <DocumentosPessoal>()
                                        };

                                        if (!string.IsNullOrEmpty(row["UKd"].ToString()))
                                        {
                                            oDoc = new DocumentosPessoal()
                                            {
                                                UniqueKey     = Guid.Parse(row["UKd"].ToString()),
                                                NomeDocumento = row["nome"].ToString(),
                                            };


                                            obj.DocumentosPessoal.Add(oDoc);
                                        }
                                    }
                                }

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


                                if (lista == null)
                                {
                                    throw new Exception("Nenhum Documento para vincular.");
                                }

                                string documento = string.Empty;

                                foreach (var item in obj.DocumentosPessoal)
                                {
                                    if (item != null)
                                    {
                                        documento += item.NomeDocumento + ",";
                                    }
                                }

                                // se vier uma array entra aqui neste if

                                if (documento.Contains(","))
                                {
                                    documento = documento.Remove(documento.Length - 1);

                                    foreach (string ativ in documento.Split(','))
                                    {
                                        if (!string.IsNullOrEmpty(ativ.Trim()))
                                        {
                                            DocumentosPessoal pTemp = DocumentosPessoalBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.NomeDocumento.Equals(ativ.Trim()));
                                            if (pTemp != null)
                                            {
                                                if (REL_DocumentosAlocadoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKDocumento.Equals(pTemp.UniqueKey) && a.UKAlocacao.Equals(ukal)).Count() == 0)
                                                {
                                                    REL_DocumentosAlocadoBusiness.Inserir(new REL_DocumentosAlocados()
                                                    {
                                                        Posicao         = 0,
                                                        UKAlocacao      = ukal,
                                                        UKDocumento     = pTemp.UniqueKey,
                                                        DataDocumento   = DateTime.MaxValue,
                                                        UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                                                    });
                                                }
                                                //else
                                                //{
                                                //    return Json(new { resultado = new RetornoJSON() { Erro = "Este documento já está cadastrado para esta alocação!." } });
                                                //}
                                            }
                                        }
                                    }
                                }

                                // se vier somente um documento entre aqui
                                else
                                {
                                    DocumentosPessoal pTemp = DocumentosPessoalBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.NomeDocumento.Equals(documento.Trim()));
                                    if (pTemp != null)
                                    {
                                        if (REL_DocumentosAlocadoBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UKDocumento.Equals(pTemp.UniqueKey) && a.UKAlocacao.Equals(ukal)).Count() == 0)
                                        {
                                            REL_DocumentosAlocadoBusiness.Inserir(new REL_DocumentosAlocados()
                                            {
                                                UKAlocacao      = ukal,
                                                UKDocumento     = pTemp.UniqueKey,
                                                UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                                            });
                                        }
                                    }
                                }
                            }
                        }


                        Extensions.GravaCookie("MensagemSucesso", "O empregado foi alocado com sucesso.", 10);

                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              URL = Url.Action("Perfil", "Empregado", new { id = oAdmissao.UKEmpregado.ToString() })
                                          } }));
                    }
                }
                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() }));
            }
        }