Neste post vou apresentar um aplicativo para Windows Mobile 6 que recebe como entrada o valor do litro do álcool, da gasolina e exibe uma mensagem dizendo qual dos dois é mais vantajoso abastecer, bastante útil quando o seu veículo é flex. Faça o download do código fonte do projeto: AlcoolGasolina.zip (56,97 kb). Caso você queira apenas o .cab do aplicativo para instalar em seu smartphone, ele está na pasta AlcoolGasolinaSetup/Release.

Requisitos:

O código é bem simples, o valor do litro do álcool é dividido pelo valor do litro da gasolina, se o resultado for maior ou igual a 0,7 compensa abastecer com gasolina, caso contrário, abasteça com álcool.

   1:  using System;
   2:  using System.Text;
   3:  using System.Windows.Forms;
   4:   
   5:  namespace AlcoolGasolina
   6:  {
   7:      public partial class frmPrincipal : Form
   8:      {
   9:          public frmPrincipal()
  10:          {
  11:              InitializeComponent();
  12:          }
  13:   
  14:          /// <summary>
  15:          /// Método de validação da entrada. Considera inválidos strings vazias e 
  16:          /// valores menores ou iguais a zero.
  17:          /// </summary>
  18:          /// <param name="valor">O valor de entrada, formato string</param>
  19:          /// <returns>True para válido, False para inválido.</returns>
  20:          private bool isValid(string valor)
  21:          {
  22:              // Não deve ser uma string vazia ou nula
  23:              if (String.IsNullOrEmpty(valor))
  24:                  return false;
  25:              try
  26:              {
  27:                  // deve ser um valor numérico válido
  28:                  double num = Convert.ToDouble(valor);
  29:   
  30:                  // não deve ser menor ou igual a zero
  31:                  if (num > 0)
  32:                      return true;
  33:                  else
  34:                      return false;
  35:              }
  36:              catch (Exception)
  37:              {
  38:                  return false;
  39:              }
  40:          }
  41:   
  42:          /// <summary>
  43:          /// Verifica se os valores digitados são válidos e, em caso positivo, 
  44:          /// faz o cálculo e apresenta a mensagem para o usuário informando
  45:          /// qual é mais viável abastecer, álcool ou gasolina. Se os valores 
  46:          /// não forem válidos para o cálculo, será exibida uma mensagem de 
  47:          /// alerta, informando que os valores de entrada são inválidos.
  48:          /// </summary>
  49:          /// <param name="sender"></param>
  50:          /// <param name="e"></param>
  51:          private void btnCalcular_Click(object sender, EventArgs e)
  52:          {
  53:              if (isValid(txtAlcool.Text.Trim()) && isValid(txtGasolina.Text.Trim()))
  54:              {
  55:                  double alcool = Convert.ToDouble(txtAlcool.Text.Trim());
  56:                  double gasolina = Convert.ToDouble(txtGasolina.Text.Trim());
  57:   
  58:                  double resultado = alcool / gasolina;
  59:                  if (resultado >= 0.7)
  60:                      lblResultado.Text = "Abasteça com Gasolina";
  61:                  else
  62:                      lblResultado.Text = "Abasteça com Álcool";
  63:              }
  64:              else
  65:              {
  66:                  MessageBox.Show("Valores de entrada inválidos.", 
  67:                                  "Erro", 
  68:                                  MessageBoxButtons.OK, 
  69:                                  MessageBoxIcon.Exclamation, 
  70:                                  MessageBoxDefaultButton.Button1);
  71:              }
  72:              txtAlcool.Text = string.Empty;
  73:              txtGasolina.Text = string.Empty;
  74:          }
  75:   
  76:          /// <summary>
  77:          /// Fecha a aplicação.
  78:          /// </summary>
  79:          private void mnuSair_Click(object sender, EventArgs e)
  80:          {
  81:              Application.Exit();
  82:          }
  83:   
  84:          /// <summary>
  85:          /// Menu "Sobre...", exibe uma mensagem com o nome da aplicação, 
  86:          /// nome do autor e endereço do blog do autor.
  87:          /// </summary>
  88:          private void mnuSobre_Click(object sender, EventArgs e)
  89:          {
  90:              StringBuilder mensagem = new StringBuilder("Álcool ou Gasolina\n\n");
  91:              mensagem.Append("Por Rogério Bragil\n\nBlog do Bragil - www.bragil.net");
  92:              MessageBox.Show(mensagem.ToString(), 
  93:                              "Sobre", 
  94:                              MessageBoxButtons.OK, 
  95:                              MessageBoxIcon.None, 
  96:                              MessageBoxDefaultButton.Button1);
  97:          }
  98:      }
  99:  }

 

 


Posted in: .Net , C# , Windows Mobile  Tags: , ,

Comments


December 28. 2009 02:08
personal loans
my God, i thought you were going to chip in with some decisive insght at the end there, not leave it with "we leave it to you to decide".

http://www.globalpaydayloans.com/http://www.globalpaydayloans.com/


January 9. 2010 10:00
home medical supply
Very good and detailed post there OP. Apprecaiate the time you put into this.

http://www.jamesbingham.info/cheap-littmann-stethoscopes.phphttp://www.jamesbingham.info/cheap-littmann-stethoscopes.php


January 13. 2010 14:39
married to the mob clothing line
Thanks for this great post. I have implemented it like your post says.

http://www.actonroad.info/married-to-the-mob-clothing-line.phphttp://www.actonroad.info/married-to-the-mob-clothing-line.php


January 29. 2010 14:07
iredale cosmetics
Menschen mitgefohlt habe der mit roten Flecken vorne gestanden ist und sein Referat gehalten hat.

http://www.elmesthorpelane.info/oily-hair-loss.phphttp://www.elmesthorpelane.info/oily-hair-loss.php


January 31. 2010 14:48
mineral make up
Menschen mitgefohlt habe der mit roten Flecken vorne gestanden ist und sein Referat gehalten hat.

http://www.mikehinton.info/kinerase-c6.phphttp://www.mikehinton.info/kinerase-c6.php


February 9. 2010 11:31
payday loans
You made some good points there. I searched this topic and found out that most people will agree with your blog.

http://www.globalpaydayloans.com/http://www.globalpaydayloans.com/


February 11. 2010 14:02
teeth whitening
This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.

http://www.super-teeth-whitening.net/http://www.super-teeth-whitening.net/


February 14. 2010 00:59
Colon cleansers
Interesting article. Were did you got all the information from? Anyway thank you for this great post!

http://www.super-colon-cleanses.com/http://www.super-colon-cleanses.com/


February 20. 2010 06:16
Acne treatment
I don't like your template but your posts are quite good so I will check back!

http://www.super-acne-treatment.com/http://www.super-acne-treatment.com/


February 21. 2010 08:44
does is clinical skin care work
Fantastic post I hope you dont mind if I link to it from my does is clinical skin care work website.

http://www.matthewbaichu.info/does-is-clinical-skin-care-work.phphttp://www.matthewbaichu.info/does-is-clinical-skin-care-work.php


February 25. 2010 10:00
paydayloans
Found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later ..

http://www.sonicloans.net/http://www.sonicloans.net/


February 25. 2010 15:25
payday loans
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

http://www.sonicloans.net/http://www.sonicloans.net/


February 27. 2010 06:37
cash advance
Your blog is so informative … keep up the good work!!!!

http://www.flyingloans.com/http://www.flyingloans.com/


February 27. 2010 09:49
cash advance
As a Noob, I am always seeking online for articles that can help me. Thank you

http://www.flyingloans.com/http://www.flyingloans.com/

Páginas

Calendário

«  September 2010  »
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
View posts in large calendar