private void DefinAgua(object sender, RoutedEventArgs e) { if ( pegaCopo.Text == "" && pegaTotal.Text == "" ) { MessageBox.Show("Informações Inválidas!!! Preencha os campos primeiro", "BebaAguaAPP", MessageBoxButton.OK, MessageBoxImage.Information); } else if ( pegaCopo.Text == "" || pegaTotal.Text == "") { MessageBox.Show("Informações Inválidas!!! Preencha todos os campos", "BebaAguaAPP", MessageBoxButton.OK, MessageBoxImage.Information); } else { MainWindow.copoml = int.Parse(pegaCopo.Text); MainWindow.totalml = int.Parse(pegaTotal.Text); if (MainWindow.copoml > 2000 && MainWindow.totalml > 10000 || MainWindow.copoml > 2000 || MainWindow.totalml > 10000) { MessageBox.Show("Informações Inválidas o copo tem que ser até 2 litros e o total até 10 litros!!!", "BebaAguaAPP", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Configurações Atualizadas com sucesso!!", "BebaAguaAPP", MessageBoxButton.OK, MessageBoxImage.Information); try { DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.ValorCopo = pegaCopo.Text; dad.ValorTotal = pegaTotal.Text; dad.Contador = MainWindow.contador.ToString(); DalHelper.Update(dad); pegaTotal.Text = ""; pegaCopo.Text = ""; } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } Close(); } } }
private void BtnAtualizarDados(object sender, RoutedEventArgs e) { try { DadosAgua dad = new DadosAgua(); dad.Id = Convert.ToInt32(txtID.Text); dad.ValorCopo = txtValorCopo.Text; dad.ValorTotal = txtValorTotal.Text; dad.Contador = txtContador.Text; DalHelper.Update(dad); ExibirDados(); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } }
public static void Update2(DadosAgua dadosAgua) { try { using (var cmd = new SQLiteCommand(DbConnection())) { if (dadosAgua.Id != null) { cmd.CommandText = "UPDATE DadosAgua SET Contador=@Contador WHERE Id=@Id"; cmd.Parameters.AddWithValue("@Id", dadosAgua.Id); cmd.Parameters.AddWithValue("@Contador", dadosAgua.Contador); cmd.ExecuteNonQuery(); } }; } catch (Exception ex) { throw ex; } }
private void ResetarAgua(object sender, RoutedEventArgs e) { // if (pegaAgua.Text == "" && copoml == 0 && totalml == 0 || pegaAgua.Text != "" && copoml == 0 && totalml == 0 || pegaAgua.Text != "" // && copoml != 0 && totalml != 0 && contador == 0) // { // MessageBox.Show("Defina as Configurações Primeiro!!!", "BebaAguaAPP", MessageBoxButton.OK, MessageBoxImage.Information); // } // else { try { DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.Contador = "0"; dad.PegaAguaValor = "0"; DalHelper.Update2(dad); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } contador = 0; textContador.Text = "0"; carinha.Source = (ImageSource)Resources["triste"]; }
public static void Add(DadosAgua dadosAgua) { try { using (var cmd = DbConnection().CreateCommand()) { cmd.CommandText = "INSERT INTO DadosAgua(id, ValorCopo, ValorTotal, Contador, carinha, Data, Hora) values (@id, @Valorcopo, @ValorTotal, @Contador, @carinha, @Data, @Hora)"; cmd.Parameters.AddWithValue("@Id", dadosAgua.Id); cmd.Parameters.AddWithValue("@ValorCopo", dadosAgua.ValorCopo); cmd.Parameters.AddWithValue("@ValorTotal", dadosAgua.ValorTotal); cmd.Parameters.AddWithValue("@Contador", dadosAgua.Contador); cmd.Parameters.AddWithValue("@carinha", dadosAgua.carinha); cmd.Parameters.AddWithValue("@Data", dadosAgua.Data); cmd.Parameters.AddWithValue("@Hora", dadosAgua.Hora); cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } }
public void PegarAgua(object sender, RoutedEventArgs e) { //if (pegaAgua.Text == "" || copoml == 0 && totalml == 0) // { // MessageBox.Show("Defina as Configurações Primeiro!!!", "BebaAguaAPP", MessageBoxButton.OK, MessageBoxImage.Information); // } // else // { // Pegaaguavalor = int.Parse(this.pegaAgua.Text) + Pegaaguavalor; contador = contador + copoml; textContador.Text = contador.ToString(); try { DadosAgua dad = new DadosAgua(); dad.Contador = contador.ToString(); dad.ValorCopo = copoml.ToString(); dad.ValorTotal = totalml.ToString(); dad.carinha = "triste"; dad.Data = getData; dad.Hora = getHora; DalHelper.Add(dad); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } if (contador < totalml / 2) { carinha.Source = (ImageSource)Resources["triste"]; DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.carinha = "triste"; DalHelper.Update3(dad); Notifica(mensagem2); } if (contador == totalml / 2) { carinha.Source = (ImageSource)Resources["zen1"]; DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.carinha = "zen1"; DalHelper.Update3(dad); Notifica(mensagem3); } if (contador > totalml / 2 && contador < totalml) { carinha.Source = (ImageSource)Resources["zen2"]; DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.carinha = "zen2"; DalHelper.Update3(dad); Notifica(mensagem4); } if (contador >= totalml && contador < totalml * 2) { carinha.Source = (ImageSource)Resources["haha"]; DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.carinha = "haha"; DalHelper.Update3(dad); Notifica(mensagem5); } if (contador >= totalml * 2) { carinha.Source = (ImageSource)Resources["wow"]; DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.carinha = "wow"; DalHelper.Update3(dad); Notifica(mensagem6); } if (contador >= 10000) { contador = 10000; try { DadosAgua dad = new DadosAgua(); sqliteConnection = new SQLiteConnection("Data Source=.\\dados\\DadosAgua.db; Version=3;"); sqliteConnection.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * from DadosAgua", sqliteConnection); SQLiteDataReader da = cmd.ExecuteReader(); while (da.Read()) { lastID = Convert.ToInt32(da.GetValue(0)); } dad.Id = lastID; dad.Contador = "10000"; DalHelper.Update2(dad); dad.carinha = "wow"; DalHelper.Update3(dad); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } textContador.Text = "10000"; carinha.Source = (ImageSource)Resources["wow"]; } }