/
controlAjoutAcquereur_new.ascx.cs
1073 lines (942 loc) · 44.8 KB
/
controlAjoutAcquereur_new.ascx.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
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Drawing.Imaging;
using System.Data.Odbc;
using GestionEmplacement;
using System.Data;
public partial class controlAjoutAcquereur : System.Web.UI.UserControl
{
protected int hauteur_liste = 168;
bool toutVirer = false;
protected Label LBL_nbre_bien = new Label();
//protected Panel PNL_Dist = new Panel();
//liste affiché sur le navigateur
public ListeEmplacement emplacementAffiche = new ListeEmplacement();
//liste generer a partir de emplacementAffiché a qui on retire les elements de la liste noire
//cette liste affiché dans option avancé
//permet de generer string a mettre dans les filtres de la base de donnée
//peut etre importée a partir d un fichier(contenant la dite string)
public ListeEmplacementRecherche listeVilleRecherche = new ListeEmplacementRecherche();
public ListeEmplacementRecherche listeNoire = new ListeEmplacementRecherche();
public List<Arrondissement> listeArrondissementNoire = new List<Arrondissement>();
DataRowCollection drcAideDep;
DataRowCollection drcAideVilles;
DataRowCollection drcAidePays;
DataRowCollection drcArrondissements;
string textBoxCibleAvant;
public void supprimerContinent(string continent)
{
List<Emplacement> copie = new List<Emplacement>(emplacementAffiche);
foreach (Emplacement ville in copie)
{
if (ville.Nom == continent.ToUpper())
{
emplacementAffiche.Remove(ville);
}
}
rafraichirEmplacementAffiche();
}
public void ajouterContinent(string continent)
{
string codeContinent = "";
switch(continent)
{
case "Europe" : codeContinent = "eu"; break;
case "Afrique" : codeContinent = "af"; break;
case "Asie" : codeContinent = "as"; break;
case "AmériqueN" : codeContinent = "na"; break;
case "AmériqueS" : codeContinent = "sa"; break;
case "Océanie" : codeContinent = "oc"; break;
}
Connexion c = new Connexion();
OdbcCommand commande = new OdbcCommand();
commande.CommandText = "SELECT DISTINCT Continent FROM Pays WHERE Continent = ?";
OdbcParameter paramContinent = new OdbcParameter("", DbType.String);
paramContinent.Value = continent;
commande.Parameters.Add(paramContinent);
DataRow dr = c.exeRequetteParametree(commande).Tables[0].Rows[0];
Emplacement cont = new Emplacement(false, dr["Continent"].ToString().ToUpper(), false, false, codeContinent, new ListeEmplacementRecherche());
cont.IsContinent = true;
emplacementAffiche.Add(cont);
rafraichirEmplacementAffiche();
}
public void ajouterPays(string pays)
{
pays = "'" + pays.Replace("'","''") + "'";
Connexion c = new Connexion();
OdbcCommand commande = new OdbcCommand();
commande.CommandText = "SELECT * FROM Pays WHERE Titre_Pays like " + pays;
DataRow dr = c.exeRequetteParametree(commande).Tables[0].Rows[0];
Emplacement cont = new Emplacement(false, dr["Titre_Pays"].ToString().ToUpper(), false, false, dr["Id_Pays"].ToString(), new ListeEmplacementRecherche());
cont.IsPays = true;
emplacementAffiche.Add(cont);
rafraichirEmplacementAffiche();
}
public void ajouterDepartement(string codeDep)
{
String codeDepartement;
if (codeDep.Length == 1) codeDepartement = "0" + codeDep;
else codeDepartement = codeDep;
Connexion c = new Connexion();
OdbcCommand commande = new OdbcCommand();
commande.CommandText = "select * from departement where departement_code = ?";
OdbcParameter paramCodeDep = new OdbcParameter("", DbType.String);
paramCodeDep.Value = codeDepartement;
commande.Parameters.Add(paramCodeDep);
DataRow dr = c.exeRequetteParametree(commande).Tables[0].Rows[0];
Emplacement dep = new Emplacement(true, dr["departement_nom"].ToString(), false, false, codeDep, new ListeEmplacementRecherche());
emplacementAffiche.Add(dep);
rafraichirEmplacementAffiche();
}
public void clear2(object sender, EventArgs e) {clear2();}
public void clear2()
{
//Absurdite necessaire pour que la liste de lieu se raffraichisse sans avoir a rafraichir la page
List<Emplacement> copie = new List<Emplacement>(emplacementAffiche);
foreach (Emplacement ville in copie)
{
emplacementAffiche.Remove(ville);
}
rafraichirEmplacementAffiche();
}
//Ne semble pas raffraichir la liste de recherche, vu que la variable emplacementAffiche est passe a null
public void clear()
{
Session["emplacementAffiche"] = null;
Session["drcArrondissements"] = null;
Session["drcAideVilles"] = null;
Session["drcAidePays"] = null;
Session["drcAideDep"] = null;
Session["listeNoire"] = null;
Session["listeArrondissementNoire"] = null;
listeNoire = null;
emplacementAffiche = null;
listeArrondissementNoire = null;
listeVilleRecherche = null;
rafraichirEmplacementAffiche();
}
protected void Page_Load(object sender, EventArgs e)
{
TextBoxCible.Attributes.Add("onkeyup", "rechercheDiffereeTicket()");
if (!IsPostBack && Request.Url.PathAndQuery.IndexOf("/ajout_acquereur.aspx") != -1 && Session["ajout_acquereur"] == "false")
{
Update_modifierAcquereur(sender, e);
}
if (Parent.FindControl("LBL_nbre_bien") != null) LBL_nbre_bien = (Label)Parent.FindControl("LBL_nbre_bien");
//if (Parent.FindControl("PNL_Dist") != null) PNL_Dist = (Panel)Parent.FindControl("PNL_Dist");
}
protected void Page_PreRender()
{
if (toutVirer == true)
{
//Page.ClientScript.RegisterStartupScript(GetType(), "viderTableAide", "viderTableAide();", true);
TableAideRecherche.Visible = false;
Session["TableAideRechercheVisible"] = false;
//TableAideRecherche.Rows.Clear();
}
if (emplacementAffiche != null) Session["emplacementAffiche"] = emplacementAffiche;
if (listeNoire != null) Session["listeNoire"] = listeNoire;
Session["drcAideDep"] = drcAideDep;
Session["drcAideVilles"] = drcAideVilles;
Session["drcAidePays"] = drcAidePays;
Session["drcArrondissements"] = drcArrondissements;
if (TextBoxCible.Text != null) textBoxCibleAvant = TextBoxCible.Text;
else textBoxCibleAvant = "";
if (listeArrondissementNoire != null) Session["listeArrondissementNoire"] = listeArrondissementNoire;
//Initialise les continents selectiones sur la carte
bool initContinent = false;
string jsCore = "";
foreach (Emplacement ville in emplacementAffiche)
{
if(ville.IsContinent)
{
initContinent = true;
jsCore += "WM_setSelected('" + ville.CodeINSEE + "');";
}
}
if(initContinent == true)
{
string jsInit = "$(document).ready(function(){"
+ jsCore
+"});";
ScriptManager.RegisterStartupScript(this, typeof(Page), "initContinent", jsInit, true);
}
}
protected void Page_Init(object sender, EventArgs e)
{
//Permet de reinitialiser les criteres de recherche lorsque la page charge est ajout_acquereur.aspx
//Mais de les conserver lorsqu'il s'agit de la page recherche
if(!IsPostBack && (Session["bugfix_reset"] != null || Session["bugfix_reset2"] != null))
{
Session["emplacementAffiche"] = null;
Session["drcArrondissements"] = null;
Session["drcAideVilles"] = null;
Session["drcAidePays"] = null;
Session["drcAideDep"] = null;
Session["listeNoire"] = null;
Session["listeArrondissementNoire"] = null;
if(Session["bugfix_reset"] != null) Session["bugfix_reset2"] = true;
else if (Session["bugfix_reset2"] != null) Session["bugfix_reset2"] = null;
Session["bugfix_reset"] = null;
}
//ce qui est en commentaire permet d eviter que le controleur conserve ses valeurs d une page a l autre, fonction desactivée sur demande
//if (!IsPostBack) Session["emplacementAffiche"] = null;// ici
if (Session["emplacementAffiche"] != null) emplacementAffiche = (ListeEmplacement)Session["emplacementAffiche"];
if (textBoxCibleAvant == null) textBoxCibleAvant = "";
/*if (!IsPostBack) Session["drcArrondissements"] = null;// ici
if (!IsPostBack) Session["drcAideVilles"] = null;// ici
if (!IsPostBack) Session["drcAidePays"] = null;// ici
if (!IsPostBack) Session["drcAideDep"] = null;// ici
if (!IsPostBack) Session["listeNoire"] = null;// ici*/
if (Session["listeNoire"] != null) listeNoire = (ListeEmplacementRecherche)Session["listeNoire"];
//if (!IsPostBack) Session["listeArrondissementNoire"] = null;// et ici
if (Session["listeArrondissementNoire"] != null) listeArrondissementNoire = (List<Arrondissement>)Session["listeArrondissementNoire"];
}
//Remplie les criteres de localisation avec celles de la recherche precedente
public void UpdatePanel1_Init(object sender, EventArgs e)
{
string eventTarget = this.Request.Params.Get("__EVENTTARGET");
string eventArgument = this.Request.Params.Get("__EVENTARGUMENT");
//jsp
TableAideRecherche.Rows.Clear();
if (eventTarget == TextBoxCible.UniqueID)
{
if (eventArgument != textBoxCibleAvant && eventArgument != null)
{
Session["TableAideRechercheVisible"] = true;
if (Session["drcAideContinent"] != null) Session["drcAideContinent"] = null;
if (Session["drcAideVilles"] != null) Session["drcAideVilles"] = null;
if (Session["drcAidePays"] != null) Session["drcAidePays"] = null;
if (Session["drcAideDep"] != null) Session["drcAideDep"] = null;
if (Session["drcArrondissements"] != null) Session["drcArrondissements"] = null;
string text = eventArgument;
recupererVilleOuDep(text);
}
}
remplirTableAide();
}
protected void Update_modifierAcquereur(object sender, EventArgs e)
{
//id acquereur
string idAcq = (string)Session["ajout_acquereur_id"];
string requete = "SELECT cible FROM Acquereurs WHERE `id_acq`=" + idAcq + "";
System.Data.DataSet ds = null;
Connexion c = null;
c = new Connexion(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
c.Open();
ds = c.exeRequette(requete);
c.Close();
c = null;
System.Data.DataRowCollection dr = ds.Tables[0].Rows;
Regex regexPays = new Regex("%type:pays%");
Regex regexVille = new Regex("%type:vil%");
Regex regexDep = new Regex("%type:dep%");
Regex regexArr = new Regex("%arr:");
String cibles = "";
foreach (System.Data.DataRow ligne in dr)
{
cibles = ligne["cible"].ToString();
}
string[] cible = cibles.Split('|');
int k;
ClickableTableCell cell = new ClickableTableCell();
for (int i = 0; i < cible.Length-1; i++) // i = boucle des villes ou département d'un acquereur
{
string currentCible = cible[i];
cible[i].Trim();
cible[i] = cible[i].Replace("type:pays", "");
cible[i] = cible[i].Replace("type:dep", "");
cible[i] = cible[i].Replace("type:vil", "");
string[] temp = cible[i].Split('%');
string[] cibleInfo = new string[4];
k = 0;
for (int j = 0; j < temp.Length; j++) // j = boucle des données de la ville i de l'acquereur
{
if (temp[j] != "")
{
cibleInfo[k] = temp[j];
k++;
}
}
string cibleCode = cibleInfo[0].Split(':')[1]; // code de la ville ou du département i de l'acquereur
string cibleNom = cibleInfo[1].Split(':')[1]; // nom de la ville ou du département i de l'acquereur
string cibleCP = "";
if(cibleInfo[2] != null) cibleCP = cibleInfo[2].Split(':')[1]; // CP de la ville ou du département i de l'acquereur
string cibleArr = "";
if(cibleInfo[3] != null) cibleArr = cibleInfo[3].Split(':')[1]; // Arrondissement de la ville i de l'acquereur
if(regexPays.IsMatch(currentCible))
{
List<Arrondissement> listeArrondissement = null;
ListeEmplacementRecherche listeVille = new ListeEmplacementRecherche();
Emplacement toto = new Emplacement(false, cibleNom, false, false, cibleCode, listeVille, cibleCP, 0, listeArrondissement);
toto.IsPays = true;
emplacementAffiche.Add(toto);
}
if(regexVille.IsMatch(currentCible) && !regexArr.IsMatch(currentCible))
{
List<Arrondissement> listeArrondissement = null;
ListeEmplacementRecherche listeVille = new ListeEmplacementRecherche();
Emplacement toto = new Emplacement(false, cibleNom, false, false, cibleCode, listeVille, cibleCP, 0, listeArrondissement);
emplacementAffiche.Add(toto);
}
else if (regexDep.IsMatch(currentCible))
{
List<Arrondissement> listeArrondissement = null;
ListeEmplacementRecherche listeVille = new ListeEmplacementRecherche();
Emplacement toto = new Emplacement(true, cibleNom, false, false, cibleCode, listeVille, cibleCP, 0, listeArrondissement);
emplacementAffiche.Add(toto);
}
else if (regexArr.IsMatch(currentCible))
{
List<Arrondissement> listeArrondissement = new List<Arrondissement>();
listeArrondissement = construireListeArrond(cibleCode);
ListeEmplacementRecherche listeVille = new ListeEmplacementRecherche();
Emplacement toto = new Emplacement(false, cibleNom, false, true, cibleCode, listeVille, cibleCP, 0, listeArrondissement);
toto.HasArrondissement = true;
emplacementAffiche.Add(toto);
}
}
rafraichirEmplacementAffiche();
}
//liste deroulante
protected void UpdatePanel1_Load(object sender, EventArgs e)
{
if (Session["TableAideRechercheVisible"] != null) TableAideRecherche.Visible = (bool)Session["TableAideRechercheVisible"];
int numLigne = 0;
if (Session["drcAideDep"] != null || drcAideDep != null)
{
if (drcAideDep == null) drcAideDep = (DataRowCollection)Session["drcAideDep"];
foreach (DataRow dr in drcAideDep)
{
ClickableTableCell cell = (ClickableTableCell)TableAideRecherche.Rows[numLigne].Cells[0];
cell.type = "dep";
cell.nom = dr["departement_nom"].ToString();
cell.codeVille = dr["departement_code"].ToString();
cell.Text = dr["departement_nom"] + " (" + dr["departement_code"] + ")";
cell.Click += new EventHandler(remplirListeEmplacement);
cell.Attributes.Add("runat", "server");
cell.CssClass = "cell_liste_lieu bold";
numLigne++;
}
}
if (Session["drcAidePays"] != null || drcAidePays != null)
{
if (drcAidePays == null) drcAidePays = (DataRowCollection)Session["drcAidePays"];
foreach (DataRow dr in drcAidePays)
{
ClickableTableCell cell = (ClickableTableCell)TableAideRecherche.Rows[numLigne].Cells[0];
cell.type = "pays";
cell.nom = dr["Titre_Pays"].ToString().ToUpper();
cell.codeVille = dr[0].ToString();
cell.Text = cell.nom.ToUpper();
cell.Click += new EventHandler(remplirListeEmplacement);
cell.Attributes.Add("runat", "server");
cell.CssClass = "cell_liste_lieu bold";
numLigne++;
}
}
if (Session["drcAideVilles"] != null || drcAideVilles != null)
{
if (drcAideVilles == null) drcAideVilles = (DataRowCollection)Session["drcAideVilles"];
foreach (DataRow dr in drcAideVilles)
{
ClickableTableCell cell = (ClickableTableCell)TableAideRecherche.Rows[numLigne].Cells[0];
cell.nom = dr["Nom"].ToString();
cell.CP = dr["Code Postal"].ToString();
cell.type = "ville";
cell.codeVille = dr["Code INSEE"].ToString();
cell.Text =(dr["Code Postal"].ToString().Length > 5)
? (dr["Nom"] + " (Tous codes postaux)")
: (dr["Nom"] + " (" + dr["Code Postal"] + ")");
cell.Click += new EventHandler(remplirListeEmplacement);
cell.Attributes.Add("runat", "server");
cell.CssClass = "cell_liste_lieu";
numLigne++;
}
}
if (Session["drcArrondissements"] != null || drcArrondissements != null)
{
if (drcArrondissements == null) drcArrondissements = (DataRowCollection)Session["drcArrondissements"];
foreach (DataRow dr in drcArrondissements)
{
ClickableTableCell cell = (ClickableTableCell)TableAideRecherche.Rows[numLigne].Cells[0];
cell.nom = dr["Nom"].ToString();
cell.CP = dr["Code Postal"].ToString();
cell.type = "arrondissement";
cell.codeVille = dr["VilleINSEE"].ToString();
cell.Text = dr["Nom"] + " (" + dr["Code Postal"] + ")";
cell.Click += new EventHandler(remplirListeEmplacement);
cell.Attributes.Add("runat", "server");
cell.CssClass = "cell_liste_lieu";
numLigne++;
}
}
if(numLigne<5) hauteur_liste = 22 + numLigne * 30;
rafraichirEmplacementAffiche();
}
//Requete SQL pour afficher la liste des villes/dep/pays correspondant a la saisie dans le champ cible
protected void recupererVilleOuDep(string text)
{
int num;
//si on cherche par ville/CP et distance
if (text != "")
{
OdbcCommand rechercherDep = new OdbcCommand();
OdbcCommand rechercherVille = new OdbcCommand();
OdbcCommand rechercherPays = new OdbcCommand();
OdbcCommand rechercheArrondissement = new OdbcCommand();
rechercherDep.CommandText = "";
rechercherVille.CommandText = "";
rechercherPays.CommandText = "";
rechercheArrondissement.CommandText = "";
if (Int32.TryParse(text, out num))
{
//le champ cible est un nombre
if (text.Trim().Length <= 2)//si departement
{
rechercherDep.CommandText = "select * from departement where [departement_code] like ?";
OdbcParameter paramDep = new OdbcParameter("", DbType.String);
paramDep.Value = text + "%";
rechercherDep.Parameters.Add(paramDep);
}
if (text.Trim().Length <= 5)//si code postal
{
rechercheArrondissement.CommandText = "select * from Arrondissement where [Code Postal] like ?";
OdbcParameter paramCPArr = new OdbcParameter("", DbType.String);
paramCPArr.Value = text + "%";
rechercheArrondissement.Parameters.Add(paramCPArr);
}
rechercherVille.CommandText = "select * from Ville where [Code Postal] like ? order by Nom";
OdbcParameter paramCP = new OdbcParameter("", DbType.String);
if (text.Trim().Length == 5) paramCP.Value = "%" + text + "%";
else paramCP.Value = text + "%";
rechercherVille.Parameters.Add(paramCP);
}
else //le champ cible est une string
{
//Recherche Pays
rechercherPays.CommandText = "select * from Pays where UCase(Titre_Pays) like ? order by Titre_Pays";
OdbcParameter paramPays = new OdbcParameter("", DbType.String);
paramPays.Value = "%" + text.ToUpper() + "%";
rechercherPays.Parameters.Add(paramPays);
//Recherche ville
rechercherVille.CommandText = "select * from Ville where UCase(NOM) like ? OR MAJ like ? order by Nom";
OdbcParameter paramNom = new OdbcParameter("", DbType.String);
paramNom.Value = "%" + text.ToUpper() + "%";
OdbcParameter paramNomBis = new OdbcParameter("", DbType.String);
paramNomBis.Value = "%" + text.ToUpper() + "%";
rechercherVille.Parameters.Add(paramNom);
rechercherVille.Parameters.Add(paramNomBis);
//Recheche Arrondissement
rechercheArrondissement.CommandText = "select * from Arrondissement where UCase(Nom) like ? order by Nom";
OdbcParameter paramCPArr = new OdbcParameter("", DbType.String);
paramCPArr.Value = "%" + text.ToUpper() + "%";
rechercheArrondissement.Parameters.Add(paramCPArr);
//Recherche departement
rechercherDep.CommandText = "select * from departement where departement_nom_uppercase like ? order by departement_nom";
OdbcParameter paramDep = new OdbcParameter("", DbType.String);
paramDep.Value = "%" + text + "%";
rechercherDep.Parameters.Add(paramDep);
}
Connexion c = new Connexion();
//cas ou la recherche se fait par arrondissement
if (rechercheArrondissement.CommandText != "") drcArrondissements = c.exeRequetteParametree(rechercheArrondissement).Tables[0].Rows;
//cas ou la recherche se fait par ville
if (rechercherVille.CommandText != "") drcAideVilles = c.exeRequetteParametree(rechercherVille).Tables[0].Rows;
if (rechercherPays.CommandText != "") drcAidePays = c.exeRequetteParametree(rechercherPays).Tables[0].Rows;
//cas ou la recherche se fait par departement
if (rechercherDep.CommandText != "") drcAideDep = c.exeRequetteParametree(rechercherDep).Tables[0].Rows;
c.Close();
}
}
//
protected void remplirTableAide()
{
if (Session["drcAideDep"] != null || drcAideDep != null)
{
if (drcAideDep == null) drcAideDep = (DataRowCollection)Session["drcAideDep"];
foreach (DataRow dr in drcAideDep)
{
ClickableTableCell cell = new ClickableTableCell();
cell.CssClass = "ajouterAcquereur_ClickableCell bold";
TableRow tr = new TableRow();
tr.Cells.Add(cell);
TableAideRecherche.Rows.Add(tr);
UpdatePanelControlTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = cell.UniqueID;
UpdatePanel1.Triggers.Add(trigger);
}
}
if (Session["drcAidePays"] != null || drcAidePays != null)
{
if (drcAidePays == null) drcAidePays = (DataRowCollection)Session["drcAidePays"];
foreach (DataRow dr in drcAidePays)
{
ClickableTableCell cell = new ClickableTableCell();
cell.CssClass = "ajouterAcquereur_ClickableCell bold";
TableRow tr = new TableRow();
tr.Cells.Add(cell);
TableAideRecherche.Rows.Add(tr);
UpdatePanelControlTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = cell.UniqueID;
UpdatePanel1.Triggers.Add(trigger);
}
}
if (Session["drcAideVilles"] != null || drcAideVilles != null)
{
if (drcAideVilles == null) drcAideVilles = (DataRowCollection)Session["drcAideVilles"];
foreach (DataRow dr in drcAideVilles)
{
ClickableTableCell cell = new ClickableTableCell();
cell.CssClass = "ajouterAcquereur_ClickableCell";
TableRow tr = new TableRow();
tr.Cells.Add(cell);
TableAideRecherche.Rows.Add(tr);
UpdatePanelControlTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = cell.UniqueID;
UpdatePanel1.Triggers.Add(trigger);
}
}
if (Session["drcArrondissements"] != null || drcArrondissements != null)
{
if (drcArrondissements == null) drcArrondissements = (DataRowCollection)Session["drcArrondissements"];
foreach (DataRow dr in drcArrondissements)
{
ClickableTableCell cell = new ClickableTableCell();
cell.CssClass = "ajouterAcquereur_ClickableCell";
TableRow tr = new TableRow();
tr.Cells.Add(cell);
TableAideRecherche.Rows.Add(tr);
UpdatePanelControlTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = cell.UniqueID;
UpdatePanel1.Triggers.Add(trigger);
}
}
}
//fonction que la cellule execute lors d un clic
protected void remplirListeEmplacement(object sender, EventArgs e)
{
ClickableTableCell cell = (ClickableTableCell)sender;
if (cell.type == "ville")
{
bool hasdistance = false;
if (Convert.ToInt32(HiddenField2.Text) != 0)
{
hasdistance = true;
}
string codeINSEE = cell.codeVille;
Emplacement ville;
bool hasArrondissement = false;
List<Arrondissement> listeArrond = null;
if (cell.CP.Length > 5)
{
hasArrondissement = true;
listeArrond = construireListeArrond(cell.codeVille);
}
List<Ville> listeINSEE = PATRIMO.Outils.OutilsDistance.villeINSEEListeDistance(cell.codeVille, Convert.ToInt32(HiddenField2.Text));
ListeEmplacementRecherche listeER = convertListeVilleToListeEmplacement(listeINSEE);
ville = new Emplacement(false, cell.nom, hasdistance, hasArrondissement, cell.codeVille, listeER, cell.CP, Convert.ToInt32(HiddenField2.Text), listeArrond);
emplacementAffiche.Add(ville);
rechargerListeERDansEmplacement(ville.CodeINSEE);
}
else if (cell.type == "pays")
{
string codePays = cell.codeVille;
Emplacement pays = new Emplacement(false, cell.nom, false, false, codePays, new ListeEmplacementRecherche());
pays.IsPays = true;
emplacementAffiche.Add(pays);
}
else if (cell.type == "dep")
{
string codeDep = cell.codeVille;
Emplacement dep = new Emplacement(true, cell.nom, false, false, codeDep, new ListeEmplacementRecherche());
emplacementAffiche.Add(dep);
}
else if (cell.type == "arrondissement")
{
//si ville pas deja recherché: ajouter ville et bannnir tout les arrondissement sauf celui la
//si ville existe deja, retirer arrondissement de la liste noir et recharger
bool villeExiste = false;
foreach (Emplacement empl in emplacementAffiche)
{
if (empl.CodeINSEE == cell.codeVille)
{
villeExiste = true;
break;
}
}
if (villeExiste)
{
foreach (Arrondissement arr in listeArrondissementNoire)
{
if (arr.CP == cell.CP)
{
listeArrondissementNoire.Remove(arr);
break;
}
}
rafraichirArrondissement();
}
else
{
// la ville n est pas deja enrengsitrée
bool hasdistance = false;
if (Convert.ToInt32(HiddenField2.Text) != 0)
{
hasdistance = true;
}
string codeINSEE = cell.codeVille;
Emplacement ville;
List<Arrondissement> listeArrond = null;
bool hasArrondissement = true;
listeArrond = construireListeArrond(cell.codeVille);
foreach (Arrondissement arr in listeArrond)
{
if (arr.CP == cell.CP)
{
listeArrond.Remove(arr);
break;
}
}
foreach (Arrondissement arr in listeArrond)
{
listeArrondissementNoire.Add(arr);
}
listeArrond = construireListeArrond(cell.codeVille);
string[] nomSplit = cell.nom.Split(' ');
string nom = "";
for (int i = 0; i < nomSplit.Length - 1; i++)
{
nom += nomSplit[i];
}
List<Ville> listeINSEE = PATRIMO.Outils.OutilsDistance.villeINSEEListeDistance(cell.codeVille, Convert.ToInt32(HiddenField2.Text));
ListeEmplacementRecherche listeER = convertListeVilleToListeEmplacement(listeINSEE);
ville = new Emplacement(false, nom, hasdistance, hasArrondissement, cell.codeVille, listeER, cell.CP, Convert.ToInt32(HiddenField2.Text), listeArrond);
emplacementAffiche.Add(ville);
}
rechargerListeERDansEmplacement(cell.codeVille);
}
rafraichirEmplacementAffiche();
toutVirer = true;
}
protected void supprimerVille(object sender, EventArgs e)
{
Label lbltest = new Label();
Panel PNL_resultPanel = new Panel();
if (Parent.FindControl("LBL_nbre_bien") != null) lbltest = (Label)Parent.FindControl("LBL_nbre_bien");
if (Parent.FindControl("PNL_resultPanel") != null) PNL_resultPanel = (Panel)Parent.FindControl("PNL_resultPanel");
if (emplacementAffiche.Count != 0)
{
lbltest.Visible = true;
PNL_resultPanel.Visible = false;
}
string code = ((MemoryButton)sender).code;
List<Emplacement> copie = new List<Emplacement>(emplacementAffiche);
foreach (Emplacement ville in copie)
{
if (ville.CodeINSEE == code)
{
emplacementAffiche.Remove(ville);
}
}
//rettirer les arrondissement correspondant de la liste noire
Connexion c = new Connexion();
OdbcCommand selectArrond = new OdbcCommand();
selectArrond.CommandText = "select * from arrondissement where VilleINSEE = ?";
OdbcParameter paramINSEE = new OdbcParameter("", OdbcType.VarChar);
paramINSEE.Value = code;
selectArrond.Parameters.Add(paramINSEE);
DataRowCollection drc = c.exeRequetteParametree(selectArrond).Tables[0].Rows;
foreach (DataRow dr in drc)
{
foreach (Arrondissement arrNoir in listeArrondissementNoire)
{
if (arrNoir.CP == dr["Code Postal"].ToString())
{
listeArrondissementNoire.Remove(arrNoir);
break;
}
}
}
rafraichirEmplacementAffiche();
}
//S'occupe de l'affichage des villes/departements selectionnes
protected void rafraichirEmplacementAffiche()
{
Label lbltest = new Label();
Panel PNL_resultPanel = new Panel();
if (Parent.FindControl("LBL_nbre_bien") != null) lbltest = (Label)Parent.FindControl("LBL_nbre_bien");
if (Parent.FindControl("PNL_resultPanel") != null) PNL_resultPanel = (Panel)Parent.FindControl("PNL_resultPanel");
UpdatePanel4.Attributes.CssStyle[HtmlTextWriterStyle.Visibility] = "hidden";
if (emplacementAffiche.Count != 0)
{
lbltest.Visible = false;
PNL_resultPanel.Visible = true;
}
if (Parent.FindControl("PNL_resultPanel") != null) PNL_resultPanel = (Panel)Parent.FindControl("PNL_resultPanel");
PNL_resultPanel.Controls.Clear();
int index = 0;
if (emplacementAffiche != null)
{
foreach (Emplacement ville in emplacementAffiche)
{
PNL_resultPanel.Controls.Add(new LiteralControl("<div class='cell_lieu_suppr'><table><tr><td valign:'top'>"));
MemoryButton boutonSuppr = new MemoryButton();
PNL_resultPanel.Controls.Add(boutonSuppr);
boutonSuppr.code = ville.CodeINSEE;
if (ville.IsContinent) boutonSuppr.OnClientClick = "WM_setUnselected('" + ville.CodeINSEE + "')"; //fonction javascript
boutonSuppr.Click += new ImageClickEventHandler(supprimerVille);
boutonSuppr.ID = index + "bouttonSuppr" + boutonSuppr.code;
UpdatePanelControlTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = boutonSuppr.ID;
UpdatePanel1.Triggers.Add(trigger);
boutonSuppr.AlternateText = "suppr ";
boutonSuppr.ImageUrl = @"~\img_site\bouton_supp_lieu_2.png";
PNL_resultPanel.Controls.Add(new LiteralControl("</td><td valign:'top'>"));
//gestion affichage de l emplacement
//nom
Label labelNom = new Label();
labelNom.Text = "<strong>"+ville.Nom+"</strong>";
PNL_resultPanel.Controls.Add(labelNom);
//CP(s)
if (!ville.HasArrondissement && !ville.IsPays && !ville.IsContinent)
{
Label labelCP = new Label();
labelCP.Text = " " + ville.CP;
PNL_resultPanel.Controls.Add(labelCP);
}
if (ville.HasDistance)
{
Label labelDistance = new Label();
labelDistance.Text = " (~ " + ville.Distance + " km)";
PNL_resultPanel.Controls.Add(labelDistance);
}
PNL_resultPanel.Controls.Add(new LiteralControl("</td></tr></table></div>"));
if (ville.HasArrondissement)
{
foreach (Arrondissement arr in ville.ListeArrondissement)
{
PNL_resultPanel.Controls.Add(new LiteralControl("<div class='cell_lieu_suppr'><table><tr><td valign:'top'>"));
//le boutton supprimer
MemoryButton buttonsupprArrond = new MemoryButton();
PNL_resultPanel.Controls.Add(buttonsupprArrond);
buttonsupprArrond.code = arr.CP;
buttonsupprArrond.Click += new ImageClickEventHandler(ajouterArrondissementALaListeNoire);
buttonsupprArrond.ID = index + "buttonsupprArrond" + buttonsupprArrond.code;
UpdatePanelControlTrigger trigg = new AsyncPostBackTrigger();
trigg.ControlID = buttonsupprArrond.ID;
UpdatePanel1.Triggers.Add(trigg);
buttonsupprArrond.AlternateText = "suppr ";
buttonsupprArrond.ImageUrl = @"~\img_site\bouton_supp_lieu_2.png";
PNL_resultPanel.Controls.Add(new LiteralControl("</td><td valign:'top'>"));
//le cp
Label labelCP = new Label();
labelCP.Text = arr.CP + " ";
PNL_resultPanel.Controls.Add(labelCP);
PNL_resultPanel.Controls.Add(new LiteralControl("</td></tr></table></div>"));
}
}
index++;
//if (!ville.HasArrondissement)
}
}
rafraichirListeEmplacementRecherche();
}
protected void rafraichirListeEmplacementRecherche()
{
Connexion c = new Connexion();
if (listeVilleRecherche != null) listeVilleRecherche.Clear();
if (emplacementAffiche != null)
{
foreach (Emplacement lieu in emplacementAffiche)
{
if (lieu.Dep == false && lieu.IsPays == false && lieu.IsContinent == false)
{
List<Ville> listeINSEE = PATRIMO.Outils.OutilsDistance.villeINSEEListeDistance(lieu.CodeINSEE, lieu.Distance);
foreach (Ville ville in listeINSEE)
{
bool noir = false;
foreach (EmplacementRecherche ER in listeNoire)
{
if (ER.CodeINSEE == ville.insee) noir = true;
}
if (noir == false)
{
bool hasArrondissement = false;
List<Arrondissement> listeArrond = null;
if (ville.cp.Length > 5)
{
hasArrondissement = true;
listeArrond = construireListeArrond(ville.insee);
}
EmplacementRecherche newER = new EmplacementRecherche(false, hasArrondissement, ville.insee, ville.nom, ville.cp, listeArrond);
listeVilleRecherche.Add(newER);
}
}
}
else if(lieu.IsPays == true)
{
EmplacementRecherche newER = new EmplacementRecherche(true, false, lieu.CodeINSEE, lieu.Nom);
newER.IsPays = true;
listeVilleRecherche.Add(newER);
}
else if(lieu.IsContinent == true)
{
EmplacementRecherche newER = new EmplacementRecherche(true, false, lieu.CodeINSEE, lieu.Nom);
newER.IsContinent = true;
listeVilleRecherche.Add(newER);
}
else
{
EmplacementRecherche newER = new EmplacementRecherche(true, false, lieu.CodeINSEE, lieu.Nom);
listeVilleRecherche.Add(newER);
}
}
}
//rafraichirAffichageAvance();
}
protected List<Arrondissement> construireListeArrond(string INSEE)
{
Connexion c = new Connexion();
OdbcCommand commande = new OdbcCommand();
commande.CommandText = "select * from Arrondissement where VilleINSEE = ? ";
OdbcParameter paramINSEE = new OdbcParameter("", DbType.String);
paramINSEE.Value = INSEE;
commande.Parameters.Add(paramINSEE);
foreach (Arrondissement arrond in listeArrondissementNoire)
{
commande.CommandText += " AND [Code Postal] <> ? ";
OdbcParameter paramCP = new OdbcParameter("", DbType.String);
paramCP.Value = arrond.CP;
commande.Parameters.Add(paramCP);
}
DataRowCollection drc = c.exeRequetteParametree(commande).Tables[0].Rows;
List<Arrondissement> liste = new List<Arrondissement>();
foreach (DataRow result in drc)
{
Arrondissement arr = new Arrondissement(result["Code Postal"].ToString());
liste.Add(arr);
}
return liste;
}
protected void ajouterArrondissementALaListeNoire(object sender, EventArgs e)
{
//on difinie l arrondissement a retirer
string CParrond = ((MemoryButton)sender).code;
Arrondissement arr = new Arrondissement(CParrond);
//on ajoute l arrondissement a la liste noire
listeArrondissementNoire.Add(arr);
//on retire l arrondissement dans les objet qui ne se rafraichissent pas au chargement
foreach (Emplacement empl in emplacementAffiche)
{
foreach (EmplacementRecherche ER in empl.ListeVille)
{
if (empl.HasArrondissement)
{
foreach (Arrondissement arrondissementDeEmplacement in ER.ListeArrondissement)
{
if (arrondissementDeEmplacement.CP == arr.CP)
{
empl.ListeArrondissement.Remove(arrondissementDeEmplacement);
break;
}
}
}
}
}
//on rafraichit
rafraichirArrondissement();
}
protected void retirerArrondissementDelaListeNoire(Object sender, EventArgs e)
{
string CParrond = ((MemoryButton)sender).code;
Arrondissement trouve = null;
foreach (Arrondissement arr in listeArrondissementNoire)
{
if (arr.CP == CParrond)
{
trouve = arr;
break;
}
}
listeArrondissementNoire.Remove(trouve);
rechargerListeERDansEmplacement();
rafraichirArrondissement();
}
protected void rafraichirArrondissement()
{
foreach (Emplacement empl in emplacementAffiche)
{
if (empl.HasArrondissement)