Ejemplo n.º 1
0
            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());
                    }
                }
            }