Esempio n. 1
0
        private void ImportaDados(String transacaoPedido, DateTime dataFiltro)
        {
            var transacaoPedidoRb = setAndGetSequence();

            //Set the main header.
            Cabecalho cabecalho = new Cabecalho();

            cabecalho.dateImport = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            cabecalho.dateFech   = dataFiltro.ToString("yyyy-MM-dd");

            cabecalho.transRequest = transacaoPedido;
            cabecalho.importSeq    = transacaoPedidoRb;
            cabecalho.status       = "N";


            String codVendedorAtualPR = BancoPadaria.obterCodigoVendedor(transacaoPedido);

            var relacaoVendedores = BancoFechamento.getVendedores();

            String codVendedorFrassini = relacaoVendedores[codVendedorAtualPR];

            VerificaFechamento(codVendedorFrassini, cabecalho.dateFech);

            cabecalho.vendCod = codVendedorFrassini;

            var detalhesGeral = carregarDadosPadaria(transacaoPedido, dataFiltro);

            setProdCodFrass(ref detalhesGeral);

            //var produtosFechamento = setDet(detalhesGeral, transacaoPedido);

            String manifestoFr = "";

            carregarDadosFrassini(transacaoPedido, dataFiltro, detalhesGeral, cabecalho.vendCod, out manifestoFr);
            cabecalho.transManifest = manifestoFr;


            var comuns = detalhesGeral.Where(t => t.prodCodigo > 0 && t.prodCodigoRB > 0);

            setTableDets(detalhesGeral, cabecalho);
        }
Esempio n. 2
0
        public void setTableDets(List <Det> detalhesGeral, Cabecalho cabecalho)
        {
            var conn = new NpgsqlConnection(ConfigurationManager.AppSettings["ConexaoFch"]);


            conn.Open();
            var transaction = conn.BeginTransaction();


            try
            {
                /*String sql = " INSERT INTO fechamento(fech_transacao, fech_vend_codigo, fech_status, fech_data_fechamento," +
                 *           " fech_data_import, fech_manifesto, fech_pr_transpedido )" +
                 *          $" VALUES ('{cabecalho.importSeq}', '{cabecalho.vendCod}', '{cabecalho.status}', '{cabecalho.dateFech}'," +
                 *          $" '{cabecalho.dateImport}', '{cabecalho.transManifest}', '{cabecalho.transRequest}')";*/


                String sql = " INSERT INTO fechamento(fech_transacao, fech_vend_codigo, fech_status, fech_data_fechamento," +
                             " fech_data_import, fech_manifesto, fech_pr_transpedido )" +
                             $" VALUES (:fech_transacao, :fech_vend_codigo, :fech_status, :fech_data_fechamento, " +
                             $" :fech_data_import, :fech_manifesto, :fech_pr_transpedido )";

                var cmd = new NpgsqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("fech_transacao", cabecalho.importSeq);
                cmd.Parameters.AddWithValue("fech_vend_codigo", cabecalho.vendCod);
                cmd.Parameters.AddWithValue("fech_status", cabecalho.status);
                cmd.Parameters.AddWithValue("fech_data_fechamento", new DateTimeConverter().ConvertFromString(cabecalho.dateFech));
                cmd.Parameters.AddWithValue("fech_data_import", new DateTimeConverter().ConvertFromString(cabecalho.dateImport));
                cmd.Parameters.AddWithValue("fech_manifesto", cabecalho.transManifest);
                cmd.Parameters.AddWithValue("fech_pr_transpedido", cabecalho.transRequest);


                int linhasInseridas = cmd.ExecuteNonQuery();

                for (int i = 0; i < detalhesGeral.Count; i++)
                {
                    /*sql = " INSERT INTO fechamentodet1220(fchd_transacao, fchd_prod_codigo, fchd_qtde_carga, fchd_pr_qtde_venda, fchd_pr_qtde_troca, fchd_pr_qtde_retorno, " +
                     *           "fchd_fr_qtde_venda, fchd_fr_qtde_troca, fchd_fr_qtde_retorno, fchd_pr_valorprod, fchd_pr_valortotal, fchd_pr_valorcomissao )" +
                     *          $" VALUES ('{cabecalho.importSeq}', '{detalhesGeral[i].prodCodigo}', '{detalhesGeral[i].qtdeCarga}', " +
                     *          $" '{detalhesGeral[i].prQtdeVenda}', '{detalhesGeral[i].prQtdeTroca}', '{detalhesGeral[i].prQtdeRetorno}', " +
                     *          $" '{detalhesGeral[i].fsQtdeVenda}', '{detalhesGeral[i].fsQtdeTroca}', 0, '{detalhesGeral[i].prValorProd}'," +
                     *          $" '{detalhesGeral[i].prValorTotal}', '{detalhesGeral[i].prComissao}')";*/


                    sql = " INSERT INTO fechamentodet1220(fchd_transacao, fchd_prod_codigo, fchd_qtde_carga, fchd_pr_qtde_venda, fchd_pr_qtde_troca, fchd_pr_qtde_retorno, " +
                          " fchd_fr_qtde_venda, fchd_fr_qtde_troca, fchd_fr_qtde_retorno, fchd_pr_valorprod, fchd_pr_valortotal, fchd_pr_valorcomissao )" +
                          $" VALUES (:fchd_transacao, :fchd_prod_codigo, :fchd_qtde_carga,:fchd_pr_qtde_venda, :fchd_pr_qtde_troca, :fchd_pr_qtde_retorno," +
                          $" :fchd_fr_qtde_venda, :fchd_fr_qtde_troca, :fchd_fr_qtde_retorno, :fchd_pr_valorprod, :fchd_pr_valortotal, :fchd_pr_valorcomissao)";

                    cmd = new NpgsqlCommand(sql, conn);

                    cmd.Parameters.AddWithValue("fchd_transacao", cabecalho.importSeq);
                    cmd.Parameters.AddWithValue("fchd_prod_codigo", detalhesGeral[i].prodCodigo);
                    cmd.Parameters.AddWithValue("fchd_qtde_carga", detalhesGeral[i].qtdeCarga);
                    cmd.Parameters.AddWithValue("fchd_pr_qtde_venda", detalhesGeral[i].prQtdeVenda);
                    cmd.Parameters.AddWithValue("fchd_pr_qtde_troca", detalhesGeral[i].prQtdeTroca);
                    cmd.Parameters.AddWithValue("fchd_pr_qtde_retorno", detalhesGeral[i].prQtdeRetorno);
                    cmd.Parameters.AddWithValue("fchd_fr_qtde_venda", detalhesGeral[i].fsQtdeVenda);
                    cmd.Parameters.AddWithValue("fchd_fr_qtde_troca", detalhesGeral[i].fsQtdeTroca);
                    cmd.Parameters.AddWithValue("fchd_fr_qtde_retorno", 0);
                    cmd.Parameters.AddWithValue("fchd_pr_valorprod", detalhesGeral[i].prValorProd);
                    cmd.Parameters.AddWithValue("fchd_pr_valortotal", detalhesGeral[i].prValorTotal);
                    cmd.Parameters.AddWithValue("fchd_pr_valorcomissao", detalhesGeral[i].prComissao);


                    linhasInseridas = cmd.ExecuteNonQuery();
                }
                transaction.Commit();
            }
            catch (Exception e)
            {
                transaction.Rollback();
                MessageBox.Show("Erro inesperado: " + e.Message.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            conn.Close();
        }