-
Notifications
You must be signed in to change notification settings - Fork 0
/
frm_cardapio.cs
311 lines (246 loc) · 11.6 KB
/
frm_cardapio.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using MySql.Data.MySqlClient;
namespace Animal_System
{
public partial class frm_cardapio : Form
{
public frm_cardapio()
{
InitializeComponent();
}
string alter = "";
private void frm_cardapio_Load(object sender, EventArgs e)
{
if (Cardapio.cod > 0)
{
string sc = "Database=animal system; Data Source=127.0.0.1; Port=3306; User Id=root; Password= ;";
MySqlConnection conexao;
MySqlCommand comando;
MySqlDataReader dr = null;
// Conexão do banco de dados
conexao = new MySqlConnection(sc);
// Abre a conexão
conexao.Open();
comando = new MySqlCommand("SELECT * FROM cardapio WHERE cod_cardapio = @cod_cardapio", conexao);
comando.Parameters.AddWithValue("@cod_cardapio", Cardapio.cod);
// Executa o comando SQL
dr = comando.ExecuteReader();
while (dr.Read())
{
txt_codigo.Text = dr["cod_cardapio"].ToString();
txt_nome.Text = dr["nome_alimento"].ToString();
txt_quantidade.Text = dr["quantidade"].ToString();
cb_unidade.Text = dr["unidade"].ToString();
cb_tipoalimento.Text = dr["tipo_cardapio"].ToString();
}
// Fecha a conexão
conexao.Close();
alter = "OK";
}
else { alter = ""; }
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image.Tag = openFileDialog1.FileName;
pictureBox1.Refresh();
}
}
private void button2_Click(object sender, EventArgs e)
{
string MessageBoxTitle = "Cancelar";
string MessageBoxContent = "Deseja Cancelar?";
DialogResult dialogResult = MessageBox.Show(MessageBoxContent, MessageBoxTitle, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
MessageBox.Show("Cancelando !!!");
Close();
}
else if (dialogResult == DialogResult.No)
{
//do something else
}
}
private void button3_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void btn_pesquisar_Click(object sender, EventArgs e)
{
Cardapio consulta = new Cardapio();
consulta.Show();
}
private void cb_tipoalimento_SelectedIndexChanged(object sender, EventArgs e)
{
cb_tipoalimento.Items.Add("Grupo1(Cereais");
cb_tipoalimento.Items.Add("Grupo2(Raizes)");
cb_tipoalimento.Items.Add("Grupo3(Pães e Massa)");
cb_tipoalimento.Items.Add("Grupo4(Frutas)");
cb_tipoalimento.Items.Add("Grupo5(Verduras)");
cb_tipoalimento.Items.Add("Grupo6(Leguminosos)");
cb_tipoalimento.Items.Add("Grupo7(Carnes/Feijão/Ovo)");
cb_tipoalimento.Items.Add("Grupo8(Leites e Derivados)");
cb_tipoalimento.Items.Add("Grupo9(Doces e açucares)");
cb_tipoalimento.Items.Add("Grupo9(Óleos e Gorduras)");
cb_tipoalimento.Items.Add("Grupo9(Hortaliças)");
}
private void button3_Click_1(object sender, EventArgs e)
{
Close();
}
private void btn_novo_Click(object sender, EventArgs e)
{
btn_novo.Enabled = false;
button1.Enabled = false;
txt_codigo.Clear();
txt_nome.Clear();
txt_quantidade.Clear();
}
private void button1_Click_1(object sender, EventArgs e)
{
cb_unidade.Items.Add("UNI");
cb_unidade.Items.Add("KG");
cb_unidade.Items.Add("PC");
cb_unidade.Items.Add("CX");
cb_unidade.Items.Add("PAR");
cb_unidade.Items.Add("ML");
cb_unidade.Items.Add("MRT");
cb_unidade.Items.Add("MT2");
cb_unidade.Items.Add("MT3");
cb_unidade.Items.Add("MIL");
cb_unidade.Items.Add("BAR");
cb_unidade.Items.Add("LTR");
cb_unidade.Items.Add("PCT");
cb_unidade.Items.Add("CNJ");
cb_unidade.Items.Add("PAC");
cb_tipoalimento.Items.Add("Cereais");
cb_tipoalimento.Items.Add("Raízes");
cb_tipoalimento.Items.Add("Pães e Massa");
cb_tipoalimento.Items.Add("Frutas");
cb_tipoalimento.Items.Add("Verduras");
cb_tipoalimento.Items.Add("Leguminosos");
cb_tipoalimento.Items.Add("Carnes/Feijão/Ovo");
cb_tipoalimento.Items.Add("Leites e Derivados");
cb_tipoalimento.Items.Add("Doces e Açucares");
cb_tipoalimento.Items.Add("Óleos e Gorduras");
cb_tipoalimento.Items.Add("Hortaliças");
string string_de_conexao = " Database=animal system; Data Source=127.0.0.1; Port=3306; User Id=root; Password= ;";
MySqlConnection conexao;
MySqlCommand comando;
// Conexão do banco de dados
conexao = new MySqlConnection(string_de_conexao);
// Abre a conexão
conexao.Open();
if (alter == "OK")
{
comando = new MySqlCommand("UPDATE cardapio SET tipo_cardapio = @tipo_cardapio ,quantidade = @quantidade,unidade = @unidade,nome_alimento = @nome_alimento WHERE cod_cardapio = @cod_cardapio ", conexao);
}
else
{
comando = new MySqlCommand("insert into cardapio(cod_cardapio,tipo_cardapio,quantidade,unidade,nome_alimento,imagem,tipo_cardapio2,tipo_cardapio3,tipo_cardapio4,quantidade2,quantidade3,quantidade4,unidade2,unidade3,unidade4,nome_alimento2,nome_alimento3,nome_alimento4,imagem2,imagem3,imagem4) values (@cod_cardapio,@tipo_cardapio,@quantidade,@unidade,@nome_alimento,@imagem,@tipo_cardapio2,@tipo_cardapio3,@tipo_cardapio4,@quantidade2,@quantidade3,@quantidade4,@unidade2,@unidade3,@unidade4,@nome_alimento2,@nome_alimento3,@nome_alimento4,@imagem2,@imagem3,@imagem4) ", conexao);
}
comando.Parameters.AddWithValue("@cod_cardapio", txt_codigo.Text);
comando.Parameters.AddWithValue("@tipo_cardapio", cb_tipoalimento.Text);
comando.Parameters.AddWithValue("@quantidade", txt_quantidade.Text);
comando.Parameters.AddWithValue("@unidade", cb_unidade.Text);
comando.Parameters.AddWithValue("@nome_alimento", txt_nome.Text);
comando.Parameters.AddWithValue("@imagem", pictureBox1.Image.Tag);
comando.Parameters.AddWithValue("@tipo_cardapio2", comboBox2.Text);
comando.Parameters.AddWithValue("@tipo_cardapio3", comboBox4.Text);
comando.Parameters.AddWithValue("@tipo_cardapio4", comboBox6.Text);
comando.Parameters.AddWithValue("@quantidade2", maskedTextBox1.Text);
comando.Parameters.AddWithValue("@quantidade3", maskedTextBox2.Text);
comando.Parameters.AddWithValue("@quantidade4", maskedTextBox3.Text);
comando.Parameters.AddWithValue("@unidade2", comboBox1.Text);
comando.Parameters.AddWithValue("@unidade3", comboBox3.Text);
comando.Parameters.AddWithValue("@unidade4", comboBox5.Text);
comando.Parameters.AddWithValue("@nome_alimento2", textBox1.Text);
comando.Parameters.AddWithValue("@nome_alimento3", textBox2.Text);
comando.Parameters.AddWithValue("@nome_alimento4", textBox3.Text);
comando.Parameters.AddWithValue("@imagem2", pictureBox2.Image.Tag);
comando.Parameters.AddWithValue("@imagem3", pictureBox3.Image.Tag);
comando.Parameters.AddWithValue("@imagem4", pictureBox4.Image.Tag);
// Executa o comando SQL
comando.ExecuteNonQuery();
// Fecha a conexão
conexao.Close();
alter = "";
Cardapio.cod = 0;
// Apresentando a mensagem de cadastro com sucesso
MessageBox.Show("Contato cadastrado com sucesso!");
}
private void button2_Click_1(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image.Tag = openFileDialog1.FileName;
pictureBox1.Refresh();
}
}
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog2.InitialDirectory = "c:\\";
openFileDialog2.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
openFileDialog2.FilterIndex = 2;
openFileDialog2.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox2.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox2.Image.Tag = openFileDialog1.FileName;
pictureBox2.Refresh();
}
}
private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog3.InitialDirectory = "c:\\";
openFileDialog3.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
openFileDialog3.FilterIndex = 2;
openFileDialog3.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox3.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox3.Image.Tag = openFileDialog1.FileName;
pictureBox3.Refresh();
}
}
private void button6_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog4.InitialDirectory = "c:\\";
openFileDialog4.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
openFileDialog4.FilterIndex = 2;
openFileDialog4.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox4.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox4.Image.Tag = openFileDialog1.FileName;
pictureBox4.Refresh();
}
}
}
}