Exemplo n.º 1
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <returns>The data.</returns>
        public List <Stock> getData()
        {
            string        connectionString = "URI=file:" + dbFile;
            IDbConnection dbcon            = (IDbConnection) new SqliteConnection(connectionString);

            dbcon.Open();

            IDbCommand dbcmd = dbcon.CreateCommand();

            dbcmd.CommandText = sql;
            IDataReader reader = dbcmd.ExecuteReader();

            List <Stock> stocklist = new List <Stock> ();

            while (reader.Read())
            {
                Int16 id;
                Int16.TryParse(Commom.getDBValue(reader [0]), out id);

                double originalValue;
                double.TryParse(Commom.getDBValue(reader [2]), out originalValue);

                int quantity;
                int.TryParse(Commom.getDBValue(reader [3]), out quantity);

                double tax;
                double.TryParse(Commom.getDBValue(reader [4]), out tax);

                double oscilacao = Commom.getDouble((Commom.getDBValue(reader [6])));

                double ultimo = Commom.getDouble((Commom.getDBValue(reader [7])));

                Stock stk = new Stock(id,
                                      Commom.getDBValue(reader[1]),
                                      originalValue,
                                      quantity,
                                      tax,
                                      Commom.getDBValue(reader[5]),
                                      oscilacao,
                                      ultimo,
                                      Commom.getDBValue(reader[8]));

                stocklist.Add(stk);
            }

            reader.Close();
            reader = null;
            dbcmd.Dispose();
            dbcon.Close();
            dbcon.Dispose();

            return(stocklist);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Buttons the new.
        /// </summary>
        /// <param name="sender">Sender.</param>
        partial void btnNew(NSObject sender)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtTaxas.Text))
                {
                    txtTaxas.Text = "0";
                }

                double vledbl;
                int    vleint;
                if (!string.IsNullOrEmpty(txtPapel.Text) &&
                    !string.IsNullOrEmpty(txtQuantidade.Text) &&
                    !string.IsNullOrEmpty(txtValor.Text) &&
                    double.TryParse(txtValor.Text, out vledbl) &&
                    int.TryParse(txtQuantidade.Text, out vleint) &&
                    double.TryParse(txtTaxas.Text, out vledbl))
                {
                    Stock stk = new Stock(0,
                                          txtPapel.Text.Trim().ToUpper(),
                                          Commom.getDouble(txtValor.Text),
                                          Commom.getInt(txtQuantidade.Text),
                                          Commom.getDouble(txtTaxas.Text),
                                          string.Empty, 0, 0, string.Empty);

                    new DataAccess(string.Format("insert into compras (papel, valor, quantidade, taxas) values ('{0}', '{1}', '{2}', '{3}')",
                                                 stk.Code,
                                                 stk.OriginalValue.ToString().Replace(',', '.'),
                                                 stk.Quantity,
                                                 stk.Tax.ToString().Replace(',', '.'))).executeQuery();
                }
                else
                {
                    new UIAlertView("Dados Inválidos :(", "Nas informações enviadas, foram identificados dados vazios ou inválidos e por isso, não foi possível realizar o cadastro.", null, "OK", null).Show();
                }
            }
            catch (Exception ex)
            {
                Insights.Report(ex);
                new UIAlertView("Ops!", "Houve um erro ao tentar realizar essa operação. \nNosso time foi informado.", null, "OK", null).Show();
            }
        }
Exemplo n.º 3
0
        public void loadInfoWhait(bool update)
        {
            try
            {
                if (tblView != null)
                {
                    List <Stock> stocklist = new DataAccess("select compras.id, compras.papel, compras.valor, compras.quantidade, compras.taxas, cotacoes.nome, cotacoes.oscilacao, cotacoes.ultimo, cotacoes.data from compras left join cotacoes on compras.papel = cotacoes.codigo and cotacoes.id in (select max(cotacoes.id) from cotacoes group by codigo) order by compras.papel").getData();
                    string       papel     = Stock.getAllCodes(stocklist);

                    ShowLoading();
                    System.Xml.XmlDocument xml = new System.Xml.XmlDocument();

                    Task.Factory.StartNew(
                        () => {
                        try
                        {
                            if (!string.IsNullOrEmpty(papel))
                            {
                                xml.Load("http://www.bmfbovespa.com.br/Pregao-Online/ExecutaAcaoAjax.asp?CodigoPapel=" + papel + "IBOV");
                            }
                        }
                        catch (Exception ex)
                        {
                            Insights.Report(ex);
                            new UIAlertView("Sem Conexão com Internet.", "Algum problema com sua conexão de internet não permitiu a atualização dos dados. ", null, "OK", null).Show();
                        }
                    }
                        ).ContinueWith(
                        t => {
                        try
                        {
                            if (update)
                            {
                                foreach (System.Xml.XmlElement node in xml.SelectNodes("ComportamentoPapeis/Papel"))
                                {
                                    foreach (Stock stk in stocklist)
                                    {
                                        if (stk.Code == node.Attributes.GetNamedItem("Codigo").InnerText)
                                        {
                                            double variationPercent = 0;
                                            double lastValue        = 0;
                                            variationPercent        = Commom.getDouble(node.Attributes.GetNamedItem("Oscilacao").InnerText);
                                            lastValue = Commom.getDouble(node.Attributes.GetNamedItem("Ultimo").InnerText);

                                            stk.Name             = node.Attributes.GetNamedItem("Nome").InnerText;
                                            stk.VariationPercent = variationPercent;

                                            if (Commom.getDateFromString(node.Attributes.GetNamedItem("Data").InnerText) != DateTime.MinValue)
                                            {
                                                stk.LastUpdatedDate = Commom.getDateFromString(node.Attributes.GetNamedItem("Data").InnerText).ToString("dd/MM/yyyy HH:mm");
                                            }
                                            else
                                            {
                                                stk.LastUpdatedDate = node.Attributes.GetNamedItem("Data").InnerText;
                                            }

                                            stk.LastValue = lastValue;
                                            stk.SaveQuotation();
                                        }

                                        if ("IBOV" == node.Attributes.GetNamedItem("Codigo").InnerText)
                                        {
                                            double variationPercent = 0;
                                            variationPercent        = Commom.getDouble(node.Attributes.GetNamedItem("Oscilacao").InnerText);

                                            if (variationPercent < 0)
                                            {
                                                txtIbov.TextColor = UIColor.Red;
                                            }
                                            else
                                            {
                                                txtIbov.TextColor = UIColor.Green;
                                            }

                                            txtIbov.Text = (variationPercent / 100).ToString("P2");
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Insights.Report(ex);
                            new UIAlertView("Xiiii.", "Alguma informação enviada pelo Bovespa não pode ser atualizada. ", null, "OK", null).Show();
                        }
                        finally
                        {
                            if (txtTotal != null)
                            {
                                txtTotal.Text = Stock.getTotalNow(stocklist);
                            }

                            if (txtInicial != null)
                            {
                                txtInicial.Text = Stock.getTotalInvested(stocklist);
                            }

                            if (txtGanhoPerda != null)
                            {
                                txtGanhoPerda.Text = Stock.getGainLoss(stocklist);
                            }

                            if (txtHomeTax != null)
                            {
                                txtHomeTax.Text = Stock.getTax(stocklist);
                            }

                            Stock[] tableItems = stocklist.ToArray();
                            tblView.Source     = new TableSource(tableItems, this);

                            tblView.ReloadData();
                        }

                        this._loadPop.Hide();
                    }, TaskScheduler.FromCurrentSynchronizationContext()
                        );
                }
            }
            catch (Exception ex)
            {
                Insights.Report(ex);
                new UIAlertView("Ops!", "Houve um erro ao tentar realizar essa operação. Nosso time será informado. ", null, "OK", null).Show();
            }
        }