-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_FIND.CPP
4327 lines (3766 loc) · 166 KB
/
GS_FIND.CPP
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************
Name:
Module description: Funzioni di filtro per estrazione oggetti
e altre funzioni varie
Author: Roberto Poltini & Paolo Carlio
(c) Copyright 1995-2015 by IREN ACQUA GAS S.p.A.
Modification history:
Notes and restrictions on use:
**********************************************************/
/*********************************************************/
/* INCLUDES */
/*********************************************************/
#include "stdafx.h" // MFC core and standard components
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <math.h>
#include <ctype.h> /* per isdigit() */
#include <fcntl.h>
#include <string.h> /* per strcat() strcmp() */
#include "rxdefs.h"
#include "adslib.h"
#include <adeads.h>
#include "adsdlg.h"
#include "GSresource.h"
#include "..\gs_def.h" // definizioni globali
#include "gs_error.h" // codici errori
#include "gs_resbf.h" // gestione resbuf
#include "gs_utily.h"
#include "gs_list.h" // gestione liste C++
#include "gs_ase.h"
#include "gs_dbref.h"
#include "gs_class.h"
#include "gs_lisp.h"
#include "gs_init.h"
#include "gs_area.h"
#include "gs_query.h"
#include "gs_thm.h" // gestione tematismi e sistemi di coordinate
#include "gs_filtr.h"
#include "gs_evid.h"
#include "gs_find.h"
#include "gs_ade.h"
#include "d2hMap.h" // doc to help
/*************************************************************************/
/* STRUTTURE PER IL PASSAGGIO VALORI FRA DCL */
/*************************************************************************/
struct Common_Dcl_main_Sql_Addr_Struct
{
int all_sel;
int all_sel_der;
int sql_punt;
int sql_ind;
int num_cls;
int n_pag;
int cat;
int tp_like;
int query_flag;
TCHAR sql_statement[MAX_LEN_SQL_STM];
TCHAR sql_field[MAX_LEN_SQL_STM];
TCHAR sql_order[MAX_LEN_SQL_STM];
TCHAR sql_via_text[MAX_LEN_SQL_STM];
TCHAR sql_civ_text[MAX_LEN_SQL_STM];
C_STRING sql_via_cod;
C_STRING sql_civ_cod;
C_CLASS *filter_cls;
C_CLASS *sql_cls;
C_CLASS *sql_cplx;
C_ATTRIB_LIST *attr_list;
C_2LONG_STR_LIST list_class_to_visual;
C_INT_INT_STR_LIST sql_list;
C_STR_LIST cls_name;
C_STR_LIST list_field_sql;
C_STR_LIST list_field_sql_addr;
C_RB_LIST last_point;
C_RB_LIST sql_risult;
C_RB_LIST list_field;
C_RB_LIST n_classi;
C_RB_LIST ris_sql_civ;
};
/*************************************************************************/
/* PRIVATE FUNCTIONS */
/*************************************************************************/
int gsc_filter_fas(C_CLASS *pCls, int md);
int gsc_filter_sql(C_CLASS *pCls, C_INT_INT_STR_LIST *sql_list, int tipo,
Common_Dcl_main_Sql_Addr_Struct *CommonStruct);
TCHAR *gsc_sql_bldqry(C_CLASS *pCls, TCHAR *in, int mod);
TCHAR *gsc_adr_bldqry(Common_Dcl_main_Sql_Addr_Struct *CommonStruct,
C_CLASS *pCls, TCHAR *in, TCHAR *via, TCHAR *civ);
int gsc_find_addr(Common_Dcl_main_Sql_Addr_Struct *CommonStruct);
int gsc_setGraphSettingsToCurrentADEQry(long flag_set, C_CLASS *pCls, C_FAS &FAS);
int gsc_get_oldusrfas(C_CLASS *pCls, C_FAS_LIST *fasList, C_FAS &FAS);
int gsc_impost_estrqry(int cls, int sub, int mod);
int gsc_find_elements(C_CLASS *pCls, C_STR_LIST *fields, TCHAR *condsql, TCHAR *condorder,
Common_Dcl_main_Sql_Addr_Struct *CommonStruct, C_RB_LIST &result_list);
int gsc_lista_val(C_RB_LIST *lista, int pos, int passo,
Common_Dcl_main_Sql_Addr_Struct *CommonStruct);
int gsc_lista_civici(C_RB_LIST *lista, int pos, ads_callback_packet *dcl,
Common_Dcl_main_Sql_Addr_Struct *CommonStruct);
int gsc_do_sql_addr(int cls, int sub, TCHAR *condition);
int gsc_extract_coord(C_RB_LIST *lista, int all_sel_der);
int gsc_calc_min_dist(C_RB_LIST lista_coord[2], ads_point p1, ads_point p2);
int gsc_calc_pnt_min_max(C_RB_LIST lista_coord[2], ads_point p1, ads_point p2);
int gsc_impost_win(ads_point p1, ads_point p2, int clsp, int clsd);
int gsc_zoom_win(TCHAR *filep, ads_point p1, ads_point p2);
int gsc_lista_classi(int prj, C_SINTH_CLASS_LIST *list_class,
Common_Dcl_main_Sql_Addr_Struct *CommonStruct);
int gsc_string_arrange(int *pos, int cntf, C_STRING *strng, C_RB_LIST *lista_val,
int spost);
int gsc_string_confirm(C_STRING *strng, C_RB_LIST *lista_val,
int posi = GS_BAD , int passo = GS_BAD);
int gsc_find_cls_env(int prj, Common_Dcl_main_Sql_Addr_Struct *CommonStruct);
int gsc_visual_list(ads_hdlg dcl_id, TCHAR *namelist, C_2LONG_STR_LIST &ListClassToVisual);
///////////////////////////////////////////////////////////////////////////
/*
Questa funzione imposta una condizione di SQL su una classe del progetto al
fine di estrarre dal disegno gli oggetti che la soddisfano. E' invocata dal
LISP con parametri di passaggio <cod.prj> <cod.cls>.
Restituisce una lista ad autocad nel seguente formato
((<cls><sql><sub>)...)
*/
///////////////////////////////////////////////////////////////////////////
int gs_filter_sql(void)
{
int prj, cls, sub;
C_INT_INT_STR_LIST sql_list;
C_CLASS *pCls;
C_STRING SQL;
presbuf arg;
C_RB_LIST ret;
Common_Dcl_main_Sql_Addr_Struct CommonStruct;
acedRetNil();
// Legge nella lista dei parametri: progetto classe e sub //
arg = acedGetArgs();
if (arg == NULL) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg_to_prj_cls_sub(&arg, &prj, &cls, &sub) == GS_BAD) return RTERROR;
// Ritorna il puntatore alla classe cercata //
if ((pCls = gsc_find_class(prj, cls, sub)) == NULL) return RTERROR;
// Compongo l'istruzione SQL
CommonStruct.sql_cls = pCls;
if (gsc_filter_sql(pCls, &sql_list, 1, &CommonStruct) == GS_BAD) return RTERROR;
// Verifico se esiste una condizione di SQL non nulla
if (sql_list.get_head() && gsc_strlen(sql_list.get_head()->get_name()) > 0)
{
SQL = sql_list.get_head()->get_name();
// Salvo la condizione SQL
if (gsc_ClsSQLQrySave(cls, 0, SQL) == GS_BAD) return RTERROR;
ret << sql_list.to_rb();
ret.LspRetList();
}
// verifico se esiste già una query di SQL per la classe corrente e la cancello
else
if (gsc_ClsSQLQryDel(cls, 0) == GS_BAD) return RTERROR;
return RTNORM;
}
///////////////////////////////////////////////////////////////////////////
/*
Questa funzione permette di variare le caratteristiche grafiche di una
classe al momento della selezione della stessa prima che venga estratta.
E' invocata dal LISP con parametri di passaggio (modo prj cls [sub])
*/
///////////////////////////////////////////////////////////////////////////
int gs_filter_fas(void)
{
int ris, prj, cls, sub, modo = 0;
C_CLASS *pCls;
resbuf *arg;
acedRetNil();
arg = acedGetArgs();
if (arg == NULL || arg->restype != RTSHORT) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
else modo = arg->resval.rint;
arg = arg->rbnext;
if (arg == NULL) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg_to_prj_cls_sub(&arg, &prj, &cls, &sub)==GS_BAD) return RTERROR;
// Ritorna il puntatore alla classe cercata
if ((pCls = gsc_find_class(prj, cls, sub))==NULL) return RTERROR;
// Compongo la condizione FAS
ris = gsc_filter_fas(pCls, modo);
if (ris == GS_CAN) { acedRetNil(); return RTNORM; }
if (ris != GS_GOOD) return RTERROR;
acedRetT();
return RTNORM;
}
///////////////////////////////////////////////////////////////////////////
/*
Questa funzione imposta la defintiva query per ogni classe del progetto selezionata
al fine di estrarre dal disegno gli oggetti che la soddisfano. E' invocata dal
LISP con parametri di passaggio <tipo_fas> <cod.prj> <cod.cls>.
*/
///////////////////////////////////////////////////////////////////////////
int gs_impost_estrqry(void)
{
int ris, prj, cls, sub, modo = 0;
C_CLASS *pCls;
resbuf *arg;
acedRetNil();
arg = acedGetArgs();
if (arg == NULL || arg->restype != RTSHORT) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
else modo = arg->resval.rint;
arg = arg->rbnext;
if (arg == NULL) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg_to_prj_cls_sub(&arg,&prj,&cls,&sub)==GS_BAD) return RTERROR;
// Ritorna il puntatore alla classe cercata //
if ((pCls = gsc_find_class(prj, cls, sub))==NULL) return RTERROR;
// Compongo la condizione di estrazione
if ((ris = gsc_impost_estrqry(cls, sub, modo))!=GS_GOOD) return RTERROR;
acedRetT();
return RTNORM;
}
/*********************************************************************/
/*.doc gsc_impost_estrqry <internal> */
/*+
Questa funzione riceve num_class,sub_class,modalità e imposta la query
definitiva di estrazione FAS-SQL per ogni classe selezionata.
Parametri:
int num_class : codice class
int sub_class : codice sottoclasse
int modo : modalità di impostazione sulla classe
0 = FAS del disegno
1 = FAS dell'utente
2 = FAS di default
3 = Condizione di SQL
La funzione restituisce GS_BAD in caso di errore altrimenti GS_GOOD.
-*/
/*********************************************************************/
int gsc_impost_estrqry(int num_class, int sub_class, int md)
{
C_RB_LIST list_cat;
TCHAR qry_cat[] = _T("fasqlestr"), *str=NULL;
C_STRING query_name;
C_CLASS *pCls;
// ricavo il puntatore alla classe
pCls = gsc_find_class(GS_CURRENT_WRK_SESSION->get_PrjId(), num_class, sub_class);
switch (md)
{
case 0:
query_name = _T("fasw");
break;
case 1:
query_name = _T("fasu");
break;
case 2:
query_name = _T("fasd");
break;
case 3:
query_name = _T("sqlu");
break;
}
query_name += num_class;
query_name += _T("-");
query_name += sub_class;
if ((list_cat << ade_qllistctgy()) != NULL)
gsc_find_qry(pCls, list_cat.get_head(), qry_cat, query_name.get_name(), 1);
return GS_GOOD;
}
/*********************************************************************/
/*.doc gsc_filter_fas <external> */
/*+
Questa funzione permette di variare le caratteristiche grafiche di una
classe al momento della selezione della stessa prima che venga estratta.
Parametri:
C_CLASS *pCls; puntatore a classe
int md: flag sulle modalità della FAS; i valori di md sono:
2 = fas di default della classe;
1 = fas definita dall'utente;
0 = fas del disegno;
-1 = fas del disegno della classe senza attivazione della dcl.
La funzione restituisce GS_BAD in caso di errore altrimenti GS_GOOD.
-*/
/*********************************************************************/
int gsc_filter_fas(C_CLASS *pCls, int md)
{
int result;
int flag, categ, tipo;
long flag_set = GSNoneSetting;
C_ID *p_id;
resbuf *list_cat;
TCHAR qry_cat[] = _T("fasqlestr");
C_STRING query_name, path;
C_FAS FAS;
double dummyDbl = 0;
int dummyInt = ALL;
// verifico se esiste una query spaziale attualmente in memoria e la memorizzo
if (gsc_ExistCurrentAdeQry() == GS_GOOD)
{
gsc_ade_qldelquery(ADE_SPATIAL_QRY_NAME);
if (gsc_save_qry() == GS_BAD)
return GS_BAD;
}
switch (md)
{
case 0:
case -1:
query_name = _T("fasw");
break;
case 1:
query_name = _T("fasu");
break;
case 2:
query_name = _T("fasd");
break;
}
query_name += pCls->ptr_id()->code;
query_name += _T("-");
query_name += pCls->ptr_id()->sub_code;
p_id = pCls->ptr_id();
categ = p_id->category;
tipo = p_id->type;
if (md <= 0)
{ // FAS disegno (DWG) (pulisco tutto ed esco)
if (ade_altpclear() != RTNORM) return GS_BAD;
if (ade_qryclear() != RTNORM) return GS_BAD;
gsc_save_qry(qry_cat, query_name.get_name());
return GS_GOOD;
}
// carico la fas di default
if (md > 0)
pCls->ptr_fas()->copy(&FAS);
// se modo = 2 (caratteristiche di default)
if (md == 2)
{
// leggo quali caratteristiche grafiche si possono modificare
flag_set = pCls->what_is_graph_updateable();
// imposto la classe a NULL per evitare che si possano modificare
// le opzioni di evidenziazione
result = gsc_ddChooseGraphSettings(NULL, FALSE, &flag_set, FAS,
&dummyDbl, &dummyInt, FALSE);
// rileggo quali caratteristiche grafiche si possono modificare
flag_set = pCls->what_is_graph_updateable();
}
else
{
// per scelta user vedo se esiste già una query impostata
if (md == 1) // fas definita dall'utente al momento
{
if ((list_cat = ade_qllistctgy()) != NULL)
{
// Carico la query
flag = gsc_find_qry(pCls, list_cat, qry_cat, query_name.get_name(), 2);
if (flag == 1)
// recupero i nuovi valori impostati
if (gsc_getGraphSettingsFromCurrentADEQry(FAS, &flag_set) == NULL)
return GS_BAD;
}
}
result = gsc_ddChooseGraphSettings(pCls, FALSE, &flag_set, FAS,
&dummyDbl, &dummyInt, FALSE);
}
if (result == GS_GOOD)
{
result = gsc_setGraphSettingsToCurrentADEQry(flag_set, pCls, FAS);
gsc_save_qry(qry_cat, query_name.get_name());
}
return result;
}
/***************************************************************************/
/*.doc gsc_get_oldusrfas <external> */
/*+
Questa funzione recupera la fas di default di una classe.
Parametri:
C_CLASS *pCls : puntatore a classe;
C_FAS_LIST *fasList : puntatore alla lista fas della classe;
C_FAS &FAS; : caratteristiche grafiche delle classe (out);
La funzione restituisce GS_BAD in caso di errore altrimenti GS_GOOD.
-*/
/***************************************************************************/
int gsc_get_oldusrfas(C_CLASS *pCls, C_FAS_LIST *fasList, C_FAS &FAS)
{
C_CLASS *mother_cls = NULL;
C_STRING name_layer;
if (!pCls) return GS_BAD;
if (!(pCls->ptr_fas())) { GS_ERR_COD = eGSInvClassType; return GS_BAD; }
if (fasList->get_count() == 0) // fasList vuota: ricavo la fas di default
{ // inserisco la fas della classe nella lista per non perdere dati successivamente
C_FAS *p_FAS = new C_FAS();
pCls->ptr_fas()->copy(p_FAS);
fasList->add_tail(p_FAS);
}
((C_FAS *) fasList->getptr_at(1))->copy(&FAS);
// se la classe che sto trattando è una sottoclasse ricavo il puntatore alla classe madre
if (pCls->ptr_id()->sub_code != 0)
if ((mother_cls = gsc_find_class(((C_PROJECT *) pCls->ptr_id()->pPrj)->get_key(),
pCls->ptr_id()->code)) == NULL) return GS_BAD;
// se sto usando la funzione durante la copia delle classi inizializzo il nome
// del piano della sottoclasse come 'nome_classe + nome_sottoclasse'
if (mother_cls != NULL)
{
name_layer.clear();
name_layer += mother_cls->get_name();
if (mother_cls->get_category() == CAT_EXTERN)
{
name_layer += _T("_");
name_layer += pCls->get_name();
}
gsc_strcpy(FAS.layer, name_layer.get_name(), MAX_LEN_LAYERNAME);
}
return GS_GOOD;
}
///////////////////////////////////////////////
// ACTION TILE : click su slider per address //
///////////////////////////////////////////////
static void CALLB dcl_address_slidqry(ads_callback_packet *dcl)
{
ads_hdlg hdlg = dcl->dialog;
C_STR *node1;
C_INT_INT_STR *node2;
TCHAR str[MAX_LEN_SQL_STM + MAX_LEN_CLASSNAME + 10], val[30];
TCHAR Buffer[MAX_LEN_SQL_STM + MAX_LEN_CLASSNAME + 10];
size_t len = MAX_LEN_SQL_STM + MAX_LEN_CLASSNAME + 10, offset;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
ads_get_tile(hdlg, _T("slidqry"), val, 30);
offset = _wtoi(val);
ads_start_list(hdlg, _T("listqry"), LIST_NEW, 0);
node1 = (C_STR*)CommonStruct->cls_name.get_head();
node2 = (C_INT_INT_STR*)CommonStruct->sql_list.get_head();
while(node1 != NULL && node2 != NULL)
{
if (len > node1->len() + node2->len())
{
swprintf(str, MAX_LEN_SQL_STM + MAX_LEN_CLASSNAME + 10, _T("%s\t:\t%s"),
node1->get_name(), node2->get_name());
if (((int) wcslen(str)) > offset)
wcscpy(Buffer, str + offset);
else
wcscpy(Buffer, GS_EMPTYSTR);
gsc_add_list(Buffer);
}
node1 = (C_STR*)node1->get_next();
node2 = (C_INT_INT_STR*)node2->get_next();
}
ads_end_list();
swprintf(val, 30, _T("%d"), CommonStruct->sql_punt);
ads_set_tile(hdlg, _T("listqry"), val);
}
///////////////////////////////////////////////
// ACTION TILE : click su slider lista campi //
///////////////////////////////////////////////
static void CALLB dcl_filter_slidfield(ads_callback_packet *dcl)
{
ads_hdlg hdlg = dcl->dialog;
int i, k, cnte, cnti, passo, pos;
TCHAR val[30];
C_STRING stringa;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
pos = _wtoi(dcl->value);
cnte = CommonStruct->list_field.GetCount() - 2;
cnti = CommonStruct->list_field_sql.get_count();
passo = (cnti * 4) + 2;
i = CommonStruct->n_pag * 50 * passo + 5;
// costruisco la lista di valori shiftati e riempio la list box
ads_start_list(hdlg, _T("liststreet"), LIST_NEW, 0);
CommonStruct->list_field.getptr_at(i);
do
{
if (gsc_string_arrange(&i, cnti, &stringa, &CommonStruct->list_field, pos) == GS_BAD) return;
gsc_add_list(stringa);
for (k = 0; k < 6; k++) { CommonStruct->list_field.get_next(); i++; }
}
while (i < (CommonStruct->n_pag + 1) * 50 * passo + 5 && i <= cnte);
ads_end_list();
swprintf(val, 30, _T("%d"), 0);
ads_set_tile(hdlg, _T("liststreet"), val);
ads_mode_tile(hdlg, _T("liststreet"), MODE_SETFOCUS);
}
///////////////////////////////////////////////
// ACTION TILE : click su pagina su //
///////////////////////////////////////////////
static void CALLB dcl_filter_up(ads_callback_packet *dcl)
{
ads_hdlg hdlg = dcl->dialog;
int k, i, cnte, cnti, passo;
TCHAR val[30];
C_STRING stringa;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
cnte = CommonStruct->list_field.GetCount()-2;
cnti = CommonStruct->list_field_sql.get_count();
passo = (cnti * 4) + 2;
if (CommonStruct->n_pag > 0) CommonStruct->n_pag--;
i = CommonStruct->n_pag * 50 * passo + 5;
// costruisco la lista di valori shiftati indietro di 50 riempio la list box
ads_start_list(hdlg, _T("liststreet"), LIST_NEW, 0);
CommonStruct->list_field.getptr_at(i);
do
{
if (gsc_string_arrange(&i, cnti, &stringa, &CommonStruct->list_field, 0) == GS_BAD) return;
gsc_add_list(stringa);
for (k = 0; k < 6; k++) { CommonStruct->list_field.get_next(); i++; }
}
while (i < (CommonStruct->n_pag + 1) * 50 * passo + 5 && i <= cnte);
ads_end_list();
swprintf(val, 30, _T("%d"), 0);
ads_set_tile(hdlg, _T("liststreet"), val);
ads_mode_tile(hdlg, _T("liststreet"), MODE_SETFOCUS);
}
///////////////////////////////////////////////
// ACTION TILE : click su pagina giù //
///////////////////////////////////////////////
static void CALLB dcl_filter_down(ads_callback_packet *dcl)
{
ads_hdlg hdlg = dcl->dialog;
int i, k, cnte, cnti, passo, npag;
TCHAR val[30];
C_STRING stringa;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
cnte = CommonStruct->list_field.GetCount() - 2;
cnti = CommonStruct->list_field_sql.get_count();
passo = (cnti * 4) + 2;
npag = (int) floor((double) (cnte / (50 * passo)));
// costruisco la lista di valori shiftati avanti di 50 e riempio la list box
ads_start_list(hdlg, _T("liststreet"), LIST_NEW, 0);
if (npag == 1) i = 5;
else
{
if (CommonStruct->n_pag < npag) CommonStruct->n_pag++;
i = CommonStruct->n_pag * 50 * passo + 5;
}
CommonStruct->list_field.getptr_at(i);
do
{
if (gsc_string_arrange(&i, cnti, &stringa, &CommonStruct->list_field, 0) == GS_BAD) return;
gsc_add_list(stringa);
for (k = 0; k < 6; k++) { CommonStruct->list_field.get_next(); i++; }
}
while (i < (CommonStruct->n_pag + 1) * 50 * passo + 5 && i <= cnte);
ads_end_list();
swprintf(val, 30, _T("%d"), 0);
ads_set_tile(hdlg, _T("liststreet"), val);
ads_mode_tile(hdlg, _T("liststreet"), MODE_SETFOCUS);
}
///////////////////////////////////////////////
// ACTION TILE : click su fine lista //
///////////////////////////////////////////////
static void CALLB dcl_filter_end(ads_callback_packet *dcl)
{
ads_hdlg hdlg = dcl->dialog;
int i, k, cnte, cnti, passo, npag;
TCHAR val[30];
C_STRING stringa;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
cnte = CommonStruct->list_field.GetCount()-2;
cnti = CommonStruct->list_field_sql.get_count();
passo = (cnti * 4) + 2;
npag = (int) floor((double) (cnte / (50 * passo)));
// costruisco la lista degli ultimi 50 valori e riempio la list box
ads_start_list(hdlg, _T("liststreet"), LIST_NEW, 0);
// controllo se la lista ha meno di 50 elementi
if (npag == 1) CommonStruct->n_pag = 0;
else CommonStruct->n_pag = npag;
i = CommonStruct->n_pag * 50 * passo + 5;
CommonStruct->list_field.getptr_at(i);
do
{
if (gsc_string_arrange(&i, cnti, &stringa, &CommonStruct->list_field, 0) == GS_BAD) return;
gsc_add_list(stringa);
for (k = 0; k < 6; k++) { CommonStruct->list_field.get_next(); i++; }
}
while (i < (CommonStruct->n_pag + 1) * 50 * passo + 5 && i <= cnte);
ads_end_list();
swprintf(val, 30, _T("%d"), 0);
ads_set_tile(hdlg, _T("liststreet"), val);
ads_mode_tile(hdlg, _T("liststreet"), MODE_SETFOCUS);
}
///////////////////////////////////////////////
// ACTION TILE : click su selezione globale //
///////////////////////////////////////////////
static void CALLB dcl_filter_allsel(ads_callback_packet *dcl)
{
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
CommonStruct->all_sel = 1;
}
///////////////////////////////////////////////
// ACTION TILE : click su seleziona singola //
///////////////////////////////////////////////
static void CALLB dcl_filter_multsel(ads_callback_packet *dcl)
{
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
CommonStruct->all_sel = 0;
}
/////////////////////////////////////////////////////////////////////
// ACTION TILE : click su selezione globale per la classe derivata //
/////////////////////////////////////////////////////////////////////
static void CALLB dcl_filter_globsel(ads_callback_packet *dcl)
{
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
CommonStruct->all_sel_der = 1;
}
/////////////////////////////////////////////////////////////////////
// ACTION TILE : click su selezione singola per la classe derivata //
/////////////////////////////////////////////////////////////////////
static void CALLB dcl_filter_singsel(ads_callback_packet *dcl)
{
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
CommonStruct->all_sel_der = 0;
}
///////////////////////////////////////////////
// ACTION TILE : click su inizio lista //
///////////////////////////////////////////////
static void CALLB dcl_filter_start(ads_callback_packet *dcl)
{
ads_hdlg hdlg = dcl->dialog;
int i, k, cnte, cnti, passo;
TCHAR val[30];
C_STRING stringa;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
cnte = CommonStruct->list_field.GetCount() - 2;
cnti = CommonStruct->list_field_sql.get_count();
passo = (cnti * 4) + 2;
// costruisco la lista di valori shiftati avanti di 50 e riempio la list box
ads_start_list(hdlg, _T("liststreet"), LIST_NEW, 0);
CommonStruct->n_pag = 0;
i = 5;
CommonStruct->list_field.getptr_at(i);
do
{
if (gsc_string_arrange(&i, cnti, &stringa, &CommonStruct->list_field, 0) == GS_BAD) return;
gsc_add_list(stringa);
for (k = 0; k < 6; k++) { CommonStruct->list_field.get_next(); i++; }
}
while (i < 5 + 50 * passo && i <= cnte);
ads_end_list();
swprintf(val, 30, _T("%d"), 0);
ads_set_tile(hdlg, _T("liststreet"), val);
ads_mode_tile(hdlg, _T("liststreet"), MODE_SETFOCUS);
}
//////////////////////////////////////////////////////////
// ACTION TILE : click su lista attributi per indirizzo //
//////////////////////////////////////////////////////////
static void CALLB dcl_address_listqry(ads_callback_packet *dcl)
{
ads_hdlg hdlg = dcl->dialog;
TCHAR *str, val[30];
TCHAR ind[MAX_LEN_CLASSNAME] = GS_EMPTYSTR, vie[MAX_LEN_CLASSNAME] = GS_EMPTYSTR;
TCHAR civ[MAX_LEN_CLASSNAME]= GS_EMPTYSTR;
C_STRING filename;
C_CLASS_LIST *clslist;
C_INT_STR_LIST lista_classe;
C_CLASS *cls;
C_STR *punt1, *nod;
C_NODE *punt, *cpunt;
C_INT_INT_STR *punt2, *punt3;
FILE *f;
ads_callback_packet temp;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
CommonStruct->sql_ind = 0;
CommonStruct->sql_punt = _wtoi(dcl->value);
if (dcl->reason == CBR_DOUBLE_CLICK)
{
punt1 = (C_STR*)CommonStruct->cls_name.getptr_at(CommonStruct->sql_punt+1);
punt2 = (C_INT_INT_STR*)CommonStruct->sql_list.getptr_at(CommonStruct->sql_punt+1);
clslist = GS_CURRENT_WRK_SESSION->get_pPrj()->ptr_classlist();
CommonStruct->num_cls = punt2->get_key(); // righe da verificare
punt3 = (C_INT_INT_STR*)CommonStruct->sql_list.get_head();
punt3 = (C_INT_INT_STR*)punt3->get_next();
while(punt3 != NULL)
{
if (punt3->get_key() != CommonStruct->num_cls)
{
CommonStruct->num_cls = punt3->get_key();
break;
}
punt3 = (C_INT_INT_STR*)punt3->get_next();
}
if ((cls = (C_CLASS*)clslist->search_name(punt1->get_name())) == NULL)
{
gsc_toupper(punt1->get_name());
if ((cls = (C_CLASS*)clslist->search_name(punt1->get_name())) == NULL)
return; // $$$ aggiungere segnalazione di errore
}
// verifico se la classe scelta è del tipo 'indirizzi' da trattarsi
// in modo particolare
filename = GS_CURRENT_WRK_SESSION->get_pPrj()->get_dir();
filename += _T("\\ADDRESS.TXT");
// verifico se esiste il file address.txt che contiene tutte le terne di gruppi
// di tipo 'indirizzo'
if ((gsc_path_exist(filename)) == GS_GOOD)
{
bool Unicode;
C_STRING Row;
if ((f = gsc_fopen(filename, _T("r"), MORETESTS, &Unicode)) == NULL) return;
// costruisco la lista delle classi elencate nel file
while (gsc_readline(f, Row, Unicode) != WEOF)
{
if ((nod = new C_INT_STR) == NULL) { GS_ERR_COD=eGSOutOfMem; return; }
lista_classe.add_tail(nod);
if ((cpunt = (C_NODE*) clslist->getptr_at(clslist->getpos_name(Row.get_name(), FALSE))) != NULL)
nod->set_key(cpunt->get_key());
else
nod->set_key(0);
Row.toupper();
if (nod->set_name(Row.get_name()) == GS_BAD) return;
}
gsc_fclose(f);
// cerco nella lista la terna dei valori corrispondenti
punt = lista_classe.get_head();
wcscpy(ind, CommonStruct->sql_cplx->get_name());
gsc_toupper(ind);
while (punt)
{
if ((gsc_strcmp(punt->get_name(), ind)) == 0)
{ // ho trovato il gruppo indirizzo che cercavo
if((punt = punt->get_next()) == NULL) return; // errore da segnalare
gsc_toupper(cls->get_name());
if ((gsc_strcmp(punt->get_name(), cls->get_name())) != 0) return; // errore da segn.
wcscpy(vie, cls->get_name());
if((punt = punt->get_next()) == NULL) return; // errore da segnalare
wcscpy(civ, punt->get_name());
CommonStruct->num_cls = punt->get_key();
CommonStruct->sql_ind = 1;
break;
}
punt = punt->get_next();
}
}
TCHAR dummy[MAX_LEN_SQL_STM];
wcscpy(dummy, CommonStruct->sql_statement);
if ((str = gsc_adr_bldqry(CommonStruct, cls, dummy, vie, civ)) != NULL)
{
if ((CommonStruct->sql_ind != 1) && (CommonStruct->cat != CAT_GROUP))
{ punt2->set_name(str); free(str); }
}
else
if (gsc_strcmp(cls->get_name(), civ) == 0)
ads_set_tile(hdlg, _T("error"), gsc_msg(366)); // "Impostare prima la Via ..."
swprintf(val, 30, _T("%d"), 1);
temp.value = val;
temp.dialog = hdlg;
temp.client_data = CommonStruct;
ads_set_tile(hdlg, _T("slidqry"), _T("1"));
dcl_address_slidqry(&temp);
}
}
///////////////////////////////////////
// ACTION TILE : click su lista vie //
///////////////////////////////////////
static void CALLB dcl_address_liststreet(ads_callback_packet *dcl)
{
int cnte, cnti, pos, posi, posiz, passo, poscod, postxt, rispdef = 1, ris;
long codice;
ads_hdlg hdlg = dcl->dialog;
C_STRING prompt, stringa;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
posiz = _wtoi(dcl->value);
if ((dcl->reason == CBR_DOUBLE_CLICK) && (CommonStruct->all_sel == 0))
{
// cerco il campo chiave della classe
C_INFO *pInfo = CommonStruct->sql_cls->ptr_info();
cnti = CommonStruct->list_field_sql.get_count();
cnte = CommonStruct->list_field.GetCount() - 2;
passo = (cnti * 4) + 2,
poscod = (CommonStruct->list_field_sql.getpos_name(pInfo->key_attrib.get_name())-1) * 4;
posi = pos = posiz * passo + CommonStruct->n_pag * 50 * passo + 5;
if (CommonStruct->sql_ind == 1) // la classe è indirizzo
{
postxt = (CommonStruct->list_field_sql.getpos_name(_T("TEXT")) - 1) * 4;
prompt += gsc_msg(358); // "Confermare la scelta"
prompt += _T(' ');
prompt += gsc_rtrim(CommonStruct->sql_risult.getptr_at(pos + postxt)->resval.rstring);
if (gsc_ddgetconfirm(prompt.get_name(), &ris, rispdef) == GS_BAD) return;
}
else // è classe diversa da indirizzo
// compongo la stringa con i valori di tutti i campi selezionati
{
if (gsc_string_confirm(&stringa, &CommonStruct->list_field,
posi - 1, passo) == GS_BAD) return;
prompt += gsc_msg(358); // "Confermare la scelta"
prompt += _T('\n');
prompt += gsc_rtrim(stringa.get_name());
if (gsc_ddgetconfirm(prompt.get_name(), &ris, rispdef,
GS_BAD, GS_BAD, GS_GOOD) == GS_BAD) return;
}
if (ris)
{
C_INT_INT_STR *node;
CommonStruct->sql_via_cod.clear();
CommonStruct->sql_via_cod += pInfo->key_attrib.get_name();
CommonStruct->sql_via_cod += _T(" = ");
CommonStruct->sql_via_cod += CommonStruct->sql_risult.getptr_at(pos + poscod);
if (CommonStruct->sql_ind == 1) // la classe gruppo è un indirizzo
{
wcscpy(CommonStruct->sql_via_text,
CommonStruct->sql_risult.getptr_at(pos + postxt)->resval.rstring);
node=(C_INT_INT_STR*)CommonStruct->sql_list.get_head();
while(node != NULL)
{
if (node->get_key() == CommonStruct->sql_cls->get_key())
{
node->set_name(CommonStruct->sql_via_text);
break;
}
node=(C_INT_INT_STR*)node->get_next();
}
}
else // la classe è gruppo, ma non indirizzo
{
node = (C_INT_INT_STR*)CommonStruct->sql_list.get_head();
while(node != NULL)
{
if (node->get_key() == CommonStruct->sql_cls->get_key())
{
node->set_name(CommonStruct->sql_via_cod.get_name());
break;
}
node = (C_INT_INT_STR*)node->get_next();
}
}
codice = CommonStruct->sql_risult.getptr_at(pos + poscod)->resval.rlong;
CommonStruct->sql_risult << acutBuildList(RTLB, RTLB, RTLB,
RTSTR, pInfo->key_attrib.get_name(),
RTLONG, codice,
RTLE, RTLE, RTLE, 0);
ads_done_dialog(hdlg, DLGOK);
}
else ads_done_dialog(hdlg, DLGCANCEL);
}
}
///////////////////////////////////////////////////////////////////
// ACTION TILE : click su tasto OK per accettazione via da lista //
///////////////////////////////////////////////////////////////////
static void CALLB dcl_liststreet_accept_ok(ads_callback_packet *dcl)
{
int posi, postxt, poscod, posiz, passo, cnti, pos, ris, rispdef = 1;
long codice;
ads_hdlg hdlg = dcl->dialog;
TCHAR valore[10];
C_STRING prompt, stringa;
Common_Dcl_main_Sql_Addr_Struct *CommonStruct;
CommonStruct = (Common_Dcl_main_Sql_Addr_Struct*)(dcl->client_data);
if (ads_get_tile(hdlg, _T("liststreet"), valore, 10) != RTNORM) return;
else posiz = _wtoi(valore);
// cerco il campo chiave della classe
C_INFO *pInfo = CommonStruct->sql_cls->ptr_info();
cnti = CommonStruct->list_field_sql.get_count();
passo = (cnti * 4) + 2;
poscod = (CommonStruct->list_field_sql.getpos_name(pInfo->key_attrib.get_name()) - 1) * 4;
posi = pos = posiz * passo + CommonStruct->n_pag * 50 * passo + 5;
if (CommonStruct->all_sel == 0) // ho fatto una scelta univoca (Singola)
{
if (CommonStruct->sql_ind == 1) // è classe indirizzo: chiedo conferma della via
{
postxt = (CommonStruct->list_field_sql.getpos_name("TEXT") - 1) * 4;