예제 #1
0
        public ChaveViewModel Salvar([FromBody] ChaveViewModel chaveViewModel)
        {
            Chave chave = null;

            if (chaveViewModel.Id == 0)
            {
                chave = new Chave();
                chave.TipoDocumento = new TipoDocumento {
                    Id = chaveViewModel.TipoDocumentoId
                };
            }
            else
            {
                chave = this.chaveRepositorio.ObterPorId(chaveViewModel.Id);
            }

            chave.Nome        = chaveViewModel.Nome;
            chave.Obrigatorio = chaveViewModel.Obrigatorio;
            chave.TipoDado    = TipoDado.FromInt32(chaveViewModel.TipoDado);
            chave.Mascara     = chaveViewModel.Mascara;
            chave.Ativo       = chaveViewModel.Ativo;
            chave.ItensLista  = chaveViewModel.ItensListaComoTexto;

            this.chaveRepositorio.Salvar(chave);

            var tipo = this.tipodocumentoRepositorio.ObterPorId(chave.TipoDocumento.Id);

            chaveViewModel.Id = chave.Id;
            chaveViewModel.TipoDocumentoId   = chave.TipoDocumento.Id;
            chaveViewModel.TipoDocumentoNome = tipo.Nome;

            return(chaveViewModel);
        }
예제 #2
0
 private Operacao(Operacao op)
 {
     tipoOperacao = op.tipoOperacao;
     tipoDado     = op.tipoDado;
     aresta       = op.aresta;
     vertice      = op.vertice;
 }
 public void Ler(TipoDado tipoDado)
 {
     TipoDado = tipoDado;
     RotuloPrompt.Text = String.Format("Informe um valor do tipo {0}:", TipoDado.ToString());
     CaixaTexto.Clear();
     ShowDialog();
 }
예제 #4
0
 public DadoTabela(string nome, TipoDado tipo, byte tamanho, bool isValido, dynamic valor)
 {
     this.nome = nome;
     this.tipo = tipo;
     this.tamanho = tamanho;
     this.posicao = -1;
     this.isValido = isValido;
     this.valor = valor;
 }
예제 #5
0
 public DadoTabela(string nome, TipoDado tipo, byte tamanho, bool isValido, dynamic valor)
 {
     this.nome     = nome;
     this.tipo     = tipo;
     this.tamanho  = tamanho;
     this.posicao  = -1;
     this.isValido = isValido;
     this.valor    = valor;
 }
예제 #6
0
 public TipoDadoModel(TipoDado dado, Type[] tipo, object[] valor,
                      Func <object, object> convert,
                      Func <object, object> convertDb,
                      Func <object, string> convertStr)
 {
     Dado       = dado;
     Tipo       = tipo ?? throw new ArgumentNullException(nameof(tipo));
     Valor      = valor ?? throw new ArgumentNullException(nameof(valor));
     Convert    = convert;
     ConvertDb  = convertDb;
     ConvertStr = convertStr;
 }
예제 #7
0
 protected override Chave ConvertDtoToEntity(KeyDefDto dto)
 {
     return(new Chave
     {
         Id = dto.Id,
         TipoDocumento = this.Create <TipoDocumento>(dto.GroupDocCode),
         Obrigatorio = dto.Obrig == "S",
         Ativo = true,
         Nome = dto.Descricao,
         TipoDado = TipoDado.FromInt32(dto.TipoDadoId)
     });
 }
        public object ler(TipoDado tipoDado)
        {
            DialogoEntrada.Ler(tipoDado);

            if (!DialogoEntrada.Cancelado)
            {
                object valor = DialogoEntrada.Valor;
                SuporteSaida.Escrever(valor);

                return valor;
            }

            return null;
        }
예제 #9
0
 public void Salvar(TipoDado tipoDado)
 {
     try
     {
         if (tipoDado.IdTipoDado == 0)
         {
             _dao.Add(tipoDado);
             _dao.CommitChanges();
         }
         else
         {
             _dao.Update(tipoDado);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private String traduzirTipoDado(TipoDado tipoDado)
        {
            switch (tipoDado)
            {
                case TipoDado.CADEIA : return "String";
                case TipoDado.CARACTER : return "char";
                case TipoDado.INTEIRO : return "int";
                case TipoDado.LOGICO : return "boolean";
                case TipoDado.REAL : return "double";
                case TipoDado.VAZIO : return "void";
            }

            return null;
        }
예제 #11
0
        }                                           // Valor registrado no indice.

        #region *** Constutor ***
        public DadoIndice(TipoDado tipo, dynamic valor)
        {
            this.tipo  = tipo;
            this.valor = valor;
        }
예제 #12
0
 public DadoIndice(TipoDado tipo, dynamic valor)
 {
     this.tipo = tipo;
     this.valor = valor;
 }
예제 #13
0
 public UnidadeMedida(string nome, TipoDado tipoDado)
 {
     Nome     = nome;
     TipoDado = tipoDado;
 }
예제 #14
0
 public Operacao(TipoOperacao o, Grafo.Aresta a)
 {
     tipoOperacao = o;
     tipoDado     = TipoDado.Aresta;
     aresta       = a;
 }
예제 #15
0
 public IComparador Cria(TipoDado tipoDado)
 {
     return(this.comparadoresTipoDado[tipoDado]());
 }
예제 #16
0
        public static string Aplicar(string valor, OperadorMatematico operador, string fator, TipoDado tipoDado)
        {
            if (tipoDado == TipoDado.DateTime)
            {
                if (string.IsNullOrEmpty(valor) == false && valor.Length == 8)
                {
                    valor = string.Format("{0}/{1}/{2}",
                                          valor.Substring(0, 2),
                                          valor.Substring(2, 2),
                                          valor.Substring(4));
                }
            }

            if (operador == OperadorMatematico.Adicao)
            {
                double @double;
                if (double.TryParse(valor, out @double))
                {
                    valor = Convert.ToString(@double + Convert.ToDouble(fator));
                }
                else
                {
                    DateTime dateTime;
                    if (DateTime.TryParse(valor,
                                          out dateTime))
                    {
                        valor = dateTime.AddDays(Convert.ToDouble(fator)).ToString("dd/MM/yyyy");
                    }
                }
            }

            if (operador == OperadorMatematico.Subtracao)
            {
                double @double;
                if (double.TryParse(valor, out @double))
                {
                    valor = Convert.ToString(@double - Convert.ToDouble(fator));
                }
                else
                {
                    DateTime dateTime;
                    if (DateTime.TryParse(valor, out dateTime))
                    {
                        valor = dateTime
                                .AddDays(-1 * Convert.ToDouble(fator))
                                .ToString("dd/MM/yyyy");
                    }
                }
            }

            if (operador == OperadorMatematico.Multiplicacao)
            {
                double @double;
                if (double.TryParse(valor, out @double))
                {
                    valor = Convert.ToString(@double * Convert.ToDouble(fator.Replace('.', ',')));
                }
                else
                {
                    valor = "0";
                }
            }

            return(valor);
        }
예제 #17
0
        public TabelaSelect returnFiltrado(Dictionary <string, Filtro> filtrosAND)
        {
            br.BaseStream.Position = 0;
            int        count;
            int        tamRegistro = 12;
            Metadados  meta        = GerenciadorMemoria.getInstance().recuperarMetadados(nome);
            TabelaDado td          = new TabelaDado(nome);

            foreach (DadosTabela dados in meta.getDados().Values)
            {
                tamRegistro += dados.getTamanho() + 2;
                //if (dados.getTipoDado() == TipoDado.String) tamRegistro++;
            }

            //lê cada registro
            while (br.BaseStream.Position != br.BaseStream.Length)
            {
                RegistroTabela r = new RegistroTabela(br.BaseStream.Position);
                count = br.ReadInt32();
                bool insere = true;
                //Lê cada dado dentro do registro
                for (int i = 0; i < count && insere; i++)
                {
                    DadoTabela d;
                    //Form1.addMensagem(i.ToString());

                    // *** erro aqui - inicio ***
                    // select localidade.* from localidade where localidade.cd_localidade = 1;
                    // da erro qdo i = 4
                    // mas quem deve limitar para nao chegar no 4 ?

                    string nomeColuna = meta.getNomesColunas()[i];
                    // *** erro aqui - Fim ***

                    TipoDado tipo  = meta.getDados()[nomeColuna].getTipoDado();
                    string   campo = meta.getNome() + "." + nomeColuna;
                    Filtro   f     = filtrosAND.ContainsKey(campo) ? filtrosAND[campo] : null;
                    if (tipo == TipoDado.Inteiro)
                    {
                        d = new DadoTabela(nomeColuna, tipo, br.ReadByte(), br.ReadBoolean(), br.ReadInt32());
                        if (f != null)
                        {
                            switch (f.Op)
                            {
                            case OperadorRel.Igual:
                                if (f.RValue.ToLower().Equals("null"))
                                {
                                    if (d.isValido)
                                    {
                                        insere = false;
                                    }
                                }
                                else
                                {
                                    if (d.getValorInt() != Convert.ToInt32(f.RValue))
                                    {
                                        insere = false;
                                    }
                                }
                                break;

                            case OperadorRel.MaiorQue:
                                if (d.getValorInt() <= Convert.ToInt32(f.RValue))
                                {
                                    insere = false;
                                }
                                break;

                            case OperadorRel.MenorQue:
                                if (d.getValorInt() >= Convert.ToInt32(f.RValue))
                                {
                                    insere = false;
                                }
                                break;

                            case OperadorRel.MaiorIgualA:
                                if (d.getValorInt() < Convert.ToInt32(f.RValue))
                                {
                                    insere = false;
                                }
                                break;

                            case OperadorRel.MenorIgualA:
                                if (d.getValorInt() > Convert.ToInt32(f.RValue))
                                {
                                    insere = false;
                                }
                                break;

                            case OperadorRel.Diferente:
                                if (f.RValue.ToLower().Equals("null"))
                                {
                                    if (!d.isValido)
                                    {
                                        insere = false;
                                    }
                                }
                                else
                                {
                                    if (d.getValorInt() == Convert.ToInt32(f.RValue))
                                    {
                                        insere = false;
                                    }
                                }
                                break;

                            default:
                                throw new SGDBException("Passou onde nao devia: GambiarraSelect.retornaDados.Inteiro.Default.");
                            }
                        }
                    }
                    else
                    {
                        byte   tamanho  = br.ReadByte();
                        bool   isValido = br.ReadBoolean();
                        byte[] valor    = br.ReadBytes(tamanho);
                        string texto    = new System.Text.ASCIIEncoding().GetString(valor);
                        d = new DadoTabela(nomeColuna, tipo, tamanho, isValido, texto);
                        if (f != null)
                        {
                            switch (f.Op)
                            {
                            case OperadorRel.Igual:
                                if (f.RValue.ToLower().Equals("null"))
                                {
                                    if (d.isValido)
                                    {
                                        insere = false;
                                    }
                                }
                                else
                                {
                                    byte[] filtro = new byte[d.tamanho];
                                    new System.Text.ASCIIEncoding().GetBytes(f.RValue.PadRight(d.tamanho)).CopyTo(filtro, 0);
                                    string filtro2 = new System.Text.ASCIIEncoding().GetString(filtro);
                                    if (!texto.Equals(filtro2))
                                    {
                                        insere = false;
                                    }
                                }
                                break;

                            case OperadorRel.Diferente:
                                if (f.RValue.ToLower().Equals("null"))
                                {
                                    if (!d.isValido)
                                    {
                                        insere = false;
                                    }
                                }
                                else
                                {
                                    byte[] filtro = new byte[d.tamanho];
                                    new System.Text.ASCIIEncoding().GetBytes(f.RValue.PadRight(d.tamanho)).CopyTo(filtro, 0);
                                    string filtro2 = new System.Text.ASCIIEncoding().GetString(filtro);
                                    if (texto.Equals(filtro2))
                                    {
                                        insere = false;
                                    }
                                }
                                break;

                            default:
                                throw new SemanticError("Comparação de literais só pode ser igual ou diferente");
                            }
                        }
                    }

                    r.dados.Add(d);
                }

                if (insere)
                {
                    td.registros.Add(r);
                }

                if (br.BaseStream.Position % tamRegistro != 0)
                {
                    br.BaseStream.Position += tamRegistro - (br.BaseStream.Position % tamRegistro);
                }
            }

            return(TabelaSelect.getTabelaSelect(td));
        }
예제 #18
0
        public TabelaSelect returnDados(Metadados tabela)
        {
            try { Base.getInstance().desalocarBinarios(tabela.getNome()); } catch { }
            TabelaSelect ts   = null;
            FileStream   file = null;
            BinaryReader br   = null;

            try
            {
                string arquivo = mem.getPath() + "\\" + tabela.getNome() + ".dat";
                file = new FileStream(arquivo, FileMode.Open);
                using (br = new BinaryReader(file))
                {
                    int count;
                    ts = new TabelaSelect();

                    Metadados meta    = GerenciadorMemoria.getInstance().recuperarMetadados(tabela.getNome());
                    int       colunas = meta.getNomesColunas().Count;
                    ts.Campos = new string[colunas];
                    for (int i = 0; i < colunas; i++)
                    {
                        ts.Campos[i] = meta.getNome() + "." + meta.getNomesColunas()[i];
                    }

                    //lê cada registro
                    while (br.BaseStream.Position != br.BaseStream.Length)
                    {
                        string[]       registro = new string[colunas];
                        RegistroTabela r        = new RegistroTabela(br.ReadInt64());
                        count = br.ReadInt32();
                        //Lê cada dado dentro do registro
                        for (int i = 0; i < count; i++)
                        {
                            string   nomeColuna = meta.getNomesColunas()[i];
                            TipoDado tipo       = meta.getDados()[nomeColuna].getTipoDado();
                            string   valor      = "";
                            if (tipo == TipoDado.Inteiro)
                            {
                                byte tamanho  = br.ReadByte();
                                bool isValido = br.ReadBoolean();
                                int  numero   = br.ReadInt32();
                                valor = isValido ? numero + "" : "NULL";
                            }
                            else
                            {
                                byte   tamanho  = br.ReadByte();
                                bool   isValido = br.ReadBoolean();
                                byte[] literal  = br.ReadBytes(tamanho);
                                string texto    = new System.Text.ASCIIEncoding().GetString(literal);
                                valor = isValido ? texto : "NULL";
                            }

                            registro[i] = valor;
                        }

                        ts.Registros.Add(registro);
                        if (ts.Registros.Count >= Base.getInstance().qtd_max_registros)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.ReadLine();
            }
            finally
            {
                if (br != null)
                {
                    br.Close();
                }
                if (file != null)
                {
                    file.Close();
                }
            }

            return(ts);
        }
예제 #19
0
        public TabelaSelect returnDados(List <Filtro> filtrosAND, Dictionary <string, List <string> > filtrosJoin, Metadados tabela)
        {
            try { Base.getInstance().desalocarBinarios(tabela.getNome()); } catch { }
            TabelaSelect ts   = null;
            FileStream   file = null;
            BinaryReader br   = null;

            try
            {
                string arquivo = mem.getPath() + "\\" + tabela.getNome() + ".dat";
                file = new FileStream(arquivo, FileMode.Open);
                using (br = new BinaryReader(file))
                {
                    int count;
                    ts = new TabelaSelect();

                    Metadados meta    = GerenciadorMemoria.getInstance().recuperarMetadados(tabela.getNome());
                    int       colunas = meta.getNomesColunas().Count;
                    ts.Campos = new string[colunas];
                    for (int i = 0; i < colunas; i++)
                    {
                        ts.Campos[i] = meta.getNome() + "." + meta.getNomesColunas()[i];
                    }

                    //calcula o tamanho de cada registro
                    int tamRegistro = 12;
                    int posPrimary  = 0;//posicao do primary key no registro
                    foreach (DadosTabela dados in meta.getDados().Values)
                    {
                        if (dados.isPrimary())
                        {
                            posPrimary = tamRegistro + 2;
                        }
                        tamRegistro += dados.getTamanho() + 2;
                    }

                    long posMax = br.BaseStream.Length; //posicao máxima para leitura do arquivo
                    //organiza os filtros por coluna
                    List <Filtro>[] filtrosCampo = new List <Filtro> [colunas];
                    for (int i = 0; i < colunas; i++)
                    {
                        ts.Campos[i]    = meta.getNome() + "." + meta.getNomesColunas()[i];
                        filtrosCampo[i] = new List <Filtro>();
                        foreach (Filtro f in filtrosAND)
                        {
                            if (f.LValue.Equals(ts.Campos[i]))
                            {
                                filtrosCampo[i].Add(f);
                            }
                        }
                        if (filtrosJoin.ContainsKey(ts.Campos[i]))
                        {
                            posMax = posicionaPonteiroArquivo(filtrosJoin[ts.Campos[i]], br, tamRegistro, posPrimary);
                        }
                        //se o campo for PrimaryKey organiza o filtro
                        else if (filtrosCampo[i].Count > 0 && meta.getDados()[meta.getNomesColunas()[i]].isPrimary())
                        {
                            ordenaFiltros(filtrosCampo[i]);
                            //define o intervalo de consulta do arquivo caso exista filtro de chave primaria
                            posMax = posicionaPonteiroArquivo(filtrosCampo[i], br, tamRegistro, posPrimary);
                        }
                    }

                    //lê cada registro
                    while (br.BaseStream.Position < posMax)
                    {
                        string[] registro = new string[colunas];
                        long     posicao  = br.ReadInt64();
                        count = br.ReadInt32();
                        bool insere = true;
                        //Lê cada dado dentro do registro
                        for (int i = 0; i < count && insere; i++)
                        {
                            string   nomeColuna = meta.getNomesColunas()[i];
                            TipoDado tipo       = meta.getDados()[nomeColuna].getTipoDado();
                            bool     isPrimary  = meta.getDados()[nomeColuna].isPrimary();
                            string   valor      = "";
                            string   campo      = meta.getNome() + "." + nomeColuna;

                            if (tipo == TipoDado.Inteiro)
                            {
                                byte tamanho  = br.ReadByte();
                                bool isValido = br.ReadBoolean();
                                int  numero   = br.ReadInt32();
                                valor = isValido ? numero + "" : "NULL";
                                foreach (Filtro f in filtrosCampo[i])
                                {
                                    switch (f.Op)
                                    {
                                    case OperadorRel.Igual:
                                        if (f.RValue.ToLower().Equals("null"))
                                        {
                                            if (isValido)
                                            {
                                                insere = false;
                                            }
                                        }
                                        else
                                        {
                                            if (numero != Convert.ToInt32(f.RValue))
                                            {
                                                insere = false;
                                            }
                                        }
                                        break;

                                    case OperadorRel.MaiorQue:
                                        if (numero <= Convert.ToInt32(f.RValue))
                                        {
                                            insere = false;
                                        }
                                        break;

                                    case OperadorRel.MenorQue:
                                        if (numero >= Convert.ToInt32(f.RValue))
                                        {
                                            insere = false;
                                        }
                                        break;

                                    case OperadorRel.MaiorIgualA:
                                        if (numero < Convert.ToInt32(f.RValue))
                                        {
                                            insere = false;
                                        }
                                        break;

                                    case OperadorRel.MenorIgualA:
                                        if (numero > Convert.ToInt32(f.RValue))
                                        {
                                            insere = false;
                                        }
                                        break;

                                    case OperadorRel.Diferente:
                                        if (f.RValue.ToLower().Equals("null"))
                                        {
                                            if (!isValido)
                                            {
                                                insere = false;
                                            }
                                        }
                                        else
                                        {
                                            if (numero == Convert.ToInt32(f.RValue))
                                            {
                                                insere = false;
                                            }
                                        }
                                        break;

                                    default:
                                        throw new SGDBException("Passou onde nao devia: GambiarraSelect.retornaDados.Inteiro.Default.");
                                    }
                                }
                                if (insere && filtrosJoin.ContainsKey(campo))
                                {
                                    insere = filtrosJoin[campo].Exists(s => s.Equals(valor));
                                }
                            }
                            else
                            {
                                byte   tamanho  = br.ReadByte();
                                bool   isValido = br.ReadBoolean();
                                byte[] literal  = br.ReadBytes(tamanho);
                                string texto    = new System.Text.ASCIIEncoding().GetString(literal);
                                valor = isValido ? texto.TrimEnd() : "NULL";
                                foreach (Filtro f in filtrosCampo[i])
                                {
                                    switch (f.Op)
                                    {
                                    case OperadorRel.Igual:
                                        if (f.RValue.ToLower().Equals("null"))
                                        {
                                            if (isValido)
                                            {
                                                insere = false;
                                            }
                                        }
                                        else
                                        {
                                            byte[] filtro = new byte[tamanho];
                                            new System.Text.ASCIIEncoding().GetBytes(f.RValue.PadRight(tamanho)).CopyTo(filtro, 0);
                                            string filtro2 = new System.Text.ASCIIEncoding().GetString(filtro).TrimEnd();
                                            if (!valor.Equals(filtro2))
                                            {
                                                insere = false;
                                            }
                                        }
                                        break;

                                    case OperadorRel.Diferente:
                                        if (f.RValue.ToLower().Equals("null"))
                                        {
                                            if (isValido)
                                            {
                                                insere = false;
                                            }
                                        }
                                        else
                                        {
                                            byte[] filtro = new byte[tamanho];
                                            new System.Text.ASCIIEncoding().GetBytes(f.RValue.PadRight(tamanho)).CopyTo(filtro, 0);
                                            string filtro2 = new System.Text.ASCIIEncoding().GetString(filtro).TrimEnd();
                                            if (valor.Equals(filtro2))
                                            {
                                                insere = false;
                                            }
                                        }
                                        break;

                                    default:
                                        throw new SemanticError("Comparação de literais só pode ser igual ou diferente");
                                    }
                                }
                                if (insere && filtrosJoin.ContainsKey(campo))
                                {
                                    insere = filtrosJoin[campo].Exists(s => s.Equals(valor));
                                }
                            }

                            registro[i] = valor;
                        }

                        if (insere)
                        {
                            ts.Registros.Add(registro);
                            if (ts.Registros.Count >= Base.getInstance().qtd_max_registros)
                            {
                                break;
                            }
                        }

                        if (br.BaseStream.Position % tamRegistro != 0)
                        {
                            br.BaseStream.Position += tamRegistro - (br.BaseStream.Position % tamRegistro);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.ReadLine();
            }
            finally
            {
                if (br != null)
                {
                    br.Close();
                }
                if (file != null)
                {
                    file.Close();
                }
            }
            return(ts);
        }
예제 #20
0
 public Operacao(TipoOperacao o, Grafo.Vertice v)
 {
     tipoOperacao = o;
     tipoDado     = TipoDado.Vertice;
     vertice      = v;
 }