Exemplo n.º 1
0
        public void IntegraEstoque()
        {
            ProcessForm processForm = new ProcessForm("", layout);
            processForm.Show();
            List<Estoque> lEstoque = new List<Estoque>();
            IEnumerable<String> streamRead = File.ReadLines(System.Environment.CurrentDirectory.ToString() + "\\config.txt");
            var connection = streamRead.First();
            using (OleDbConnection con = new OleDbConnection(connection))
            {
                try
                {
                    con.Open();
                    using (OleDbCommand commandCount = new OleDbCommand("SELECT COUNT(*) FROM ESTOQUE ", con))
                    using (OleDbDataReader readerCount = commandCount.ExecuteReader())
                    {
                        while (readerCount.Read())
                        {

                            countRegister = readerCount.GetValue(0).ToString();

                        }
                    }
                    try
                    {

                        using (OleDbCommand command = new OleDbCommand("SELECT SKU_PRODUTO,ID_DISTRIBUIDOR,QUANTIDADE_ATUAL_ESTOQUE,QUANTIDADE_ULTIMA_COMPRA,QUANTIDADE_ULTIMA_VENDA,DATA_PRIMEIRA_COMPRA,DATA_ULTIMA_COMPRA,DATA_ULTIMA_VENDA,VALOR_CUSTO_UNITARIO_ESTOQUE,VALOR_CUSTO_TOTAL_ESTOQUE FROM ESTOQUE", con))
                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Estoque estoque = new Estoque();
                                Validator valid = new Validator();

                                estoque.produtoId = reader.GetString(0);
                                estoque.distribuidorId = reader.GetString(1);
                                estoque.quantidadeAtualEstoque = reader.GetString(2);
                                estoque.quantidadeUltimaCompra = reader.GetString(3);
                                estoque.quantidadeUltimaVenda = reader.GetString(4);

                                if (reader.IsDBNull(5))
                                {
                                    estoque.dataPrimeiraCompra = valid.ValidaString();
                                }
                                else
                                {
                                    estoque.dataPrimeiraCompra = (reader.GetString(5));
                                }

                                if (reader.IsDBNull(6))
                                {
                                    estoque.dataUltimaCompra = valid.ValidaString();
                                }
                                else
                                {
                                    estoque.dataUltimaCompra = (reader.GetString(6));
                                }

                                if (reader.IsDBNull(7))
                                {
                                    estoque.dataUltimaVenda = valid.ValidaString();
                                }
                                else
                                {
                                    estoque.dataUltimaVenda = (reader.GetString(7));
                                }

                                estoque.valorCustoUnitarioEstoque = reader.GetString(8);
                                estoque.valorCustoTotalEstoque = reader.GetString(9);

                                PostEstoque(estoque);

                                string msg = "Foram inseridos: " + lEstoque.Count().ToString() + " de " + countRegister + " registros";
                                processForm.writeMessage(msg);
                                processForm.Enabled = false;
                                processForm.Enabled = true;

                                lEstoque.Add(estoque);
                            }
                        }

                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        logErro.EscreverLog(layout, ex.Message.ToString());
                        //MessageBox.Show(ex.Message.ToString(), "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                }
                catch (Exception ex)
                {
                    logErro.EscreverLog(layout, ex.Message.ToString());
                    //MessageBox.Show(ex.Message.ToString(), "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                int countWrite = lEstoque.Count();
                //MessageBox.Show("Foram inseridos "+countWrite.ToString()+" registros", "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                processForm.Close();
            }
        }
Exemplo n.º 2
0
        public void IntegraFaturamento()
        {
            ProcessForm processForm = new ProcessForm("", layout);
            processForm.Show();
            List<Faturamento> lFaturamento = new List<Faturamento>();

            IEnumerable<String> streamRead = File.ReadLines(System.Environment.CurrentDirectory.ToString() + "\\config.txt");
            var connection = streamRead.First();

            using (OleDbConnection con = new OleDbConnection(connection))
            {
                try
                {
                    con.Open();

                    using (OleDbCommand commandCount = new OleDbCommand("SELECT COUNT(*) FROM FATURAMENTO ", con))
                    using (OleDbDataReader readerCount = commandCount.ExecuteReader())
                    {
                        while (readerCount.Read())
                        {

                            countRegister = readerCount.GetValue(0).ToString();

                        }
                    }

                    try
                    {
                        using (OleDbCommand command = new OleDbCommand("SELECT SKU_PRODUTO,ID_CLIENTE,ID_DISTRIBUIDOR,ID_FV,ID_FORMA_PAGAMENTO,ID_END_ENTREGA,ID_END_COBRANCA,QTD_ITEM_NF_FATURA,VALOR_UNITARIO_ITEM_NF_FATURA,VALOR_TOTAL_NF_FATURA,VALOR_BRUTO_ITEM_NF_FATURA,VALOR_DESCONTO_ITEM_NF_FATURA,VALOR_TOTAL_ITEM_NF_FATURA,VALOR_LIQUIDO_ITEM_NF_FATURA,VALOR_CUSTO_ITEM_NF_FATURA,QTD_LITROS_ITEM_NF_FATURA,NUM_NF_FATURA,SERIE_NF_FATURA,ITEM_NF_FATURA,CFOP_NF_FATURA,NATUREZA_OPERACAO_NF_FATURA,OBSERVACAO_NF_FATURA,DATA_NF_FATURA,FLAG_ITEM_CANCELADO,DATA_CANCELAMENTO,QUANTIDADE_CANCELADO,VALOR_FRETE_NF,VALOR_IPI_ITEM,VALOR_PIS_ITEM,VALOR_COFINS_ITEM,VALOR_ICMS_ITEM,VALOR_ICMS_ST_ITEM,VALOR_SEGURO_ITEM,VALOR_DESPESAS_EXTRA_ITEM,FLAG_FATURAMENTO_TP_ENTREGA FROM FATURAMENTO", con))
                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Faturamento faturamento = new Faturamento();
                                Validator valid = new Validator();
                                for(int i = reader.FieldCount-1; i>=0; i--){
                                    if (!(i == 34 || i == 33 || i == 32 || i == 25 || i == 24 || i == 21))
                                    {
                                        if (reader.IsDBNull(i))
                                        {
                                            MessageBox.Show(i.ToString(), "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }

                                }

                                faturamento.produtoId = reader.GetValue(0).ToString();
                                faturamento.clienteId = reader.GetString(1);
                                faturamento.distribuidorId = reader.GetString(2);
                                faturamento.forcaDeVendaId = reader.GetString(3);
                                faturamento.formaDePagamentoId = reader.GetString(4);
                                faturamento.enderecoEntregaId = reader.GetString(5);
                                faturamento.enderecoCobrancaId = reader.GetString(6);
                                faturamento.quantidadeItem = reader.GetString(7);
                                faturamento.valorUnitarioItem = reader.GetString(8);
                                faturamento.valorTotalFatura = reader.GetString(9);
                                faturamento.valorBrutoItem = reader.GetString(10);
                                faturamento.valorDescontoItem = reader.GetString(11);
                                faturamento.valorTotalItem = reader.GetString(12);
                                faturamento.valorLiquidoItem = reader.GetString(13);
                                faturamento.valorCustoItem = reader.GetString(14);
                                faturamento.quantidadeLitrosItem = reader.GetString(15);
                                faturamento.numeroFatura = reader.GetString(16);
                                faturamento.serieFatura = reader.GetString(17);
                                faturamento.itemFatura = reader.GetString(18);
                                faturamento.CFOP = reader.GetString(19);
                                faturamento.naturezaOpercao = reader.GetString(20);

                                if(reader.IsDBNull(21))
                                {
                                    faturamento.observacaoFatura = valid.ValidaString();

                                }else{
                                    faturamento.observacaoFatura = reader.GetString(21);
                                }

                                faturamento.dataFatura = reader.GetString(22);
                                faturamento.flagItemCancelado = (reader.GetString(23));
                                if (reader.IsDBNull(24))
                                {
                                    faturamento.dataItemCancelado = valid.ValidaString();

                                }
                                else
                                {
                                    faturamento.dataItemCancelado = reader.GetString(24);
                                }

                                if (reader.IsDBNull(25))
                                {
                                    faturamento.quantidadeItemCancelado = valid.ValidaString();

                                }
                                else
                                {
                                    faturamento.quantidadeItemCancelado = reader.GetString(25);
                                }

                                faturamento.valorFrete = reader.GetString(26);
                                faturamento.valorIpi = reader.GetString(27);
                                faturamento.valorPis = reader.GetString(28);
                                faturamento.valorConfins = reader.GetString(29);
                                faturamento.valorIcms = reader.GetString(30);
                                faturamento.valorIcmsSt = reader.GetString(31);
                                if (reader.IsDBNull(32))
                                {
                                    faturamento.valorSeguro = valid.ValidaString();

                                }
                                else
                                {
                                    faturamento.valorSeguro = (reader.GetValue(32).ToString());
                                }

                                if (reader.IsDBNull(33))
                                {
                                    faturamento.valorDespesaExtra = valid.ValidaString();

                                }
                                else
                                {
                                    faturamento.valorDespesaExtra = reader.GetString(33);
                                }

                                if (reader.IsDBNull(34))
                                {
                                    faturamento.flagTipoEntrega = valid.ValidaString();

                                }
                                else
                                {
                                    faturamento.flagTipoEntrega = reader.GetString(34);
                                }

                                PostFaturamento(faturamento);

                                string msg = "Foram inseridos: " + lFaturamento.Count().ToString() + " de " + countRegister + " registros";
                                processForm.writeMessage(msg);
                                processForm.Enabled = false;
                                processForm.Enabled = true;

                                lFaturamento.Add(faturamento);

                            }
                        }
                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        logErro.EscreverLog(layout, ex.Message.ToString());
                        //MessageBox.Show(ex.Message.ToString(), "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                }
                catch (Exception ex)
                {
                    logErro.EscreverLog(layout, ex.Message.ToString());
                    //MessageBox.Show(ex.Message.ToString(), "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

                int countWrite = lFaturamento.Count();
                //MessageBox.Show("Foram inseridos "+countWrite.ToString()+" registros", "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                processForm.Close();
        }
Exemplo n.º 3
0
        public int IntegraCliente()
        {
            ProcessForm processForm = new ProcessForm("", layout);
            processForm.Show();

            List<Cliente> lCliente = new List<Cliente>();

            IEnumerable<String> streamRead = File.ReadLines(System.Environment.CurrentDirectory.ToString()+"\\config.txt");
            var connection = streamRead.First();
            int index = 0;
            using (OleDbConnection con = new OleDbConnection(connection))
            {
                try
                {
                    con.Open();

                        using (OleDbCommand commandCount = new OleDbCommand("SELECT COUNT(*) FROM CLIENTES ", con))
                        using (OleDbDataReader readerCount = commandCount.ExecuteReader())
                        {
                            while (readerCount.Read())
                            {

                                countRegister = readerCount.GetValue(0).ToString();

                            }
                        }

                        try
                        {

                        using (OleDbCommand command = new OleDbCommand("SELECT ID_CLIENTE,ID_DISTRIBUIDOR,RAZAO_SOCIAL_CLIENTE,NOME_FANTASIA_CLIENTE,CNPJ_CPF_CLIENTE,COD_MUNICIPIO_IBGE_MATRIZ,RUA_END_MATRIZ_CLIENTE,NUMERO_END_MATRIZ_CLIENTE,COMPLEMENTO_END_MATRIZ_CLIENTE,CEP_END_MATRIZ_CLIENTE,BAIRRO_END_MATRIZ_CLIENTE,MUNICIPIO_END_MATRIZ_CLIENTE,UF_END_MATRIZ_CLIENTE,TEL_END_MATRIZ_CLIENTE,EMAIL_END_MATRIZ_CLIENTE,PESSOA_CONTATO,RAMO_NEGOCIO_CLIENTE,SUB_RAMO_NEGOCIO_CLIENTE,CURVA_ABC_CLIENTE,STATUS_FINANCEIRO_CLIENTE,DATA_CADASTRO_CLIENTE,DATA_DESATIVACAO_CLIENTE,FLAG_ATIVO_CLIENTE,GRUPO_ECONOMICO_CLIENTE FROM CLIENTES ", con))
                        using (OleDbDataReader reader = command.ExecuteReader())
                        {

                            while (reader.Read())
                            {
                                Cliente cliente = new Cliente();
                                Validator valid = new Validator();

                                cliente.id = reader.GetString(0);
                                cliente.distribuidorId = reader.GetString(1);
                                cliente.razaoSocial = reader.GetString(2);
                                cliente.nomeFantasia = reader.GetString(3);
                                cliente.cnpjCpf = reader.GetString(4);
                                if (reader.IsDBNull(5))
                                {
                                    cliente.codigoMunicipio = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.codigoMunicipio = reader.GetString(5);
                                }
                                //cliente.codigoMunicipio = reader.GetString(5);

                                if (reader.IsDBNull(6))
                                {
                                    cliente.enderecoLogradouro = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.enderecoLogradouro = reader.GetString(6);
                                }
                                //cliente.enderecoLogradouro = reader.GetString(6);
                                if (reader.IsDBNull(7))
                                {
                                    cliente.enderecoNumero = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.enderecoNumero = reader.GetString(7);
                                }
                                //cliente.enderecoNumero = reader.GetString(7);

                                if (reader.IsDBNull(8))
                                {
                                    cliente.enderecoComplemento = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.enderecoComplemento = reader.GetString(8);
                                }
                                //cliente.enderecoComplemento = reader.GetString(8);

                                if (reader.IsDBNull(9))
                                {
                                    cliente.enderecoCep = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.enderecoCep = reader.GetString(9);
                                }
                                //cliente.enderecoCep = reader.GetString(9);
                                if (reader.IsDBNull(10))
                                {
                                    cliente.enderecoBairro = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.enderecoBairro = reader.GetString(10);
                                }
                                //cliente.enderecoBairro = reader.GetString(10);
                                if (reader.IsDBNull(11))
                                {
                                    cliente.enderecoMunicipio = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.enderecoMunicipio = reader.GetString(11);
                                }
                                //cliente.enderecoMunicipio = reader.GetString(11);
                                if (reader.IsDBNull(12))
                                {
                                    cliente.enderecoEstado = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.enderecoEstado = reader.GetString(12);
                                }
                                //cliente.enderecoEstado = reader.GetString(12);
                                if (reader.IsDBNull(13))
                                {
                                    cliente.telefone = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.telefone = reader.GetString(13);
                                }
                                //cliente.telefone = reader.GetString(13);

                                if (reader.IsDBNull(14))
                                {
                                    cliente.email = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.email = reader.GetString(14);
                                }

                                //cliente.email = reader.GetString(14);

                                if (reader.IsDBNull(15))
                                {
                                    cliente.pessoaContato = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.pessoaContato = reader.GetString(15);
                                }

                                //cliente.pessoaContato = reader.GetString(15);

                                if (reader.IsDBNull(16))
                                {
                                    cliente.ramoNegocio = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.ramoNegocio = reader.GetString(16);
                                }
                                //cliente.ramoNegocio = reader.GetString(16);

                                if (reader.IsDBNull(17))
                                {
                                    cliente.subRamoNegocio = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.subRamoNegocio = reader.GetString(17);
                                }
                                //cliente.subRamoNegocio = reader.GetString(17);

                                if (reader.IsDBNull(18))
                                {
                                   cliente.curvaABC = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.curvaABC = reader.GetString(18);
                                }

                                if (reader.IsDBNull(19)||reader.GetValue(19).ToString()=="")
                                {
                                   cliente.statusFinanceiro = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.statusFinanceiro = reader.GetString(19);
                                }

                                if ((reader.IsDBNull(20) || (reader.GetValue(20).ToString() == "") || (reader.GetValue(20) == null)))
                                {
                                    cliente.dataCadastro = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.dataCadastro = (reader.GetValue(20).ToString());
                                }

                                if ((reader.IsDBNull(21)) || (reader.GetValue(21).ToString() == "") || (reader.GetValue(21)==null))
                                {
                                    cliente.dataDesativacao = valid.ValidaString();

                                }
                                else
                                {
                                    try
                                    {
                                        cliente.dataDesativacao = reader.GetString(20);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.Message.ToString(), "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                }

                                //cliente.ativo = (reader.GetString(22));
                                if ((reader.IsDBNull(22) || (reader.GetValue(22).ToString() == "") || (reader.GetValue(22) == null)))
                                {
                                    cliente.ativo = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.ativo = reader.GetString(22);
                                }

                                if  ((reader.IsDBNull(23) || (reader.GetValue(23).ToString() == "") || (reader.GetValue(23) == null)))
                                {
                                    cliente.grupoEconomico = valid.ValidaString();
                                }
                                else
                                {
                                    cliente.grupoEconomico = reader.GetString(23);
                                }

                                PostCliente(cliente);

                                string msg = "Foram inseridos: " + lCliente.Count().ToString() +" de "+countRegister+" registros";
                                processForm.writeMessage(msg);
                                processForm.Enabled = false;
                                processForm.Enabled = true;

                                lCliente.Add(cliente);
                                index++;
                            }
                        }

                        con.Dispose();
                        //MessageBox.Show("Advetisament","Fim da execução de cliente",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);

                    }

                    catch (Exception ex)
                    {
                        logErro.EscreverLog(layout, ex.Message.ToString()+ex.ToString());
                        //MessageBox.Show(ex.Message.ToString(), "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message.ToString(), "Falha ao abrir a conexao", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    logErro.EscreverLog(layout, ex.Message.ToString());
                }

                int countWrite = lCliente.Count();
                //MessageBox.Show("Foram inseridos " + countWrite.ToString() + " registros", "Advetisament", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                processForm.Close();
                return index;

            }
        }