public static ListaOrcamento RetornaOrcamento() { try { con = ConnectionFactory.getConnection(); con.Open(); comando = "SELECT Orcamento.IdPedido, Orcamento.Tipo, DataEmissao,Observacoes, Vendedor, PrazoEntrega, CondicaoPag, Orcamento.ValorSoma, QtdItens FROM Orcamento INNER JOIN Pedido on Pedido.IdPedido = Orcamento.IdPedido WHERE Pedido.Status = 'ORCAMENTO' ORDER BY DataEmissao;"; XmlSerializer ser = new XmlSerializer(typeof(ListaOrcamento)); list = new ListaOrcamento(); using (var cmd = con.CreateCommand()) { cmd.CommandText = comando.ToString(); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { list.Items.Add(new Orcamento { Pedido = rdr.GetInt32(0), Tipo = rdr.GetString(1), DataEmissao = rdr.GetDateTime(2).ToString("dd/MM/yyyy"), Observacoes = rdr.GetString(3), Vendedor = rdr.GetString(4), PrazoEntrega = rdr.GetString(5), CondicaoPag = rdr.GetString(6), ValorTotal = rdr.GetDouble(7), QtdItens = rdr.GetInt32(8) }); } } } return(list); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { try { if (con != null) { con.Close(); } } catch (Exception ex) { throw new Exception(ex.ToString()); } try { if (rdr != null) { rdr.Close(); } } catch (Exception ex) { throw new Exception(ex.ToString()); } try { if (cmd != null) { cmd.Dispose(); } } catch (Exception ex) { throw new Exception(ex.ToString()); } } }
protected void btnAddItem_Click(object sender, ImageClickEventArgs e) { if (Page.IsValid) { if (ddlItem.SelectedIndex > 0) { Resultado resultado = new Resultado(); List <PedidosOrcamentos> ListaOrcamento = null; PedidosOrcamentos ItemOrcamento = new PedidosOrcamentos(); if (ListaGridPersistida != null) { ListaOrcamento = (List <PedidosOrcamentos>)ListaGridPersistida; } else { ListaOrcamento = new List <PedidosOrcamentos>(); } Projetos oProd = new Projetos(); oProd.ProjetoID = Convert.ToInt32(ddlProjeto.SelectedValue); oProd.Nome = ddlProjeto.SelectedItem.ToString(); Categoria oCat = new Categoria(); oCat.CategoriaID = Convert.ToInt32(ddlCategoria.SelectedValue); oCat.Nome = ddlCategoria.SelectedItem.ToString(); ItemOrcamento.UnidadeMedida = new UnidadeMedida(Convert.ToInt32(ddlUnidadeMedida.SelectedItem.Value), ddlUnidadeMedida.SelectedItem.Text); Grupo oArea = new Grupo(); if (((Usuario)Session["USUARIO"]).Perfil.PerfilId != 3) { oArea.ID = Convert.ToInt32(ddlArea.SelectedValue); oArea.Nome = ddlArea.SelectedItem.ToString(); } else { oArea = ((Usuario)Session["USUARIO"]).Area; } Item oItem = new Item(); oItem.ItemID = Convert.ToInt32(ddlItem.SelectedValue); oItem.Nome = ddlItem.SelectedItem.ToString(); oItem.Categoria = oCat; ItemOrcamento.Cod_PedidosOrcamentos = ListaOrcamento.Count + 1; ItemOrcamento.Item = oItem; ItemOrcamento.Projeto = oProd; ItemOrcamento.Area = oArea; ItemOrcamento.Quantidade = Convert.ToInt32(txtQuantidade.Text); ItemOrcamento.DataNecessidade = Convert.ToDateTime(dtNecessidade.Text); ItemOrcamento.UsuarioPedido.UsuarioId = ((Usuario)Session["USUARIO"]).UsuarioId; if (txtOutros.Text.ToString() != string.Empty) { ItemOrcamento.Outros = txtOutros.Text.ToString(); } if (txtDesc.Text.ToString() != string.Empty) { ItemOrcamento.Descricao = txtDesc.Text.ToString(); } string msgConfirmacao = string.Empty; //resultado = oPedItemFacade.Validar(ItemOrcamento); //if (resultado.Sucesso) //{ ListaGridPersistida = ListaOrcamento; ListaOrcamento.Add(ItemOrcamento); gvPedItens.DataSource = (List <PedidosOrcamentos>)ListaGridPersistida; gvPedItens.DataBind(); btnSalvar.Visible = true; btnCancelar.Visible = true; ddlCategoria.Enabled = false; //} } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "ResultadoConfirmaĆ§Ć£o", "alert('Selecione um Item para adicionar a lista!');", true); } ddlCategoria_SelectedIndexChanged(null, null); txtDesc.Text = ""; txtOutros.Text = ""; txtQuantidade.Text = ""; } }