private void TFMateriais_Load(object sender, EventArgs e) { vFicha = lFicha; TList_CadCFGEmpreendimento registro_CadCFG = TCN_CadCFGEmpreendimento.Busca(string.Empty, string.Empty, null); if (registro_CadCFG.Count.Equals(0)) { MessageBox.Show("Necessário ter pré-cadastrado configuração empreendimento", "Informativo", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Abort; } else if (registro_CadCFG[0].Cd_tabelapreco == null || string.IsNullOrEmpty(registro_CadCFG[0].Cd_tabelapreco)) { MessageBox.Show("Necessário ter pré-cadastrado tabela de preço na configuração do empreendimento", "Informativo", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Abort; } vFicha.ForEach(r => { object d = new CamadaDados.Estoque.Cadastros.TCD_CadProduto().BuscarPrecoVenda(registro_CadCFG[0].cd_empresa, r.Cd_produto, registro_CadCFG[0].Cd_tabelapreco); r.Vl_unitarioAtual = d == null ? 0 : Convert.ToDecimal(d); }); bsMateriais.DataSource = vFicha; bsMateriais.ResetBindings(true); }
public static string GravarDireto(TRegistro_Orcamento orcamento, TList_FichaTec litens, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_CompraEmpreendimento qtb_orc = new TCD_CompraEmpreendimento(); try { if (banco == null) { st_transacao = qtb_orc.CriarBanco_Dados(true); } else { qtb_orc.Banco_Dados = banco; } TList_CadCFGEmpreendimento lCfg = TCN_CadCFGEmpreendimento.Busca(string.Empty, string.Empty, qtb_orc.Banco_Dados); if (lCfg.Count.Equals(0)) { throw new Exception("Não existe cadastro CFG.Empreendimento."); } TList_FichaTec itensDireto = new TList_FichaTec(); if (litens == null) { orcamento.lOrcProjeto.ForEach(o => { o.lFicha.ForEach(p => { if (p.St_fatdiretobool) { itensDireto.Add(p); } }); }); } else { litens.ForEach(p => { itensDireto.Add(p); }); } string ret = string.Empty; itensDireto.ForEach(p => { CamadaDados.Compra.Lancamento.TRegistro_Requisicao req = new CamadaDados.Compra.Lancamento.TRegistro_Requisicao(); req.Cd_empresa = orcamento.Cd_empresa; req.Cd_produto = p.Cd_produto; req.Ds_produto = p.Ds_produto; req.Quantidade = p.quantidade_agregar == decimal.Zero? p.Quantidade : p.quantidade_agregar; CamadaDados.Financeiro.Cadastros.TList_CadClifor lclifor = new CamadaDados.Financeiro.Cadastros.TCD_CadClifor().Select( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "isnull(a.st_registro, 'A')", vOperador = "<>", vVL_Busca = "'C'" }, new Utils.TpBusca() { vNM_Campo = string.Empty, vOperador = "exists", vVL_Busca = "(select 1 from tb_cmp_usuariocompra x " + "where x.cd_clifor_cmp = a.cd_clifor " + "and isnull(x.st_requisitar, 'N') = 'S' " + "and x.login = '******')" } }, 0, string.Empty); if (lclifor.Count > 0) { req.Cd_clifor_comprador = lclifor[0].Cd_clifor; req.Cd_clifor_requisitante = lclifor[0].Cd_clifor; } req.St_requisicao = "AC"; req.Id_tprequisicaostr = p.St_fatdiretobool ? lCfg[0].tp_requisicaodir: lCfg[0].tp_requisicao; //GRAVAR req.Id_requisicao = Convert.ToDecimal(CamadaDados.TDataQuery.getPubVariavel( CamadaNegocio.Compra.Lancamento.TCN_Requisicao.GravarRequisicao(req, qtb_orc.Banco_Dados), "@P_ID_REQUISICAO")); TRegistro_CompraEmpreendimento val = new TRegistro_CompraEmpreendimento(); val.Id_orcamentostr = p.Id_orcamentostr; val.Id_registrostr = p.Id_registrostr; val.Id_requisicao = req.Id_requisicao; val.Nr_versao = p.Nr_versao; val.Id_ficha = p.Id_ficha; val.id_atividade = p.Id_projetostr; val.Cd_empresa = p.Cd_empresa; ret = qtb_orc.Gravar(val); val.Id_requisicao = Convert.ToDecimal(CamadaDados.TDataQuery.getPubVariavel(ret, "@P_ID_REQUISICAO")); }); //string ret = qtb_orc.Gravar(val); if (st_transacao) { qtb_orc.Banco_Dados.Commit_Tran(); } return(ret); } catch (Exception ex) { if (st_transacao) { qtb_orc.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro gravar requisicao: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_orc.deletarBanco_Dados(); } } }
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); } } } }
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); } }
private void bbImportar_Click(object sender, EventArgs e) { if (bsOrcamento.Current != null) { string id_orcamento = string.Empty; using (TFConsultaProjetos cProjetos = new TFConsultaProjetos()) { if (cProjetos.ShowDialog() == DialogResult.OK) { TList_Orcamento lorcamento = new TList_Orcamento(); TList_Orcamento lprojeto2 = new TList_Orcamento(); lorcamento = cProjetos.lOrc; lorcamento.ForEach(o => { o.lDespesas.Where(p => p.st_importar).ToList().ForEach(p => { p.Id_orcamentostr = (bsOrcamento.Current as TRegistro_Orcamento).Id_orcamentostr; p.Nr_versaostr = (bsOrcamento.Current as TRegistro_Orcamento).Nr_versaostr; p.Id_RegDesp = (bsDespesas.Count) + 1; bsDespesas.Add(p); }); o.lOEncargo.Where(p => p.st_importar).ToList().ForEach(p => { p.Id_orcamentostr = (bsOrcamento.Current as TRegistro_Orcamento).Id_orcamentostr; p.Nr_versaostr = (bsOrcamento.Current as TRegistro_Orcamento).Nr_versaostr; p.vl_encargo = decimal.Zero; bsEncargo.Add(p); }); o.lMaoObra.Where(p => p.st_importar).ToList().ForEach(p => { p.Id_orcamentostr = (bsOrcamento.Current as TRegistro_Orcamento).Id_orcamentostr; p.Nr_versaostr = (bsOrcamento.Current as TRegistro_Orcamento).Nr_versaostr; p.Id_MaoObra = (bsMaoObra).Count + 1; bsMaoObra.Add(p); }); o.lOrcProjeto.Where(p => p.st_importar).ToList().ForEach(p => { TList_FichaTec lista = new TList_FichaTec(); p.lFicha.Where(i => i.st_agregar).ToList().ForEach(i => { i.Quantidade = i.quantidade_agregar; i.quantidade_agregar = decimal.Zero; i.Id_ficha = decimal.Zero; i.Id_orcamentostr = (bsOrcamento.Current as TRegistro_Orcamento).Id_orcamentostr; i.Id_projetostr = string.Empty; i.Nr_versaostr = (bsOrcamento.Current as TRegistro_Orcamento).Nr_versaostr; i.Vl_subtotal = i.Vl_unitario * i.Quantidade; if (i.st_composto.Equals("S")) { CamadaDados.Estoque.Cadastros.TList_FichaTecProduto lFichaitens = CamadaNegocio.Estoque.Cadastros.TCN_FichaTecProduto.Buscar(i.Cd_produto, string.Empty, null); lFichaitens.ForEach(iten => { TRegistro_FichaItens item = new TRegistro_FichaItens(); item.Cd_itemstr = iten.Cd_item; item.ds_item = iten.Ds_item; item.quantidade = iten.Quantidade; item.vl_unitario = iten.Vl_custoservico; item.vl_subtotal = iten.Vl_subtotalservico; i.lfichaItens.Add(item); }); } lista.Add(i); }); p.Id_orcamentostr = (bsOrcamento.Current as TRegistro_Orcamento).Id_orcamentostr; p.Id_projeto = (bsAtividade).Count + 1; p.Nr_versaostr = (bsOrcamento.Current as TRegistro_Orcamento).Nr_versaostr; p.lFicha = lista; bsAtividade.Add(p); bsAtividade.ResetCurrentItem(); }); }); bsAtividade.Position = bsAtividade.Count - 1; MessageBox.Show("Importado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { MessageBox.Show("Selecione um Orcamento.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }