public Retorno AtualizarSenha(int idUsuario, string senhaAntiga, string senhaNova)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();

                _cmd = _db.GetStoredProcCommand("AtualizaSenha");
                _db.AddInParameter(_cmd, "@idUsuario", DbType.Int16, idUsuario);
                _db.AddInParameter(_cmd, "@SenhaAntiga", DbType.String, senhaAntiga);
                _db.AddInParameter(_cmd, "@SenhaNova", DbType.String, senhaNova);

                var _retorno = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {

                        _retorno.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _retorno.Mensagem = _dr[1].ToString();
                    }
                }

                if (_retorno == null) { throw new Erro("Retorno não localizado. AtualizarSenha"); }

                return _retorno;
            }
            catch (Exception ex) { throw ex; }
        }
        public ActionResult Create(FormCollection frm)
        {
            var Retorno = new Retorno();
            try
            {

                int idperfil = int.Parse(frm["acao"].ToString()) == 1 ? 0 : int.Parse(frm["SelPerfil"].ToString());
                var p = new Perfil()
                {
                     TipoAcao = int.Parse(frm["acao"].ToString()),
                     Descricao = idperfil == 0 ? frm["SelPerfil"].ToString() : frm["nomeperfil"].ToString(),
                     idServico = int.Parse(frm["SelServico"].ToString()),
                     idPerfil = idperfil>0?idperfil:0,
                     idModulo = frm["modulos"].ToString(),
                     qtdeModulo = int.Parse(frm["qtdeModulos"].ToString()),
                };

                var perfilRet = new PerfilRepository();
                Retorno = perfilRet.Incluir(p);
                if (Retorno.CodigoRetorno < 0)
                {
                    throw new Exception(Retorno.Mensagem);
                }
                TempData["Msg"] = Retorno.Mensagem;
                return RedirectToAction("Index");

            }
            catch(Exception ex)
            {
                TempData["Error"] = ex.Message;
                return View();
            }
        }
        public Retorno Incluir(Ocorrencia _ocor)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("proc_Manutencao_Ocorrencia");
                _db.AddInParameter(_cmd, "@TipoAcao", DbType.Int16, _ocor.TipoAcao);
                _db.AddInParameter(_cmd, "@Descricao", DbType.String, _ocor.descOcorrencia);
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, _ocor.idServico);
                _db.AddInParameter(_cmd, "@idOcorrencia", DbType.Int16, _ocor.IdOcorrencia);
                _db.AddInParameter(_cmd, "@idUsuario", DbType.Int16, _ocor.idUsuario);
                _db.AddInParameter(_cmd, "@Tipo", DbType.Int16, _ocor.Tipo);

                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno AlterarUsuario(int _idusualt, int _idusu, string _nome, string _login, string _email, string _senha,int? _primacesso, int _idperfil, int _idservico)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("Proc_Manu_AlterarUsuario");
                _db.AddInParameter(_cmd, "@idUsuarioAlt", DbType.Int16, _idusualt);
                _db.AddInParameter(_cmd, "@idUsuario", DbType.Int16, _idusu);
                _db.AddInParameter(_cmd, "@Nome", DbType.String, _nome);
                _db.AddInParameter(_cmd, "@Login", DbType.String, _login);
                _db.AddInParameter(_cmd, "@Email", DbType.String, _email);
                _db.AddInParameter(_cmd, "@Senha", DbType.String, _senha);
                _db.AddInParameter(_cmd, "@PrimeiroAcesso", DbType.Int16, _primacesso);
                _db.AddInParameter(_cmd, "@idPerfil", DbType.Int16, _idperfil);
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, _idservico);

                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno Incluir(Perfil p)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("proc_Manutencao_Perfil");
                _db.AddInParameter(_cmd, "@TipoAcao", DbType.Int16, p.TipoAcao);
                _db.AddInParameter(_cmd, "@Descricao", DbType.String, p.Descricao);
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, p.idServico);
                _db.AddInParameter(_cmd, "@idPerfil", DbType.Int16, p.idPerfil);
                _db.AddInParameter(_cmd, "@idModulo", DbType.String, p.idModulo);
                _db.AddInParameter(_cmd, "@QtdeModulo", DbType.Int16, p.qtdeModulo);

                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
 public JsonResult AjaxExcluir(string cpf_cnpj)
 {
     var Retorno = new Retorno();
     try
     {
         var cli = new Cliente()
         {
             TipoAcao = 3, //TipoAcao 3 é Exclusão
             CPF_CNPJ = Decimal.Parse(cpf_cnpj),
             idUsuarioAtual = UsuarioAtual.ID
         };
         var cliRet = new ClienteRepository();
         Retorno = cliRet.Incluir(cli);
         if (Retorno.CodigoRetorno < 0)
         {
             throw new Exception(Retorno.Mensagem);
         }
         //ViewBag.Msg = Retorno.Mensagem;
         TempData["Msg"] = Retorno.Mensagem;
         return Json(Retorno, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         //ViewBag.Error = ex.Message;
         //throw new Exception(ex.Message);
         return Json(Retorno, JsonRequestBehavior.AllowGet);
     }
 }
 public JsonResult AjaxMudaStatusDocumento(string idDocumento)
 {
     var ret = new Retorno();
     try
     {
         _docService.MudaStatusDocumento(int.Parse(idDocumento), UsuarioAtual.ID, 3010, ServicoAtual.ID);
         bool EmUso = _docService.EmUso(int.Parse(idDocumento), UsuarioAtual.ID, 2, ServicoAtual.ID);
     }
     catch (Exception erx)
     {
         ret.CodigoRetorno = 1;
         ret.Mensagem = erx.Message;
         return Json(ret, JsonRequestBehavior.AllowGet);
     }
     return Json(ret, JsonRequestBehavior.AllowGet);
 }
 public JsonResult AjaxVincular(int id_documento, int id_servico, int id_documentopai)
 {
     var ret = new Retorno();
     try
     {
         new DocumentoRepository().VincularDocumento(new Vinculo() { idDocumento = id_documento, idServico = id_servico, idDocumentoPai = id_documentopai });
         ret.CodigoRetorno = 1;
         ret.Mensagem = "Vinculo efetuado com sucesso.";
     }
     catch (Exception erx)
     {
         ret.CodigoRetorno = -1;
         ret.Mensagem = erx.Message;
         return Json(ret, JsonRequestBehavior.AllowGet);
     }
     return Json(ret, JsonRequestBehavior.AllowGet);
 }
예제 #9
0
        public List<Log> ConsultaLOG(int idServico, int idAcao = 0, string Localizador = "")
        {
            var lstLOG = new List<Log>();
            var _Ret = new Retorno();
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("GET_LocalizarAuditoria");
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, idServico);
                _db.AddInParameter(_cmd, "@idAcao", DbType.Int16, idAcao);
                _db.AddInParameter(_cmd, "@Localizador", DbType.String, Localizador);

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {

                        if (_dr.FieldCount==2 && int.Parse(_dr[0].ToString())<0)
                        {
                            throw new Exception("Erro, " + _dr[1].ToString());
                        }
                        else
                        {
                            lstLOG.Add(new Log()
                            {
                                IDLOG = decimal.Parse(_dr["IDLOG"].ToString()),
                                Cliente = _dr["Cliente"].ToString(),
                                Servico = _dr["Serviço"].ToString(),
                                Acao = _dr["Ação"].ToString(),
                                Localizador = _dr["Localizador"].ToString(),
                                DataHora = DateTime.Parse(_dr["Data"].ToString())
                            });
                        }

                    }
                }

                return lstLOG;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno Incluir(Licensa acs)
        {
            var _Ret = new Retorno();
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("Proc_Manutencao_Licenca");
                _db.AddInParameter(_cmd, "@TipoAcao", DbType.Int16, acs.TipoAcao); //(1)Criar, (2)Alterar, (3)Excluir
                _db.AddInParameter(_cmd, "@idCliente", DbType.Int16, acs.idCliente);
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, acs.idServico);
                _db.AddInParameter(_cmd, "@idUsuario", DbType.Int16, acs.idUsuario);

                _db.AddInParameter(_cmd, "@IPServerHost", DbType.String, acs.IPServerHost);
                _db.AddInParameter(_cmd, "@HostnameServer", DbType.String, acs.HostnameServer);
                _db.AddInParameter(_cmd, "@IPPublicClient", DbType.String, acs.IPPublicClient);
                _db.AddInParameter(_cmd, "@IPPrivateClient", DbType.String, acs.IPPrivateClient);
                _db.AddInParameter(_cmd, "@HostnameClient", DbType.String, acs.HostnameClient);

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex)
            {
                _Ret.CodigoRetorno = -2;
                _Ret.Mensagem = ex.Message;
                return _Ret;
                //throw new Exception(ex.Message);
            }
        }
        public Retorno GravarFormalizacao(Formalizacao frm)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("Inserir_documento_formalizacao");
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, frm.IdServico);
                _db.AddInParameter(_cmd, "@idDocumento", DbType.Int16, frm.IdDocumento);
                _db.AddInParameter(_cmd, "@idFormalizacao", DbType.Int16, frm.IdFormalizacao);
                _db.AddInParameter(_cmd, "@Valor", DbType.Int16, frm.Valor);

                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
예제 #12
0
        public List<LogDetalhe> ConsultaLOG_Detalhe(int idLOG)
        {
            var lstLOG_Detalhe = new List<LogDetalhe>();
            var _Ret = new Retorno();
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("GET_LocalizarAuditoriaDetalhe");
                _db.AddInParameter(_cmd, "@idLog", DbType.Int16, idLOG);

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {

                        if (_dr.FieldCount == 2 && int.Parse(_dr[0].ToString()) < 0)
                        {
                            throw new Exception("Erro, " + _dr[1].ToString());
                        }
                        else
                        {
                            lstLOG_Detalhe.Add(new LogDetalhe()
                            {
                                Data = DateTime.Parse(_dr["Data do evento"].ToString()).ToString("dd/MM/yyyy hh:mm:ss"),
                                Detalhe = _dr["Descrição"].ToString(),
                                Conteudo = _dr["Localizador"].ToString(),
                            });
                        }

                    }
                }

                return lstLOG_Detalhe;
            }
            catch (Exception ex) { throw ex; }
        }
예제 #13
0
        public Retorno RegistrarLOGDetalhe(int idAcao, string conteudo)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("LOG_InserirAuditoriaDetalhe");
                _db.AddInParameter(_cmd, "@IdLog", DbType.Int32, this.idLOG);
                _db.AddInParameter(_cmd, "@IdAcao", DbType.Int32, idAcao);
                _db.AddInParameter(_cmd, "@IdServico", DbType.Int32, this.idServico);
                _db.AddInParameter(_cmd, "@Conteudo", DbType.String, conteudo);

                var _Ret = new Retorno();
                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                        if (_Ret.CodigoRetorno < 0)
                        {
                            throw new Exception("Erro, " + _Ret.Mensagem);
                        }
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno Incluir(Cliente usu)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("proc_Manutencao_Cliente");
                _db.AddInParameter(_cmd, "@TipoAcao", DbType.Int16, usu.TipoAcao);
                _db.AddInParameter(_cmd, "@CPF_CNPJ", DbType.Decimal, usu.CPF_CNPJ);
                _db.AddInParameter(_cmd, "@Descricao", DbType.String, usu.Descricao);
                _db.AddInParameter(_cmd, "@UrlEstilo", DbType.String, "URL.CSS");
                _db.AddInParameter(_cmd, "@DataCriacao", DbType.Int16, 0);
                _db.AddInParameter(_cmd, "@DataExclusao", DbType.Int16, 0);
                _db.AddInParameter(_cmd, "@DataAlteracao", DbType.Int16, 0);
                _db.AddInParameter(_cmd, "@Status", DbType.Int16, usu.Status);
                _db.AddInParameter(_cmd, "@QtdeUsuario", DbType.Int16, usu.QtdeUsuario);
                _db.AddInParameter(_cmd, "@Email_principal", DbType.String, usu.EmailPrincipal);
                _db.AddInParameter(_cmd, "@idUsuarioAtual", DbType.Int16, usu.idUsuarioAtual);

                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno VerificaServicoPerfil(string login, string senha)
        {
            var ret = new Retorno();
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();

                _cmd = _db.GetStoredProcCommand("Proc_VerificaServicoPerfilUsuario");
                _db.AddInParameter(_cmd, "@login", DbType.String, login);
                _db.AddInParameter(_cmd, "@senha", DbType.String, senha);

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                           ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                           ret.Mensagem = _dr[1].ToString();
                    }
                }

                return ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public ActionResult Incluir(FormCollection frm)
        {
            var Retorno = new Retorno();

            try
            {

                var cli = new Cliente()
                {
                    TipoAcao=1,
                    CPF_CNPJ = Decimal.Parse(frm["cpfcnpj"].ToString()),
                    Descricao = frm["nome"].ToString(),
                    Status = frm["status"]==null ? 0 : int.Parse(frm["status"].ToString()),
                    QtdeUsuario = int.Parse(frm["qtdusu"].ToString()),
                    EmailPrincipal = frm["email"].ToString(),
                    idUsuarioAtual = UsuarioAtual.ID
                };
                ViewBag.Cliente = cli;
                var RetCPF = new UsuarioRepository().VerificaCPFDisponivel(UsuarioAtual.ID, decimal.Parse(frm["cpfcnpj"].ToString()));
                if (RetCPF.CodigoRetorno == 1)
                    throw new Exception(RetCPF.Mensagem);

                var cliRet = new ClienteRepository();
                Retorno = cliRet.Incluir(cli);
                if (Retorno.CodigoRetorno < 0)
                {
                    throw new Exception(Retorno.Mensagem);
                }
                TempData["Msg"] = Retorno.Mensagem;
                return RedirectToAction("Index", new { msg = Retorno.Mensagem });
            }
            catch(Exception ex)
            {
                ViewBag.Error = ex.Message;
                TempData["Error"] = ex.Message;
                return View("Create",frm);
                //throw new Exception(ex.Message);
            }
        }
        public Retorno ReativarUsuarioExcluido(int idUsuario, decimal cpf)
        {
            var _retorno = new Retorno();
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();

                _cmd = _db.GetStoredProcCommand("Proc_ReativaUsuarioExcluido");
                _db.AddInParameter(_cmd, "@idUsuario", DbType.Int16, idUsuario);
                _db.AddInParameter(_cmd, "@CPF", DbType.Decimal, cpf);

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {

                        _retorno.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _retorno.Mensagem = _dr[1].ToString();
                    }
                }

                if (_retorno == null) { throw new Erro("Retorno não localizado."); }

                return _retorno;
            }
            catch (Exception ex) {
                _retorno.Mensagem = ex.Message;
                return _retorno;
            }
        }
        public Retorno IncluirUsuario(Usuario usu)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("proc_Manutencao_Usuario");
                _db.AddInParameter(_cmd, "@CPF", DbType.Decimal, Decimal.Parse(usu.CPF));
                _db.AddInParameter(_cmd, "@Nome", DbType.String, usu.NomeCompleto);
                _db.AddInParameter(_cmd, "@UserName", DbType.String, usu.NomeUsuario);
                _db.AddInParameter(_cmd, "@Senha", DbType.String, usu.Senha);
                _db.AddInParameter(_cmd, "@TipoAcao", DbType.Int16, usu.TipoAcao);
                _db.AddInParameter(_cmd, "@idCliente", DbType.Int16, usu.ClienteID);
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, usu.ServicoID);
                _db.AddInParameter(_cmd, "@Perfil", DbType.Int16, usu.PerfilID);
                _db.AddInParameter(_cmd, "@Situacao", DbType.Int16, usu.Situacao);
                _db.AddInParameter(_cmd, "@Email", DbType.String, usu.Email);

                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno BloquearUsuario(int idServico, int idUsuarioBloqueado, int idUsuario)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("UPD_BloqueioUsuario");
                _db.AddInParameter(_cmd, "@idServico", DbType.Int16, idServico);
                _db.AddInParameter(_cmd, "@idUsuarioBloqueio", DbType.Int16, idUsuarioBloqueado);
                _db.AddInParameter(_cmd, "@idUsuario", DbType.Int16, idUsuario);

                //_db.ExecuteNonQuery(_cmd);
                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                        _Ret.Bloqueado = int.Parse(_dr[2].ToString());
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno ExcluirUsuario(int idUsuario, int idServico, int idUsuarioAtual)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();
                _cmd = _db.GetStoredProcCommand("Proc_Manu_ExcluirUsuario");
                _db.AddInParameter(_cmd, "@IdUsuario", DbType.Int16, idUsuario);
                _db.AddInParameter(_cmd, "@IdServico", DbType.Int16, idServico);
                _db.AddInParameter(_cmd, "@IdUsuarioExcluir", DbType.Int16, idUsuarioAtual);

                var _Ret = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {
                        _Ret.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _Ret.Mensagem = _dr[1].ToString();
                    }
                }
                return _Ret;
            }
            catch (Exception ex) { throw ex; }
        }
        public Retorno VerificaLoginDisponivel(int idUsuario, string novoUserName)
        {
            try
            {
                DbCommand _cmd;
                Database _db = DbConn.CreateDB();

                _cmd = _db.GetStoredProcCommand("Proc_verificaLogin_Disponivel");
                _db.AddInParameter(_cmd, "@idUsuario", DbType.Int16, idUsuario);
                _db.AddInParameter(_cmd, "@UserName", DbType.String, novoUserName);

                var _retorno = new Retorno();

                using (IDataReader _dr = _db.ExecuteReader(_cmd))
                {
                    while (_dr.Read())
                    {

                        _retorno.CodigoRetorno = int.Parse(_dr[0].ToString());
                        _retorno.Mensagem = _dr[1].ToString();
                    }
                }

                if (_retorno == null) { throw new Erro("Retorno não localizado."); }

                return _retorno;
            }
            catch (Exception ex) { throw ex; }
        }
        public ActionResult Edit(FormCollection frm)
        {
            var Retorno = new Retorno();
            try
            {
                var p = new DocumentoModelo();

                p.TipoAcao = 2;
                p.Descricao = frm["txtnomedoc"].ToString();
                p.Rotulo = frm["txtrotulo"].ToString();
                p.idServico = int.Parse(frm["idservico"].ToString()); //int.Parse(frm["SelServico"].ToString());
                p.Tipificalote = int.Parse(frm["retTipificar"].ToString());
                p.Multi_Pagina = int.Parse(frm["retMultipagina"].ToString());
                p.ScriptSQLTipificar = frm["txtscriptsqltipificar"].ToString();
                p.ScriptSQLValidar = frm["txtscriptsqlvalidar"].ToString();
                p.ScriptSQLConsulta = frm["txtscriptsqlconsulta"].ToString();
                p.ScriptSQLModulo = frm["txtscriptsqlmodulo"].ToString();
                p.DocumentoModeloPai = frm["txtdocmodelopai"].ToString() == "" ? 0 : int.Parse(frm["txtdocmodelopai"].ToString());
                p.ArquivoDados = int.Parse(frm["retArqDados"].ToString());
                p.idCampoModelo = frm["idCampoModelo"].ToString();

                var docModelo = new DocumentoModeloRepository();
                Retorno = docModelo.Incluir(p);
                if (Retorno.CodigoRetorno < 0)
                {
                    throw new Exception(Retorno.Mensagem);
                }
                else
                {
                    if (frm["listaCampos"].ToString() != "")
                    {
                        //var campos_selecionados = p.idCampoModelo.Split(',');
                        var items = frm["listaCampos"].ToString(); // Get the JSON string
                        JArray o = JArray.Parse(items); // It is an array so parse into a JArray
                        int n = 1;
                        foreach (var itm in o)
                        {
                            int _IdCampo = int.Parse(itm.SelectToken("idcampo").ToString());   //o.SelectToken("[0].cod").ToString(); // Get the name value of the 1st object in the array
                            int _Digita = int.Parse(itm.SelectToken("Digita").ToString()); //o.SelectToken("[0].valor").ToString();
                            int _FiltroConsulta = int.Parse(itm.SelectToken("FiltroConsulta").ToString());

                            int _Obrigatorio = int.Parse(itm.SelectToken("Obrigatorio").ToString());
                            int _Reconhece = int.Parse(itm.SelectToken("Reconhece").ToString());
                            string _Validacao = itm.SelectToken("Validacao").ToString();

                            var cpm = new DocumentoCampoModelo();
                            cpm.idDocumentoModelo = Retorno.idDocumentoModelo;
                            cpm.idCampoModelo = _IdCampo;
                            cpm.Digita = _Digita;
                            cpm.FiltroConsulta = _FiltroConsulta;
                            cpm.Requerido = _Obrigatorio;
                            cpm.Reconhece = _Reconhece;
                            cpm.ProcSqlValidacao = _Validacao;
                            cpm.IdDocumentoModeloPai = p.DocumentoModeloPai;
                            cpm.Tabulacao = n;
                            new DocumentoModeloRepository().IncluirCampos(cpm);
                            n++;
                        }
                    }
                }
                TempData["Msg"] = Retorno.Mensagem;
                return RedirectToAction("Index");

            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
                return RedirectToAction("Novo", new { msg = ex.Message });
            }
        }