Ejemplo n.º 1
0
 public void Initialize()
 {
     using (BombasContext context = new BombasContext())
     {
         int currentVersion = 0;
         if (context.SchemaInfoes.Count() > 0)
         {
             currentVersion = context.SchemaInfoes.Max(x => x.Version);
         }
         BombasContextHelper mmSqliteHelper = new BombasContextHelper();
         while (currentVersion < RequiredDatabaseVersion)
         {
             currentVersion++;
             foreach (string migration in mmSqliteHelper.Migrations[currentVersion])
             {
                 context.Database.ExecuteSqlCommand(migration);
             }
             context.SchemaInfoes.Add(new SchemaInfo()
             {
                 Version = currentVersion
             });
             context.SaveChanges();
         }
     }
 }
Ejemplo n.º 2
0
        private Preco fetchPreco()
        {
            Preco preco;

            using (var context = new BombasContext())
            {
                DateTime data = DateTime.Now;
                preco = context.Precos.Where(p => p.data == data.ToShortDateString()).FirstOrDefault();
            }

            return(preco);
        }
Ejemplo n.º 3
0
        private void definePreco_Click(object sender, EventArgs e)
        {
            if (precoGasolina.Text.Length > 0)
            {
                using (var context = new BombasContext())
                {
                    Preco    novoPreco = new Preco();
                    DateTime data      = DateTime.Now;
                    novoPreco.valor = Convert.ToDecimal(precoGasolina.Text);
                    novoPreco.data  = data.ToString();

                    context.Precos.Add(novoPreco);

                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 4
0
        private void salvaVenda(string valor, int bombaId)
        {
            using (var context = new BombasContext())
            {
                Preco preco = fetchPreco();
                Bomba bomba = context.Bombas.Find(bombaId);

                Venda venda = new Venda();
                venda.bomba  = bomba;
                venda.preco  = preco;
                venda.litros = Convert.ToDecimal(valor) / preco.valor;

                context.Vendas.Add(venda);

                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
 public void Initialize()
 {
     using (BombasContext context = new BombasContext())
     {
         int currentVersion = 0;
         if (context.SchemaInfoes.Count() > 0)
             currentVersion = context.SchemaInfoes.Max(x => x.Version);
         BombasContextHelper mmSqliteHelper = new BombasContextHelper();
         while (currentVersion < RequiredDatabaseVersion)
         {
             currentVersion++;
             foreach (string migration in mmSqliteHelper.Migrations[currentVersion])
             {
                 context.Database.ExecuteSqlCommand(migration);
             }
             context.SchemaInfoes.Add(new SchemaInfo() { Version = currentVersion });
             context.SaveChanges();
         }
     }
 }
Ejemplo n.º 6
0
        private void salvaVenda(string valor, int bombaId)
        {
            using (var context = new BombasContext())
            {
                Preco preco = fetchPreco();
                Bomba bomba = context.Bombas.Find(bombaId);

                Venda venda = new Venda();
                venda.bomba = bomba;
                venda.preco = preco;
                venda.litros = Convert.ToDecimal(valor) / preco.valor;

                context.Vendas.Add(venda);

                context.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        private Preco fetchPreco()
        {
            Preco preco;

            using (var context = new BombasContext())
            {
                DateTime data = DateTime.Now;
                preco = context.Precos.Where(p => p.data == data.ToShortDateString()).FirstOrDefault();
            }

            return preco;
        }
Ejemplo n.º 8
0
        private void definePreco_Click(object sender, EventArgs e)
        {
            if (precoGasolina.Text.Length > 0)
            {
                using (var context = new BombasContext())
                {
                    Preco novoPreco = new Preco();
                    DateTime data = DateTime.Now;
                    novoPreco.valor = Convert.ToDecimal(precoGasolina.Text);
                    novoPreco.data = data.ToString();

                    context.Precos.Add(novoPreco);

                    context.SaveChanges();
                }

            }
        }