Esempio n. 1
0
        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            if (bsOrcamento.Current == null)
            {
                return;
            }

            using (FRequisicaoCompra comp = new FRequisicaoCompra())
            {//Buscar Atividades
                TRegistro_Orcamento orc = new TRegistro_Orcamento();
                orc             = (bsOrcamento.Current as TRegistro_Orcamento);
                orc.lOrcProjeto =
                    TCN_OrcProjeto.Buscar((bsOrcamento.Current as TRegistro_Orcamento).Cd_empresa,
                                          (bsOrcamento.Current as TRegistro_Orcamento).Id_orcamentostr,
                                          (bsOrcamento.Current as TRegistro_Orcamento).Nr_versaostr,
                                          string.Empty,
                                          string.Empty,
                                          null);
                orc.lOrcProjeto.ForEach(p =>
                {
                    TpBusca[] filtro = new TpBusca[0];
                    if (!string.IsNullOrEmpty(p.Cd_empresa))
                    {
                        Array.Resize(ref filtro, filtro.Length + 1);
                        filtro[filtro.Length - 1].vNM_Campo = "a.cd_empresa";
                        filtro[filtro.Length - 1].vOperador = "=";
                        filtro[filtro.Length - 1].vVL_Busca = "'" + p.Cd_empresa.Trim() + "'";
                    }
                    if (!string.IsNullOrEmpty(p.Id_orcamentostr))
                    {
                        Array.Resize(ref filtro, filtro.Length + 1);
                        filtro[filtro.Length - 1].vNM_Campo = "a.id_orcamento";
                        filtro[filtro.Length - 1].vOperador = "=";
                        filtro[filtro.Length - 1].vVL_Busca = p.Id_orcamentostr;
                    }
                    if (!string.IsNullOrEmpty(p.Nr_versaostr))
                    {
                        Array.Resize(ref filtro, filtro.Length + 1);
                        filtro[filtro.Length - 1].vNM_Campo = "a.nr_versao";
                        filtro[filtro.Length - 1].vOperador = "=";
                        filtro[filtro.Length - 1].vVL_Busca = p.Nr_versaostr;
                    }
                    if (!string.IsNullOrEmpty(p.Id_projetostr))
                    {
                        Array.Resize(ref filtro, filtro.Length + 1);
                        filtro[filtro.Length - 1].vNM_Campo = "a.id_atividade";
                        filtro[filtro.Length - 1].vOperador = "=";
                        filtro[filtro.Length - 1].vVL_Busca = p.Id_projetostr;
                    }
                    if (!string.IsNullOrEmpty(p.Id_registrostr))
                    {
                        Array.Resize(ref filtro, filtro.Length + 1);
                        filtro[filtro.Length - 1].vNM_Campo = "a.Id_Registro";
                        filtro[filtro.Length - 1].vOperador = "=";
                        filtro[filtro.Length - 1].vVL_Busca = p.Id_registrostr;
                    }

                    Array.Resize(ref filtro, filtro.Length + 1);
                    filtro[filtro.Length - 1].vOperador = "not exists ";
                    filtro[filtro.Length - 1].vVL_Busca = " (select 1 from TB_EMP_CompraEmpreendimento x " +
                                                          "where a.id_orcamento = x.id_orcamento and a.nr_versao = x.nr_versao " +
                                                          "and a.ID_Atividade = x.ID_Atividade and a.ID_Ficha = x.ID_Ficha " +
                                                          "and a.ID_Registro = x.ID_Registro and a.cd_empresa = x.cd_empresa) ";



                    p.lFicha = new TCD_FichaTec().Select(filtro, 0, string.Empty);
                });
                comp.rOrcamento = orc;
                if (comp.ShowDialog() == DialogResult.OK)
                {
                    TList_FichaTec lficha = new TList_FichaTec();
                    lficha = comp.objetoItens.lFicha;
                    //(bsOrcamento.Current as TRegistro_Orcamento).St_registro = "E";
                    TList_FichaTec lficha2 = new TList_FichaTec();
                    lficha.ForEach(p =>
                    {
                        if (p.st_agregar)
                        {
                            lficha2.Add(p);
                        }
                    });

                    try
                    {
                        TCN_Orcamento.GravarOrcReq((bsOrcamento.Current as TRegistro_Orcamento), lficha2, null);
                        MessageBox.Show("Requisição de compra gravada com sucesso.", "Informativo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LimparFiltros();
                        afterBusca();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Esempio n. 2
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if ((bsOrcamento.Current) != null)
            {
                if ((bsOrcamento.Current as TRegistro_Orcamento).St_registro.Equals("T"))
                {
                    if (CamadaNegocio.Diversos.TCN_Usuario_RegraEspecial.ValidaRegra(Parametros.pubLogin, "VISAO PROJETISTA", null))
                    {
                        if (MessageBox.Show("Orcamento está em " + (bsOrcamento.Current as TRegistro_Orcamento).Status + ", Deseja finalizar o projeto e evoluir para execução?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                            MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            try
                            {
                                bsOrcamento_PositionChanged(this, new EventArgs());
                                TList_FichaTec lficha = new TList_FichaTec();

                                //valida
                                TList_CadCFGEmpreendimento lcfg = new TCD_CadCFGEmpreendimento().Select(
                                    new TpBusca[]
                                {
                                    new TpBusca()
                                    {
                                        vNM_Campo = "a.cd_empresa",
                                        vOperador = "=",
                                        vVL_Busca = (bsOrcamento.Current as TRegistro_Orcamento).Cd_empresa
                                    }
                                }, 1, string.Empty);
                                if (string.IsNullOrEmpty(lcfg[0].tp_requisicao) || string.IsNullOrEmpty(lcfg[0].tp_requisicaodir))
                                {
                                    MessageBox.Show("Favor corrigir a configuração do empreendimento!\n (Tipo Requisição)", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                                (bsOrcamento.Current as TRegistro_Orcamento).lOrcProjeto.ForEach(o =>
                                {
                                    o.lFicha.ForEach(p =>
                                    {
                                        if (p.Tot_saldo < p.Quantidade)
                                        {
                                            p.st_agregar         = true;
                                            p.quantidade_agregar = p.Quantidade;
                                        }
                                    });
                                });

                                TList_FichaTec lista_nao_cadastrados = new TList_FichaTec();
                                bool           lista = false;
                                (bsOrcamento.Current as TRegistro_Orcamento).lOrcProjeto.ForEach(o =>
                                {
                                    o.lFicha.ForEach(p =>
                                    {
                                        if (string.IsNullOrEmpty(p.Cd_produto))
                                        {
                                            lista_nao_cadastrados.Add(p);
                                            lista = true;
                                        }
                                    });
                                });

                                if (lista)
                                {
                                    using (FListCadProd ls = new FListCadProd())
                                    {
                                        ls.rLItens = lista_nao_cadastrados;
                                        if (ls.ShowDialog() == DialogResult.OK)
                                        {
                                            (bsOrcamento.Current as TRegistro_Orcamento).lOrcProjeto.ForEach(o =>
                                            {
                                                o.lFicha.ForEach(p =>
                                                {
                                                    ls.rLItens.ForEach(i =>
                                                    {
                                                        if (p.Ds_produto.Equals(i.Ds_produto))
                                                        {
                                                            p.Cd_produto = i.Cd_produto;
                                                            CamadaNegocio.Empreendimento.TCN_FichaTec.Gravar(p, null);
                                                        }
                                                    });
                                                });
                                            });
                                            bsOrcamento.ResetCurrentItem();
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                }

                                using (FRequisicaoCompra comp = new FRequisicaoCompra())
                                {//Buscar Atividades
                                    TRegistro_Orcamento orc = new TRegistro_Orcamento();
                                    orc             = (bsOrcamento.Current as TRegistro_Orcamento);
                                    orc.lOrcProjeto =
                                        TCN_OrcProjeto.Buscar((bsOrcamento.Current as TRegistro_Orcamento).Cd_empresa,
                                                              (bsOrcamento.Current as TRegistro_Orcamento).Id_orcamentostr,
                                                              (bsOrcamento.Current as TRegistro_Orcamento).Nr_versaostr,
                                                              string.Empty,
                                                              string.Empty,
                                                              null);
                                    orc.lOrcProjeto.ForEach(p =>
                                    {
                                        TpBusca[] filtro = new TpBusca[0];
                                        if (!string.IsNullOrEmpty(p.Cd_empresa))
                                        {
                                            Array.Resize(ref filtro, filtro.Length + 1);
                                            filtro[filtro.Length - 1].vNM_Campo = "a.cd_empresa";
                                            filtro[filtro.Length - 1].vOperador = "=";
                                            filtro[filtro.Length - 1].vVL_Busca = "'" + p.Cd_empresa.Trim() + "'";
                                        }
                                        if (!string.IsNullOrEmpty(p.Id_orcamentostr))
                                        {
                                            Array.Resize(ref filtro, filtro.Length + 1);
                                            filtro[filtro.Length - 1].vNM_Campo = "a.id_orcamento";
                                            filtro[filtro.Length - 1].vOperador = "=";
                                            filtro[filtro.Length - 1].vVL_Busca = p.Id_orcamentostr;
                                        }
                                        if (!string.IsNullOrEmpty(p.Nr_versaostr))
                                        {
                                            Array.Resize(ref filtro, filtro.Length + 1);
                                            filtro[filtro.Length - 1].vNM_Campo = "a.nr_versao";
                                            filtro[filtro.Length - 1].vOperador = "=";
                                            filtro[filtro.Length - 1].vVL_Busca = p.Nr_versaostr;
                                        }
                                        if (!string.IsNullOrEmpty(p.Id_projetostr))
                                        {
                                            Array.Resize(ref filtro, filtro.Length + 1);
                                            filtro[filtro.Length - 1].vNM_Campo = "a.id_atividade";
                                            filtro[filtro.Length - 1].vOperador = "=";
                                            filtro[filtro.Length - 1].vVL_Busca = p.Id_projetostr;
                                        }
                                        if (!string.IsNullOrEmpty(p.Id_registrostr))
                                        {
                                            Array.Resize(ref filtro, filtro.Length + 1);
                                            filtro[filtro.Length - 1].vNM_Campo = "a.Id_Registro";
                                            filtro[filtro.Length - 1].vOperador = "=";
                                            filtro[filtro.Length - 1].vVL_Busca = p.Id_registrostr;
                                        }

                                        Array.Resize(ref filtro, filtro.Length + 1);
                                        filtro[filtro.Length - 1].vOperador = "not exists ";
                                        filtro[filtro.Length - 1].vVL_Busca = " (select 1 from TB_EMP_CompraEmpreendimento x " +
                                                                              "where a.id_orcamento = x.id_orcamento and a.nr_versao = x.nr_versao " +
                                                                              "and a.ID_Atividade = x.ID_Atividade and a.ID_Ficha = x.ID_Ficha " +
                                                                              "and a.ID_Registro = x.ID_Registro and a.cd_empresa = x.cd_empresa) ";



                                        p.lFicha = new TCD_FichaTec().Select(filtro, 0, string.Empty);
                                    });
                                    comp.rOrcamento = orc;
                                    if (comp.ShowDialog() == DialogResult.OK)
                                    {
                                        lficha = comp.objetoItens.lFicha;
                                        //(bsOrcamento.Current as TRegistro_Orcamento) = comp.rOrcamento;
                                        (bsOrcamento.Current as TRegistro_Orcamento).St_registro = "E";
                                        TList_FichaTec lficha2 = new TList_FichaTec();
                                        lficha.ForEach(p =>
                                        {
                                            if (p.st_agregar)
                                            {
                                                lficha2.Add(p);
                                            }
                                        });
                                        TCN_Orcamento.GravarOrcReq((bsOrcamento.Current as TRegistro_Orcamento), lficha2, null);

                                        // MessageBox.Show("Orçamento gravado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        LimparFiltros();
                                        //cbHomologacao.Checked = true;
                                        afterBusca();
                                        MessageBox.Show("Orçamento está aguardando em execução.", "Orçamento", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }
                                }
                            }
                            catch (Exception ex)
                            { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Usuário não tem permissão de projetista para esta evolução.", "Orçamento", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else
            {
                MessageBox.Show("Selecione um orcamento!", "Orçamento", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }