Exemplo n.º 1
0
        public void atualizar(
            dsFROGIOS.COMPRARow compra,
            dsFROGIOS.ITEM_COMPRADataTable itemCompra
            )
        {
            TblCompra compraSQL = new TblCompra();
                compraSQL.atualizar(compra);

                dsFROGIOS.ITEM_COMPRADataTable deletados = (dsFROGIOS.ITEM_COMPRADataTable)itemCompra.GetChanges(DataRowState.Deleted);
                dsFROGIOS.ITEM_COMPRADataTable inseridos = (dsFROGIOS.ITEM_COMPRADataTable)itemCompra.GetChanges(DataRowState.Added);
                TblItemCompra itemCompraSQL = new TblItemCompra();
                dsFROGIOS.ITEM_COMPRARow itemCompraLinha = itemCompra.NewITEM_COMPRARow();

                int linhasDeletadas = deletados.Rows.Count;
                for (int i = 0; i < linhasDeletadas; i++) {
                    itemCompraLinha.ITEM_COMPRA_CODIGO = (int)deletados.Rows[i][deletados.ITEM_COMPRA_CODIGOColumn, DataRowVersion.Original];
                    itemCompraSQL.deletar(itemCompraLinha);
                }

                itemCompraLinha.ITEM_COMPRA_COMPRA = (int)compra.COMPRA_CODIGO;

                int linhasInseridas = inseridos.Rows.Count;
                for (int i = 0; i < linhasInseridas; i++) {
                    itemCompraLinha.ITEM_COMPRA_QUANTIDADE = (short)inseridos.Rows[i][inseridos.ITEM_COMPRA_QUANTIDADEColumn, DataRowVersion.Current];
                    itemCompraLinha.ITEM_COMPRA_DESCONTO = (int)inseridos.Rows[i][inseridos.ITEM_COMPRA_DESCONTOColumn, DataRowVersion.Current];
                    itemCompraLinha.ITEM_COMPRA_PRECO = (int)inseridos.Rows[i][inseridos.ITEM_COMPRA_PRECOColumn, DataRowVersion.Current];
                    itemCompraLinha.ITEM_COMPRA_PRECO_TOTAL = (int)inseridos.Rows[i][inseridos.ITEM_COMPRA_PRECO_TOTALColumn, DataRowVersion.Current];
                    itemCompraLinha.ITEM_COMPRA_PRODUTO = (int)inseridos.Rows[i][inseridos.ITEM_COMPRA_PRODUTOColumn, DataRowVersion.Current];
                    itemCompraSQL.inserir(itemCompraLinha);
                }
        }
Exemplo n.º 2
0
        public void atualizar(
            dsFROGIOS.SERVICORow servico,
            dsFROGIOS.TIPODataTable tipos
            )
        {
            TblServico servicoSQL = new TblServico();
                servicoSQL.atualizar(servico);

                dsFROGIOS.TIPODataTable deletados = new dsFROGIOS.TIPODataTable();
                dsFROGIOS.TIPODataTable inseridos = new dsFROGIOS.TIPODataTable();

                /*
                 * Essa foi puta merda. Tava usando um método GetChanges da
                 * classe DataTable. Esse método já me retornava um DataTable
                 * todo arrumadinho já com as linhas novas ou excluidas. Mas
                 * por problemas de constraint, tive que adotar essa
                 * pequena solução manual. Funciona assim também :)
                 */
                //Mas sério XP

                //Aqui pegamos todas as linhas que foram inseridas ou excluidas
                //o que foi inserido vai ser inserido e o que foi excluido vai ser excluido do BD
                foreach (dsFROGIOS.TIPORow linha in tipos.Rows) {
                    if (linha.RowState == DataRowState.Added) {
                        inseridos.AddTIPORow(linha.TIPO_CODIGO, linha.TIPO_DESCRICAO);
                    } /*else if (linha.RowState == DataRowState.Deleted) {
                        deletados.AddTIPORow(linha.TIPO_CODIGO, linha.TIPO_DESCRICAO);
                    }*/
                }
                deletados = (dsFROGIOS.TIPODataTable)tipos.GetChanges(DataRowState.Deleted);

                TblServicoTipo servicoTipoSQL = new TblServicoTipo();

                dsFROGIOS.SERVICO_TIPODataTable servicoTipo =  new dsFROGIOS.SERVICO_TIPODataTable();
                dsFROGIOS.SERVICO_TIPORow servicoTipoLinha = servicoTipo.NewSERVICO_TIPORow();
                servicoTipoLinha.SERVICO_TIPO_SERVICO = servico.SERVICO_CODIGO;

                int linhasDeletadas = (deletados != null) ? deletados.Rows.Count : 0;
                for (int i = 0; i < linhasDeletadas; i++) {
                    servicoTipoLinha.SERVICO_TIPO_TIPO =
                        (int)deletados.Rows[i][deletados.TIPO_CODIGOColumn, DataRowVersion.Original];
                    servicoTipoSQL.deletar(servicoTipoLinha);
                }

                int linhasInseridas = (inseridos != null) ? inseridos.Rows.Count : 0;
                for (int i = 0; i < linhasInseridas; i++) {
                    servicoTipoLinha.SERVICO_TIPO_TIPO =
                        (int)inseridos.Rows[i][inseridos.TIPO_CODIGOColumn, DataRowVersion.Current];
                    servicoTipoSQL.inserir(servicoTipoLinha);
                }
        }
Exemplo n.º 3
0
        public void atualizar(
            dsFROGIOS.ORCAMENTORow orcamento,
            dsFROGIOS.ORCAMENTO_ITEMDataTable itens,
            dsFROGIOS.ORCAMENTO_SERVICODataTable servicos)
        {
            orcamentoSQL.atualizar(orcamento);

            dsFROGIOS.ORCAMENTO_ITEMDataTable itensDeletados = new dsFROGIOS.ORCAMENTO_ITEMDataTable();
            dsFROGIOS.ORCAMENTO_ITEMDataTable itensInseridos = new dsFROGIOS.ORCAMENTO_ITEMDataTable();
            dsFROGIOS.ORCAMENTO_ITEMDataTable itensAlterados = new dsFROGIOS.ORCAMENTO_ITEMDataTable();
            dsFROGIOS.ORCAMENTO_SERVICODataTable servicosDeletados = new dsFROGIOS.ORCAMENTO_SERVICODataTable();
            dsFROGIOS.ORCAMENTO_SERVICODataTable servicosInseridos = new dsFROGIOS.ORCAMENTO_SERVICODataTable();
            dsFROGIOS.ORCAMENTO_SERVICODataTable servicosAlterados = new dsFROGIOS.ORCAMENTO_SERVICODataTable();

            int contador = 0;
            foreach (dsFROGIOS.ORCAMENTO_ITEMRow item in itens) {
                if (item.RowState == DataRowState.Added) {
                    item.ORCAMENTO_ITEM_CODIGO = contador; contador++;
                    item.ORCAMENTO_ITEM_ORCAMENTO = orcamento.ORCAMENTO_CODIGO;
                    itensInseridos.ImportRow(item);
                }

                if (item.RowState == DataRowState.Modified) {
                    itensAlterados.ImportRow(item);
                }
            }
            itensDeletados = (dsFROGIOS.ORCAMENTO_ITEMDataTable)itens.GetChanges(DataRowState.Deleted);

            contador = 0;
            foreach (dsFROGIOS.ORCAMENTO_SERVICORow servico in servicos) {
                if (servico.RowState == DataRowState.Added) {
                    servico.ORCAMENTO_SERVICO_CODIGO = contador; contador++;
                    servico.ORCAMENTO_SERVICO_ORCAMENTO = orcamento.ORCAMENTO_CODIGO;
                    servicosInseridos.ImportRow(servico);
                }

                if (servico.RowState == DataRowState.Modified) {
                    servicosAlterados.ImportRow(servico);
                }

            }
            servicosDeletados = (dsFROGIOS.ORCAMENTO_SERVICODataTable)servicos.GetChanges(DataRowState.Deleted);

            dsFROGIOS.ORCAMENTO_ITEMRow itemTmp = itens.NewORCAMENTO_ITEMRow();
            dsFROGIOS.ORCAMENTO_SERVICORow servicoTmp = servicos.NewORCAMENTO_SERVICORow();

            int qtdItensDeletados = itensDeletados != null ? itensDeletados.Rows.Count : 0;
            int qtdItensInseridos = itensInseridos != null ? itensInseridos.Rows.Count : 0;
            int qtdServicosDeletados = servicosDeletados != null ? servicosDeletados.Rows.Count : 0;
            int qtdServicosInseridos = servicosInseridos != null ? servicosInseridos.Rows.Count : 0;

            for (int i = 0; i < qtdItensDeletados; i++) {
                itemTmp.ORCAMENTO_ITEM_CODIGO = (int)itensDeletados.Rows[i][itensDeletados.ORCAMENTO_ITEM_CODIGOColumn, DataRowVersion.Original];
                orcamentoItemSQL.deletar(itemTmp);
            }

            for (int i = 0; i < qtdServicosDeletados; i++) {
                servicoTmp.ORCAMENTO_SERVICO_CODIGO = (int)servicosDeletados.Rows[i][servicosDeletados.ORCAMENTO_SERVICO_CODIGOColumn, DataRowVersion.Original];
                orcamentoServicoSQL.deletar(servicoTmp);
            }

            for (int i = 0; i < qtdItensInseridos; i++) {
                itemTmp.ORCAMENTO_ITEM_ORCAMENTO = orcamento.ORCAMENTO_CODIGO;
                itemTmp.ORCAMENTO_ITEM_PRODUTO = (int)itensInseridos.Rows[i][itensInseridos.ORCAMENTO_ITEM_PRODUTOColumn, DataRowVersion.Current];
                itemTmp.ORCAMENTO_ITEM_VALOR = (double)itensInseridos.Rows[i][itensInseridos.ORCAMENTO_ITEM_VALORColumn, DataRowVersion.Current];
                itemTmp.ORCAMENTO_ITEM_DESCRICAO = (string) itensInseridos.Rows[i][itensInseridos.ORCAMENTO_ITEM_DESCRICAOColumn, DataRowVersion.Current];
                itemTmp.ORCAMENTO_ITEM_DESCONTO = (double)itensInseridos.Rows[i][itensInseridos.ORCAMENTO_ITEM_DESCONTOColumn, DataRowVersion.Current];
                itemTmp.ORCAMENTO_ITEM_QUANTIDADE = (short)itensInseridos.Rows[i][itensInseridos.ORCAMENTO_ITEM_QUANTIDADEColumn, DataRowVersion.Current];
                itemTmp.ORCAMENTO_ITEM_TOTAL = (double)itensInseridos.Rows[i][itensInseridos.ORCAMENTO_ITEM_TOTALColumn, DataRowVersion.Current];
                orcamentoItemSQL.inserir(itemTmp);
            }

            for (int i = 0; i < qtdServicosInseridos; i++) {
                servicoTmp.ORCAMENTO_SERVICO_ORCAMENTO = orcamento.ORCAMENTO_CODIGO;
                servicoTmp.ORCAMENTO_SERVICO_SERVICO = (int)servicosInseridos.Rows[i][servicosInseridos.ORCAMENTO_SERVICO_SERVICOColumn, DataRowVersion.Current];
                servicoTmp.ORCAMENTO_SERVICO_VALOR = (double)servicosInseridos.Rows[i][servicosInseridos.ORCAMENTO_SERVICO_VALORColumn, DataRowVersion.Current];
                servicoTmp.ORCAMENTO_SERVICO_DESCRICAO = (string)servicosInseridos.Rows[i][servicosInseridos.ORCAMENTO_SERVICO_DESCRICAOColumn, DataRowVersion.Current];
                servicoTmp.ORCAMENTO_SERVICO_DESCONTO = (double)servicosInseridos.Rows[i][servicosInseridos.ORCAMENTO_SERVICO_DESCONTOColumn, DataRowVersion.Current];
                servicoTmp.ORCAMENTO_SERVICO_ACRESCIMO = (double)servicosInseridos.Rows[i][servicosInseridos.ORCAMENTO_SERVICO_ACRESCIMOColumn, DataRowVersion.Current];
                servicoTmp.ORCAMENTO_SERVICO_TOTAL = (double)servicosInseridos.Rows[i][servicosInseridos.ORCAMENTO_SERVICO_TOTALColumn, DataRowVersion.Current];
                orcamentoServicoSQL.inserir(servicoTmp);
            }

            foreach (dsFROGIOS.ORCAMENTO_ITEMRow item in itensAlterados) {
                orcamentoItemSQL.atualizar(item);
            }

            foreach (dsFROGIOS.ORCAMENTO_SERVICORow servico in servicosAlterados) {
                orcamentoServicoSQL.atualizar(servico);
            }
        }
Exemplo n.º 4
0
        public void atualizar(
            dsFROGIOS.OSRow os,
            dsFROGIOS.OS_ITEMDataTable itens,
            dsFROGIOS.OS_SERVICODataTable servicos)
        {
            sqlOs.atualizar(os);

            dsFROGIOS.OS_ITEMDataTable itensDeletados = new dsFROGIOS.OS_ITEMDataTable();
            dsFROGIOS.OS_ITEMDataTable itensInseridos = new dsFROGIOS.OS_ITEMDataTable();
            dsFROGIOS.OS_ITEMDataTable itensAlterados = new dsFROGIOS.OS_ITEMDataTable();
            dsFROGIOS.OS_SERVICODataTable servicosDeletados = new dsFROGIOS.OS_SERVICODataTable();
            dsFROGIOS.OS_SERVICODataTable servicosInseridos = new dsFROGIOS.OS_SERVICODataTable();
            dsFROGIOS.OS_SERVICODataTable servicosAlterados = new dsFROGIOS.OS_SERVICODataTable();

            int contador = 0;
            foreach (dsFROGIOS.OS_ITEMRow item in itens)
            {
                if (item.RowState == DataRowState.Added)
                {
                    item.OS_ITEM_CODIGO = contador; contador++;
                    item.OS_ITEM_OS = os.OS_CODIGO;
                    itensInseridos.ImportRow(item);
                }

                if (item.RowState == DataRowState.Modified) {
                    itensAlterados.ImportRow(item);
                }
            }
            itensDeletados = (dsFROGIOS.OS_ITEMDataTable)itens.GetChanges(DataRowState.Deleted);

            contador = 0;
            foreach (dsFROGIOS.OS_SERVICORow servico in servicos)
            {
                if (servico.RowState == DataRowState.Added)
                {
                    servico.OS_SERVICO_CODIGO = contador; contador++;
                    servico.OS_SERVICO_OS = os.OS_CODIGO;
                    servicosInseridos.ImportRow(servico);
                }

                if (servico.RowState == DataRowState.Modified) {
                    servicosAlterados.ImportRow(servico);
                }
            }
            servicosDeletados = (dsFROGIOS.OS_SERVICODataTable)servicos.GetChanges(DataRowState.Deleted);

            dsFROGIOS.OS_ITEMRow itemTmp = itens.NewOS_ITEMRow();
            dsFROGIOS.OS_SERVICORow servicoTmp = servicos.NewOS_SERVICORow();

            int qtdItensDeletados = itensDeletados != null ? itensDeletados.Rows.Count : 0;
            int qtdItensInseridos = itensInseridos != null ? itensInseridos.Rows.Count : 0;
            int qtdItensAlterados = itensAlterados != null ? itensAlterados.Rows.Count : 0;
            int qtdServicosDeletados = servicosDeletados != null ? servicosDeletados.Rows.Count : 0;
            int qtdServicosInseridos = servicosInseridos != null ? servicosInseridos.Rows.Count : 0;

            string sqlRetirar =
                "UPDATE PRODUTO " +
                "SET PRODUTO_ESTOQUE_ATUAL = ((SELECT PRODUTO_ESTOQUE_ATUAL FROM PRODUTO WHERE PRODUTO_CODIGO = " + paramCodigo + ")-" + paramEstoque + ") " +
                "WHERE PRODUTO_CODIGO = " + paramCodigo;

            string sqlAdicionar =
                "UPDATE PRODUTO " +
                "SET PRODUTO_ESTOQUE_ATUAL = ((SELECT PRODUTO_ESTOQUE_ATUAL FROM PRODUTO WHERE PRODUTO_CODIGO = " + paramCodigo + ")+" + paramEstoque + ") " +
                "WHERE PRODUTO_CODIGO = " + paramCodigo;

            FbCommand comando = new FbCommand(sqlAdicionar, Conexao.getConexao, Conexao.getTransacao);

            for (int i = 0; i < qtdItensDeletados; i++) {
                itemTmp.OS_ITEM_CODIGO = (int)itensDeletados.Rows[i][itensDeletados.OS_ITEM_CODIGOColumn, DataRowVersion.Original];
                sqlOsItem.deletar(itemTmp);

                comando.Parameters.Clear();
                comando.Parameters.AddWithValue(paramCodigo, (itensDeletados.Rows[i][itensDeletados.OS_ITEM_PRODUTOColumn, DataRowVersion.Original] as dsFROGIOS.OS_ITEMRow).OS_ITEM_PRODUTO);
                comando.Parameters.AddWithValue(paramEstoque, (itensDeletados.Rows[i][itensDeletados.OS_ITEM_PRODUTOColumn, DataRowVersion.Original] as dsFROGIOS.OS_ITEMRow).OS_ITEM_QUANTIDADE);
                comando.ExecuteNonQuery();
            }

            for (int i = 0; i < qtdServicosDeletados; i++) {
                servicoTmp.OS_SERVICO_CODIGO = (int)servicosDeletados.Rows[i][servicosDeletados.OS_SERVICO_CODIGOColumn, DataRowVersion.Original];
                sqlOsServico.deletar(servicoTmp);
            }

            for (int i = 0; i < qtdItensInseridos; i++) {
                itemTmp.OS_ITEM_DESCONTO = (double) itensInseridos.Rows[i][itensInseridos.OS_ITEM_DESCONTOColumn, DataRowVersion.Current];
                itemTmp.OS_ITEM_DESCRICAO = (string) itensInseridos.Rows[i][itensInseridos.OS_ITEM_DESCRICAOColumn, DataRowVersion.Current];
                itemTmp.OS_ITEM_OS = os.OS_CODIGO;
                itemTmp.OS_ITEM_PRODUTO = (int)itensInseridos.Rows[i][itensInseridos.OS_ITEM_PRODUTOColumn, DataRowVersion.Current];
                itemTmp.OS_ITEM_QUANTIDADE = (short)itensInseridos.Rows[i][itensInseridos.OS_ITEM_QUANTIDADEColumn, DataRowVersion.Current];
                itemTmp.OS_ITEM_TOTAL = (double)itensInseridos.Rows[i][itensInseridos.OS_ITEM_TOTALColumn, DataRowVersion.Current];
                itemTmp.OS_ITEM_VALOR = (double)itensInseridos.Rows[i][itensInseridos.OS_ITEM_VALORColumn, DataRowVersion.Current];
                sqlOsItem.inserir(itemTmp);

                comando.CommandText = sqlRetirar;
                comando.Parameters.Clear();
                comando.Parameters.AddWithValue(paramCodigo, itemTmp.OS_ITEM_PRODUTO);
                comando.Parameters.AddWithValue(paramEstoque, itemTmp.OS_ITEM_QUANTIDADE);
                comando.ExecuteNonQuery();
            }

            for (int i = 0; i < qtdServicosInseridos; i++) {
                servicoTmp.OS_SERVICO_OS = os.OS_CODIGO;
                servicoTmp.OS_SERVICO_SERVICO = (int)servicosInseridos.Rows[i][servicosInseridos.OS_SERVICO_SERVICOColumn, DataRowVersion.Current];
                servicoTmp.OS_SERVICO_VALOR = (double)servicosInseridos.Rows[i][servicosInseridos.OS_SERVICO_VALORColumn, DataRowVersion.Current];
                servicoTmp.OS_SERVICO_DESCRICAO = (string)servicosInseridos.Rows[i][servicosInseridos.OS_SERVICO_DESCRICAOColumn, DataRowVersion.Current];
                servicoTmp.OS_SERVICO_DESCONTO = (double)servicosInseridos.Rows[i][servicosInseridos.OS_SERVICO_DESCONTOColumn, DataRowVersion.Current];
                servicoTmp.OS_SERVICO_ACRESCIMO = (double)servicosInseridos.Rows[i][servicosInseridos.OS_SERVICO_ACRESCIMOColumn, DataRowVersion.Current];
                servicoTmp.OS_SERVICO_TOTAL = (double)servicosInseridos.Rows[i][servicosInseridos.OS_SERVICO_TOTALColumn, DataRowVersion.Current];

                sqlOsServico.inserir(servicoTmp);
            }

            foreach (dsFROGIOS.OS_ITEMRow item in itensAlterados) {
                sqlOsItem.atualizar(item);
            }

            foreach (dsFROGIOS.OS_SERVICORow servico in servicosAlterados) {
                sqlOsServico.atualizar(servico);
            }

            TblOsItem osItemSQL = new TblOsItem();
            for (int i = 0; i < qtdItensAlterados; i++) {

                short quantidadeAtual = (short)itensAlterados.Rows[i][itensAlterados.OS_ITEM_QUANTIDADEColumn, DataRowVersion.Current];
                short quantidadeOriginal = (short)itensAlterados.Rows[i][itensAlterados.OS_ITEM_QUANTIDADEColumn, DataRowVersion.Original];
                int codigoProduto = (int)itensAlterados.Rows[i][itensAlterados.OS_ITEM_PRODUTOColumn, DataRowVersion.Current];
                int diferenca = quantidadeOriginal - quantidadeAtual;
                dsFROGIOS.OS_ITEMRow item = itensAlterados.Rows[i] as dsFROGIOS.OS_ITEMRow;

                if (diferenca > 0) {
                    //somar estoque à um produto
                    comando.CommandText = sqlAdicionar;
                    comando.Parameters.Clear();
                    comando.Parameters.AddWithValue(paramCodigo, codigoProduto);
                    comando.Parameters.AddWithValue(paramEstoque, diferenca);
                    comando.ExecuteNonQuery();
                } else if (diferenca < 0) {
                    // subtrair estoque de um produto
                    comando.CommandText = sqlRetirar;
                    comando.Parameters.Clear();
                    comando.Parameters.AddWithValue(paramCodigo, codigoProduto);
                    comando.Parameters.AddWithValue(paramEstoque, (diferenca * (-1)));
                    comando.ExecuteNonQuery();
                }

                osItemSQL.atualizar(item);
            }
        }