/
Form1.cs
127 lines (105 loc) · 3.58 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FireSharp.Config;
using FireSharp.Interfaces;
using FireSharp.Response;
namespace testefirebase
{
public partial class Form1 : Form
{
IFirebaseConfig config = new FirebaseConfig
{
AuthSecret = "X30A726Yojr4KcC6fyHubhnHgOqIMZXNytwaQ7bq",
BasePath = "https://testerecuperacao-590b8.firebaseio.com/"
};
IFirebaseClient client;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
client = new FireSharp.FirebaseClient(config);
if(client!=null)
{
MessageBox.Show("Conectado ao banco");
}
}
private async void button1_Click(object sender, EventArgs e)
{
var data = new Data
{
Nome = textBox1.Text,
Categoria = textBox2.Text,
Rendimento = textBox3.Text,
TempoPreparo = textBox4.Text,
Ingredientes = textBox5.Text,
ModoPreparo = textBox6.Text
};
SetResponse response = await client.SetTaskAsync("Information/" + textBox1.Text, data);
Data result = response.ResultAs<Data>();
MessageBox.Show("Receita Cadastrada!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
}
private async void button2_Click(object sender, EventArgs e)
{
FirebaseResponse response = await client.GetTaskAsync("Information/" + textBox1.Text);
Data obj = response.ResultAs<Data>();
textBox1.Text = obj.Nome;
textBox2.Text = obj.Categoria;
textBox3.Text = obj.Rendimento;
textBox4.Text = obj.TempoPreparo;
textBox5.Text = obj.Ingredientes;
textBox6.Text = obj.ModoPreparo;
MessageBox.Show("Busca realizada!");
}
private async void button3_Click(object sender, EventArgs e)
{
var data = new Data
{
Nome = textBox1.Text,
Categoria = textBox2.Text,
Rendimento = textBox3.Text,
TempoPreparo = textBox4.Text,
Ingredientes = textBox5.Text,
ModoPreparo = textBox6.Text
};
FirebaseResponse response = await client.UpdateTaskAsync("Information/" + textBox1.Text, data);
Data result = response.ResultAs<Data>();
MessageBox.Show("Atualização concluida!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
}
private async void button4_Click(object sender, EventArgs e)
{
FirebaseResponse response = await client.DeleteTaskAsync("Information/" + textBox1.Text);
MessageBox.Show("Receita excluida com sucesso!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
}
private void button5_Click(object sender, EventArgs e)
{
Close();
}
}
}