-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuc_cli.c
executable file
·464 lines (350 loc) · 14.5 KB
/
fuc_cli.c
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#include <mysql/mysql.h>
#include <gtk/gtk.h>
#include "layout.h"
#include "lay_lista_cli.h"
#include "lay_det_cli.h"
#include "con.h"
#include "datausuario.h"
#include "nume.h"
//enum{ CODCLI_COL,NOMECLI_COL,CPFCLI_COL,CIDCLI_COL,NUM_COLS};
enum
{
COL_DATA,COL_DESCVE,COL_VALORI,COL_VALORR,COL_DATAEFE,COL_PAR,COL_ICO,COL_COR,NUM_COL
};
int scliente(GtkWidget *entri, gpointer treecli){
gchar *s;
s = (gchar*)gtk_entry_get_text(GTK_ENTRY(entri));
gtk_tree_store_clear(treecli);
MYSQL_RES *resp;
MYSQL_ROW linhas;
char sql[ 1000 ];
sprintf(sql,"SELECT * FROM tb_clientes WHERE nome_cliente LIKE '%%%s%%';",s);
GtkTreeIter iter;
if (mysql_query(&conexao,sql))
g_print("Erro: %s\n",mysql_error(&conexao));
else
{
resp = mysql_store_result(&conexao);//recebe a consulta
if (resp) //se houver consulta
{
while ((linhas=mysql_fetch_row(resp)) != NULL) //enquanto linhas for diferente de nulo faca
{
gtk_tree_store_append (treecli, &iter, NULL); //pega interator do tree
gtk_tree_store_set (treecli, &iter,
CODCLI_COL, linhas[0],
NOMECLI_COL, linhas[1],
CPFCLI_COL, linhas[10],
CIDCLI_COL,linhas[5],
-1);
}
}
mysql_free_result(resp);//limpa a variável do resultado: resp
}
sprintf(sql,"SELECT * FROM tb_clientes WHERE cpf_cliente LIKE '%%%s%%'AND nome_cliente NOT LIKE '%%%s%%';",s,s);
if (mysql_query(&conexao,sql))
g_print("Erro: %s\n",mysql_error(&conexao));
else {
resp = mysql_store_result(&conexao);//recebe a consulta
if (resp) //se houver consulta
{
while ((linhas=mysql_fetch_row(resp)) != NULL) //enquanto linhas for diferente de nulo faca
{
gtk_tree_store_append (treecli, &iter, NULL); //pega interator do tree
gtk_tree_store_set (treecli, &iter,
CODCLI_COL, linhas[0],
NOMECLI_COL, linhas[1],
CPFCLI_COL, linhas[10],
CIDCLI_COL,linhas[5],
-1);
}
}
mysql_free_result(resp);//limpa a variável do resultado: resp
}
return 0;
}
int updatecliente(char dcampo[], char valorup[],char codclic[]){
// MYSQL_RES *resp;
// MYSQL_ROW linhas;
char sql[1000];
sprintf(sql,"UPDATE tb_clientes SET %s ='%s' WHERE cod_cliente='%s';",dcampo,valorup,codclic);
//g_print("texto passado = %s\n%d\n",codclic,campo);
g_print("%s\n\n",sql);
if (mysql_query(&conexao,sql))
g_print("Erro: %s\n",mysql_error(&conexao));
else
{
sprintf(sql," ");
//mysql_free_result(resp);//limpa a variável do resultado: resp
}
return 0;
}
char* lastnewcliente(void){
char sql[1000];
char* s;
MYSQL_RES *resp;
MYSQL_ROW linhas;
//int lastid;
sprintf(sql,"INSERT INTO `tb_clientes` (`cod_cliente` ,`nome_cliente` ,`ed_cliente` ,`num_end_cliente` ,`bairro_cliente` ,`cidade_cliente` ,`uf_cliente` ,`tel1_cliente` ,`tel2_cliente` ,`dtnasc_cliente` ,`cpf_cliente` ,`rg_cliente` ,`email_cliente` ,`obs_cliente`)VALUES (NULL , '','', '', '', '', '', '', '', '', '111.111.111-11', '', '', '');");
mysql_query(&conexao,sql);
///g_print("Last inserted record has id %d\n", (int)mysql_insert_id(&conexao));
sprintf(sql,"SELECT * FROM tb_clientes WHERE cpf_cliente LIKE '111.111.111-11';");
if (mysql_query(&conexao,sql))
g_print("Erro: %s\n",mysql_error(&conexao));
else
{
resp = mysql_store_result(&conexao);//recebe a consulta
if (resp) //se houver consulta
{
while ((linhas=mysql_fetch_row(resp)) != NULL) //enquanto linhas for diferente de nulo faca
{
s = linhas[0];
}
}
mysql_free_result(resp);//limpa a variável do resultado: resp
}
return (s);
}
char* dadoscliente (char codclid[], int campo){
//g_print("codclid e campo = %s\n%d\n",codclid,campo);
MYSQL_RES *resp;
MYSQL_ROW linhas;
char sql[1000];
char* tex ="";
sprintf(sql,"SELECT * FROM tb_clientes WHERE cod_cliente LIKE '%s';",codclid);
if (mysql_query(&conexao,sql))
g_print("Erro: %s\n",mysql_error(&conexao));
else
{
resp = mysql_store_result(&conexao);//recebe a consulta
if (resp) //se houver consulta
{
while ((linhas=mysql_fetch_row(resp)) != NULL) //enquanto linhas for diferente de nulo faca
{
tex = linhas[campo];
}
}
mysql_free_result(resp);//limpa a variável do resultado: resp
}
return (tex);
}
int apagacli(char codcli[]){
char sql[1000];
g_print("cliente numeto %s apagado .\n",codcli );
sprintf(sql,"DELETE FROM tb_clientes WHERE `cod_cliente` LIKE '%s' ",codcli);
//g_print("texto passado = %s\n%d\n",codclic,campo);
//g_print("%s\n",sql);
if (mysql_query(&conexao,sql))
g_print("Erro: %s\n",mysql_error(&conexao));
else
{
sprintf(sql," ");
}
//g_print("todos os pagamentos do cliente %s apagados .\n",codcli );
//sprintf(sql,"DELETE FROM tb_cheques WHERE `idcliente` LIKE '%s' ",codcli);
//g_print("texto passado = %s\n%d\n",codclic,campo);
//g_print("%s\n",sql);
// if (mysql_query(&conexao,sql)){
// g_print("Erro: %s\n",mysql_error(&conexao));
// else
// {
//sprintf(sql," ");
// }
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////
GtkListStore * create_liststore(char clicod[])
{
GtkListStore *store;
GtkTreeIter iter;
GdkPixbuf *icon;
GError *error = NULL;
gchar *s;
GdkColor color;
//gboolean success;
s = (gchar*)clicod;
//gtk_tree_store_clear(&store);
store = gtk_list_store_new(NUM_COL,G_TYPE_STRING, G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,GDK_TYPE_PIXBUF,GDK_TYPE_COLOR);
MYSQL_RES *resp;
MYSQL_ROW linhas;
char sql[ 1000 ];
sprintf(sql,"SELECT * FROM tb_payment WHERE cod_cliente LIKE '%%%s%%' AND numemp LIKE '%%%d%%' ; ",s,numep());
if (mysql_query(&conexao,sql))
g_print("Erro: %s\n",mysql_error(&conexao));
else
{
resp = mysql_store_result(&conexao);//recebe a consulta
if (resp) //se houver consulta
{
while ((linhas=mysql_fetch_row(resp)) != NULL) //enquanto linhas for diferente de nulo faca
{
//int ano,mes,dia,hora,min,seg;
int codmov;
//codmov = linhas[11];
sscanf(linhas[11],"%d",&codmov);
char data[20],datae[20];
int ano,mes,dia,hora,min,seg;
sscanf(linhas[8],"%d-%d-%d %d:%d:%d",&ano,&mes,&dia,&hora,&min,&seg);
sprintf(data,"%d/%d/%d",dia,mes,ano);
sscanf(linhas[7],"%d-%d-%d %d:%d:%d",&ano,&mes,&dia,&hora,&min,&seg);
sprintf(datae,"%d/%d/%d",dia,mes,ano);
MYSQL_RES *respe;
MYSQL_ROW linhase;
char sqle[1000];
char descmov[100];
sprintf(sqle,"SELECT * FROM tb_cod_mov WHERE cod_mov_merc LIKE '%s';",linhas[2]);
if (mysql_query(&conexao,sqle))
g_print("Erro: %s\n",mysql_error(&conexao));
else
{
respe = mysql_store_result(&conexao);//recebe a consulta
if (respe) //se houver consulta
{
while ((linhase=mysql_fetch_row(respe)) != NULL) //enquanto linhas for diferente de nulo faca
{
sprintf( descmov,"%s",linhase[1]);
}
}
mysql_free_result(respe);//limpa a variável do resultado: resp
}
if(codmov == 1)
{
icon = gdk_pixbuf_new_from_file("imagens/share.png", &error);//35535,65333,15000
color.red = 65535;
color.blue = 47424;
color.green = 65535;
if (error)
{
g_warning ("Could not load icon: %s\n", error->message);
g_error_free(error);
error = NULL;
}
}
else if (codmov == 2 )
{
icon = gdk_pixbuf_new_from_file("imagens/tick_32.png", &error);
color.red = 62194;
color.blue = 58596;
color.green = 65535;
if (error)
{
g_warning ("Could not load icon: %s\n", error->message);
g_error_free(error);
error = NULL;
}
}
else
{
icon = gdk_pixbuf_new_from_file("imagens/warning_32.png", &error);
color.red = 60762;
color.blue = 21242;
color.green = 21242;
if (error)
{
g_warning ("Could not load icon: %s\n", error->message);
g_error_free(error);
error = NULL;
}
}
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,COL_DATA,data,COL_DESCVE,descmov,COL_VALORI,linhas[5],COL_VALORR,linhas[10],COL_DATAEFE,datae,COL_PAR,linhas[6],COL_ICO,icon,COL_COR,&color,-1);
}
}
mysql_free_result(resp);//limpa a variável do resultado: resp
}
return store;
}
/**************************************************************
*
* create_treeview
*
**************************************************************/
GtkWidget *
create_treeview(char clicod[])
{
GtkTreeModel *model;
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
GtkWidget *view;
model = GTK_TREE_MODEL(create_liststore(clicod));
view = gtk_tree_view_new_with_model(model);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Data inic");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_set_attributes(col, renderer,
"text", COL_DATA,"cell-background-gdk", COL_COR,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
/* 2nd column */
///gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "descrição ");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_set_attributes(col, renderer,
"text", COL_DESCVE,"cell-background-gdk", COL_COR,
NULL);
// "cell-background-gdk" GdkColor*
//"foreground-gdk"
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
/* 3 column */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "valor ");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_set_attributes(col, renderer,
"text", COL_VALORI,"cell-background-gdk", COL_COR,
NULL);
// "cell-background-gdk" GdkColor*
//"foreground-gdk"
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
/* 4nd column */
///gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Data efetuada ");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_set_attributes(col, renderer,
"text", COL_DATAEFE,"cell-background-gdk", COL_COR,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
// "cell-background-gdk" GdkColor*
//"foreground-gdk"
/* 5nd column */
///gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "valor realizado ");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_set_attributes(col, renderer,
"text", COL_VALORR,"cell-background-gdk", COL_COR,
NULL);
// "cell-background-gdk" GdkColor*
//"foreground-gdk"
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
/* 6nd column */
///gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "parc ");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_set_attributes(col, renderer,
"text", COL_PAR,"cell-background-gdk", COL_COR,
NULL);
// "cell-background-gdk" GdkColor*
//"foreground-gdk"
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "st");
renderer = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_column_pack_start(col, renderer, FALSE);
gtk_tree_view_column_set_attributes(col, renderer,
"pixbuf", COL_ICO,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
return view;
}
int listpgclientecod (gpointer swp ,char clicod[]){
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swp),create_treeview(clicod));
return 0;
}