private void lblLanche_MouseDoubleClick(object sender, MouseButtonEventArgs e) { ModelReceita r = new ModelReceita(); r = dao.Selection(lblLanche.Content.ToString()); ViewCadastro c = new ViewCadastro(r); c.ShowDialog(); }
private void Bebidas_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (TableBebidas(0) != null) { ModelReceita r = new ModelReceita(); r = dao.Selection(TableBebidas(0)); ViewCadastro c = new ViewCadastro(r); c.ShowDialog(); tblBebidas.ItemsSource = dao.CarregarReceitas(receita.Tipo); } }
private void btnViewLanche_Click(object sender, RoutedEventArgs e) { if (TableLanches(0) != null) { ModelReceita r = new ModelReceita(); r = dao.Selection(TableLanches(0)); ViewCadastro c = new ViewCadastro(r); c.ShowDialog(); tblLanches.ItemsSource = dao.CarregarReceitas(receita.Tipo); } }
public bool CadastroReceita(ModelReceita receita) { bool i = false; try { string sql = @"insert into tbl_receita(receita_ingrediente1, receita_ingrediente2, receita_ingrediente3, receita_ingrediente4, receita_ingrediente5, receita_ingrediente6, receita_ingrediente7, receita_ingrediente8, receita_ingrediente9, receita_ingrediente10, receita_titulo, receita_preparo, receita_tipo, receita_rendimento, receita_tempoPreparo, receita_custoTotal) values('" + receita.Ingrediente1 + "', '" + receita.Ingrediente2 + "', '" + receita.Ingrediente3 + "', '" + receita.Ingrediente4 + "', '" + receita.Ingrediente5 + "', '" + receita.Ingrediente6 + "', '" + receita.Ingrediente7 + "', '" + receita.Ingrediente8 + "', '" + receita.Ingrediente9 + "', '" + receita.Ingrediente10 + "', '" + receita.Titulo + "', '" + receita.Preparo + "', '" + receita.Tipo + "', '" + receita.Rendimento + "', '" + receita.TempoPreparo + "', '" + receita.CustoTotal + "');"; con = ConnectionFactory.Connection(); con.Open(); MySqlCommand cmd = new MySqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); sql = "select receita_titulo from tbl_receita where receita_titulo = '" + receita.Titulo + "';"; con.Open(); cmd = new MySqlCommand(sql, con); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { i = true; } else { i = false; } } catch (MySqlException e) { MessageBox.Show("Algo errado aconteceu durante o cadastro. Por favor, tente novamente mais tarde.", "Erro!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); throw new Exception(e.Message); } finally { con.Close(); } return(i); }
public ModelReceita Selection(string titulo) { ModelReceita receita = new ModelReceita(); string sql = @"select receita_ingrediente1, receita_ingrediente2, receita_ingrediente3, receita_ingrediente4, receita_ingrediente5, receita_ingrediente6, receita_ingrediente7, receita_ingrediente8, receita_ingrediente9, receita_ingrediente10, receita_titulo, receita_preparo, receita_tipo, receita_rendimento, receita_tempoPreparo, receita_custoTotal from tbl_receita where receita_titulo = '" + titulo + "';"; con = ConnectionFactory.Connection(); try { con.Open(); MySqlCommand cmd = new MySqlCommand(sql, con); MySqlDataReader dt = cmd.ExecuteReader(); if (dt.Read()) { receita.Ingrediente1 = dt.GetString("receita_ingrediente1"); receita.Ingrediente2 = dt.GetString("receita_ingrediente2"); receita.Ingrediente3 = dt.GetString("receita_ingrediente3"); receita.Ingrediente4 = dt.GetString("receita_ingrediente4"); receita.Ingrediente5 = dt.GetString("receita_ingrediente5"); receita.Ingrediente6 = dt.GetString("receita_ingrediente6"); receita.Ingrediente7 = dt.GetString("receita_ingrediente7"); receita.Ingrediente8 = dt.GetString("receita_ingrediente8"); receita.Ingrediente9 = dt.GetString("receita_ingrediente9"); receita.Ingrediente10 = dt.GetString("receita_ingrediente10"); receita.Titulo = dt.GetString("receita_titulo"); receita.Preparo = dt.GetString("receita_preparo"); receita.Tipo = dt.GetString("receita_tipo"); receita.Rendimento = dt.GetString("receita_rendimento"); receita.TempoPreparo = dt.GetString("receita_tempoPreparo"); receita.CustoTotal = dt.GetString("receita_custoTotal"); } con.Close(); } catch (MySqlException e) { MessageBox.Show("Algo errado aconteceu durante a seleção. Por favor, tente novamente mais tarde.", "Erro!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); throw new Exception(e.Message); } return(receita); }
public List <ModelReceita> CarregarReceitas(string tipo) { List <ModelReceita> x = new List <ModelReceita>(); try { string sql = "select receita_titulo, receita_rendimento, receita_tempoPreparo, receita_custoTotal from tbl_receita where receita_tipo = '" + tipo + "';"; con = ConnectionFactory.Connection(); MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); MySqlDataReader dtreader = cmd.ExecuteReader(); while (dtreader.Read())//If there's any data. { ModelReceita receita = new ModelReceita(); receita.Titulo = dtreader.GetString("receita_titulo"); receita.Rendimento = dtreader.GetString("receita_rendimento"); receita.TempoPreparo = dtreader.GetString("receita_tempoPreparo"); receita.CustoTotal = dtreader.GetString("receita_custoTotal"); x.Add(receita); } con.Close(); } catch (MySqlException e) { MessageBox.Show("Algo errado aconteceu ao as receitas. Por favor, tente novamente mais tarde.", "Erro!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); throw new Exception(e.Message); } return(x); }
internal ViewCadastro(ModelReceita receita) { InitializeComponent(); txtIngrediente1.IsEnabled = false; txtIngrediente2.IsEnabled = false; txtIngrediente3.IsEnabled = false; txtIngrediente4.IsEnabled = false; txtIngrediente5.IsEnabled = false; txtIngrediente6.IsEnabled = false; txtIngrediente7.IsEnabled = false; txtIngrediente8.IsEnabled = false; txtIngrediente8.IsEnabled = false; txtIngrediente9.IsEnabled = false; txtIngrediente10.IsEnabled = false; txtModoDePreparo.IsEnabled = true; txtRendimento.IsEnabled = false; txtTitulo.IsEnabled = false; txtTempoPreparo.IsEnabled = false; txtCustoTotal.IsEnabled = false; imgReceita.Visibility = Visibility.Hidden; btnSelecionar.Visibility = Visibility.Hidden; txtIngrediente1.Text = receita.Ingrediente1; txtIngrediente2.Text = receita.Ingrediente2; txtIngrediente3.Text = receita.Ingrediente3; txtIngrediente4.Text = receita.Ingrediente4; txtIngrediente5.Text = receita.Ingrediente5; txtIngrediente6.Text = receita.Ingrediente6; txtIngrediente7.Text = receita.Ingrediente7; txtIngrediente8.Text = receita.Ingrediente8; txtIngrediente9.Text = receita.Ingrediente9; txtIngrediente10.Text = receita.Ingrediente10; txtModoDePreparo.Text = receita.Preparo; txtRendimento.Text = receita.Rendimento; txtTitulo.Text = receita.Titulo; txtTempoPreparo.Text = receita.TempoPreparo; txtCustoTotal.Text = receita.CustoTotal; btnCadastrar.IsEnabled = false; btnCancelar.IsEnabled = false; btnSelecionar.IsEnabled = false; if (receita.Tipo == "Doce") { rdbtn_Doce.IsChecked = true; } else if (receita.Tipo == "Salgado") { rdbtn_Salgado.IsChecked = true; } else if (receita.Tipo == "Lanche") { rdbtn_Lanche.IsChecked = true; } else if (receita.Tipo == "Bebida") { rdbtn_Bebida.IsChecked = true; } if (!System.IO.File.Exists(@"C:\CookYourself\" + receita.Titulo + ".png")) { //The image does not exists. } else { if (System.IO.File.Exists(@"C:\CookYourself\" + receita.Titulo + "Temp.png")) { File.Copy(@"C:\CookYourself\" + receita.Titulo + ".png", @"C:\CookYourself\" + receita.Titulo + "Temp" + y + ".png", true); if (System.IO.File.Exists(@"C:\CookYourself\" + receita.Titulo + "Temp" + y + ".png")) { y = Directory.GetFiles(@"C:\CookYourself\", "*", SearchOption.TopDirectoryOnly).Length; y++; File.Copy(@"C:\CookYourself\" + receita.Titulo + ".png", @"C:\CookYourself\" + receita.Titulo + "Temp" + y + ".png", true); ImageBrush ib = new ImageBrush(); ib.ImageSource = new BitmapImage(new Uri(@"C:\CookYourself\" + receita.Titulo + "Temp" + y + ".png", UriKind.Relative)); Cadastro.Background = ib; } } else { File.Copy(@"C:\CookYourself\" + receita.Titulo + ".png", @"C:\CookYourself\" + receita.Titulo + "Temp.png", true); ImageBrush ib = new ImageBrush(); ib.ImageSource = new BitmapImage(new Uri(@"C:\CookYourself\" + receita.Titulo + "Temp.png", UriKind.Relative)); Cadastro.Background = ib; } } }